feat : added total amont (shows) at end
This commit is contained in:
parent
b6f9827c83
commit
6d9be9c8e4
@ -57,10 +57,11 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="buttons-custom">
|
||||
<div class="buttons-custom d-flex justify-content-between align-items-center">
|
||||
<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>
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
|
||||
filledRows: SelectionData[] = [];
|
||||
currentRow: SelectionData = { label: '', numbers: [], value: 0, total: 0 };
|
||||
grandTotal: number = 0;
|
||||
|
||||
private selections: SelectionData[] = [];
|
||||
private sub1!: Subscription;
|
||||
@ -24,13 +25,11 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
constructor(private selectionService: SelectionService) {}
|
||||
|
||||
ngOnInit() {
|
||||
// Subscription for finalized selections
|
||||
this.sub1 = this.selectionService.selections$.subscribe(data => {
|
||||
this.selections = data;
|
||||
this.updateFilledRows(this.selections, this.currentRow);
|
||||
});
|
||||
|
||||
// Subscription for current in-progress row
|
||||
this.sub2 = this.selectionService.currentRow$.subscribe(row => {
|
||||
this.currentRow = row;
|
||||
this.updateFilledRows(this.selections, row);
|
||||
@ -39,7 +38,7 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
|
||||
updateFilledRows(saved: SelectionData[], current: SelectionData) {
|
||||
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 emptyRows = Array.from({ length: emptyCount }, () => ({
|
||||
@ -50,6 +49,11 @@ export class MiddleSectionComponent implements OnInit, OnDestroy {
|
||||
}));
|
||||
|
||||
this.filledRows = [...rows, ...emptyRows].slice(0, 5);
|
||||
this.calculateTotal();
|
||||
}
|
||||
|
||||
calculateTotal() {
|
||||
this.grandTotal = this.filledRows.reduce((sum, row) => sum + (row.total || 0), 0);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user