Invoices on a contract and FX recalculation – system description

Rules and write path of invoice linking, and the source order, side effects and limits of contract-based exchange rate recalculation.

Invoice linking writes the invoice's contract field through the invoice's owning model; the exchange rate recalculation sets the contract's foreign-currency invoices to the contract rate.

Data model

Table names carry the installation's own prefix in the database.

TableRole
invoicecontract_id, rate, forint values, outstanding balance
transaction_settlementexchange differences of settlements
transactionrelated vouchers

Invoice linking

  1. invoicesearch, invoicelink, invoices (list + contractInScope).
  2. The invoice must belong to the contract's client (error_invoice_scope); an invoice linked to another contract cannot be moved (error_invoice_other_contract).
  3. Writing goes through finance/invoice::setInvoiceContract.

Exchange rate recalculation (fxrecalc)

  1. apply=0 preview, apply=1 apply.
  2. Source: the contract's, otherwise the client's fx_income_source setting, finally MNB; rate day and rate under the contract come from the exchange rate library.
  3. Invoices in a closed period (periodLockedUntil) are skipped.
  4. On apply: rebookRate(), settlement exchange differences (refreshSettlementFx), outstanding balance recalculated, interest document refreshed (ensureDoc); each row flags a ledger gross difference above HUF 1.
  5. Error codes: error_fx_no_contract, no_fx_source.

Permissions

  • Linking: edit + contractInScope; recalculation: fxrecalc + contractInScope (the button appears only with the right).
  • Models involved: finance/invoice, finance/transaction, finance/entry, finance/interest; library: invoice service.
Related topics: contract invoice exchange rate