mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for tests
This commit is contained in:
parent
faf1e6d227
commit
2d6e2e5976
@ -174,8 +174,8 @@ class BaseRepository
|
|||||||
$model->client_id = $data['client_id'];
|
$model->client_id = $data['client_id'];
|
||||||
|
|
||||||
//pickup changes here to recalculate reminders
|
//pickup changes here to recalculate reminders
|
||||||
if($model instanceof Invoice && ($model->isDirty('date') || $model->isDirty('due_date')))
|
//if($model instanceof Invoice && ($model->isDirty('date') || $model->isDirty('due_date')))
|
||||||
$model->service()->setReminder()->save();
|
// $model->service()->setReminder()->save();
|
||||||
|
|
||||||
$client = Client::where('id', $model->client_id)->withTrashed()->first();
|
$client = Client::where('id', $model->client_id)->withTrashed()->first();
|
||||||
|
|
||||||
@ -213,6 +213,9 @@ class BaseRepository
|
|||||||
|
|
||||||
/* Model now persisted, now lets do some child tasks */
|
/* Model now persisted, now lets do some child tasks */
|
||||||
|
|
||||||
|
if($model instanceof Invoice)
|
||||||
|
$model->service()->setReminder()->save();
|
||||||
|
|
||||||
/* Save any documents */
|
/* Save any documents */
|
||||||
if (array_key_exists('documents', $data))
|
if (array_key_exists('documents', $data))
|
||||||
$this->saveDocuments($data['documents'], $model);
|
$this->saveDocuments($data['documents'], $model);
|
||||||
|
@ -42,6 +42,9 @@ class UpdateReminder extends AbstractService
|
|||||||
return $this->invoice; //exit early
|
return $this->invoice; //exit early
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->invoice->next_send_date)
|
||||||
|
$this->invoice->next_send_date = null;
|
||||||
|
|
||||||
$offset = $this->invoice->client->timezone_offset();
|
$offset = $this->invoice->client->timezone_offset();
|
||||||
|
|
||||||
$date_collection = collect();
|
$date_collection = collect();
|
||||||
@ -52,7 +55,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 1 after due date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder1_sent) &&
|
if (is_null($this->invoice->reminder1_sent) &&
|
||||||
@ -61,7 +64,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder1)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 1 before_due_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder1_sent) &&
|
if (is_null($this->invoice->reminder1_sent) &&
|
||||||
@ -70,7 +73,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder1)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 1 after_due_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder2_sent) &&
|
if (is_null($this->invoice->reminder2_sent) &&
|
||||||
@ -79,7 +82,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 2 after_invoice_date = ".$reminder_date->format('Y-m-d'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder2_sent) &&
|
if (is_null($this->invoice->reminder2_sent) &&
|
||||||
@ -88,7 +91,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder2)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 2 before_due_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder2_sent) &&
|
if (is_null($this->invoice->reminder2_sent) &&
|
||||||
@ -97,7 +100,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder2)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 2 after_due_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder3_sent) &&
|
if (is_null($this->invoice->reminder3_sent) &&
|
||||||
@ -106,7 +109,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 3 after_invoice_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder3_sent) &&
|
if (is_null($this->invoice->reminder3_sent) &&
|
||||||
@ -115,7 +118,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->subDays($this->settings->num_days_reminder3)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 3 before_due_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder3_sent) &&
|
if (is_null($this->invoice->reminder3_sent) &&
|
||||||
@ -124,7 +127,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
|
$reminder_date = Carbon::parse($this->invoice->due_date)->startOfDay()->addDays($this->settings->num_days_reminder3)->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings reminder 3 after_due_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->invoice->last_sent_date &&
|
if ($this->invoice->last_sent_date &&
|
||||||
@ -137,7 +140,7 @@ class UpdateReminder extends AbstractService
|
|||||||
$reminder_date->addSeconds($offset);
|
$reminder_date->addSeconds($offset);
|
||||||
|
|
||||||
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
if ($reminder_date->gt(Carbon::parse($this->invoice->next_send_date)))
|
||||||
$date_collection->push($reminder_date);
|
$date_collection->push($reminder_date); nlog("settings endless reminder");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,12 +107,11 @@ class ReminderTest extends TestCase
|
|||||||
// ReminderJob::dispatchNow();
|
// ReminderJob::dispatchNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cant set a reminder in the past so need to skip reminder 2 and go straigh to reminder 3*/
|
||||||
public function testReminderNextSendRecalculation()
|
public function testReminderNextSendRecalculation()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->invoice->date = now()->subDays(2)->format('Y-m-d');
|
$this->invoice->date = now()->subDays(2)->format('Y-m-d');
|
||||||
|
|
||||||
$this->invoice->due_date = now()->addDays(30)->format('Y-m-d');
|
$this->invoice->due_date = now()->addDays(30)->format('Y-m-d');
|
||||||
$this->invoice->reminder1_sent = now()->subDays(1)->format('Y-m-d');
|
$this->invoice->reminder1_sent = now()->subDays(1)->format('Y-m-d');
|
||||||
$this->invoice->last_sent_date = now()->subDays(1)->format('Y-m-d');
|
$this->invoice->last_sent_date = now()->subDays(1)->format('Y-m-d');
|
||||||
@ -136,7 +135,7 @@ class ReminderTest extends TestCase
|
|||||||
|
|
||||||
$this->invoice->fresh();
|
$this->invoice->fresh();
|
||||||
|
|
||||||
$this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), now()->format('Y-m-d'));
|
$this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), now()->addDay()->format('Y-m-d'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user