gdfasg
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { SelectionModel } from '@angular/cdk/collections';
|
import { SelectionModel } from '@angular/cdk/collections';
|
||||||
import { Injectable, inject } from '@angular/core';
|
import { Injectable, inject, signal, computed } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
import { BehaviorSubject, throwError, Observable } from 'rxjs';
|
import { throwError, Observable } from 'rxjs';
|
||||||
import { map, tap } from 'rxjs/operators';
|
import { tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { ModifierCategory } from '../core/modifier-category';
|
import { ModifierCategory } from '../core/modifier-category';
|
||||||
import { ProductQuery } from '../core/product-query';
|
import { ProductQuery } from '../core/product-query';
|
||||||
@@ -30,60 +30,37 @@ export class BillService {
|
|||||||
private ser = inject(VoucherService);
|
private ser = inject(VoucherService);
|
||||||
private modifierCategoryService = inject(ModifierCategoryService);
|
private modifierCategoryService = inject(ModifierCategoryService);
|
||||||
|
|
||||||
public dataObs: BehaviorSubject<Kot[]>;
|
public data = signal<Kot[]>([]);
|
||||||
public bill: Bill = new Bill();
|
public bill: Bill = new Bill();
|
||||||
private originalBill: Bill = new Bill();
|
private originalBill: Bill = new Bill();
|
||||||
public grossAmount: Observable<number>;
|
|
||||||
public discountAmount: Observable<number>;
|
|
||||||
public hhAmount: Observable<number>;
|
|
||||||
public taxAmount: Observable<number>;
|
|
||||||
public amount: BehaviorSubject<number>;
|
|
||||||
public selection = new SelectionModel<string>(true, []);
|
|
||||||
private updateTable: boolean;
|
|
||||||
private allowDeactivate: boolean;
|
|
||||||
|
|
||||||
// To disable Deactivate Guard on navigation after printing bill or kot.
|
public grossAmount = computed(() =>
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.dataObs = new BehaviorSubject<Kot[]>([]);
|
|
||||||
this.updateTable = true;
|
|
||||||
this.allowDeactivate = false;
|
|
||||||
|
|
||||||
this.grossAmount = this.dataObs.pipe(
|
|
||||||
map((kots: Kot[]) =>
|
|
||||||
this.math.halfRoundEven(
|
this.math.halfRoundEven(
|
||||||
kots.reduce((t, k) => k.inventories.reduce((a, c) => a + c.price * c.quantity, 0) + t, 0),
|
this.data().reduce((t, k) => k.inventories.reduce((a, c) => a + c.price * c.quantity, 0) + t, 0),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.hhAmount = this.dataObs.pipe(
|
public hhAmount = computed(() =>
|
||||||
map((kots: Kot[]) => {
|
this.math.halfRoundEven(
|
||||||
return this.math.halfRoundEven(
|
this.data().reduce(
|
||||||
kots.reduce(
|
|
||||||
(t, k) => k.inventories.reduce((a, c) => a + (c.isHappyHour ? c.price : 0) * c.quantity, 0) + t,
|
(t, k) => k.inventories.reduce((a, c) => a + (c.isHappyHour ? c.price : 0) * c.quantity, 0) + t,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.discountAmount = this.dataObs.pipe(
|
|
||||||
map((kots: Kot[]) => {
|
|
||||||
return this.math.halfRoundEven(
|
|
||||||
kots.reduce(
|
|
||||||
(t, k) =>
|
|
||||||
k.inventories.reduce((a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * c.discount, 0) + t,
|
|
||||||
0,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
|
||||||
|
public discountAmount = computed(() =>
|
||||||
|
this.math.halfRoundEven(
|
||||||
|
this.data().reduce(
|
||||||
|
(t, k) => k.inventories.reduce((a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * c.discount, 0) + t,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.taxAmount = this.dataObs.pipe(
|
public taxAmount = computed(() =>
|
||||||
map((kots: Kot[]) => {
|
this.math.halfRoundEven(
|
||||||
return this.math.halfRoundEven(
|
this.data().reduce(
|
||||||
kots.reduce(
|
|
||||||
(t, k) =>
|
(t, k) =>
|
||||||
k.inventories.reduce(
|
k.inventories.reduce(
|
||||||
(a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * c.taxRate,
|
(a, c) => a + (c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * c.taxRate,
|
||||||
@@ -91,37 +68,24 @@ export class BillService {
|
|||||||
) + t,
|
) + t,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.amount = new BehaviorSubject<number>(0);
|
public amount = computed(() => this.grossAmount() - this.discountAmount() + this.taxAmount());
|
||||||
this.dataObs
|
public selection = new SelectionModel<string>(true, []);
|
||||||
.pipe(
|
private updateTable: boolean;
|
||||||
map((kots: Kot[]) => {
|
private allowDeactivate: boolean;
|
||||||
return this.math.halfRoundEven(
|
|
||||||
kots.reduce(
|
// To disable Deactivate Guard on navigation after printing bill or kot.
|
||||||
(t, k) =>
|
|
||||||
k.inventories.reduce(
|
constructor() {
|
||||||
(a, c) =>
|
this.updateTable = true;
|
||||||
a +
|
this.allowDeactivate = false;
|
||||||
this.math.halfRoundEven(
|
|
||||||
(c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * (1 + c.taxRate),
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
0,
|
|
||||||
) + t,
|
|
||||||
0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.subscribe((value) => this.amount.next(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
displayBill(): void {
|
displayBill(): void {
|
||||||
this.allowDeactivate = false;
|
this.allowDeactivate = false;
|
||||||
this.dataObs.next(this.bill.kots);
|
this.data.set([...this.bill.kots]);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData(bill: Bill, updateTable: boolean): void {
|
loadData(bill: Bill, updateTable: boolean): void {
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
import { DataSource } from '@angular/cdk/collections';
|
|
||||||
import { map, Observable, tap } from 'rxjs';
|
|
||||||
|
|
||||||
import { BillRow } from './bill-row';
|
|
||||||
import { Kot } from './kot';
|
|
||||||
|
|
||||||
export class BillsDataSource extends DataSource<BillRow> {
|
|
||||||
private data: Kot[] = [];
|
|
||||||
constructor(private readonly dataObs: Observable<Kot[]>) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(): Observable<BillRow[]> {
|
|
||||||
return this.dataObs.pipe(
|
|
||||||
tap((x) => {
|
|
||||||
this.data = x;
|
|
||||||
}),
|
|
||||||
map((d) =>
|
|
||||||
d.flatMap((k) => {
|
|
||||||
const kotRow: BillRow = new BillRow({ kind: 'kot', kot: k, id: k.id! });
|
|
||||||
const rows: BillRow[] = [];
|
|
||||||
for (const inv of k.inventories) {
|
|
||||||
if (!inv.id) {
|
|
||||||
inv.clientId = inv.clientId || crypto.randomUUID();
|
|
||||||
}
|
|
||||||
rows.push(new BillRow({ kind: 'inv', kot: k, inv, id: `${k.id}-${inv.id || inv.clientId}` }));
|
|
||||||
if (inv.type === 'bundle') {
|
|
||||||
for (const child of inv.children) {
|
|
||||||
if (!child.id) {
|
|
||||||
child.clientId = child.clientId || crypto.randomUUID();
|
|
||||||
}
|
|
||||||
child.parentId = inv.id || inv.clientId;
|
|
||||||
rows.push(
|
|
||||||
new BillRow({
|
|
||||||
kind: 'child',
|
|
||||||
kot: k,
|
|
||||||
parent: inv,
|
|
||||||
inv: child,
|
|
||||||
id: `${k.id}-${child.id || child.clientId}`,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [kotRow, ...rows];
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect() {}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<h2>Bill</h2>
|
<h2>Bill</h2>
|
||||||
<table mat-table #table [dataSource]="dataSource" class="mat-elevation-z8" [trackBy]="trackByRow">
|
<table mat-table #table [dataSource]="dataSource()" class="mat-elevation-z8" [trackBy]="trackByRow">
|
||||||
<ng-container matColumnDef="bill-no-title">
|
<ng-container matColumnDef="bill-no-title">
|
||||||
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold">Bill / KOT number</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold">Bill / KOT number</mat-header-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="gross-amount">
|
<ng-container matColumnDef="gross-amount">
|
||||||
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
||||||
bs.grossAmount | async | currency: 'INR'
|
bs.grossAmount() | currency: 'INR'
|
||||||
}}</mat-footer-cell>
|
}}</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
@@ -174,9 +174,7 @@
|
|||||||
<mat-footer-cell *matFooterCellDef class="bold">Happy Hour Discount</mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef class="bold">Happy Hour Discount</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="hh-amount">
|
<ng-container matColumnDef="hh-amount">
|
||||||
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
<mat-footer-cell *matFooterCellDef class="bold right-align">{{ bs.hhAmount() | currency: 'INR' }}</mat-footer-cell>
|
||||||
bs.hhAmount | async | currency: 'INR'
|
|
||||||
}}</mat-footer-cell>
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<mat-footer-row *matFooterRowDef="['discount-title', 'discount-amount']"></mat-footer-row>
|
<mat-footer-row *matFooterRowDef="['discount-title', 'discount-amount']"></mat-footer-row>
|
||||||
@@ -185,7 +183,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="discount-amount">
|
<ng-container matColumnDef="discount-amount">
|
||||||
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
||||||
bs.discountAmount | async | currency: 'INR'
|
bs.discountAmount() | currency: 'INR'
|
||||||
}}</mat-footer-cell>
|
}}</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
@@ -194,9 +192,7 @@
|
|||||||
<mat-footer-cell *matFooterCellDef class="bold">Tax</mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef class="bold">Tax</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="tax-amount">
|
<ng-container matColumnDef="tax-amount">
|
||||||
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
<mat-footer-cell *matFooterCellDef class="bold right-align">{{ bs.taxAmount() | currency: 'INR' }}</mat-footer-cell>
|
||||||
bs.taxAmount | async | currency: 'INR'
|
|
||||||
}}</mat-footer-cell>
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<mat-footer-row *matFooterRowDef="['amount-title', 'amount-amount']"></mat-footer-row>
|
<mat-footer-row *matFooterRowDef="['amount-title', 'amount-amount']"></mat-footer-row>
|
||||||
@@ -204,9 +200,7 @@
|
|||||||
<mat-footer-cell *matFooterCellDef>Amount</mat-footer-cell>
|
<mat-footer-cell *matFooterCellDef>Amount</mat-footer-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container matColumnDef="amount-amount">
|
<ng-container matColumnDef="amount-amount">
|
||||||
<mat-footer-cell *matFooterCellDef class="bold right-align">{{
|
<mat-footer-cell *matFooterCellDef class="bold right-align">{{ bs.amount() | currency: 'INR' }}</mat-footer-cell>
|
||||||
bs.amount | async | currency: 'INR'
|
|
||||||
}}</mat-footer-cell>
|
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import { QuantityComponent } from '../quantity/quantity.component';
|
|||||||
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
|
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
|
||||||
import { Bill } from './bill';
|
import { Bill } from './bill';
|
||||||
import { BillRow } from './bill-row';
|
import { BillRow } from './bill-row';
|
||||||
import { BillsDataSource } from './bills-datasource';
|
|
||||||
import { Inventory } from './inventory';
|
import { Inventory } from './inventory';
|
||||||
import { Kot } from './kot';
|
import { Kot } from './kot';
|
||||||
import { VoucherType } from './voucher-type';
|
import { VoucherType } from './voucher-type';
|
||||||
@@ -63,7 +62,36 @@ export class BillsComponent implements OnInit {
|
|||||||
|
|
||||||
updateTable = computed(() => this.bill() !== null && this.voucher() !== null);
|
updateTable = computed(() => this.bill() !== null && this.voucher() !== null);
|
||||||
|
|
||||||
dataSource: BillsDataSource = new BillsDataSource(this.bs.dataObs);
|
dataSource = computed(() => {
|
||||||
|
return this.bs.data().flatMap((k) => {
|
||||||
|
const kotRow: BillRow = new BillRow({ kind: 'kot', kot: k, id: k.id! });
|
||||||
|
const rows: BillRow[] = [];
|
||||||
|
for (const inv of k.inventories) {
|
||||||
|
if (!inv.id) {
|
||||||
|
inv.clientId = inv.clientId || crypto.randomUUID();
|
||||||
|
}
|
||||||
|
rows.push(new BillRow({ kind: 'inv', kot: k, inv, id: `${k.id}-${inv.id || inv.clientId}` }));
|
||||||
|
if (inv.type === 'bundle') {
|
||||||
|
for (const child of inv.children) {
|
||||||
|
if (!child.id) {
|
||||||
|
child.clientId = child.clientId || crypto.randomUUID();
|
||||||
|
}
|
||||||
|
child.parentId = inv.id || inv.clientId;
|
||||||
|
rows.push(
|
||||||
|
new BillRow({
|
||||||
|
kind: 'child',
|
||||||
|
kot: k,
|
||||||
|
parent: inv,
|
||||||
|
inv: child,
|
||||||
|
id: `${k.id}-${child.id || child.clientId}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [kotRow, ...rows];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
billResource = this.voucherService.getFromBill(this.bill);
|
billResource = this.voucherService.getFromBill(this.bill);
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ export class SalesHomeComponent {
|
|||||||
if (!this.receivePaymentAllowed()) {
|
if (!this.receivePaymentAllowed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const amount = this.bs.amount.value;
|
const amount = this.bs.amount();
|
||||||
const type = this.bs.bill.voucherType;
|
const type = this.bs.bill.voucherType;
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(ReceivePaymentComponent, {
|
.open(ReceivePaymentComponent, {
|
||||||
|
|||||||
Reference in New Issue
Block a user