diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index 2cb1535c5bee..9387866e3685 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -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']; diff --git a/app/Models/Client.php b/app/Models/Client.php index 5c414e978ae4..7b09fa68f80e 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -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; } diff --git a/app/Services/Invoice/ApplyNumber.php b/app/Services/Invoice/ApplyNumber.php index 58b976eb2b86..d71faf7c73ae 100644 --- a/app/Services/Invoice/ApplyNumber.php +++ b/app/Services/Invoice/ApplyNumber.php @@ -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; } + } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 9dea5d139e02..2debb8ac9647 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -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; }