mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 17:14:28 -04:00
Tests for reminders
This commit is contained in:
parent
12ccb04f76
commit
2893c98b0e
@ -98,6 +98,8 @@ class BillingPortalPurchase extends Component
|
||||
*/
|
||||
public $payment_method_id;
|
||||
|
||||
private $user_coupon;
|
||||
|
||||
/**
|
||||
* List of steps that frontend form follows.
|
||||
*
|
||||
@ -436,32 +438,45 @@ class BillingPortalPurchase extends Component
|
||||
*/
|
||||
public function updateQuantity(string $option): int
|
||||
{
|
||||
$this->handleCoupon();
|
||||
|
||||
if ($this->quantity == 1 && $option == 'decrement') {
|
||||
$this->price = $this->price * 1;
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
if ($this->quantity >= $this->subscription->max_seats_limit && $option == 'increment') {
|
||||
if ($this->quantity > $this->subscription->max_seats_limit && $option == 'increment') {
|
||||
$this->price = $this->price * $this->subscription->max_seats_limit;
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
if ($option == 'increment') {
|
||||
$this->quantity++;
|
||||
$this->price = $this->subscription->promo_price * $this->quantity;
|
||||
$this->price = $this->price * $this->quantity;
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
$this->quantity--;
|
||||
$this->price = $this->subscription->promo_price * $this->quantity;
|
||||
$this->price = $this->price * $this->quantity;
|
||||
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
public function handleCoupon()
|
||||
{
|
||||
|
||||
if($this->steps['discount_applied']){
|
||||
$this->price = $this->subscription->promo_price;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->coupon == $this->subscription->promo_code) {
|
||||
$this->price = $this->subscription->promo_price;
|
||||
$this->quantity = 1;
|
||||
$this->steps['discount_applied'] = true;
|
||||
}
|
||||
else
|
||||
$this->price = $this->subscription->price;
|
||||
}
|
||||
|
||||
public function passwordlessLogin()
|
||||
|
@ -75,6 +75,7 @@ class ReminderJob implements ShouldQueue
|
||||
->with('invitations')->cursor()->each(function ($invoice) {
|
||||
if ($invoice->isPayable()) {
|
||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||
nlog("reminder template = {$reminder_template}");
|
||||
$invoice->service()->touchReminder($reminder_template)->save();
|
||||
$invoice = $this->calcLateFee($invoice, $reminder_template);
|
||||
|
||||
@ -93,6 +94,7 @@ class ReminderJob implements ShouldQueue
|
||||
$invoice->client->getSetting($enabled_reminder) &&
|
||||
$invoice->client->getSetting('send_reminders') &&
|
||||
(Ninja::isSelfHost() || $invoice->company->account->isPaidHostedClient())) {
|
||||
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) {
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $reminder_template);
|
||||
nlog("Firing reminder email for invoice {$invoice->number}");
|
||||
|
@ -370,6 +370,8 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
return $this->settings->{$setting};
|
||||
} elseif (is_bool($this->settings->{$setting})) {
|
||||
return $this->settings->{$setting};
|
||||
} elseif (is_int($this->settings->{$setting})) { //10-08-2022 integer client values are not being passed back! This resolves it.
|
||||
return $this->settings->{$setting};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ trait MakesReminders
|
||||
{
|
||||
public function inReminderWindow($schedule_reminder, $num_days_reminder)
|
||||
{
|
||||
|
||||
switch ($schedule_reminder) {
|
||||
case 'after_invoice_date':
|
||||
return Carbon::parse($this->date)->addDays($num_days_reminder)->startOfDay()->eq(Carbon::now()->startOfDay());
|
||||
|
@ -48,6 +48,89 @@ class ReminderTest extends TestCase
|
||||
$this->withoutExceptionHandling();
|
||||
}
|
||||
|
||||
|
||||
public function testForClientTimezoneEdges()
|
||||
{
|
||||
|
||||
$this->invoice->next_send_date = null;
|
||||
$this->invoice->date = now()->format('Y-m-d');
|
||||
$this->invoice->due_date = Carbon::now()->addDays(5)->format('Y-m-d');
|
||||
$this->invoice->save();
|
||||
|
||||
$settings = $this->company->settings;
|
||||
$settings->enable_reminder1 = true;
|
||||
$settings->schedule_reminder1 = 'before_due_date';
|
||||
$settings->num_days_reminder1 = 4;
|
||||
$settings->enable_reminder2 = true;
|
||||
$settings->schedule_reminder2 = 'before_due_date';
|
||||
$settings->num_days_reminder2 = 2;
|
||||
$settings->enable_reminder3 = true;
|
||||
$settings->schedule_reminder3 = 'after_due_date';
|
||||
$settings->num_days_reminder3 = 3;
|
||||
$settings->timezone_id = '15';
|
||||
$settings->entity_send_time = 8;
|
||||
|
||||
$this->client->company->settings = $settings;
|
||||
$this->client->push();
|
||||
|
||||
$client_settings = $settings;
|
||||
$client_settings->timezone_id = '15';
|
||||
$client_settings->entity_send_time = 8;
|
||||
|
||||
$this->invoice->client->settings = $client_settings;
|
||||
$this->invoice->push();
|
||||
|
||||
$this->invoice = $this->invoice->service()->markSent()->save();
|
||||
$this->invoice->service()->setReminder($client_settings)->save();
|
||||
|
||||
$next_send_date = Carbon::parse($this->invoice->next_send_date);
|
||||
$calculatedReminderDate = Carbon::parse($this->invoice->due_date)->subDays(4)->addSeconds($this->invoice->client->timezone_offset());
|
||||
|
||||
nlog($next_send_date->format('Y-m-d h:i:s'));
|
||||
nlog($calculatedReminderDate->format('Y-m-d h:i:s'));
|
||||
|
||||
$this->travelTo(now()->addDays(1));
|
||||
|
||||
$reminder_template = $this->invoice->calculateTemplate('invoice');
|
||||
|
||||
$this->assertEquals('reminder1', $reminder_template);
|
||||
|
||||
$this->assertTrue($next_send_date->eq($calculatedReminderDate));
|
||||
|
||||
$this->invoice->service()->touchReminder($reminder_template)->save();
|
||||
|
||||
$this->assertNotNull($this->invoice->last_sent_date);
|
||||
$this->assertNotNull($this->invoice->reminder1_sent);
|
||||
$this->assertNotNull($this->invoice->reminder_last_sent);
|
||||
|
||||
//calc next send date
|
||||
$this->invoice->service()->setReminder()->save();
|
||||
|
||||
$next_send_date = Carbon::parse($this->invoice->next_send_date);
|
||||
|
||||
nlog($next_send_date->format('Y-m-d h:i:s'));
|
||||
|
||||
$calculatedReminderDate = Carbon::parse($this->invoice->due_date)->subDays(2)->addSeconds($this->invoice->client->timezone_offset());
|
||||
$this->assertTrue($next_send_date->eq($calculatedReminderDate));
|
||||
|
||||
$this->travelTo(now()->addDays(2));
|
||||
|
||||
$reminder_template = $this->invoice->calculateTemplate('invoice');
|
||||
|
||||
$this->assertEquals('reminder2', $reminder_template);
|
||||
$this->invoice->service()->touchReminder($reminder_template)->save();
|
||||
$this->assertNotNull($this->invoice->reminder2_sent);
|
||||
|
||||
$this->invoice->service()->setReminder()->save();
|
||||
|
||||
$next_send_date = Carbon::parse($this->invoice->next_send_date);
|
||||
$calculatedReminderDate = Carbon::parse($this->invoice->due_date)->addDays(3)->addSeconds($this->invoice->client->timezone_offset());
|
||||
$this->assertTrue($next_send_date->eq($calculatedReminderDate));
|
||||
|
||||
nlog($next_send_date->format('Y-m-d h:i:s'));
|
||||
|
||||
}
|
||||
|
||||
public function testReminderQueryCatchesDate()
|
||||
{
|
||||
$this->invoice->next_send_date = now()->format('Y-m-d');
|
||||
@ -189,4 +272,6 @@ class ReminderTest extends TestCase
|
||||
|
||||
$this->assertNotNull($this->invoice->next_send_date);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user