Merge pull request #6786 from turbo124/v5-develop

Fixes for Invoice Observer
This commit is contained in:
David Bomba 2021-10-07 17:37:13 +11:00 committed by GitHub
commit eb26f647a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View File

@ -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],

View File

@ -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);
}
}

View File

@ -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 */