mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Fixes for reminders
This commit is contained in:
parent
3928ab3e39
commit
60a141d529
@ -380,7 +380,7 @@ class WebhookController extends BaseController
|
||||
*
|
||||
* @throws \Exception
|
||||
* @OA\Delete(
|
||||
* path="/api/v1/Webhooks/{id}",
|
||||
* path="/api/v1/webhooks/{id}",
|
||||
* operationId="deleteWebhook",
|
||||
* tags={"Webhooks"},
|
||||
* summary="Deletes a Webhook",
|
||||
|
@ -68,7 +68,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
* @param Company $company
|
||||
* @param ?string $reminder_template
|
||||
*/
|
||||
public function __construct($invitation, Company $company, ?string $reminder_template = null, ?array $template_data = null)
|
||||
public function __construct($invitation, Company $company, ?string $reminder_template = null, $template_data = null)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
|
@ -41,11 +41,6 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
public function build()
|
||||
{
|
||||
|
||||
info(print_r($this->template_data,1));
|
||||
info((bool) is_array($this->template_data));
|
||||
info((bool) array_key_exists('body', $this->template_data));
|
||||
info((bool) strlen($this->template_data['body']) > 0);
|
||||
|
||||
if(is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0)
|
||||
$body_template = $this->template_data['body'];
|
||||
else
|
||||
|
@ -31,127 +31,83 @@ trait MakesReminders
|
||||
|
||||
return; //exit early
|
||||
}
|
||||
//@TODO buiuld collection, then ->sort()->first
|
||||
|
||||
$nsd = null; //abbreviation for next_send_date
|
||||
$date_collection = collect();
|
||||
|
||||
if ($settings->schedule_reminder1 == 'after_invoice_date' &&
|
||||
$settings->num_days_reminder1 > 0) {
|
||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder1);
|
||||
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder1 == 'before_due_date' &&
|
||||
$settings->num_days_reminder1 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder1);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder1 == 'after_due_date' &&
|
||||
$settings->num_days_reminder1 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder1);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder2 == 'after_invoice_date' &&
|
||||
$settings->num_days_reminder2 > 0) {
|
||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder2);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder2 == 'before_due_date' &&
|
||||
$settings->num_days_reminder2 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder2);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder2 == 'after_due_date' &&
|
||||
$settings->num_days_reminder2 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder2);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder3 == 'after_invoice_date' &&
|
||||
$settings->num_days_reminder3 > 0) {
|
||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder3);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder3 == 'before_due_date' &&
|
||||
$settings->num_days_reminder3 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder3);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->schedule_reminder3 == 'after_due_date' &&
|
||||
$settings->num_days_reminder3 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder3);
|
||||
|
||||
if (! $nsd) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
$date_collection->push($reminder_date->format('Y-m-d'));
|
||||
|
||||
if ($reminder_date->lt($nsd)) {
|
||||
$nsd = $reminder_date->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
$this->next_send_date = $nsd;
|
||||
$this->next_send_date = $date_collection->sort()->first();
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
|
@ -114,9 +114,6 @@ class CheckRemindersTest extends TestCase
|
||||
$settings->enable_reminder1 = true;
|
||||
$settings->schedule_reminder1 = 'after_invoice_date';
|
||||
$settings->num_days_reminder1 = 50;
|
||||
$settings->enable_reminder2 = false;
|
||||
$settings->schedule_reminder2 = 'before_due_date';
|
||||
$settings->num_days_reminder2 = 50;
|
||||
$settings->enable_reminder3 = true;
|
||||
$settings->schedule_reminder3 = 'after_due_date';
|
||||
$settings->num_days_reminder3 = 1;
|
||||
@ -125,12 +122,7 @@ class CheckRemindersTest extends TestCase
|
||||
$this->invoice->service()->markSent();
|
||||
$this->invoice->setReminder($settings);
|
||||
|
||||
info($this->invoice->date);
|
||||
info($this->invoice->due_date);
|
||||
info($this->invoice->next_send_date);
|
||||
//@TODO
|
||||
$this->assertTrue(true);
|
||||
// $this->assertEquals(0, Carbon::parse($this->invoice->due_date)->addDays(1)->diffInDays($this->invoice->next_send_date));
|
||||
$this->assertEquals(0, Carbon::parse($this->invoice->due_date)->addDays(1)->diffInDays($this->invoice->next_send_date));
|
||||
}
|
||||
|
||||
public function test_turning_off_reminders()
|
||||
@ -141,13 +133,13 @@ $this->assertTrue(true);
|
||||
$settings = $this->company->settings;
|
||||
$settings->enable_reminder1 = false;
|
||||
$settings->schedule_reminder1 = 'after_invoice_date';
|
||||
$settings->num_days_reminder1 = 50;
|
||||
$settings->num_days_reminder1 = 0;
|
||||
$settings->enable_reminder2 = false;
|
||||
$settings->schedule_reminder2 = 'before_due_date';
|
||||
$settings->num_days_reminder2 = 50;
|
||||
$settings->num_days_reminder2 = 0;
|
||||
$settings->enable_reminder3 = false;
|
||||
$settings->schedule_reminder3 = 'after_due_date';
|
||||
$settings->num_days_reminder3 = 1;
|
||||
$settings->num_days_reminder3 = 0;
|
||||
|
||||
$this->company->settings = $settings;
|
||||
$this->invoice->service()->markSent();
|
||||
|
Loading…
Reference in New Issue
Block a user