Fixes for import / migrartions

This commit is contained in:
David Bomba 2021-02-07 23:35:16 +11:00
parent 507367f430
commit 6681b4fbfe
5 changed files with 31 additions and 7 deletions

View File

@ -315,7 +315,7 @@ class CheckData extends Command
$total_invoice_payments += $credit_total_applied; $total_invoice_payments += $credit_total_applied;
} //todo this is contentious } //todo this is contentious
nlog("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}"); // nlog("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) { if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
$wrong_paid_to_dates++; $wrong_paid_to_dates++;

View File

@ -238,7 +238,7 @@ class InvoiceItemSum
$item_tax += $item_tax_rate1_total; $item_tax += $item_tax_rate1_total;
if ($item_tax_rate1_total > 0) { if ($item_tax_rate1_total != 0) {
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total); $this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
} }
@ -246,7 +246,7 @@ class InvoiceItemSum
$item_tax += $item_tax_rate2_total; $item_tax += $item_tax_rate2_total;
if ($item_tax_rate2_total > 0) { if ($item_tax_rate2_total != 0) {
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total); $this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
} }
@ -254,7 +254,7 @@ class InvoiceItemSum
$item_tax += $item_tax_rate3_total; $item_tax += $item_tax_rate3_total;
if ($item_tax_rate3_total > 0) { if ($item_tax_rate3_total != 0) {
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
} }
} }

View File

@ -233,7 +233,7 @@ class InvoiceItemSumInclusive
$item_tax += $item_tax_rate1_total; $item_tax += $item_tax_rate1_total;
if ($item_tax_rate1_total > 0) { if ($item_tax_rate1_total != 0) {
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total); $this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
} }
@ -241,7 +241,7 @@ class InvoiceItemSumInclusive
$item_tax += $item_tax_rate2_total; $item_tax += $item_tax_rate2_total;
if ($item_tax_rate2_total > 0) { if ($item_tax_rate2_total != 0) {
$this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total); $this->groupTax($this->item->tax_name2, $this->item->tax_rate2, $item_tax_rate2_total);
} }
@ -249,7 +249,7 @@ class InvoiceItemSumInclusive
$item_tax += $item_tax_rate3_total; $item_tax += $item_tax_rate3_total;
if ($item_tax_rate3_total > 0) { if ($item_tax_rate3_total != 0) {
$this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total);
} }
} }

View File

@ -932,6 +932,11 @@ class Import implements ShouldQueue
], ],
]; ];
if(in_array($payment->status_id, [Payment::STATUS_REFUNDED, Payment::STATUS_PARTIALLY_REFUNDED])) {
$this->processPaymentRefund($payment);
}
} }
Payment::reguard(); Payment::reguard();
@ -941,6 +946,24 @@ class Import implements ShouldQueue
$payment_repository = null; $payment_repository = null;
} }
private function processPaymentRefund($payment)
{
$invoices = $payment->invoices()->get();
$invoices->each(function ($invoice) use($payment) {
if ($payment->refunded > 0 && in_array($invoice->status_id, [Invoice::STATUS_SENT])) {
$invoice->service()
->updateBalance($payment->refunded)
->updatePaidToDate($payment->refunded*-1)
->updateStatus()
->save();
}
});
}
private function updatePaymentForStatus($payment, $status_id) :Payment private function updatePaymentForStatus($payment, $status_id) :Payment
{ {
// define('PAYMENT_STATUS_PENDING', 1); // define('PAYMENT_STATUS_PENDING', 1);

View File

@ -92,6 +92,7 @@ class PaymentMigrationRepository extends BaseRepository
} }
$payment->status_id = $data['status_id']; $payment->status_id = $data['status_id'];
$payment->refunded = $data['refunded'];
if($payment->status_id == Payment::STATUS_CANCELLED) if($payment->status_id == Payment::STATUS_CANCELLED)
$payment->is_deleted = true; $payment->is_deleted = true;