From f0c6df6c4a83ec7fb395472b5e13ade484185eb2 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Tue, 7 Feb 2023 15:46:52 +0100 Subject: [PATCH] Minor fixes --- app/Models/BaseModel.php | 2 +- app/Services/Credit/MarkSent.php | 8 +------- app/Services/PurchaseOrder/MarkSent.php | 7 +------ app/Services/Quote/MarkSent.php | 7 +------ 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index abed950b7cf8..988928722164 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -206,7 +206,7 @@ class BaseModel extends Model return ctrans('texts.item'); } - public function sendEvent($event_id, $additional_data){ + public function sendEvent($event_id, $additional_data=""){ $subscriptions = Webhook::where('company_id', $this->company_id) ->where('event_id', $event_id) ->exists(); diff --git a/app/Services/Credit/MarkSent.php b/app/Services/Credit/MarkSent.php index 32766372b261..d8ad848dbc70 100644 --- a/app/Services/Credit/MarkSent.php +++ b/app/Services/Credit/MarkSent.php @@ -54,13 +54,7 @@ class MarkSent event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - $subscriptions = Webhook::where('company_id', $this->credit->company_id) - ->where('event_id', Webhook::EVENT_SENT_CREDIT) - ->exists(); - - if ($subscriptions) { - WebhookHandler::dispatch(Webhook::EVENT_SENT_CREDIT, $this->credit, $this->credit->company)->delay(0); - } + $this->credit->sendEvent(Webhook::EVENT_SENT_CREDIT); return $this->credit; } diff --git a/app/Services/PurchaseOrder/MarkSent.php b/app/Services/PurchaseOrder/MarkSent.php index 63c3477aaa47..a81d91b45433 100644 --- a/app/Services/PurchaseOrder/MarkSent.php +++ b/app/Services/PurchaseOrder/MarkSent.php @@ -45,12 +45,7 @@ class MarkSent ->adjustBalance($this->purchase_order->amount) //why was this commented out previously? ->save(); - $subscriptions = Webhook::where('company_id', $this->purchase_order->company_id) - ->where('event_id', Webhook::EVENT_SENT_PURCHASE_ORDER) - ->exists(); - - if ($subscriptions) - WebhookHandler::dispatch(Webhook::EVENT_SENT_PURCHASE_ORDER, $this->purchase_order, $this->purchase_order->company, 'vendor')->delay(0); + $this->purchase_order->sendEvent(Webhook::EVENT_SENT_PURCHASE_ORDER, "vendor"); return $this->purchase_order; } diff --git a/app/Services/Quote/MarkSent.php b/app/Services/Quote/MarkSent.php index 9b4ba391c059..76a4687db885 100644 --- a/app/Services/Quote/MarkSent.php +++ b/app/Services/Quote/MarkSent.php @@ -54,12 +54,7 @@ class MarkSent event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - $subscriptions = Webhook::where('company_id', $this->quote->company_id) - ->where('event_id', Webhook::EVENT_SENT_QUOTE) - ->exists(); - - if ($subscriptions) - WebhookHandler::dispatch(Webhook::EVENT_SENT_QUOTE, $this->quote, $this->quote->company, 'client')->delay(0); + $this->quote->sendEvent(Webhook::EVENT_SENT_QUOTE, "client"); return $this->quote; }