# Monthly Reporting

<details>

<summary><strong>Generate P&amp;L JSON for every entity</strong> (read)</summary>

To archive profit and loss data for each entity in a workspace, resolve ledger ids and export JSON. The CLI does not emit PDF; save JSON and convert externally if you need PDF.

**The Script**

```bash
#!/bin/bash
# monthly-pl-reports.sh

WORKSPACE_ID="<workspace-id>"
START_DATE="2026-01-01"
END_DATE="2026-01-31"
OUTPUT_DIR="./reports/${START_DATE}-to-${END_DATE}"

mkdir -p "$OUTPUT_DIR"

kick workspaces list --include-entities --fields id,name,entities --output json | \
  jq -r --arg ws "$WORKSPACE_ID" '.[] | select(.id == $ws) | .entities[]? | "	" + .id + "	" + .name' | \
while IFS=$'\t' read -r entity_id entity_name; do
  ledger_id=$(kick --workspace "$WORKSPACE_ID" accounting ledgers get --entity-id "$entity_id" --output json | jq -r '.ledgers[0].id')
  safe_name=${entity_name// /-}

echo "Generating P&L for $entity_name (entity $entity_id)..."

kick --workspace "$WORKSPACE_ID" reports profit-loss \
    --entity "$entity_id" \
    --ledger-id "$ledger_id" \
    --start-date "$START_DATE" \
    --end-date "$END_DATE" \
    --cycle month \
    --output json \
    > "$OUTPUT_DIR/pl-${safe_name}-${START_DATE}.json"

echo "Saved $OUTPUT_DIR/pl-${safe_name}-${START_DATE}.json"
done

echo "All reports saved in $OUTPUT_DIR"
```

**How to Customize**

* Change `START_DATE` and `END_DATE` to the period you are closing
* Add `--comparisons previous_period` to include a comparison column in the report output
* Filter entities in the `jq` step if you only need active clients

**What It Outputs**

* One JSON file per entity in `./reports/<start>-to-<end>/`
* Filename format: `pl-Entity-Name-2026-01-01.json`

</details>

<details>

<summary><strong>Compare month-over-month with built-in comparisons</strong> (read)</summary>

To see current-period profit and loss beside the previous period for one entity, use the report comparison flags instead of running two separate exports.

**The Script**

```bash
#!/bin/bash
# mom-pl-comparison.sh

WORKSPACE_ID="<workspace-id>"
ENTITY_ID=123
START_DATE="2026-02-01"
END_DATE="2026-02-28"

ledger_id=$(kick --workspace "$WORKSPACE_ID" accounting ledgers get --entity-id "$ENTITY_ID" --output json | jq -r '.ledgers[0].id')

kick --workspace "$WORKSPACE_ID" reports profit-loss \
  --entity "$ENTITY_ID" \
  --ledger-id "$ledger_id" \
  --start-date "$START_DATE" \
  --end-date "$END_DATE" \
  --cycle month \
  --comparisons previous_period \
  --output json | jq .
```

**How to Customize**

* Change `ENTITY_ID` and the date range
* Add `--comparison-diffs amount` or `--comparison-diffs percent` to control how differences display
* Run for multiple entities by looping over ids from `kick workspaces list --include-entities`

**What It Outputs**

* Formatted JSON profit and loss with a previous-period comparison column
* Pipe through `jq` to extract the rows you need for a spreadsheet

</details>

<details>

<summary><strong>Archive trial balance before statements</strong> (read)</summary>

To snapshot trial balance rows before you prepare statements, export JSON for one entity.

**The Script**

```bash
#!/bin/bash
# trial-balance-export.sh

WORKSPACE_ID="<workspace-id>"
ENTITY_ID=123
START_DATE="2026-01-01"
END_DATE="2026-01-31"
OUTPUT_FILE="trial-balance-${ENTITY_ID}-${END_DATE}.json"

ledger_id=$(kick --workspace "$WORKSPACE_ID" accounting ledgers get --entity-id "$ENTITY_ID" --output json | jq -r '.ledgers[0].id')

kick --workspace "$WORKSPACE_ID" reports trial-balance \
  --entity "$ENTITY_ID" \
  --ledger-id "$ledger_id" \
  --start-date "$START_DATE" \
  --end-date "$END_DATE" \
  --cycle month \
  --output json \
  > "$OUTPUT_FILE"

echo "Saved $OUTPUT_FILE"
```

**How to Customize**

* Add `--fields` to limit columns when the full row set is too large
* Use `--limit` and `--cursor` to page through very large trial balances

**What It Outputs**

* A JSON file with trial balance rows for the entity and period

</details>
