From 2bc6fca6b3794fb0d386cd1c91bb18b3000b41af Mon Sep 17 00:00:00 2001 From: Quentin Gabriele Date: Mon, 5 Feb 2024 16:06:43 +0100 Subject: [PATCH] add proformat and better default serial number prefix --- config/invoices.php | 8 +++++++- resources/lang/en/invoice.php | 1 + resources/lang/fr/invoice.php | 1 + src/Invoice.php | 18 +++++++++++++++++- src/InvoiceType.php | 2 ++ src/SerialNumberGenerator.php | 1 - 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/config/invoices.php b/config/invoices.php index 1f6f25c..7de5e3d 100644 --- a/config/invoices.php +++ b/config/invoices.php @@ -5,6 +5,7 @@ use Finller\Invoice\Invoice; use Finller\Invoice\InvoiceDiscount; use Finller\Invoice\InvoiceItem; +use Finller\Invoice\InvoiceType; return [ @@ -39,7 +40,12 @@ */ 'format' => 'PPYYCCCC', - 'prefix' => 'IN', + 'prefix' => [ + InvoiceType::Invoice->value => 'IN', + InvoiceType::Quote->value => 'QO', + InvoiceType::Credit->value => 'CR', + InvoiceType::Proforma->value => 'PF', + ], ], diff --git a/resources/lang/en/invoice.php b/resources/lang/en/invoice.php index 47124d8..2cf6868 100644 --- a/resources/lang/en/invoice.php +++ b/resources/lang/en/invoice.php @@ -32,5 +32,6 @@ 'invoice' => 'Invoice', 'quote' => 'Quote', 'credit' => 'Credit note', + 'proforma' => 'Proforma invoice', ], ]; diff --git a/resources/lang/fr/invoice.php b/resources/lang/fr/invoice.php index 71046eb..6f2173e 100644 --- a/resources/lang/fr/invoice.php +++ b/resources/lang/fr/invoice.php @@ -32,5 +32,6 @@ 'invoice' => 'Facture', 'quote' => 'Devis', 'credit' => "Facture d'avoir", + 'proforma' => 'Facture Proforma', ], ]; diff --git a/src/Invoice.php b/src/Invoice.php index b425ce8..9364528 100644 --- a/src/Invoice.php +++ b/src/Invoice.php @@ -232,9 +232,25 @@ public function setSerialNumberDate(Carbon $value): static return $this; } + /** + * Retrieve the matching prefix according to the invoice type + */ + public function getSerialNumberPrefixFromConfig(string $default = ''): string + { + /** @var string|array $prefixes */ + $prefixes = config('invoices.serial_number.prefix', ''); + + if (is_string($prefixes)) { + return $prefixes; + } + + return data_get($prefixes, $this->type?->value, $default); + } + public function getSerialNumberPrefix(): ?string { - return data_get($this->serial_number_details, 'prefix', config('invoices.serial_number.prefix')); + + return data_get($this->serial_number_details, 'prefix', $this->getSerialNumberPrefixFromConfig()); } public function getSerialNumberSerie(): ?int diff --git a/src/InvoiceType.php b/src/InvoiceType.php index 02c38b6..b3322e8 100644 --- a/src/InvoiceType.php +++ b/src/InvoiceType.php @@ -7,6 +7,7 @@ enum InvoiceType: string case Invoice = 'invoice'; case Quote = 'quote'; case Credit = 'credit'; + case Proforma = 'proforma'; public function trans() { @@ -14,6 +15,7 @@ public function trans() self::Invoice => __('invoices::invoice.types.invoice'), self::Quote => __('invoices::invoice.types.quote'), self::Credit => __('invoices::invoice.types.credit'), + self::Proforma => __('invoices::invoice.types.proforma'), }; } } diff --git a/src/SerialNumberGenerator.php b/src/SerialNumberGenerator.php index f3b0605..319fad8 100644 --- a/src/SerialNumberGenerator.php +++ b/src/SerialNumberGenerator.php @@ -9,7 +9,6 @@ public function __construct( public ?string $prefix = null, ) { $this->format = $format ?? config('invoices.serial_number.format', ''); - $this->prefix = $prefix ?? config('invoices.serial_number.prefix', ''); } public function generate(