Forráskód Böngészése

feat(tbrs): create new fields in table and increment the model

ebagabee 1 napja
szülő
commit
cb4af6a78c

+ 11 - 5
app/Http/Requests/TbrRequest.php

@@ -11,17 +11,23 @@ public function rules(): array
         $tbrId = $this->route('id');
 
         return [
-            'year'      => ['required', 'integer', 'min:2000', 'max:2100', "unique:tbrs,year,{$tbrId}"],
-            'tbr_value' => ['required', 'numeric', 'min:0'],
+            'year'                   => ['required', 'integer', 'min:2000', 'max:2100', "unique:tbrs,year,{$tbrId}"],
+            'tbr_value'              => ['required', 'numeric', 'min:0'],
+            'royalties_percentage'   => ['required', 'numeric', 'min:0', 'max:1'],
+            'fnm_percentage'         => ['required', 'numeric', 'min:0', 'max:1'],
+            'maintenance_percentage' => ['required', 'numeric', 'min:0', 'max:1'],
         ];
     }
 
     public function messages(): array
     {
         return [
-            'year.required'      => 'O ano é obrigatório.',
-            'year.unique'        => 'Já existe uma TBR para este ano.',
-            'tbr_value.required' => 'O valor da TBR é obrigatório.',
+            'year.required'                   => 'O ano é obrigatório.',
+            'year.unique'                     => 'Já existe uma TBR para este ano.',
+            'tbr_value.required'              => 'O valor da TBR é obrigatório.',
+            'royalties_percentage.required'   => 'O percentual de royalties é obrigatório.',
+            'fnm_percentage.required'         => 'O percentual de FMN é obrigatório.',
+            'maintenance_percentage.required' => 'O percentual de manutenção é obrigatório.',
         ];
     }
 }

+ 8 - 5
app/Http/Resources/TbrResource.php

@@ -18,11 +18,14 @@ class TbrResource extends JsonResource
     public function toArray(Request $request): array
     {
         return [
-            'id'         => $this->id,
-            'year'       => $this->year,
-            'tbr_value'  => $this->tbr_value,
-            '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'),
+            'id'                     => $this->id,
+            'year'                   => $this->year,
+            'tbr_value'              => $this->tbr_value,
+            'royalties_percentage'   => $this->royalties_percentage,
+            'fnm_percentage'         => $this->fnm_percentage,
+            'maintenance_percentage' => $this->maintenance_percentage,
+            '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'),
         ];
     }
 

+ 6 - 3
app/Models/Tbr.php

@@ -21,8 +21,11 @@ class Tbr extends Model
     protected $guarded = ['id'];
 
     protected $casts = [
-        'tbr_value'  => 'decimal:2',
-        'created_at' => 'datetime',
-        'updated_at' => 'datetime',
+        'tbr_value'              => 'decimal:2',
+        'royalties_percentage'   => 'decimal:4',
+        'fnm_percentage'         => 'decimal:4',
+        'maintenance_percentage' => 'decimal:4',
+        'created_at'             => 'datetime',
+        'updated_at'             => 'datetime',
     ];
 }

+ 27 - 0
database/migrations/2026_04_30_130656_add_percentages_to_tbrs_table.php

@@ -0,0 +1,27 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('tbrs', function (Blueprint $table) {
+            $table->decimal('royalties_percentage', 5, 4)->after('tbr_value');
+            $table->decimal('fnm_percentage', 5, 4)->after('royalties_percentage');
+            $table->decimal('maintenance_percentage', 5, 4)->after('fnm_percentage');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('tbrs', function (Blueprint $table) {
+            $table->dropColumn(['royalties_percentage', 'fnm_percentage', 'maintenance_percentage']);
+        });
+    }
+};

+ 0 - 1
database/seeders/DatabaseSeeder.php

@@ -16,7 +16,6 @@ public function run(): void
             PermissionSeeder::class,
             UserTypePermissionSeeder::class,
             BrazilCitiesSeeder::class,
-            TbrBaseBracketsSeeder::class,
         ]);
     }
 }

+ 0 - 95
database/seeders/TbrBaseBracketsSeeder.php

@@ -1,95 +0,0 @@
-<?php
-
-namespace Database\Seeders;
-
-use Illuminate\Database\Seeder;
-use Illuminate\Support\Facades\DB;
-
-class TbrBaseBracketsSeeder extends Seeder
-{
-    public function run(): void
-    {
-        $now = now();
-
-        DB::table('royalties_base_brackets')->insert([
-            [
-                'description' => 'Isento',
-                'start_month' => 1,
-                'end_month'   => 3,
-                'percentage'  => 0.0000,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-            [
-                'description' => 'Maior entre % fixo TBR ou 8% do faturamento',
-                'start_month' => 4,
-                'end_month'   => 12,
-                'percentage'  => 0.0800,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-            [
-                'description' => 'Maior entre % fixo TBR ou 8% do faturamento',
-                'start_month' => 13,
-                'end_month'   => 60,
-                'percentage'  => 0.0800,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-        ]);
-
-        DB::table('fnm_base_brackets')->insert([
-            [
-                'description' => 'Isento',
-                'start_month' => 1,
-                'end_month'   => 3,
-                'percentage'  => 0.0000,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-            [
-                'description' => 'Maior entre: % fixo TBR ou 2% do faturamento',
-                'start_month' => 4,
-                'end_month'   => 12,
-                'percentage'  => 0.0200,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-            [
-                'description' => 'Maior entre: % fixo TBR ou 2% do faturamento',
-                'start_month' => 13,
-                'end_month'   => 60,
-                'percentage'  => 0.0200,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-        ]);
-
-        DB::table('maintenance_base_brackets')->insert([
-            [
-                'description' => '30% fixo da TBR',
-                'start_month' => 1,
-                'end_month'   => 3,
-                'percentage'  => 0.3000,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-            [
-                'description' => '30% fixo da TBR',
-                'start_month' => 4,
-                'end_month'   => 12,
-                'percentage'  => 0.3000,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-            [
-                'description' => '30% fixo da TBR',
-                'start_month' => 13,
-                'end_month'   => 60,
-                'percentage'  => 0.3000,
-                'created_at'  => $now,
-                'updated_at'  => $now,
-            ],
-        ]);
-    }
-}