From b2730463eb53622a1bdd9b7e3d2a89fbcd231fe5 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 31 Mar 2017 11:55:26 +0300 Subject: [PATCH] Check invoices aren't sent hours early --- app/Models/Invoice.php | 11 +++++------ app/Models/Traits/GeneratesNumbers.php | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 8f8a48d93c09..ef9cc26615a6 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1207,13 +1207,12 @@ class Invoice extends EntityModel implements BalanceAffecting $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); - */ + // check we don't send a few hours early due to timezone difference + if (Carbon::now()->format('Y-m-d') != Carbon::now($timezone)->format('Y-m-d')) { + return false; + } + // check we never send twice on one day if ($daysSinceLastSent == 0) { return false; } diff --git a/app/Models/Traits/GeneratesNumbers.php b/app/Models/Traits/GeneratesNumbers.php index aabd6a69f148..09bbc923c7e0 100644 --- a/app/Models/Traits/GeneratesNumbers.php +++ b/app/Models/Traits/GeneratesNumbers.php @@ -161,8 +161,8 @@ trait GeneratesNumbers if (count($matches) > 1) { $format = $matches[1]; $search[] = $matches[0]; - $date = date_create()->format($format); - //$date = Carbon::now(session(SESSION_TIMEZONE, DEFAULT_TIMEZONE))->format($format); + //$date = date_create()->format($format); + $date = Carbon::now(session(SESSION_TIMEZONE, DEFAULT_TIMEZONE))->format($format); $replace[] = str_replace($format, $date, $matches[1]); }