Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/RoyGeova07/Credith/llms.txt

Use this file to discover all available pages before exploring further.

Credith exposes three dedicated report endpoints that give business owners a detailed view of operational performance across their retail network. The Products report shows per-product sales volume, current inventory, and gross/net gain broken down by store. The Stores report provides a monthly snapshot of a single branch — including revenue and staff roster. The Companies report aggregates monthly gross and net gain across all active stores under a company. All three endpoints run optimised raw SQL queries against the cd PostgreSQL schema and are accessible only to users with the OWNER role (and ADMIN for the stores report).
In the Credith React frontend (ManagerReportsPage.jsx), report controls are only rendered for users whose session cookie contains role: "OWNER". Non-owner roles are redirected away from the reports section entirely. Ensure the authenticated user was assigned the Owner role via POST /api/roles/associate-user before using these endpoints.

Report Types

GET /api/reports/products

Returns product-level performance for a given company, optionally scoped to a specific store and/or calendar month. Results are paginated and sorted alphabetically by product name.Query Parameters
ParameterRequiredDescription
companyIdUUID of the company to scope the report to
storeIdUUID of a specific store; filters both sales and inventory data
monthMonth to filter. Accepts YYYY-MM format (e.g. 2025-06) or a numeric 1–12 alongside year
yearRequired when month is passed as a number (e.g. month=6&year=2025)
limitMax products to return (default 10, max 100)
offsetPagination offset (default 0)
When neither month nor year is provided, the report returns historical data (all time). The period.type field in the response will be "historical".Example Request
curl "http://localhost:3000/api/reports/products?\
companyId=a11111e5-9ae8-4597-b95e-9889028f0001\
&month=2025-06\
&limit=10\
&offset=0" \
  -b cookies.txt
Example Response
{
  "period": {
    "type": "month",
    "year": 2025,
    "month": 6,
    "startDate": "2025-06-01",
    "endDate": "2025-07-01"
  },
  "filters": {
    "companyId": "a11111e5-9ae8-4597-b95e-9889028f0001",
    "storeId": null
  },
  "pagination": {
    "limit": 10,
    "offset": 0
  },
  "products": [
    {
      "productId": "e11111e5-9ae8-4597-b95e-9889028f4444",
      "name": "Refrigeradora 14 pies",
      "quantitySold": 3,
      "inStock": 7,
      "grossGain": 4500.00,
      "netGain": 3870.00,
      "stores": [
        {
          "storeId": "b22222e5-9ae8-4597-b95e-9889028f0002",
          "address": 101,
          "quantitySold": 2,
          "inStock": 5,
          "grossGain": 3000.00,
          "netGain": 2580.00
        },
        {
          "storeId": "b33333e5-9ae8-4597-b95e-9889028f0003",
          "address": 202,
          "quantitySold": 1,
          "inStock": 2,
          "grossGain": 1500.00,
          "netGain": 1290.00
        }
      ]
    }
  ]
}
Each product entry contains:
  • quantitySold — total units sold during the period across all stores (or the filtered store)
  • inStock — current inventory units available
  • grossGain(sellPrice − buyPrice) × quantity summed over all matching bill details
  • netGain(lineTotal − buyPrice × quantity) summed, accounting for line-item discounts
  • stores — per-store breakdown of the same metrics

Exporting Reports

The ManagerReportsPage in the React frontend provides a Exportar CSV button for each report section. The export is entirely client-side — the page calls downloadCsv() which converts the in-memory report JSON into CSV rows and triggers a browser download without any additional API call.
ReportCSV filename pattern
Companycompany-report-{name}.csv
Storestore-report-{storeId}.csv
Productsproduct-report.csv

Dashboard Revenue Charts

The DashboardHomePage uses the GET /api/reports/stores/range endpoint to power a Recharts AreaChart that visualises the last 6 months of revenue for the current store. The frontend computes the startDate as 6 months before today and endDate as today, passes the authenticated user’s storeId from the session cookie, and maps the returned daily { date, grossGain, netGain } array directly into the chart data prop. This gives store admins an at-a-glance revenue trend without navigating to the full reports page.

Role Requirements

EndpointRequired role
GET /api/reports/productsOWNER
GET /api/reports/storesOWNER or ADMIN
GET /api/reports/stores/rangeOWNER or ADMIN
GET /api/reports/companiesOWNER
All report endpoints are protected by both authMiddleware (requires a valid JWT cookie) and roleMiddleware (checks req.user.role against the allowed roles). A request from an ADMIN user to GET /api/reports/companies will be rejected with 403.

Build docs developers (and LLMs) love