PHP · Track 8 · Tutorial 1 of 4
Put the steps in order
Put everything together in one run: the chart, the month, the detail, and the consolidation request - in the order BrizoConsol needs them.
1Put it together
Every track so far sent one thing. A monthly run sends them all, in the order BrizoConsol needs them.
2Write the run
Create monthly.php. Its two functions return the same data the earlier tutorials sent: replace them with reads from your own system.
monthly.php
// Replace these with reads from your own system. They return the same shapes the earlier tutorials sent.
function chartFromMySystem(): array
{
return [
['code' => '1000', 'name' => 'Operating bank', 'type' => 'Bank'],
['code' => '1200', 'name' => 'Trade receivables', 'type' => 'Accounts Receivable'],
['code' => '2000', 'name' => 'Trade payables', 'type' => 'Accounts Payable'],
['code' => '4000', 'name' => 'Sales revenue', 'type' => 'Revenue'],
['code' => '5000', 'name' => 'Cost of sales', 'type' => 'Direct Costs'],
['code' => '6000', 'name' => 'Rent', 'type' => 'Expense'],
];
}
function trialBalanceFromMySystem(string $period): array
{
return [
['account_code' => '1000', 'debit' => 20000.00, 'credit' => 0],
['account_code' => '1200', 'debit' => 5000.00, 'credit' => 0],
['account_code' => '2000', 'debit' => 0, 'credit' => 5000.00],
['account_code' => '4000', 'debit' => 0, 'credit' => 30000.00],
['account_code' => '5000', 'debit' => 8000.00, 'credit' => 0],
['account_code' => '6000', 'debit' => 2000.00, 'credit' => 0],
];
}The run itself:
monthly.php
function declarations(string $source, string $period, string $currency, ?string $webhook): array
{
$declarations = [
'source_reference' => $source,
'period' => $period,
'value_basis' => 'company_base',
'rate_direction' => 'document_to_base',
'base_currency' => $currency,
];
if ($webhook !== null) {
$declarations['webhook_url'] = $webhook;
}
return $declarations;
}
echo "Sending $period\n";
// 1. The chart first: a trial balance can only name accounts the chart already holds.
show('Chart', written(call('POST', "/organisations/$companyId/accounts", [
'declarations' => ['source_reference' => 'my-ledger', 'mode' => 'merge'],
'records' => chartFromMySystem(),
])));
// 2. The month, whole. The key makes a retry of this run harmless.
$month = written(call('POST', "/organisations/$companyId/trial-balances", [
'declarations' => declarations('my-ledger', $period, $currency, $webhook),
'records' => trialBalanceFromMySystem($period),
], ["Idempotency-Key: $companyId-$period-$version"]));
show('Trial balance', $month);
// 3. Invoices, bills and journal lines go here, as in tracks 4 and 5.
// 4. Ask for tonight's consolidation, once, after the last write.
$run = written(call('POST', "/organisations/$companyId/consolidation-requests"))['data'];
echo "Consolidation request {$run['id']}: {$run['status']}\n";
// Keep these two numbers: tomorrow, check-run.php reads what became of them.
file_put_contents(__DIR__ . "/run-$period.json", json_encode(['month' => $month['id'], 'consolidation' => $run['id']]));
echo "Tomorrow: php check-run.php {$month['id']} {$run['id']}\n";
3Run it
php monthly.php 2026-09Check
Sending 2026-09
Chart: request 101 - 0 created, 1 updated, 5 unchanged, 0 refused
Trial balance: request 92 - 6 created, 0 updated, 0 unchanged, 0 refused
Consolidation request 12: pending
Tomorrow: php check-run.php 92 12The trial balance answers the request from before, because the key is the same: nothing was written twice.
4Run it every month
Schedule it for after your books close each month - with cron, the Windows Task Scheduler, or your own scheduler - and schedule check-run.php for the next morning. Without a month on the command line, it sends last month.
Want more detail? See the documentation