Bills initially working just as proof of concept
ng linted modifier categories list is better at displaying data sanely now
This commit is contained in:
84
bookie/src/app/sales/bill.service.ts
Normal file
84
bookie/src/app/sales/bill.service.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Product } from '../core/product';
|
||||
import { ModifiersComponent } from './modifiers/modifiers.component';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { ModifierCategoryService } from '../modifier-categories/modifier-category.service';
|
||||
import {Subject} from "rxjs";
|
||||
import {Modifier} from "../core/modifier";
|
||||
import {ModifierCategory} from "../core/modifier-category";
|
||||
import {isNotNullOrUndefined} from "codelyzer/util/isNotNullOrUndefined";
|
||||
|
||||
@Injectable()
|
||||
export class BillService {
|
||||
public dataObs = new Subject<any[]>();
|
||||
public data = [];
|
||||
constructor(
|
||||
private dialog: MatDialog,
|
||||
private modifierCategoryService: ModifierCategoryService
|
||||
) { }
|
||||
|
||||
addProduct(product: Product) {
|
||||
let item = {
|
||||
isKot: false,
|
||||
product: product,
|
||||
productId: product.id,
|
||||
info: `${product.name} (${product.units}) @ ${product.price}`,
|
||||
quantity: 1,
|
||||
modifiers: []
|
||||
};
|
||||
this.data.push(item);
|
||||
this.modifierCategoryService.listIsActiveOfProduct(product.id).subscribe(result => {
|
||||
if (result.reduce((a: any, c: ModifierCategory) => {return a + c.minimum}, 0)) {
|
||||
this.showModifier(item);
|
||||
}
|
||||
});
|
||||
this.dataObs.next(this.data);
|
||||
}
|
||||
|
||||
showModifier(item: any): void {
|
||||
// [routerLink]="['/sales', 'modifiers', item.id]"
|
||||
const dialogRef = this.dialog.open(ModifiersComponent, {
|
||||
position: {
|
||||
top: '10vh'
|
||||
},
|
||||
data: {
|
||||
list: this.modifierCategoryService.listIsActiveOfProduct(item.productId),
|
||||
selected: item.modifiers
|
||||
}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if (isNotNullOrUndefined(result)) {
|
||||
item.modifiers = result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addOne(item: any): void {
|
||||
item.quantity += 1;
|
||||
this.dataObs.next(this.data);
|
||||
}
|
||||
|
||||
quantity(item: any): void {
|
||||
|
||||
}
|
||||
|
||||
subtractOne(item: any): void {
|
||||
if (item.quantity > 1) {
|
||||
item.quantity -= 1;
|
||||
this.dataObs.next(this.data);
|
||||
} else if (item.quantity === 0) {
|
||||
this.removeItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
removeItem(item: any): void {
|
||||
this.data.splice(this.data.indexOf(item), 1);
|
||||
this.dataObs.next(this.data);
|
||||
}
|
||||
|
||||
modifier(item: any): void {
|
||||
this.showModifier(item);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user