Add Notification class to DocumentReminded event

This commit is contained in:
Burak Çakırel 2021-04-20 23:23:30 +03:00
parent 62d5442578
commit 96f9a99077
No known key found for this signature in database
GPG Key ID: 48FFBB7771B99C7C
3 changed files with 15 additions and 12 deletions

View File

@ -10,6 +10,7 @@ use App\Models\Banking\Transaction;
use App\Models\Common\Company; use App\Models\Common\Company;
use App\Models\Common\Recurring; use App\Models\Common\Recurring;
use App\Models\Document\Document; use App\Models\Document\Document;
use App\Notifications\Sale\Invoice as Notification;
use App\Utilities\Date; use App\Utilities\Date;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -122,6 +123,7 @@ class RecurringCheck extends Command
protected function recur($model, $type, $schedule_date) protected function recur($model, $type, $schedule_date)
{ {
\DB::transaction(function () use ($model, $type, $schedule_date) { \DB::transaction(function () use ($model, $type, $schedule_date) {
/** @var Document $clone */
if (!$clone = $this->getClone($model, $schedule_date)) { if (!$clone = $this->getClone($model, $schedule_date)) {
return; return;
} }
@ -130,7 +132,9 @@ class RecurringCheck extends Command
case 'App\Models\Document\Document': case 'App\Models\Document\Document':
event(new DocumentCreated($clone, request())); event(new DocumentCreated($clone, request()));
event(new DocumentRecurring($clone)); if ($clone->type === Document::INVOICE_TYPE) {
event(new DocumentRecurring($clone, Notification::class));
}
break; break;
case 'App\Models\Banking\Transaction': case 'App\Models\Banking\Transaction':

View File

@ -2,21 +2,20 @@
namespace App\Events\Document; 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 $document;
public $notification;
/** /**
* Create a new event instance. * 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;
} }
} }

View File

@ -3,7 +3,6 @@
namespace App\Listeners\Document; namespace App\Listeners\Document;
use App\Events\Document\DocumentRecurring as Event; use App\Events\Document\DocumentRecurring as Event;
use App\Notifications\Sale\Invoice as Notification;
class SendDocumentRecurringNotification class SendDocumentRecurringNotification
{ {
@ -16,10 +15,11 @@ class SendDocumentRecurringNotification
public function handle(Event $event) public function handle(Event $event)
{ {
$document = $event->document; $document = $event->document;
$notification = $event->notification;
// Notify the customer // Notify the customer
if ($document->contact && !empty($document->contact_email)) { 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 // Notify all users assigned to this company
@ -28,7 +28,7 @@ class SendDocumentRecurringNotification
continue; continue;
} }
$user->notify(new Notification($document, "{$document->type}_recur_admin")); $user->notify(new $notification($document, "{$document->type}_recur_admin"));
} }
} }
} }