12 lines
5.3 KiB
PHP
12 lines
5.3 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
$output=$s['root'].'/industrial-extra-cases.json';if(file_exists($output))throw new LogicException('Completed extra evidence preserved');$before=$fingerprint();$checks=0;$cases=[];$ok=function($v,$m)use(&$checks){$checks++;if(!$v)throw new LogicException($m);};$refuse=function($fn,$fragment=null)use($ok){$caught=false;try{$fn();}catch(DomainException|Symfony\Component\HttpKernel\Exception\HttpException|Illuminate\Validation\ValidationException $e){$caught=$fragment===null||str_contains($e->getMessage(),$fragment);}$ok($caught,'Expected extra industrial refusal'.($fragment?' '.$fragment:''));};$case=function($name,$fn)use(&$checks,&$cases,$enter){$at=$checks;DB::beginTransaction();try{$fn();$cases[]=['name'=>$name,'checks'=>$checks-$at,'passed'=>true];}finally{while(DB::transactionLevel())DB::rollBack();$enter('read');}};
|
|
$refresh=function($amount,$approved=true)use($i,$ic,$enter){$r=DB::table('ic_inputs')->find($i['refs']['material_rate']['id']);$d=json_decode($r->data,true);$d['amount']=$amount;$v=$ic->input($i['lot_id'],$enter('prepare')->id,['kind'=>'material_rate','source_ref'=>$r->source_ref,'version'=>2,'previous_id'=>$r->id,'data'=>$d,'evidence'=>'New rollback-only rate for exact industrial boundary cases.'],(string)Str::uuid());$ic->decide($i['lot_id'],$enter('validate')->id,['type'=>'input','id'=>$v['id'],'version'=>2,'decision'=>'approved','reason'=>'Distinct exact rate version for rollback-only boundary.'],(string)Str::uuid());$refs=$i['refs'];$refs['material_rate']=['id'=>$v['id'],'version'=>2];$r=$ic->calculate($i['lot_id'],$enter('prepare')->id,['version'=>2,'previous_id'=>$i['result_id'],'refs'=>$refs,'currency'=>'MZN'],(string)Str::uuid());if($approved)$ic->decide($i['lot_id'],$enter('validate')->id,['type'=>'result','id'=>$r['id'],'version'=>2,'decision'=>'approved','reason'=>'Distinct successor result review; no accounting correction.'],(string)Str::uuid());return $r;};
|
|
$case('unapproved-result-and-non-cent-total',function()use($refresh,$refuse,$provider,$enter,$i,$ok){$refresh('50.00000001',false);$refuse(fn()=>$provider->source($enter('read'),$i['lot_id']));DB::rollBack();DB::beginTransaction();$refresh('50.00000001');$c=app(App\Modules\Industry\IndustrialCosts::class)->conference($i['lot_id'],$enter('read')->id);$ok($c['snapshot']['selected_total_exact']==='1800.0000002','Industrial rational total preserved exactly');$refuse(fn()=>$provider->source($enter('read'),$i['lot_id']),'cêntimos');});
|
|
$case('production-not-completed-and-criterion-pending',function()use($ic,$i,$enter,$provider,$refuse){$row=DB::table('ic_inputs')->find($i['refs']['production']['id']);$data=json_decode($row->data,true);$data['completed']=false;$refuse(fn()=>$ic->input($i['lot_id'],$enter('prepare')->id,['kind'=>'production','source_ref'=>$row->source_ref,'version'=>2,'previous_id'=>$row->id,'data'=>$data,'evidence'=>'Incomplete production must remain refused.'],(string)Str::uuid()));$row=DB::table('ic_inputs')->find($i['refs']['criterion']['id']);$ic->input($i['lot_id'],$enter('prepare')->id,['kind'=>'criterion','source_ref'=>$row->source_ref,'version'=>2,'previous_id'=>$row->id,'data'=>json_decode($row->data,true),'evidence'=>'Unreviewed current criterion cannot support capture.'],(string)Str::uuid());$refuse(fn()=>$provider->source($enter('read'),$i['lot_id']));});
|
|
$case('canonical-source-cannot-be-used-by-second-lot',function()use($ic,$i,$enter,$refuse){$lot=$ic->open($enter('prepare')->id,['reference'=>'LOT-TEST-'.Str::uuid(),'product_reference'=>'PROD-TEST-'.Str::uuid(),'product_name'=>'Rollback-only duplicate origin product','centre'=>'QA synthetic centre','period_start'=>'2026-10-01','period_end'=>'2026-10-31','currency'=>'MZN'],(string)Str::uuid());$row=DB::table('ic_inputs')->find($i['refs']['material']['id']);$refuse(fn()=>$ic->input($lot['id'],$enter('prepare')->id,['kind'=>'material','source_ref'=>$row->source_ref,'version'=>1,'previous_id'=>null,'data'=>json_decode($row->data,true),'evidence'=>'Do not reuse original industrial source in another lot.'],(string)Str::uuid()));});
|
|
$case('changed-posted-result-needs-future-correction',function()use($refresh,$provider,$enter,$i,$ok){$refresh('50');$d=$provider->workspace($enter('read'),$i['lot_id'],1);$ok($d['source']['principal_minor']===180000&&$d['accounting_state']==='requires_future_correction','Same amount with new result does not silently replace posted version');$ok(DB::table('gl_journals')->where('snapshot->source->effect_type','industry.cost.validated')->count()===1,'No second recognition or automatic correction');});
|
|
$case('whole-lot-period-must-fit',function()use($scope,$command,$body,$refuse){$r=(array)DB::table('gl_periods')->where($scope)->where('period_key','QA-2026-10')->orderByDesc('version')->first();unset($r['id']);$r['version']++;$r['starts_on']='2026-10-02';$r['status']='open';DB::table('gl_periods')->insert($r);$refuse(fn()=>$command('prepare','effect-prepare',$body),'Período não contém');});
|
|
$ok($fingerprint()===$before,'Extra probes preserve all industrial originals/outbox/rights');file_put_contents($output,json_encode(['passed'=>true,'checks'=>$checks,'cases'=>$cases,'rollback_only'=>true,'source_outbox_rights_unchanged'=>true],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo 'Extra industrial boundaries: '.count($cases)." cases/$checks checks.\n";
|