Implementa conferencia de facturas e consumo por empresa

This commit is contained in:
2026-10-28 14:26:18 +02:00
parent f86ecef44d
commit 332cb9f1b7
28 changed files with 1356 additions and 8 deletions
+2
View File
@@ -3,6 +3,7 @@
namespace App\Services;
use App\Models\Budget;
use App\Models\BudgetConsumption;
use App\Models\BudgetEntry;
use App\Models\Requisition;
use App\Models\User;
@@ -52,6 +53,7 @@ class BudgetWorkflow
};
$ledger = BudgetEntry::query()->where('budget_id', $budget->id);
$used = (int) (clone $ledger)->sum('reserved_minor') + (int) $ledger->sum('committed_minor');
$used += (int) BudgetConsumption::query()->where('budget_id', $budget->id)->sum('amount_minor');
if ($used + $reserveDelta + $commitDelta > $budget->amount_minor) {
throw ValidationException::withMessages(['budget' => 'Saldo orçamental insuficiente. Não são permitidos excessos.']);
}