From d9047b413a97b4475e1726da5821a962e8ecccdb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 07:36:20 +1000 Subject: [PATCH 1/4] Disable product price updating if currencies do not match --- app/Jobs/Product/UpdateOrCreateProduct.php | 3 ++ tests/Unit/CompanySettingsTest.php | 32 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php index 156159791934..b5149e6b84cd 100644 --- a/app/Jobs/Product/UpdateOrCreateProduct.php +++ b/app/Jobs/Product/UpdateOrCreateProduct.php @@ -55,6 +55,9 @@ class UpdateOrCreateProduct implements ShouldQueue { MultiDB::setDB($this->company->db); + if(strval($this->invoice->client->getSetting('currency_id')) != strval($this->company->settings->currency_id)) + return; + /* * If the invoice was generated from a Task or Expense then * we do NOT update the product details this short block we diff --git a/tests/Unit/CompanySettingsTest.php b/tests/Unit/CompanySettingsTest.php index fca71d397064..de748e2f2839 100644 --- a/tests/Unit/CompanySettingsTest.php +++ b/tests/Unit/CompanySettingsTest.php @@ -55,4 +55,36 @@ class CompanySettingsTest extends TestCase $this->assertEquals(1, count($diff)); } + + public function testStringEquivalence() + { + + $value = (strval(4) != strval(3)); + + $this->assertTrue($value); + + $value = (strval(4) != strval(4)); + + $this->assertFalse($value); + + $value = (strval('4') != strval(4)); + $this->assertFalse($value); + + $value = (strval('4') != strval('4')); + + $this->assertFalse($value); + + $value = (strval('4') != strval(3)); + + $this->assertTrue($value); + + $value = (strval(4) != strval('3')); + + $this->assertTrue($value); + + $value = (strval('4') != strval('3')); + + $this->assertTrue($value); + + } } From 40335c0d926b2b9fda4619a0e09ae82ff41b3c98 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 07:41:51 +1000 Subject: [PATCH 2/4] Add rest method and headers to webhooks --- app/Factory/WebhookFactory.php | 4 ++- app/Models/Webhook.php | 6 ++++ ...3802_add_rest_fields_to_webhooks_table.php | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2021_04_05_213802_add_rest_fields_to_webhooks_table.php diff --git a/app/Factory/WebhookFactory.php b/app/Factory/WebhookFactory.php index 045ed87cb258..bced2b321690 100644 --- a/app/Factory/WebhookFactory.php +++ b/app/Factory/WebhookFactory.php @@ -23,7 +23,9 @@ class WebhookFactory $webhook->target_url = ''; $webhook->event_id = 1; $webhook->format = 'JSON'; - + $webhook->rest_method = 'post'; + $webhook->headers = []; + return $webhook; } } diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php index 8684fd757459..1540f87f6604 100644 --- a/app/Models/Webhook.php +++ b/app/Models/Webhook.php @@ -57,6 +57,12 @@ class Webhook extends BaseModel 'target_url', 'format', 'event_id', + 'rest_method', + 'headers', + ]; + + protected $casts = [ + 'headers' => 'array', ]; public function user() diff --git a/database/migrations/2021_04_05_213802_add_rest_fields_to_webhooks_table.php b/database/migrations/2021_04_05_213802_add_rest_fields_to_webhooks_table.php new file mode 100644 index 000000000000..ca43f4c01af0 --- /dev/null +++ b/database/migrations/2021_04_05_213802_add_rest_fields_to_webhooks_table.php @@ -0,0 +1,33 @@ +text('rest_method')->nullable(); + $table->text('headers')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('webhooks', function (Blueprint $table) { + // + }); + } +} From b1e6325ef8f226f20716e0b54a345eaaf3d73ae5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 08:19:27 +1000 Subject: [PATCH 3/4] Fixes for tests --- app/Http/Requests/Subscription/StoreSubscriptionRequest.php | 5 ++++- app/Http/Requests/Subscription/UpdateSubscriptionRequest.php | 5 ++++- app/Jobs/Util/Import.php | 2 ++ app/Listeners/Invoice/InvoiceArchivedActivity.php | 2 ++ app/Models/Webhook.php | 3 +++ app/Services/Payment/UpdateInvoicePayment.php | 1 + app/Transformers/WebhookTransformer.php | 2 ++ 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/Subscription/StoreSubscriptionRequest.php b/app/Http/Requests/Subscription/StoreSubscriptionRequest.php index 84bdc274b6b2..f79ed33f7d7e 100644 --- a/app/Http/Requests/Subscription/StoreSubscriptionRequest.php +++ b/app/Http/Requests/Subscription/StoreSubscriptionRequest.php @@ -34,7 +34,7 @@ class StoreSubscriptionRequest extends Request */ public function rules() { - return [ + $rules = [ 'product_id' => ['sometimes'], 'assigned_user_id' => ['sometimes'], 'is_recurring' => ['sometimes'], @@ -55,6 +55,9 @@ class StoreSubscriptionRequest extends Request 'webhook_configuration' => ['array'], 'name' => ['required', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)] ]; + + return $this->globalRules($rules); + } protected function prepareForValidation() diff --git a/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php b/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php index 4b7a0c4bbe46..c2e5ba47b72f 100644 --- a/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php +++ b/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php @@ -35,8 +35,11 @@ class UpdateSubscriptionRequest extends Request */ public function rules() { - return [ + $rules = [ // ]; + + return $this->globalRules($rules); + } } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 6a06eac4446a..09ddb6b159f7 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -227,6 +227,8 @@ class Import implements ShouldQueue CompanySizeCheck::dispatch(); info('CompletedπŸš€πŸš€πŸš€πŸš€πŸš€ at '.now()); + + unlink($this->file_path); } private function setInitialCompanyLedgerBalances() diff --git a/app/Listeners/Invoice/InvoiceArchivedActivity.php b/app/Listeners/Invoice/InvoiceArchivedActivity.php index 7fd3672b8825..cbb175904773 100644 --- a/app/Listeners/Invoice/InvoiceArchivedActivity.php +++ b/app/Listeners/Invoice/InvoiceArchivedActivity.php @@ -41,6 +41,8 @@ class InvoiceArchivedActivity implements ShouldQueue { MultiDB::setDb($event->company->db); + $event->invoice->service()->deletePdf(); + $fields = new stdClass; $fields->invoice_id = $event->invoice->id; diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php index 1540f87f6604..1372bf03e92c 100644 --- a/app/Models/Webhook.php +++ b/app/Models/Webhook.php @@ -63,6 +63,9 @@ class Webhook extends BaseModel protected $casts = [ 'headers' => 'array', + 'updated_at' => 'timestamp', + 'created_at' => 'timestamp', + 'deleted_at' => 'timestamp', ]; public function user() diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index d2fc2eefed5c..0af4a1e4311c 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -82,6 +82,7 @@ class UpdateInvoicePayment ->updateBalance($paid_amount * -1) ->updatePaidToDate($paid_amount) ->updateStatus() + ->deletePdf() ->save(); InvoiceWorkflowSettings::dispatchNow($invoice); diff --git a/app/Transformers/WebhookTransformer.php b/app/Transformers/WebhookTransformer.php index 8c4f62884ca9..b67686600261 100644 --- a/app/Transformers/WebhookTransformer.php +++ b/app/Transformers/WebhookTransformer.php @@ -34,6 +34,8 @@ class WebhookTransformer extends EntityTransformer 'target_url' => $webhook->target_url ? (string) $webhook->target_url : '', 'event_id' => (string) $webhook->event_id, 'format' => (string) $webhook->format, + 'rest_method' => (string) $webhook->rest_method ?: '', + 'headers' => $webhook->headers ?: [], ]; } } From 9cb8e865fc47495bed70c83ec3172f4bc19ddd5b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 08:21:55 +1000 Subject: [PATCH 4/4] Fixes for assigned_user_id and group_id not sticking to subscriptions --- .../Requests/Subscription/StoreSubscriptionRequest.php | 2 ++ .../Requests/Subscription/UpdateSubscriptionRequest.php | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/app/Http/Requests/Subscription/StoreSubscriptionRequest.php b/app/Http/Requests/Subscription/StoreSubscriptionRequest.php index f79ed33f7d7e..7e9622f30c89 100644 --- a/app/Http/Requests/Subscription/StoreSubscriptionRequest.php +++ b/app/Http/Requests/Subscription/StoreSubscriptionRequest.php @@ -64,6 +64,8 @@ class StoreSubscriptionRequest extends Request { $input = $this->all(); + $input = $this->decodePrimaryKeys($input); + $this->replace($input); } } diff --git a/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php b/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php index c2e5ba47b72f..bd5e45aebe43 100644 --- a/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php +++ b/app/Http/Requests/Subscription/UpdateSubscriptionRequest.php @@ -42,4 +42,13 @@ class UpdateSubscriptionRequest extends Request return $this->globalRules($rules); } + + protected function prepareForValidation() + { + $input = $this->all(); + + $input = $this->decodePrimaryKeys($input); + + $this->replace($input); + } }