Inventory costing (FIFO, average) API

Cost of goods issued and closing stock by FIFO, periodic weighted average, moving average or specific lot, exact decimals and a per-transaction ledger.

POSThttps://apibox.io.vn/v1/inventory-costing

Send the receipts and issues of one period as transactions (JSON, CSV or XLSX): date, type (receipt / issue, also nhap / xuat), item (SKU), quantity, and unit_cost or amount for receipts, plus opening stock per item. Choose method: fifo (nhập trước xuất trước: issues consume the oldest layers), weighted_average (bình quân gia quyền cuối kỳ: one unit cost for the period from opening + all receipts), moving_average (bình quân sau mỗi lần nhập) or specific (thực tế đích danh, by lot).

All arithmetic uses integers (quantities to 6 decimals, amounts in minor units with decimals 0 for VND or 2 for USD), so there is no floating-point drift: each issue value is rounded once and the remainder stays in stock, and issuing the last unit takes the whole remaining value. The answer has a ledger per item in the style of the S10-DN stock card (quantity, unit cost, amount, running balance, the FIFO layers used), totals of receipts, issues and closing stock, the remaining FIFO layers and, for the periodic average, the rounding difference. Issues beyond the stock are refused unless allow_negative=true.

Parameters

NameInTypeRequiredDefault
transactionsbodyarrayyes[{"date":"2026-01-05","type":"receipt","item":"A","quantity":200,"unit_cost":12000,"ref":"PN01"}, {"type":"issue","item":"A","quantity":150}]. Or file / csv.
methodbody|querystringnofifofifo, weighted_average, moving_average, specific.
openingbodyarraynoOpening stock: [{"item":"A","quantity":100,"amount":1000000}].
decimalsbody|querynumberno0Currency decimals (0 VND, 2 USD).
allow_negativebody|querybooleannofalseValue issues beyond stock at the last receipt cost.

Example

curl -X POST "https://apibox.io.vn/v1/inventory-costing" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"method":"fifo","opening":[{"item":"A","quantity":100,"amount":1000000}],"transactions":[{"date":"2026-01-05","type":"receipt","item":"A","quantity":200,"unit_cost":12000,"ref":"PN01"},{"date":"2026-01-10","type":"issue","item":"A","quantity":150,"ref":"PX01"}]}'

Response

{
  "method": "fifo",
  "decimals": 0,
  "items": 1,
  "transactions": 2,
  "totals": {
    "opening": 1000000,
    "receipts": 2400000,
    "issues_cost": 1600000,
    "closing": 1800000
  },
  "results": [
    {
      "item": "A",
      "opening": {
        "quantity": 100,
        "amount": 1000000
      },
      "receipts": {
        "quantity": 200,
        "amount": 2400000
      },
      "issues": {
        "quantity": 150,
        "amount": 1600000
      },
      "closing": {
        "quantity": 150,
        "amount": 1800000,
        "unit_cost": 12000
      },
      "closing_layers": [
        {
          "from": "2026-01-05",
          "quantity": 150,
          "amount": 1800000,
          "unit_cost": 12000
        }
      ],
      "ledger": [
        {
          "date": "2026-01-05",
          "ref": "PN01",
          "type": "receipt",
          "quantity": 200,
          "unit_cost": 12000,
          "amount": 2400000,
          "balance_quantity": 300,
          "balance_amount": 3400000
        },
        {
          "date": "2026-01-10",
          "ref": "PX01",
          "type": "issue",
          "quantity": 150,
          "unit_cost": 10666.6667,
          "amount": 1600000,
          "balance_quantity": 150,
          "balance_amount": 1800000,
          "layers": [
            {
              "from": "opening",
              "quantity": 100,
              "amount": 1000000
            },
            {
              "from": "2026-01-05",
              "quantity": 50,
              "amount": 600000
            }
          ]
        }
      ]
    }
  ],
  "warnings": [],
  "reviewed": "2026-11-11"
}

Use cases

  • Compute cost of goods sold for a POS or e-commerce shop
  • Value closing inventory for monthly reports
  • Compare FIFO and average cost before choosing a policy
  • Check stock cards exported from a warehouse app

FAQ

Why not floats?

Repeated averages in floating point drift by fractions of a đồng. The API keeps quantities and money as integers and rounds each issue once, so receipts − issues always equals the closing value.

Is LIFO supported?

No. LIFO is not allowed under Vietnamese accounting standards (VAS 02, TT 99/2025); FIFO, weighted average and specific identification are.

How are same-day transactions ordered?

In the order you send them. For the periodic average the order does not matter: every issue of the period uses the same unit cost.

Related APIs

Start with 1,000 free requests every month. Get free API key →