Add Notification class to DocumentReminded event

This commit is contained in:
Burak Çakırel 2020-12-25 22:30:59 +03:00
parent 2d023873cc
commit ec7511a8bc
No known key found for this signature in database
GPG Key ID: 48FFBB7771B99C7C
6 changed files with 22 additions and 11 deletions

View File

@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Events\Document\DocumentReminded; use App\Events\Document\DocumentReminded;
use App\Models\Common\Company; use App\Models\Common\Company;
use App\Models\Document\Document; use App\Models\Document\Document;
use App\Notifications\Purchase\Bill as Notification;
use App\Utilities\Overrider; use App\Utilities\Overrider;
use Date; use Date;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -84,7 +85,7 @@ class BillReminder extends Command
foreach ($bills as $bill) { foreach ($bills as $bill) {
try { try {
event(new DocumentReminded($bill)); event(new DocumentReminded($bill, Notification::class));
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) { } catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
$this->error($e->getMessage()); $this->error($e->getMessage());

View File

@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Events\Document\DocumentReminded; use App\Events\Document\DocumentReminded;
use App\Models\Common\Company; use App\Models\Common\Company;
use App\Models\Document\Document; use App\Models\Document\Document;
use App\Notifications\Sale\Invoice as Notification;
use App\Utilities\Overrider; use App\Utilities\Overrider;
use Date; use Date;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -84,7 +85,7 @@ class InvoiceReminder extends Command
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
try { try {
event(new DocumentReminded($invoice)); event(new DocumentReminded($invoice, Notification::class));
} catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) { } catch (\Exception | \Throwable | \Swift_RfcComplianceException | \Illuminate\Database\QueryException $e) {
$this->error($e->getMessage()); $this->error($e->getMessage());

View File

@ -3,18 +3,22 @@
namespace App\Events\Document; namespace App\Events\Document;
use App\Abstracts\Event; use App\Abstracts\Event;
use App\Models\Document\Document;
class DocumentReminded extends Event class DocumentReminded extends Event
{ {
public $document; public $document;
public $notification;
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @param $document * @param $document
* @param $notification
*/ */
public function __construct($document) public function __construct(Document $document, string $notification)
{ {
$this->document = $document; $this->document = $document;
$this->notification = $notification;
} }
} }

View File

@ -3,9 +3,6 @@
namespace App\Listeners\Document; namespace App\Listeners\Document;
use App\Events\Document\DocumentReminded as Event; 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 class SendDocumentReminderNotification
{ {
@ -18,11 +15,7 @@ class SendDocumentReminderNotification
public function handle(Event $event) public function handle(Event $event)
{ {
$document = $event->document; $document = $event->document;
$notification = $event->notification;
$notification = InvoiceNotification::class;
if ($document->type === Document::BILL_TYPE) {
$notification = BillNotification::class;
}
// Notify the customer // Notify the customer
if ($document->contact && !empty($document->contact_email)) { if ($document->contact && !empty($document->contact_email)) {

View File

@ -3,6 +3,8 @@
namespace App\Events\Purchase; namespace App\Events\Purchase;
use App\Events\Document\DocumentReminded; use App\Events\Document\DocumentReminded;
use App\Models\Document\Document;
use App\Notifications\Purchase\Bill as Notification;
/** /**
* @deprecated * @deprecated
@ -10,4 +12,8 @@ use App\Events\Document\DocumentReminded;
*/ */
class BillReminded extends DocumentReminded class BillReminded extends DocumentReminded
{ {
public function __construct(Document $document)
{
parent::__construct($document, Notification::class);
}
} }

View File

@ -3,6 +3,8 @@
namespace App\Events\Sale; namespace App\Events\Sale;
use App\Events\Document\DocumentReminded; use App\Events\Document\DocumentReminded;
use App\Models\Document\Document;
use App\Notifications\Sale\Invoice as Notification;
/** /**
* @deprecated * @deprecated
@ -10,4 +12,8 @@ use App\Events\Document\DocumentReminded;
*/ */
class InvoiceReminded extends DocumentReminded class InvoiceReminded extends DocumentReminded
{ {
public function __construct(Document $document)
{
parent::__construct($document, Notification::class);
}
} }