Merge pull request #1409 from SevanNerse/dev-reminder
invoice and bill reminder is moved console command to listeners
This commit is contained in:
commit
022b36e460
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\Purchase\BillReminded;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Notifications\Purchase\Bill as Notification;
|
||||
use App\Utilities\Overrider;
|
||||
use Date;
|
||||
use Illuminate\Console\Command;
|
||||
@ -60,7 +60,7 @@ class BillReminder extends Command
|
||||
foreach ($days as $day) {
|
||||
$day = (int) trim($day);
|
||||
|
||||
$this->remind($day, $company);
|
||||
$this->remind($day);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ class BillReminder extends Command
|
||||
setting()->forgetAll();
|
||||
}
|
||||
|
||||
protected function remind($day, $company)
|
||||
protected function remind($day)
|
||||
{
|
||||
// Get due date
|
||||
$date = Date::today()->addDays($day)->toDateString();
|
||||
@ -78,14 +78,8 @@ class BillReminder extends Command
|
||||
$bills = Bill::with('contact')->accrued()->notPaid()->due($date)->cursor();
|
||||
|
||||
foreach ($bills as $bill) {
|
||||
// Notify all users assigned to this company
|
||||
foreach ($company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($bill, 'bill_remind_admin'));
|
||||
}
|
||||
event(new BillReminded($bill));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\Sale\InvoiceReminded;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Notifications\Sale\Invoice as Notification;
|
||||
use App\Utilities\Overrider;
|
||||
use Date;
|
||||
use Illuminate\Console\Command;
|
||||
@ -60,7 +60,7 @@ class InvoiceReminder extends Command
|
||||
foreach ($days as $day) {
|
||||
$day = (int) trim($day);
|
||||
|
||||
$this->remind($day, $company);
|
||||
$this->remind($day);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ class InvoiceReminder extends Command
|
||||
setting()->forgetAll();
|
||||
}
|
||||
|
||||
protected function remind($day, $company)
|
||||
protected function remind($day)
|
||||
{
|
||||
// Get due date
|
||||
$date = Date::today()->subDays($day)->toDateString();
|
||||
@ -78,19 +78,7 @@ class InvoiceReminder extends Command
|
||||
$invoices = Invoice::with('contact')->accrued()->notPaid()->due($date)->cursor();
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
// Notify the customer
|
||||
if ($invoice->contact && !empty($invoice->contact_email)) {
|
||||
$invoice->contact->notify(new Notification($invoice, 'invoice_remind_customer'));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($invoice, 'invoice_remind_admin'));
|
||||
}
|
||||
event(new InvoiceReminded($invoice));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
app/Events/Purchase/BillReminded.php
Normal file
22
app/Events/Purchase/BillReminded.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Purchase;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BillReminded
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $bill;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $bill
|
||||
*/
|
||||
public function __construct($bill)
|
||||
{
|
||||
$this->bill = $bill;
|
||||
}
|
||||
}
|
22
app/Events/Sale/InvoiceReminded.php
Normal file
22
app/Events/Sale/InvoiceReminded.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\Sale;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class InvoiceReminded
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $invoice
|
||||
*/
|
||||
public function __construct($invoice)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
29
app/Listeners/Purchase/SendBillReminderNotification.php
Normal file
29
app/Listeners/Purchase/SendBillReminderNotification.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Purchase;
|
||||
|
||||
use App\Events\Purchase\BillReminded as Event;
|
||||
use App\Notifications\Purchase\Bill as Notification;
|
||||
|
||||
class SendBillReminderNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$bill = $event->bill;
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($bill->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($bill, 'bill_remind_admin'));
|
||||
}
|
||||
}
|
||||
}
|
34
app/Listeners/Sale/SendInvoiceReminderNotification.php
Normal file
34
app/Listeners/Sale/SendInvoiceReminderNotification.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\InvoiceReminded as Event;
|
||||
use App\Notifications\Sale\Invoice as Notification;
|
||||
|
||||
class SendInvoiceReminderNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
|
||||
// Notify the customer
|
||||
if ($invoice->contact && !empty($invoice->contact_email)) {
|
||||
$invoice->contact->notify(new Notification($invoice, 'invoice_remind_customer'));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($invoice->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($invoice, 'invoice_remind_admin'));
|
||||
}
|
||||
}
|
||||
}
|
@ -39,6 +39,9 @@ class Event extends Provider
|
||||
'App\Events\Purchase\BillRecurring' => [
|
||||
'App\Listeners\Purchase\SendBillRecurringNotification',
|
||||
],
|
||||
'App\Events\Purchase\BillReminded' => [
|
||||
'App\Listeners\Purchase\SendBillReminderNotification',
|
||||
],
|
||||
'App\Events\Sale\PaymentReceived' => [
|
||||
'App\Listeners\Sale\CreateInvoiceTransaction',
|
||||
'App\Listeners\Sale\SendInvoicePaymentNotification',
|
||||
@ -59,6 +62,9 @@ class Event extends Provider
|
||||
'App\Events\Sale\InvoiceRecurring' => [
|
||||
'App\Listeners\Sale\SendInvoiceRecurringNotification',
|
||||
],
|
||||
'App\Events\Sale\InvoiceReminded' => [
|
||||
'App\Listeners\Sale\SendInvoiceReminderNotification',
|
||||
],
|
||||
'App\Events\Menu\AdminCreated' => [
|
||||
'App\Listeners\Menu\AddAdminItems',
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user