Skip to content

Update bank transaction

Creates a provisional bank transaction, changes a line and adds one, then deletes it again. This changes data in Twinfield.

Twinfield documentation: Bank transactions.

Start from $transaction->edit(): it returns an input with all values of the transaction, including the number, so update() changes this transaction instead of creating a new one. Then change what you need:

  • mapLines() changes the detail lines one by one, e.g. a description;
  • receive(), pay() and line() add lines; withLines() replaces them all;
  • the total line and the closing balance are calculated again.

update() reads the transaction first and throws a TransactionNotFoundException when it does not exist. Only provisional transactions can be changed.

$twinfield = Example::twinfield();
$bank = $twinfield->bankTransactions();
$costs = Example::profitAndLossAccount($twinfield);
$created = $bank->create(
BankTransactionInput::forBankBook(Example::bankBook($twinfield), new DateTimeImmutable())
->pay($costs, '12.50', description: 'Bank costs'),
);
echo 'Created: ', $created->number(), ' ', $created->details[0]->description, ' ', $created->balance(), PHP_EOL;
// Start from edit(), so all current values are kept; change the line and add one.
$updated = $bank->update(
$created->edit()
->mapLines(static fn (DetailLineInput $line): DetailLineInput => $line->description('Bank costs October'))
->pay($costs, '2.50', description: 'Bank costs November'),
);
echo 'Updated: ', $updated->number(), ' ', count($updated->details), ' lines, ', $updated->balance(), PHP_EOL;
foreach ($updated->details as $line) {
echo ' ', $line->description, ': ', $line->value, PHP_EOL;
}
// Clean up: delete the provisional example transaction again.
$bank->delete($updated->dayBook(), $updated->number(), 'twinfield-php example');
Terminal window
php examples/bank-transactions/update-bank-transaction/example.php
Created: 202600047 Bank costs -12.50
Updated: 202600047 2 lines, -15.00
Bank costs October: 12.50
Bank costs November: 2.50

What 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: Bank transactions: Update.

$bank = $twinfield->bankTransactions();
$transaction = $bank->get('BNK', 202600045);
$bank->update($transaction->edit()->description('Statement 245 (checked)'));

The SDK sends this XML as xmlRequest of ProcessXmlString to processxml.asmx:

<transaction destiny="temporary">
<header>
<office>1000</office>
<code>BNK</code>
<number>202600045</number>
<period>2026/11</period>
<currency>EUR</currency>
<date>20261103</date>
<statementnumber>245</statementnumber>
<startvalue>974.01</startvalue>
<closevalue>1397.46</closevalue>
<freetext1>Statement 245</freetext1>
</header>
<lines>
<line type="total" id="1">
<dim1>1010</dim1>
<debitcredit>debit</debitcredit>
<value>423.45</value>
<description>Statement 245 (checked)</description>
</line>
<line type="detail" id="2">
<dim1>1300</dim1>
<dim2>1000</dim2>
<debitcredit>credit</debitcredit>
<value>435.55</value>
<rate>1</rate>
<reprate>1.500000000</reprate>
<duedate>20261108</duedate>
<invoicenumber>2026-0042</invoicenumber>
<description>Invoice 2026-0042</description>
</line>
<line type="detail" id="3">
<dim1>4500</dim1>
<dim2>KPL01</dim2>
<debitcredit>debit</debitcredit>
<value>10.00</value>
<rate>1</rate>
<reprate>1.500000000</reprate>
<description>Bank costs</description>
<vatcode>IH</vatcode>
<vatvalue>2.10</vatvalue>
<comment>Monthly fee</comment>
</line>
<line type="vat" id="4">
<dim1>1520</dim1>
<debitcredit>debit</debitcredit>
<value>2.10</value>
<vatturnover>10.00</vatturnover>
<vatcode>IH</vatcode>
<baseline>3</baseline>
</line>
</lines>
</transaction>

update() reads the transaction first, to check that it exists, and then saves the whole transaction again. Twinfield answers with the saved transaction, with its number and the names of the codes, in the same format as Read bank transaction.

View examples/bank-transactions/update-bank-transaction/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.