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;
|
|
|
|
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 [
|
|
|
|
'to_name' => $this->to['name'],
|
|
|
|
'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-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 20:35:28 +01:00
|
|
|
],
|
|
|
|
'vias' => BillKind::forSelect(),
|
|
|
|
'statuses' => InvoiceStatus::forSelect(),
|
2023-12-16 01:13:49 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|