From 8a6eea83505a2578c2583efe638a616d0732cd94 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 22 Apr 2022 22:01:32 +1000 Subject: [PATCH] Fixes for regression - incorrect type setting in ClientSettings --- VERSION.txt | 2 +- app/Services/Invoice/MarkPaid.php | 14 ++++-- app/Services/Invoice/MarkSent.php | 15 ++++-- config/ninja.php | 4 +- ...115838_client_settings_parse_for_types.php | 47 +++++++++++++++++++ resources/views/index/index.blade.php | 1 - tests/Feature/PaymentTest.php | 2 +- tests/Integration/CompanyLedgerTest.php | 6 +-- 8 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 database/migrations/2022_04_22_115838_client_settings_parse_for_types.php diff --git a/VERSION.txt b/VERSION.txt index a7e0a988addf..12d56fd94bff 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.81 \ No newline at end of file +5.3.82 \ No newline at end of file diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 920f72e27a09..17cfdf5e1437 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -18,6 +18,7 @@ use App\Jobs\Invoice\InvoiceWorkflowSettings; use App\Jobs\Ninja\TransactionLog; use App\Jobs\Payment\EmailPayment; use App\Libraries\Currency\Conversion\CurrencyApi; +use App\Models\Client; use App\Models\Invoice; use App\Models\Payment; use App\Models\TransactionEvent; @@ -99,10 +100,15 @@ class MarkPaid extends AbstractService $payment->ledger() ->updatePaymentBalance($payment->amount * -1); - $this->invoice->client->fresh(); - $this->invoice->client->paid_to_date += $payment->amount; - $this->invoice->client->balance += $payment->amount * -1; - $this->invoice->client->push(); + \DB::connection(config('database.default'))->transaction(function () use($payment){ + + /* Get the last record for the client and set the current balance*/ + $client = Client::where('id', $this->invoice->client_id)->lockForUpdate()->first(); + $client->paid_to_date += $payment->amount; + $client->balance += $payment->amount * -1; + $client->save(); + + }, 1); $this->invoice = $this->invoice ->service() diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 292521ea5a7f..886888cd77ed 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -57,16 +57,21 @@ class MarkSent extends AbstractService ->service() ->applyNumber() ->setDueDate() - // ->deletePdf() //08-01-2022 - ->touchPdf() //08-01-2022 + ->touchPdf() ->setReminder() ->save(); /*Adjust client balance*/ - $this->client->fresh(); - $this->client->balance += $adjustment; - $this->client->save(); + + \DB::connection(config('database.default'))->transaction(function () use($adjustment){ + + /* Get the last record for the client and set the current balance*/ + $client = Client::where('id', $this->client->id)->lockForUpdate()->first(); + $client->balance += $adjustment; + $client->save(); + + }, 1); $this->invoice->markInvitationsSent(); diff --git a/config/ninja.php b/config/ninja.php index 5cd221c4039e..10f6f4404b78 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.81', - 'app_tag' => '5.3.81', + 'app_version' => '5.3.82', + 'app_tag' => '5.3.82', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/database/migrations/2022_04_22_115838_client_settings_parse_for_types.php b/database/migrations/2022_04_22_115838_client_settings_parse_for_types.php new file mode 100644 index 000000000000..6612ff12a959 --- /dev/null +++ b/database/migrations/2022_04_22_115838_client_settings_parse_for_types.php @@ -0,0 +1,47 @@ +each( function ($client) { + $entity_settings = $this->checkSettingType($client->settings); + $entity_settings->md5 = md5(time()); + $client->settings = $entity_settings; + $client->save(); + + }); + + + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php index c794eddecf2c..99a10c3303b9 100644 --- a/resources/views/index/index.blade.php +++ b/resources/views/index/index.blade.php @@ -152,7 +152,6 @@ -
diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 5299cdbf8eec..7c4be819c05a 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -1426,7 +1426,7 @@ class PaymentTest extends TestCase $this->assertEquals(10, $this->invoice->balance); - $this->assertEquals(10, $this->invoice->client->balance); + $this->assertEquals(10, $this->invoice->client->fresh()->balance); $this->invoice->service()->markPaid()->save(); diff --git a/tests/Integration/CompanyLedgerTest.php b/tests/Integration/CompanyLedgerTest.php index 01d87f9fce9c..2a9a7f1788da 100644 --- a/tests/Integration/CompanyLedgerTest.php +++ b/tests/Integration/CompanyLedgerTest.php @@ -187,7 +187,7 @@ class CompanyLedgerTest extends TestCase $invoice_ledger = $invoice->company_ledger->sortByDesc('id')->first(); - $this->assertEquals($invoice_ledger->balance, $invoice->client->balance); + $this->assertEquals($invoice_ledger->balance, $this->client->balance); $this->assertEquals($invoice->client->paid_to_date, 0); /* Test adding another invoice */ @@ -203,10 +203,10 @@ class CompanyLedgerTest extends TestCase $invoice->service()->markSent()->save(); //client balance should = 20 - $this->assertEquals($invoice->client->balance, 20); + $this->assertEquals($this->client->fresh()->balance, 20); $invoice_ledger = $invoice->company_ledger->sortByDesc('id')->first(); - $this->assertEquals($invoice_ledger->balance, $invoice->client->balance); + $this->assertEquals($invoice_ledger->balance, $this->client->fresh()->balance); $this->assertEquals($invoice->client->paid_to_date, 0); /* Test making a payment */