Create journal transaction
Books a correction as journal transaction in day book MEMO, then deletes it again. Without --save it only shows the request. With --save it changes data in Twinfield.
Twinfield documentation: Journal transactions.
JournalTransactionInput::create($dayBook, $date) starts the input. A journal transaction has no total line: every line has its own side.
debit($dim1, $amount, ...)adds a debit detail line,credit(...)a credit one. Both take the same named arguments:customer,supplierorcostCenter(dim2),project(dim3),invoice,description,vatCodeandvatValue.- The lines must balance: the sum of the debit lines equals the sum of the credit lines.
balance()gives the difference, and the input throws anInvalidArgumentExceptionbefore anything is sent when it is not zero. - A line with a VAT code needs the VAT amount. Twinfield books the VAT on the VAT account, on the same side as the line, so the other lines include it. With a
VatCodeobject instead of a code, the VAT is calculated with its percentage on the transaction date.
New transactions are provisional, so they can still be changed or deleted. Call final() on the input to post it at once. regime(Regime::Fiscal) books it in one regime only; without it Twinfield uses Generic.
The example uses the first two profit and loss accounts of the company.
$twinfield = Example::twinfield();$journal = $twinfield->journalTransactions();
// In your own application: your journal day book and accounts, e.g. 4500 and 4510.[$from, $to] = Example::generalLedgerAccounts($twinfield, 'PNL', 2);$date = new DateTimeImmutable('today');
// A correction: move costs that were booked on the wrong account. Every line has its own side// and the lines must balance; the input checks that before anything is sent.$input = JournalTransactionInput::create('MEMO', $date) ->freeText(1, 'Correction') ->debit($to, '125.00', description: 'Booked on the wrong account') ->credit($from, '125.00', description: 'Booked on the wrong account');
if (!in_array('--save', $argv ?? [], true)) { echo 'Dry run; add --save to create it as provisional transaction and delete it again:', PHP_EOL, PHP_EOL; echo Example::xml($input->toXml((string) $twinfield->companyCode())), PHP_EOL;
exit(0);}
try { $transaction = $journal->create($input);} catch (ProcessXmlException $exception) { foreach ($exception->result->messages() as $message) { echo $message->type->value, ' at ', $message->path, ': ', $message->text, PHP_EOL; }
exit(1);}
echo 'Created: ', $transaction->dayBook(), ' ', $transaction->number(), ' (', $transaction->header->status->name, ')', ', period ', $transaction->header->period, PHP_EOL;
foreach ($transaction->details as $line) { echo ' ', $line->id, ' ', $line->dim1->code, ' ', $line->debitCredit->value, ' ', $line->value, PHP_EOL;}
// Clean up: delete the provisional example transaction again.$journal->delete($transaction->dayBook(), $transaction->number(), 'twinfield-php example');
echo 'Deleted: ', $transaction->dayBook(), ' ', $transaction->number(), PHP_EOL;php examples/journal-transactions/create-journal-transaction/example.phpDry run; add --save to create it as provisional transaction and delete it again:
<transaction destiny="temporary"> <header> <office>1002</office> <code>MEMO</code> <date>20261109</date> <freetext1>Correction</freetext1> </header> <lines> <line type="detail" id="1"> <dim1>40005</dim1> <debitcredit>debit</debitcredit> <value>125.00</value> <description>Booked on the wrong account</description> </line> <line type="detail" id="2"> <dim1>40000</dim1> <debitcredit>credit</debitcredit> <value>125.00</value> <description>Booked on the wrong account</description> </line> </lines></transaction>Add --save to send it. This creates a provisional transaction and deletes it again:
php examples/journal-transactions/create-journal-transaction/example.php --saveWhat 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.
Create
Section titled “Create”Twinfield documentation: Journal transactions: Create.
$twinfield->journalTransactions()->create( JournalTransactionInput::create('MEMO', new DateTimeImmutable('2026-11-04')) ->debit('4008', '435.55') ->credit('1300', '435.55', customer: '1000', invoice: '11001770', description: 'Invoice paid'),);The SDK sends this XML as xmlRequest of ProcessXmlString to processxml.asmx:
<transaction destiny="temporary"> <header> <office>1000</office> <code>MEMO</code> <date>20261104</date> </header> <lines> <line type="detail" id="1"> <dim1>4008</dim1> <debitcredit>debit</debitcredit> <value>435.55</value> </line> <line type="detail" id="2"> <dim1>1300</dim1> <dim2>1000</dim2> <debitcredit>credit</debitcredit> <value>435.55</value> <invoicenumber>11001770</invoicenumber> <description>Invoice paid</description> </line> </lines></transaction>Twinfield answers with this XML in ProcessXmlStringResult:
<transaction destiny="temporary" result="1" location="temporary"> <header> <office name="Example Holding B.V." shortname="">1000</office> <code name="Memoriaal" shortname="Memo">MEMO</code> <number>202600004</number> <period>2026/11</period> <currency name="Euro" shortname="Euro">EUR</currency> <regime>Generic</regime> <date>20261104</date> <origin>import</origin> <originreference/> <modificationdate>20261201091200</modificationdate> <user name="Example user" shortname="User">EXAMPLE</user> <inputdate>20261130101530</inputdate> </header> <lines> <line type="detail" id="1"> <dim1 name="Betalingsverschillen" shortname="" dimensiontype="PNL">4008</dim1> <debitcredit>debit</debitcredit> <basevalue>435.55</basevalue> <rate>1</rate> <value>435.55</value> <reprate>1</reprate> <repvalue>435.55</repvalue> <invoicenumber/> <description/> <matchstatus>notmatchable</matchstatus> </line> <line type="detail" id="2"> <dim1 name="Debiteuren" shortname="" dimensiontype="BAS">1300</dim1> <dim2 name="Example customer" shortname="" dimensiontype="DEB">1000</dim2> <debitcredit>credit</debitcredit> <basevalue>435.55</basevalue> <rate>1</rate> <value>435.55</value> <reprate>1</reprate> <repvalue>435.55</repvalue> <invoicenumber>11001770</invoicenumber> <description>Invoice paid</description> <matchstatus>available</matchstatus> <matchlevel>2</matchlevel> <relation>2</relation> <basevalueopen>-435.55</basevalueopen> <repvalueopen>-435.55</repvalueopen> </line> </lines></transaction>Source
Section titled “Source”View examples/journal-transactions/create-journal-transaction/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.