@@ -17,10 +17,12 @@ final class CommonBudget
|
||||
{
|
||||
public const DISTRIBUTIONS_CONTRACT = 'COMMON-BUDGET-DISTRIBUTION-QA-v1';
|
||||
|
||||
public const ORDER_PARTS_CONTRACT = 'COMMON-BUDGET-ORDER-PARTS-QA-v1';
|
||||
public const ORDER_PARTS_CONTRACT = 'COMMON-BUDGET-ORDER-PARTS-QA-v2';
|
||||
|
||||
public const LANDED_COSTS_CONTRACT = 'COMMON-BUDGET-LANDED-COST-QA-v2';
|
||||
|
||||
public const IMPORT_ESTIMATE_CONTRACT = 'COMMON-BUDGET-IMPORT-ESTIMATE-QA-v1';
|
||||
|
||||
public function for(User $user): BudgetControl
|
||||
{
|
||||
abort_unless(auth()->id() === $user->id && $user->tenant_id !== null, 403);
|
||||
@@ -28,6 +30,12 @@ final class CommonBudget
|
||||
$landedTables = ['budget_landed_commands', 'budget_landed_entries'];
|
||||
$landedPresent = array_values(array_filter($landedTables, fn ($table) => Schema::hasTable($table)));
|
||||
abort_if(count($landedPresent) !== 0 && count($landedPresent) !== count($landedTables), 503, 'Estrutura de aterragem incompleta; saldo não presumido.');
|
||||
if (in_array('budget_landed_entries', $landedPresent, true)
|
||||
&& (! $runtime->hasConstant('IMPORT_ESTIMATE_VERSION') || $runtime->getConstant('IMPORT_ESTIMATE_VERSION') !== self::IMPORT_ESTIMATE_CONTRACT
|
||||
|| ! $runtime->hasMethod('reserveImportEstimate'))) {
|
||||
abort_if(DB::table('budget_landed_entries')->where('tenant_id', $user->tenant_id)->where('source_kind', 'import_estimate')->exists(), 503,
|
||||
'Existem estimativas reservadas. Preserve o motor compatível; pressupostos não podem ser tratados como documentos efectivos.');
|
||||
}
|
||||
if (! $runtime->hasConstant('LANDED_COSTS_VERSION') || $runtime->getConstant('LANDED_COSTS_VERSION') !== self::LANDED_COSTS_CONTRACT
|
||||
|| ! $runtime->hasMethod('reserveLandedCosts') || ! $runtime->hasMethod('transitionLandedCosts')) {
|
||||
foreach ($landedPresent as $table) {
|
||||
@@ -64,7 +72,7 @@ final class CommonBudget
|
||||
abort_unless(DB::table('tenants')->where('id', $user->tenant_id)->value('currency') === 'MZN', 422, 'Moeda da organização incompatível com esta entrega.');
|
||||
$roles = in_array($action, ['create', 'approve', 'reinforcement.propose', 'reinforcement.review', 'view'], true)
|
||||
? [PurchasingRole::Admin, PurchasingRole::Finance]
|
||||
: (in_array($action, ['consume', 'consume.preview', 'distribution.amend', 'orders.cancel', 'landed.reserve', 'landed.commit', 'landed.consume', 'landed.cancel', 'landed.amend'], true) ? [PurchasingRole::Finance]
|
||||
: (in_array($action, ['consume', 'consume.preview', 'distribution.amend', 'orders.cancel', 'orders.amend', 'landed.reserve', 'landed.commit', 'landed.consume', 'landed.cancel', 'landed.amend'], true) ? [PurchasingRole::Finance]
|
||||
: (in_array($action, ['orders.commit', 'orders.adopt'], true) ? [PurchasingRole::Procurement] : null));
|
||||
app(CurrentActor::class)->lock($user, $roles);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user