Skip to content

Switch company

Runs the same call for several companies (offices).

Most Twinfield calls work on one company. company('1000') gives you a client for that company. The client is immutable: company() returns a new client and leaves the original as it was, so you can safely keep one client per company.

$twinfield = Example::twinfield();
foreach (array_slice($twinfield->offices()->list(), 0, 3) as $office) {
$company = $twinfield->company($office->code);
$dimensions = $company->finder(FinderType::Dimensions)->limit(1)->get()->totalRows;
echo "{$office->code} {$office->name}: {$dimensions} dimensions", PHP_EOL;
}
echo 'The default company is still ', $twinfield->companyCode(), PHP_EOL;

limit(1) keeps the call small: only the total (totalRows) is needed here.

Terminal window
php examples/offices/switch-company/example.php
1000 Example Holding B.V.: 412 dimensions
1001 Example Retail B.V.: 1290 dimensions
1002 Example Services B.V.: 87 dimensions
The default company is still 1000

View examples/offices/switch-company/example.php on GitHub.