TbrCalculationResource.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  7. use App\Models\TbrCalculation;
  8. class TbrCalculationResource extends JsonResource
  9. {
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @return array<string, mixed>
  14. */
  15. public function toArray(Request $request): array
  16. {
  17. return [
  18. 'id' => $this->id,
  19. 'unit_id' => $this->unit_id,
  20. 'revenue_value' => $this->revenue_value,
  21. 'contract_month_reference' => $this->contract_month_reference,
  22. 'tbr_value' => $this->tbr_value,
  23. 'royalties_bracket_id' => $this->royalties_bracket_id,
  24. 'royalties_bracket_percentage' => $this->royalties_bracket_percentage,
  25. 'royalties_bracket_value' => $this->royalties_bracket_value,
  26. 'fnm_bracket_percentage' => $this->fnm_bracket_percentage,
  27. 'fnm_bracket_value' => $this->fnm_bracket_value,
  28. 'maintenance_bracket_percentage' => $this->maintenance_bracket_percentage,
  29. 'maintenance_bracket_value' => $this->maintenance_bracket_value,
  30. 'royalties_effective_percentage' => $this->royalties_effective_percentage,
  31. 'royalties_effective_value' => $this->royalties_effective_value,
  32. 'fnm_effective_percentage' => $this->fnm_effective_percentage,
  33. 'fnm_effective_value' => $this->fnm_effective_value,
  34. 'maintenance_effective_percentage' => $this->maintenance_effective_percentage,
  35. 'maintenance_effective_value' => $this->maintenance_effective_value,
  36. 'bracket_subtotal' => $this->bracket_subtotal,
  37. 'subtotal' => $this->subtotal,
  38. 'final_value' => $this->final_value,
  39. 'user_id' => $this->user_id,
  40. 'royalties_applied_criteria' => $this->royalties_applied_criteria,
  41. 'receivable_generated' => $this->receivable_generated,
  42. 'unit' => $this->whenLoaded('unit', fn () => [
  43. 'id' => $this->unit->id,
  44. 'fantasy_name' => $this->unit->fantasy_name,
  45. ]),
  46. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  47. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  48. ];
  49. }
  50. /**
  51. * @param \Illuminate\Database\Eloquent\Collection<TbrCalculation> $resource
  52. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<TbrCalculationResource>
  53. */
  54. public static function collection($resource): AnonymousResourceCollection
  55. {
  56. return parent::collection($resource);
  57. }
  58. }