Skip to content

Create bank transaction

Creates a bank transaction for one bank statement, then deletes it again. This changes data in Twinfield.

Twinfield documentation: Bank transactions.

BankTransactionInput::create($dayBook, $dim1, $date) takes the bank book, its ledger account and the date; forBankBook() takes the code and ledger account from a BankBook. Then add a line per bank line:

  • receive($dim1, $amount, …): money comes in, e.g. a customer paying an invoice;
  • pay($dim1, $amount, …): money goes out, e.g. a supplier invoice or a cost.

You never write debit or credit yourself: receive() and pay() choose the side, and the input calculates the total line on the bank account and the closing balance from the opening balance in statement(). So the transaction always balances.

New transactions are provisional (destiny="temporary"): you can still change, post or delete them. Call final() to save them as final at once.

The example uses the first bank book with a ledger account and the first profit and loss account of the company, so it runs in any administration.

$twinfield = Example::twinfield();
$bank = $twinfield->bankTransactions();
$bankBook = Example::bankBook($twinfield);
$costs = Example::profitAndLossAccount($twinfield);
$transaction = $bank->create(
BankTransactionInput::forBankBook($bankBook, new DateTimeImmutable())
->statement(1, startValue: '100.00')
->description('Example statement')
->pay($costs, '12.50', description: 'Example bank costs'),
);
echo 'Created: ', $transaction->dayBook(), ' ', $transaction->number(),
' (', $transaction->header->status->name, ')', PHP_EOL;
echo 'Total: ', $transaction->total->debitCredit->value, ' ', $transaction->total->value, PHP_EOL;
echo 'Balance: ', $transaction->startValue, ' → ', $transaction->closeValue, PHP_EOL;
// Clean up: delete the provisional example transaction again.
$bank->delete($transaction->dayBook(), $transaction->number(), 'twinfield-php example');
echo 'Deleted: ', $transaction->dayBook(), ' ', $transaction->number(), PHP_EOL;
Terminal window
php examples/bank-transactions/create-bank-transaction/example.php
Created: ING 202600046 (Provisional)
Total: credit 12.50
Balance: 100.00 → 87.50
Deleted: ING 202600046

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: Create.

$twinfield->bankTransactions()->create(
BankTransactionInput::create('BNK', '1010', new DateTimeImmutable('2026-11-03'))
->statement(246, '1397.46')
->receive('1300', '121.00', customer: '1000', invoice: '2026-0043', description: 'Invoice 2026-0043'),
);

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

<transaction destiny="temporary">
<header>
<office>1000</office>
<code>BNK</code>
<date>20261103</date>
<statementnumber>246</statementnumber>
<startvalue>1397.46</startvalue>
<closevalue>1518.46</closevalue>
</header>
<lines>
<line type="total" id="1">
<dim1>1010</dim1>
<debitcredit>debit</debitcredit>
<value>121.00</value>
</line>
<line type="detail" id="2">
<dim1>1300</dim1>
<dim2>1000</dim2>
<debitcredit>credit</debitcredit>
<value>121.00</value>
<invoicenumber>2026-0043</invoicenumber>
<description>Invoice 2026-0043</description>
</line>
</lines>
</transaction>

Twinfield answers with this XML in ProcessXmlStringResult:

<transaction result="1" location="temporary">
<header>
<office name="Example Holding B.V." shortname="Holding">1000</office>
<code name="Bank" shortname="Bank">BNK</code>
<currency name="Euro" shortname="Euro">EUR</currency>
<date>20261103</date>
<statementnumber>246</statementnumber>
<startvalue>1397.46</startvalue>
<closevalue>1518.46</closevalue>
<origin>webservice</origin>
<user name="Example user" shortname="User">EXAMPLE</user>
<period>2026/11</period>
<number>202600046</number>
</header>
<lines>
<line type="total" id="1">
<dim1 name="Bank" shortname="" type="BAS" inuse="true" vatcode="" vatobligatory="false">1010</dim1>
<debitcredit>debit</debitcredit>
<value>121.00</value>
<rate>1</rate>
<basevalue>121.00</basevalue>
<matchstatus>notmatchable</matchstatus>
</line>
<line type="detail" id="2">
<dim1 name="Debiteuren" shortname="Debiteuren" type="BAS" inuse="true" vatcode="" vatobligatory="false">1300</dim1>
<dim2 name="Example customer" shortname="" type="DEB" inuse="true" vatcode="" vatobligatory="false">1000</dim2>
<debitcredit>credit</debitcredit>
<value>121.00</value>
<invoicenumber>2026-0043</invoicenumber>
<description>Invoice 2026-0043</description>
<rate>1</rate>
<basevalue>121.00</basevalue>
<matchlevel>2</matchlevel>
<openvalue>121.00</openvalue>
<openbasevalue>121.00</openbasevalue>
<matchstatus>available</matchstatus>
</line>
</lines>
</transaction>

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