On this page
TermsThe formula, before and afterData‑model notesSource referencesWorked reference numbers (sandbox)Glossary & data model
Terms
Analytics bar — the row of summary tiles above the invoices table, shown by clicking Show Analytics. Each tile is a money total plus a small percentage. Rendered by InvoiceInfo (web) / InvoicesInfo (mobile).
Discount tile — the tile this change fixes. Money amount = sum of discounts; percentage = discount as a share of the pre‑discount price.
Subtotal — the list price of all procedures on an invoice, before any discount or tax.
Discount — the money amount taken off the subtotal.
Tax — VAT added to the invoice. Often zero for VAT‑Exempt invoices, which are common in the sandbox data.
Total — the net amount after discount and tax: subtotal − discount + tax. Because the discount is already subtracted, Total is not a valid base for a discount percentage on its own.
Pre‑discount base — total + discount. Adding the discount back to the net total reconstructs the tax‑inclusive price before the discount. This is the new denominator for the discount tile.
discountPercent (stored) — a per‑invoice field storing discount ÷ subtotal (pre‑tax). Distinct from the analytics tile's figure; the two match only when tax = 0.
Balance invoice — an invoice flagged balanceInvoice. The analytics total excludes these (filter(p => !p.balanceInvoice)), while discount sums across all invoices.
invoicesInfo — the GraphQL query that aggregates invoice money fields for the analytics bar.
The formula, before and after
Before: discountPct = discount / total × 100 (inflated)
After: discountPct = discount / (total + discount) × 100 (correct)
because total = subtotal − discount + tax
so total + discount = subtotal + tax
Data‑model notes
Invoice (Prisma) — packages/prisma/schema.prisma:2620
| Field | Type | Meaning |
|---|---|---|
subtotal | Float | list price of procedures, pre‑discount |
discount | Float | money discounted |
discountPercent | Float | stored discount ÷ subtotal |
tax / taxPercent | Float | VAT amount / rate |
total | Float | subtotal − discount + tax (net of discount) |
paid | Decimal | amount paid |
pendingPayment | Float | amount awaiting confirmation |
insurance | Float | insurer‑covered portion |
diagnosticFee | Float | diagnostic fee component |
released | Float | amount released to clinic revenue |
balanceInvoice | Bool | whether this is a balance invoice |
InvoiceGroupInfo (GraphQL) — packages/server/src/types.graphql:4059
Returned by invoicesInfo: balanceInvoice, paid, tax, discount, diagnosticFee, pendingPayment, total, balance, released, insurance.
Source references
| What | Location |
|---|---|
| Web discount tile (changed) | packages/clinic-web/src/components/dashboard/finances/invoices/InvoiceInfo.js:118 |
| Mobile discount tile (changed) | packages/clinic-mobile/src/components/dashboard/finances/invoices/InvoicesInfo.js:99 |
Web aggregation of total/discount | InvoiceInfo.js:16, InvoiceInfo.js:22 |
| Total formula | packages/server/src/resolvers/mutations/actions/invoices/invoiceUtils.js:205 |
| Per‑line invariant | packages/server/src/resolvers/mutations/actions/invoices/invoiceUtils.js:118 |
Stored discountPercent | packages/server/src/resolvers/mutations/actions/invoices/invoiceUtils.js:145 |
| Values written to DB | packages/server/src/resolvers/mutations/actions/invoices/createNewInvoice.js:232 |
invoicesInfo schema | packages/server/src/schema.graphql:226 |
invoicesInfo resolver (groupBy _sum) | packages/server/src/resolvers/queries/patientQueries.js:2881 |
| Invoice model | packages/prisma/schema.prisma:2620 |
Worked reference numbers (sandbox)
| Set | Total | Discount | Pre‑discount base | New % | Old % |
|---|---|---|---|---|---|
| All invoices | ₺246,439.25 | ₺2,373.25 | ₺248,812.50 | ~1 % | ~1 % |
| Discounted only | ₺18,301.75 | ₺2,373.25 | ₺20,675.00 | 11.5 % | 13.0 % |
| Invoice #26 | ₺488.76 | ₺75.00 | ₺563.76 | — | — |
For invoice #26 the pieces are Subtotal ₺500 − Discount ₺75 + Tax ₺63.76 = Total ₺488.76.