2025-10-09 18:25:02 +03:00

63 lines
2.6 KiB
PHP

<?php
namespace App\Http\Resources\Client;
use App\Http\Resources\Contact\ContactResource;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClientResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
//'company_id' => $this->company_id,
'commercial' => $this->commercial(),
'type_label' => $this->getTypeLabel(),
'name' => $this->name,
'vat_number' => $this->vat_number,
'siret' => $this->siret,
'email' => $this->email,
'phone' => $this->phone,
'billing_address' => [
'line1' => $this->billing_address_line1,
'line2' => $this->billing_address_line2,
'postal_code' => $this->billing_postal_code,
'city' => $this->billing_city,
'country_code' => $this->billing_country_code,
'full_address' => $this->billing_address,
],
'group_id' => $this->group_id,
'notes' => $this->notes,
'is_active' => $this->is_active,
// 'default_tva_rate_id' => $this->default_tva_rate_id,
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
// Counts
'contacts_count' => $this->whenCounted('contacts'),
'locations_count' => $this->whenCounted('locations'),
// 'interventions_count' => $this->whenCounted('interventions'),
// 'quotes_count' => $this->whenCounted('quotes'),
// 'invoices_count' => $this->whenCounted('invoices'),
// Relations
// 'company' => new CompanyResource($this->whenLoaded('company')),
'group' => new ClientGroupResource($this->whenLoaded('group')),
// 'default_tva_rate' => new TvaRateResource($this->whenLoaded('defaultTvaRate')),
'contacts' => ContactResource::collection($this->whenLoaded('contacts')),
'locations' => ClientLocationResource::collection($this->whenLoaded('locations')),
// 'price_lists' => PriceListResource::collection($this->whenLoaded('priceLists')),
// 'interventions' => InterventionResource::collection($this->whenLoaded('interventions')),
// 'quotes' => QuoteResource::collection($this->whenLoaded('quotes')),
// 'invoices' => InvoiceResource::collection($this->whenLoaded('invoices')),
];
}
}