Read general ledger account
Reads one general ledger account, by the code you pass or else the first profit and loss account, and shows its settings.
A code belongs to a balance sheet account or a profit and loss account, so the example tries both with find(), which gives null when the code is not of that type. get() throws a DimensionNotFoundException instead.
GeneralLedgerAccount is strict: required values are never null, and optional values (short name, VAT code, periods) are null when they are not set. The settings:
subAnalysis: whether lines need a dimension 2, e.g. a cost center:Required,NotAllowedorOptional.childValidations: which dimensions lines may have below the account, e.g. typeKPL(cost centers) on level 2.matchable,vatCode(withvatCodeFixed),groups,activeFromandactiveUntil.
$twinfield = Example::twinfield();
// The code from the command line, or else the first profit and loss account.$code = $argv[1] ?? $twinfield->profitAndLossAccounts()->search()->limit(1)->get()->items[0]->code ?? exit('The company has no profit and loss accounts.' . PHP_EOL);
// A code is a balance sheet or a profit and loss account: find() gives null for the other type.$account = $twinfield->balanceSheetAccounts()->find($code) ?? $twinfield->profitAndLossAccounts()->find($code) ?? exit('No general ledger account ' . $code . PHP_EOL);
echo 'Code: ', $account->code, PHP_EOL;echo 'Name: ', $account->name, PHP_EOL;echo 'Type: ', $account->type->label(), ' (', $account->type->value, ')', PHP_EOL;echo 'Status: ', $account->status->value, $account->inUse ? ' (in use)' : '', PHP_EOL;echo 'Matchable: ', $account->matchable ? 'yes' : 'no', PHP_EOL;echo 'Sub-analysis: ', $account->subAnalysis->name, PHP_EOL;echo 'Validations: ', implode(', ', array_map( static fn (ChildValidation $validation): string => $validation->type->value . ' ' . $validation->value, $account->childValidations,)) ?: '-', PHP_EOL;echo 'VAT code: ', $account->vatCode?->code ?? '-', $account->vatCodeFixed ? ' (fixed)' : '', PHP_EOL;echo 'Groups: ', implode(', ', $account->groups) ?: '-', PHP_EOL;echo 'Modified: ', $account->modified?->format('Y-m-d H:i') ?? '-', PHP_EOL;php examples/general-ledger-accounts/read-general-ledger-account/example.phpCode: 40000Name: Brutolonen en salarissenType: profit and loss account (PNL)Status: active (in use)Matchable: noSub-analysis: OptionalValidations: type KPLVAT code: -Groups: -Modified: 2014-12-19 07:14php examples/general-ledger-accounts/read-general-ledger-account/example.php 0100Code: 0100Name: OprichtingskostenType: balance sheet account (BAS)Status: hide (in use)Matchable: noSub-analysis: NotAllowedValidations: -VAT code: -Groups: -Modified: 2014-12-19 07:04Source
Section titled “Source”View examples/general-ledger-accounts/read-general-ledger-account/example.php on GitHub.
Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.