فهرست منبع

refactor(treasury): add financial plan account relationship and include in resource

ebagabee 1 ماه پیش
والد
کامیت
73062437e7
3فایلهای تغییر یافته به همراه15 افزوده شده و 0 حذف شده
  1. 9 0
      app/Http/Resources/TreasuryLaunchResource.php
  2. 5 0
      app/Models/TreasuryLaunch.php
  3. 1 0
      app/Services/TreasuryLaunchService.php

+ 9 - 0
app/Http/Resources/TreasuryLaunchResource.php

@@ -26,6 +26,15 @@ public function toArray(Request $request): array
             // 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,

+ 5 - 0
app/Models/TreasuryLaunch.php

@@ -65,6 +65,11 @@ class TreasuryLaunch extends Model
 
     // Relationships
 
+    public function financialPlanAccount(): \Illuminate\Database\Eloquent\Relations\BelongsTo
+    {
+        return $this->belongsTo(FinancialPlanAccount::class, 'financial_plan_account_id');
+    }
+
     // Business Logic Methods
 
     // Custom Finders

+ 1 - 0
app/Services/TreasuryLaunchService.php

@@ -16,6 +16,7 @@ class TreasuryLaunchService
     public function getAll(?int $accountId = null): Collection
     {
         return TreasuryLaunch::query()
+            ->with('financialPlanAccount')
             ->when($accountId !== null, fn ($query) => $query->where(function ($q) use ($accountId) {
                 $q->where('from_account_id', $accountId)
                     ->orWhere('to_account_id', $accountId);