From ba2af136ca9bec6e7a66cea234a58115398649dc Mon Sep 17 00:00:00 2001 From: karthik Date: Thu, 7 Aug 2025 14:34:45 +0530 Subject: [PATCH] fix : added helper for labels TRE,MJP & JKP (print) --- .../touch-pad-menu.component.ts | 81 ++++++++++++++++++- 1 file changed, 78 insertions(+), 3 deletions(-) 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 1dba641..17e76f6 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 @@ -771,6 +771,31 @@ getHorseNumbersForSelectedRace(): number[] { } } +// Helper: Get horse numbers for a specific race index (0-based) +getHorseNumbersForRaceIdx(raceIdx: number): number[] { + try { + const raceCardDataStr = localStorage.getItem('raceCardData'); + if (!raceCardDataStr) return []; + const raceCardData = JSON.parse(raceCardDataStr); + const races = raceCardData.raceVenueRaces?.races || []; + const race = races[raceIdx]; + if (Array.isArray(race)) { + // If race is array of runners, extract their numbers + return race + .map((runner: any) => { + if (typeof runner === 'number') return runner; + if (typeof runner === 'object' && runner.number) return Number(runner.number); + if (typeof runner === 'object' && runner.horseNumber) return Number(runner.horseNumber); + return null; + }) + .filter((n: any): n is number => typeof n === 'number' && n > 0); + } + return []; + } catch { + return []; + } +} + @@ -835,9 +860,60 @@ printTicket() { const winLabels = allRows.map(row => { let displayNumbers = row.numbers; - // 🐎 Expand 'F' to full horse numbers + // --- Multi-leg pools: Expand 'F' for each leg --- + if (['TRE', 'MJP', 'JKP'].includes(row.label)) { + // Split by '/' for legs + let legs: (number | string)[][] = []; + let currentLeg: (number | string)[] = []; + for (const n of displayNumbers) { + if (n === '/') { + legs.push(currentLeg); + currentLeg = []; + } else { + currentLeg.push(n); + } + } + if (currentLeg.length) legs.push(currentLeg); + + // For each leg, expand 'F' to correct horse numbers for that leg + const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JKP' ? 'jkp1' : row.label === 'TRE' ? 'trb1' : row.label; + const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}'); + const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || []; + // Fallback to hardcoded mapping if needed + const raceMap: { [key: string]: number[] } = { + 'mjp1': [1, 2, 3, 4], + 'jkp1': [3, 4, 5, 6, 7], + 'trb1': [2, 3, 4], + 'trb2': [5, 6, 7] + }; + const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []); + // If no mapping, fallback to consecutive races from 1 + const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1; + + let expandedLegs: string[] = legs.map((leg, i) => { + // Find race index for this leg + let raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i); + let expanded = leg.flatMap(n => + n === 'F' + ? this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()) + : [n] + ); + // Remove '-' and '#' for display + return expanded.filter(n => n !== '-' && n !== '#').join(','); + }); + + // Join legs with '/' + let numbersStr = expandedLegs.join(' / '); + + const label = row.label.padEnd(10); + const numbers = numbersStr.padEnd(15); + const value = (`*${row.value || 0}`).padEnd(8); + return `${label}${numbers} ${value}`; + } + + // 🐎 Expand 'F' to full horse numbers for other pools if (displayNumbers.includes('F')) { - displayNumbers = displayNumbers.flatMap(n => + displayNumbers = displayNumbers.flatMap(n => n === 'F' ? this.getHorseNumbersForSelectedRace().map(num => num.toString()) : [n] ); } @@ -860,7 +936,6 @@ const winLabels = allRows.map(row => { const label = row.label.padEnd(10); const numbers = numbersStr.padEnd(15); const value = (`*${row.value || 0}`).padEnd(8); - // const total = `Rs ${row.total || 0}`.padStart(8); return `${label}${numbers} ${value}`; }).join('\n');