82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { Bill } from './bill';
|
|
import { BillsDataSource } from './bills-datasource';
|
|
import { BillService } from '../bill.service';
|
|
import { QuantityComponent } from '../quantity/quantity.component';
|
|
import { MatDialog } from '@angular/material';
|
|
|
|
@Component({
|
|
selector: 'app-bills',
|
|
templateUrl: './bills.component.html',
|
|
styleUrls: ['./bills.component.css']
|
|
})
|
|
export class BillsComponent implements OnInit {
|
|
dataSource: BillsDataSource;
|
|
item: Bill;
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns: string[] = ['info', 'quantity'];
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private dialog: MatDialog,
|
|
private bs: BillService
|
|
) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data
|
|
.subscribe((data: { item: Bill }) => {
|
|
this.item = data.item;
|
|
this.bs.loadData(data.item);
|
|
});
|
|
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
|
}
|
|
|
|
addOne(item: any): void {
|
|
this.bs.addOne(item);
|
|
}
|
|
|
|
quantity(item: any): void {
|
|
const dialogRef = this.dialog.open(QuantityComponent, {
|
|
// width: '750px',
|
|
data: item.quantity
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe((result: boolean | number) => {
|
|
if (!result) {
|
|
return;
|
|
}
|
|
this.bs.quantity(item, result as number);
|
|
});
|
|
}
|
|
|
|
subtractOne(item: any): void {
|
|
this.bs.subtractOne(item);
|
|
}
|
|
|
|
removeItem(item: any): void {
|
|
this.bs.removeItem(item);
|
|
}
|
|
|
|
modifier(item: any): void {
|
|
this.bs.modifier(item);
|
|
}
|
|
|
|
netAmount(): number {
|
|
return this.bs.netAmount();
|
|
}
|
|
|
|
discountAmount(): number {
|
|
return this.bs.discountAmount();
|
|
}
|
|
|
|
taxAmount(): number {
|
|
return this.bs.taxAmount();
|
|
}
|
|
|
|
amount(): number {
|
|
return this.bs.amount();
|
|
}
|
|
}
|