1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Improve invoice payment registrations

This commit is contained in:
David Bomba 2022-03-28 16:36:00 +11:00
parent da47f1bf32
commit 4c2c62bd85
3 changed files with 18 additions and 25 deletions

View File

@ -322,8 +322,6 @@ class BaseDriver extends AbstractPaymentDriver
if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save();
// $invoice->client->service()->updateBalance($fee_total)->save();
// $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
}
$transaction = [

View File

@ -404,7 +404,6 @@ class InvoiceService
public function updatePartial($amount)
{
$this->invoice->partial += $amount;
// $this->invoice->increment('partial', $amount);
return $this;
}
@ -535,7 +534,7 @@ class InvoiceService
/* Throws: Payment amount xxx does not match invoice totals. */
if ($this->invoice->trashed())
return;
return $this;
$this->invoice->delete();

View File

@ -40,19 +40,20 @@ class UpdateInvoicePayment
$paid_invoices = $this->payment_hash->invoices();
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
$client = $this->payment->client;
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices) {
if($client->trashed())
$client->restore();
$client = $this->payment->client;
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices, $client) {
if($client->trashed())
$client->restore();
$client = $client->fresh();
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
return $paid_invoice->invoice_id == $inv->hashed_id;
});
if($invoice->trashed())
$invoice->restore();
@ -62,23 +63,23 @@ class UpdateInvoicePayment
$paid_amount = $paid_invoice->amount;
}
$client
->service()
->updatePaidToDate($paid_amount)
->save();
$client->paid_to_date += $paid_amount;
$client->balance -= $paid_amount;
$client->save();
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */
if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
$paid_amount = $invoice->balance;
/*Improve performance here - 26-01-2022 - also change the order of events for invoice first*/
$invoice->service() //caution what if we amount paid was less than partial - we wipe it!
->clearPartial()
->updateBalance($paid_amount * -1)
->updatePaidToDate($paid_amount)
->updateStatus()
->touchPdf()
->save();
//caution what if we amount paid was less than partial - we wipe it!
$invoice = $invoice->service()
->clearPartial()
->updateBalance($paid_amount * -1)
->updatePaidToDate($paid_amount)
->updateStatus()
->touchPdf()
->save();
$invoice->service()
->workFlow()
@ -89,11 +90,6 @@ class UpdateInvoicePayment
->ledger()
->updatePaymentBalance($paid_amount * -1);
$client
->service()
->updateBalance($paid_amount * -1)
->save();
$pivot_invoice = $this->payment->invoices->first(function ($inv) use ($paid_invoice) {
return $inv->hashed_id == $paid_invoice->invoice_id;
});