Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Mar 25, 2024
1 parent 46422d7 commit 555077c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function getPreviousInvoice(): ?static
$invoice = static::query()
->when($this->getSerialNumberPrefix(), fn (Builder $query) => $query->where('serial_number_details->prefix', $this->getSerialNumberPrefix()))
->when($this->getSerialNumberSerie(), fn (Builder $query) => $query->where('serial_number_details->serie', $this->getSerialNumberSerie()))
->latest('serial_number')
->latest('serial_number_details->count')
->first();

return $invoice;
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@
'year' => (int) $year,
'count' => 2,
]);

/** @var Invoice */
$invoice = Invoice::factory()->make();
$invoice->setSerialNumberSerie(42);
$invoice->setSerialNumberPrefix('ORG');

$invoice->save();

expect($invoice->serial_number)->toBe("ORG000042-{$year}0003");
expect($invoice->serial_number_details)->toMatchArray([
'prefix' => 'ORG',
'serie' => 42,
'month' => null,
'year' => (int) $year,
'count' => 3,
]);
});

it('denormalize amounts in invoice', function () {
Expand Down

0 comments on commit 555077c

Please sign in to comment.