Files
SGF/app/Modules/Finance/BankLedgerSource.php
2026-11-11 09:00:17 +02:00

19 lines
2.1 KiB
PHP

<?php
namespace App\Modules\Finance;
use App\Shared\Installation\CompositionRuntime;use App\Modules\Accounting\SourceBook;use Illuminate\Support\Facades\DB;
/** Strict read adapter over two existing native QA lines. No fixture fallback or bank classification. */
class BankLedgerSource
{
public function snapshot(array $scope,array $binding):array
{
$p=CompositionRuntime::physical();$file='C:/laragon/data/sgf-tempo/run/modular-regression-'.getenv('SGF_ISOLATED_REGRESSION_RUN').'/private/receipt-composition-'.$p['composition'].'/binding.json';abort_unless(realpath((string)config('receipt_qa.profile'))===realpath($file),403);$profile=json_decode(file_get_contents($file),true,64,JSON_THROW_ON_ERROR);$c=$profile['connection'];abort_unless($c['database']==='compras_receipts_test_'.$p['composition']&&$c['username']==='payable_history_native_'.$p['composition']&&$c['host']==='127.0.0.1'&&(int)$c['port']===55439,403);config(['database.connections.receipt_native'=>$c]);
return $this->read($scope,$binding);
}
private function read(array $s,array $b):array
{
$rows=SourceBook::table('gl_lines')->where($s)->whereIn('id',$b['ledger_line_ids'])->orderBy('id')->get();abort_unless($rows->count()===2,409,'As duas fontes contabilísticas do exercício não estão disponíveis.');$out=[];
foreach($rows as$r){$j=SourceBook::table('gl_journals')->where($s)->where('id',$r->journal_id)->first();$a=SourceBook::table('gl_accounts')->where($s)->where('id',$r->account_id)->first();abort_unless($j&&$a&&$a->code==='QA-LIQUIDACAO'&&$j->currency==='MZN'&&$j->journal_on==='2026-11-10'&&max($r->debit_minor,$r->credit_minor)===2000,409,'Linha contabilística incompatível com o exercício autorizado.');$out[]=['id'=>$r->id,'journal_id'=>$r->journal_id,'account_code'=>$a->code,'date'=>$j->journal_on,'currency'=>'MZN','debit_minor'=>$r->debit_minor,'credit_minor'=>$r->credit_minor,'journal_sha256'=>hash('sha256',$j->snapshot)];}
return ['kind'=>'native_qa_ledger','lines'=>$out,'hash'=>hash('sha256',\Tempo\Finance\Payables\Payables::canonical($out))];
}
}