diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 2065f80e00be..d2124dad42c8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -14,6 +14,7 @@ use DateTime; use Illuminate\Database\Eloquent\SoftDeletes; use Laracasts\Presenter\PresentableTrait; use Utils; +use Carbon; /** * Class Invoice. @@ -1159,28 +1160,24 @@ class Invoice extends EntityModel implements BalanceAffecting return false; } - if (! $this->start_date || strtotime($this->start_date) > strtotime('now')) { + $account = $this->account; + $timezone = $account->getTimezone(); + + if (! $this->start_date || Carbon::parse($this->start_date, $timezone)->isFuture()) { return false; } - if ($this->end_date && strtotime($this->end_date) < strtotime('now')) { + if ($this->end_date && Carbon::parse($this->end_date, $timezone)->isPast()) { return false; } - $dayOfWeekToday = date('w'); - $dayOfWeekStart = date('w', strtotime($this->start_date)); - - $dayOfMonthToday = date('j'); - $dayOfMonthStart = date('j', strtotime($this->start_date)); - if (! $this->last_sent_date) { return true; } else { - $date1 = new DateTime($this->last_sent_date); - $date2 = new DateTime(); - $diff = $date2->diff($date1); - $daysSinceLastSent = $diff->format('%a'); - $monthsSinceLastSent = ($diff->format('%y') * 12) + $diff->format('%m'); + $date1 = Carbon::parse($this->last_sent_date, $timezone); + $date2 = Carbon::now($timezone); + $daysSinceLastSent = $date1->diffInDays($date2); + $monthsSinceLastSent = $date1->diffInMonths($date2); if ($daysSinceLastSent == 0) { return false;