mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
commit
3669189308
@ -34,76 +34,94 @@ trait MakesReminders
|
|||||||
|
|
||||||
$date_collection = collect();
|
$date_collection = collect();
|
||||||
|
|
||||||
if ($settings->schedule_reminder1 == 'after_invoice_date' &&
|
if (is_null($this->reminder1_sent) &&
|
||||||
|
$settings->schedule_reminder1 == 'after_invoice_date' &&
|
||||||
$settings->num_days_reminder1 > 0) {
|
$settings->num_days_reminder1 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder1);
|
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder1);
|
||||||
|
nlog("reminder 1 = after invoice date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('after_invoice_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder1 == 'before_due_date' &&
|
if (is_null($this->reminder1_sent) &&
|
||||||
|
$settings->schedule_reminder1 == 'before_due_date' &&
|
||||||
$settings->num_days_reminder1 > 0) {
|
$settings->num_days_reminder1 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder1);
|
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder1);
|
||||||
|
nlog("reminder 1 = before_due_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('before_due_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder1 == 'after_due_date' &&
|
if (is_null($this->reminder1_sent) &&
|
||||||
|
$settings->schedule_reminder1 == 'after_due_date' &&
|
||||||
$settings->num_days_reminder1 > 0) {
|
$settings->num_days_reminder1 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder1);
|
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder1);
|
||||||
|
nlog("reminder 1 = after_due_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('after_due_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder2 == 'after_invoice_date' &&
|
if (is_null($this->reminder2_sent) &&
|
||||||
|
$settings->schedule_reminder2 == 'after_invoice_date' &&
|
||||||
$settings->num_days_reminder2 > 0) {
|
$settings->num_days_reminder2 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder2);
|
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder2);
|
||||||
|
nlog("reminder 2 = after_invoice_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('after_invoice_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder2 == 'before_due_date' &&
|
if (is_null($this->reminder2_sent) &&
|
||||||
|
$settings->schedule_reminder2 == 'before_due_date' &&
|
||||||
$settings->num_days_reminder2 > 0) {
|
$settings->num_days_reminder2 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder2);
|
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder2);
|
||||||
|
nlog("reminder 2 = before_due_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('before_due_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder2 == 'after_due_date' &&
|
if (is_null($this->reminder2_sent) &&
|
||||||
|
$settings->schedule_reminder2 == 'after_due_date' &&
|
||||||
$settings->num_days_reminder2 > 0) {
|
$settings->num_days_reminder2 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder2);
|
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder2);
|
||||||
|
nlog("reminder 2 = after_due_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('after_due_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder3 == 'after_invoice_date' &&
|
if (is_null($this->reminder3_sent) &&
|
||||||
|
$settings->schedule_reminder3 == 'after_invoice_date' &&
|
||||||
$settings->num_days_reminder3 > 0) {
|
$settings->num_days_reminder3 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder3);
|
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder3);
|
||||||
|
nlog("reminder 3 = after_invoice_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('after_invoice_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder3 == 'before_due_date' &&
|
if (is_null($this->reminder3_sent) &&
|
||||||
|
$settings->schedule_reminder3 == 'before_due_date' &&
|
||||||
$settings->num_days_reminder3 > 0) {
|
$settings->num_days_reminder3 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder3);
|
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder3);
|
||||||
|
nlog("reminder 3 = before_due_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('before_due_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($settings->schedule_reminder3 == 'after_due_date' &&
|
if (is_null($this->reminder3_sent) &&
|
||||||
|
$settings->schedule_reminder3 == 'after_due_date' &&
|
||||||
$settings->num_days_reminder3 > 0) {
|
$settings->num_days_reminder3 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder3);
|
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder3);
|
||||||
|
nlog("reminder 3 = after_due_date = {$reminder_date}");
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
if ($reminder_date->gt(Carbon::parse($this->next_send_date)));
|
||||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
$date_collection->push($reminder_date->format('Y-m-d')); nlog('after_due_date pushed to collection');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->next_send_date = $date_collection->sort()->first();
|
$this->next_send_date = $date_collection->sort()->first();
|
||||||
|
@ -85,24 +85,59 @@ class ReminderTest extends TestCase
|
|||||||
public function testReminderNextSendRecalculation()
|
public function testReminderNextSendRecalculation()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->invoice->date = now()->subDays(1)->format('Y-m-d');
|
$this->invoice->date = now()->subDays(2)->format('Y-m-d');
|
||||||
$this->invoice->due_date = Carbon::now()->addDays(30)->format('Y-m-d');
|
$this->invoice->due_date = Carbon::now()->addDays(30)->format('Y-m-d');
|
||||||
$this->invoice->reminder1_sent = now()->format('Y-m-d');
|
$this->invoice->reminder1_sent = now()->subDays(1)->format('Y-m-d');
|
||||||
|
|
||||||
$settings = $this->company->settings;
|
$settings = $this->company->settings;
|
||||||
$settings->enable_reminder1 = true;
|
$settings->enable_reminder1 = true;
|
||||||
$settings->schedule_reminder1 = 'after_invoice_date';
|
$settings->schedule_reminder1 = 'after_invoice_date';
|
||||||
$settings->num_days_reminder1 = 1;
|
$settings->num_days_reminder1 = 1;
|
||||||
$settings->enable_reminder2 = true;
|
$settings->enable_reminder2 = true;
|
||||||
$settings->schedule_reminder2 = 'before_due_date';
|
$settings->schedule_reminder2 = 'after_invoice_date';
|
||||||
$settings->num_days_reminder2 = 1;
|
$settings->num_days_reminder2 = 2;
|
||||||
$settings->enable_reminder3 = true;
|
$settings->enable_reminder3 = true;
|
||||||
$settings->schedule_reminder3 = 'after_due_date';
|
$settings->schedule_reminder3 = 'after_invoice_date';
|
||||||
$settings->num_days_reminder3 = 1;
|
$settings->num_days_reminder3 = 3;
|
||||||
|
|
||||||
$this->company->settings = $settings;
|
$this->company->settings = $settings;
|
||||||
$this->invoice->service()->markSent();
|
$this->invoice->service()->markSent();
|
||||||
$this->invoice->setReminder($settings);
|
$this->invoice->setReminder($settings);
|
||||||
|
|
||||||
|
$this->invoice->fresh();
|
||||||
|
|
||||||
|
$this->assertEquals($this->invoice->next_send_date, now()->format('Y-m-d'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testReminder3NextSendRecalculation()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->invoice->date = now()->subDays(3)->format('Y-m-d');
|
||||||
|
$this->invoice->due_date = Carbon::now()->addDays(30)->format('Y-m-d');
|
||||||
|
$this->invoice->reminder1_sent = now()->subDays(2)->format('Y-m-d');
|
||||||
|
$this->invoice->reminder2_sent = now()->subDays(1)->format('Y-m-d');
|
||||||
|
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
$settings->enable_reminder1 = true;
|
||||||
|
$settings->schedule_reminder1 = 'after_invoice_date';
|
||||||
|
$settings->num_days_reminder1 = 1;
|
||||||
|
$settings->enable_reminder2 = true;
|
||||||
|
$settings->schedule_reminder2 = 'after_invoice_date';
|
||||||
|
$settings->num_days_reminder2 = 2;
|
||||||
|
$settings->enable_reminder3 = true;
|
||||||
|
$settings->schedule_reminder3 = 'after_invoice_date';
|
||||||
|
$settings->num_days_reminder3 = 3;
|
||||||
|
|
||||||
|
$this->company->settings = $settings;
|
||||||
|
$this->invoice->service()->markSent();
|
||||||
|
$this->invoice->setReminder($settings);
|
||||||
|
|
||||||
|
$this->invoice->fresh();
|
||||||
|
|
||||||
|
$this->assertEquals($this->invoice->next_send_date, now()->format('Y-m-d'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user