From 554fdffa230dd35a2b778964ba4b78ef8d569e9f Mon Sep 17 00:00:00 2001 From: Sibin Sabu Date: Thu, 14 Aug 2025 12:07:17 +0530 Subject: [PATCH] fix : validation before print , auto fetch ticket id and wsp function (bug wsp) --- .../middle-section.component.ts | 183 ++----- .../components/sidebar/sidebar.component.css | 13 + .../components/sidebar/sidebar.component.html | 11 + .../components/sidebar/sidebar.component.ts | 502 +++--------------- .../touch-pad-menu.component.ts | 132 +++-- 5 files changed, 247 insertions(+), 594 deletions(-) diff --git a/btc-UI/src/app/components/middle-section/middle-section.component.ts b/btc-UI/src/app/components/middle-section/middle-section.component.ts index 34d7f43..5ba0bf6 100755 --- a/btc-UI/src/app/components/middle-section/middle-section.component.ts +++ b/btc-UI/src/app/components/middle-section/middle-section.component.ts @@ -112,69 +112,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy { -// repeat() { -// try { -// const storedTickets = localStorage.getItem('localTicketsnew'); -// if (storedTickets) { -// const tickets = JSON.parse(storedTickets); -// const latestTicket = Array.isArray(tickets) -// ? (tickets.length > 0 ? tickets[tickets.length - 1] : null) -// : tickets; -// if (latestTicket && latestTicket.winLabels) { -// const parsedRows = this.parseWinLabelsToRows(latestTicket.winLabels); - -// // โœ… Always make sure we have exactly 5 rows -// this.updateFilledRows(parsedRows, { label: '', numbers: [], value: 0, total: 0 }); - -// console.log('๐Ÿ“œ Updated Filled Rows:', parsedRows); // debug output -// this.showConfirmButton = true; -// this.showPrintButton = false; -// this.lastTicket = latestTicket; -// } else { -// console.warn('โš ๏ธ No valid ticket data found in localStorage.'); -// } -// } else { -// console.warn('โš ๏ธ No tickets found in localStorage.'); -// } -// } catch (error) { -// console.error('โŒ Failed to load ticket from localStorage:', error); -// } -// } - -// parseWinLabelsToRows(winLabels: string): SelectionData[] { -// // Match: LABEL NUMBERS *VALUE [Rs TOTAL optional] -// return (winLabels.split('\n') as string[]) -// .map(line => { -// // Works for both single-leg and multi-leg tickets -// const match = line.match(/^(\S+)\s+(.+?)\s+\*([\d.]+)(?:\s+Rs\s*(\d+))?/); -// if (!match) return null; - -// const label = match[1].trim(); -// const numbersRaw = match[2].trim(); -// const value = Number(match[3]); -// const total = match[4] ? Number(match[4]) : 0; - -// // If multi-leg ticket (MJP, TRE, etc.), split by '/' -// let numbers: string[] | string[][]; -// if (numbersRaw.includes('/')) { -// numbers = numbersRaw -// .split('/') -// .map(part => part.split(',').map(s => s.trim()).filter(Boolean)); -// } else { -// numbers = numbersRaw.split(',').map(s => s.trim()).filter(Boolean); -// } - -// return { -// label, -// numbers, -// value, -// total, -// isBoxed: numbersRaw.startsWith('#') -// }; -// }) -// .filter(Boolean) as SelectionData[]; -// } repeat() { try { const storedTickets = localStorage.getItem('localTicketsnew'); @@ -209,6 +147,8 @@ export class MiddleSectionComponent implements OnInit, OnDestroy { } } + + parseWinLabelsToRows(winLabels: string, fallbackTotal?: number): SelectionData[] { return (winLabels.split('\n') as string[]) .map(line => { @@ -248,85 +188,66 @@ parseWinLabelsToRows(winLabels: string, fallbackTotal?: number): SelectionData[] } - //-----------------------REPEAT PRINT LOGIC ---------------------------------- - printRepeat() { - console.log('๐Ÿ–จ๏ธ [DEBUG] Printing ticket...'); + //-------------------------------------------------REPEAT PRINT LOGIC ----------------------------------------------- + + +printRepeat() { + console.log('๐Ÿ–จ๏ธ [DEBUG] Printing ticket...'); const userName = localStorage.getItem('userName') || 'Unknown'; - const currentDate = new Date().toLocaleString(); - const printableRows = this.filledRows - .filter(row => row.label && row.numbers.length > 0 && row.total > 0) - .map(row => { - const horses = Array.isArray(row.numbers) ? row.numbers.join(',') : row.numbers; - return `${row.label.padEnd(6)} ${horses.padEnd(15)} * ${String(row.value).padEnd(3)} โ‚น${row.total}`; - }) - .join('\n'); + // Keep currentDate as a Date object + const now = new Date(); - const ticketContent = ` -================================= - ๐Ÿ‡ BTC Race Ticket ๐Ÿ‡ -================================= + // ๐Ÿ†• Create Barcode ID (same combo format) + const day = String(now.getDate()).padStart(2, '0'); + const month = String(now.getMonth() + 1).padStart(2, '0'); + const year = String(now.getFullYear()).slice(-2); + const timeStr = `${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`; + const millis = String(now.getMilliseconds()).padStart(3, '0'); + const barcodeId = `1111${day}${month}${year}${timeStr}${millis}`; + + const printableRows = this.filledRows + .filter(row => row.label && row.numbers.length > 0 && row.total > 0) + .map(row => { + const horses = Array.isArray(row.numbers) ? row.numbers.join(',') : row.numbers; + return `${row.label.padEnd(6)} ${horses.padEnd(15)} * ${String(row.value).padEnd(3)} โ‚น${row.total}`; + }) + .join('\n'); + + const ticketContent = ` + BTC Race Ticket ${printableRows} +Barcode ID : ${barcodeId} Printed by : ${userName} -Date : ${currentDate} -================================= - `; +Date : ${now.toLocaleString()}`; - // โœ… Log preview in console - console.log('%c\n' + ticketContent, 'font-family: monospace; color: green'); + console.log('%c\n' + ticketContent, 'font-family: monospace; color: green'); - // โœ… Send to print server - const payload = { - type: 'repeat', + const payload = { + type: 'repeat', printedBy: userName, - content: ticketContent, - timestamp: currentDate - }; + barcodeId, // send barcode separately + content: ticketContent, + timestamp: now.toLocaleString() + }; - fetch('http://localhost:9100/print', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(payload) - }) - .then(response => { - if (!response.ok) throw new Error(`Printer error: ${response.status}`); - return response.text(); - }) - .then(result => { - console.log("โœ… Repeat ticket print successful:", result); - }) - .catch(error => { - console.error("โŒ Repeat ticket print failed:", error); - }); - - // --- Update localStorage for transaction summary like normal print --- - // 1. Increment printClickCount - let clickCount = Number(localStorage.getItem('printClickCount') || '0'); - clickCount += 1; - localStorage.setItem('printClickCount', clickCount.toString()); - - // 2. Add a new ticket entry to localTickets (type: 'ticket', totalAmount) - try { - const existingTicketsStr = localStorage.getItem('localTickets'); - const existingTickets = existingTicketsStr ? JSON.parse(existingTicketsStr) : []; - // Calculate totalAmount for this repeat print - const totalAmount = this.filledRows - .filter(row => row.label && row.numbers.length > 0 && row.total > 0) - .reduce((sum, row) => sum + (row.total || 0), 0); - const ticketEntry = { - type: 'ticket', - printedBy: userName, - totalAmount, - content: ticketContent, - timestamp: currentDate - }; - existingTickets.push(ticketEntry); - localStorage.setItem('localTickets', JSON.stringify(existingTickets)); - } catch (error) { - console.error('โŒ Failed to update localTickets for repeat print:', error); - } + fetch('http://localhost:9100/print', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }) + .then(response => { + if (!response.ok) throw new Error(`Printer error: ${response.status}`); + return response.text(); + }) + .then(result => { + console.log("โœ… Repeat ticket print successful:", result); + }) + .catch(error => { + console.error("โŒ Repeat ticket print failed:", error); + }); // Hide Confirm and Print buttons before clearing selections this.showConfirmButton = false; @@ -340,6 +261,8 @@ Date : ${currentDate} //------------------------------PRINT REPEAT ENDED HERE-----------------------------------------------------S + + erase() { this.selectionService.clearSelections(); this.resetSelections(); diff --git a/btc-UI/src/app/components/sidebar/sidebar.component.css b/btc-UI/src/app/components/sidebar/sidebar.component.css index bca2f4f..f4e1760 100755 --- a/btc-UI/src/app/components/sidebar/sidebar.component.css +++ b/btc-UI/src/app/components/sidebar/sidebar.component.css @@ -504,3 +504,16 @@ h4{ font-size: 0.9em; font-weight: bold; } + +.deposit-warning { + margin-top: 0; + color: red; + font-weight: normal; +} + +.withdraw-warning { + margin-top: 8px; + color: red; + font-weight:normal; +} + diff --git a/btc-UI/src/app/components/sidebar/sidebar.component.html b/btc-UI/src/app/components/sidebar/sidebar.component.html index 6a4578f..6a9e745 100755 --- a/btc-UI/src/app/components/sidebar/sidebar.component.html +++ b/btc-UI/src/app/components/sidebar/sidebar.component.html @@ -34,6 +34,7 @@ id="ticketNo" class="modal-input" [(ngModel)]="ticketNo" + readonly />
{{ cancelWarning }} @@ -131,6 +132,11 @@
+ +
+ {{ depositWarning }} +
+ + +
+ {{ withdrawWarning }} +
+