Fix for applied amount when using credits to pay invoices

This commit is contained in:
David Bomba 2020-06-18 13:19:38 +10:00
parent a669e9342f
commit a7e05cb3bd
2 changed files with 6 additions and 4 deletions

View File

@ -151,14 +151,16 @@ class PaymentRepository extends BaseRepository
$invoice_totals -= $credit_totals; $invoice_totals -= $credit_totals;
//$payment->amount = $invoice_totals; //creates problems when setting amount like this. //$payment->amount = $invoice_totals; //creates problems when setting amount like this.
if($credit_totals == $payment->amount){
if ($invoice_totals == $payment->amount) { $payment->applied += $credit_totals;
} elseif ($invoice_totals == $payment->amount) {
$payment->applied += $payment->amount; $payment->applied += $payment->amount;
} elseif ($invoice_totals < $payment->amount) { } elseif ($invoice_totals < $payment->amount) {
$payment->applied += $invoice_totals; $payment->applied += $invoice_totals;
} }
$payment->save(); $payment->save();
return $payment->fresh(); return $payment->fresh();
} }

View File

@ -37,7 +37,7 @@ class ApplyPayment extends AbstractService
->ledger() ->ledger()
->updatePaymentBalance($this->payment_amount*-1); ->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}"); info("reducing client balance by payment amount {$this->payment_amount}");
@ -56,7 +56,7 @@ class ApplyPayment extends AbstractService
$this->invoice->fresh('client'); $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()) { if ($this->invoice->hasPartial()) {
//is partial and amount is exactly the partial amount //is partial and amount is exactly the partial amount