@@ -22,7 +22,7 @@ final class ImportLegalAmounts
|
||||
'charges.*.kind' => 'required|in:duty,ice,vat,other',
|
||||
'charges.*.method' => 'required|in:unknown,not_applicable,ad_valorem,specific,maximum',
|
||||
'charges.*.rate_percent' => ['present', 'nullable', 'regex:/^\d{1,4}(\.\d{1,6})?$/', 'numeric', 'min:0', 'max:10000'],
|
||||
'charges.*.specific_minor' => 'present|nullable|integer|min:0|max:100000000000000',
|
||||
'charges.*.specific_minor' => ['present', 'nullable', 'regex:/^\d{1,15}(\.\d{1,6})?$/', 'numeric', 'min:0', 'max:100000000000000'],
|
||||
'charges.*.quantity_unit' => 'present|nullable|string|max:40',
|
||||
'charges.*.basis_reference' => 'required|string|min:3|max:4000',
|
||||
])->validate();
|
||||
@@ -34,8 +34,21 @@ final class ImportLegalAmounts
|
||||
|| ($specific && trim($charge['quantity_unit'] ?? '') === '')) {
|
||||
throw ValidationException::withMessages(['charges.'.$index => 'Indique exactamente as taxas e a unidade do método documentado; desconhecido ou não aplicável não presume uma taxa.']);
|
||||
}
|
||||
$coefficient = null;
|
||||
if ($specific) {
|
||||
if (! is_int($charge['specific_minor']) && ! is_string($charge['specific_minor'])) {
|
||||
throw ValidationException::withMessages(['charges.'.$index.'.specific_minor' => 'Indique a taxa específica como decimal exacto, sem conversão binária.']);
|
||||
}
|
||||
$decimal = BigDecimal::of($charge['specific_minor'])->strippedOfTrailingZeros();
|
||||
if ($decimal->isGreaterThan('100000000000000')) {
|
||||
throw ValidationException::withMessages(['charges.'.$index.'.specific_minor' => 'A taxa específica excede o limite suportado.']);
|
||||
}
|
||||
// Keep the canonical integer representation of all previous rules.
|
||||
// Fractional cents belong to the coefficient, not a rounded payment.
|
||||
$coefficient = str_contains((string) $decimal, '.') ? (string) $decimal : $decimal->toInt();
|
||||
}
|
||||
$result[] = [...$charge, 'rate_percent' => $percent ? (string) BigDecimal::of($charge['rate_percent'])->toScale(6) : null,
|
||||
'specific_minor' => $specific ? (int) $charge['specific_minor'] : null];
|
||||
'specific_minor' => $coefficient];
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user