Dry Cleaning Tracker

Enter your SmartPOS PIN

Incorrect PIN - try again

Dry Cleaning

Wedding Dress Jobs

Loading...
'; return; } _jobPage = job; _pendingStage = null; _ciTicked = new Set(); _ciItems = []; _editingItems = false; renderJobPageFull(); } catch(e) { document.getElementById('job-page').innerHTML = '
Failed: '+esc(e.message)+'
'; } } function backToList() { history.pushState({}, '', window.location.pathname); document.getElementById('job-page').style.display = 'none'; document.getElementById('main-view').style.display = ''; _jobPage = null; } window.addEventListener('popstate', function(e) { if (e.state && e.state.jobPage) { loadJobPage(e.state.jobPage); } else if (document.getElementById('job-page') && document.getElementById('job-page').style.display !== 'none') { document.getElementById('job-page').style.display = 'none'; document.getElementById('main-view').style.display = ''; _jobPage = null; } }); function renderJobPageFull() { const j = _jobPage; if (!j) return; const isBranch = j.source === 'krg' || j._migratedFrom === 'stitch'; const curIdx = STAGES.indexOf(j.stage); const histList = j.history || []; const items = j.items || []; const stepsHtml = STAGES.map(function(s, i) { const done = i < curIdx; const cur = i === curIdx; const sel = _pendingStage === s; let cls = done ? 'done' : cur ? 'cur' : (i === curIdx+1 ? 'next' : ''); if (sel) cls = 'sel'; const cap = done ? 'Done' : cur ? 'Now' : (i === curIdx+1 ? 'Next' : ''); return ''; }).join(''); const confirmBar = _pendingStage ? '
' : ''; const statBar = !_pendingStage && j.stage !== 'Delivered' ? '
'+ (j.stage==='Pick up'?'🚐 Waiting for pickup':j.stage==='Warehouse'?'📦 In the warehouse · ':j.stage==='In process'?'🫧 Cleaning in progress':j.stage==='Ready'?'✅ Ready to collect':'')+'
' : ''; const total = items.reduce(function(s,i){return s+(parseFloat(i.price)||0)*(parseInt(i.qty)||1);},0); const itemRows = _editingItems ? renderItemEditor(items, isBranch) : ( items.map(function(it) { return '
'+esc(it.name||it.item||'Item')+((it.qty||1)>1?' × '+it.qty:'')+''+(!isBranch?'$'+((parseFloat(it.price)||0)*(parseInt(it.qty)||1)).toFixed(2)+'':'')+'
'; }).join('') || '

No items yet.

' ); const totalRow = !_editingItems && !isBranch && items.length ? '
Total$'+total.toFixed(2)+'
' : ''; const photosHtml = (j.photos||[]).map(function(p){ return ''; }).join(''); const histHtml = histList.length ? histList.slice().reverse().map(function(h){ const dt = h.at ? new Date(h.at).toLocaleString('en-AU',{day:'numeric',month:'short',hour:'numeric',minute:'2-digit'}) : ''; return '
  • '+esc(h.t)+'
  • '; }).join('') : '
  • No history yet.
  • '; document.getElementById('job-page').innerHTML = '
    ' + '
    ' + '' + '
    ' + '

    '+esc(j.customerName||'Unknown')+'

    ' + '
    ' + ''+esc(j.orderNumber||j.id)+''+(j.branch||j.location?' · '+esc(j.branch||j.location):'')+'' + (j.phone?''+esc(j.phone)+'':'') + (j.email?''+esc(j.email)+'':'') + '
    ' + '
    ' + '
    ' + '
    '+stepsHtml+'
    ' + confirmBar + statBar + '
    ' + '
    ' + '
    ' + '

    Items'+(!_editingItems?'':'')+'

    ' + itemRows + totalRow + (!_editingItems?'
    White dress cover
    ':'') + '
    ' + '
    ' + '
    ' + '
    ' + '

    Notes & photos

    ' + '' + '' + '
    '+photosHtml+'
    ' + '' + '
    ' + '
    ' + '

    History

    ' + '
      '+histHtml+'
    ' + '
    ' + '
    ' + '
    ' + '
    '; } function renderItemEditor(items, isBranch) { const rows = items.map(function(it, idx) { return '
    ' + '' + '
    '+(it.qty||1)+'
    ' + (!isBranch?'':'') + '' + '
    '; }).join(''); const totalVal = items.reduce(function(s,i){return s+(parseFloat(i.price)||0)*(parseInt(i.qty)||1);},0); const quickPicks = QUICK_ITEMS.map(function(q){ return ''; }).join(''); return rows + (!isBranch && items.length?'
    Total ('+items.reduce(function(s,i){return s+(parseInt(i.qty)||1);},0)+' pcs)$'+totalVal.toFixed(2)+'
    ':'') + '

    Quick add

    ' + '
    '+quickPicks+'
    ' + '
    '; } function selectStage(s) { if(s===_jobPage.stage)return; _pendingStage=s; renderJobPageFull(); } function cancelStageSelect() { _pendingStage=null; renderJobPageFull(); } async function confirmStageChange() { if(!_pendingStage||!_jobPage)return; const stage=_pendingStage; if(stage==='Warehouse'&&_jobPage.stage==='Pick up'){startCheckin();return;} try { const r=await fetch('/api/stage',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pin,id:_jobPage.id,stage})}); const d=await r.json(); if(d.error){showToast('Error: '+d.error);return;} _jobPage.stage=stage; _pendingStage=null; if(!_jobPage.history)_jobPage.history=[]; _jobPage.history.push({t:'Stage changed to '+stage,at:new Date().toISOString()}); renderJobPageFull(); showToast('Stage updated: '+stage); loadJobs(); } catch(e){showToast('Error saving stage');} } function startCheckin() { _pendingStage=null; _ciTicked=new Set(); const j=_jobPage; const items=j.items||[]; const isBranch=j.source==='krg'||j._migratedFrom==='stitch'; _ciItems=items.map(function(i,idx){return Object.assign({},i,{idx:idx});}); const ciRows=_ciItems.map(function(it){return ciRowHtml(it,isBranch);}).join(''); const quickPicks=QUICK_ITEMS.map(function(q){return '';}).join(''); document.getElementById('job-page').innerHTML= '
    '+ '

    Warehouse Check-in

    '+esc(j.customerName)+' · '+esc(j.orderNumber||j.id)+'

    '+ '

    Tick each item as you check it in

    '+ciRows+'
    '+ '

    Add item

    '+quickPicks+'
    '+ '
    0 of '+items.length+' checked'+(!isBranch?'Total $0.00':'')+'
    '+ '

    Note (optional)

    '+ '
    White dress cover
    '+ ''+ '
    '; updateCiStatus(); } function ciRowHtml(it,isBranch){const on=_ciTicked.has(it.idx);return '
    '+esc(it.name||it.item||'Item')+((it.qty||1)>1?' × '+(it.qty||1):'')+''+(!isBranch?'$'+((parseFloat(it.price)||0)*(parseInt(it.qty)||1)).toFixed(2)+'':'')+'
    ';} function ciTick(idx){if(_ciTicked.has(idx))_ciTicked.delete(idx);else _ciTicked.add(idx);const btn=document.querySelector('#ci-row-'+idx+' .ci-tick');if(btn){btn.classList.toggle('on',_ciTicked.has(idx));btn.textContent=_ciTicked.has(idx)?'✓':'';}updateCiStatus();} function ciAddItem(name,price,isBranch){const idx=_ciItems.length;const item={idx,name,item:name,qty:1,price:isBranch?0:price};_ciItems.push(item);const c=document.getElementById('ci-items');if(c){const d=document.createElement('div');d.innerHTML=ciRowHtml(item,isBranch);c.appendChild(d.firstElementChild);}updateCiStatus();} function updateCiStatus(){const total=_ciItems.reduce(function(s,i){return s+(parseFloat(i.price)||0)*(parseInt(i.qty)||1);},0);const st=document.getElementById('ci-status');if(st)st.textContent=(_ciTicked.size===_ciItems.length&&_ciItems.length?'✓ All '+_ciItems.length+' checked':_ciTicked.size+' of '+_ciItems.length+' checked');const b=document.querySelector('#ci-foot b');if(b)b.textContent='Total $'+total.toFixed(2);} function cancelCheckin(){_ciTicked=new Set();_ciItems=[];renderJobPageFull();} async function completeCheckin(){ const note=document.getElementById('ci-note')?.value.trim()||''; const cover=document.getElementById('ci-cover')?.checked||false; try{ const r=await fetch('/api/checkin',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pin,id:_jobPage.id,items:_ciItems.map(function(i){return{name:i.name,item:i.item,qty:i.qty,price:i.price};}),cover,note})}); const d=await r.json(); if(d.error){showToast('Error: '+d.error);return;} _jobPage.stage='Warehouse';_jobPage.items=_ciItems.map(function(i){return{name:i.name,item:i.item,qty:i.qty,price:i.price};});_jobPage.cover=cover; if(note)_jobPage.notes=(_jobPage.notes?_jobPage.notes+'\n':'')+note; if(!_jobPage.history)_jobPage.history=[]; _jobPage.history.push({t:'Check-in completed – moved to Warehouse',at:new Date().toISOString()}); _ciTicked=new Set();_ciItems=[];renderJobPageFull();showToast('Check-in complete ✓');loadJobs(); }catch(e){showToast('Error saving check-in');} } function startEditItems(){_editingItems=true;renderJobPageFull();} function cancelEditItems(){_editingItems=false;renderJobPageFull();} function updateItemField(idx,field,val){if(!_jobPage.items)_jobPage.items=[];if(!_jobPage.items[idx])return;if(field==='name'){_jobPage.items[idx].name=val;_jobPage.items[idx].item=val;}else _jobPage.items[idx][field]=val;} function updateItemQty(idx,delta){if(!_jobPage.items||!_jobPage.items[idx])return;const nq=Math.max(1,(parseInt(_jobPage.items[idx].qty)||1)+delta);_jobPage.items[idx].qty=nq;renderJobPageFull();} function removeItem(idx){if(_jobPage.items){_jobPage.items.splice(idx,1);renderJobPageFull();}} function addQuickItem(name,price,isBranch){if(!_jobPage.items)_jobPage.items=[];_jobPage.items.push({name,item:name,qty:1,price:isBranch?0:price});renderJobPageFull();} async function saveItems(){ try{const r=await fetch('/api/items',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pin,id:_jobPage.id,items:_jobPage.items||[]})});const d=await r.json();if(d.error){showToast('Error: '+d.error);return;}_editingItems=false;if(!_jobPage.history)_jobPage.history=[];_jobPage.history.push({t:'Items updated',at:new Date().toISOString()});renderJobPageFull();showToast('Items saved ✓');}catch(e){showToast('Error saving items');} } async function toggleCover(checked){ try{const r=await fetch('/api/cover',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pin,id:_jobPage.id,cover:checked})});const d=await r.json();if(d.error){showToast('Error: '+d.error);return;}_jobPage.cover=checked;if(!_jobPage.history)_jobPage.history=[];_jobPage.history.push({t:'White dress cover '+(checked?'on':'off'),at:new Date().toISOString()});showToast(checked?'Cover: on':'Cover: off');}catch(e){showToast('Error saving cover');} } async function saveJobNote(){ const note=document.getElementById('job-notes')?.value||''; try{const r=await fetch('/api/note-history',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pin,id:_jobPage.id,note})});const d=await r.json();if(d.error){showToast('Error: '+d.error);return;}_jobPage.notes=note;if(!_jobPage.history)_jobPage.history=[];_jobPage.history.push({t:'Note saved',at:new Date().toISOString()});showToast('Note saved ✓');}catch(e){showToast('Error saving note');} } >