Fixes for paid to date adjustments:

This commit is contained in:
David Bomba 2023-08-08 19:11:59 +10:00
parent b352178696
commit f1ab55ec0f
3 changed files with 8 additions and 11 deletions

View File

@ -185,6 +185,9 @@ class CheckData extends Command
if ($cu->company && $cu->user) { if ($cu->company && $cu->user) {
(new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle(); (new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle();
} }
else {
// $cu->forceDelete();
}
} }
}); });
} }

View File

@ -273,7 +273,7 @@ class InstantPayment
'is_recurring' => $this->request->is_recurring, 'is_recurring' => $this->request->is_recurring,
]; ];
if ($is_credit_payment || $totals <= 0) { if ($is_credit_payment) {
return $this->processCreditPayment($this->request, $data); return $this->processCreditPayment($this->request, $data);
} }

View File

@ -238,7 +238,8 @@ class RefundPayment
private function adjustInvoices() private function adjustInvoices()
{ {
if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) { if (isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0) {
foreach ($this->refund_data['invoices'] as $refunded_invoice) { foreach ($this->refund_data['invoices'] as $refunded_invoice)
{
$invoice = Invoice::withTrashed()->find($refunded_invoice['invoice_id']); $invoice = Invoice::withTrashed()->find($refunded_invoice['invoice_id']);
if ($invoice->trashed()) { if ($invoice->trashed()) {
@ -265,10 +266,10 @@ class RefundPayment
$invoice->saveQuietly(); $invoice->saveQuietly();
//06-09-2022 //08-08-2023
$client = $invoice->client $client = $invoice->client
->service() ->service()
->updateBalance($refunded_invoice['amount']) ->updateBalanceAndPaidToDate($refunded_invoice['amount'], -1 * $refunded_invoice['amount'])
->save(); ->save();
if ($invoice->is_deleted) { if ($invoice->is_deleted) {
@ -276,13 +277,6 @@ class RefundPayment
} }
} }
$client = $this->payment->client->fresh();
if ($client->trashed()) {
$client->restore();
}
$client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save();
} else { } else {
//if we are refunding and no payments have been tagged, then we need to decrement the client->paid_to_date by the total refund amount. //if we are refunding and no payments have been tagged, then we need to decrement the client->paid_to_date by the total refund amount.