diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 3f6e13c43410..2237f992fb86 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -151,14 +151,16 @@ class PaymentRepository extends BaseRepository $invoice_totals -= $credit_totals; //$payment->amount = $invoice_totals; //creates problems when setting amount like this. - - if ($invoice_totals == $payment->amount) { + if($credit_totals == $payment->amount){ + $payment->applied += $credit_totals; + } elseif ($invoice_totals == $payment->amount) { $payment->applied += $payment->amount; } elseif ($invoice_totals < $payment->amount) { $payment->applied += $invoice_totals; } $payment->save(); + return $payment->fresh(); } diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index d8f5ead9213c..05a0d0ac99d2 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -37,7 +37,7 @@ class ApplyPayment extends AbstractService ->ledger() ->updatePaymentBalance($this->payment_amount*-1); - info("apply paymenet method - current client balance = {$this->payment->client->balance}"); + info("apply payment method - current client balance = {$this->payment->client->balance}"); info("reducing client balance by payment amount {$this->payment_amount}"); @@ -56,7 +56,7 @@ class ApplyPayment extends AbstractService $this->invoice->fresh('client'); - info("1 end of apply payment method the client balnace = {$this->invoice->client->balance}"); + info("1 end of apply payment method the client balance = {$this->invoice->client->balance}"); if ($this->invoice->hasPartial()) { //is partial and amount is exactly the partial amount