fix : added new local storage for repeat
This commit is contained in:
parent
a079bb9100
commit
05d356626f
@ -77,7 +77,7 @@
|
||||
<div>
|
||||
<button class="btn btn-dark" (click)="repeat()">Repeat</button>
|
||||
<button *ngIf="showConfirmButton" class="btn btn-success ms-2" (click)="confirm()">Confirm</button>
|
||||
<button *ngIf="showPrintButton" class="btn btn-primary ms-2" (click)="print()">Print</button>
|
||||
<button *ngIf="showPrintButton" class="btn btn-primary ms-2" (click)="printRepeat()">Print</button>
|
||||
<!-- <button class="btn btn-danger ms-2" (click)="erase()">Erase</button> -->
|
||||
</div>
|
||||
<div class="fw-bold fs-5">Amount : ₹ {{ grandTotal }}</div>
|
||||
|
||||
@ -94,7 +94,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
|
||||
repeat() {
|
||||
try {
|
||||
const storedTickets = localStorage.getItem('localTickets');
|
||||
const storedTickets = localStorage.getItem('localTicketsnew');
|
||||
if (storedTickets) {
|
||||
const tickets = JSON.parse(storedTickets);
|
||||
const latestTicket = Array.isArray(tickets)
|
||||
@ -143,25 +143,72 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
console.log('✅ [DEBUG] Ticket confirmed.');
|
||||
}
|
||||
|
||||
print() {
|
||||
|
||||
//-----------------------REPEAT PRINT LOGIC ----------------------------------
|
||||
printRepeat() {
|
||||
console.log('🖨️ [DEBUG] Printing ticket...');
|
||||
// Add your print logic here (e.g., window.print() or a custom print service)
|
||||
}
|
||||
|
||||
const username = localStorage.getItem('username') || 'Unknown';
|
||||
const currentDate = new Date().toLocaleString();
|
||||
|
||||
const printableRows = this.filledRows
|
||||
.filter(row => row.label && row.numbers.length > 0 && row.total > 0)
|
||||
.map(row => {
|
||||
const horses = Array.isArray(row.numbers) ? row.numbers.join(',') : row.numbers;
|
||||
return `${row.label.padEnd(6)} ${horses.padEnd(15)} * ${String(row.value).padEnd(3)} ₹${row.total}`;
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
const ticketContent = `
|
||||
=================================
|
||||
🏇 BTC Race Ticket 🏇
|
||||
=================================
|
||||
${printableRows}
|
||||
|
||||
Printed by : ${username}
|
||||
Date : ${currentDate}
|
||||
=================================
|
||||
`;
|
||||
|
||||
// ✅ Log preview in console
|
||||
console.log('%c\n' + ticketContent, 'font-family: monospace; color: green');
|
||||
|
||||
// ✅ Send to print server
|
||||
const payload = {
|
||||
type: 'repeat',
|
||||
printedBy: username,
|
||||
content: ticketContent,
|
||||
timestamp: currentDate
|
||||
};
|
||||
|
||||
fetch('http://localhost:9100/print', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error(`Printer error: ${response.status}`);
|
||||
return response.text();
|
||||
})
|
||||
.then(result => {
|
||||
console.log("✅ Repeat ticket print successful:", result);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("❌ Repeat ticket print failed:", error);
|
||||
});
|
||||
this.erase(); // Clear selections after printing
|
||||
|
||||
}
|
||||
|
||||
|
||||
//------------------------------PRINT REPEAT ENDED HERE-----------------------------------------------------S
|
||||
erase() {
|
||||
// Clear all rows and hide confirm/print buttons
|
||||
this.filledRows = Array.from({ length: 5 }, () => ({
|
||||
label: '',
|
||||
numbers: [],
|
||||
value: 0,
|
||||
total: 0
|
||||
}));
|
||||
this.grandTotal = 0;
|
||||
this.showConfirmButton = false;
|
||||
this.showPrintButton = false;
|
||||
// Optionally reset other state if needed
|
||||
this.selectionService.clearSelections();
|
||||
this.resetSelections();
|
||||
}
|
||||
resetSelections() {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.sub1.unsubscribe();
|
||||
this.sub2.unsubscribe();
|
||||
|
||||
@ -1017,12 +1017,14 @@ const winLabels = allRows.map(row => {
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to store ticket locally:', error);
|
||||
}
|
||||
// try {
|
||||
// localStorage.setItem('localTickets', JSON.stringify([payload]));
|
||||
// console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
|
||||
// } catch (error) {
|
||||
// console.error('❌ Failed to store ticket locally:', error);
|
||||
// }
|
||||
|
||||
try {
|
||||
localStorage.setItem('localTicketsnew', JSON.stringify([payload]));
|
||||
console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to store ticket locally:', error);
|
||||
}
|
||||
|
||||
fetch('http://192.168.1.12:8083/api/tickets', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user