Postman collection
Orders Write

pixiMergeOrders

Merges a source order into a target order by moving all orderlines and bundle orderlines, recalculating tax rates and shipping costs.

Moves the content of the order SourceOrderNr into the order TargetOrderNr.

  1. Reads the order headers of both orders (order type, currency, shipping cost).
  2. Raises an error and stops if the two orders have different order types or different currencies. This also happens if neither order exists.
  3. Runs pipiCanMergeOrders, which checks the following conditions and returns its own result row (CanMerge, Reason):
    • both orders exist
    • both belong to the same customer
    • all orderlines have status ANG
    • both use the same payment type, which must not be credit card K
    • no orderline is on an active picklist
    • both have the same currency and order type
  4. If the merge is allowed, the following steps run in one transaction:
    • The shipping cost of the target order header is set to the higher shipping cost of the two orders.
    • All existing orderlines and bundle orderlines of the target order get this shipping cost, UpdateEmp and UpdateDate.
    • The orderlines of the source order are moved to the target order. They take over the billing and shipping address, Order_Id, OrderNrExternal and VoucherID of the target order's orderlines.
    • Their TaxRate is recalculated with fPixi_GetVATRate. The calculation uses the source order type and the country and VAT liability of the target shipping address.
    • With setting CalculateBundleVAT = 0, bundle components take the tax rate of their bundle orderline.
    • The bundle orderlines of the source order are moved the same way. With CalculateBundleVAT = 1, their tax rate is the net-weighted average of their components; otherwise it comes from the VAT function.
    • Bank matches (BankMatch) of the source order are reassigned to the target order.
    • The Discount of the source order header is set to 0.
  5. Returns ResultMessage:
    • 200 OK on success
    • the reason code from pipiCanMergeOrders (401–407) if the merge is not allowed
    • 500 Unexpected error if the transaction failed

UpdateEmp is set to Employee plus (API), or to API if no employee is given.

Notes

  • The call returns two result sets. SqlRowSet1 comes from pipiCanMergeOrders (CanMerge, Reason). SqlRowSet2 holds ResultMessage.
  • The source order header itself is not deleted. It remains without orderlines, with Discount = 0.
  • The shipping cost update on OrderHeader sets CONTEXT_INFO 0x66666 to bypass the update trigger.
  • Values taken from the target orderlines (addresses, Order_Id, OrderNrExternal, VoucherID) are read from an arbitrary orderline of the target order. If the target order has no orderlines, these values become NULL on the moved lines.
  • Source orderlines whose ItemRef has no matching row in items are not moved.
  • Bundle orderlines without component lines are not moved either.
  • With CalculateBundleVAT = 1, a net sum of 0 over the components of a bundle causes a division error. This rolls back the transaction and returns 500 Unexpected error.
  • Error details are not returned in that case; any failure in the transaction only yields 500 Unexpected error.
  • Reads use NOLOCK.
  • fPixi_GetDefaultCountryCode, used inside fPixi_GetVATRate, is not attached, so the default-country logic cannot be fully described here.

Tables used

OrderHeader · Write Orderlines · Write BundleOrderlines · Write BankMatch · Write Addresses · Read items · Read Settings · Read VATs · Read Countries · Read PLitem · Read plheader · Read
SQL object:
dbo.pipiMergeOrders
Updated at 2026-10-30