fix : added helper for labels TRE,MJP & JKP (print)
This commit is contained in:
parent
39910e2c21
commit
ba2af136ca
@ -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,7 +860,58 @@ printTicket() {
|
|||||||
const winLabels = allRows.map(row => {
|
const winLabels = allRows.map(row => {
|
||||||
let displayNumbers = row.numbers;
|
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')) {
|
if (displayNumbers.includes('F')) {
|
||||||
displayNumbers = displayNumbers.flatMap(n =>
|
displayNumbers = displayNumbers.flatMap(n =>
|
||||||
n === 'F' ? this.getHorseNumbersForSelectedRace().map(num => num.toString()) : [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 label = row.label.padEnd(10);
|
||||||
const numbers = numbersStr.padEnd(15);
|
const numbers = numbersStr.padEnd(15);
|
||||||
const value = (`*${row.value || 0}`).padEnd(8);
|
const value = (`*${row.value || 0}`).padEnd(8);
|
||||||
// const total = `Rs ${row.total || 0}`.padStart(8);
|
|
||||||
return `${label}${numbers} ${value}`;
|
return `${label}${numbers} ${value}`;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user