fix : added print and proper enter logic to wsp
This commit is contained in:
parent
554fdffa23
commit
200360cb68
@ -147,8 +147,6 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
parseWinLabelsToRows(winLabels: string, fallbackTotal?: number): SelectionData[] {
|
||||
return (winLabels.split('\n') as string[])
|
||||
.map(line => {
|
||||
@ -188,9 +186,7 @@ parseWinLabelsToRows(winLabels: string, fallbackTotal?: number): SelectionData[]
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------REPEAT PRINT LOGIC -----------------------------------------------
|
||||
|
||||
|
||||
//-----------------------REPEAT PRINT LOGIC ----------------------------------
|
||||
printRepeat() {
|
||||
console.log('🖨️ [DEBUG] Printing ticket...');
|
||||
|
||||
@ -225,6 +221,7 @@ Date : ${now.toLocaleString()}`;
|
||||
|
||||
console.log('%c\n' + ticketContent, 'font-family: monospace; color: green');
|
||||
|
||||
// ✅ Send to print server
|
||||
const payload = {
|
||||
type: 'repeat',
|
||||
printedBy: userName,
|
||||
@ -249,6 +246,33 @@ Date : ${now.toLocaleString()}`;
|
||||
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,
|
||||
|
||||
};
|
||||
existingTickets.push(ticketEntry);
|
||||
localStorage.setItem('localTickets', JSON.stringify(existingTickets));
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to update localTickets for repeat print:', error);
|
||||
}
|
||||
|
||||
// Hide Confirm and Print buttons before clearing selections
|
||||
this.showConfirmButton = false;
|
||||
this.showPrintButton = false;
|
||||
@ -261,8 +285,6 @@ Date : ${now.toLocaleString()}`;
|
||||
|
||||
|
||||
//------------------------------PRINT REPEAT ENDED HERE-----------------------------------------------------S
|
||||
|
||||
|
||||
erase() {
|
||||
this.selectionService.clearSelections();
|
||||
this.resetSelections();
|
||||
|
||||
@ -586,7 +586,6 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||
}
|
||||
|
||||
onPadEnter() {
|
||||
// Disable Enter if maxRowsReached
|
||||
if (this.maxRowsReached) return;
|
||||
|
||||
if (!this.canPrint) {
|
||||
@ -598,13 +597,21 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||
if (this.selectedLabel === 'WSP') {
|
||||
const labels = ['WIN', 'SHP', 'PLC'];
|
||||
const targetLabel = labels[this.wspTicketStage];
|
||||
const selections = this.selectionService.getSelections();
|
||||
|
||||
const updatedSelections = this.selectionService.getSelections().map(sel => {
|
||||
if (sel.label === targetLabel && JSON.stringify(sel.numbers) === JSON.stringify(this.selectedNumbers)) {
|
||||
// Find the current WSP row to ensure numbers are synchronized
|
||||
const currentWSPRow = selections.find(sel => sel.label === targetLabel);
|
||||
if (currentWSPRow) {
|
||||
this.selectedNumbers = [...currentWSPRow.numbers]; // Synchronize selectedNumbers
|
||||
}
|
||||
|
||||
const updatedSelections = selections.map(sel => {
|
||||
if (sel.label === targetLabel) {
|
||||
const total = value * (sel.numbers?.length || 0) * 10;
|
||||
return {
|
||||
...sel,
|
||||
value,
|
||||
total: value * (sel.numbers?.length || 0) * 10
|
||||
total
|
||||
};
|
||||
}
|
||||
return sel;
|
||||
@ -612,17 +619,26 @@ if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||
|
||||
this.selectionService.setSelections(updatedSelections);
|
||||
|
||||
// Move to next stage
|
||||
this.wspTicketStage = (this.wspTicketStage + 1) % 3;
|
||||
// Only increment stage if not at the last stage (PLC)
|
||||
if (this.wspTicketStage < 2) {
|
||||
this.wspTicketStage++;
|
||||
// Update selectedNumbers for the next stage
|
||||
const nextLabel = labels[this.wspTicketStage];
|
||||
const nextWSPRow = updatedSelections.find(sel => sel.label === nextLabel);
|
||||
if (nextWSPRow) {
|
||||
this.selectedNumbers = [...nextWSPRow.numbers];
|
||||
}
|
||||
}
|
||||
|
||||
this.padValue = '';
|
||||
this.updateCanPrint();
|
||||
return;
|
||||
}
|
||||
|
||||
// ✅ Default path: finalize row and reset input
|
||||
this.print();
|
||||
}
|
||||
|
||||
|
||||
onShashEnter() {
|
||||
if (this.selectedLabel === 'TAN' && this.isBoxed) {
|
||||
return;
|
||||
@ -841,6 +857,24 @@ enterPadVal(key: string) {
|
||||
// At least one valid row in finalized selections or current row
|
||||
const selections = this.selectionService.getSelections();
|
||||
const currentRow = this.selectionService.getCurrentRow();
|
||||
if (this.selectedLabel === 'WSP') {
|
||||
// For WSP, require all three rows (WIN, SHP, PLC) to have valid numbers and values >= 1
|
||||
const wspLabels = ['WIN', 'SHP', 'PLC'];
|
||||
const wspSelections = selections.filter(sel => wspLabels.includes(sel.label));
|
||||
|
||||
// Check if we are at the last stage (PLC) and all rows are valid
|
||||
const allWSPRowsValid = wspSelections.length === 3 && wspSelections.every(row =>
|
||||
row.label &&
|
||||
row.numbers &&
|
||||
row.numbers.length > 0 &&
|
||||
row.value >= 1 &&
|
||||
row.total > 0
|
||||
);
|
||||
|
||||
return this.wspTicketStage === 2 && allWSPRowsValid;
|
||||
}
|
||||
|
||||
// For non-WSP, keep existing logic: any valid row enables printing
|
||||
const hasValidRow = selections.some(
|
||||
row => !!row.label && !!row.numbers && row.numbers.length > 0 && row.value > 0 && row.total > 0
|
||||
) || (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user