7 lines
2.2 KiB
PHP
7 lines
2.2 KiB
PHP
<?php
|
|
use Illuminate\Support\Str;
|
|
$book=$argv[1]??'regression';require __DIR__.'/sgf-single-bootstrap.php';if(!$host->getSchemaBuilder()->hasTable('cash_events'))$host->transaction(fn()=>$host->unprepared(file_get_contents($repo.'/database/sql/cash.sql')));
|
|
$output=$host->table('sd_outputs')->where($f['scope'])->where('kind','invoice_receipt')->firstOrFail();$allocation=$host->table('sr_effects')->where('id',$output->effect_id)->where('kind','allocate')->firstOrFail();$receipt=$host->table('sr_records')->where($f['scope'])->where(['id'=>$allocation->receipt_id,'kind'=>'receipt','amount'=>'1000.00'])->firstOrFail();$path=$s['root'].'/cash-binding.json';
|
|
if(!is_file($path))file_put_contents($path,json_encode(['composition'=>$tag,'scope'=>$f['scope'],'session_key'=>(string)Str::uuid(),'receipt_id'=>$receipt->id,'invoice_id'=>$receipt->invoice_id,'source_output_id'=>$output->id,'amount_minor'=>100000,'expense_minor'=>5000,'period_key'=>'QA-2026-INTEGRADO'],JSON_PRETTY_PRINT));
|
|
$native->transaction(function()use($native,$f){$s=$f['scope'];$ids=[];foreach(['QA-CAIXA','QA-DESPESA-CAIXA','QA-LIQUIDACAO-CLIENTE'] as $code){$id=$native->table('gl_accounts')->where($s)->where('code',$code)->value('id');if(!$id&&$code==='QA-LIQUIDACAO-CLIENTE')throw new LogicException('Existing liquidity account required');if(!$id)$id=$native->table('gl_accounts')->insertGetId($s+['code'=>$code,'label'=>'Conta exclusivamente QA '.$code,'currency'=>'MZN','is_movement'=>true]);$ids[$code]=$id;}foreach(['cash.receipt_classified'=>['QA-CAIXA','QA-LIQUIDACAO-CLIENTE'],'cash.expense_confirmed'=>['QA-DESPESA-CAIXA','QA-CAIXA']] as $kind=>[$debit,$credit])if(!$native->table('gl_rules')->where($s)->where('rule_key',$kind)->exists())$native->table('gl_rules')->insert($s+['rule_key'=>$kind,'effect_type'=>$kind,'version'=>1,'policy'=>'QA-CASH-JOURNAL-v1','currency'=>'MZN','valid_from'=>'2026-01-01','valid_to'=>'2026-12-31','debit_account_id'=>$ids[$debit],'credit_account_id'=>$ids[$credit],'created_by'=>4,'reason'=>'Ciclo Caixa QA0+1000-50=950 expressamente autorizado.','created_at'=>now()]);});echo json_encode(['passed'=>true,'book'=>$book,'binding_sha256'=>hash_file('sha256',$path),'journals_unchanged'=>true]).PHP_EOL;
|