Przeglądaj źródła

feat(migrations): adiciona nova estrutura de tabelas para modulo financeiro

ebagabee 1 tydzień temu
rodzic
commit
0fea088ccf

+ 23 - 0
database/migrations/2026_04_23_165627_create_tbrs_table.php

@@ -0,0 +1,23 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('tbrs', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedSmallInteger('year')->unique();
+            $table->decimal('tbr_value', 10, 2);
+            $table->timestamps();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('tbrs');
+    }
+};

+ 23 - 0
database/migrations/2026_04_23_165628_create_inhabitant_classifications_table.php

@@ -0,0 +1,23 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('inhabitant_classifications', function (Blueprint $table) {
+            $table->id();
+            $table->string('description', 150);
+            $table->string('acronym', 2)->unique();
+            $table->timestamps();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('inhabitant_classifications');
+    }
+};

+ 36 - 0
database/migrations/2026_04_23_165629_create_franchisee_tbrs_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('franchisee_tbrs', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('franchisee_id')->constrained('franchisees')->onDelete('cascade');
+            $table->foreignId('contract_id')->constrained('franchisee_contracts')->onDelete('cascade');
+            $table->foreignId('inhabitant_classification_id')->constrained('inhabitant_classifications');
+            $table->unsignedSmallInteger('year');
+            $table->decimal('tbr_value', 10, 2);
+            $table->date('start_date');
+            $table->tinyInteger('invoice_due_day');
+            $table->decimal('base_royalties_percentage', 5, 4);
+            $table->decimal('base_fnm_percentage', 5, 4);
+            $table->unsignedBigInteger('franchisee_royalties_bracket_id')->nullable();
+            $table->unsignedBigInteger('franchisee_fnm_bracket_id')->nullable();
+            $table->unsignedBigInteger('franchisee_maintenance_bracket_id')->nullable();
+            $table->timestamps();
+
+            $table->index('franchisee_id');
+            $table->index('contract_id');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('franchisee_tbrs');
+    }
+};

+ 25 - 0
database/migrations/2026_04_23_165631_create_royalties_base_brackets_table.php

@@ -0,0 +1,25 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('royalties_base_brackets', function (Blueprint $table) {
+            $table->id();
+            $table->string('description', 150);
+            $table->unsignedInteger('start_month');
+            $table->unsignedInteger('end_month')->nullable();
+            $table->decimal('percentage', 5, 4);
+            $table->timestamps();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('royalties_base_brackets');
+    }
+};

+ 25 - 0
database/migrations/2026_04_23_165632_create_fnm_base_brackets_table.php

@@ -0,0 +1,25 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('fnm_base_brackets', function (Blueprint $table) {
+            $table->id();
+            $table->string('description', 150);
+            $table->unsignedInteger('start_month');
+            $table->unsignedInteger('end_month')->nullable();
+            $table->decimal('percentage', 5, 4);
+            $table->timestamps();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('fnm_base_brackets');
+    }
+};

+ 25 - 0
database/migrations/2026_04_23_165633_create_maintenance_base_brackets_table.php

@@ -0,0 +1,25 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('maintenance_base_brackets', function (Blueprint $table) {
+            $table->id();
+            $table->string('description', 150);
+            $table->unsignedInteger('start_month');
+            $table->unsignedInteger('end_month')->nullable();
+            $table->decimal('percentage', 5, 4);
+            $table->timestamps();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('maintenance_base_brackets');
+    }
+};

+ 28 - 0
database/migrations/2026_04_23_165634_create_franchisee_royalties_brackets_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('franchisee_royalties_brackets', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('franchisee_id')->constrained('franchisees')->onDelete('cascade');
+            $table->string('description', 150);
+            $table->unsignedInteger('start_month');
+            $table->unsignedInteger('end_month')->nullable();
+            $table->decimal('percentage', 5, 4);
+            $table->timestamps();
+
+            $table->index('franchisee_id');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('franchisee_royalties_brackets');
+    }
+};

+ 28 - 0
database/migrations/2026_04_23_165635_create_franchisee_fnm_brackets_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('franchisee_fnm_brackets', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('franchisee_id')->constrained('franchisees')->onDelete('cascade');
+            $table->string('description', 150);
+            $table->unsignedInteger('start_month');
+            $table->unsignedInteger('end_month')->nullable();
+            $table->decimal('percentage', 5, 4);
+            $table->timestamps();
+
+            $table->index('franchisee_id');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('franchisee_fnm_brackets');
+    }
+};

+ 28 - 0
database/migrations/2026_04_23_165636_create_franchisee_maintenance_brackets_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('franchisee_maintenance_brackets', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('franchisee_id')->constrained('franchisees')->onDelete('cascade');
+            $table->string('description', 150);
+            $table->unsignedInteger('start_month');
+            $table->unsignedInteger('end_month')->nullable();
+            $table->decimal('percentage', 5, 4);
+            $table->timestamps();
+
+            $table->index('franchisee_id');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('franchisee_maintenance_brackets');
+    }
+};

+ 58 - 0
database/migrations/2026_04_23_165638_create_tbr_calculations_table.php

@@ -0,0 +1,58 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::create('tbr_calculations', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('unit_id')->constrained('units');
+            $table->decimal('revenue_value', 12, 2);
+            $table->unsignedInteger('contract_month_reference');
+            $table->decimal('tbr_value', 10, 2);
+
+            $table->foreignId('fnm_bracket_id')->constrained('franchisee_fnm_brackets');
+            $table->decimal('fnm_bracket_percentage', 5, 4);
+            $table->decimal('fnm_bracket_value', 10, 2);
+
+            $table->foreignId('maintenance_bracket_id')->constrained('franchisee_maintenance_brackets');
+            $table->decimal('maintenance_bracket_percentage', 5, 4);
+            $table->decimal('maintenance_bracket_value', 10, 2);
+
+            $table->foreignId('royalties_bracket_id')->constrained('franchisee_royalties_brackets');
+            $table->decimal('royalties_bracket_percentage', 5, 4);
+            $table->decimal('royalties_bracket_value', 10, 2);
+
+            $table->decimal('fnm_effective_percentage', 5, 4);
+            $table->decimal('fnm_effective_value', 10, 2);
+
+            $table->decimal('royalties_effective_percentage', 5, 4);
+            $table->decimal('royalties_effective_value', 10, 2);
+
+            $table->decimal('maintenance_effective_percentage', 5, 4);
+            $table->decimal('maintenance_effective_value', 10, 2);
+
+            $table->decimal('bracket_subtotal', 10, 2);
+            $table->decimal('subtotal', 10, 2);
+            $table->decimal('final_value', 10, 2);
+
+            $table->foreignId('user_id')->constrained('users');
+            $table->enum('royalties_applied_criteria', ['tbr_fixo', 'percentual_faturamento']);
+            $table->boolean('receivable_generated')->default(false);
+
+            $table->timestamps();
+
+            $table->index('unit_id');
+            $table->index('user_id');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::dropIfExists('tbr_calculations');
+    }
+};