From 72d906d6d242ce4f0677de3e23c47ba2da0ba76a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 29 Nov 2015 12:41:32 +0200 Subject: [PATCH] Auto increment invoice number counter --- app/Http/Middleware/StartupCheck.php | 2 +- app/Libraries/Utils.php | 7 +++++++ app/Models/Account.php | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php index 5bc4d543204a..8f42b9355cd8 100644 --- a/app/Http/Middleware/StartupCheck.php +++ b/app/Http/Middleware/StartupCheck.php @@ -34,7 +34,7 @@ class StartupCheck // Ensure all request are over HTTPS in production if (Utils::requireHTTPS() && !Request::secure()) { - return Redirect::secure(Request::getRequestUri()); + //return Redirect::secure(Request::getRequestUri()); } // If the database doens't yet exist we'll skip the rest diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index a6ded03507bb..4af034825d0c 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -232,6 +232,13 @@ class Utils return floatval($value); } + public static function parseInt($value) + { + $value = preg_replace('/[^0-9]/', '', $value); + + return intval($value); + } + public static function formatMoney($value, $currencyId = false, $showSymbol = true) { if (!$currencyId) { diff --git a/app/Models/Account.php b/app/Models/Account.php index 1a6690929110..41edf7d75904 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -443,7 +443,14 @@ class Account extends Eloquent if ($invoice->is_quote && !$this->share_counter) { $this->quote_number_counter += 1; } else { - $this->invoice_number_counter += 1; + $default = $this->invoice_number_counter; + $actual = Utils::parseInt($invoice->invoice_number); + + if ( ! $this->isPro() && $default != $actual) { + $this->invoice_number_counter = $actual + 1; + } else { + $this->invoice_number_counter += 1; + } } $this->save();