From 790766c0289867e1ee85c55be5fd6822c7578dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Sat, 9 Jul 2016 23:38:33 +0200 Subject: [PATCH] Reset the invoice schema counter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix #585 and resolve #585 - Reset the invoice schema counter back to „1“ at the turn of the year - Implemented as command the also call it manually --- .../Commands/ResetInvoiceSchemaCounter.php | 65 +++++++++++++++++++ app/Console/Kernel.php | 5 ++ 2 files changed, 70 insertions(+) create mode 100644 app/Console/Commands/ResetInvoiceSchemaCounter.php diff --git a/app/Console/Commands/ResetInvoiceSchemaCounter.php b/app/Console/Commands/ResetInvoiceSchemaCounter.php new file mode 100644 index 000000000000..e5e0bf217904 --- /dev/null +++ b/app/Console/Commands/ResetInvoiceSchemaCounter.php @@ -0,0 +1,65 @@ +account = $account; + $this->invoice = $invoice; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $latestInvoice = $this->invoice->latest()->first(); + $invoiceYear = Carbon::parse($latestInvoice->created_at)->year; + + if(Carbon::now()->year > $invoiceYear || $this->option('force')) { + $this->account->invoice_number_counter = 1; + $this->account->update(); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 179e423388f1..fe91080b8e41 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -15,6 +15,7 @@ class Kernel extends ConsoleKernel 'App\Console\Commands\SendRecurringInvoices', 'App\Console\Commands\RemoveOrphanedDocuments', 'App\Console\Commands\ResetData', + 'App\Console\Commands\ResetInvoiceSchemaCounter', 'App\Console\Commands\CheckData', 'App\Console\Commands\PruneData', 'App\Console\Commands\CreateTestData', @@ -52,5 +53,9 @@ class Kernel extends ConsoleKernel ->sendOutputTo($logFile) ->daily(); } + + $schedule + ->command('ninja:reset-invoice-schema-counter') + ->daily(); } }