From ec7511a8bc94624046190df0d543fca6b9f9797d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87ak=C4=B1rel?= Date: Fri, 25 Dec 2020 22:30:59 +0300 Subject: [PATCH] Add Notification class to DocumentReminded event --- app/Console/Commands/BillReminder.php | 3 ++- app/Console/Commands/InvoiceReminder.php | 3 ++- app/Events/Document/DocumentReminded.php | 6 +++++- .../Document/SendDocumentReminderNotification.php | 9 +-------- modules/BC21/Events/Purchase/BillReminded.php | 6 ++++++ modules/BC21/Events/Sale/InvoiceReminded.php | 6 ++++++ 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/BillReminder.php b/app/Console/Commands/BillReminder.php index e3b909143..5062daf11 100644 --- a/app/Console/Commands/BillReminder.php +++ b/app/Console/Commands/BillReminder.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Events\Document\DocumentReminded; use App\Models\Common\Company; use App\Models\Document\Document; +use App\Notifications\Purchase\Bill as Notification; use App\Utilities\Overrider; use Date; use Illuminate\Console\Command; @@ -84,7 +85,7 @@ class BillReminder extends Command foreach ($bills as $bill) { try { - event(new DocumentReminded($bill)); + event(new DocumentReminded($bill, Notification::class)); } catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) { $this->error($e->getMessage()); diff --git a/app/Console/Commands/InvoiceReminder.php b/app/Console/Commands/InvoiceReminder.php index 1e8e83773..7874e5bdb 100644 --- a/app/Console/Commands/InvoiceReminder.php +++ b/app/Console/Commands/InvoiceReminder.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use App\Events\Document\DocumentReminded; use App\Models\Common\Company; use App\Models\Document\Document; +use App\Notifications\Sale\Invoice as Notification; use App\Utilities\Overrider; use Date; use Illuminate\Console\Command; @@ -84,7 +85,7 @@ class InvoiceReminder extends Command foreach ($invoices as $invoice) { try { - event(new DocumentReminded($invoice)); + event(new DocumentReminded($invoice, Notification::class)); } catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) { $this->error($e->getMessage()); diff --git a/app/Events/Document/DocumentReminded.php b/app/Events/Document/DocumentReminded.php index 3adb13561..65a819b20 100644 --- a/app/Events/Document/DocumentReminded.php +++ b/app/Events/Document/DocumentReminded.php @@ -3,18 +3,22 @@ namespace App\Events\Document; use App\Abstracts\Event; +use App\Models\Document\Document; class DocumentReminded extends Event { public $document; + public $notification; /** * Create a new event instance. * * @param $document + * @param $notification */ - public function __construct($document) + public function __construct(Document $document, string $notification) { $this->document = $document; + $this->notification = $notification; } } diff --git a/app/Listeners/Document/SendDocumentReminderNotification.php b/app/Listeners/Document/SendDocumentReminderNotification.php index 801ba1ef4..0392eb3b3 100644 --- a/app/Listeners/Document/SendDocumentReminderNotification.php +++ b/app/Listeners/Document/SendDocumentReminderNotification.php @@ -3,9 +3,6 @@ namespace App\Listeners\Document; use App\Events\Document\DocumentReminded as Event; -use App\Models\Document\Document; -use App\Notifications\Sale\Invoice as InvoiceNotification; -use App\Notifications\Purchase\Bill as BillNotification; class SendDocumentReminderNotification { @@ -18,11 +15,7 @@ class SendDocumentReminderNotification public function handle(Event $event) { $document = $event->document; - - $notification = InvoiceNotification::class; - if ($document->type === Document::BILL_TYPE) { - $notification = BillNotification::class; - } + $notification = $event->notification; // Notify the customer if ($document->contact && !empty($document->contact_email)) { diff --git a/modules/BC21/Events/Purchase/BillReminded.php b/modules/BC21/Events/Purchase/BillReminded.php index b6e165d4c..0e611e5da 100644 --- a/modules/BC21/Events/Purchase/BillReminded.php +++ b/modules/BC21/Events/Purchase/BillReminded.php @@ -3,6 +3,8 @@ namespace App\Events\Purchase; use App\Events\Document\DocumentReminded; +use App\Models\Document\Document; +use App\Notifications\Purchase\Bill as Notification; /** * @deprecated @@ -10,4 +12,8 @@ use App\Events\Document\DocumentReminded; */ class BillReminded extends DocumentReminded { + public function __construct(Document $document) + { + parent::__construct($document, Notification::class); + } } diff --git a/modules/BC21/Events/Sale/InvoiceReminded.php b/modules/BC21/Events/Sale/InvoiceReminded.php index 16ded3e36..45fd1f770 100644 --- a/modules/BC21/Events/Sale/InvoiceReminded.php +++ b/modules/BC21/Events/Sale/InvoiceReminded.php @@ -3,6 +3,8 @@ namespace App\Events\Sale; use App\Events\Document\DocumentReminded; +use App\Models\Document\Document; +use App\Notifications\Sale\Invoice as Notification; /** * @deprecated @@ -10,4 +12,8 @@ use App\Events\Document\DocumentReminded; */ class InvoiceReminded extends DocumentReminded { + public function __construct(Document $document) + { + parent::__construct($document, Notification::class); + } }