diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index c0cf2bd37..2d6d1c26c 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -550,17 +550,7 @@ abstract class DocumentForm extends Base return $document->document_number; } - $next = $type; - - if ($alias = config('type.' . $type . '.alias')) { - $next = $alias . '.' . str_replace('-', '_', $type); - } - - $document_number = $this->getNextDocumentNumber($next); - - if (empty($document_number)) { - $document_number = $this->getNextDocumentNumber($type); - } + $document_number = $this->getNextDocumentNumber($type); if (empty($document_number)) { $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE); diff --git a/app/Traits/Documents.php b/app/Traits/Documents.php index d4e7137dc..6caeaacab 100644 --- a/app/Traits/Documents.php +++ b/app/Traits/Documents.php @@ -11,6 +11,10 @@ trait Documents { public function getNextDocumentNumber(string $type): string { + if ($alias = config('type.' . $type . '.alias')) { + $type = $alias . '.' . str_replace('-', '_', $type); + } + $prefix = setting("$type.number_prefix"); $next = setting("$type.number_next"); $digit = setting("$type.number_digit"); @@ -20,6 +24,10 @@ trait Documents public function increaseNextDocumentNumber(string $type): void { + if ($alias = config('type.' . $type . '.alias')) { + $type = $alias . '.' . str_replace('-', '_', $type); + } + $next = setting("$type.number_next", 1) + 1; setting(["$type.number_next" => $next]);