From 96f9a99077f9093f509ecf801ff9a2ebcd3a8bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87ak=C4=B1rel?= Date: Tue, 20 Apr 2021 23:23:30 +0300 Subject: [PATCH] Add Notification class to DocumentReminded event --- app/Console/Commands/RecurringCheck.php | 6 +++++- app/Events/Document/DocumentRecurring.php | 15 +++++++-------- .../SendDocumentRecurringNotification.php | 6 +++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/RecurringCheck.php b/app/Console/Commands/RecurringCheck.php index 16f6e83fe..d2644ca40 100644 --- a/app/Console/Commands/RecurringCheck.php +++ b/app/Console/Commands/RecurringCheck.php @@ -10,6 +10,7 @@ use App\Models\Banking\Transaction; use App\Models\Common\Company; use App\Models\Common\Recurring; use App\Models\Document\Document; +use App\Notifications\Sale\Invoice as Notification; use App\Utilities\Date; use Illuminate\Console\Command; @@ -122,6 +123,7 @@ class RecurringCheck extends Command protected function recur($model, $type, $schedule_date) { \DB::transaction(function () use ($model, $type, $schedule_date) { + /** @var Document $clone */ if (!$clone = $this->getClone($model, $schedule_date)) { return; } @@ -130,7 +132,9 @@ class RecurringCheck extends Command case 'App\Models\Document\Document': event(new DocumentCreated($clone, request())); - event(new DocumentRecurring($clone)); + if ($clone->type === Document::INVOICE_TYPE) { + event(new DocumentRecurring($clone, Notification::class)); + } break; case 'App\Models\Banking\Transaction': diff --git a/app/Events/Document/DocumentRecurring.php b/app/Events/Document/DocumentRecurring.php index 470bafa02..4fb5edf83 100644 --- a/app/Events/Document/DocumentRecurring.php +++ b/app/Events/Document/DocumentRecurring.php @@ -2,21 +2,20 @@ namespace App\Events\Document; -use Illuminate\Queue\SerializesModels; +use App\Abstracts\Event; +use App\Models\Document\Document; -class DocumentRecurring +class DocumentRecurring extends Event { - use SerializesModels; - public $document; + public $notification; /** * Create a new event instance. - * - * @param $document */ - public function __construct($document) + public function __construct(Document $document, string $notification) { - $this->document = $document; + $this->document = $document; + $this->notification = $notification; } } diff --git a/app/Listeners/Document/SendDocumentRecurringNotification.php b/app/Listeners/Document/SendDocumentRecurringNotification.php index 5dec8347e..77f3b5bf0 100644 --- a/app/Listeners/Document/SendDocumentRecurringNotification.php +++ b/app/Listeners/Document/SendDocumentRecurringNotification.php @@ -3,7 +3,6 @@ namespace App\Listeners\Document; use App\Events\Document\DocumentRecurring as Event; -use App\Notifications\Sale\Invoice as Notification; class SendDocumentRecurringNotification { @@ -16,10 +15,11 @@ class SendDocumentRecurringNotification public function handle(Event $event) { $document = $event->document; + $notification = $event->notification; // Notify the customer if ($document->contact && !empty($document->contact_email)) { - $document->contact->notify(new Notification($document, "{$document->type}_recur_customer")); + $document->contact->notify(new $notification($document, "{$document->type}_recur_customer")); } // Notify all users assigned to this company @@ -28,7 +28,7 @@ class SendDocumentRecurringNotification continue; } - $user->notify(new Notification($document, "{$document->type}_recur_admin")); + $user->notify(new $notification($document, "{$document->type}_recur_admin")); } } }