Add Notification class to DocumentReminded event
This commit is contained in:
parent
62d5442578
commit
96f9a99077
@ -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':
|
||||
|
@ -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->notification = $notification;
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user