mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Endless reminders
This commit is contained in:
parent
e2d4c0a22b
commit
d6c8191b7e
@ -126,6 +126,7 @@ class SendReminders extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// standard reminders
|
||||||
$invoices = $this->invoiceRepo->findNeedingReminding($account);
|
$invoices = $this->invoiceRepo->findNeedingReminding($account);
|
||||||
$this->info($account->name . ': ' . count($invoices) . ' invoices found');
|
$this->info($account->name . ': ' . count($invoices) . ' invoices found');
|
||||||
|
|
||||||
@ -135,6 +136,15 @@ class SendReminders extends Command
|
|||||||
$this->mailer->sendInvoice($invoice, $reminder);
|
$this->mailer->sendInvoice($invoice, $reminder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// endless reminders
|
||||||
|
$invoices = $this->invoiceRepo->findNeedingEndlessReminding($account);
|
||||||
|
$this->info($account->name . ': ' . count($invoices) . ' endless invoices found');
|
||||||
|
|
||||||
|
foreach ($invoices as $invoice) {
|
||||||
|
$this->info('Send email: ' . $invoice->id);
|
||||||
|
$this->mailer->sendInvoice($invoice, 'reminder4');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use Illuminate\Queue\Events\JobExceptionOccurred;
|
|||||||
use App\Events\InvoiceInvitationWasViewed;
|
use App\Events\InvoiceInvitationWasViewed;
|
||||||
use App\Events\InvoiceWasCreated;
|
use App\Events\InvoiceWasCreated;
|
||||||
use App\Events\InvoiceWasUpdated;
|
use App\Events\InvoiceWasUpdated;
|
||||||
|
use App\Events\InvoiceWasEmailed;
|
||||||
use App\Events\PaymentFailed;
|
use App\Events\PaymentFailed;
|
||||||
use App\Events\PaymentWasCreated;
|
use App\Events\PaymentWasCreated;
|
||||||
use App\Events\PaymentWasDeleted;
|
use App\Events\PaymentWasDeleted;
|
||||||
@ -60,6 +61,16 @@ class InvoiceListener
|
|||||||
$invitation->markViewed();
|
$invitation->markViewed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param InvoiceWasEmailed $event
|
||||||
|
*/
|
||||||
|
public function emailedInvoice(InvoiceWasEmailed $event)
|
||||||
|
{
|
||||||
|
$invoice = $event->invoice;
|
||||||
|
$invoice->last_sent_date = date('Y-m-d');
|
||||||
|
$invoice->save();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PaymentWasCreated $event
|
* @param PaymentWasCreated $event
|
||||||
*/
|
*/
|
||||||
|
@ -697,7 +697,7 @@ class AccountRepository
|
|||||||
|
|
||||||
public function findWithReminders()
|
public function findWithReminders()
|
||||||
{
|
{
|
||||||
return Account::whereRaw('enable_reminder1 = 1 OR enable_reminder2 = 1 OR enable_reminder3 = 1')->get();
|
return Account::whereRaw('enable_reminder1 = 1 OR enable_reminder2 = 1 OR enable_reminder3 = 1 OR enable_reminder4 = 1')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findWithFees()
|
public function findWithFees()
|
||||||
|
@ -1204,6 +1204,40 @@ class InvoiceRepository extends BaseRepository
|
|||||||
return $invoices;
|
return $invoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findNeedingEndlessReminding(Account $account)
|
||||||
|
{
|
||||||
|
$frequencyId = $account->account_email_settings->frequency_id_reminder4;
|
||||||
|
$frequency = Utils::getFromCache($frequencyId, 'frequencies');
|
||||||
|
|
||||||
|
$lastSentDate = date_create();
|
||||||
|
$lastSentDate->sub(date_interval_create_from_date_string($frequency->date_interval));
|
||||||
|
|
||||||
|
$invoices = Invoice::invoiceType(INVOICE_TYPE_STANDARD)
|
||||||
|
->with('client', 'invoice_items')
|
||||||
|
->whereHas('client', function ($query) {
|
||||||
|
$query->whereSendReminders(true);
|
||||||
|
})
|
||||||
|
->whereAccountId($account->id)
|
||||||
|
->where('balance', '>', 0)
|
||||||
|
->where('is_recurring', '=', false)
|
||||||
|
->whereIsPublic(true)
|
||||||
|
->where('last_sent_date', '<', $lastSentDate);
|
||||||
|
|
||||||
|
for ($i=1; $i<=3; $i++) {
|
||||||
|
if (!$account->{"enable_reminder{$i}"}) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$field = $account->{"field_reminder{$i}"} == REMINDER_FIELD_DUE_DATE ? 'due_date' : 'invoice_date';
|
||||||
|
$date = date_create();
|
||||||
|
if ($account->{"direction_reminder{$i}"} == REMINDER_DIRECTION_AFTER) {
|
||||||
|
$date->sub(date_interval_create_from_date_string($account->{"num_days_reminder{$i}"} . ' days'));
|
||||||
|
}
|
||||||
|
$invoices->where($field, '<', $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $invoices->get();
|
||||||
|
}
|
||||||
|
|
||||||
public function clearGatewayFee($invoice)
|
public function clearGatewayFee($invoice)
|
||||||
{
|
{
|
||||||
$account = $invoice->account;
|
$account = $invoice->account;
|
||||||
|
@ -56,6 +56,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
],
|
],
|
||||||
'App\Events\InvoiceWasEmailed' => [
|
'App\Events\InvoiceWasEmailed' => [
|
||||||
'App\Listeners\NotificationListener@emailedInvoice',
|
'App\Listeners\NotificationListener@emailedInvoice',
|
||||||
|
'App\Listeners\InvoiceListener@emailedInvoice',
|
||||||
],
|
],
|
||||||
'App\Events\InvoiceInvitationWasEmailed' => [
|
'App\Events\InvoiceInvitationWasEmailed' => [
|
||||||
'App\Listeners\ActivityListener@emailedInvoice',
|
'App\Listeners\ActivityListener@emailedInvoice',
|
||||||
|
@ -69,6 +69,20 @@ class AddRemember2faToken extends Migration
|
|||||||
$table->unsignedInteger('frequency_id_reminder4')->nullable();
|
$table->unsignedInteger('frequency_id_reminder4')->nullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('frequencies', function ($table) {
|
||||||
|
$table->string('date_interval')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::statement("update invoices, (
|
||||||
|
select max(created_at) created_at, invoice_id
|
||||||
|
from activities
|
||||||
|
where activity_type_id = 6
|
||||||
|
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 = 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,5 +131,10 @@ class AddRemember2faToken extends Migration
|
|||||||
$table->dropColumn('email_template_reminder4');
|
$table->dropColumn('email_template_reminder4');
|
||||||
$table->dropColumn('frequency_id_reminder4');
|
$table->dropColumn('frequency_id_reminder4');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('frequencies', function ($table) {
|
||||||
|
$table->dropColumn('date_interval');
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,21 +9,22 @@ class FrequencySeeder extends Seeder
|
|||||||
Eloquent::unguard();
|
Eloquent::unguard();
|
||||||
|
|
||||||
$frequencies = [
|
$frequencies = [
|
||||||
['name' => 'Weekly'],
|
['name' => 'Weekly', 'date_interval' => '1 week'],
|
||||||
['name' => 'Two weeks'],
|
['name' => 'Two weeks', 'date_interval' => '2 weeks'],
|
||||||
['name' => 'Four weeks'],
|
['name' => 'Four weeks', 'date_interval' => '4 weeks'],
|
||||||
['name' => 'Monthly'],
|
['name' => 'Monthly', 'date_interval' => '1 month'],
|
||||||
['name' => 'Two months'],
|
['name' => 'Two months', 'date_interval' => '2 months'],
|
||||||
['name' => 'Three months'],
|
['name' => 'Three months', 'date_interval' => '3 months'],
|
||||||
['name' => 'Four months'],
|
['name' => 'Four months', 'date_interval' => '4 months'],
|
||||||
['name' => 'Six months'],
|
['name' => 'Six months', 'date_interval' => '6 months'],
|
||||||
['name' => 'Annually'],
|
['name' => 'Annually', 'date_interval' => '1 year'],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($frequencies as $frequency) {
|
foreach ($frequencies as $frequency) {
|
||||||
$record = Frequency::whereName($frequency['name'])->first();
|
$record = Frequency::whereName($frequency['name'])->first();
|
||||||
if ($record) {
|
if ($record) {
|
||||||
//$record->save();
|
$record->date_interval = $frequency['date_interval'];
|
||||||
|
$record->save();
|
||||||
} else {
|
} else {
|
||||||
Frequency::create($frequency);
|
Frequency::create($frequency);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user