mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 07:02:34 +01:00
Merge pull request #5999 from turbo124/v5-develop
Timezone Offset implementation
This commit is contained in:
commit
7712b7ba69
@ -52,7 +52,7 @@ class Kernel extends ConsoleKernel
|
|||||||
|
|
||||||
$schedule->command('ninja:check-data --database=db-ninja-01')->daily()->withoutOverlapping();
|
$schedule->command('ninja:check-data --database=db-ninja-01')->daily()->withoutOverlapping();
|
||||||
|
|
||||||
$schedule->job(new ReminderJob)->daily()->withoutOverlapping();
|
$schedule->job(new ReminderJob)->hourly()->withoutOverlapping();
|
||||||
|
|
||||||
$schedule->job(new CompanySizeCheck)->daily()->withoutOverlapping();
|
$schedule->job(new CompanySizeCheck)->daily()->withoutOverlapping();
|
||||||
|
|
||||||
|
@ -206,12 +206,10 @@ class RecurringInvoiceController extends BaseController
|
|||||||
|
|
||||||
event(new RecurringInvoiceWasCreated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new RecurringInvoiceWasCreated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
|
|
||||||
$offset = $recurring_invoice->client->timezone_offset();
|
$offset = $recurring_invoice->client->timezone_offset();
|
||||||
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->addSeconds($offset);
|
$recurring_invoice->next_send_date = Carbon::parse($recurring_invoice->next_send_date)->startOfDay()->addSeconds($offset);
|
||||||
$recurring_invoice->save();
|
$recurring_invoice->save();
|
||||||
|
|
||||||
|
|
||||||
return $this->itemResponse($recurring_invoice);
|
return $this->itemResponse($recurring_invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,16 +178,17 @@ class SendReminders implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
private function calculateScheduledDate($invoice, $schedule_reminder, $num_days_reminder) :?Carbon
|
private function calculateScheduledDate($invoice, $schedule_reminder, $num_days_reminder) :?Carbon
|
||||||
{
|
{
|
||||||
|
$offset = $invoice->client->timezone_offset();
|
||||||
|
|
||||||
switch ($schedule_reminder) {
|
switch ($schedule_reminder) {
|
||||||
case 'after_invoice_date':
|
case 'after_invoice_date':
|
||||||
return Carbon::parse($invoice->date)->addDays($num_days_reminder)->startOfDay();
|
return Carbon::parse($invoice->date)->addDays($num_days_reminder)->startOfDay()->addSeconds($offset);
|
||||||
break;
|
break;
|
||||||
case 'before_due_date':
|
case 'before_due_date':
|
||||||
return Carbon::parse($invoice->due_date)->subDays($num_days_reminder)->startOfDay();
|
return Carbon::parse($invoice->due_date)->subDays($num_days_reminder)->startOfDay()->addSeconds($offset);
|
||||||
break;
|
break;
|
||||||
case 'after_due_date':
|
case 'after_due_date':
|
||||||
return Carbon::parse($invoice->due_date)->addDays($num_days_reminder)->startOfDay();
|
return Carbon::parse($invoice->due_date)->addDays($num_days_reminder)->startOfDay()->addSeconds($offset);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
@ -70,9 +70,9 @@ class SendRecurring implements ShouldQueue
|
|||||||
|
|
||||||
nlog("updating recurring invoice dates");
|
nlog("updating recurring invoice dates");
|
||||||
/* Set next date here to prevent a recurring loop forming */
|
/* Set next date here to prevent a recurring loop forming */
|
||||||
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate()->format('Y-m-d');
|
$this->recurring_invoice->next_send_date = $this->recurring_invoice->nextSendDate();
|
||||||
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
|
$this->recurring_invoice->remaining_cycles = $this->recurring_invoice->remainingCycles();
|
||||||
$this->recurring_invoice->last_sent_date = date('Y-m-d');
|
$this->recurring_invoice->last_sent_date = now();
|
||||||
|
|
||||||
/* Set completed if we don't have any more cycles remaining*/
|
/* Set completed if we don't have any more cycles remaining*/
|
||||||
if ($this->recurring_invoice->remaining_cycles == 0) {
|
if ($this->recurring_invoice->remaining_cycles == 0) {
|
||||||
|
@ -53,7 +53,7 @@ class ReminderJob implements ShouldQueue
|
|||||||
|
|
||||||
private function processReminders()
|
private function processReminders()
|
||||||
{
|
{
|
||||||
Invoice::where('next_send_date', Carbon::today()->format('Y-m-d'))->with('invitations')->cursor()->each(function ($invoice) {
|
Invoice::whereDate('next_send_date', '<=', now())->with('invitations')->cursor()->each(function ($invoice) {
|
||||||
|
|
||||||
if ($invoice->isPayable()) {
|
if ($invoice->isPayable()) {
|
||||||
$reminder_template = $invoice->calculateTemplate('invoice');
|
$reminder_template = $invoice->calculateTemplate('invoice');
|
||||||
|
@ -105,9 +105,6 @@ class Account extends BaseModel
|
|||||||
return $this->hasOne(Company::class, 'id', 'default_company_id');
|
return $this->hasOne(Company::class, 'id', 'default_company_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return BelongsTo
|
|
||||||
*/
|
|
||||||
public function payment()
|
public function payment()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Payment::class)->withTrashed();
|
return $this->belongsTo(Payment::class)->withTrashed();
|
||||||
@ -323,4 +320,5 @@ class Account extends BaseModel
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -256,31 +256,33 @@ class RecurringInvoice extends BaseModel
|
|||||||
|
|
||||||
public function nextDateByFrequency($date)
|
public function nextDateByFrequency($date)
|
||||||
{
|
{
|
||||||
|
$offset = $this->client->timezone_offset();
|
||||||
|
|
||||||
switch ($this->frequency_id) {
|
switch ($this->frequency_id) {
|
||||||
case self::FREQUENCY_DAILY:
|
case self::FREQUENCY_DAILY:
|
||||||
return Carbon::parse($date)->addDay();
|
return Carbon::parse($date)->startOfDay()->addDay()->addSeconds($offset);
|
||||||
case self::FREQUENCY_WEEKLY:
|
case self::FREQUENCY_WEEKLY:
|
||||||
return Carbon::parse($date)->addWeek();
|
return Carbon::parse($date)->startOfDay()->addWeek()->addSeconds($offset);
|
||||||
case self::FREQUENCY_TWO_WEEKS:
|
case self::FREQUENCY_TWO_WEEKS:
|
||||||
return Carbon::parse($date)->addWeeks(2);
|
return Carbon::parse($date)->startOfDay()->addWeeks(2)->addSeconds($offset);
|
||||||
case self::FREQUENCY_FOUR_WEEKS:
|
case self::FREQUENCY_FOUR_WEEKS:
|
||||||
return Carbon::parse($date)->addWeeks(4);
|
return Carbon::parse($date)->startOfDay()->addWeeks(4)->addSeconds($offset);
|
||||||
case self::FREQUENCY_MONTHLY:
|
case self::FREQUENCY_MONTHLY:
|
||||||
return Carbon::parse($date)->addMonthNoOverflow();
|
return Carbon::parse($date)->startOfDay()->addMonthNoOverflow()->addSeconds($offset);
|
||||||
case self::FREQUENCY_TWO_MONTHS:
|
case self::FREQUENCY_TWO_MONTHS:
|
||||||
return Carbon::parse($date)->addMonthsNoOverflow(2);
|
return Carbon::parse($date)->startOfDay()->addMonthsNoOverflow(2)->addSeconds($offset);
|
||||||
case self::FREQUENCY_THREE_MONTHS:
|
case self::FREQUENCY_THREE_MONTHS:
|
||||||
return Carbon::parse($date)->addMonthsNoOverflow(3);
|
return Carbon::parse($date)->startOfDay()->addMonthsNoOverflow(3)->addSeconds($offset);
|
||||||
case self::FREQUENCY_FOUR_MONTHS:
|
case self::FREQUENCY_FOUR_MONTHS:
|
||||||
return Carbon::parse($date)->addMonthsNoOverflow(4);
|
return Carbon::parse($date)->startOfDay()->addMonthsNoOverflow(4)->addSeconds($offset);
|
||||||
case self::FREQUENCY_SIX_MONTHS:
|
case self::FREQUENCY_SIX_MONTHS:
|
||||||
return Carbon::parse($date)->addMonthsNoOverflow(6);
|
return Carbon::parse($date)->addMonthsNoOverflow(6)->addSeconds($offset);
|
||||||
case self::FREQUENCY_ANNUALLY:
|
case self::FREQUENCY_ANNUALLY:
|
||||||
return Carbon::parse($date)->addYear();
|
return Carbon::parse($date)->startOfDay()->addYear()->addSeconds($offset);
|
||||||
case self::FREQUENCY_TWO_YEARS:
|
case self::FREQUENCY_TWO_YEARS:
|
||||||
return Carbon::parse($date)->addYears(2);
|
return Carbon::parse($date)->startOfDay()->addYears(2)->addSeconds($offset);
|
||||||
case self::FREQUENCY_THREE_YEARS:
|
case self::FREQUENCY_THREE_YEARS:
|
||||||
return Carbon::parse($date)->addYears(3);
|
return Carbon::parse($date)->startOfDay()->addYears(3)->addSeconds($offset);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -41,87 +41,89 @@ class UpdateReminder extends AbstractService
|
|||||||
return $this->invoice; //exit early
|
return $this->invoice; //exit early
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$offset = $this->invoice->client->timezone_offset();
|
||||||
|
|
||||||
$date_collection = collect();
|
$date_collection = collect();
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder1_sent) &&
|
if (is_null($this->invoice->reminder1_sent) &&
|
||||||
$this->settings->schedule_reminder1 == 'after_invoice_date' &&
|
$this->settings->schedule_reminder1 == 'after_invoice_date' &&
|
||||||
$this->settings->num_days_reminder1 > 0) {
|
$this->settings->num_days_reminder1 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->date)->addDays($this->settings->num_days_reminder1);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder1_sent) &&
|
if (is_null($this->invoice->reminder1_sent) &&
|
||||||
$this->settings->schedule_reminder1 == 'before_due_date' &&
|
$this->settings->schedule_reminder1 == 'before_due_date' &&
|
||||||
$this->settings->num_days_reminder1 > 0) {
|
$this->settings->num_days_reminder1 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->subDays($this->settings->num_days_reminder1);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder1_sent) &&
|
if (is_null($this->invoice->reminder1_sent) &&
|
||||||
$this->settings->schedule_reminder1 == 'after_due_date' &&
|
$this->settings->schedule_reminder1 == 'after_due_date' &&
|
||||||
$this->settings->num_days_reminder1 > 0) {
|
$this->settings->num_days_reminder1 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->addDays($this->settings->num_days_reminder1);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder2_sent) &&
|
if (is_null($this->invoice->reminder2_sent) &&
|
||||||
$this->settings->schedule_reminder2 == 'after_invoice_date' &&
|
$this->settings->schedule_reminder2 == 'after_invoice_date' &&
|
||||||
$this->settings->num_days_reminder2 > 0) {
|
$this->settings->num_days_reminder2 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->date)->addDays($this->settings->num_days_reminder2);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder2_sent) &&
|
if (is_null($this->invoice->reminder2_sent) &&
|
||||||
$this->settings->schedule_reminder2 == 'before_due_date' &&
|
$this->settings->schedule_reminder2 == 'before_due_date' &&
|
||||||
$this->settings->num_days_reminder2 > 0) {
|
$this->settings->num_days_reminder2 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->subDays($this->settings->num_days_reminder2);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder2_sent) &&
|
if (is_null($this->invoice->reminder2_sent) &&
|
||||||
$this->settings->schedule_reminder2 == 'after_due_date' &&
|
$this->settings->schedule_reminder2 == 'after_due_date' &&
|
||||||
$this->settings->num_days_reminder2 > 0) {
|
$this->settings->num_days_reminder2 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->addDays($this->settings->num_days_reminder2);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder3_sent) &&
|
if (is_null($this->invoice->reminder3_sent) &&
|
||||||
$this->settings->schedule_reminder3 == 'after_invoice_date' &&
|
$this->settings->schedule_reminder3 == 'after_invoice_date' &&
|
||||||
$this->settings->num_days_reminder3 > 0) {
|
$this->settings->num_days_reminder3 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->date)->addDays($this->settings->num_days_reminder3);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder3_sent) &&
|
if (is_null($this->invoice->reminder3_sent) &&
|
||||||
$this->settings->schedule_reminder3 == 'before_due_date' &&
|
$this->settings->schedule_reminder3 == 'before_due_date' &&
|
||||||
$this->settings->num_days_reminder3 > 0) {
|
$this->settings->num_days_reminder3 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->subDays($this->settings->num_days_reminder3);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoice->reminder3_sent) &&
|
if (is_null($this->invoice->reminder3_sent) &&
|
||||||
$this->settings->schedule_reminder3 == 'after_due_date' &&
|
$this->settings->schedule_reminder3 == 'after_due_date' &&
|
||||||
$this->settings->num_days_reminder3 > 0) {
|
$this->settings->num_days_reminder3 > 0) {
|
||||||
$reminder_date = Carbon::parse($this->invoice->due_date)->addDays($this->settings->num_days_reminder3);
|
$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->format('Y-m-d'));
|
$date_collection->push($reminder_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->invoice->next_send_date = $date_collection->sort()->first();
|
$this->invoice->next_send_date = $date_collection->sort()->first();
|
||||||
|
@ -51,7 +51,7 @@ class CompanyUserTransformer extends EntityTransformer
|
|||||||
'archived_at' => (int) $company_user->deleted_at,
|
'archived_at' => (int) $company_user->deleted_at,
|
||||||
'created_at' => (int) $company_user->created_at,
|
'created_at' => (int) $company_user->created_at,
|
||||||
'permissions_updated_at' => (int) $company_user->permissions_updated_at,
|
'permissions_updated_at' => (int) $company_user->permissions_updated_at,
|
||||||
//'number_years_active' => (int) $company_user->number_years_active,
|
'ninja_portal_url' => (string) $company_user->ninja_portal_url,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddNinjaPortalColumnToAccountsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('company_user', function (Blueprint $table) {
|
||||||
|
$table->text('ninja_portal_url')->default('');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -77,7 +77,7 @@ class ReminderTest extends TestCase
|
|||||||
$this->invoice->service()->markSent();
|
$this->invoice->service()->markSent();
|
||||||
$this->invoice->service()->setReminder($settings)->save();
|
$this->invoice->service()->setReminder($settings)->save();
|
||||||
|
|
||||||
$this->assertEquals($this->invoice->next_send_date, Carbon::now()->addDays(7)->format('Y-m-d'));
|
$this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), Carbon::now()->addDays(7)->format('Y-m-d'));
|
||||||
|
|
||||||
// ReminderJob::dispatchNow();
|
// ReminderJob::dispatchNow();
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ class ReminderTest extends TestCase
|
|||||||
|
|
||||||
$this->invoice->fresh();
|
$this->invoice->fresh();
|
||||||
|
|
||||||
$this->assertEquals($this->invoice->next_send_date, now()->format('Y-m-d'));
|
$this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), now()->format('Y-m-d'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ class ReminderTest extends TestCase
|
|||||||
|
|
||||||
$this->invoice->fresh();
|
$this->invoice->fresh();
|
||||||
|
|
||||||
$this->assertEquals($this->invoice->next_send_date, now()->format('Y-m-d'));
|
$this->assertEquals(Carbon::parse($this->invoice->next_send_date)->format('Y-m-d'), now()->format('Y-m-d'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user