|
|
@@ -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();
|
|
|
}
|
|
|
|