Adjustments for client balance

This commit is contained in:
David Bomba 2022-03-09 13:49:31 +11:00
parent b0d5117a0f
commit b2b937f9ad
2 changed files with 7 additions and 5 deletions

View File

@ -66,6 +66,8 @@ class PaymentRepository extends BaseRepository {
*/ */
private function applyPayment(array $data, Payment $payment): ?Payment private function applyPayment(array $data, Payment $payment): ?Payment
{ {
nlog("applying payment");
nlog($data);
$is_existing_payment = true; $is_existing_payment = true;
$client = false; $client = false;

View File

@ -82,6 +82,8 @@ class DeletePayment
$net_deletable = $paymentable_invoice->pivot->amount - $paymentable_invoice->pivot->refunded; $net_deletable = $paymentable_invoice->pivot->amount - $paymentable_invoice->pivot->refunded;
$client = $this->payment->client->fresh();
nlog("net deletable amount - refunded = {$net_deletable}"); nlog("net deletable amount - refunded = {$net_deletable}");
if(!$paymentable_invoice->is_deleted) if(!$paymentable_invoice->is_deleted)
@ -95,11 +97,9 @@ class DeletePayment
->updateInvoiceBalance($net_deletable, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}") ->updateInvoiceBalance($net_deletable, "Adjusting invoice {$paymentable_invoice->number} due to deletion of Payment {$this->payment->number}")
->save(); ->save();
$paymentable_invoice->client $client = $client->service()
->service() ->updateBalance($net_deletable)
->updateBalance($net_deletable) ->save();
// ->updatePaidToDate($net_deletable * -1)
->save();
if ($paymentable_invoice->balance == $paymentable_invoice->amount) { if ($paymentable_invoice->balance == $paymentable_invoice->amount) {
$paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save(); $paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save();