mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 19:00:55 -04:00
Refactor client invoice/quote counter
This commit is contained in:
parent
5791e2bc9f
commit
f40b72c014
@ -64,9 +64,8 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
*/
|
||||
public static $patternFields = [
|
||||
'counter',
|
||||
'clientCounter',
|
||||
'clientIdNumber',
|
||||
'clientInvoiceCounter',
|
||||
'clientQuoteCounter',
|
||||
'clientCustom1',
|
||||
'clientCustom2',
|
||||
'userId',
|
||||
|
@ -191,8 +191,7 @@ trait GeneratesNumbers
|
||||
'{$clientCustom1}',
|
||||
'{$clientCustom2}',
|
||||
'{$clientIdNumber}',
|
||||
'{$clientInvoiceCounter}',
|
||||
'{$clientQuoteCounter}',
|
||||
'{$clientCounter}',
|
||||
];
|
||||
|
||||
$replace = [
|
||||
@ -253,10 +252,11 @@ trait GeneratesNumbers
|
||||
}
|
||||
|
||||
if ($this->usesClientInvoiceCounter()) {
|
||||
$entity->client->invoice_number_counter += 1;
|
||||
$entity->client->save();
|
||||
} elseif ($this->usesClientQuoteCounter()) {
|
||||
$entity->client->quote_number_counter += 1;
|
||||
if ($entity->isType(INVOICE_TYPE_QUOTE) && ! $this->share_counter) {
|
||||
$entity->client->quote_number_counter += 1;
|
||||
} else {
|
||||
$entity->client->invoice_number_counter += 1;
|
||||
}
|
||||
$entity->client->save();
|
||||
}
|
||||
|
||||
@ -277,12 +277,7 @@ trait GeneratesNumbers
|
||||
|
||||
public function usesClientInvoiceCounter()
|
||||
{
|
||||
return strpos($this->invoice_number_pattern, '{$clientInvoiceCounter}') !== false;
|
||||
}
|
||||
|
||||
public function usesClientQuoteCounter()
|
||||
{
|
||||
return strpos($this->invoice_number_pattern, '{$clientQuoteCounter}') !== false;
|
||||
return strpos($this->invoice_number_pattern, '{$clientCounter}') !== false;
|
||||
}
|
||||
|
||||
public function clientNumbersEnabled()
|
||||
|
@ -183,7 +183,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
return ((strstr($value, '{$idNumber}') !== false || strstr($value, '{$clientIdNumber}') != false) && (strstr($value, '{$clientInvoiceCounter}') || strstr($value, '{$clientQuoteCounter}')));
|
||||
return ((strstr($value, '{$idNumber}') !== false || strstr($value, '{$clientIdNumber}') != false) && (strstr($value, '{$clientCounter}')));
|
||||
});
|
||||
|
||||
Validator::extend('valid_invoice_items', function ($attribute, $value, $parameters) {
|
||||
|
@ -73,7 +73,7 @@ return array(
|
||||
"has_credit" => "The client does not have enough credit.",
|
||||
"notmasked" => "The values are masked",
|
||||
"less_than" => "The :attribute must be less than :value",
|
||||
"has_counter" => "To enusre all invoice numbers are unique the pattern needs to contain either {\$counter} or {\$clientIdNumber} and {\$clientInvoiceCounter}",
|
||||
"has_counter" => "To enusre all invoice numbers are unique the pattern needs to contain either {\$counter} or {\$clientIdNumber} and {\$clientCounter}",
|
||||
"valid_contacts" => "The contact must have either an email or name",
|
||||
"valid_invoice_items" => "The invoice exceeds the maximum amount",
|
||||
"valid_subdomain" => "The subdomain is restricted",
|
||||
|
@ -59,10 +59,10 @@
|
||||
|
||||
@if ($account->usesClientInvoiceCounter())
|
||||
{!! Former::text('invoice_number_counter')->label('invoice_counter') !!}
|
||||
@endif
|
||||
|
||||
@if ($account->usesClientQuoteCounter())
|
||||
{!! Former::text('quote_number_counter')->label('quote_counter') !!}
|
||||
@if (! $account->share_counter)
|
||||
{!! Former::text('quote_number_counter')->label('quote_counter') !!}
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1629,8 +1629,11 @@
|
||||
number = number.replace('{$clientCustom1}', client.custom_value1 ? client.custom_value1 : '');
|
||||
number = number.replace('{$clientCustom2}', client.custom_value2 ? client.custom_value1 : '');
|
||||
number = number.replace('{$clientIdNumber}', client.id_number ? client.id_number : '');
|
||||
number = number.replace('{$clientInvoiceCounter}', pad(client.invoice_number_counter, {{ $account->invoice_number_padding }}));
|
||||
number = number.replace('{$clientQuoteCounter}', pad(client.quote_number_counter, {{ $account->invoice_number_padding }}));
|
||||
@if ($invoice->isQuote() && ! $account->share_counter)
|
||||
number = number.replace('{$clientCounter}', pad(client.quote_number_counter, {{ $account->invoice_number_padding }}));
|
||||
@else
|
||||
number = number.replace('{$clientCounter}', pad(client.invoice_number_counter, {{ $account->invoice_number_padding }}));
|
||||
@endif
|
||||
// backwards compatibility
|
||||
number = number.replace('{$custom1}', client.custom_value1 ? client.custom_value1 : '');
|
||||
number = number.replace('{$custom2}', client.custom_value2 ? client.custom_value1 : '');
|
||||
|
Loading…
x
Reference in New Issue
Block a user