FranchiseeAccountReceiveResource.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 'invoice_url' => $this->invoice_url,
  33. 'asaas_status' => $this->asaas_status,
  34. 'status' => $this->status,
  35. 'payment_date' => $this->payment_date?->format('Y-m-d'),
  36. 'details' => $this->whenLoaded('details', fn () => $this->details->map(fn ($d) => [
  37. 'id' => $d->id,
  38. 'value' => $d->value,
  39. 'history' => $d->history,
  40. ])),
  41. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  42. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  43. ];
  44. }
  45. public static function collection($resource): AnonymousResourceCollection
  46. {
  47. return parent::collection($resource);
  48. }
  49. }