commit compras 2711
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-27 13:49:31 +02:00
parent dc73540558
commit e709d900d1
81 changed files with 5352 additions and 107 deletions
+11 -2
View File
@@ -65,7 +65,6 @@ final class OrderPartsInvoices
abort_unless(auth()->id() === $actor->id && $actor->hasFunctions([PurchasingRole::Finance])
&& $invoice->tenant_id === $actor->tenant_id && $order->tenant_id === $actor->tenant_id && $invoice->purchase_order_id === $order->id, 403);
app(OrderPartsAccess::class)->assertProcess($actor, $order);
abort_unless($order->currency === 'MZN', 503, 'A imputação multimoeda por origem ainda está em preparação.');
$data = Validator::make($input, $this->rules())->validate();
$rows = [];
$seen = [];
@@ -116,6 +115,7 @@ final class OrderPartsInvoices
'subtotal_minor' => $line['subtotal_minor'], 'total_minor' => $line['subtotal_minor'] + $line['tax_minor']];
}
$sources = $sums = [];
$reference = $order->currency === 'MZN' ? null : app(OrderPartsExchange::class)->invoiceSources($order, $nativeLines);
foreach ($rows as $row) {
if (! in_array($row['origin'], $origins, true)) {
throw ValidationException::withMessages(['order_part_allocations' => 'Origem fora desta ordem.']);
@@ -139,10 +139,19 @@ final class OrderPartsInvoices
'subtotal_minor' => $row['subtotal_minor'], 'total_minor' => $row['total_minor']];
}
foreach ($expected as $id => $line) {
if (($sums[$id] ?? null) !== ['subtotal_minor' => $line['subtotal_minor'], 'total_minor' => $line['total_minor']]) {
if ($order->currency === 'MZN' && ($sums[$id] ?? null) !== ['subtotal_minor' => $line['subtotal_minor'], 'total_minor' => $line['total_minor']]) {
throw ValidationException::withMessages(['order_part_allocations' => 'As imputações devem coincidir exactamente com cada linha nativa da factura.']);
}
}
if ($reference !== null) {
foreach ($reference as $origin => $amount) {
$allocated = $sources[$origin]['allocations'] ?? [];
if (array_sum(array_column($allocated, 'subtotal_minor')) !== $amount['subtotal_minor']
|| array_sum(array_column($allocated, 'total_minor')) !== $amount['total_minor']) {
throw ValidationException::withMessages(['order_part_allocations' => 'As imputações em MZN devem coincidir exactamente com a referência de cada origem facturada.']);
}
}
}
foreach ($sources as &$source) {
unset($source['frozen']);
}