Skip to content

Commit

Permalink
Refactor for invoice deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Jan 15, 2025
1 parent 132f053 commit 8bd2213
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions app/Repositories/InvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ public function getInvitationByKey($key): ?InvoiceInvitation
*/
public function delete($invoice): Invoice
{
$invoice = $invoice->fresh();

$invoice = \DB::transaction(function () use ($invoice) {
return \App\Models\Invoice::lockForUpdate()->find($invoice->id);
});

if ($invoice->is_deleted) {
if (!$invoice || $invoice->is_deleted) {
return $invoice;
}

$invoice->is_deleted = true;
$invoice->saveQuietly();

$invoice = $invoice->service()->markDeleted()->save();

parent::delete($invoice);

return $invoice;
}

Expand Down
10 changes: 6 additions & 4 deletions app/Services/Invoice/MarkInvoiceDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace App\Services\Invoice;

use App\Events\Invoice\InvoiceWasDeleted;
use App\Jobs\Inventory\AdjustProductInventory;
use App\Models\Invoice;
use App\Models\Quote;
Expand All @@ -33,10 +34,7 @@ public function __construct(public Invoice $invoice)

public function run()
{
if ($this->invoice->is_deleted) {
return $this->invoice;
}


if ($this->invoice->company->track_inventory) {
(new AdjustProductInventory($this->invoice->company, $this->invoice, []))->handleDeletedInvoice();
}
Expand All @@ -49,6 +47,10 @@ public function run()
->adjustLedger()
->triggeredActions();

$this->invoice->delete();

event(new \App\Events\Invoice\InvoiceWasDeleted($this->invoice, $this->invoice->company, \App\Utils\Ninja::eventVars(auth()->guard('api')->user() ? auth()->guard('api')->user()->id : null)));

return $this->invoice;
}

Expand Down
4 changes: 2 additions & 2 deletions resources/views/email/template/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@
font-family: Verdana, Geneva, Tahoma, sans-serif;"{{ date('Y') }} Invoice Ninja, All Rights Reserved
</p>

<a href="{{ $email_preferences }}">
<!-- <a href="{{ $email_preferences }}">
<p style="text-align: center; color: #ffffff; font-size: 10px; font-family: Verdana, Geneva, Tahoma, sans-serif;">
{{ ctrans('texts.email_preferences') }}
</p>
</a>
</a> -->

</div>
</td>
Expand Down

0 comments on commit 8bd2213

Please sign in to comment.