Skip to content

Bind accounts

Binds a general ledger account to a node of a reporting structure, and unbinds it again. This example changes data: run it on a test company, after Save hierarchy.

  • hierarchies()->bind($node, ...$accounts) adds accounts to a node; unbind() removes them. Pass a HierarchyNode or its ID ($node->id).
  • Only the accounts of the company of the client change; other companies keep theirs.

Twinfield refuses an account that is already bound elsewhere in the reporting structure with the same balance type (HierarchyBindMessage::BindingNotUnique).

$twinfield = Example::twinfield();
$hierarchies = $twinfield->hierarchies();
// A reporting structure from the save-hierarchy example, one of its nodes and an account.
$code = $argv[1] ?? 'SDK_EXAMPLE';
$nodeCode = $argv[2] ?? 'C1';
$account = HierarchyAccount::profitAndLoss($argv[3] ?? '4010');
$node = $hierarchies->get($code)->node($nodeCode)
?? throw new RuntimeException(sprintf('Reporting structure %s has no node %s.', $code, $nodeCode));
// Binding changes only this node, for the accounts of the company of the client.
$hierarchies->bind($node, $account);
echo 'Bound ', $account, ' to ', $hierarchies->get($code)->node($nodeCode), PHP_EOL;
$hierarchies->unbind($node, $account);
echo 'Unbound it again: ', implode(', ', $hierarchies->get($code)->node($nodeCode)->accounts ?? []), PHP_EOL;
Terminal window
php examples/hierarchies/bind-accounts/example.php
php examples/hierarchies/bind-accounts/example.php SDK_EXAMPLE C1 4010

Add TWINFIELD_DEBUG=1 to see the SOAP requests and responses.

View examples/hierarchies/bind-accounts/example.php on GitHub.

Made by SolveBeam

Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.