# Dashboard authoring SOP

Use the [catalog](../catalog.json) to choose the enterprise and nearest
[FFCSA](recipes/ffcsa.md), [Layers](recipes/layers.md), or [Sales](recipes/sales.md)
example. Read this reporting procedure before implementation; it governs source
discovery, metric definitions, example inspection, template selection, validation,
reconciliation, private creation and verification. Operational enterprise
[SOPs](sops.md) explain business practices and vocabulary; they do not prove activity.

An enterprise dashboard means a private native Google Sheets workbook unless the
user explicitly requests another format. HTML, Markdown, screenshots and local
spreadsheets can support preparation or review but cannot replace the deliverable.

## Inspect and select the template

Resolve the enterprise's `recipeId` in the catalog. The recipe's `workbookUrl` is
the default template/reference, distinct from its operational `datasetIds`.
Inspect relevant tabs, layout, labels, formulas, number formats, charts, manual
inputs and generated areas before authoring. Record workbook/tab/range evidence,
inspection date and the template decision privately. Follow its structure,
formatting and presentation; do not reinterpret it as an unrelated dashboard.
Use native workbook copying where appropriate to preserve features, into a
private destination. Never modify the reference workbook without explicit
authorization. Review copied formulas, external links and sample values before
presenting results; flag and document corrections to suspected template errors.
If reference access is blocked, report the inspection gap and seek authorized
access; a provisional artifact cannot claim template compliance.

## Handle access gaps

When source access is blocked, create a clearly labelled **mockup** in a private
native Google Sheets workbook following the example's layout. Keep unavailable
actuals unknown or visibly unavailable. Remove or clearly mark copied sample
actuals so they cannot appear verified; never invent figures. Include coverage,
source-as-of/extraction dates, provenance and unresolved reconciliation differences.
If Sheets creation itself is unavailable, state that separate capability gap and
identify any local/HTML artifact as a fallback. Report incomplete acceptance
criteria; a fallback does not complete a dashboard request.

## Specify the result before coding

Record the enterprise, business questions, period, date basis, timezone, intended
audience, private destination, and exact generated tabs/ranges. For each metric
record a stable ID, definition, source fields/dataset IDs, units, calculation,
aggregation, missing-data behavior, and assumptions with effective dates.

Classify every input as recorded, calculated, estimated or manual. Keep actuals,
goals and scenarios distinct. Declare whether a result is operating contribution,
accounting income or a narrower measure; name missing cost categories.

Use a generated dashboard with these sections as applicable: operating context
(Givens), revenue, COGS, gross profit, expenses, net result, assumptions, and source
coverage. Separate manual input areas from generated areas. A count at period end
is not a sum; compute ratios from summed numerators and denominators rather than
averaging weekly percentages. Preserve zero and unknown as different values.

## Read, calculate and reconcile

1. Resolve and verify private releases using [the data-bank guide](data-bank.md).
   Pin manifests, source-as-of times and transformation versions. Refresh on demand
   with documented read-only collectors when the saved coverage is insufficient.
   For the historical Sales companion, follow the [bundle contract](sales-bundle.md)
   for authenticated download, trusted byte hash and source-owned validation.
   Bundle access and reference-workbook/Sheets creation access are separate checks.
2. Reuse source-owned calculations and reviewed corrections. Do not import an
   operational app bootstrap to query data: startup can migrate schemas or run jobs.
3. Calculate with code/SQL and exact money arithmetic. Keep orders, items,
   payments and refunds at their own grain before joining. Do not add Local Line
   and CSA Store copies of one order, or payments to revenue.
4. Compare source totals and known differences. Keep unmatched records, unknown
   money, missing labor and incomplete weeks visible. Do not replace missing data
   with zero or a current price as a historical cost.
5. Produce a preview and provenance receipt before changing a destination.

## Publish a Google Sheet

The module-independent reference is the Poultry repository's
`docs/google-sheets-dashboard-integration/README.md` at the revision recorded in
the catalog. It covers service-account setup, owned tabs, export jobs and failures.

- Reuse the deployment's existing Google service account and transport. Store
  credentials server-side and share only the intended destination with it.
- Complete all reads, calculations and validation before writing. Produce a
  rectangular values array, then apply formatting. Send numbers as numbers.
- A full replacement is allowed only on an exporter-owned tab. Never clear a
  shared Summary tab. Use a documented bounded range there.
- Escape untrusted text before a `USER_ENTERED` write so leading `=`, `+`, `-`,
  or `@` cannot become an unintended formula. Quote tab names in formulas.
- Preserve manual inputs. FFCSA currently reads designated manual rows back by
  label; document that dependency explicitly. New dashboards use separate Inputs
  and Assumptions areas instead of adding manual cells inside replaceable output.
- Run long exports as jobs in the owning application. Use one implementation for
  manual and scheduled execution, prevent overlap, and return a concise receipt:
  destination, owned tabs/ranges, covered dates, row count, input release IDs,
  metric-definition version and success/failure status.
- Do not add a schedule unless requested. Reports has no export endpoint or jobs.

## Acceptance criteria

Completion requires:

- A private native Google Sheets deliverable and final link to the created workbook.
- Private evidence that the linked example was inspected and followed, including
  relevant tabs/ranges and preserved layout, labels, formats and charts.
- Compliance with this reporting SOP, documented metric definitions and provenance.
- Defined generated tabs/ranges and preserved manual inputs.
- Verified formulas, number formats, formatting and reference-workbook protection
  (writes targeted only the new destination; no reference changes).
- Visible coverage gaps, source dates, unknown actuals and unresolved reconciliation.

Verify sharing is restricted to intended authorized users; do not enable public
or anyone-with-link access. Do not publish publicly, write operational records,
email results or add schedules without an explicit request.

## Verify the handoff

Use a disposable private workbook. Verify empty inputs, partial periods, midnight
and year boundaries, numeric formats, formulas, repeat runs, and preservation of
manual areas. Revoked sharing must produce a visible failed job, not a success
receipt. Document the command, exact source revision, inputs, owned ranges,
assumptions and known gaps alongside the resulting link.
