Files
compras/app/Services/OrderPartsReference.php
T
nala e709d900d1
tests / ci (push) Waiting to run
commit compras 2711
2026-11-27 13:49:31 +02:00

22 lines
939 B
PHP

<?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];
}
}