Fixes for refund payments

This commit is contained in:
David Bomba 2022-03-26 13:58:49 +11:00
parent cdf8f04457
commit d30987c203
3 changed files with 18 additions and 9 deletions

View File

@ -28,8 +28,6 @@ class ClientService
public function updateBalance(float $amount)
{
// $this->client->balance += $amount;
$this->client->increment('balance', $amount);
return $this;
@ -37,8 +35,6 @@ class ClientService
public function updatePaidToDate(float $amount)
{
// $this->client->paid_to_date += $amount;
$this->client->increment('paid_to_date', $amount);
return $this;
@ -46,8 +42,6 @@ class ClientService
public function adjustCreditBalance(float $amount)
{
// $this->client->credit_balance += $amount;
$this->client->increment('credit_balance', $amount);
return $this;

View File

@ -263,7 +263,8 @@ class RefundPayment
foreach ($this->refund_data['invoices'] as $refunded_invoice) {
$invoice = Invoice::withTrashed()->find($refunded_invoice['invoice_id']);
$invoice->restore();
if($invoice->trashed())
$invoice->restore();
$invoice->service()->updateBalance($refunded_invoice['amount'])->save();
$invoice->ledger()->updateInvoiceBalance($refunded_invoice['amount'], "Refund of payment # {$this->payment->number}")->save();
@ -300,6 +301,10 @@ class RefundPayment
}
$client = $this->payment->client->fresh();
if($client->trashed())
$client->restore();
$client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save();
@ -318,6 +323,10 @@ class RefundPayment
//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.
$client = $this->payment->client->fresh();
if($client->trashed())
$client->restore();
$client->service()->updatePaidToDate(-1 * $this->total_refund)->save();
$transaction = [

View File

@ -43,12 +43,19 @@ class UpdateInvoicePayment
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices) {
$client = $this->payment->client->fresh();
$client = $this->payment->client;
if($client->trashed())
$client->restore();
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
return $paid_invoice->invoice_id == $inv->hashed_id;
});
if($invoice->trashed())
$invoice->restore();
if ($invoice->id == $this->payment_hash->fee_invoice_id) {
$paid_amount = $paid_invoice->amount + $this->payment_hash->fee_total;
} else {
@ -116,7 +123,6 @@ class UpdateInvoicePayment
$invoices->each(function ($invoice) {
$invoice = $invoice->fresh();
event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
});