Add invoice/estimate/payment number length setting (#425)

* Add invoice/estimate/payment number length setting
This commit is contained in:
Florian Gareis
2021-03-26 08:31:43 +01:00
committed by GitHub
parent 3f7db2793f
commit bfd9850bf6
15 changed files with 209 additions and 24 deletions

View File

@ -78,6 +78,10 @@ class Estimate extends Model implements HasMedia
->orderBy('estimate_number', 'desc')
->first();
// Get number length config
$numberLength = CompanySetting::getSetting('estimate_number_length', request()->header('company'));
$numberLengthText = "%0{$numberLength}d";
if (!$lastOrder) {
// We get here if there is no order at all
// If there is no number set it to 0, which will be 1 at the end.
@ -94,7 +98,7 @@ class Estimate extends Model implements HasMedia
// the %05d part makes sure that there are always 6 numbers in the string.
// so it adds the missing zero's when needed.
return sprintf('%06d', intval($number) + 1);
return sprintf($numberLengthText, intval($number) + 1);
}
public function emailLogs()

View File

@ -82,6 +82,9 @@ class Invoice extends Model implements HasMedia
->orderBy('invoice_number', 'desc')
->first();
// Get number length config
$numberLength = CompanySetting::getSetting('invoice_number_length', request()->header('company'));
$numberLengthText = "%0{$numberLength}d";
if (!$lastOrder) {
// We get here if there is no order at all
@ -98,7 +101,7 @@ class Invoice extends Model implements HasMedia
// the %06d part makes sure that there are always 6 numbers in the string.
// so it adds the missing zero's when needed.
return sprintf('%06d', intval($number) + 1);
return sprintf($numberLengthText, intval($number) + 1);
}
public function emailLogs()

View File

@ -271,6 +271,11 @@ class Payment extends Model implements HasMedia
$payment = Payment::where('payment_number', 'LIKE', $value . '-%')
->orderBy('payment_number', 'desc')
->first();
// Get number length config
$numberLength = CompanySetting::getSetting('payment_number_length', request()->header('company'));
$numberLengthText = "%0{$numberLength}d";
if (!$payment) {
// We get here if there is no order at all
// If there is no number set it to 0, which will be 1 at the end.
@ -286,7 +291,7 @@ class Payment extends Model implements HasMedia
// the %05d part makes sure that there are always 6 numbers in the string.
// so it adds the missing zero's when needed.
return sprintf('%06d', intval($number) + 1);
return sprintf($numberLengthText, intval($number) + 1);
}
public function scopeWhereSearch($query, $search)