From 4ae45cb3aa289a8545a7a758c40fec70b6d8a8f2 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 30 Oct 2026 23:33:11 +0200 Subject: [PATCH] fix(pos): accept a comma as the decimal point in custom item price and cash given SA decimal keypads type ',' and the sanitizer stripped it, so R12,50 became R1250. Bump service worker cache to pos-v37 so tills pick up the new pos-app.js. Co-Authored-By: Claude Sonnet 5.5 --- public/pos/pos-app.js | 14 ++++++++++++-- public/pos/sw.js | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/public/pos/pos-app.js b/public/pos/pos-app.js index e0404dc..bf9fd20 100644 --- a/public/pos/pos-app.js +++ b/public/pos/pos-app.js @@ -315,6 +315,16 @@ function initials(s){ return parts.map(p=>p[0]||'').join('').toUpperCase().slice(0,2); } +// Decimal keyboards on South African phones type "," as the decimal key. +// Treat it as ".", drop everything else, keep only the first separator and +// at most 2 decimals (cents), so "12,50" -> "12.50" instead of 1250. +function cleanDecimal(v){ + let s = String(v||'').replace(/,/g,'.').replace(/[^0-9.]/g,''); + const i = s.indexOf('.'); + if(i !== -1) s = s.slice(0,i+1) + s.slice(i+1).replace(/\./g,'').slice(0,2); + return s; +} + // ---------------- custom (ad-hoc) lines ---------------- // // A line the cashier types by hand — "Bolt cutting" at R20 — that @@ -368,7 +378,7 @@ function closeCustomItem(){ } function saveCustomItem(){ const desc = document.getElementById('customDesc').value; - const price = document.getElementById('customPrice').value.replace(/[^0-9.]/g,''); + const price = cleanDecimal(document.getElementById('customPrice').value); const p = addCustomItem(desc, Number(price)); if(p) closeCustomItem(); } @@ -807,7 +817,7 @@ document.addEventListener('input', e=>{ }); document.addEventListener('input', e=>{ if(e.target.id!=='givenIn') return; - const raw = e.target.value.replace(/[^0-9.]/g,''); + const raw = cleanDecimal(e.target.value); e.target.value = raw; state.cashGiven = Number(raw)||0; paintChange(); diff --git a/public/pos/sw.js b/public/pos/sw.js index bbb48be..1927b2b 100644 --- a/public/pos/sw.js +++ b/public/pos/sw.js @@ -59,7 +59,8 @@ // painted under an unchanged total. Fixed with a global `[hidden]` override // plus blanking the figure when the row is hidden. Also carries the dark // palette lift. -const CACHE = "pos-v36"; +// v37: pos-app.js accepts a comma as the decimal point (custom item price, cash given). +const CACHE = "pos-v37"; const APP_SHELL = [ './', './index.html',