Add inventory audit mode with camera QR scanning

Lets an employee walk the premises, scan each object's QR to confirm
it's present and record where it was found (defaulting to the last
picked location), and track found/not-found progress for the walk.
Scanning a box's QR shows its contents read-only without affecting
the found/not-found counts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
jze9
2026-07-22 14:04:00 +05:00
parent 78862296c4
commit f99949559c
16 changed files with 506 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
import { useCallback, useState } from 'react'
const SESSION_START_KEY = 'inventory_audit_session_start'
const LAST_BOX_KEY = 'inventory_audit_last_box_id'
function readSessionStart(): number {
const raw = sessionStorage.getItem(SESSION_START_KEY)
if (raw) return Number(raw)
const now = Date.now()
sessionStorage.setItem(SESSION_START_KEY, String(now))
return now
}
/** Tracks the current audit walk: when it started (for the found/not-found split) and the
* last room/box picked, so the next scanned object can default to the same location. */
export function useAuditSession() {
const [sessionStart, setSessionStart] = useState<number>(readSessionStart)
const [lastBoxId, setLastBoxIdState] = useState<string | null>(() =>
sessionStorage.getItem(LAST_BOX_KEY),
)
const restart = useCallback(() => {
const now = Date.now()
sessionStorage.setItem(SESSION_START_KEY, String(now))
sessionStorage.removeItem(LAST_BOX_KEY)
setSessionStart(now)
setLastBoxIdState(null)
}, [])
const setLastBoxId = useCallback((boxId: string | null) => {
if (boxId) sessionStorage.setItem(LAST_BOX_KEY, boxId)
else sessionStorage.removeItem(LAST_BOX_KEY)
setLastBoxIdState(boxId)
}, [])
return { sessionStart, restart, lastBoxId, setLastBoxId }
}