feat : almost completed cancel

This commit is contained in:
Sibin Sabu 2025-09-15 15:15:15 +05:30
parent 3486b342d7
commit d851b0f949
2 changed files with 146 additions and 132 deletions

View File

@ -41,7 +41,7 @@ export class SidebarComponent {
this.showCancel = true;
this.cancelWarning = '';
const localTicketsStr = localStorage.getItem('localTicketsnew');
const localTicketsStr = localStorage.getItem('canceltickets');
if (localTicketsStr) {
try {
const localTickets = JSON.parse(localTicketsStr);
@ -52,7 +52,7 @@ export class SidebarComponent {
}
}
} 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
// printTicketCancel() {
// async printTicketCancel() {
// const enteredTicketNo = this.ticketNo?.trim();
// console.log('[STEP 1] Entered Ticket No:', enteredTicketNo);
// this.cancelWarning = '';
// const localTicketsStr = localStorage.getItem('localTicketsnew');
// const localTicketsStr = localStorage.getItem('canceltickets');
// if (!localTicketsStr) {
// console.error('[STEP 2] No localTickets found in localStorage.');
// this.cancelWarning = '❌ No ticket history found.';
@ -108,20 +107,49 @@ export class SidebarComponent {
// console.log('[STEP 7] Stored Barcode ID:', storedBarcode);
// if (enteredTicketNo === storedBarcode) {
// console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to print...');
// console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to cancel...');
// // 🧾 Construct cancel print layout (only totalAmount)
// const cancelTicketData = {
// type: 'CANCEL_TICKET',
// ticketId: lastTicket.ticketId || '',
// barcodeId: lastTicket.barcodeId,
// cancelDate: new Date().toLocaleString(),
// totalAmount: lastTicket.totalAmount || 0 // <-- only totalAmount
// };
// 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 Preview
// console.log('🧾 [CANCEL TICKET LAYOUT]');
// console.log(`
// 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 wont show until next ticket is issued
// this.ticketNo = ''; // <-- THIS LINE CLEARS THE INPUT
// const cancelTicketData = {
// type: 'CANCEL_TICKET',
// ticketId: lastTicket.ticketId || '',
// barcodeId: lastTicket.barcodeId,
// cancelDate: new Date().toLocaleString(),
// totalAmount: lastTicket.totalAmount || 0
// };
// // 🔍 Console Preview
// console.log('🧾 [CANCEL TICKET LAYOUT]');
// console.log(`
// ========================================
// ⚠️ TICKET CANCELLED ⚠️
// ----------------------------------------
@ -130,26 +158,28 @@ export class SidebarComponent {
// Cancelled At : ${cancelTicketData.cancelDate}
// Original Total: ₹${cancelTicketData.totalAmount}
// ========================================
// `);
// `);
// // 🖨️ Send to printer server
// fetch('http://localhost:9100/print', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify(cancelTicketData)
// })
// .then(response => {
// if (!response.ok) throw new Error(`Printer error: ${response.status}`);
// return response.text();
// // 🖨️ Send to printer server
// fetch('http://localhost:9100/print', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify(cancelTicketData)
// })
// .then(result => {
// console.log("✅ Cancel ticket print successful:", result);
// })
// .catch(error => {
// console.error("❌ Cancel ticket print failed:", error);
// });
// .then(r => r.text())
// .then(result => {
// console.log("✅ Cancel ticket print successful:", result);
// })
// .catch(error => {
// console.error("❌ Cancel ticket print failed:", error);
// });
// this.closeCancelPopup();
// this.closeCancelPopup();
// } catch (e) {
// console.error("❌ Cancel API call failed:", e);
// this.cancelWarning = '❌ Cancel API call failed. Please try again.';
// }
// } else {
// console.warn('[❌ MISMATCH] Entered Ticket No does NOT match last stored barcode.');
@ -160,14 +190,14 @@ export class SidebarComponent {
// //--------------------------------COMPLETED THE CANCEL PRINT ---------------------------------------
//--------------------------------------- UPDATED CANCEL PRINT -------------------------------------------
cancelWarning: string = ''; // For showing inline warnings
async printTicketCancel() {
const enteredTicketNo = this.ticketNo?.trim();
console.log('[STEP 1] Entered Ticket No:', enteredTicketNo);
this.cancelWarning = '';
const localTicketsStr = localStorage.getItem('localTicketsnew');
const localTicketsStr = localStorage.getItem('canceltickets');
if (!localTicketsStr) {
console.error('[STEP 2] No localTickets found in localStorage.');
this.cancelWarning = '❌ No ticket history found.';
@ -201,46 +231,69 @@ async printTicketCancel() {
const storedBarcode = lastTicket.barcodeId.trim();
console.log('[STEP 7] Stored Barcode ID:', storedBarcode);
if (enteredTicketNo === storedBarcode) {
console.log('[✅ MATCH] Ticket No matches barcode. Proceeding to cancel...');
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...');
try {
const cancelReq = {
ticketNo: lastTicket.barcodeId,
btId: lastTicket.btId || "0485",
usrId: lastTicket.usrId || "341"
};
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;
}
// ===== SUCCESS =====
// 1) Remove the last ticket from canceltickets so modal won't auto-fill it again
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;
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);
}
// ✅ Only print if cancel API succeeded
const cancelTicketData = {
type: 'CANCEL_TICKET',
ticketId: lastTicket.ticketId || '',
barcodeId: lastTicket.barcodeId,
cancelDate: new Date().toLocaleString(),
totalAmount: lastTicket.totalAmount || 0
};
// 2) Clear the UI input immediately
this.ticketNo = '';
this.cancelWarning = '';
// 🔍 Console Preview
console.log('🧾 [CANCEL TICKET LAYOUT]');
console.log(`
// 3) Prepare print payload and send to printer (non-blocking)
const cancelTicketData = {
type: 'CANCEL_TICKET',
ticketId: lastTicket.ticketId || '',
barcodeId: lastTicket.barcodeId,
cancelDate: new Date().toLocaleString(),
totalAmount: lastTicket.totalAmount || 0
};
console.log('🧾 [CANCEL TICKET LAYOUT]');
console.log(`
========================================
TICKET CANCELLED
----------------------------------------
@ -249,32 +302,27 @@ Barcode ID : ${cancelTicketData.barcodeId}
Cancelled At : ${cancelTicketData.cancelDate}
Original Total: ${cancelTicketData.totalAmount}
========================================
`);
`);
// 🖨️ Send to printer server
fetch('http://localhost:9100/print', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(cancelTicketData)
fetch('http://localhost:9100/print', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(cancelTicketData)
})
.then(r => r.text())
.then(result => {
console.log("✅ Cancel ticket print successful:", result);
})
.then(r => r.text())
.then(result => {
console.log("✅ Cancel ticket print successful:", result);
})
.catch(error => {
console.error("❌ Cancel ticket print failed:", error);
});
.catch(error => {
console.error("❌ Cancel ticket print failed:", error);
});
this.closeCancelPopup();
// 4) Close the modal
this.closeCancelPopup();
} catch (e) {
console.error("❌ Cancel API call failed:", e);
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.';
} catch (e) {
console.error("❌ Cancel API call failed:", e);
this.cancelWarning = '❌ Cancel API call failed. Please try again.';
}
}
@ -554,48 +602,12 @@ ${receiptText}
}
//----------------------------------------------PRINT WITHDRAW TICKET ENDS HERE -----------------------------
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() {
const cachedData = localStorage.getItem('rpinfo');

View File

@ -12,7 +12,7 @@ import { Subscription } from 'rxjs';
import { SelectionService, SelectionData } from '../selection.service/selection.service';
import { SharedStateService } from '../../service/shared-state.service';
import { LabelRestrictionService } from '../selection.service/label-restriction.service';
import _ from 'lodash';
import _, { join } from 'lodash';
@Component({
selector: 'app-touch-pad-menu',
@ -1438,6 +1438,7 @@ try {
try {
localStorage.setItem('issueT', JSON.stringify(commitJson));
console.log('Saved commitJson into localStorage key: issueT');
localStorage.setItem('cancelT', JSON.stringify(commitJson));
} catch (e) {
console.warn('Failed to save issueT:', e);
}
@ -1524,6 +1525,7 @@ try {
try {
localStorage.setItem('localTicketsnew', JSON.stringify([payload]));
console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
localStorage.setItem('canceltickets', JSON.stringify([payload]));
} catch (error) {
console.error('❌ Failed to store ticket locally:', error);
}