mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Improve resilience of client number creation
This commit is contained in:
parent
59fdc51ce0
commit
20c2a1690f
@ -14,6 +14,9 @@ namespace App\Http\Requests\Preview;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Http\ValidationRules\Project\ValidProjectForClient;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Validation\Rule;
|
||||
@ -30,15 +33,13 @@ class PreviewInvoiceRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('create', Invoice::class);
|
||||
return auth()->user()->can('create', Invoice::class) || auth()->user()->can('create', Quote::class) || auth()->user()->can('create', RecurringInvoice::class) || auth()->user()->can('create', Credit::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
$rules = [];
|
||||
|
||||
// $rules['client_id'] = 'bail|required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
|
||||
$rules['number'] = ['nullable'];
|
||||
|
||||
return $rules;
|
||||
|
@ -17,6 +17,7 @@ use App\Models\Company;
|
||||
use App\Utils\Traits\ClientGroupSettingsSaver;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\SavesDocuments;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
/**
|
||||
* ClientRepository.
|
||||
@ -26,6 +27,8 @@ class ClientRepository extends BaseRepository
|
||||
use GeneratesCounter;
|
||||
use SavesDocuments;
|
||||
|
||||
private bool $completed = true;
|
||||
|
||||
/**
|
||||
* @var ClientContactRepository
|
||||
*/
|
||||
@ -76,8 +79,35 @@ class ClientRepository extends BaseRepository
|
||||
|
||||
|
||||
if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) {
|
||||
$client->number = $this->getNextClientNumber($client);
|
||||
$client->save();
|
||||
// $client->number = $this->getNextClientNumber($client);
|
||||
// $client->save();
|
||||
|
||||
$x=1;
|
||||
|
||||
do{
|
||||
|
||||
try{
|
||||
|
||||
$client->number = $this->getNextClientNumber($client);
|
||||
$client->saveQuietly();
|
||||
|
||||
$this->completed = false;
|
||||
|
||||
|
||||
}
|
||||
catch(QueryException $e){
|
||||
|
||||
$x++;
|
||||
|
||||
if($x>10)
|
||||
$this->completed = false;
|
||||
}
|
||||
|
||||
}
|
||||
while($this->completed);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (empty($data['name'])) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user