feat : almost completed cancel
This commit is contained in:
parent
3486b342d7
commit
d851b0f949
@ -41,7 +41,7 @@ export class SidebarComponent {
|
|||||||
this.showCancel = true;
|
this.showCancel = true;
|
||||||
this.cancelWarning = '';
|
this.cancelWarning = '';
|
||||||
|
|
||||||
const localTicketsStr = localStorage.getItem('localTicketsnew');
|
const localTicketsStr = localStorage.getItem('canceltickets');
|
||||||
if (localTicketsStr) {
|
if (localTicketsStr) {
|
||||||
try {
|
try {
|
||||||
const localTickets = JSON.parse(localTicketsStr);
|
const localTickets = JSON.parse(localTicketsStr);
|
||||||
@ -52,7 +52,7 @@ export class SidebarComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error reading localTicketsnew:', e);
|
console.error('Error reading canceltickets:', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,17 +63,16 @@ export class SidebarComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------- UPDATED CANCEL PRINT -------------------------------------------
|
||||||
|
|
||||||
// //---------------------------------------ADDED THE CANCEL PRINT -------------------------------------------
|
cancelWarning: string = ''; // For showing inline warnings
|
||||||
|
|
||||||
// cancelWarning: string = ''; // For showing inline warnings
|
// async printTicketCancel() {
|
||||||
|
|
||||||
// printTicketCancel() {
|
|
||||||
// const enteredTicketNo = this.ticketNo?.trim();
|
// const enteredTicketNo = this.ticketNo?.trim();
|
||||||
// console.log('[STEP 1] Entered Ticket No:', enteredTicketNo);
|
// console.log('[STEP 1] Entered Ticket No:', enteredTicketNo);
|
||||||
// this.cancelWarning = '';
|
// this.cancelWarning = '';
|
||||||
|
|
||||||
// const localTicketsStr = localStorage.getItem('localTicketsnew');
|
// const localTicketsStr = localStorage.getItem('canceltickets');
|
||||||
// if (!localTicketsStr) {
|
// if (!localTicketsStr) {
|
||||||
// console.error('[STEP 2] No localTickets found in localStorage.');
|
// console.error('[STEP 2] No localTickets found in localStorage.');
|
||||||
// this.cancelWarning = '❌ No ticket history found.';
|
// this.cancelWarning = '❌ No ticket history found.';
|
||||||
@ -108,15 +107,44 @@ export class SidebarComponent {
|
|||||||
// console.log('[STEP 7] Stored Barcode ID:', storedBarcode);
|
// console.log('[STEP 7] Stored Barcode ID:', storedBarcode);
|
||||||
|
|
||||||
// if (enteredTicketNo === storedBarcode) {
|
// if (enteredTicketNo === storedBarcode) {
|
||||||
// console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to print...');
|
// console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to cancel...');
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// // 🔗 Call cancel API first
|
||||||
|
// const cancelReq = {
|
||||||
|
// ticketNo: lastTicket.barcodeId,
|
||||||
|
// btId: lastTicket.btId || "0485", // <-- put correct btId here
|
||||||
|
// usrId: lastTicket.usrId || "341" // <-- put correct usrId here
|
||||||
|
// };
|
||||||
|
|
||||||
|
// console.log("📡 Sending cancel request:", cancelReq);
|
||||||
|
|
||||||
|
// const response = await fetch("http://localhost:8085/cancel/ticket", {
|
||||||
|
// method: "POST",
|
||||||
|
// headers: { "Content-Type": "application/json" },
|
||||||
|
// body: JSON.stringify(cancelReq)
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const data = await response.json();
|
||||||
|
// console.log("📩 Cancel API Response:", data);
|
||||||
|
|
||||||
|
|
||||||
|
// if (!data.ok) {
|
||||||
|
// console.error("❌ Cancel failed:", data.error);
|
||||||
|
// this.cancelWarning = `❌ Cancel failed: ${data.error}`;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // ✅ Cancel succeeded
|
||||||
|
// // Clear the input so it won’t show until next ticket is issued
|
||||||
|
// this.ticketNo = ''; // <-- THIS LINE CLEARS THE INPUT
|
||||||
|
|
||||||
// // 🧾 Construct cancel print layout (only totalAmount)
|
|
||||||
// const cancelTicketData = {
|
// const cancelTicketData = {
|
||||||
// type: 'CANCEL_TICKET',
|
// type: 'CANCEL_TICKET',
|
||||||
// ticketId: lastTicket.ticketId || '',
|
// ticketId: lastTicket.ticketId || '',
|
||||||
// barcodeId: lastTicket.barcodeId,
|
// barcodeId: lastTicket.barcodeId,
|
||||||
// cancelDate: new Date().toLocaleString(),
|
// cancelDate: new Date().toLocaleString(),
|
||||||
// totalAmount: lastTicket.totalAmount || 0 // <-- only totalAmount
|
// totalAmount: lastTicket.totalAmount || 0
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// // 🔍 Console Preview
|
// // 🔍 Console Preview
|
||||||
@ -138,10 +166,7 @@ export class SidebarComponent {
|
|||||||
// headers: { 'Content-Type': 'application/json' },
|
// headers: { 'Content-Type': 'application/json' },
|
||||||
// body: JSON.stringify(cancelTicketData)
|
// body: JSON.stringify(cancelTicketData)
|
||||||
// })
|
// })
|
||||||
// .then(response => {
|
// .then(r => r.text())
|
||||||
// if (!response.ok) throw new Error(`Printer error: ${response.status}`);
|
|
||||||
// return response.text();
|
|
||||||
// })
|
|
||||||
// .then(result => {
|
// .then(result => {
|
||||||
// console.log("✅ Cancel ticket print successful:", result);
|
// console.log("✅ Cancel ticket print successful:", result);
|
||||||
// })
|
// })
|
||||||
@ -151,6 +176,11 @@ export class SidebarComponent {
|
|||||||
|
|
||||||
// this.closeCancelPopup();
|
// this.closeCancelPopup();
|
||||||
|
|
||||||
|
// } catch (e) {
|
||||||
|
// console.error("❌ Cancel API call failed:", e);
|
||||||
|
// this.cancelWarning = '❌ Cancel API call failed. Please try again.';
|
||||||
|
// }
|
||||||
|
|
||||||
// } else {
|
// } else {
|
||||||
// console.warn('[❌ MISMATCH] Entered Ticket No does NOT match last stored barcode.');
|
// console.warn('[❌ MISMATCH] Entered Ticket No does NOT match last stored barcode.');
|
||||||
// this.cancelWarning = '❌ Invalid ticket number. Please check and try again.';
|
// this.cancelWarning = '❌ Invalid ticket number. Please check and try again.';
|
||||||
@ -160,14 +190,14 @@ export class SidebarComponent {
|
|||||||
// //--------------------------------COMPLETED THE CANCEL PRINT ---------------------------------------
|
// //--------------------------------COMPLETED THE CANCEL PRINT ---------------------------------------
|
||||||
//--------------------------------------- UPDATED CANCEL PRINT -------------------------------------------
|
//--------------------------------------- UPDATED CANCEL PRINT -------------------------------------------
|
||||||
|
|
||||||
cancelWarning: string = ''; // For showing inline warnings
|
|
||||||
|
|
||||||
async printTicketCancel() {
|
async printTicketCancel() {
|
||||||
const enteredTicketNo = this.ticketNo?.trim();
|
const enteredTicketNo = this.ticketNo?.trim();
|
||||||
console.log('[STEP 1] Entered Ticket No:', enteredTicketNo);
|
console.log('[STEP 1] Entered Ticket No:', enteredTicketNo);
|
||||||
this.cancelWarning = '';
|
this.cancelWarning = '';
|
||||||
|
|
||||||
const localTicketsStr = localStorage.getItem('localTicketsnew');
|
const localTicketsStr = localStorage.getItem('canceltickets');
|
||||||
if (!localTicketsStr) {
|
if (!localTicketsStr) {
|
||||||
console.error('[STEP 2] No localTickets found in localStorage.');
|
console.error('[STEP 2] No localTickets found in localStorage.');
|
||||||
this.cancelWarning = '❌ No ticket history found.';
|
this.cancelWarning = '❌ No ticket history found.';
|
||||||
@ -201,15 +231,19 @@ async printTicketCancel() {
|
|||||||
const storedBarcode = lastTicket.barcodeId.trim();
|
const storedBarcode = lastTicket.barcodeId.trim();
|
||||||
console.log('[STEP 7] Stored Barcode ID:', storedBarcode);
|
console.log('[STEP 7] Stored Barcode ID:', storedBarcode);
|
||||||
|
|
||||||
if (enteredTicketNo === storedBarcode) {
|
if (enteredTicketNo !== storedBarcode) {
|
||||||
|
console.warn('[❌ MISMATCH] Entered Ticket No does NOT match last stored barcode.');
|
||||||
|
this.cancelWarning = '❌ Invalid ticket number. Please check and try again.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to cancel...');
|
console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to cancel...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 🔗 Call cancel API first
|
|
||||||
const cancelReq = {
|
const cancelReq = {
|
||||||
ticketNo: lastTicket.barcodeId,
|
ticketNo: lastTicket.barcodeId,
|
||||||
btId: lastTicket.btId || "0485", // <-- put correct btId here
|
btId: lastTicket.btId || "0485",
|
||||||
usrId: lastTicket.usrId || "341" // <-- put correct usrId here
|
usrId: lastTicket.usrId || "341"
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("📡 Sending cancel request:", cancelReq);
|
console.log("📡 Sending cancel request:", cancelReq);
|
||||||
@ -229,7 +263,27 @@ async printTicketCancel() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Only print if cancel API succeeded
|
// ===== SUCCESS =====
|
||||||
|
// 1) Remove the last ticket from canceltickets so modal won't auto-fill it again
|
||||||
|
try {
|
||||||
|
const ctStr = localStorage.getItem('canceltickets');
|
||||||
|
if (ctStr) {
|
||||||
|
const ct = JSON.parse(ctStr);
|
||||||
|
if (Array.isArray(ct) && ct.length > 0) {
|
||||||
|
ct.pop(); // remove last (the one we just cancelled)
|
||||||
|
localStorage.setItem('canceltickets', JSON.stringify(ct));
|
||||||
|
console.log('[localStorage] removed last entry from canceltickets after cancel');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Could not update canceltickets after cancel', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Clear the UI input immediately
|
||||||
|
this.ticketNo = '';
|
||||||
|
this.cancelWarning = '';
|
||||||
|
|
||||||
|
// 3) Prepare print payload and send to printer (non-blocking)
|
||||||
const cancelTicketData = {
|
const cancelTicketData = {
|
||||||
type: 'CANCEL_TICKET',
|
type: 'CANCEL_TICKET',
|
||||||
ticketId: lastTicket.ticketId || '',
|
ticketId: lastTicket.ticketId || '',
|
||||||
@ -238,7 +292,6 @@ async printTicketCancel() {
|
|||||||
totalAmount: lastTicket.totalAmount || 0
|
totalAmount: lastTicket.totalAmount || 0
|
||||||
};
|
};
|
||||||
|
|
||||||
// 🔍 Console Preview
|
|
||||||
console.log('🧾 [CANCEL TICKET LAYOUT]');
|
console.log('🧾 [CANCEL TICKET LAYOUT]');
|
||||||
console.log(`
|
console.log(`
|
||||||
========================================
|
========================================
|
||||||
@ -251,7 +304,6 @@ Original Total: ₹${cancelTicketData.totalAmount}
|
|||||||
========================================
|
========================================
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// 🖨️ Send to printer server
|
|
||||||
fetch('http://localhost:9100/print', {
|
fetch('http://localhost:9100/print', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -265,17 +317,13 @@ Original Total: ₹${cancelTicketData.totalAmount}
|
|||||||
console.error("❌ Cancel ticket print failed:", error);
|
console.error("❌ Cancel ticket print failed:", error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 4) Close the modal
|
||||||
this.closeCancelPopup();
|
this.closeCancelPopup();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("❌ Cancel API call failed:", e);
|
console.error("❌ Cancel API call failed:", e);
|
||||||
this.cancelWarning = '❌ Cancel API call failed. Please try again.';
|
this.cancelWarning = '❌ Cancel API call failed. Please try again.';
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
console.warn('[❌ MISMATCH] Entered Ticket No does NOT match last stored barcode.');
|
|
||||||
this.cancelWarning = '❌ Invalid ticket number. Please check and try again.';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------- COMPLETED THE CANCEL PRINT WITH API CALL --------------------------------
|
//-------------------------------- COMPLETED THE CANCEL PRINT WITH API CALL --------------------------------
|
||||||
@ -554,48 +602,12 @@ ${receiptText}
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------PRINT WITHDRAW TICKET ENDS HERE -----------------------------
|
//----------------------------------------------PRINT WITHDRAW TICKET ENDS HERE -----------------------------
|
||||||
|
|
||||||
|
|
||||||
raceCardData: any = null; // ✅ Hold fetched data
|
raceCardData: any = null; // ✅ Hold fetched data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// openViewRcPopup() {
|
|
||||||
// const cachedData = localStorage.getItem('rpinfo');
|
|
||||||
|
|
||||||
// if (cachedData) {
|
|
||||||
// this.raceCardData = JSON.parse(cachedData);
|
|
||||||
// console.log('📦 Loaded race card from localStorage:', this.raceCardData);
|
|
||||||
// } else {
|
|
||||||
// this.raceCardData = { error: 'Race card not available locally' };
|
|
||||||
// console.warn('⚠️ No race card data found in localStorage.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.showViewRc = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// openViewRcPopup() {
|
|
||||||
// const cachedData = localStorage.getItem('rpinfo');
|
|
||||||
|
|
||||||
// if (cachedData) {
|
|
||||||
// try {
|
|
||||||
// this.raceCardData = JSON.parse(cachedData); // now it's an array
|
|
||||||
// console.log('📦 Loaded race card from localStorage:', this.raceCardData);
|
|
||||||
// } catch (e) {
|
|
||||||
// console.error('Error parsing rpinfo:', e);
|
|
||||||
// this.raceCardData = { error: 'Invalid race card data' };
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// this.raceCardData = { error: 'Race card not available locally' };
|
|
||||||
// console.warn('⚠️ No race card data found in localStorage.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this.showViewRc = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
openViewRcPopup() {
|
openViewRcPopup() {
|
||||||
const cachedData = localStorage.getItem('rpinfo');
|
const cachedData = localStorage.getItem('rpinfo');
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { Subscription } from 'rxjs';
|
|||||||
import { SelectionService, SelectionData } from '../selection.service/selection.service';
|
import { SelectionService, SelectionData } from '../selection.service/selection.service';
|
||||||
import { SharedStateService } from '../../service/shared-state.service';
|
import { SharedStateService } from '../../service/shared-state.service';
|
||||||
import { LabelRestrictionService } from '../selection.service/label-restriction.service';
|
import { LabelRestrictionService } from '../selection.service/label-restriction.service';
|
||||||
import _ from 'lodash';
|
import _, { join } from 'lodash';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-touch-pad-menu',
|
selector: 'app-touch-pad-menu',
|
||||||
@ -1438,6 +1438,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
localStorage.setItem('issueT', JSON.stringify(commitJson));
|
localStorage.setItem('issueT', JSON.stringify(commitJson));
|
||||||
console.log('Saved commitJson into localStorage key: issueT');
|
console.log('Saved commitJson into localStorage key: issueT');
|
||||||
|
localStorage.setItem('cancelT', JSON.stringify(commitJson));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to save issueT:', e);
|
console.warn('Failed to save issueT:', e);
|
||||||
}
|
}
|
||||||
@ -1524,6 +1525,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
localStorage.setItem('localTicketsnew', JSON.stringify([payload]));
|
localStorage.setItem('localTicketsnew', JSON.stringify([payload]));
|
||||||
console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
|
console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
|
||||||
|
localStorage.setItem('canceltickets', JSON.stringify([payload]));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Failed to store ticket locally:', error);
|
console.error('❌ Failed to store ticket locally:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user