diff --git a/btc-UI/src/app/components/middle-section/middle-section.component.html b/btc-UI/src/app/components/middle-section/middle-section.component.html
index 7e67d69..adc2e86 100755
--- a/btc-UI/src/app/components/middle-section/middle-section.component.html
+++ b/btc-UI/src/app/components/middle-section/middle-section.component.html
@@ -20,25 +20,30 @@
+
| Sales |
- |
- |
+ {{ totalClicks }} |
+
+
+ {{ showSalesTotal ? salesTotal : '' }}
+ |
+
| Cancel |
- |
- |
+ 0 |
+ 0 |
| Payout |
- |
- |
+ 0 |
+ 0 |
| Receive |
- |
- |
+ {{ totalClicks }} |
+ {{ salesTotal }} |
diff --git a/btc-UI/src/app/components/middle-section/middle-section.component.ts b/btc-UI/src/app/components/middle-section/middle-section.component.ts
index 6d6eecb..73ae830 100755
--- a/btc-UI/src/app/components/middle-section/middle-section.component.ts
+++ b/btc-UI/src/app/components/middle-section/middle-section.component.ts
@@ -18,6 +18,9 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
filledRows: SelectionData[] = [];
currentRow: SelectionData = { label: '', numbers: [], value: 0, total: 0 };
grandTotal: number = 0;
+ salesTotal: number = 0;
+ receiveTotal: number = 0;
+ totalClicks: number = 0;
showConfirmButton: boolean = false;
lastTicket: any = null;
showRepeatTicket: boolean = false;
@@ -63,11 +66,32 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
this.filledRows = [...rows, ...emptyRows].slice(0, 5);
this.calculateTotal();
}
+ showSalesTotal: boolean = false;
calculateTotal() {
- this.grandTotal = this.filledRows.reduce((sum, row) => sum + (row.total || 0), 0);
+ this.grandTotal = this.filledRows.reduce((sum, row) => sum + (row.total || 0), 0);
+
+ let storedTotal = 0;
+ try {
+ const storedTickets = JSON.parse(localStorage.getItem('localTickets') || '[]');
+ if (Array.isArray(storedTickets)) {
+ storedTotal = storedTickets
+ .filter(ticket => ticket.type === 'ticket')
+ .reduce((sum: number, ticket: any) => sum + (ticket.totalAmount || 0), 0);
+ }
+ } catch (e) {
+ console.error('โ Failed to parse localTickets from localStorage:', e);
}
+ this.salesTotal = this.grandTotal + storedTotal;
+ this.receiveTotal = this.salesTotal;
+ this.totalClicks = Number(localStorage.getItem('printClickCount') || '0');
+
+ // ๐ Toggle visibility based on localStorage flag
+ this.showSalesTotal = localStorage.getItem('hasPrinted') === 'true';
+}
+
+
repeat() {
try {
const storedTickets = localStorage.getItem('localTickets');
diff --git a/btc-UI/src/app/components/sidebar/sidebar.component.ts b/btc-UI/src/app/components/sidebar/sidebar.component.ts
index b9596dd..6321d4e 100755
--- a/btc-UI/src/app/components/sidebar/sidebar.component.ts
+++ b/btc-UI/src/app/components/sidebar/sidebar.component.ts
@@ -68,6 +68,7 @@ export class SidebarComponent {
//--------------------Printer Logic added here ----------------------------------------------
+//---------------------------------Print Payout Ticket --------------------------------------------------------
printPayoutTicket() {
@@ -129,10 +130,64 @@ printPayoutTicket() {
this.depositAmount = '';
}
- printDeposit() {
- alert(`Deposit: โน${this.depositAmount}`);
- this.closeDepositPopup();
- }
+//----------------------------Print Deposit ticket -------------------------------------------------------
+
+printDeposit() {
+ const userName = localStorage.getItem('userName') || 'Unknown';
+
+ const receiptText = `
+==============================
+ ๐ฐ DEPOSIT RECEIPT
+==============================
+Operator ID : ${this.depositOperatorId}
+Shroff ID : ${this.depositShroffId}
+Amount : โน${this.depositAmount}
+Printed By : ${userName}
+Date : ${new Date().toLocaleString()}
+==============================
+
+๐งพ Denomination Voucher
+1000 x _____________ = _____________
+500 x _____________ = _____________
+100 x _____________ = _____________
+50 x _____________ = _____________
+20 x _____________ = _____________
+10 x _____________ = _____________
+5 x _____________ = _____________
+
+==============================
+`;
+
+ // โ
Send to print server
+ const payload = {
+ type: 'deposit',
+ printedBy: userName,
+ operatorId: this.depositOperatorId,
+ shroffId: this.depositShroffId,
+ amount: this.depositAmount,
+ content: receiptText // ๐งพ Include formatted text
+ };
+
+ 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("โ
Deposit print successful:", result);
+ })
+ .catch(error => {
+ console.error("โ Deposit print failed:", error);
+ });
+
+ this.closeDepositPopup();
+}
+
+//-----------------------------------------------------------------------------------------------------------------
openWithdrawPopup() {
this.withdrawClick.emit();
@@ -146,10 +201,67 @@ printPayoutTicket() {
this.withdrawAmount = '';
}
+ // printWithdraw() {
+ // alert(`Withdraw: โน${this.withdrawAmount}`);
+ // this.closeWithdrawPopup();
+ // }
+
+
printWithdraw() {
- alert(`Withdraw: โน${this.withdrawAmount}`);
- this.closeWithdrawPopup();
- }
+ const userName = localStorage.getItem('userName') || 'Unknown';
+
+ const receiptText = `
+==============================
+ ๐ธ WITHDRAW RECEIPT
+==============================
+Operator ID : ${this.withdrawOperatorId}
+Shroff ID : ${this.withdrawShroffId}
+Amount : โน${this.withdrawAmount}
+Printed By : ${userName}
+Date : ${new Date().toLocaleString()}
+==============================
+
+๐งพ Denomination Voucher
+1000 x _____________ = _____________
+500 x _____________ = _____________
+100 x _____________ = _____________
+50 x _____________ = _____________
+20 x _____________ = _____________
+10 x _____________ = _____________
+5 x _____________ = _____________
+
+==============================
+`;
+
+ const payload = {
+ type: 'withdraw',
+ printedBy: userName,
+ operatorId: this.withdrawOperatorId,
+ shroffId: this.withdrawShroffId,
+ amount: this.withdrawAmount,
+ content: receiptText
+ };
+
+ 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("โ
Withdraw print successful:", result);
+ })
+ .catch(error => {
+ console.error("โ Withdraw print failed:", error);
+ });
+
+ this.closeWithdrawPopup();
+}
+
+
raceCardData: any = null; // โ
Hold fetched data
diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html
index 6b238f0..eacdc1a 100755
--- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html
+++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html
@@ -6,7 +6,7 @@
-
+
diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts
index f7409c3..22e0496 100755
--- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts
+++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts
@@ -795,9 +795,21 @@ getHorseNumbersForRaceIdx(raceIdx: number): number[] {
return [];
}
}
+clearLocalTickets() {
+ localStorage.removeItem('localTickets');
+ console.log('๐งน localTickets cleared from localStorage');
+ // Clear the print count
+ localStorage.removeItem('printClickCount');
+ console.log('๐งผ printClickCount cleared from localStorage');
+ // Reset via shared state
+ this.sharedStateService.setSalesTotal(0);
+ this.sharedStateService.setReceiveTotal(0);
+ window.location.reload();
-
+ // Optionally clear print clicks
+ // localStorage.removeItem('printClickCount');
+}
//-------------------PRINT LOGIC----------------------------------------
@@ -817,6 +829,12 @@ printTicket() {
let allRows = [...selections];
+ // โ
Just count clicks โ update click count in localStorage
+ let clickCount = Number(localStorage.getItem('printClickCount') || '0');
+ clickCount += 1;
+ localStorage.setItem('printClickCount', clickCount.toString());
+
+
// โ
Calculate total if currentRow is valid and not already finalized
if (currentRow.label && currentRow.numbers.length > 0 && currentRow.value > 0) {
if (!currentRow.total) {
@@ -987,24 +1005,24 @@ const winLabels = allRows.map(row => {
// ---------------------sending data to backend ---------------------------------
-// try {
-// const existingTicketsStr = localStorage.getItem('localTickets');
-// const existingTickets = existingTicketsStr ? JSON.parse(existingTicketsStr) : [];
+ try {
+ const existingTicketsStr = localStorage.getItem('localTickets');
+ const existingTickets = existingTicketsStr ? JSON.parse(existingTicketsStr) : [];
-// existingTickets.push(payload);
+ existingTickets.push(payload);
-// localStorage.setItem('localTickets', JSON.stringify(existingTickets));
+ 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).');
+ 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' },
@@ -1037,14 +1055,15 @@ try {
}
//----------------------------------PRINT ENDS HERE ------------------------------------------------------
-
-
-
-
erase() {
this.selectionService.clearSelections();
this.resetSelections();
}
+ eraseAndReload() {
+ this.erase();
+ window.location.reload();
+}
+
resetSelections() {
this.selectedLabel = null;
diff --git a/btc-UI/src/app/service/shared-state.service.ts b/btc-UI/src/app/service/shared-state.service.ts
index 077aec3..fa2b087 100644
--- a/btc-UI/src/app/service/shared-state.service.ts
+++ b/btc-UI/src/app/service/shared-state.service.ts
@@ -52,4 +52,21 @@ export class SharedStateService {
getSelectedRace(): number {
return this.selectedRaceSubject.value;
}
+
+
+ private salesTotalSubject = new BehaviorSubject(0);
+salesTotal$ = this.salesTotalSubject.asObservable();
+
+private receiveTotalSubject = new BehaviorSubject(0);
+receiveTotal$ = this.receiveTotalSubject.asObservable();
+
+// Methods to update
+setSalesTotal(total: number) {
+ this.salesTotalSubject.next(total);
+}
+
+setReceiveTotal(total: number) {
+ this.receiveTotalSubject.next(total);
+}
+
}
\ No newline at end of file