fix : added repeat function
This commit is contained in:
parent
ba2af136ca
commit
c18efeddcf
@ -54,10 +54,10 @@
|
||||
>
|
||||
<table class="table borderless-custom w-100 mb-2 table-main">
|
||||
<colgroup>
|
||||
<col style="width: 12%" /> <!-- Label column -->
|
||||
<col style="width: 60%" /> <!-- Numbers column -->
|
||||
<col style="width: 10%" /> <!-- Value column -->
|
||||
<col style="width: 18%" /> <!-- Total column -->
|
||||
<col style="width: 12%" />
|
||||
<col style="width: 60%" />
|
||||
<col style="width: 10%" />
|
||||
<col style="width: 18%" />
|
||||
</colgroup>
|
||||
<tbody>
|
||||
<tr *ngFor="let row of filledRows">
|
||||
@ -69,7 +69,12 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="buttons-custom d-flex justify-content-between align-items-center">
|
||||
<button class="btn btn-dark">Repeat</button>
|
||||
<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 class="btn btn-danger ms-2" (click)="erase()">Erase</button> -->
|
||||
</div>
|
||||
<div class="fw-bold fs-5">Amount : ₹ {{ grandTotal }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Component, Input, OnInit, OnDestroy, Output, EventEmitter } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { SelectionService, SelectionData } from '../selection.service/selection.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
@ -12,11 +12,17 @@ import { Subscription } from 'rxjs';
|
||||
})
|
||||
export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
@Input() containerHeight: string = '50vh';
|
||||
@Input() eraseTrigger: any;
|
||||
summaryRows = Array.from({ length: 4 });
|
||||
|
||||
filledRows: SelectionData[] = [];
|
||||
currentRow: SelectionData = { label: '', numbers: [], value: 0, total: 0 };
|
||||
grandTotal: number = 0;
|
||||
showConfirmButton: boolean = false;
|
||||
lastTicket: any = null;
|
||||
showRepeatTicket: boolean = false;
|
||||
confirmRepeat: boolean = false;
|
||||
showPrintButton: boolean = false;
|
||||
|
||||
private selections: SelectionData[] = [];
|
||||
private sub1!: Subscription;
|
||||
@ -36,6 +42,12 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
ngOnChanges(changes: any) {
|
||||
if (changes.eraseTrigger && changes.eraseTrigger.currentValue) {
|
||||
this.erase();
|
||||
}
|
||||
}
|
||||
|
||||
updateFilledRows(saved: SelectionData[], current: SelectionData) {
|
||||
const rows: SelectionData[] = [...saved];
|
||||
if (rows.length < 5 && current.label) rows.push(current); // Include current row if label is selected
|
||||
@ -56,6 +68,76 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
this.grandTotal = this.filledRows.reduce((sum, row) => sum + (row.total || 0), 0);
|
||||
}
|
||||
|
||||
repeat() {
|
||||
try {
|
||||
const storedTickets = localStorage.getItem('localTickets');
|
||||
if (storedTickets) {
|
||||
const tickets = JSON.parse(storedTickets);
|
||||
const latestTicket = Array.isArray(tickets)
|
||||
? (tickets.length > 0 ? tickets[tickets.length - 1] : null)
|
||||
: tickets;
|
||||
|
||||
if (latestTicket && latestTicket.winLabels) {
|
||||
const parsedRows = this.parseWinLabelsToRows(latestTicket.winLabels);
|
||||
|
||||
// ✅ Always make sure we have exactly 5 rows
|
||||
this.updateFilledRows(parsedRows, { label: '', numbers: [], value: 0, total: 0 });
|
||||
|
||||
this.showConfirmButton = true;
|
||||
this.showPrintButton = false;
|
||||
this.lastTicket = latestTicket;
|
||||
} else {
|
||||
console.warn('⚠️ No valid ticket data found in localStorage.');
|
||||
}
|
||||
} else {
|
||||
console.warn('⚠️ No tickets found in localStorage.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to load ticket from localStorage:', error);
|
||||
}
|
||||
}
|
||||
|
||||
parseWinLabelsToRows(winLabels: string): SelectionData[] {
|
||||
// Each line: `${label.padEnd(10)}${numbers.padEnd(15)} *${value} Rs${total}`
|
||||
return (winLabels.split('\n') as string[])
|
||||
.map(line => {
|
||||
const match = line.match(/^(.{10})(.{15}) *\*([\d.]+) *Rs ?(\d+)/);
|
||||
if (!match) return null;
|
||||
return {
|
||||
label: match[1].trim(),
|
||||
numbers: match[2].trim().split(',').map(s => s.trim()).filter(s => s.length > 0),
|
||||
value: Number(match[3]),
|
||||
total: Number(match[4]),
|
||||
isBoxed: match[2].trim().startsWith('#')
|
||||
};
|
||||
})
|
||||
.filter(Boolean) as SelectionData[];
|
||||
}
|
||||
|
||||
confirm() {
|
||||
this.showPrintButton = true; // Show Print button after confirming
|
||||
console.log('✅ [DEBUG] Ticket confirmed.');
|
||||
}
|
||||
|
||||
print() {
|
||||
console.log('🖨️ [DEBUG] Printing ticket...');
|
||||
// Add your print logic here (e.g., window.print() or a custom print service)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.sub1.unsubscribe();
|
||||
this.sub2.unsubscribe();
|
||||
|
||||
@ -217,7 +217,7 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy {
|
||||
if (['FOR', 'QUI', 'TAN'].includes(label) && this.isBoxed) {
|
||||
return false;
|
||||
}
|
||||
const specialLabels = ['FOR', 'QUI', 'TAN', 'EXA', 'WSP', 'TRE', 'MJP', 'JKP', '.'];
|
||||
const specialLabels = ['FOR', 'QUI', 'TAN', 'EXA', 'TRE', 'MJP', 'JKP', '.'];
|
||||
return specialLabels.includes(label);
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ export class TouchPadMenuComponent implements OnInit, OnDestroy {
|
||||
|
||||
get isBoxToggleDisabled(): boolean {
|
||||
if (!this.selectedLabel) return true;
|
||||
const disallowedBoxLabels = ['WIN', 'SHP', 'THP', 'PLC', 'SHW', 'TRE', 'MJP', 'JKP'];
|
||||
const disallowedBoxLabels = ['WIN', 'SHP', 'THP', 'PLC', 'WSP','SHW', 'TRE', 'MJP', 'JKP'];
|
||||
if (disallowedBoxLabels.includes(this.selectedLabel)) {
|
||||
return true;
|
||||
}
|
||||
@ -936,7 +936,8 @@ const winLabels = allRows.map(row => {
|
||||
const label = row.label.padEnd(10);
|
||||
const numbers = numbersStr.padEnd(15);
|
||||
const value = (`*${row.value || 0}`).padEnd(8);
|
||||
return `${label}${numbers} ${value}`;
|
||||
const total = `Rs ${row.total || 0}`.padStart(8);
|
||||
return `${label}${numbers} ${value} ${total}`;
|
||||
}).join('\n');
|
||||
|
||||
|
||||
@ -985,6 +986,25 @@ const winLabels = allRows.map(row => {
|
||||
})
|
||||
|
||||
// ---------------------sending data to backend ---------------------------------
|
||||
|
||||
// try {
|
||||
// const existingTicketsStr = localStorage.getItem('localTickets');
|
||||
// const existingTickets = existingTicketsStr ? JSON.parse(existingTicketsStr) : [];
|
||||
|
||||
// existingTickets.push(payload);
|
||||
|
||||
// localStorage.setItem('localTickets', JSON.stringify(existingTickets));
|
||||
|
||||
// console.log('📦 [DEBUG] Ticket saved locally to localStorage.');
|
||||
// } 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);
|
||||
}
|
||||
fetch('http://192.168.1.12:8083/api/tickets', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user