mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Reset the invoice schema counter
- 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
This commit is contained in:
parent
386c606558
commit
790766c028
65
app/Console/Commands/ResetInvoiceSchemaCounter.php
Normal file
65
app/Console/Commands/ResetInvoiceSchemaCounter.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Invoice;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ResetInvoiceSchemaCounter extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:reset-invoice-schema-counter
|
||||
{--force : Force setting the counter back to "1", regardless if the year changed}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Reset the invoice schema counter at the turn of the year.';
|
||||
|
||||
/**
|
||||
* @var Account
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* @var Invoice
|
||||
*/
|
||||
protected $invoice;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(Account $account, Invoice $invoice)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user