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.
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
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
transactions | body | array | yes | [{"date":"2026-01-05","type":"receipt","item":"A","quantity":200,"unit_cost":12000,"ref":"PN01"}, {"type":"issue","item":"A","quantity":150}]. Or file / csv. | |
method | body|query | string | no | fifo | fifo, weighted_average, moving_average, specific. |
opening | body | array | no | Opening stock: [{"item":"A","quantity":100,"amount":1000000}]. | |
decimals | body|query | number | no | 0 | Currency decimals (0 VND, 2 USD). |
allow_negative | body|query | boolean | no | false | Value 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"}]}'const res = await fetch('https://apibox.io.vn/v1/inventory-costing', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"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"
}
]
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/inventory-costing",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"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"}]},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/inventory-costing');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"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 = curl_exec($ch);
print_r(json_decode($response, true));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
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.