fix : added auto clear to multi leg pool also

This commit is contained in:
karthik 2025-08-13 16:11:07 +05:30
parent 9451abf500
commit 494e40d17d

View File

@ -616,68 +616,148 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
}
//-----------------------------ENTER PAD VALUE-------------------------------------
enterPadVal(key: string) {
if (!this.numericPadEnabled || this.totalAmountLimitReached) return;
enterPadVal(key: string) {
if (!this.numericPadEnabled || this.totalAmountLimitReached) return;
if (key === 'X') {
this.padValue = '';
if (this.selectedLabel === 'WSP') {
this.wspTicketStage = 0; // Reset stage if WSP
}
// 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)) {
const currentValue = parseInt(this.padValue + key) || 0;
if (currentValue > 100) return;
this.padValue += key;
}
this.updateCanPrint();
const value = parseFloat(this.padValue) || 0;
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;
});
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;
if (key === 'X') {
this.padValue = '';
this.selectedNumbers = [];
if (this.selectedLabel === 'WSP') {
this.wspTicketStage = 0;
}
this.selectionService.updatePartial({
label: this.selectedLabel || '',
numbers: [...this.selectedNumbers],
value: 0,
total: 0,
isBoxed: this.isBoxed
});
this.updateCanPrint();
return;
}
if (/[0-9]/.test(key)) {
const currentValue = parseInt(this.padValue + key) || 0;
if (currentValue > 100) return;
this.padValue += key;
}
this.updateCanPrint();
const value = parseFloat(this.padValue) || 0;
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;
});
this.selectionService.setSelections(updatedSelections);
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
});
}
return;
}
if (this.multiLegLabels.includes(this.selectedLabel || '')) {
const maxLegs = this.getMaxLegs(this.currentPool || '');
const legsFilled = this.multiLegGroups.slice(0, maxLegs).every(group => group.length > 0);
if (!legsFilled) {
console.log('[DEBUG] Multi-leg pool incomplete (not all legs filled), clearing row');
this.selectionService.updatePartial({
label: '',
numbers: [],
value: 0,
total: 0,
isBoxed: false
});
this.selectedLabel = null;
this.selectedNumbers = [];
this.padValue = '';
this.isBoxed = false;
this.multiLegStage = 0;
this.multiLegGroups = [[], [], [], [], []];
this.currentPool = null;
this.multiLegBaseRaceIdx = 0;
this.currentLegRaceDisplay = '';
this.sharedStateService.updateSharedData({
type: 'multiLegPoolEnd',
value: null
});
this.updateCanPrint();
return;
}
this.selectionService.updatePartial({
value,
isBoxed: this.isBoxed,
label: this.selectedLabel || '',
numbers: [...this.selectedNumbers]
});
const currentRow = this.selectionService.getCurrentRow();
if (currentRow.total === 0 && value > 0 && currentRow.numbers.length > 0) {
console.log('[DEBUG] Multi-leg 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.multiLegStage = 0;
this.multiLegGroups = [[], [], [], [], []];
this.currentPool = null;
this.multiLegBaseRaceIdx = 0;
this.currentLegRaceDisplay = '';
this.sharedStateService.updateSharedData({
type: 'multiLegPoolEnd',
value: null
});
this.updateCanPrint();
}
return;
}
this.selectionService.updatePartial({
value,
isBoxed: this.isBoxed,
label: this.selectedLabel || '',
numbers: [...this.selectedNumbers]
});
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: [],
@ -685,36 +765,13 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
total: 0,
isBoxed: false
});
this.selectedLabel = null;
this.selectedNumbers = [];
this.padValue = '';
this.isBoxed = false;
this.updateCanPrint();
}
return;
}
// 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();
}
}
//---------------------------------------------------------------------------------------------
updateCanPrint() {