mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Improve invoice payment registrations
This commit is contained in:
parent
da47f1bf32
commit
4c2c62bd85
@ -322,8 +322,6 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
|
|
||||||
if (collect($invoice->line_items)->contains('type_id', '3')) {
|
if (collect($invoice->line_items)->contains('type_id', '3')) {
|
||||||
$invoice->service()->toggleFeesPaid()->save();
|
$invoice->service()->toggleFeesPaid()->save();
|
||||||
// $invoice->client->service()->updateBalance($fee_total)->save();
|
|
||||||
// $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$transaction = [
|
$transaction = [
|
||||||
|
@ -404,7 +404,6 @@ class InvoiceService
|
|||||||
public function updatePartial($amount)
|
public function updatePartial($amount)
|
||||||
{
|
{
|
||||||
$this->invoice->partial += $amount;
|
$this->invoice->partial += $amount;
|
||||||
// $this->invoice->increment('partial', $amount);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -535,7 +534,7 @@ class InvoiceService
|
|||||||
/* Throws: Payment amount xxx does not match invoice totals. */
|
/* Throws: Payment amount xxx does not match invoice totals. */
|
||||||
|
|
||||||
if ($this->invoice->trashed())
|
if ($this->invoice->trashed())
|
||||||
return;
|
return $this;
|
||||||
|
|
||||||
$this->invoice->delete();
|
$this->invoice->delete();
|
||||||
|
|
||||||
|
@ -40,19 +40,20 @@ class UpdateInvoicePayment
|
|||||||
$paid_invoices = $this->payment_hash->invoices();
|
$paid_invoices = $this->payment_hash->invoices();
|
||||||
|
|
||||||
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
|
$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 = $client->fresh();
|
||||||
$client->restore();
|
|
||||||
|
|
||||||
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
|
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
|
||||||
return $paid_invoice->invoice_id == $inv->hashed_id;
|
return $paid_invoice->invoice_id == $inv->hashed_id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if($invoice->trashed())
|
if($invoice->trashed())
|
||||||
$invoice->restore();
|
$invoice->restore();
|
||||||
|
|
||||||
@ -62,23 +63,23 @@ class UpdateInvoicePayment
|
|||||||
$paid_amount = $paid_invoice->amount;
|
$paid_amount = $paid_invoice->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
$client
|
$client->paid_to_date += $paid_amount;
|
||||||
->service()
|
$client->balance -= $paid_amount;
|
||||||
->updatePaidToDate($paid_amount)
|
$client->save();
|
||||||
->save();
|
|
||||||
|
|
||||||
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */
|
/* 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)
|
if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
|
||||||
$paid_amount = $invoice->balance;
|
$paid_amount = $invoice->balance;
|
||||||
|
|
||||||
/*Improve performance here - 26-01-2022 - also change the order of events for invoice first*/
|
/*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!
|
//caution what if we amount paid was less than partial - we wipe it!
|
||||||
->clearPartial()
|
$invoice = $invoice->service()
|
||||||
->updateBalance($paid_amount * -1)
|
->clearPartial()
|
||||||
->updatePaidToDate($paid_amount)
|
->updateBalance($paid_amount * -1)
|
||||||
->updateStatus()
|
->updatePaidToDate($paid_amount)
|
||||||
->touchPdf()
|
->updateStatus()
|
||||||
->save();
|
->touchPdf()
|
||||||
|
->save();
|
||||||
|
|
||||||
$invoice->service()
|
$invoice->service()
|
||||||
->workFlow()
|
->workFlow()
|
||||||
@ -89,11 +90,6 @@ class UpdateInvoicePayment
|
|||||||
->ledger()
|
->ledger()
|
||||||
->updatePaymentBalance($paid_amount * -1);
|
->updatePaymentBalance($paid_amount * -1);
|
||||||
|
|
||||||
$client
|
|
||||||
->service()
|
|
||||||
->updateBalance($paid_amount * -1)
|
|
||||||
->save();
|
|
||||||
|
|
||||||
$pivot_invoice = $this->payment->invoices->first(function ($inv) use ($paid_invoice) {
|
$pivot_invoice = $this->payment->invoices->first(function ($inv) use ($paid_invoice) {
|
||||||
return $inv->hashed_id == $paid_invoice->invoice_id;
|
return $inv->hashed_id == $paid_invoice->invoice_id;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user