Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pricing Calculator

[![Tests](https://github.com/sterlingspares/calc/actions/workflows/tests.yml/badge.svg)](https://github.com/sterlingspares/calc/actions/workflows/tests.yml) ![Tests](https://img.shields.io/badge/tests-1406%20passing-brightgreen?style=flat-square) ![Coverage](https://img.shields.io/badge/coverage-80%25-green?style=flat-square) ![Lighthouse Performance](https://img.shields.io/badge/Lighthouse%20Perf-97-brightgreen?style=flat-square&logo=lighthouse) ![Lighthouse Accessibility](https://img.shields.io/badge/Lighthouse%20A11y-100-brightgreen?style=flat-square&logo=lighthouse) ![Lighthouse Best Practices](https://img.shields.io/badge/Best%20Practices-100-brightgreen?style=flat-square&logo=lighthouse) ![a11y](https://img.shields.io/badge/WCAG%202.1-AA-brightgreen?style=flat-square) ![PWA](https://img.shields.io/badge/PWA-offline--ready-brightgreen?style=flat-square&logo=pwa) ![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)
[![Tests](https://github.com/sterlingspares/calc/actions/workflows/tests.yml/badge.svg)](https://github.com/sterlingspares/calc/actions/workflows/tests.yml) ![Tests](https://img.shields.io/badge/tests-1479%20passing-brightgreen?style=flat-square) ![Coverage](https://img.shields.io/badge/coverage-80%25-green?style=flat-square) ![Lighthouse Performance](https://img.shields.io/badge/Lighthouse%20Perf-97-brightgreen?style=flat-square&logo=lighthouse) ![Lighthouse Accessibility](https://img.shields.io/badge/Lighthouse%20A11y-100-brightgreen?style=flat-square&logo=lighthouse) ![Lighthouse Best Practices](https://img.shields.io/badge/Best%20Practices-100-brightgreen?style=flat-square&logo=lighthouse) ![a11y](https://img.shields.io/badge/WCAG%202.1-AA-brightgreen?style=flat-square) ![PWA](https://img.shields.io/badge/PWA-offline--ready-brightgreen?style=flat-square&logo=pwa) ![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)

**Live app:** [calc.sterlingspares.com](https://calc.sterlingspares.com)

Expand Down Expand Up @@ -76,7 +76,7 @@ rebate from the supplier:
| **Profit** | **₹168.00** | ₹750.00 − ₹582.00 |
| GP % | 22.40% | 168 ÷ 750 |
| Margin % | 28.87% | 168 ÷ 582 |
| Break-even SP | ₹686.76 | incl GST — below this you lose money |
| Break-even SP (incl GST) | ₹686.76 | incl GST — below this you lose money |

Without the two incentives the same deal shows ₹150.00 profit and 20.00% GP.
That 3% off-invoice is a fifth of the profit, and it is exactly the part that is
Expand Down Expand Up @@ -145,7 +145,7 @@ sw.js service worker
manifest.json PWA manifest
_headers response headers for the host
tests/ test suite (dev-only)
docs/ screenshots for this README
docs/ screenshots for this README (npm run screenshots)
robots.txt · sitemap.xml indexing
```

Expand Down Expand Up @@ -410,8 +410,8 @@ Shown in the **Profit card**, beside the profit they are measured against:

| Row | Meaning |
|---|---|
| **Break-even SP** | Price at which profit reaches zero |
| **SP at GP floor** | Price at which GP % hits your Settings floor |
| **Break-even SP (incl GST)** | Price at which profit reaches zero |
| **SP at GP floor (incl GST)** | Price at which GP % hits your Settings floor |

Both are stated *before* SP incentives — those reduce what you actually receive,
so the quotable price is grossed back up accordingly.
Expand Down Expand Up @@ -449,6 +449,26 @@ takes its own SP input (discount % or manual ₹) and shows SP, Profit ₹, GP %
Margin %. The highest-GP scenario is highlighted automatically, and everything
updates live.

### GP % / markup % converter

Two ways of quoting the same profit, over different denominators — which is why
a supplier offering "25%" and a customer expecting "25%" can mean different
money. **GP ⇄ Markup** in the header takes either and returns the other:

| GP % | Markup % |
|---:|---:|
| 20.00 | 25.00 |
| 25.00 | 33.33 |
| 50.00 | 100.00 |

`markup = GP ÷ (100 − GP)` and `GP = markup ÷ (100 + markup)`. It shows the
result as money as well — *buy at ₹100.00, sell at ₹125.00* — because a
percentage on its own is easy to nod along to. **Use this calculation** seeds it
from whatever is on screen, and the two ends with no finite answer (100% GP,
−100% markup) say so rather than blanking.

Markup % is what this app calls **Margin %** elsewhere.

### Quote builder

A multi-line quoting tool — press `M`, or use **Quote** in the header / menu.
Expand Down Expand Up @@ -505,12 +525,23 @@ CSV · Clear all.

### Undo / redo

Every state-changing action is undoable: adding, deleting, renaming or retyping
an incentive, changing rounding, resetting, editing the quote, and all history
operations.
Every state-changing action is undoable — **including typed values**. Correcting
an MRP, a discount, a quantity, a landed cost or an incentive rate is a step you
can walk back, as are the chips, toggles and dropdowns.

One field edit is one step, not one per keystroke: the state is captured when
you enter the field and recorded when you leave it, so `⌘/Ctrl + Z` takes back
the whole number rather than the last digit. Entering a field and leaving it
untouched records nothing.

Anything that does not change what the app saves — opening a dialog, switching a
Settings tab, searching history — stays out of the stack, so undo never burns a
step on a no-op.

- **Undo / Redo** buttons in the header (Undo also in the mobile menu)
- `⌘/Ctrl + Z` and `⌘/Ctrl + ⇧ + Z` — these work even while typing in a field
- `⌘/Ctrl + Z` and `⌘/Ctrl + ⇧ + Z` — these work even while typing in a field,
and take the edit in progress with them
- The toast names what it reverted: *Undid: cost discount*
- Destructive actions show a toast with an inline **Undo**
- Up to **40 steps** retained

Expand Down Expand Up @@ -562,6 +593,7 @@ and it disappears from the screen:
| | |
|---|---|
| **Presets** | the header button, menu entry and the manager |
| **GP / markup converter** | the header button |
| **Quote builder** | the header button, menu item and bottom-nav tab |
| **What-if scenarios** | the button on the summary |
| **Landed costs** | both fields in the MRP bar |
Expand Down Expand Up @@ -743,7 +775,7 @@ Every number here is reproducible from the repo — none is hand-written.

| Metric | Value | Reproduce with |
|---|---|---|
| Tests | 1406 passing, 7 suites | `npm test` |
| Tests | 1479 passing, 7 suites | `npm test` |
| Statement coverage | **82.7%** (app.js 86.3%, app-extra.js 72.3%) | `npm run coverage` |
| Lighthouse Performance | **97** | `npm i -D lighthouse && npm run lighthouse` |
| Lighthouse Accessibility | **100** | ” |
Expand Down Expand Up @@ -780,7 +812,7 @@ commands after significant changes.

## Tests

1406 assertions across seven suites. They load the real `index.html`,
1479 assertions across seven suites. They load the real `index.html`,
`assets/styles.css` and both script bundles, and drive the actual application
functions — no application code is mocked. **Node 22 or newer.**

Expand All @@ -791,13 +823,13 @@ npm test

| Suite | Assertions | Covers |
|---|---|---|
| `features` | 979 | GST, incentives, quantity, landed costs, rounding, undo/redo, quote maths, history |
| `features` | 1041 | GST, incentives, quantity, landed costs, rounding, undo/redo of typed values and controls, quote maths, history |
| `errors` | 33 | every failure path logs; a clean run stays silent; storage and payload recovery |
| `mobile` | 78 | modal layering, touch targets, sticky result bar, responsive quote layouts |
| `fab` | 50 | floating action button behaviour and z-index ordering |
| `modes` | 85 | solve modes, price input modes, what-if, comparison, Quick mode, wizard, share-link round trip, theming, auto-save |
| `a11y` | 103 | contrast ratios, structure, names, keyboard operability, focus trap, live regions, reduced motion, axe-core |
| `browser` | 78 | real Chromium over HTTP: asset loading, CSS cascade, `defer` timing, clicks, dialogs, mobile viewport, axe with layout |
| `a11y` | 104 | contrast ratios, structure, names, keyboard operability, focus trap, live regions, reduced motion, axe-core |
| `browser` | 88 | real Chromium over HTTP: asset loading, CSS cascade, `defer` timing, clicks, dialogs, control-bar spacing, mobile viewport, axe with layout |

Individual suites: `npm run test:features`, `test:errors`, `test:mobile`,
`test:fab`, `test:modes`, `test:a11y`, `test:browser`. Full assertion output:
Expand Down
12 changes: 7 additions & 5 deletions assets/app-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ function fcBuildCards(){
function fcMkField(symTxt,inputId,placeholder,extraStyle,sufId){
var isRupee=(symTxt!=='%');
var wrap=document.createElement('div');wrap.className='fc-input-wrap';if(extraStyle)wrap.style.cssText=extraStyle;
var sym=document.createElement('span');sym.className='fc-input-sym';sym.textContent=symTxt;
var sym=document.createElement('span');
// A word rather than a currency glyph needs the smaller treatment, or it
// eats half the field on a phone.
sym.className='fc-input-sym'+(symTxt.length>2?' word':'');sym.textContent=symTxt;
var inp=document.createElement('input');inp.className='fc-input';inp.inputMode='decimal';inp.autocomplete='off';
inp.id=inputId;inp.placeholder=placeholder;
if(isRupee){
Expand Down Expand Up @@ -326,7 +329,7 @@ function fcBuildCPCard(){
// disc input
var discWrap=document.createElement('div');discWrap.id='fc-cp-disc-wrap';
discWrap.style.display=FC_CM==='manual'?'none':'';
discWrap.appendChild(fcMkField('Disc','fc-cpd','e.g. 34',null,'fc-cpd-suf'));
discWrap.appendChild(fcMkField('Discount','fc-cpd','e.g. 34',null,'fc-cpd-suf'));
card.appendChild(discWrap);

// manual input
Expand Down Expand Up @@ -383,7 +386,7 @@ function fcBuildSPCard(){

var discWrap=document.createElement('div');discWrap.id='fc-sp-disc-wrap';
discWrap.style.display=FC_SM==='manual'?'none':'';
discWrap.appendChild(fcMkField('Disc','fc-spd','e.g. 20',null,'fc-spd-suf'));
discWrap.appendChild(fcMkField('Discount','fc-spd','e.g. 20',null,'fc-spd-suf'));
card.appendChild(discWrap);

var manWrap=document.createElement('div');manWrap.id='fc-sp-manual-wrap';manWrap.style.cssText='display:'+(FC_SM==='manual'?'flex':'none')+';flex-direction:column;gap:8px';
Expand Down Expand Up @@ -942,7 +945,6 @@ function qtField(i,field,val,opts){
+(opts.step?' step="'+opts.step+'"':'')
+(opts.style?' style="'+opts.style+'"':'')
+(opts.label?' aria-label="'+opts.label+'"':'')
+' data-focus="undoQuote"'
+' data-input="qtSet" data-p="'+i+'" data-q="'+field+'" autocomplete="off">';
}

Expand Down Expand Up @@ -1496,7 +1498,7 @@ function _renderWhatIfImpl(cp){
} else {
// disc % input — oninput stores + updateWiResults() only
var fld=document.createElement('div');fld.className='field';
var sym=document.createElement('span');sym.className='sym';sym.textContent='Disc %';
var sym=document.createElement('span');sym.className='sym';sym.textContent='Discount %';
var inp=document.createElement('input');inp.type='number';inp.inputMode='decimal';inp.placeholder='e.g. 20';
inp.min='0';inp.max='100';inp.step='0.01';inp.value=sc.spDisc;inp.autocomplete='off';
inp.oninput=(function(idx){return function(){
Expand Down
Loading
Loading