|
|
@@ -306,10 +306,12 @@ private function resolveContract(int $unitId): FranchiseeContract
|
|
|
|
|
|
private function buildPreview(FranchiseeContract $contract, int $referenceYear, int $referenceMonth, float $revenueValue): array
|
|
|
{
|
|
|
+ $tbrConfig = Tbr::where('year', $referenceYear)->orderByDesc('id')->first();
|
|
|
+
|
|
|
$tbrValue = (float) ($contract->tbr_fixed_value ?? 0);
|
|
|
|
|
|
if ($tbrValue <= 0) {
|
|
|
- $tbrValue = (float) (Tbr::where('year', $referenceYear)->orderByDesc('id')->value('tbr_value') ?? 0);
|
|
|
+ $tbrValue = (float) ($tbrConfig->tbr_value ?? 0);
|
|
|
}
|
|
|
|
|
|
if ($tbrValue <= 0) {
|
|
|
@@ -318,6 +320,9 @@ private function buildPreview(FranchiseeContract $contract, int $referenceYear,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ $fnmPercentageConfig = $tbrConfig ? (float) $tbrConfig->fnm_percentage : self::FNM_BRACKET_PERCENTAGE;
|
|
|
+ $maintenancePercentageConfig = $tbrConfig ? (float) $tbrConfig->maintenance_percentage : self::MAINTENANCE_RATE;
|
|
|
+
|
|
|
$contractMonth = $this->resolveContractMonth($contract->start_date, $referenceYear, $referenceMonth);
|
|
|
$municipalitySizeId = (int) $contract->municipality_size_id;
|
|
|
|
|
|
@@ -332,8 +337,8 @@ private function buildPreview(FranchiseeContract $contract, int $referenceYear,
|
|
|
: null;
|
|
|
$royaltiesBracketPercentage = $royaltiesBracket ? (float) $royaltiesBracket->tbr_percentage : 0.0;
|
|
|
|
|
|
- $fnmPercentage = $chargeFnm ? $this->resolveFnmPercentage($contractMonth) : 0.0;
|
|
|
- $maintenancePercentage = self::MAINTENANCE_RATE;
|
|
|
+ $fnmPercentage = $chargeFnm ? $this->resolveFnmPercentage($contractMonth, $fnmPercentageConfig) : 0.0;
|
|
|
+ $maintenancePercentage = $maintenancePercentageConfig;
|
|
|
|
|
|
$royaltiesBracketValue = round($royaltiesBracketPercentage * $tbrValue, 2);
|
|
|
$fnmBracketValue = round($fnmPercentage * $tbrValue, 2);
|
|
|
@@ -563,9 +568,9 @@ private function findRoyaltiesBracket(int $municipalitySizeId, int $contractMont
|
|
|
return $bracket;
|
|
|
}
|
|
|
|
|
|
- private function resolveFnmPercentage(int $contractMonth): float
|
|
|
+ private function resolveFnmPercentage(int $contractMonth, float $fnmPercentage): float
|
|
|
{
|
|
|
- return $contractMonth <= self::EXEMPT_THRESHOLD_MONTH ? 0.0 : self::FNM_BRACKET_PERCENTAGE;
|
|
|
+ return $contractMonth <= self::EXEMPT_THRESHOLD_MONTH ? 0.0 : $fnmPercentage;
|
|
|
}
|
|
|
|
|
|
private function resolveDueDate(?FranchiseeContract $contract, Carbon $referenceDate): Carbon
|