diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 37d408eb4b72..19f71a58ea52 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -66,6 +66,8 @@ class PaymentRepository extends BaseRepository { */ private function applyPayment(array $data, Payment $payment): ?Payment { + nlog("applying payment"); + nlog($data); $is_existing_payment = true; $client = false; diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index f9a92cecb64c..481e2d5a3147 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -82,6 +82,8 @@ class DeletePayment $net_deletable = $paymentable_invoice->pivot->amount - $paymentable_invoice->pivot->refunded; + $client = $this->payment->client->fresh(); + nlog("net deletable amount - refunded = {$net_deletable}"); 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}") ->save(); - $paymentable_invoice->client - ->service() - ->updateBalance($net_deletable) - // ->updatePaidToDate($net_deletable * -1) - ->save(); + $client = $client->service() + ->updateBalance($net_deletable) + ->save(); if ($paymentable_invoice->balance == $paymentable_invoice->amount) { $paymentable_invoice->service()->setStatus(Invoice::STATUS_SENT)->save();