Dentolize · Invoice Discount Percentage Fix Walkthrough
On this pageTermsThe 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 basetotal + 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

FieldTypeMeaning
subtotalFloatlist price of procedures, pre‑discount
discountFloatmoney discounted
discountPercentFloatstored discount ÷ subtotal
tax / taxPercentFloatVAT amount / rate
totalFloatsubtotal − discount + tax (net of discount)
paidDecimalamount paid
pendingPaymentFloatamount awaiting confirmation
insuranceFloatinsurer‑covered portion
diagnosticFeeFloatdiagnostic fee component
releasedFloatamount released to clinic revenue
balanceInvoiceBoolwhether 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

WhatLocation
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/discountInvoiceInfo.js:16, InvoiceInfo.js:22
Total formulapackages/server/src/resolvers/mutations/actions/invoices/invoiceUtils.js:205
Per‑line invariantpackages/server/src/resolvers/mutations/actions/invoices/invoiceUtils.js:118
Stored discountPercentpackages/server/src/resolvers/mutations/actions/invoices/invoiceUtils.js:145
Values written to DBpackages/server/src/resolvers/mutations/actions/invoices/createNewInvoice.js:232
invoicesInfo schemapackages/server/src/schema.graphql:226
invoicesInfo resolver (groupBy _sum)packages/server/src/resolvers/queries/patientQueries.js:2881
Invoice modelpackages/prisma/schema.prisma:2620

Worked reference numbers (sandbox)

SetTotalDiscountPre‑discount baseNew %Old %
All invoices₺246,439.25₺2,373.25₺248,812.50~1 %~1 %
Discounted only₺18,301.75₺2,373.25₺20,675.0011.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.