fix : added new local storage for repeat
This commit is contained in:
parent
a079bb9100
commit
05d356626f
@ -77,7 +77,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<button class="btn btn-dark" (click)="repeat()">Repeat</button>
|
<button class="btn btn-dark" (click)="repeat()">Repeat</button>
|
||||||
<button *ngIf="showConfirmButton" class="btn btn-success ms-2" (click)="confirm()">Confirm</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> -->
|
<!-- <button class="btn btn-danger ms-2" (click)="erase()">Erase</button> -->
|
||||||
</div>
|
</div>
|
||||||
<div class="fw-bold fs-5">Amount : ₹ {{ grandTotal }}</div>
|
<div class="fw-bold fs-5">Amount : ₹ {{ grandTotal }}</div>
|
||||||
|
|||||||
@ -94,7 +94,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
repeat() {
|
repeat() {
|
||||||
try {
|
try {
|
||||||
const storedTickets = localStorage.getItem('localTickets');
|
const storedTickets = localStorage.getItem('localTicketsnew');
|
||||||
if (storedTickets) {
|
if (storedTickets) {
|
||||||
const tickets = JSON.parse(storedTickets);
|
const tickets = JSON.parse(storedTickets);
|
||||||
const latestTicket = Array.isArray(tickets)
|
const latestTicket = Array.isArray(tickets)
|
||||||
@ -143,25 +143,72 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
|||||||
console.log('✅ [DEBUG] Ticket confirmed.');
|
console.log('✅ [DEBUG] Ticket confirmed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
print() {
|
|
||||||
|
//-----------------------REPEAT PRINT LOGIC ----------------------------------
|
||||||
|
printRepeat() {
|
||||||
console.log('🖨️ [DEBUG] Printing ticket...');
|
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() {
|
erase() {
|
||||||
// Clear all rows and hide confirm/print buttons
|
this.selectionService.clearSelections();
|
||||||
this.filledRows = Array.from({ length: 5 }, () => ({
|
this.resetSelections();
|
||||||
label: '',
|
}
|
||||||
numbers: [],
|
resetSelections() {
|
||||||
value: 0,
|
throw new Error('Method not implemented.');
|
||||||
total: 0
|
|
||||||
}));
|
|
||||||
this.grandTotal = 0;
|
|
||||||
this.showConfirmButton = false;
|
|
||||||
this.showPrintButton = false;
|
|
||||||
// Optionally reset other state if needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.sub1.unsubscribe();
|
this.sub1.unsubscribe();
|
||||||
this.sub2.unsubscribe();
|
this.sub2.unsubscribe();
|
||||||
|
|||||||
@ -1017,12 +1017,14 @@ const winLabels = allRows.map(row => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Failed to store ticket locally:', error);
|
console.error('❌ Failed to store ticket locally:', error);
|
||||||
}
|
}
|
||||||
// try {
|
|
||||||
// localStorage.setItem('localTickets', JSON.stringify([payload]));
|
try {
|
||||||
// console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
|
localStorage.setItem('localTicketsnew', JSON.stringify([payload]));
|
||||||
// } catch (error) {
|
console.log('📦 [DEBUG] Latest ticket stored in localStorage (previous cleared).');
|
||||||
// console.error('❌ Failed to store ticket locally:', error);
|
} catch (error) {
|
||||||
// }
|
console.error('❌ Failed to store ticket locally:', error);
|
||||||
|
}
|
||||||
|
|
||||||
fetch('http://192.168.1.12:8083/api/tickets', {
|
fetch('http://192.168.1.12:8083/api/tickets', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user