diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts index fbd4e96..ce9a82e 100755 --- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts +++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts @@ -627,11 +627,17 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { if (this.selectedLabel === 'WSP') { this.wspTicketStage = 0; // Reset stage if WSP } - else if (/[0-9]/.test(key)) { - const currentValue = parseInt(this.padValue + key) || 0; - if (currentValue > 100) return; - this.padValue += key; - } + + // Clear the current row to reset any invalid state + this.selectionService.updatePartial({ + label: this.selectedLabel || '', + numbers: [...this.selectedNumbers], + value: 0, + total: 0, + isBoxed: this.isBoxed + }); + this.updateCanPrint(); + return; } if (/[0-9]/.test(key)) { @@ -640,37 +646,74 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) { this.padValue += key; } - this.updateCanPrint(); + this.updateCanPrint(); - const value = parseFloat(this.padValue) || 0; + const value = parseFloat(this.padValue) || 0; - if (this.selectedLabel === 'WSP') { - const labels = ['WIN', 'SHP', 'PLC']; - const targetLabel = labels[this.wspTicketStage]; + if (this.selectedLabel === 'WSP') { + const labels = ['WIN', 'SHP', 'PLC']; + const targetLabel = labels[this.wspTicketStage]; - const updatedSelections = this.selectionService.getSelections().map(sel => { - if (sel.label === targetLabel && JSON.stringify(sel.numbers) === JSON.stringify(this.selectedNumbers)) { - const total = value * (sel.numbers?.length || 0) * 10; - return { - ...sel, - value, - total - }; - } - return sel; + const updatedSelections = this.selectionService.getSelections().map(sel => { + if (sel.label === targetLabel && JSON.stringify(sel.numbers) === JSON.stringify(this.selectedNumbers)) { + const total = value * (sel.numbers?.length || 0) * 10; + return { + ...sel, + value, + total + }; + } + return sel; + }); + + this.selectionService.setSelections(updatedSelections); + + // Check if total is 0 for WSP (indicating invalid row) + const currentTotal = updatedSelections.find(sel => sel.label === targetLabel)?.total || 0; + if (currentTotal === 0 && value > 0) { + console.log('[DEBUG] WSP row invalid (total = 0), clearing row'); + this.selectionService.setSelections( + updatedSelections.filter(sel => sel.label !== targetLabel || sel.numbers.length > 0) + ); + this.wspTicketStage = 0; + this.padValue = ''; + this.selectedNumbers = []; + this.selectionService.updatePartial({ + label: '', + numbers: [], + value: 0, + total: 0, + isBoxed: false }); - - this.selectionService.setSelections(updatedSelections); - return; } + return; + } - // 🔵 Default path for non-WSP + // Default path for non-WSP this.selectionService.updatePartial({ value, isBoxed: this.isBoxed, label: this.selectedLabel || '', numbers: [...this.selectedNumbers] }); + + // Check if total is 0 after updating (indicating invalid mathematical logic) + const currentRow = this.selectionService.getCurrentRow(); + if (currentRow.total === 0 && value > 0 && currentRow.numbers.length > 0) { + console.log('[DEBUG] Row invalid (total = 0), auto-clearing current row'); + this.selectionService.updatePartial({ + label: '', + numbers: [], + value: 0, + total: 0, + isBoxed: false + }); + this.selectedLabel = null; + this.selectedNumbers = []; + this.padValue = ''; + this.isBoxed = false; + this.updateCanPrint(); + } } //---------------------------------------------------------------------------------------------