Skip to content

Commit

Permalink
add proformat and better default serial number prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Feb 5, 2024
1 parent c19404c commit 2bc6fca
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
8 changes: 7 additions & 1 deletion config/invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Finller\Invoice\Invoice;
use Finller\Invoice\InvoiceDiscount;
use Finller\Invoice\InvoiceItem;
use Finller\Invoice\InvoiceType;

return [

Expand Down Expand Up @@ -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',
],

],

Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
'invoice' => 'Invoice',
'quote' => 'Quote',
'credit' => 'Credit note',
'proforma' => 'Proforma invoice',
],
];
1 change: 1 addition & 0 deletions resources/lang/fr/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
'invoice' => 'Facture',
'quote' => 'Devis',
'credit' => "Facture d'avoir",
'proforma' => 'Facture Proforma',
],
];
18 changes: 17 additions & 1 deletion src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 247 in src/Invoice.php

View workflow job for this annotation

GitHub Actions / phpstan

Using nullsafe property access on non-nullable type Finller\Invoice\InvoiceType. Use -> instead.
}

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
Expand Down
2 changes: 2 additions & 0 deletions src/InvoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ enum InvoiceType: string
case Invoice = 'invoice';
case Quote = 'quote';
case Credit = 'credit';
case Proforma = 'proforma';

public function trans()
{
return match ($this) {
self::Invoice => __('invoices::invoice.types.invoice'),
self::Quote => __('invoices::invoice.types.quote'),
self::Credit => __('invoices::invoice.types.credit'),
self::Proforma => __('invoices::invoice.types.proforma'),
};
}
}
1 change: 0 additions & 1 deletion src/SerialNumberGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2bc6fca

Please sign in to comment.