Procházet zdrojové kódy

feat: correcao no historico

ebagabee před 1 měsícem
rodič
revize
a04584f1e6

+ 1 - 0
app/Http/Resources/FranchiseeContractTaxHistoryResource.php

@@ -14,6 +14,7 @@ public function toArray(Request $request): array
             'inhabitant_classification_id' => $this->inhabitant_classification_id,
             'inhabitant_classification'    => $this->whenLoaded('inhabitantClassification', fn() => $this->inhabitantClassification?->description),
             'tbr_fixed_value'              => $this->tbr_fixed_value,
+            'tbr_fixed_value_percentage'   => $this->tbr_fixed_value_percentage,
             'marketing_fund_percentage'    => $this->marketing_fund_percentage,
             'maintance_tax_percentage'     => $this->maintance_tax_percentage,
             'created_at'                   => $this->created_at?->format('Y-m-d H:i:s'),

+ 4 - 3
app/Models/FranchiseeContractTaxHistory.php

@@ -12,9 +12,10 @@ class FranchiseeContractTaxHistory extends Model
     protected $guarded = ['id'];
 
     protected $casts = [
-        'tbr_fixed_value'           => 'decimal:2',
-        'marketing_fund_percentage' => 'decimal:4',
-        'maintance_tax_percentage'  => 'decimal:4',
+        'tbr_fixed_value'            => 'decimal:2',
+        'tbr_fixed_value_percentage' => 'decimal:4',
+        'marketing_fund_percentage'  => 'decimal:4',
+        'maintance_tax_percentage'   => 'decimal:4',
     ];
 
     public function contract(): BelongsTo

+ 19 - 3
app/Services/FranchiseeContractService.php

@@ -60,21 +60,37 @@ public function update(int $id, array $data): ?FranchiseeContract
             return null;
         }
 
-        $taxFields = ['inhabitant_classification_id', 'tbr_fixed_value', 'marketing_fund_percentage', 'maintance_tax_percentage'];
+        $taxFields = ['inhabitant_classification_id', 'tbr_fixed_value', 'tbr_fixed_value_percentage', 'marketing_fund_percentage', 'maintance_tax_percentage'];
         $hasTaxChange = collect($taxFields)->contains(fn($field) => array_key_exists($field, $data));
 
+        if ($hasTaxChange) {
+            $hasHistory = FranchiseeContractTaxHistory::where('franchisee_contract_id', $model->id)->exists();
+
+            if (!$hasHistory) {
+                FranchiseeContractTaxHistory::create([
+                    'franchisee_contract_id'       => $model->id,
+                    'inhabitant_classification_id' => $model->inhabitant_classification_id,
+                    'tbr_fixed_value'              => $model->tbr_fixed_value,
+                    'tbr_fixed_value_percentage'   => $model->tbr_fixed_value_percentage,
+                    'marketing_fund_percentage'    => $model->marketing_fund_percentage,
+                    'maintance_tax_percentage'     => $model->maintance_tax_percentage,
+                ]);
+            }
+        }
+
+        $model->update($data);
+
         if ($hasTaxChange) {
             FranchiseeContractTaxHistory::create([
                 'franchisee_contract_id'       => $model->id,
                 'inhabitant_classification_id' => $model->inhabitant_classification_id,
                 'tbr_fixed_value'              => $model->tbr_fixed_value,
+                'tbr_fixed_value_percentage'   => $model->tbr_fixed_value_percentage,
                 'marketing_fund_percentage'    => $model->marketing_fund_percentage,
                 'maintance_tax_percentage'     => $model->maintance_tax_percentage,
             ]);
         }
 
-        $model->update($data);
-
         return $model->fresh();
     }
 

+ 22 - 0
database/migrations/2026_05_06_000001_add_royalties_to_franchisee_contract_tax_histories_table.php

@@ -0,0 +1,22 @@
+<?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::table('franchisee_contract_tax_histories', function (Blueprint $table) {
+            $table->decimal('tbr_fixed_value_percentage', 10, 4)->nullable()->after('tbr_fixed_value');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('franchisee_contract_tax_histories', function (Blueprint $table) {
+            $table->dropColumn('tbr_fixed_value_percentage');
+        });
+    }
+};