81 lines
6.1 KiB
PHP
81 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Database\Schema\Builder;
|
|
use LogicException;
|
|
|
|
/** Read-only startup preflight; never installs, repairs or enables a module. */
|
|
final class StandaloneSchema
|
|
{
|
|
/** @param array<string,mixed> $features */
|
|
public static function verify(Builder $schema, array $features): void
|
|
{
|
|
foreach (['import-legal' => ['import-tariffs'], 'import-bank-support' => ['import-dossier'],
|
|
'import-readiness' => ['import-dossier'], 'general-ledger' => ['supplier-payables'],
|
|
'supplier-settlements' => ['supplier-payables'], 'general-ledger-cycle' => ['general-ledger', 'supplier-settlements'],
|
|
'finance-configuration' => ['supplier-payables', 'general-ledger'],
|
|
'standalone-sales' => ['general-ledger-cycle', 'finance-configuration']] as $feature => $dependencies) {
|
|
foreach ($dependencies as $dependency) {
|
|
if (($features[$feature] ?? false) === true && ($features[$dependency] ?? false) !== true) {
|
|
throw new LogicException('COMPRAS_RUNTIME_FEATURE_DEPENDENCY:'.$feature.':'.$dependency);
|
|
}
|
|
}
|
|
}
|
|
$tables = ['supply_records' => ['id', 'tenant_id', 'kind', 'record_key', 'version', 'data', 'snapshot', 'operation_key'],
|
|
'requisitions' => ['id', 'tenant_id', 'status'], 'users' => ['id', 'tenant_id']];
|
|
foreach ($features as $feature => $enabled) {
|
|
if ($enabled !== true) {
|
|
continue;
|
|
}
|
|
$required = match ($feature) {
|
|
'standalone-sales' => ['business_clients' => ['id', 'tenant_id', 'version'],
|
|
'cr_series' => ['id', 'tenant_id', 'company_id', 'unit_id', 'series_key'],
|
|
'cr_invoice_proposals' => ['id', 'revision', 'snapshot'], 'cr_invoice_reviews' => ['id', 'proposal_id', 'decision'],
|
|
'cr_invoices' => ['id', 'client_id', 'reference', 'total_minor', 'snapshot'],
|
|
'cr_receipt_proposals' => ['id', 'client_id', 'amount_minor'], 'cr_receipt_decisions' => ['id', 'proposal_id', 'decision'],
|
|
'cr_allocation_proposals' => ['id', 'invoice_id', 'receipt_id', 'amount_minor'], 'cr_allocation_decisions' => ['id', 'proposal_id', 'decision'],
|
|
'cr_reversal_proposals' => ['id', 'allocation_id'], 'cr_reversal_decisions' => ['id', 'proposal_id', 'decision'],
|
|
'cr_commands' => ['id', 'operation_key', 'request_hash'], 'cr_events' => ['id', 'kind', 'entity_id'],
|
|
'gl_configured_sales' => ['contract', 'original_validator_sha256'], 'gl_rules' => ['tax_account_id'],
|
|
'customer_deliveries' => ['id', 'tenant_id', 'invoice_id', 'invoice_line_no', 'stock_operation_id', 'quantity_milli']],
|
|
'capital-register' => ['equipment' => ['id', 'tenant_id', 'department_id']],
|
|
'private-audit' => ['private_audit_exports' => ['id', 'tenant_id']],
|
|
'conflict-releases' => ['conflict_releases' => ['id', 'tenant_id']],
|
|
'requisition-accounts' => ['gl_accounts' => ['id', 'tenant_id', 'company_id', 'unit_id', 'code', 'label', 'currency', 'is_movement']],
|
|
'requisition-expiry' => ['budget_requisition_cycles' => ['id', 'requisition_id', 'cycle', 'state'],
|
|
'requisitions' => ['approval_cycle', 'process_version'], 'approval_steps' => ['approval_cycle'],
|
|
'budget_entries' => ['requisition_cycle'], 'workflow_notices' => ['event_kind'], 'requisition_commands' => ['id']],
|
|
'budget-distributions' => ['budget_distributions' => ['id', 'tenant_id'], 'budget_distribution_events' => ['id'],
|
|
'budget_distribution_entries' => ['id'], 'budget_distribution_consumptions' => ['id'],
|
|
'requisitions' => ['budget_distribution_preparation']],
|
|
'order-parts' => ['budget_order_commands' => ['id', 'tenant_id'], 'budget_order_bindings' => ['id'],
|
|
'budget_order_allocations' => ['id'], 'budget_order_consumptions' => ['id'], 'purchase_order_sources' => ['id']],
|
|
'import-landed-costs' => ['budget_landed_commands' => ['id', 'tenant_id'], 'budget_landed_entries' => ['id']],
|
|
'supplier-payables' => ['pa_sources' => ['id', 'tenant_id'], 'pa_proposals' => ['id'], 'pa_obligations' => ['id'],
|
|
'pa_events' => ['id'], 'pa_outbox' => ['event_id', 'state'], 'pa_commands' => ['id'], 'pa_access' => ['user_id', 'person', 'action']],
|
|
'general-ledger' => ['gl_accounts' => ['id', 'tenant_id'], 'gl_periods' => ['id'], 'gl_rules' => ['id'],
|
|
'gl_proposals' => ['id'], 'gl_reviews' => ['id'], 'gl_journals' => ['id'], 'gl_lines' => ['id'],
|
|
'gl_commands' => ['id'], 'gl_events' => ['id']],
|
|
'supplier-settlements' => ['ps_payments' => ['id', 'tenant_id'], 'ps_payment_decisions' => ['id'],
|
|
'ps_proposals' => ['id', 'allocation_cycle'], 'ps_allocation_aliases' => ['id'], 'ps_allocation_decisions' => ['id'],
|
|
'ps_allocations' => ['id'], 'ps_commands' => ['id'], 'ps_events' => ['id'], 'ps_outbox' => ['event_id', 'state'],
|
|
'ps_reversal_proposals' => ['id'], 'ps_reversals' => ['id']],
|
|
'general-ledger-cycle' => ['gl_corrections' => ['id'], 'gl_correction_results' => ['id'],
|
|
'gl_period_checks' => ['id'], 'gl_period_reviews' => ['id'], 'gl_period_closures' => ['id']],
|
|
'finance-configuration' => ['pa_access' => ['id', 'user_id', 'person', 'action'], 'gl_accounts' => ['id'],
|
|
'gl_rules' => ['id'], 'gl_periods' => ['id'], 'gl_commands' => ['id'], 'gl_events' => ['id']],
|
|
default => [],
|
|
};
|
|
foreach ($required as $table => $columns) {
|
|
$tables[$table] = array_values(array_unique([...($tables[$table] ?? []), ...$columns]));
|
|
}
|
|
}
|
|
foreach ($tables as $table => $columns) {
|
|
if (! $schema->hasColumns($table, $columns)) {
|
|
throw new LogicException('COMPRAS_RUNTIME_SCHEMA_INCOMPLETE:'.$table);
|
|
}
|
|
}
|
|
}
|
|
}
|