Read project
Reads all settings of one project: the code from the command line, or else the first project.
get() returns a Project, or throws a DimensionNotFoundException when the code does not exist. Use find() to get null instead.
$project->vatCode is the VAT code for all activities of the project; an activity with its own VAT code uses that one instead.
The time & expenses settings are in $project->projects, the same ProjectSettings as an activity has:
validFrom/validTill: the dates users can book hours on the project (null: no limit).invoiceDescription: longer description for the invoice template.customer,rateandauthoriser: aCodeSettingwith acodeand aChangeMode.billable: aBillableSettingwithbillable,forRatio(counts for the productivity ratio) and aChangeMode.quantities: extra quantities such as kilometres.
ChangeMode says whether users may change the setting in their timesheet (Allow, Disallow), or whether it comes from the activity or user level (Inherit). Inherited settings have no value of their own, so code and billable are null then.
$twinfield = Example::twinfield();
// The code from the command line, or else the first project.$code = $argv[1] ?? $twinfield->projects()->search()->limit(1)->get()->items[0]->code ?? exit('The company has no projects.' . PHP_EOL);
try { $project = $twinfield->projects()->get($code);} catch (DimensionNotFoundException $exception) { echo 'Not found: ', $exception->reason, PHP_EOL;
exit(1);}
$settings = $project->projects;
// A code with its change mode, e.g. "1010 (Disallow)" or "- (Inherit)".$setting = static fn (CodeSetting $setting): string => ($setting->code ?? '-') . ' (' . $setting->change->name . ')';
echo 'Code: ', $project->code, PHP_EOL;echo 'Name: ', $project->name, PHP_EOL;echo 'Short name: ', $project->shortName ?? '-', PHP_EOL;echo 'Status: ', $project->status->value, $project->inUse ? ' (in use)' : '', PHP_EOL;echo 'Modified: ', $project->modified?->format('Y-m-d H:i') ?? '-', PHP_EOL;echo 'VAT code: ', $project->vatCode ?? '-', PHP_EOL;echo 'Valid from: ', $settings->validFrom?->format('Y-m-d') ?? '-', PHP_EOL;echo 'Valid till: ', $settings->validTill?->format('Y-m-d') ?? '-', PHP_EOL;echo 'Invoice: ', $settings->invoiceDescription ?? '-', PHP_EOL;echo 'Customer: ', $setting($settings->customer), PHP_EOL;echo 'Authoriser: ', $setting($settings->authoriser), PHP_EOL;echo 'Rate: ', $setting($settings->rate), PHP_EOL;echo 'Billable: ', match ($settings->billable->billable) { true => 'yes', false => 'no', null => '-',}, ' (', $settings->billable->change->name, ')', $settings->billable->forRatio ? ', counts for the ratio' : '', PHP_EOL;
foreach ($settings->quantities as $quantity) { echo 'Quantity: ', $quantity->label, $quantity->mandatory ? ' (mandatory)' : '', PHP_EOL;}php examples/projects/read-project/example.php P0001Code: P0001Name: Website redesignShort name: WebsiteStatus: active (in use)Modified: 2025-03-14 09:30VAT code: VHValid from: 2025-01-01Valid till: 2025-12-31Invoice: Redesign of the website & the API documentationCustomer: 1010 (Allow)Authoriser: SUPER (Disallow)Rate: T001 (Disallow)Billable: yes (Allow), counts for the ratioQuantity: KMSource
Section titled “Source”View examples/projects/read-project/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.