1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Console/Commands/SendReminders.php

98 lines
2.3 KiB
PHP
Raw Normal View History

2016-07-21 14:35:23 +02:00
<?php namespace App\Console\Commands;
2015-09-17 21:01:06 +02:00
use App\Models\Invoice;
2015-09-17 21:01:06 +02:00
use Illuminate\Console\Command;
use App\Ninja\Mailers\ContactMailer as Mailer;
use App\Ninja\Repositories\AccountRepository;
2015-09-17 21:01:06 +02:00
use App\Ninja\Repositories\InvoiceRepository;
/**
* Class SendReminders
*/
2015-09-17 21:01:06 +02:00
class SendReminders extends Command
{
/**
* @var string
*/
2015-09-17 21:01:06 +02:00
protected $name = 'ninja:send-reminders';
/**
* @var string
*/
2015-09-17 21:01:06 +02:00
protected $description = 'Send reminder emails';
/**
* @var Mailer
*/
2015-09-17 21:01:06 +02:00
protected $mailer;
/**
* @var InvoiceRepository
*/
2015-09-17 21:01:06 +02:00
protected $invoiceRepo;
/**
* @var accountRepository
*/
2015-09-17 21:01:06 +02:00
protected $accountRepo;
/**
* SendReminders constructor.
* @param Mailer $mailer
* @param InvoiceRepository $invoiceRepo
* @param accountRepository $accountRepo
*/
2015-09-17 21:01:06 +02:00
public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, AccountRepository $accountRepo)
{
parent::__construct();
$this->mailer = $mailer;
$this->invoiceRepo = $invoiceRepo;
$this->accountRepo = $accountRepo;
}
public function fire()
{
$this->info(date('Y-m-d') . ' Running SendReminders...');
2015-09-17 21:01:06 +02:00
$accounts = $this->accountRepo->findWithReminders();
$this->info(count($accounts) . ' accounts found');
2015-09-17 21:01:06 +02:00
/** @var \App\Models\Account $account */
2015-09-17 21:01:06 +02:00
foreach ($accounts as $account) {
if (!$account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) {
2015-10-13 09:11:44 +02:00
continue;
}
2015-09-17 21:01:06 +02:00
$invoices = $this->invoiceRepo->findNeedingReminding($account);
$this->info($account->name . ': ' . count($invoices) . ' invoices found');
2015-09-17 21:01:06 +02:00
/** @var Invoice $invoice */
2015-09-17 21:01:06 +02:00
foreach ($invoices as $invoice) {
if ($reminder = $account->getInvoiceReminder($invoice)) {
2015-11-17 14:42:54 +01:00
$this->info('Send to ' . $invoice->id);
2015-09-17 21:01:06 +02:00
$this->mailer->sendInvoice($invoice, $reminder);
}
}
}
$this->info('Done');
}
/**
* @return array
*/
2015-09-17 21:01:06 +02:00
protected function getArguments()
{
return [];
2015-09-17 21:01:06 +02:00
}
/**
* @return array
*/
2015-09-17 21:01:06 +02:00
protected function getOptions()
{
return [];
2015-09-17 21:01:06 +02:00
}
}