PHP · Track 2 · Tutorial 1 of 4
Send your chart of accounts
Send the company's chart of accounts: the list of account codes every figure you send later will refer to.
1Why the chart comes first
The trial balance, invoice and bill lines and journal lines you send later all name an account by its code. BrizoConsol only accepts codes the company's chart already holds, so the chart is always the first thing you send - and the thing you send again whenever your chart changes.
2Write the chart
Create chart.php. Each account has a code, a name, and a type - one of BrizoConsol's account types, by name: Bank, Accounts Receivable, Revenue, Expense and so on.
chart.php
<?php
// chart.php - sends the company's chart of accounts.
require __DIR__ . '/brizo.php';
$accounts = [
['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'],
['code' => '6900', 'name' => 'Sundry expenses', 'type' => 'Expense'],
];
$request = written(call('POST', "/organisations/$companyId/accounts", [
'declarations' => ['source_reference' => 'my-ledger', 'mode' => 'merge'],
'records' => $accounts,
]));
show('Chart', $request);source_reference is your own name for where the data comes from - my-ledger here. Use the same name every time you send from the same system.
The answer is counted for you by show(). Add it, with the function it uses to list refused records, to brizo.php:
brizo.php
// A write answers 202 when it was written. Anything else stops the script with BrizoConsol's own reason.
function written(array $answer): array
{
if ($answer['status'] === 202) {
return $answer['body'];
}
$body = $answer['body'] ?? [];
$reason = $body['message'] ?? 'No reason given';
foreach ($body['errors'] ?? [] as $error) {
$reason .= "\n " . ($error['field'] ?? '') . ': ' . ($error['code'] ?? '') . ' - ' . ($error['detail'] ?? '');
}
if (isset($body['failure']['code'])) {
$reason .= "\n " . $body['failure']['code'];
}
throw new RuntimeException("Refused ({$answer['status']}): $reason");
}brizo.php
// Lists the records a written request refused, with BrizoConsol's reason for each.
function reportRefused(array $request): void
{
global $companyId;
if ($request['counts']['rejected'] === 0) {
return;
}
$results = call('GET', "/organisations/$companyId/requests/{$request['id']}/results")['body'];
foreach ($results['records'] as $record) {
foreach ($record['errors'] as $error) {
echo " Refused record {$record['index']} ({$record['identity']}): {$error['code']} - {$error['detail']}\n";
}
}
}brizo.php
// Prints what a written request did.
function show(string $what, array $request): void
{
$c = $request['counts'];
echo "$what: request {$request['id']} - {$c['created']} created, {$c['updated']} updated, "
. "{$c['unchanged']} unchanged, {$c['rejected']} refused\n";
reportRefused($request);
}3Send it
php chart.phpCheck
Chart: request 90 - 7 created, 0 updated, 0 unchanged, 0 refusedYour request number will be different: every request gets the next number. Run it again and every account is unchanged: sending the same chart twice changes nothing.
4Which account types there are
The type must be one BrizoConsol has. Ask for the list with GET /account-types; the names are matched whatever their capitals. A type BrizoConsol doesn't have refuses that account, and the rest of the chart is still stored.
5Limits to know
- A company's chart holds up to 300 accounts. A request that would take it past that is refused whole.
- A chart is sent for a company, never for a group: groups hold no accounts of their own.
Want more detail? See the documentation