ソースを参照

feat(tbr): gera conta a pagar da unidade ao efetivar a cobrança do TBR

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ebagabee 4 週間 前
コミット
65bbce6896
1 ファイル変更15 行追加0 行削除
  1. 15 0
      app/Services/TbrCalculationService.php

+ 15 - 0
app/Services/TbrCalculationService.php

@@ -387,6 +387,21 @@ private function buildReceivable(TbrCalculation $calculation, ?FranchiseeContrac
 
         $calculation->update(['receivable_generated' => true]);
 
+        // Espelho na unidade: o TBR que a matriz cobra vira uma Conta a Pagar da
+        // franquia (ciclo próprio, com ou sem Asaas). A dívida é registrada sempre.
+        \App\Models\UnitAccountPayable::create([
+            'unit_id'                       => $receive->unit_id,
+            'franchisee_account_receive_id' => $receive->id,
+            'origin'                        => \App\Models\UnitAccountPayable::ORIGIN_TBR,
+            'history'                       => $receive->history,
+            'value'                         => $receive->value,
+            'paid_value'                    => 0,
+            'discount'                      => 0,
+            'fine'                          => 0,
+            'due_date'                      => $receive->due_date,
+            'status'                        => 'pending',
+        ]);
+
         \App\Jobs\SyncFranchiseeChargeJob::dispatch($receive);
 
         return $receive->load('details');