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 <noreply@anthropic.com>
This commit is contained in:
Dave 2026-10-30 23:33:11 +02:00
parent 83aec143d4
commit 4ae45cb3aa
2 changed files with 14 additions and 3 deletions

View file

@ -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();

View file

@ -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',