mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for migrations - do not applied cancelled payments to invoices
This commit is contained in:
parent
d7677d1d0c
commit
59ae0d3219
@ -225,7 +225,12 @@ class InvoiceItemSumInclusive
|
||||
$item_tax = 0;
|
||||
|
||||
foreach ($this->line_items as $this->item) {
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
|
||||
if($this->sub_total == 0)
|
||||
$amount = $this->item->line_total;
|
||||
else
|
||||
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total));
|
||||
|
||||
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
|
||||
|
||||
$item_tax += $item_tax_rate1_total;
|
||||
|
@ -92,6 +92,10 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$payment->status_id = $data['status_id'];
|
||||
|
||||
if($payment->status_id == Payment::STATUS_CANCELLED)
|
||||
$payment->is_deleted = true;
|
||||
|
||||
$payment->deleted_at = $data['deleted_at'] ?: null;
|
||||
$payment->save();
|
||||
|
||||
@ -113,24 +117,28 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
|
||||
$payment->invoices()->saveMany($invoices);
|
||||
|
||||
$payment->invoices->each(function ($inv) use ($invoice_totals, $refund_totals) {
|
||||
$payment->invoices->each(function ($inv) use ($invoice_totals, $refund_totals, $payment) {
|
||||
|
||||
$inv->pivot->amount = $invoice_totals;
|
||||
$inv->pivot->refunded = $refund_totals;
|
||||
$inv->pivot->save();
|
||||
|
||||
$inv->paid_to_date += $invoice_totals;
|
||||
$inv->balance -= $invoice_totals;
|
||||
if($payment->status_id != Payment::STATUS_CANCELLED)
|
||||
{
|
||||
$inv->pivot->amount = $invoice_totals;
|
||||
$inv->pivot->refunded = $refund_totals;
|
||||
$inv->pivot->save();
|
||||
|
||||
if($inv->status_id == Invoice::STATUS_PAID)
|
||||
$inv->balance = 0;
|
||||
$inv->paid_to_date += $invoice_totals;
|
||||
$inv->balance -= $invoice_totals;
|
||||
|
||||
// if($inv->balance > 0)
|
||||
//
|
||||
if($inv->status_id == Invoice::STATUS_PAID)
|
||||
$inv->balance = 0;
|
||||
|
||||
// $inv->balance = max(0, $inv->balance);
|
||||
// if($inv->balance > 0)
|
||||
//
|
||||
|
||||
$inv->save();
|
||||
// $inv->balance = max(0, $inv->balance);
|
||||
|
||||
$inv->save();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user