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.

Bill creation in Credith is a complex transactional operation that touches six tables in a single database transaction. The server validates the cashier’s checkout machine, resolves the active CAI and CAI Range, formats the SAR-compliant bill number, deducts inventory for every line item, calculates ISV-15 tax, and then creates either a fully-paid cash payment plan or a multi-installment credit plan — all atomically. A failure at any step rolls back the entire transaction, so partial bills are never persisted.

POST /api/bills

Creates a new invoice. No authentication is required on this endpoint; the userId in the request body is used to resolve the cashier’s checkout machine and store assignment.

Validations performed (in order)

  1. Cashier checkuserId must correspond to an existing user who has an active checkout machine assigned.
  2. Store check — The user’s store must match the storeId in the request body.
  3. CAI check — The store must have an active CAI with an active, non-exhausted range. The range lock is held (SELECT FOR UPDATE) during the transaction to prevent race conditions.
  4. Inventory check — Every product in details must exist in the store’s inventory with sufficient inStock quantity.
The bill_number for each invoice is derived from the active CAI Range as minRange + currentNumber. After the bill is persisted, currentNumber is incremented by 1 on the range record. The fully formatted billNumberFinal follows the pattern {storeNumber:3}-{machineNumber:3}-{documentType}-{billNumber:8}, e.g. 001-001-01-00000001.
A client can only have one active (status PENDING or OVERDUE) installment payment plan at a time. Attempting to create an INSTALLMENT bill for a client who already has an open plan returns HTTP 400.

Request body

userId
string (UUID)
required
UUID of the cashier (user) processing the sale. Must have an assigned checkout machine and a valid store association.
storeId
string (UUID)
required
UUID of the store where the sale takes place. Must match the store on record for the given userId.
paymentType
string
required
Payment method for this invoice. Accepted values: "CASH" or "INSTALLMENT". Determines which payment-plan creation branch runs.
limitDate
string (date)
Optional due date printed on the invoice, e.g. "2025-12-31".
discountPercentage
integer
default:"0"
Overall invoice-level discount percentage (stored for display; the monetary amount must be supplied in discountAmount).
discountAmount
number
default:"0"
Monetary discount applied to the invoice subtotal before ISV calculation.
exonerated
number
default:"0"
Exonerated amount (ISV-exempt portion) for fiscal reporting.
exempt
number
default:"0"
Exempt amount for fiscal reporting.
details
array
required
One or more line items. The server re-validates each item’s total as quantity × sellPrice × (1 - discountPercentage / 100).
customer
object
required
Customer information printed on the invoice.
paymentData
object
required
Payment plan details. Required fields vary by paymentType.

Example — CASH bill

curl -X POST https://your-domain.com/api/bills \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "c98765e5-9ae8-4597-b95e-9889028f2222",
    "storeId": "d55555e5-9ae8-4597-b95e-9889028f3333",
    "paymentType": "CASH",
    "limitDate": "2025-12-31",
    "discountPercentage": 0,
    "discountAmount": 0,
    "exonerated": 0,
    "exempt": 0,
    "details": [
      {
        "productId": "e11111e5-9ae8-4597-b95e-9889028f4444",
        "productName": "Laptop HP 15",
        "quantity": 1,
        "sellPrice": 850.00,
        "discountPercentage": 0,
        "discountAmount": 0,
        "total": 850.00
      }
    ],
    "customer": {
      "customerName": "Maria Lopez",
      "customerPhone": "9888-7766",
      "customerAddress": "Tegucigalpa, FM"
    },
    "paymentData": {
      "payment": 977.50,
      "interestRate": 0
    }
  }'

Example — INSTALLMENT bill

{
  "userId": "c98765e5-9ae8-4597-b95e-9889028f2222",
  "storeId": "d55555e5-9ae8-4597-b95e-9889028f3333",
  "paymentType": "INSTALLMENT",
  "limitDate": "2025-12-31",
  "discountPercentage": 0,
  "discountAmount": 0,
  "exonerated": 0,
  "exempt": 0,
  "details": [
    {
      "productId": "e11111e5-9ae8-4597-b95e-9889028f4444",
      "productName": "Televisor Samsung 55\"",
      "quantity": 1,
      "sellPrice": 1200.00,
      "discountPercentage": 0,
      "discountAmount": 0,
      "total": 1200.00
    }
  ],
  "customer": {
    "customerName": "Juan Pérez",
    "customerPhone": "9999-8888",
    "customerAddress": "San Pedro Sula, Cortés",
    "clientId": "f22222e5-9ae8-4597-b95e-9889028f5555"
  },
  "paymentData": {
    "payment": 380.00,
    "startingDate": "2025-02-01",
    "monthsToPay": 6,
    "paymentDay": 15,
    "interestRate": 0
  }
}

Response fields

billId
string (UUID)
Auto-generated primary key for the created bill.
billNumber
integer
Raw sequential number within the active CAI Range (minRange + currentNumber at time of creation).
billNumberFinal
string
Fully formatted SAR-compliant invoice number: {storeNumber:3}-{machineNumber:3}-{documentType}-{billNumber:8}.
paymentType
string
"CASH" or "INSTALLMENT".
subtotal
number
Sum of all line-item totals before any invoice-level discount.
isv15Amount
number
ISV-15 tax amount (15% of the discounted subtotal).
discountAmount
number
Invoice-level monetary discount applied before tax.
total
number
Final invoice total: (subtotal - discountAmount) + isv15Amount.
companyName
string
Snapshot of the company name at time of invoice creation.
companyRtn
string
Snapshot of the company RTN (tax ID) at time of creation.
cashierName
string
Full name of the user who processed the sale.
caiRangeId
string (UUID)
UUID of the CAI Range used to generate this invoice’s bill number.
plan
object
The payment plan created alongside this bill. Shape varies by paymentType — see Payment Plans for full field definitions.

Error responses

StatusCause
400Invalid paymentType, mismatched line-item total, or client already has an active installment plan
404User, checkout machine, store, active CAI, CAI Range, company, or product inventory not found
406CAI Range exhausted (nextBillNumber > maxRange), store mismatch between user and request, or insufficient stock
500Unexpected server error

Build docs developers (and LLMs) love