# LinenBalance: Laundry Piece Movement Reconciliation (`usta/linenbalance-laundry-piece-reconciliation`) Actor

Reconcile recorded laundry piece movements against opening balances. Download account closings, movement lineage and unresolved rows. Missing required openings stay UNKNOWN; no inferred inventory.

- **URL**: https://apify.com/usta/linenbalance-laundry-piece-reconciliation.md
- **Developed by:** [US Tech Automations](https://apify.com/usta) (community)
- **Categories:** Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.50 / completed product packet

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## LinenBalance

LinenBalance is for a commercial laundry or linen service that already records integer piece counts (openings and movements) and needs a period close: per-account incoming, outgoing, net, and closing, with UNKNOWN when an opening is missing. It does not connect to a plant system, infer wash yield, attribute theft, raise invoices, or guess unmatched events.

The Actor produces a downloadable reconciliation packet from the records you supply.

### What you get

A ZIP of the original engine files (leaf names only):

- `report.json` — status, summary, tables, findings, provenance.
- `input.json` — the exact input used.
- `accounts.csv` — per account / SKU / unit: opening, in, out, net, closing, whether closing is known.
- `unresolved.csv` — movements that could not be matched (for example a reversal of an unknown id).
- `movement-lineage.csv` — every movement, UTC time, and whether it posted in the period.
- `opening-close.json`, `policy.json` — snapshot and applied policy.
- `manifest.json`, `hashes.json` — content hashes.
- `drilldown.html`, `styles.css` — portable offline viewer using the shared USTA shell and current stylesheet (family `domain-tools`).
- `README.txt` — package legend.

Adapter status is the engine status: `PASS` or `UNKNOWN`. Missing openings on a tracked account stay `UNKNOWN`. The adapter never upgrades that to `PASS`. Invalid input raises `ValueError` (it does not emit a FAIL ZIP).

### Limits (from the engine)

- Movement types: `dispatch`, `receipt`, `disposal`, `correction`, `adjustment`, `reversal`.
- Quantities are integers. Booleans, fractions, and non-finite numbers are rejected. Absolute quantity at most 10^12. At most 200,000 rows per openings or movements list. Identifier strings at most 4,096 characters. Nesting depth 16.
- Every timestamp must include an explicit UTC offset (or `Z`). Naive local times are rejected.
- Period, if present, is half-open `[start, end)`.
- `policy.tracked_accounts` names accounts whose absolute closing must be known for `PASS`. A missing opening is never treated as zero.
- Matching is exact and user-controlled. No wash-yield inference, unequal-count matching, theft attribution, invoicing, or system integration.
- Adapter input is a JSON object of at most 1 MiB. Unknown top-level fields are rejected.

This is not hardware certification, domain certification, a laundry-system integration, or a professional assurance of inventory.

### Complete input example

`example.json` matches `samples/valid.json`. Paste this object into the **payload** JSON field:

```json
{
  "movements": [
    {
      "destination": "PLANT",
      "movement_id": "D-0001",
      "quantity": 35,
      "sku": "BATH_TOWEL",
      "source": "CLIENT_A",
      "timestamp": "2026-01-05T08:00:00-05:00",
      "type": "dispatch",
      "unit": "pieces"
    },
    {
      "destination": "CLIENT_A",
      "movement_id": "R-0001",
      "quantity": 20,
      "sku": "BATH_TOWEL",
      "source": "PLANT",
      "timestamp": "2026-01-06T08:00:00-05:00",
      "type": "receipt",
      "unit": "pieces"
    }
  ],
  "openings": [
    {
      "account": "CLIENT_A",
      "quantity": 100,
      "sku": "BATH_TOWEL",
      "unit": "pieces"
    }
  ],
  "policy": {
    "period": {
      "end": "2026-02-01T00:00:00-05:00",
      "start": "2026-01-01T00:00:00-05:00"
    },
    "timezone": "America/New_York",
    "tracked_accounts": [
      "CLIENT_A"
    ]
  }
}
```

Under these rows, CLIENT\_A closing is 85 (100 + 20 − 35). `samples/unknown.json` has movements on CLIENT\_B with no opening: status stays `UNKNOWN`. `samples/invalid.json` (boolean quantity) is refused.

### Cloud hosting

When you run this Actor, the JSON you submit is sent to Apify’s cloud and stored under your Apify account. It is not a local-only run. You control retention in that account. There is no lasting service-level agreement in this package.

### Run and download

1. Review the supported input and try the included synthetic example. Replace **payload** with your authorized records. For API runs, send an object with a single payload field containing that input.
2. Run the Actor. Open **Status and coverage** to inspect the result.
3. For a completed result, open **Download completed ZIP** or the artifact link in the dataset. Save and extract the ZIP before Apify retention expires. Open the HTML report where provided; retain the JSON and CSV evidence.

### Price and unsuccessful runs

**$0.50 per completed packet**, with one packet per run and no start fee. A retry of the same run reuses the packet and the same billing identity. Starting a separate run is a separate request. Invalid input or an incomplete UNKNOWN result produces a diagnostic without a completed-packet charge. A completed conflict or shortage report can still require manual review; PASS does not mean every business problem was resolved.

The minimum run budget is $0.50. The example is a normal run and follows the same price; it is not a free preview promise. Apify handles account billing. These files are not permanent storage: download them promptly.

### Access and support

Your input and output are processed on Apify under the run owner's account. Use authorized data and opaque IDs; do not upload passwords or sensitive personal records. Treat artifact URLs as access-bearing links and share them only intentionally. The USTA report may fetch the Satoshi font; it does not upload your report. For a product issue, use this Actor's Issues tab with the run ID and a redacted example. Never post private input or access-bearing links in a public issue.

# Actor input Schema

## `payload` (type: `object`):

Linen movement journal: openings, movements and optional policy. Same object as example.json and samples/valid.json.

## Actor input object example

```json
{
  "payload": {
    "movements": [
      {
        "destination": "PLANT",
        "movement_id": "D-0001",
        "quantity": 35,
        "sku": "BATH_TOWEL",
        "source": "CLIENT_A",
        "timestamp": "2026-01-05T08:00:00-05:00",
        "type": "dispatch",
        "unit": "pieces"
      },
      {
        "destination": "CLIENT_A",
        "movement_id": "R-0001",
        "quantity": 20,
        "sku": "BATH_TOWEL",
        "source": "PLANT",
        "timestamp": "2026-01-06T08:00:00-05:00",
        "type": "receipt",
        "unit": "pieces"
      }
    ],
    "openings": [
      {
        "account": "CLIENT_A",
        "quantity": 100,
        "sku": "BATH_TOWEL",
        "unit": "pieces"
      }
    ],
    "policy": {
      "period": {
        "end": "2026-02-01T00:00:00-05:00",
        "start": "2026-01-01T00:00:00-05:00"
      },
      "timezone": "America/New_York",
      "tracked_accounts": [
        "CLIENT_A"
      ]
    }
  }
}
```

# Actor output Schema

## `packet` (type: `string`):

No description

## `report` (type: `string`):

No description

## `dataset` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "payload": {
        "movements": [
            {
                "destination": "PLANT",
                "movement_id": "D-0001",
                "quantity": 35,
                "sku": "BATH_TOWEL",
                "source": "CLIENT_A",
                "timestamp": "2026-01-05T08:00:00-05:00",
                "type": "dispatch",
                "unit": "pieces"
            },
            {
                "destination": "CLIENT_A",
                "movement_id": "R-0001",
                "quantity": 20,
                "sku": "BATH_TOWEL",
                "source": "PLANT",
                "timestamp": "2026-01-06T08:00:00-05:00",
                "type": "receipt",
                "unit": "pieces"
            }
        ],
        "openings": [
            {
                "account": "CLIENT_A",
                "quantity": 100,
                "sku": "BATH_TOWEL",
                "unit": "pieces"
            }
        ],
        "policy": {
            "period": {
                "end": "2026-02-01T00:00:00-05:00",
                "start": "2026-01-01T00:00:00-05:00"
            },
            "timezone": "America/New_York",
            "tracked_accounts": [
                "CLIENT_A"
            ]
        }
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("usta/linenbalance-laundry-piece-reconciliation").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "payload": {
        "movements": [
            {
                "destination": "PLANT",
                "movement_id": "D-0001",
                "quantity": 35,
                "sku": "BATH_TOWEL",
                "source": "CLIENT_A",
                "timestamp": "2026-01-05T08:00:00-05:00",
                "type": "dispatch",
                "unit": "pieces",
            },
            {
                "destination": "CLIENT_A",
                "movement_id": "R-0001",
                "quantity": 20,
                "sku": "BATH_TOWEL",
                "source": "PLANT",
                "timestamp": "2026-01-06T08:00:00-05:00",
                "type": "receipt",
                "unit": "pieces",
            },
        ],
        "openings": [{
                "account": "CLIENT_A",
                "quantity": 100,
                "sku": "BATH_TOWEL",
                "unit": "pieces",
            }],
        "policy": {
            "period": {
                "end": "2026-02-01T00:00:00-05:00",
                "start": "2026-01-01T00:00:00-05:00",
            },
            "timezone": "America/New_York",
            "tracked_accounts": ["CLIENT_A"],
        },
    } }

# Run the Actor and wait for it to finish
run = client.actor("usta/linenbalance-laundry-piece-reconciliation").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "payload": {
    "movements": [
      {
        "destination": "PLANT",
        "movement_id": "D-0001",
        "quantity": 35,
        "sku": "BATH_TOWEL",
        "source": "CLIENT_A",
        "timestamp": "2026-01-05T08:00:00-05:00",
        "type": "dispatch",
        "unit": "pieces"
      },
      {
        "destination": "CLIENT_A",
        "movement_id": "R-0001",
        "quantity": 20,
        "sku": "BATH_TOWEL",
        "source": "PLANT",
        "timestamp": "2026-01-06T08:00:00-05:00",
        "type": "receipt",
        "unit": "pieces"
      }
    ],
    "openings": [
      {
        "account": "CLIENT_A",
        "quantity": 100,
        "sku": "BATH_TOWEL",
        "unit": "pieces"
      }
    ],
    "policy": {
      "period": {
        "end": "2026-02-01T00:00:00-05:00",
        "start": "2026-01-01T00:00:00-05:00"
      },
      "timezone": "America/New_York",
      "tracked_accounts": [
        "CLIENT_A"
      ]
    }
  }
}' |
apify call usta/linenbalance-laundry-piece-reconciliation --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,usta/linenbalance-laundry-piece-reconciliation"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/sWWYjokMf75UW1RKq/builds/ZYhQDd0pqQ3aKyR2y/openapi.json
