27 lines
4.0 KiB
PHP
27 lines
4.0 KiB
PHP
<?php
|
|
use IlluminateSupportStr;
|
|
require __DIR__.'/sgf-ledger-proof-bootstrap.php';
|
|
$obligationsBefore=$native->table('pa_obligations')->orderBy('id')->get()->toJson();$oldMovements=$native->table('stock_movements')->orderBy('id')->get()->toJson();$journalBefore=$native->table('gl_journals')->count();
|
|
$source=(int)$native->table('pa_obligations')->where('tenant_id',$nf['tenant'])->orderByDesc('id')->value('id');
|
|
$native->beginTransaction();
|
|
try{
|
|
$key=(string)Str::uuid();$input=['obligation_id'=>$source,'journal_on'=>'2026-11-10','period_key'=>'QA-2026-INTEGRADO','rule_key'=>'supplier_payable.recognised','reason'=>'Conferência integrada QA da obrigação existente, sem copiar dívida.'];
|
|
$proposal=$call('accounting_prepare','prepare',fn($e)=>$e->command('prepare',$input,$key));
|
|
$ok($proposal['state']==='prepared','existing native obligation is captured for the explicit SGF ledger scope');
|
|
$same=$call('accounting_prepare','prepare',fn($e)=>$e->command('prepare',$input,$key));$ok($same['proposal_id']===$proposal['proposal_id'],'same preparation key recovers the same proposal');
|
|
$p=$native->table('gl_proposals')->find($proposal['proposal_id']);$ok((int)$p->company_id===2&&(int)$p->unit_id===2,'ledger carries SGF company2/unit2 while obligation remains in native financial scope0/0');
|
|
$review=['proposal_id'=>$proposal['proposal_id'],'revision'=>$proposal['revision'],'decision'=>'approved','reason'=>'Revisão independente do impacto de100MZN e da origem existente.'];
|
|
$forbidden=false;try{$call('accounting_prepare','validate',fn($e)=>$e->command('validate',$review,(string)Str::uuid()));}catch(Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e){$forbidden=$e->getStatusCode()===403;}
|
|
$ok($forbidden,'preparation profile cannot acquire the review right through native identity mapping');
|
|
$decision=$call('accounting_review','validate',fn($e)=>$e->command('validate',$review,(string)Str::uuid()));$ok($decision['state']==='approved','distinct host and native person reviews the exact version');
|
|
$postKey=(string)Str::uuid();$post=['proposal_id'=>$proposal['proposal_id'],'revision'=>$proposal['revision'],'reason'=>'Aplicação única do impacto revisto; sem nova obrigação ou pagamento.'];
|
|
$posted=$call('accounting_prepare','post',fn($e)=>$e->command('post',$post,$postKey));$replay=$call('accounting_prepare','post',fn($e)=>$e->command('post',$post,$postKey));
|
|
$ok($posted['journal_id']===$replay['journal_id']&&$native->table('gl_journals')->count()===$journalBefore+1,'posting and response recovery create one journal only');
|
|
$lines=$native->table('gl_lines')->where('journal_id',$posted['journal_id'])->get();$ok($lines->count()===2&&(int)$lines->sum('debit_minor')===10000&&(int)$lines->sum('credit_minor')===10000,'same common writer balances100MZN in two scoped accounts');
|
|
$report=$call('read_only','view',fn($e)=>$e->trialBalance(['from_on'=>'2026-01-01','to_on'=>'2026-12-31','page'=>1,'per_page'=>25]));$ok(is_array($report),'read-only SGF profile can obtain the same ledger trial balance');
|
|
$native->statement('SET CONSTRAINTS ALL IMMEDIATE');$ok(true,'deferred journal and review constraints validate the qualified financial scope');
|
|
$ok($native->table('pa_obligations')->orderBy('id')->get()->toJson()===$obligationsBefore&&$native->table('stock_movements')->orderBy('id')->get()->toJson()===$oldMovements,'ledger operation neither copies debt nor changes physical stock');
|
|
}finally{while($native->transactionLevel()>0)$native->rollBack();}
|
|
$ok($native->table('gl_journals')->count()===$journalBefore,'isolated ledger proof rolls back all new journal effects');
|
|
$result=['passed'=>true,'checks'=>$checks,'book'=>'regression','native_financial_scope'=>['tenant_id'=>$nf['tenant'],'company_id'=>0,'unit_id'=>0],'sgf_ledger_scope'=>$f['scope'],'new_database'=>false,'target8085_touched'=>false];file_put_contents($work.'/ledger-result.json',json_encode($result,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/ledger-result.json']).PHP_EOL;
|