2023-12-16 01:13:49 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Invoice\Resources;
|
|
|
|
|
2023-12-16 20:35:28 +01:00
|
|
|
use App\Invoice\BillKind;
|
|
|
|
use App\Invoice\Enums\InvoiceStatus;
|
2023-12-16 01:13:49 +01:00
|
|
|
use App\Invoice\Models\Invoice;
|
|
|
|
use App\Lib\HasMeta;
|
2023-12-16 23:52:41 +01:00
|
|
|
use App\Member\Member;
|
2023-12-16 01:13:49 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin Invoice
|
|
|
|
*/
|
|
|
|
class InvoiceResource extends JsonResource
|
|
|
|
{
|
|
|
|
|
|
|
|
use HasMeta;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
2023-12-17 00:45:03 +01:00
|
|
|
'id' => $this->id,
|
|
|
|
'to' => $this->to,
|
2023-12-16 01:13:49 +01:00
|
|
|
'sum_human' => number_format($this->positions->sum('price') / 100, 2, ',', '') . ' €',
|
2023-12-16 13:08:17 +01:00
|
|
|
'sent_at_human' => $this->sent_at?->format('d.m.Y') ?: '',
|
2023-12-16 01:13:49 +01:00
|
|
|
'status' => $this->status->value,
|
2023-12-16 11:18:00 +01:00
|
|
|
'via' => $this->via->value,
|
2023-12-17 00:45:03 +01:00
|
|
|
'positions' => InvoicePositionResource::collection($this->whenLoaded('positions')),
|
|
|
|
'greeting' => $this->greeting,
|
|
|
|
'links' => [
|
|
|
|
'update' => route('invoice.update', ['invoice' => $this->getModel()]),
|
2023-12-17 00:55:31 +01:00
|
|
|
'destroy' => route('invoice.destroy', ['invoice' => $this->getModel()]),
|
2023-12-17 00:45:03 +01:00
|
|
|
]
|
2023-12-16 01:13:49 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'links' => [
|
|
|
|
'mass-store' => route('invoice.mass-store'),
|
2023-12-16 22:30:56 +01:00
|
|
|
'store' => route('invoice.store'),
|
2023-12-16 20:35:28 +01:00
|
|
|
],
|
|
|
|
'vias' => BillKind::forSelect(),
|
|
|
|
'statuses' => InvoiceStatus::forSelect(),
|
2023-12-16 23:52:41 +01:00
|
|
|
'members' => Member::forSelect(),
|
2023-12-16 22:30:56 +01:00
|
|
|
'default' => [
|
|
|
|
'to' => [
|
|
|
|
'name' => '',
|
|
|
|
'address' => '',
|
|
|
|
'zip' => '',
|
|
|
|
'location' => '',
|
|
|
|
],
|
|
|
|
'positions' => [],
|
|
|
|
'greeting' => '',
|
|
|
|
'status' => InvoiceStatus::NEW->value,
|
|
|
|
'via' => null,
|
|
|
|
],
|
|
|
|
'default_position' => [
|
2023-12-17 00:45:03 +01:00
|
|
|
'id' => null,
|
2023-12-16 22:30:56 +01:00
|
|
|
'price' => 0,
|
|
|
|
'description' => '',
|
2023-12-16 23:52:41 +01:00
|
|
|
'member_id' => null,
|
2023-12-16 22:30:56 +01:00
|
|
|
]
|
2023-12-16 01:13:49 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|