Просмотр исходного кода

feat(unit-payable): migration de contas a pagar da unidade

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ebagabee 4 недель назад
Родитель
Сommit
8117464285

+ 50 - 0
database/migrations/2026_07_01_000001_create_unit_account_payables_table.php

@@ -0,0 +1,50 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Contas a Pagar da unidade (Franchisee).
+     *
+     * Ciclo próprio (a unidade dá baixa por conta dela, independente do recebível
+     * da matriz). A cobrança do TBR gera automaticamente um registro aqui com
+     * origin='tbr' vinculado ao franchisee_account_receive de origem; lançamentos
+     * avulsos usam origin='manual'. Asaas não é obrigatório: é apenas um registro
+     * de dívida da unidade.
+     */
+    public function up(): void
+    {
+        Schema::create('unit_account_payables', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('unit_id')->constrained('units')->onDelete('cascade');
+            $table->foreignId('franchisee_account_receive_id')
+                ->nullable()
+                ->constrained('franchisee_account_receives')
+                ->nullOnDelete();
+            $table->string('origin')->default('manual'); // tbr | manual
+            $table->string('history');
+            $table->decimal('value', 10, 2);
+            $table->decimal('paid_value', 10, 2)->default(0);
+            $table->decimal('discount', 10, 2)->default(0);
+            $table->decimal('fine', 10, 2)->default(0);
+            $table->date('due_date');
+            $table->date('payment_date')->nullable();
+            $table->string('status')->default('pending'); // pending | paid | overdue | cancelled
+            $table->text('obs')->nullable();
+            $table->timestamps();
+            $table->softDeletes();
+
+            $table->index('unit_id');
+            $table->index('status');
+            $table->index('due_date');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('unit_account_payables');
+    }
+};