diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index da45f65a7ca8..c48f426567fc 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -203,7 +203,7 @@ class InvoiceSum { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -211,7 +211,7 @@ class InvoiceSum public function getQuote() { $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -219,7 +219,7 @@ class InvoiceSum public function getCredit() { $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -230,7 +230,7 @@ class InvoiceSum $this->invoice->total_taxes = $this->getTotalTaxes(); $this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index 49a0b5593da5..fe0b26268be5 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -191,7 +191,7 @@ class InvoiceSumInclusive $this->invoice->total_taxes = $this->getTotalTaxes(); $this->invoice->balance = $this->formatValue($this->getTotal(), $this->invoice->client->currency()->precision); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -206,7 +206,7 @@ class InvoiceSumInclusive { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -215,7 +215,7 @@ class InvoiceSumInclusive { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -224,7 +224,7 @@ class InvoiceSumInclusive { //Build invoice values here and return Invoice $this->setCalculatedAttributes(); - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index f88a07ccabae..03bbe94cfffd 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -208,7 +208,7 @@ class RecurringInvoiceController extends BaseController $offset = $recurring_invoice->client->timezone_offset(); $recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset); - $recurring_invoice->save(); + $recurring_invoice->saveQuietly(); $recurring_invoice->service() ->triggeredActions($request) diff --git a/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php b/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php index dfcd3d771730..3c6424c46c1f 100644 --- a/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php +++ b/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php @@ -23,7 +23,7 @@ class UpdateAutoBilling extends Component { if ($this->invoice->auto_bill == 'optin' || $this->invoice->auto_bill == 'optout') { $this->invoice->auto_bill_enabled = !$this->invoice->auto_bill_enabled; - $this->invoice->save(); + $this->invoice->saveQuietly(); } } diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 37f42a2fa149..e973568c3635 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -102,7 +102,7 @@ class CreateEntityPdf implements ShouldQueue public function handle() { $start = microtime(true); - nlog("Start ". $start); + // nlog("Start ". $start); /* Forget the singleton*/ App::forgetInstance('translator'); @@ -154,7 +154,7 @@ class CreateEntityPdf implements ShouldQueue $html = new HtmlEngine($this->invitation); $design_time = microtime(true); - nlog("Design ". $design_time - $translate); + // nlog("Design ". $design_time - $translate); if ($design->is_custom) { $options = [ @@ -168,7 +168,7 @@ class CreateEntityPdf implements ShouldQueue $variables = $html->generateLabelsAndValues(); $labels_time = microtime(true); - nlog("Labels ". $labels_time - $design_time); + // nlog("Labels ". $labels_time - $design_time); $state = [ 'template' => $template->elements([ @@ -194,7 +194,7 @@ class CreateEntityPdf implements ShouldQueue $template_time = microtime(true); - nlog("Template Build ". $template_time - $labels_time); + // nlog("Template Build ". $template_time - $labels_time); $pdf = null; @@ -217,7 +217,7 @@ class CreateEntityPdf implements ShouldQueue $pdf_time = microtime(true); - nlog("PDF time " . $pdf_time - $template_time); + // nlog("PDF time " . $pdf_time - $template_time); if ($pdf) { diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 5b5a72019b7f..38cafd03bb4c 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -43,18 +43,19 @@ class WebhookHandler implements ShouldQueue public $deleteWhenMissingModels = true; - + private string $includes; /** * Create a new job instance. * * @param $event_id * @param $entity */ - public function __construct($event_id, $entity, $company) + public function __construct($event_id, $entity, $company, $includes = '') { $this->event_id = $event_id; $this->entity = $entity; $this->company = $company; + $this->includes = $includes; } /** @@ -90,6 +91,7 @@ class WebhookHandler implements ShouldQueue // generate JSON data $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); + $manager->parseIncludes($this->includes); $class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity)); diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index f58e1018f26a..d38e1509edfb 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -35,10 +35,8 @@ class InvoiceObserver ->exists(); if ($subscriptions) { - - $invoice->load('client'); - WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company, 'client'); } } @@ -50,17 +48,14 @@ class InvoiceObserver */ public function updated(Invoice $invoice) { + $subscriptions = Webhook::where('company_id', $invoice->company_id) ->where('event_id', Webhook::EVENT_UPDATE_INVOICE) ->exists(); - - if ($subscriptions) { - - $invoice->load('client'); - - WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company); + + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company, 'client'); } @@ -80,9 +75,7 @@ class InvoiceObserver if ($subscriptions) { - $invoice->load('client'); - - WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company, 'client'); } } diff --git a/app/Observers/PaymentObserver.php b/app/Observers/PaymentObserver.php index 976d261c3e1c..ad2a6f7b8215 100644 --- a/app/Observers/PaymentObserver.php +++ b/app/Observers/PaymentObserver.php @@ -29,11 +29,8 @@ class PaymentObserver ->where('event_id', Webhook::EVENT_CREATE_PAYMENT) ->exists(); - if($payment->invoices()->exists()) - $payment->load('invoices'); - if ($subscriptions) { - WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company, 'invoices'); } } @@ -60,7 +57,7 @@ class PaymentObserver ->exists(); if ($subscriptions) { - WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company, 'invoices'); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ca9b7e809930..495ed33f2242 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,36 +12,8 @@ namespace App\Providers; use App\Http\Middleware\SetDomainNameDb; -use App\Models\Account; -use App\Models\Client; -use App\Models\Company; -use App\Models\CompanyGateway; -use App\Models\CompanyToken; -use App\Models\Credit; -use App\Models\Expense; use App\Models\Invoice; -use App\Models\Payment; -use App\Models\Product; use App\Models\Proposal; -use App\Models\Quote; -use App\Models\Subscription; -use App\Models\Task; -use App\Models\User; -use App\Observers\AccountObserver; -use App\Observers\ClientObserver; -use App\Observers\CompanyGatewayObserver; -use App\Observers\CompanyObserver; -use App\Observers\CompanyTokenObserver; -use App\Observers\CreditObserver; -use App\Observers\ExpenseObserver; -use App\Observers\InvoiceObserver; -use App\Observers\PaymentObserver; -use App\Observers\ProductObserver; -use App\Observers\ProposalObserver; -use App\Observers\QuoteObserver; -use App\Observers\SubscriptionObserver; -use App\Observers\TaskObserver; -use App\Observers\UserObserver; use App\Utils\Ninja; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Database\Eloquent\Relations\Relation; @@ -80,23 +52,6 @@ class AppServiceProvider extends ServiceProvider Schema::defaultStringLength(191); - Account::observe(AccountObserver::class); - Subscription::observe(SubscriptionObserver::class); - Client::observe(ClientObserver::class); - Company::observe(CompanyObserver::class); - CompanyGateway::observe(CompanyGatewayObserver::class); - CompanyToken::observe(CompanyTokenObserver::class); - Credit::observe(CreditObserver::class); - Expense::observe(ExpenseObserver::class); - Invoice::observe(InvoiceObserver::class); - Payment::observe(PaymentObserver::class); - Product::observe(ProductObserver::class); - Proposal::observe(ProposalObserver::class); - Quote::observe(QuoteObserver::class); - Task::observe(TaskObserver::class); - User::observe(UserObserver::class); - - /* Handles setting the correct database with livewire classes */ if(Ninja::isHosted()) { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index cee0ce7eaa40..52b15e64ba81 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -202,6 +202,36 @@ use App\Listeners\User\DeletedUserActivity; use App\Listeners\User\RestoredUserActivity; use App\Listeners\User\UpdateUserLastLogin; use App\Listeners\User\UpdatedUserActivity; +use App\Models\Account; +use App\Models\Client; +use App\Models\Company; +use App\Models\CompanyGateway; +use App\Models\CompanyToken; +use App\Models\Credit; +use App\Models\Expense; +use App\Models\Invoice; +use App\Models\Payment; +use App\Models\Product; +use App\Models\Proposal; +use App\Models\Quote; +use App\Models\Subscription; +use App\Models\Task; +use App\Models\User; +use App\Observers\AccountObserver; +use App\Observers\ClientObserver; +use App\Observers\CompanyGatewayObserver; +use App\Observers\CompanyObserver; +use App\Observers\CompanyTokenObserver; +use App\Observers\CreditObserver; +use App\Observers\ExpenseObserver; +use App\Observers\InvoiceObserver; +use App\Observers\PaymentObserver; +use App\Observers\ProductObserver; +use App\Observers\ProposalObserver; +use App\Observers\QuoteObserver; +use App\Observers\SubscriptionObserver; +use App\Observers\TaskObserver; +use App\Observers\UserObserver; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Mail\Events\MessageSending; use Illuminate\Mail\Events\MessageSent; @@ -542,5 +572,21 @@ class EventServiceProvider extends ServiceProvider public function boot() { parent::boot(); + + Account::observe(AccountObserver::class); + Subscription::observe(SubscriptionObserver::class); + Client::observe(ClientObserver::class); + Company::observe(CompanyObserver::class); + CompanyGateway::observe(CompanyGatewayObserver::class); + CompanyToken::observe(CompanyTokenObserver::class); + Credit::observe(CreditObserver::class); + Expense::observe(ExpenseObserver::class); + Invoice::observe(InvoiceObserver::class); + Payment::observe(PaymentObserver::class); + Product::observe(ProductObserver::class); + Proposal::observe(ProposalObserver::class); + Quote::observe(QuoteObserver::class); + Task::observe(TaskObserver::class); + User::observe(UserObserver::class); } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index b4e11a655cdf..c6120c281ad2 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -326,6 +326,8 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\Invoice', $model); + else + event('eloquent.updated: App\Models\Invoice', $model); } @@ -339,6 +341,9 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\Credit', $model); + else + event('eloquent.updated: App\Models\Credit', $model); + } if ($model instanceof Quote) { @@ -351,7 +356,8 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\Quote', $model); - + else + event('eloquent.updated: App\Models\Quote', $model); } if ($model instanceof RecurringInvoice) { @@ -364,6 +370,8 @@ class BaseRepository if($this->new_model) event('eloquent.created: App\Models\RecurringInvoice', $model); + else + event('eloquent.updated: App\Models\RecurringInvoice', $model); } $model->save(); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 5bbb7352c4b4..7b6bef89196b 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -356,9 +356,9 @@ class AutoBillInvoice extends AbstractService $items[] = $item; $this->invoice->line_items = $items; - $this->invoice->save(); + $this->invoice->saveQuietly(); - $this->invoice = $this->invoice->calc()->getInvoice()->save(); + $this->invoice = $this->invoice->calc()->getInvoice()->saveQuietly(); if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) { $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save(); diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index 872697666bb8..e380d69f7549 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -75,7 +75,7 @@ class HandleCancellation extends AbstractService $backup = $this->invoice->backup; unset($backup->cancellation); $this->invoice->backup = $backup; - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; } @@ -101,6 +101,6 @@ class HandleCancellation extends AbstractService $invoice_backup->cancellation = $cancellation; $this->invoice->backup = $invoice_backup; - $this->invoice->save(); + $this->invoice->saveQuietly(); } } diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index e1615b3ab16f..14216f2751f1 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -129,7 +129,7 @@ nlog("second payment_amount = {$payment_amount}"); else $this->invoice->number = $new_invoice_number; - $this->invoice->save(); + $this->invoice->saveQuietly(); } catch (\Exception $e) { nlog("I could not wind back the invoice number"); diff --git a/app/Services/Invoice/UpdateReminder.php b/app/Services/Invoice/UpdateReminder.php index e693da6f6d21..01c9ba30549a 100644 --- a/app/Services/Invoice/UpdateReminder.php +++ b/app/Services/Invoice/UpdateReminder.php @@ -37,7 +37,7 @@ class UpdateReminder extends AbstractService if (! $this->invoice->isPayable()) { $this->invoice->next_send_date = null; - $this->invoice->save(); + $this->invoice->saveQuietly(); return $this->invoice; //exit early } diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index 6d9f8a76e1eb..2b44eae951e8 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -250,7 +250,7 @@ class RefundPayment $invoice->service()->setStatus(Invoice::STATUS_PARTIAL); } - $invoice->save(); + $invoice->saveQuietly(); $client = $invoice->client;