Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions POS/src/components/sale/PaymentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,23 @@
</div>
<div class="grid grid-cols-4 gap-1.5">
<button
v-for="amount in quickAmounts"
v-if="quickAmounts.length > 0"
ref="firstQuickAmountBtnRef"
@click="addCustomPayment(lastSelectedMethod, quickAmounts[0])"
@keydown.enter.stop.prevent="handleFirstQuickAmountEnter"
:disabled="isQuickAmountDisabled(quickAmounts[0])"
:class="[
'font-semibold rounded-lg border-2 transition-all',
isCompactMode ? 'px-2 py-2 text-sm' : 'px-2 py-2 text-sm',
isQuickAmountDisabled(quickAmounts[0])
? 'bg-gray-50 border-gray-100 text-gray-300 cursor-not-allowed'
: 'bg-white border-gray-200 hover:border-blue-400 hover:bg-blue-50 text-gray-700 hover:text-blue-600'
]"
>
{{ formatCurrency(quickAmounts[0]) }}
</button>
<button
v-for="amount in quickAmounts.slice(1)"
:key="amount"
@click="addCustomPayment(lastSelectedMethod, amount)"
:disabled="isQuickAmountDisabled(amount)"
Expand Down Expand Up @@ -685,6 +701,7 @@
isExactAmountModeActive && !isCashPaymentMethod(lastSelectedMethod) ? 'text-gray-300' : 'text-gray-400'
]">{{ currencySymbol }}</span>
<input
ref="mobileAmountInputRef"
v-model="mobileCustomAmount"
type="number"
inputmode="decimal"
Expand All @@ -699,6 +716,7 @@
? 'bg-gray-50 border-gray-100 text-gray-300 cursor-not-allowed'
: 'bg-white border-gray-200 focus:ring-1 focus:ring-blue-500'
]"
@keydown.enter.prevent="handleMobileAmountEnter"
/>
</div>
<button
Expand Down Expand Up @@ -1178,12 +1196,16 @@ watch(
function handleNumpadEnter(value) {
if (value > 0 && lastSelectedMethod.value) {
numpadAddPayment()
nextTick(() => {
if (remainingAmount.value === 0 && totalPaid.value > 0 && canComplete.value) {
completePayment()
}
})
} else if (
remainingAmount.value === 0 &&
totalPaid.value > 0 &&
canComplete.value
) {
// If fully paid and can complete, trigger complete payment
completePayment()
}
}
Expand All @@ -1203,6 +1225,10 @@ const {

// Mobile custom amount state
const mobileCustomAmount = ref("")
const mobileAmountInputRef = ref(null)

// Desktop first quick-amount button ref (focused on open for Enter-to-pay)
const firstQuickAmountBtnRef = ref(null)

function addMobileCustomPayment() {
const amount = Number.parseFloat(mobileCustomAmount.value)
Expand All @@ -1212,6 +1238,33 @@ function addMobileCustomPayment() {
}
}

async function handleMobileAmountEnter() {
const amount = Number.parseFloat(mobileCustomAmount.value)
if (amount > 0 && lastSelectedMethod.value) {
await addCustomPayment(lastSelectedMethod.value, amount)
mobileCustomAmount.value = ""
nextTick(() => {
mobileAmountInputRef.value?.focus()
mobileAmountInputRef.value?.select()
})
if (canComplete.value && !isSubmitting.value) {
completePayment()
}
} else if (canComplete.value && !isSubmitting.value) {
completePayment()
} else if (props.allowCreditSale && paymentEntries.value.length === 0) {
addCreditAccountPayment()
}
}

async function handleFirstQuickAmountEnter() {
if (!lastSelectedMethod.value || !quickAmounts.value?.[0]) return
await addCustomPayment(lastSelectedMethod.value, quickAmounts.value[0])
if (canComplete.value && !isSubmitting.value) {
completePayment()
}
}

function numpadAddPayment() {
if (numpadValue.value > 0 && lastSelectedMethod.value) {
addCustomPayment(lastSelectedMethod.value, numpadValue.value)
Expand Down Expand Up @@ -1990,6 +2043,16 @@ watch(show, (newVal) => {
lastSelectedMethod.value = defaultMethod || paymentMethods.value[0]
}

// Pre-populate mobile input and focus first quick-amount button on desktop
if (props.grandTotal > 0) {
mobileCustomAmount.value = props.grandTotal.toFixed(2)
nextTick(() => {
mobileAmountInputRef.value?.focus()
mobileAmountInputRef.value?.select()
firstQuickAmountBtnRef.value?.focus()
})
}

// Customer credit and balance is pre-fetched when customer changes (see watcher above)
// Just log for debugging
const creditEnabled = props.allowCreditSale || props.allowCustomerCreditPayment
Expand Down
Loading