mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 05:10:59 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Sales\Http\Resources;
|
|
|
|
/**
|
|
* API representation of a credit note (Stornorechnung).
|
|
*
|
|
* A credit note is an invoice with type = CREDIT_NOTE, so this mirrors
|
|
* InvoiceResource and adds the credit-note specific fields: the type and a
|
|
* compact reference to the original invoice it reverses. Using a dedicated
|
|
* resource (rather than PaymentResource, which was the bug in PR #536) keeps
|
|
* the credit-note payload explicit and self-describing.
|
|
*/
|
|
class CreditNoteResource extends InvoiceResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*/
|
|
public function toArray($request): array
|
|
{
|
|
return array_merge(parent::toArray($request), [
|
|
// type + related_invoice_id come from InvoiceResource; this adds the
|
|
// expanded reference to the original invoice being reversed.
|
|
// Read off the loaded relation rather than probing it: the caller
|
|
// eager-loads relatedInvoice, so an exists() query here would be
|
|
// pure overhead.
|
|
'related_invoice' => $this->when(
|
|
$this->relationLoaded('relatedInvoice') && $this->relatedInvoice !== null,
|
|
function () {
|
|
$related = $this->relatedInvoice;
|
|
|
|
return [
|
|
'id' => $related->id,
|
|
'invoice_number' => $related->invoice_number,
|
|
'invoice_date' => $related->invoice_date,
|
|
'formatted_invoice_date' => $related->formattedInvoiceDate,
|
|
'total' => $related->total,
|
|
'unique_hash' => $related->unique_hash,
|
|
];
|
|
}
|
|
),
|
|
]);
|
|
}
|
|
}
|