# Inventory fifo period close

`inventory-fifo-period-close` · version 1.0.0 · Financial calculations · free, no key needed

Close a periodic FIFO inventory period with exact valuation and a balanced caller-mapped closing entry.

**Use when you need to: close periodic FIFO inventory · prepare FIFO closing entry · post periodic inventory adjustment.**

## Decide before calling

Read the [versioned contract](/v1/tools/inventory-fifo-period-close/versions/1.0.0) and the supported scope below. Reuse `inventory-fifo-period-close@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `inventory-fifo-period-close@1.0.0` for close periodic FIFO inventory. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- close periodic FIFO inventory
- prepare FIFO closing entry
- post periodic inventory adjustment
- balance FIFO inventory close
- period-end FIFO journal
- inventory close exact arithmetic

## Not supported

- perpetual FIFO transaction processing
- tax or legal advice

## Behavior

- Periodic FIFO assigns the earliest available units to cost of goods sold and retains the latest units in ending inventory; it does not model intra-period sales.
- Layers sort by acquired_on ascending, then beginning before purchase, then zero-based input_index, then layer_id; input_index makes equal-date ties explicit and deterministic.
- Quantities and unit costs are canonical nonnegative decimal strings. All products and sums use integer/rational arithmetic; binary floating point is never used.
- output_scale is explicit (0 through 12). Valuation totals and layer extensions are rounded once at final presentation, never per unit or cumulatively. The journal uses a documented balancing-residual policy: round goods available, beginning inventory, and ending inventory once; post COGS as rounded goods available minus rounded ending inventory and Purchases as rounded goods available minus rounded beginning inventory. Thus actual lines balance even when independently rounded components would not. Supported modes are half-up, half-even, half-down, up, down, ceiling and floor.
- Inputs are immutable. Output contains reference_version IAS-2-2024-25-27+periodic-FIFO-v1.
- Disclaimer: arithmetic calculation only; not financial, tax, legal, or investment advice.

## Input

- `beginning_layers` (array of object, required): max items 500
- `purchases` (array of object, required): max items 500
- `physical_ending_quantity` (string, required): max length 32; pattern `^(0|[1-9][0-9]{0,17})(\.[0-9]{1,12})?$`
- `output_scale` (integer, required): min 0; max 12
- `rounding_mode` (one of "half-up", "half-even", "half-down", "up", "down", "ceiling", "floor", required)
- `accounts` (object, required)

## Output

- `reference_version` (constant "IAS-2-2024-25-27+periodic-FIFO-v1", required)
- `valuation` (object, required)
- `postings` (array of object, required): min items 4; max items 4
- `debits` (string, required)
- `credits` (string, required)

## Limits

- max input bytes: 131072
- max layers per source: 500
- max layers: 1000
- max string bytes: 64
- max output bytes: 8192

## Example

Request input:

```json
{
  "beginning_layers": [
    {
      "layer_id": "B1",
      "acquired_on": "2026-01-01",
      "quantity": "10",
      "unit_cost": "2.00"
    }
  ],
  "purchases": [
    {
      "layer_id": "P1",
      "acquired_on": "2026-01-10",
      "quantity": "5",
      "unit_cost": "3.00"
    }
  ],
  "physical_ending_quantity": "6",
  "output_scale": 2,
  "rounding_mode": "half-up",
  "accounts": {
    "inventory": "Inventory",
    "cogs": "COGS",
    "purchases": "Purchases"
  }
}
```

Response:

```json
{
  "result": {
    "reference_version": "IAS-2-2024-25-27+periodic-FIFO-v1",
    "valuation": {
      "reference_version": "IAS-2-2024-25-27+periodic-FIFO-v1",
      "available_quantity": "15",
      "ending_quantity": "6",
      "sold_quantity": "9",
      "goods_available_cost": "35.00",
      "ending_inventory": "17.00",
      "cogs": "18.00",
      "ending_layers": [
        {
          "layer_id": "B1",
          "source": "beginning",
          "input_index": 0,
          "acquired_on": "2026-01-01",
          "quantity": "1",
          "unit_cost": "2",
          "extended_cost": "2.00"
        },
        {
          "layer_id": "P1",
          "source": "purchase",
          "input_index": 0,
          "acquired_on": "2026-01-10",
          "quantity": "5",
          "unit_cost": "3",
          "extended_cost": "15.00"
        }
      ]
    },
    "postings": [
      {
        "line": 1,
        "account": "Inventory",
        "debit": "17.00",
        "credit": "0.00"
      },
      {
        "line": 2,
        "account": "COGS",
        "debit": "18.00",
        "credit": "0.00"
      },
      {
        "line": 3,
        "account": "Purchases",
        "debit": "0.00",
        "credit": "15.00"
      },
      {
        "line": 4,
        "account": "Inventory",
        "debit": "0.00",
        "credit": "20.00"
      }
    ],
    "debits": "35.00",
    "credits": "35.00"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "inventory-fifo-period-close",
  "version": "1.0.0",
  "input": {
    "beginning_layers": [
      {
        "layer_id": "B1",
        "acquired_on": "2026-01-01",
        "quantity": "10",
        "unit_cost": "2.00"
      }
    ],
    "purchases": [
      {
        "layer_id": "P1",
        "acquired_on": "2026-01-10",
        "quantity": "5",
        "unit_cost": "3.00"
      }
    ],
    "physical_ending_quantity": "6",
    "output_scale": 2,
    "rounding_mode": "half-up",
    "accounts": {
      "inventory": "Inventory",
      "cogs": "COGS",
      "purchases": "Purchases"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/inventory-fifo-period-close/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"beginning_layers":[{"layer_id":"B1","acquired_on":"2026-01-01","quantity":"10","unit_cost":"2.00"}],"purchases":[{"layer_id":"P1","acquired_on":"2026-01-10","quantity":"5","unit_cost":"3.00"}],"physical_ending_quantity":"6","output_scale":2,"rounding_mode":"half-up","accounts":{"inventory":"Inventory","cogs":"COGS","purchases":"Purchases"}}'
```

The machine-readable contract is at [/v1/tools/inventory-fifo-period-close/versions/1.0.0](/v1/tools/inventory-fifo-period-close/versions/1.0.0).

### CLI

```sh
node cli.mjs run inventory-fifo-period-close 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Inventory fifo period reconcile](/tools/inventory-fifo-period-reconcile): Reconcile reported ending inventory and COGS against an exact periodic FIFO recomputation.
- [Inventory fifo periodic value](/tools/inventory-fifo-periodic-value): Value ending inventory and cost of goods sold under periodic FIFO with exact, reproducible layer retention.
- [Bond cashflow schedule](/tools/bond-cashflow-schedule): Coupon dates, coupons remaining, accrued days and accrued interest for a regular fixed-coupon bond (Excel COUP* rules).
- [Cashflow irr](/tools/cashflow-irr): IRR of equally spaced cash flows with every root reported, the chosen root named and no-solution cases signalled.
- [Cashflow payback period](/tools/cashflow-payback-period): Payback period of periodic cash flows with linear interpolation, optional discounting and the cumulative path.
- [Daycount year fraction](/tools/daycount-year-fraction): Year fraction between two ISO dates under ISDA 30/360, 30E/360, ACT/360, ACT/365F, ACT/ACT ISDA or ICMA, and NL/365.
