expenses
The v2 purchase is the same as v1 (same fields, cost centers, and document types) plus currency (currency_code, exchange_rate) and tax_ids required per line. Its errors carry a code; see API v2: what changes.
Fields not described here (
observation, is_credit, credit_days, number_control, generation_code, stamp, cost centers, etc.) are those of Register a purchase in v1. Line types remain goods (goods) and services (service).Register a purchase
0.128.
netTotals + totalTax + charge_1 + charge_2 − totalRetein − totalRent: 937.50 + 97.50 + 15.63 + 7.81 − 7.50 − 10.00 = 1,040.94.
New or different fields from v1
totals.expenseTotalTax is the taxed base, totalTax the VAT, and charge_1 / charge_2 the special charges (in El Salvador, COTRANS and FOVIAL). If the line carries those fixed taxes in tax_ids, the amounts are recorded per tax. See totals in v1.
Withholding and income tax
totalRetein (VAT withheld) and totalRent (income tax withheld) subtract from the total payable. Example in USD with VAT 26.00, withholding 2.00, and income tax 5.00 on 200.00: expenseTotalToPayment = 200.00 + 26.00 − 2.00 − 5.00 = 219.00.
200 response
For a purchase in base currency:
currency_code is the base currency, exchange_rate is "1.00000000", and foreign_total is null.
Errors
They are validated before saving; no error creates the purchase.Get a purchase
totals and products are in base currency; the total in the document’s currency is in foreign_total.
404 with { "status": false, "message": "..." }.
Let FileXpress calculate the totals
As in sales, you can omit the total payable and send only the lines: FileXpress calculates the line amounts, VAT, fixed charges, and the total. When it activates: whentotals does not include expenseTotalToPayment.
What you send per line: sku, name, type (goods or services), quantity, price_before_taxes, discount or discount_percent, taxability (taxed, exempt, not_subject), and tax_ids. You do not need subtotal, expense_taxed, expense_exent, or expense_not_suject: they are filled in automatically.
What is calculated
- VAT: sum of each line’s taxed amount times the rate, rounded at the end.
- COTRANS (
C8) and FOVIAL (D1) ascharge_1andcharge_2(quantity × catalog value), with their row in the purchase’s taxes. They are the only fixed per-unit taxes a purchase can carry today: the purchase only has those two charge slots. totals.totalReteinandtotals.totalRent(VAT withholding and income tax) are sent by you: they are the buyer’s decisions. They are subtracted from the amount payable.
data.calculated_totals): netTotals 1234567.89, totalTax 160493.83, expenseTotalToPayment 1382716.04. Amounts are stored exactly: a purchase worth millions does not lose a single cent.
The rounding and foreign-currency rules are those of sales. Errors use the same code values (validation_error, tax_invalid).