Read article
Reads one article with its sub-articles: the code you pass, or else the first one.
Twinfield documentation: Articles.
get() returns an Article; find() returns null instead of throwing when the code does not exist.
| Property | What it holds |
|---|---|
code, name, shortName |
The article; shortName is null when not set. |
status |
ArticleStatus: active, deleted or hidden (deleted while used in an invoice). |
type, percentage |
ArticleType::Normal, Discount or Premium; a discount or premium is an amount or a percentage. |
vatCode |
The default VAT code; null when not set, as for a discount. |
unitNameSingular, unitNamePlural |
The unit, e.g. Piece and Pieces; null when not set. |
allowChangeVatCode, allowChangeUnitPrice, allowDiscountOrPremium, allowDecimalQuantity |
What may be changed on the invoice line. |
performanceType, allowChangePerformanceType |
For ICT VAT codes; null when not set. Twinfield leaves them out for discounts and premiums. |
subArticles |
The SubArticles, deleted ones included; activeSubArticles() leaves those out, subArticle($code) gives one. |
A SubArticle has the price and where the revenue goes:
| Property | What it holds |
|---|---|
code |
The code for the invoice line; null for the only sub-article of an article, which may have no code. |
name, shortName, units |
Name, and the number of units of the article per quantity. |
unitPriceExcl, unitPriceInc |
Price excluding and including VAT; for a discount or premium with a percentage, the percentage. |
generalLedgerAccount, generalLedgerAccountName |
The revenue account. |
costCenter, costCenterName, freeText3 |
null when not set. |
status, inUse |
SubArticleStatus (active or deleted), and whether an invoice uses it. |
Prices are Amount objects: numeric strings with two decimals ('750.00'), never floats.
subArticles($articleCode) on the resource gives only the code and name of the sub-articles, with the Finder type SAR: one small request, e.g. to fill a list.
When Twinfield returns something the SDK does not expect, such as an unknown article type, you get an UnexpectedResponseException with the path of the element, instead of a silent default.
$twinfield = Example::twinfield();
try { $article = $twinfield->articles()->get($code);} catch (ArticleNotFoundException $exception) { echo 'Not found: ', $exception->reason, PHP_EOL;
exit(1);}
foreach ($article->subArticles as $subArticle) { echo 'Sub: ', $subArticle->code ?? '(no code)', ' ', $subArticle->name, ': '; echo $subArticle->unitPriceExcl, ' excl., ', $subArticle->unitPriceInc, ' incl., '; echo 'account ', $subArticle->generalLedgerAccount, ', ', $subArticle->status->value; echo $subArticle->inUse ? ' (in use)' : '', PHP_EOL;}php examples/articles/read-article/example.phpphp examples/articles/read-article/example.php BIKECode: BIKEName: Bike summer editionStatus: activeType: normalVAT code: VHUnit: Piece / PiecesSub: BIKE.L Lady's bike summer edition: 750.00 excl., 907.50 incl., account 8050, active (in use)Sub: BIKE.M Man's bike summer edition: 760.00 excl., 919.60 incl., account 8051, activeWhat the SDK sends to Twinfield and what Twinfield sends back, for a call like the one in this example. The responses come from the tests, with example data.
Twinfield documentation: Articles: Read.
$twinfield->articles()->get('BIKE');The SDK sends this XML as xmlRequest of ProcessXmlString to processxml.asmx:
<read> <type>article</type> <office>1000</office> <code>BIKE</code></read>Twinfield answers with this XML in ProcessXmlStringResult:
<article result="1"> <header status="active"> <office>1000</office> <code>BIKE</code> <type>normal</type> <name>Bike summer edition</name> <shortname>Bike summer</shortname> <unitnamesingular>Piece</unitnamesingular> <unitnameplural>Pieces</unitnameplural> <vatcode>VH</vatcode> <allowchangevatcode>false</allowchangevatcode> <performancetype/> <allowchangeperformancetype>false</allowchangeperformancetype> <percentage>false</percentage> <allowdiscountorpremium>true</allowdiscountorpremium> <allowchangeunitsprice>false</allowchangeunitsprice> <allowdecimalquantity>false</allowdecimalquantity> </header> <lines> <line inuse="true" status="active"> <unitspriceexcl>750.00</unitspriceexcl> <unitspriceinc>907.50</unitspriceinc> <units>1</units> <name>Lady's bike summer edition</name> <shortname>Lady summer</shortname> <subcode>BIKE.L</subcode> <freetext1 name="Bike lady" shortname="" dimensiontype="PNL">8050</freetext1> <freetext2 name="" shortname="" dimensiontype=""/> <freetext3/> <freetext4/> <freetext5/> <freetext6/> </line> <line inuse="false" status="active"> <unitspriceexcl>760.00</unitspriceexcl> <unitspriceinc>919.60</unitspriceinc> <units>1</units> <name>Man's bike summer edition</name> <shortname/> <subcode>BIKE.M</subcode> <freetext1 name="Bike man" shortname="" dimensiontype="PNL">8051</freetext1> <freetext2 name="Sales" shortname="" dimensiontype="KPL">00001</freetext2> <freetext3>Summer</freetext3> <freetext4/> <freetext5/> <freetext6/> </line> <line inuse="false" status="deleted"> <unitspriceexcl>350.00</unitspriceexcl> <unitspriceinc>423.50</unitspriceinc> <units>1</units> <name>Kid's bike summer edition</name> <shortname>Kid summer</shortname> <subcode>BIKE.K</subcode> <freetext1 name="" shortname="" dimensiontype="PNL">8052</freetext1> <freetext2 name="" shortname="" dimensiontype=""/> <freetext3/> <freetext4/> <freetext5/> <freetext6/> </line> </lines></article>Source
Section titled “Source”View examples/articles/read-article/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.