diff --git a/app/Console/Commands/ResetInvoiceSchemaCounter.php b/app/Console/Commands/ResetInvoiceSchemaCounter.php index 2f3a231d188e..ed849a25a26f 100644 --- a/app/Console/Commands/ResetInvoiceSchemaCounter.php +++ b/app/Console/Commands/ResetInvoiceSchemaCounter.php @@ -15,7 +15,7 @@ class ResetInvoiceSchemaCounter extends Command * @var string */ protected $signature = 'ninja:reset-invoice-schema-counter - {account : The ID of the account} + {account? : The ID of the account} {--force : Force setting the counter back to "1", regardless if the year changed}'; /** @@ -48,14 +48,28 @@ class ResetInvoiceSchemaCounter extends Command */ public function handle() { + $force = $this->option('force'); + $account = $this->argument('account'); + + $accounts = null; + + if ($account) { + $accounts = Account::find($account)->get(); + } else { + $accounts = Account::all(); + } + $latestInvoice = $this->invoice->latest()->first(); $invoiceYear = Carbon::parse($latestInvoice->created_at)->year; - if(Carbon::now()->year > $invoiceYear || $this->option('force')) { - $account = Account::find($this->argument('account'))->first(); - $account->invoice_number_counter = 1; - $account->update(); - $this->info('The counter has been resetted successfully.'); + if(Carbon::now()->year > $invoiceYear || $force) { + $accounts->transform(function ($a) { + /** @var Account $a */ + $a->invoice_number_counter = 1; + $a->update(); + }); + + $this->info('The counter has been resetted successfully for '.$accounts->count().' account(s).'); } } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fe91080b8e41..5dcc14da2f6f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -54,6 +54,7 @@ class Kernel extends ConsoleKernel ->daily(); } + // Reset the invoice schema counter at the turn of the year $schedule ->command('ninja:reset-invoice-schema-counter') ->daily();