Fixes for applying numbers

This commit is contained in:
David Bomba 2022-09-12 21:08:50 +10:00
parent 9dd06fae34
commit a1629bbab4
4 changed files with 8 additions and 18 deletions

View File

@ -62,7 +62,7 @@ class StoreInvoiceRequest extends Request
$rules['invitations.*.client_contact_id'] = 'distinct';
$rules['number'] = ['nullable', Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)];
$rules['number'] = ['bail', 'nullable', Rule::unique('invoices')->where('company_id', auth()->user()->company()->id)];
$rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];
$rules['is_amount_discount'] = ['boolean'];

View File

@ -613,19 +613,19 @@ class Client extends BaseModel implements HasLocalePreference
{
$defaults = [];
if (! (array_key_exists('terms', $data) && strlen($data['terms']) > 1)) {
if (! (array_key_exists('terms', $data) && is_string($data['terms']) && strlen($data['terms']) > 1)) {
$defaults['terms'] = $this->getSetting($entity_name.'_terms');
} elseif (array_key_exists('terms', $data)) {
$defaults['terms'] = $data['terms'];
}
if (! (array_key_exists('footer', $data) && strlen($data['footer']) > 1)) {
if (! (array_key_exists('footer', $data) && is_string($data['footer']) && strlen($data['footer']) > 1)) {
$defaults['footer'] = $this->getSetting($entity_name.'_footer');
} elseif (array_key_exists('footer', $data)) {
$defaults['footer'] = $data['footer'];
}
if (strlen($this->public_notes) >= 1) {
if (is_string($this->public_notes) && strlen($this->public_notes) >= 1) {
$defaults['public_notes'] = $this->public_notes;
}

View File

@ -70,7 +70,6 @@ class ApplyNumber extends AbstractService
$this->invoice->saveQuietly();
$this->completed = false;
}
catch(QueryException $e){
@ -84,5 +83,8 @@ class ApplyNumber extends AbstractService
}
while($this->completed);
return $this;
}
}

View File

@ -416,10 +416,8 @@ trait GeneratesCounter
{
$check = false;
$check_counter = 1;
$original_counter = $counter;
do {
nlog($check_counter);
$number = $this->padCounter($counter, $padding);
@ -433,21 +431,13 @@ trait GeneratesCounter
$check_counter++;
if ($check_counter > 100) {
nlog("counter error");
nlog("check counter = {$check_counter}");
nlog("original_counter = {$original_counter}");
nlog("entity company = {$entity->company_id}");
nlog("counter = {$counter}");
nlog("returning = {$number}");
return $number.'_'.Str::random(5);
}
} while ($check);
nlog($number);
return $number;
}
@ -472,12 +462,10 @@ trait GeneratesCounter
$settings = $entity->settings;
if ($counter_name == 'invoice_number_counter' && ! property_exists($entity->settings, 'invoice_number_counter')) {
nlog("BAD STATE - why no invoice_number_counter set?");
$settings->invoice_number_counter = 0;
}
if (! property_exists($settings, $counter_name)) {
nlog("BAD STATE - why no {$counter_name} set?");
$settings->{$counter_name} = 1;
}