true,'cost_ledger.synthetic_enabled'=>true,'industrial_ledger.synthetic_enabled'=>true,'cost_ledger.correction_enabled'=>true,'industrial_ledger.correction_enabled'=>true]); $commercial=json_decode(file_get_contents($s['root'].'/single-commercial.json'),true);$receivables=json_decode(file_get_contents($s['root'].'/single-receivables.json'),true); $before=$native->table('gl_journals')->count();$native->beginTransaction(); try{ $posted=[]; foreach([['sales.invoice',$commercial['invoice'],100000],['receivable.allocated',$receivables['allocations'][0],40000],['receivable.allocated',$receivables['allocations'][1],60000],['receivable.reversed',$receivables['reversal_effect'],40000]] as [$kind,$id,$amount]){ $proposal=$call('accounting_prepare','prepare',fn($e)=>$e->command('effect-prepare',['effect_type'=>$kind,'source_id'=>$id,'journal_on'=>'2026-11-10','period_key'=>'QA-2026-INTEGRADO','rule_key'=>$kind,'reason'=>'Origem comercial explícita e actual do mesmo SGF, sem copiar dívida.'],(string)Str::uuid())); $call('accounting_review','validate',fn($e)=>$e->command('validate',['proposal_id'=>$proposal['proposal_id'],'revision'=>$proposal['revision'],'decision'=>'approved','reason'=>'Conferência independente da fotografia entre os dois livros.'],(string)Str::uuid())); $journal=$call('accounting_prepare','post',fn($e)=>$e->command('post',['proposal_id'=>$proposal['proposal_id'],'revision'=>$proposal['revision'],'reason'=>'Lançamento único após revalidar a origem de Comercial/Financeiro.'],(string)Str::uuid())); $rows=$native->table('gl_lines')->where('journal_id',$journal['journal_id'])->get();$ok((int)$rows->sum('debit_minor')===$amount&&(int)$rows->sum('credit_minor')===$amount,'qualified cross-book '.$kind.' amount '.$amount.' balances in the same common journal'); if($kind==='sales.invoice')$ok($rows->count()===3,'test invoice uses exact base862.07 plus documentary tax137.93 in three lines'); $posted[]=$journal['journal_id']; } $native->statement('SET CONSTRAINTS ALL IMMEDIATE');$ok(true,'native SQL balance constraints validate all four host-origin effects'); $receipt=$native->table('gl_journals')->where('id',$posted[0])->first();$snap=json_decode($receipt->snapshot,true);$ok($snap['source']['document_revision']===hash('sha256',$host->table('si_invoices')->where('id',$commercial['invoice'])->value('snapshot')),'native journal retains exact immutable SGF document revision'); $bad=false;try{$call('accounting_prepare','prepare',fn($e)=>$e->command('effect-prepare',['effect_type'=>'sales.invoice','source_id'=>999999999,'journal_on'=>'2026-11-10','period_key'=>'QA-2026-INTEGRADO','rule_key'=>'sales.invoice','reason'=>'Origem inexistente não pode ser substituída por outro documento.'],(string)Str::uuid()));}catch(Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e){$bad=$e->getStatusCode()===403;} $ok($bad,'unqualified or missing host invoice is refused without choosing another source'); }finally{while($native->transactionLevel()>0)$native->rollBack();} $ok($native->table('gl_journals')->count()===$before,'new commercial journal effects are rolled back after regression'); file_put_contents($work.'/sales-ledger-result.json',json_encode(['passed'=>true,'checks'=>$checks,'same_native_book'=>true,'new_database'=>false,'new_server'=>false,'host_business_writes_from_ledger'=>0],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'proof'=>$work.'/sales-ledger-result.json']).PHP_EOL;