Endless reminders

This commit is contained in:
Hillel Coren 2017-12-26 12:11:58 +02:00
parent d6c8191b7e
commit 57549437f9
4 changed files with 31 additions and 1 deletions

View File

@ -132,6 +132,9 @@ class SendReminders extends Command
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
if ($reminder = $account->getInvoiceReminder($invoice)) { if ($reminder = $account->getInvoiceReminder($invoice)) {
if ($invoice->last_sent_date == date('Y-m-d')) {
continue;
}
$this->info('Send email: ' . $invoice->id); $this->info('Send email: ' . $invoice->id);
$this->mailer->sendInvoice($invoice, $reminder); $this->mailer->sendInvoice($invoice, $reminder);
} }
@ -142,6 +145,9 @@ class SendReminders extends Command
$this->info($account->name . ': ' . count($invoices) . ' endless invoices found'); $this->info($account->name . ': ' . count($invoices) . ' endless invoices found');
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
if ($invoice->last_sent_date == date('Y-m-d')) {
continue;
}
$this->info('Send email: ' . $invoice->id); $this->info('Send email: ' . $invoice->id);
$this->mailer->sendInvoice($invoice, 'reminder4'); $this->mailer->sendInvoice($invoice, 'reminder4');
} }

View File

@ -3,6 +3,7 @@
namespace App\Listeners; namespace App\Listeners;
use App\Events\QuoteInvitationWasViewed; use App\Events\QuoteInvitationWasViewed;
use App\Events\QuoteWasEmailed;
/** /**
* Class QuoteListener. * Class QuoteListener.
@ -17,4 +18,15 @@ class QuoteListener
$invitation = $event->invitation; $invitation = $event->invitation;
$invitation->markViewed(); $invitation->markViewed();
} }
/**
* @param InvoiceWasEmailed $event
*/
public function emailedQuote(QuoteWasEmailed $event)
{
$quote = $event->quote;
$quote->last_sent_date = date('Y-m-d');
$quote->save();
}
} }

View File

@ -55,8 +55,8 @@ class EventServiceProvider extends ServiceProvider
'App\Listeners\ActivityListener@restoredInvoice', 'App\Listeners\ActivityListener@restoredInvoice',
], ],
'App\Events\InvoiceWasEmailed' => [ 'App\Events\InvoiceWasEmailed' => [
'App\Listeners\NotificationListener@emailedInvoice',
'App\Listeners\InvoiceListener@emailedInvoice', 'App\Listeners\InvoiceListener@emailedInvoice',
'App\Listeners\NotificationListener@emailedInvoice',
], ],
'App\Events\InvoiceInvitationWasEmailed' => [ 'App\Events\InvoiceInvitationWasEmailed' => [
'App\Listeners\ActivityListener@emailedInvoice', 'App\Listeners\ActivityListener@emailedInvoice',
@ -90,6 +90,7 @@ class EventServiceProvider extends ServiceProvider
'App\Listeners\ActivityListener@restoredQuote', 'App\Listeners\ActivityListener@restoredQuote',
], ],
'App\Events\QuoteWasEmailed' => [ 'App\Events\QuoteWasEmailed' => [
'App\Listeners\QuoteListener@emailedQuote',
'App\Listeners\NotificationListener@emailedQuote', 'App\Listeners\NotificationListener@emailedQuote',
], ],
'App\Events\QuoteInvitationWasEmailed' => [ 'App\Events\QuoteInvitationWasEmailed' => [

View File

@ -83,6 +83,17 @@ class AddRemember2faToken extends Migration
where invoices.id = activities.invoice_id where invoices.id = activities.invoice_id
and invoices.is_recurring = 0 and invoices.is_recurring = 0
and invoices.invoice_type_id = 1"); and invoices.invoice_type_id = 1");
DB::statement("update invoices, (
select max(created_at) created_at, invoice_id
from activities
where activity_type_id = 20
group by invoice_id
) as activities
set invoices.last_sent_date = activities.created_at
where invoices.id = activities.invoice_id
and invoices.is_recurring = 0
and invoices.invoice_type_id = 2");
} }
/** /**