@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
/** Converts cumulative documentary amounts with the frozen rate of one origin. */
|
||||
final class OrderPartsReference
|
||||
{
|
||||
/** @return array{subtotal_minor:int,tax_minor:int,total_minor:int} */
|
||||
public static function portion(int $beforeNet, int $beforeTax, int $net, int $tax, string $rate): array
|
||||
{
|
||||
if (min($beforeNet, $beforeTax, $net, $tax) < 0
|
||||
|| $beforeNet > PHP_INT_MAX - $net || $beforeTax > PHP_INT_MAX - $tax) {
|
||||
throw new \InvalidArgumentException('Base cambial cumulativa inválida.');
|
||||
}
|
||||
$exchange = new QuotationExchange;
|
||||
$subtotal = $exchange->convert($beforeNet + $net, $rate) - $exchange->convert($beforeNet, $rate);
|
||||
$vat = $exchange->convert($beforeTax + $tax, $rate) - $exchange->convert($beforeTax, $rate);
|
||||
|
||||
return ['subtotal_minor' => $subtotal, 'tax_minor' => $vat, 'total_minor' => $subtotal + $vat];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user