From 3155fcca53cff011351ba47e4bf3f37c644430c5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 13 May 2024 11:26:45 +1000 Subject: [PATCH] Add credit adjustment notes to credit notes --- app/Jobs/Credit/ApplyCreditPayment.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Credit/ApplyCreditPayment.php b/app/Jobs/Credit/ApplyCreditPayment.php index 211fe4383d6c..d2ebc361ef35 100644 --- a/app/Jobs/Credit/ApplyCreditPayment.php +++ b/app/Jobs/Credit/ApplyCreditPayment.php @@ -11,13 +11,16 @@ namespace App\Jobs\Credit; +use App\Utils\Number; use App\Models\Credit; use App\Models\Payment; use Illuminate\Bus\Queueable; +use Illuminate\Support\Carbon; +use App\DataMapper\InvoiceItem; +use Illuminate\Queue\SerializesModels; +use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\SerializesModels; class ApplyCreditPayment implements ShouldQueue { @@ -67,6 +70,19 @@ class ApplyCreditPayment implements ShouldQueue $credit_balance = $this->credit->balance; + $item_date = Carbon::parse($this->payment->date)->format($this->payment->client->date_format()); + $invoice_numbers = $this->payment->invoices->pluck('number')->implode(","); + + $item = new InvoiceItem(); + $item->quantity = 0; + $item->cost = $this->amount * -1; + $item->notes = "{$item_date} - " . ctrans('texts.credit_payment', ['invoice_number' => $invoice_numbers]) . " ". Number::formatMoney($this->amount, $this->payment->client); + $item->type_id = "1"; + + $line_items = $this->credit->line_items; + $line_items[] = $item; + $this->credit->line_items = $line_items; + if ($this->amount == $credit_balance) { //total credit applied. $this->credit ->service() @@ -90,7 +106,7 @@ class ApplyCreditPayment implements ShouldQueue ->client ->service() ->adjustCreditBalance($this->amount * -1) - ->save(); + ->save(); /* Update Payment Applied Amount*/ $this->payment->save();