feat : added total amont (shows) at end

This commit is contained in:
karthik 2025-07-26 14:43:46 +05:30
parent b6f9827c83
commit 6d9be9c8e4
2 changed files with 12 additions and 7 deletions

View File

@ -57,10 +57,11 @@
</tbody> </tbody>
</table> </table>
<div class="buttons-custom"> <div class="buttons-custom d-flex justify-content-between align-items-center">
<button class="btn btn-dark">Repeat</button> <button class="btn btn-dark">Repeat</button>
<div class="fw-bold">Amount :</div> <div class="fw-bold fs-5">Amount : ₹ {{ grandTotal }}</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -16,6 +16,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
filledRows: SelectionData[] = []; filledRows: SelectionData[] = [];
currentRow: SelectionData = { label: '', numbers: [], value: 0, total: 0 }; currentRow: SelectionData = { label: '', numbers: [], value: 0, total: 0 };
grandTotal: number = 0;
private selections: SelectionData[] = []; private selections: SelectionData[] = [];
private sub1!: Subscription; private sub1!: Subscription;
@ -24,13 +25,11 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
constructor(private selectionService: SelectionService) {} constructor(private selectionService: SelectionService) {}
ngOnInit() { ngOnInit() {
// Subscription for finalized selections
this.sub1 = this.selectionService.selections$.subscribe(data => { this.sub1 = this.selectionService.selections$.subscribe(data => {
this.selections = data; this.selections = data;
this.updateFilledRows(this.selections, this.currentRow); this.updateFilledRows(this.selections, this.currentRow);
}); });
// Subscription for current in-progress row
this.sub2 = this.selectionService.currentRow$.subscribe(row => { this.sub2 = this.selectionService.currentRow$.subscribe(row => {
this.currentRow = row; this.currentRow = row;
this.updateFilledRows(this.selections, row); this.updateFilledRows(this.selections, row);
@ -39,7 +38,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
updateFilledRows(saved: SelectionData[], current: SelectionData) { updateFilledRows(saved: SelectionData[], current: SelectionData) {
const rows: SelectionData[] = [...saved]; const rows: SelectionData[] = [...saved];
if (rows.length < 5) rows.push(current); if (rows.length < 5 && current.label) rows.push(current); // Include current row if label is selected
const emptyCount = Math.max(5 - rows.length, 0); const emptyCount = Math.max(5 - rows.length, 0);
const emptyRows = Array.from({ length: emptyCount }, () => ({ const emptyRows = Array.from({ length: emptyCount }, () => ({
@ -50,6 +49,11 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
})); }));
this.filledRows = [...rows, ...emptyRows].slice(0, 5); this.filledRows = [...rows, ...emptyRows].slice(0, 5);
this.calculateTotal();
}
calculateTotal() {
this.grandTotal = this.filledRows.reduce((sum, row) => sum + (row.total || 0), 0);
} }
ngOnDestroy() { ngOnDestroy() {