commit de compras

This commit is contained in:
2026-11-04 09:37:20 +02:00
parent fcf31e8d48
commit 0b05a1192c
741 changed files with 114127 additions and 116 deletions
@@ -5,6 +5,7 @@ namespace App\Modules\Purchasing;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Tempo\Finance\Payables\HistoricalPayments;
use Tempo\Finance\Payables\HistoricalCapture;
use Tempo\Finance\Payables\Payables;
/** Reads explicitly reconciled immutable receipts; never imports or decides payments. */
@@ -34,7 +35,7 @@ final class SupplierHistoryReceipts
}
/** Local read snapshots only; no command obtains its source through this batch. */
public function page(User $user, array $documents): array
public function page(User $user, array $documents, bool $validatedCapture = false): array
{
abort_unless($this->available(), 503);
$adapter = app(SupplierPayables::class); $scope = $adapter->scope($user);
@@ -43,14 +44,14 @@ final class SupplierHistoryReceipts
->distinct('local_source_id')->orderBy('local_source_id')->orderByDesc('version')->get()->keyBy('local_source_id');
$result = [];
foreach ($documents as $id => $source) {
try { $result[$id] = $this->decode($source, $receipts->get($id)); }
try { $result[$id] = $this->decode($source, $receipts->get($id), $validatedCapture ? $scope : null); }
catch (\DomainException $e) { $result[$id] = $e; }
}
return $result;
}
private function decode(array $source, ?object $receipt): array
private function decode(array $source, ?object $receipt, ?array $captureScope = null): array|HistoricalCapture
{
if (! $receipt) {
throw new \DomainException('Histórico não reconciliado para esta origem e contexto.');
@@ -66,11 +67,12 @@ final class SupplierHistoryReceipts
&& is_array($payload['payments'] ?? null) && array_is_list($payload['payments']))) {
throw new \DomainException('Recibo histórico antigo ou incompatível; exige nova conferência da origem.');
}
$capture = HistoricalPayments::capture($source, $payload['payments']);
$value = $captureScope === null ? null : HistoricalCapture::fromPayments($captureScope, $source, $payload['payments']);
$capture = $value ? $value->forSource($captureScope, $source) : HistoricalPayments::capture($source, $payload['payments']);
if (($payload['history_hash'] ?? null) !== $capture['history_hash']) {
throw new \DomainException('Fotografia histórica incompatível com os pagamentos originais.');
}
return $capture['payments'];
return $value ?? $capture['payments'];
}
}