make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); \App\Shared\Testing\TestingDatabaseGuard::assertSafe(); $db = \Illuminate\Support\Facades\DB::class; $count = $db::table('b_internal_confirmations')->count(); $histories = $db::table('a_history')->where('area', 'internal_confirmations')->count(); $events = $db::table('a_events')->where('type', 'b1.billing_draft.confirmed_internal')->count(); $captured = $db::table('a_events as e')->join('a_outbox as o', 'e.id', '=', 'o.event_id')->where('e.type', 'b1.billing_draft.confirmed_internal')->where('o.state', 'captured')->count(); $missingHistory = $db::table('b_internal_confirmations as b')->whereNotExists(fn ($q) => $q->selectRaw('1')->from('a_history as h')->where('h.area', 'internal_confirmations')->whereColumn('h.record_id', 'b.id'))->count(); if ($count < 1 || $count !== $histories || $count !== $events || $count !== $captured || $missingHistory !== 0) { throw new RuntimeException('Incomplete B1 capture.'); } $report = ['database' => 'sgf_tempo_test', 'confirmations' => $count, 'histories' => $histories, 'confirmation_events' => $events, 'captured_outbox' => $captured, 'missing_history' => $missingHistory, 'fiscal_states' => $db::table('b_internal_confirmations')->selectRaw("DISTINCT snapshot->>'fiscal_status' AS state")->pluck('state')->all(), 'accounting_states' => $db::table('b_internal_confirmations')->selectRaw("DISTINCT snapshot->>'accounting_status' AS state")->pluck('state')->all()]; file_put_contents(base_path('docs/proofs/b1-capture.json'), json_encode($report, JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR)); echo "B1 confirmation/history/event/outbox counts match; no missing historical capture.\n";