From 20bfc999d0e4bf676ea65a31c352564d49082b02 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 7 Oct 2021 14:33:43 +1100 Subject: [PATCH 1/2] Fixes for Company Import --- app/Jobs/Company/CompanyImport.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 2898617112cc..234040ea9f32 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -1331,6 +1331,12 @@ class CompanyImport implements ShouldQueue $new_obj->save(['timestamps' => false]); $new_obj->number = $this->getNextQuoteNumber($client = Client::find($obj_array['client_id']), $new_obj); } + elseif($class == 'App\Models\ClientContact'){ + $new_obj = new ClientContact(); + $new_obj->company_id = $this->company->id; + $new_obj->fill($obj_array); + $new_obj->save(['timestamps' => false]); + } else{ $new_obj = $class::firstOrNew( [$match_key => $obj->{$match_key}, 'company_id' => $this->company->id], From 40a90c4ea84e80309ee95d5e518ed46cd83ce46f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 7 Oct 2021 17:34:23 +1100 Subject: [PATCH 2/2] Fixes for invoice observer --- app/Observers/InvoiceObserver.php | 12 ++++++++++-- app/Repositories/BaseRepository.php | 9 ++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index c7da824f246d..6fdb6ee82907 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -34,9 +34,11 @@ class InvoiceObserver ->where('event_id', Webhook::EVENT_CREATE_INVOICE) ->exists(); - $invoice->load('client'); if ($subscriptions) { + + $invoice->load('client'); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company); } } @@ -53,11 +55,14 @@ class InvoiceObserver ->where('event_id', Webhook::EVENT_UPDATE_INVOICE) ->exists(); - $invoice->load('client'); if ($subscriptions) { + + $invoice->load('client'); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company); + } } @@ -75,6 +80,9 @@ class InvoiceObserver ->exists(); if ($subscriptions) { + + $invoice->load('client'); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company); } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index b828ff1ba150..9f0eece3a67f 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -174,10 +174,6 @@ class BaseRepository if(array_key_exists('client_id', $data)) $model->client_id = $data['client_id']; - //pickup changes here to recalculate reminders - //if($model instanceof Invoice && ($model->isDirty('date') || $model->isDirty('due_date'))) - // $model->service()->setReminder()->save(); - $client = Client::where('id', $model->client_id)->withTrashed()->first(); $state = []; @@ -210,7 +206,10 @@ class BaseRepository $model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3; $model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4; - $model->saveQuietly(); + if(!$model->id) + $model->save(); + else + $model->saveQuietly(); /* Model now persisted, now lets do some child tasks */