diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 513199e863aa..06dec862bbad 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -315,7 +315,7 @@ class CheckData extends Command $total_invoice_payments += $credit_total_applied; } //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)) { $wrong_paid_to_dates++; diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 6cb00c4b6b2e..b2eed5d96870 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -238,7 +238,7 @@ class InvoiceItemSum $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); } @@ -246,7 +246,7 @@ class InvoiceItemSum $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); } @@ -254,7 +254,7 @@ class InvoiceItemSum $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); } } diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index a04d4f229e7e..b65b3cc75921 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -233,7 +233,7 @@ class InvoiceItemSumInclusive $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); } @@ -241,7 +241,7 @@ class InvoiceItemSumInclusive $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); } @@ -249,7 +249,7 @@ class InvoiceItemSumInclusive $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); } } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 04bf3f62b2e8..b8ac86b755e0 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -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(); @@ -941,6 +946,24 @@ class Import implements ShouldQueue $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 { // define('PAYMENT_STATUS_PENDING', 1); diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index fc66ebe6708d..90e6cf8c7198 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -92,6 +92,7 @@ class PaymentMigrationRepository extends BaseRepository } $payment->status_id = $data['status_id']; + $payment->refunded = $data['refunded']; if($payment->status_id == Payment::STATUS_CANCELLED) $payment->is_deleted = true;