FranchiseeAccountReceiveResource.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class FranchiseeAccountReceiveResource extends JsonResource
  8. {
  9. public function toArray(Request $request): array
  10. {
  11. return [
  12. 'id' => $this->id,
  13. 'unit_id' => $this->unit_id,
  14. 'unit_name' => $this->whenLoaded('unit', fn () => $this->unit?->fantasy_name),
  15. 'tbr_calculation_id' => $this->tbr_calculation_id,
  16. 'origin' => $this->origin,
  17. 'financial_plan_account_id' => $this->financial_plan_account_id,
  18. 'plan_account' => $this->whenLoaded('planAccount', fn () => $this->planAccount ? [
  19. 'id' => $this->planAccount->id,
  20. 'code' => $this->planAccount->code,
  21. 'description' => $this->planAccount->description,
  22. ] : null),
  23. 'order' => $this->order,
  24. 'history' => $this->history,
  25. 'value' => $this->value,
  26. 'paid_value' => $this->paid_value,
  27. 'due_date' => $this->due_date?->format('Y-m-d'),
  28. 'discount' => $this->discount,
  29. 'fees' => $this->fees,
  30. 'obs' => $this->obs,
  31. 'asaas_id' => $this->asaas_id,
  32. 'status' => $this->status,
  33. 'payment_date' => $this->payment_date?->format('Y-m-d'),
  34. 'details' => $this->whenLoaded('details', fn () => $this->details->map(fn ($d) => [
  35. 'id' => $d->id,
  36. 'value' => $d->value,
  37. 'history' => $d->history,
  38. ])),
  39. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  40. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  41. ];
  42. }
  43. public static function collection($resource): AnonymousResourceCollection
  44. {
  45. return parent::collection($resource);
  46. }
  47. }