Trigger model created event manually after model calculations have been performed

This commit is contained in:
David Bomba 2021-10-10 20:56:05 +11:00
parent 0b84c86aed
commit 21d08d2d7e
6 changed files with 23 additions and 10 deletions

View File

@ -34,7 +34,6 @@ class InvoiceObserver
->where('event_id', Webhook::EVENT_CREATE_INVOICE)
->exists();
if ($subscriptions) {
$invoice->load('client');

View File

@ -29,8 +29,9 @@ class BaseRepository
use MakesHash;
use SavesDocuments;
public $import_mode = false;
public bool $import_mode = false;
private bool $new_model = false;
/**
* @param $entity
* @param $type
@ -207,9 +208,9 @@ class BaseRepository
$model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4;
if(!$model->id)
$model->save();
else
$model->saveQuietly();
$this->new_model = true;
$model->saveQuietly();
/* Model now persisted, now lets do some child tasks */
@ -323,6 +324,9 @@ class BaseRepository
//links tasks and expenses back to the invoice.
$model->service()->linkEntities()->save();
if($this->new_model)
event('eloquent.created: App\Models\Invoice', $model);
}
if ($model instanceof Credit) {
@ -331,7 +335,10 @@ class BaseRepository
if (! $model->design_id)
$model->design_id = $this->decodePrimaryKey($client->getSetting('credit_design_id'));
if($this->new_model)
event('eloquent.created: App\Models\Credit', $model);
}
if ($model instanceof Quote) {
@ -341,6 +348,10 @@ class BaseRepository
$model = $model->calc()->getQuote();
if($this->new_model)
event('eloquent.created: App\Models\Quote', $model);
}
if ($model instanceof RecurringInvoice) {
@ -350,6 +361,9 @@ class BaseRepository
$model = $model->calc()->getRecurringInvoice();
if($this->new_model)
event('eloquent.created: App\Models\RecurringInvoice', $model);
}
$model->save();

View File

@ -155,7 +155,7 @@ class CreditService
*/
public function save() : ?Credit
{
$this->credit->save();
$this->credit->saveQuietly();
return $this->credit;
}

View File

@ -490,7 +490,7 @@ class InvoiceService
*/
public function save() :?Invoice
{
$this->invoice->save();
$this->invoice->saveQuietly();
return $this->invoice;
}

View File

@ -202,7 +202,7 @@ class QuoteService
*/
public function save() : ?Quote
{
$this->quote->save();
$this->quote->saveQuietly();
return $this->quote;
}

View File

@ -105,7 +105,7 @@ class RecurringService
public function save()
{
$this->recurring_entity->save();
$this->recurring_entity->saveQuietly();
return $this->recurring_entity;
}