From 0ae3eecec72747fea26959e63b1372a09f2fac8e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 Feb 2021 18:40:07 +1100 Subject: [PATCH 1/4] Version 5.1.2 --- VERSION.txt | 2 +- config/ninja.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 3bff059174b8..1b47e8f3efe7 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.1 \ No newline at end of file +5.1.2 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index 9dad10d7515f..cd0abe143d50 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -13,7 +13,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.1.1', + 'app_version' => '5.1.2', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), From 507367f4301934882863e4846a98ba848fd7bd81 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 Feb 2021 19:25:05 +1100 Subject: [PATCH 2/4] Set vendor -> number in demo data --- app/Console/Commands/DemoMode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 65629ecacb9c..7a926807e131 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -339,7 +339,7 @@ class DemoMode extends Command ]); - $vendor->id_number = $this->getNextVendorNumber($vendor); + $vendor->number = $this->getNextVendorNumber($vendor); $vendor->save(); } From 6681b4fbfefd45eb625ed38e06d447f15656d5ac Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 Feb 2021 23:35:16 +1100 Subject: [PATCH 3/4] Fixes for import / migrartions --- app/Console/Commands/CheckData.php | 2 +- app/Helpers/Invoice/InvoiceItemSum.php | 6 ++--- .../Invoice/InvoiceItemSumInclusive.php | 6 ++--- app/Jobs/Util/Import.php | 23 +++++++++++++++++++ .../Migration/PaymentMigrationRepository.php | 1 + 5 files changed, 31 insertions(+), 7 deletions(-) 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; From e56a37a71814455fcefa39b2ca99bdbc09d02e70 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Feb 2021 00:03:59 +1100 Subject: [PATCH 4/4] Return object not null if you have to return early!! --- app/Services/Invoice/UpdateBalance.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Services/Invoice/UpdateBalance.php b/app/Services/Invoice/UpdateBalance.php index 4ae9408c4553..cd4e50aeb641 100644 --- a/app/Services/Invoice/UpdateBalance.php +++ b/app/Services/Invoice/UpdateBalance.php @@ -16,9 +16,9 @@ use App\Services\AbstractService; class UpdateBalance extends AbstractService { - private $invoice; + public $invoice; - private $balance_adjustment; + public $balance_adjustment; public function __construct($invoice, $balance_adjustment) { @@ -29,7 +29,7 @@ class UpdateBalance extends AbstractService public function run() { if ($this->invoice->is_deleted) { - return; + return $this->invoice; } $this->invoice->balance += floatval($this->balance_adjustment);