diff --git a/app/Console/Commands/SendReminders.php b/app/Console/Commands/SendReminders.php index 51e5a7b940a4..b58268a0b258 100644 --- a/app/Console/Commands/SendReminders.php +++ b/app/Console/Commands/SendReminders.php @@ -132,6 +132,9 @@ class SendReminders extends Command foreach ($invoices as $invoice) { if ($reminder = $account->getInvoiceReminder($invoice)) { + if ($invoice->last_sent_date == date('Y-m-d')) { + continue; + } $this->info('Send email: ' . $invoice->id); $this->mailer->sendInvoice($invoice, $reminder); } @@ -142,6 +145,9 @@ class SendReminders extends Command $this->info($account->name . ': ' . count($invoices) . ' endless invoices found'); foreach ($invoices as $invoice) { + if ($invoice->last_sent_date == date('Y-m-d')) { + continue; + } $this->info('Send email: ' . $invoice->id); $this->mailer->sendInvoice($invoice, 'reminder4'); } diff --git a/app/Listeners/QuoteListener.php b/app/Listeners/QuoteListener.php index 0a47a049d4a0..e756a3539258 100644 --- a/app/Listeners/QuoteListener.php +++ b/app/Listeners/QuoteListener.php @@ -3,6 +3,7 @@ namespace App\Listeners; use App\Events\QuoteInvitationWasViewed; +use App\Events\QuoteWasEmailed; /** * Class QuoteListener. @@ -17,4 +18,15 @@ class QuoteListener $invitation = $event->invitation; $invitation->markViewed(); } + + /** + * @param InvoiceWasEmailed $event + */ + public function emailedQuote(QuoteWasEmailed $event) + { + $quote = $event->quote; + $quote->last_sent_date = date('Y-m-d'); + $quote->save(); + } + } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 35cf2f23f7c9..87d520bcea6b 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -55,8 +55,8 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\ActivityListener@restoredInvoice', ], 'App\Events\InvoiceWasEmailed' => [ - 'App\Listeners\NotificationListener@emailedInvoice', 'App\Listeners\InvoiceListener@emailedInvoice', + 'App\Listeners\NotificationListener@emailedInvoice', ], 'App\Events\InvoiceInvitationWasEmailed' => [ 'App\Listeners\ActivityListener@emailedInvoice', @@ -90,6 +90,7 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\ActivityListener@restoredQuote', ], 'App\Events\QuoteWasEmailed' => [ + 'App\Listeners\QuoteListener@emailedQuote', 'App\Listeners\NotificationListener@emailedQuote', ], 'App\Events\QuoteInvitationWasEmailed' => [ diff --git a/database/migrations/2017_12_13_074024_add_remember_2fa_token.php b/database/migrations/2017_12_13_074024_add_remember_2fa_token.php index 46fee1c73dff..c96d039da028 100644 --- a/database/migrations/2017_12_13_074024_add_remember_2fa_token.php +++ b/database/migrations/2017_12_13_074024_add_remember_2fa_token.php @@ -83,6 +83,17 @@ class AddRemember2faToken extends Migration where invoices.id = activities.invoice_id and invoices.is_recurring = 0 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"); } /**