| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
- use App\Models\TreasuryLaunch;
- class TreasuryLaunchResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'unit_id' => $this->unit_id,
- 'transaction_type' => $this->transaction_type,
- 'from_account_id' => $this->from_account_id,
- 'to_account_id' => $this->to_account_id,
- // Banco da movimentação (destino na entrada, origem na saída).
- 'account_id' => $this->transaction_type === 'entrada' ? $this->to_account_id : $this->from_account_id,
- 'description' => $this->description,
- 'financial_plan_account_id' => $this->financial_plan_account_id,
- 'financial_plan_account' => $this->whenLoaded('financialPlanAccount', function () {
- return $this->financialPlanAccount ? [
- 'id' => $this->financialPlanAccount->id,
- 'code' => $this->financialPlanAccount->code,
- 'description' => $this->financialPlanAccount->description,
- 'label' => "{$this->financialPlanAccount->code} - {$this->financialPlanAccount->description}",
- ] : null;
- }),
- 'amount' => (float) $this->amount,
- 'launch_date' => $this->launch_date,
- 'origin' => $this->origin,
- 'is_reconciled' => (bool) $this->is_reconciled,
- 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
- 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
- ];
- }
- /**
- * @param \Illuminate\Database\Eloquent\Collection<TreasuryLaunch> $resource
- * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<TreasuryLaunchResource>
- */
- public static function collection($resource): AnonymousResourceCollection
- {
- return parent::collection($resource);
- }
- }
|