diff --git a/app/Console/Commands/RecurringCheck.php b/app/Console/Commands/RecurringCheck.php index 16f6e83fe..e19e44d79 100644 --- a/app/Console/Commands/RecurringCheck.php +++ b/app/Console/Commands/RecurringCheck.php @@ -10,6 +10,8 @@ use App\Models\Banking\Transaction; use App\Models\Common\Company; use App\Models\Common\Recurring; use App\Models\Document\Document; +use App\Notifications\Purchase\Bill as BillNotification; +use App\Notifications\Sale\Invoice as InvoiceNotification; use App\Utilities\Date; use Illuminate\Console\Command; @@ -122,6 +124,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 +133,11 @@ 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, InvoiceNotification::class)); + } elseif ($clone->type === Document::BILL_TYPE) { + event(new DocumentRecurring($clone, BillNotification::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..885e40686 100644 --- a/app/Listeners/Document/SendDocumentRecurringNotification.php +++ b/app/Listeners/Document/SendDocumentRecurringNotification.php @@ -3,7 +3,7 @@ namespace App\Listeners\Document; use App\Events\Document\DocumentRecurring as Event; -use App\Notifications\Sale\Invoice as Notification; +use App\Models\Document\Document; class SendDocumentRecurringNotification { @@ -16,10 +16,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")); + if ($document->type === Document::INVOICE_TYPE && $document->contact && !empty($document->contact_email)) { + $document->contact->notify(new $notification($document, "{$document->type}_recur_customer")); } // Notify all users assigned to this company @@ -28,7 +29,7 @@ class SendDocumentRecurringNotification continue; } - $user->notify(new Notification($document, "{$document->type}_recur_admin")); + $user->notify(new $notification($document, "{$document->type}_recur_admin")); } } }