ClassPackageUnitResource.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use App\Http\Resources\Concerns\SerializesProposalPricing;
  7. class ClassPackageUnitResource extends JsonResource
  8. {
  9. use SerializesProposalPricing;
  10. public function toArray(Request $request): array
  11. {
  12. return [
  13. 'id' => $this->id,
  14. 'unit_id' => $this->unit_id,
  15. 'class_package_id' => $this->class_package_id,
  16. 'name' => $this->name,
  17. 'quantity_classes' => $this->quantity_classes,
  18. 'contract_value' => $this->contract_value,
  19. 'contract_material_value' => $this->contract_material_value,
  20. 'contract_register_value' => $this->contract_register_value,
  21. 'contrat_discount_value' => $this->contrat_discount_value,
  22. 'visible' => $this->visible,
  23. 'class_duration_minutes' => $this->class_duration_minutes,
  24. 'weekday' => $this->weekday,
  25. 'start_time' => $this->start_time,
  26. 'second_weekday' => $this->second_weekday,
  27. 'second_start_time' => $this->second_start_time,
  28. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  29. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  30. 'materials' => $this->whenLoaded('products', fn() =>
  31. $this->products->map(fn($item) => [
  32. 'product_id' => $item->product_id,
  33. 'name' => $item->product?->name,
  34. 'quantity' => $item->quantity,
  35. 'price' => (float) $item->price,
  36. ])
  37. ),
  38. 'pavao' => $this->whenLoaded('pavaoProposalUnit', fn() => $this->proposalPricingArray($this->pavaoProposalUnit)),
  39. 'irrecusavel' => $this->whenLoaded('irrecusableProposalUnit', fn() => $this->proposalPricingArray($this->irrecusableProposalUnit, withCondition: true)),
  40. ];
  41. }
  42. }