Skip to content
74 changes: 74 additions & 0 deletions POS/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,77 @@ async function initializeApp() {
}

initializeApp()

window.addEventListener('keydown', function (e) {

const key = e.key.toLowerCase()
const active = document.activeElement

// Prevent shortcuts while typing
if (active && (
active.tagName === "INPUT" ||
active.tagName === "TEXTAREA" ||
active.isContentEditable
)) {
return
}

const boxShortcuts = {
'o': "View Shift",
'd': "Draft Invoices",
'i': "Invoice History",
'k': "Return Invoice",
'p': "Close Shift",
'f': "Create Customer"
}

// Box Actions
if (e.ctrlKey && boxShortcuts[key]) {
e.preventDefault()
e.stopPropagation()

const targetText = boxShortcuts[key]

setTimeout(() => {
const btn = Array.from(document.querySelectorAll("button"))
.find(b => b.innerText?.trim().toLowerCase() === targetText.toLowerCase())

if (btn) btn.click()
}, 300)

return
}

// Focus Item Search
if (e.ctrlKey && key === 'b') {
e.preventDefault()

const input = document.querySelector('input[placeholder*="Search"]')
input?.focus()
return
}

// Focus Customer Search
if (e.ctrlKey && key === 'u') {
e.preventDefault()

const input = document.querySelector('input[placeholder*="customer"]')
input?.focus()
return
}

// Promotion Popup
if (e.ctrlKey && e.shiftKey && key === 'x') {
e.preventDefault()

const btn = Array.from(document.querySelectorAll("button"))
.find(b =>
b.innerText?.toLowerCase().includes("promotion") ||
b.innerText?.toLowerCase().includes("coupon")
)

if (btn) btn.click()
return
}

}, true)