Fix: import script to fit the new structure of voucher table (is_printed field removed, voucher_type != KOT is now assumed to be printed)

Fix: Take-away bill type is now removed
Fix: Table overview now shows the right amounts
Voucher Save and Update should now work
Discounts now working (permissions are not checked)
This commit is contained in:
Amritanshu
2019-08-08 13:31:30 +05:30
parent 7d06a2f961
commit c81b92c336
24 changed files with 534 additions and 249 deletions

View File

@ -1,12 +1,15 @@
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material';
import { BehaviorSubject } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
import { Product } from '../core/product';
import { ModifiersComponent } from './modifiers/modifiers.component';
import { ModifierCategoryService } from '../modifier-categories/modifier-category.service';
import { ModifierCategory } from '../core/modifier-category';
import { Bill, Inventory, Kot, PrintType } from './bills/bill';
import {VoucherService} from './bills/voucher.service';
import { VoucherService } from './bills/voucher.service';
import { ToasterService } from "../core/toaster.service";
import { tap } from "rxjs/operators";
@Injectable()
export class BillService {
@ -16,6 +19,7 @@ export class BillService {
constructor(
private dialog: MatDialog,
private toaster: ToasterService,
private ser: VoucherService,
private modifierCategoryService: ModifierCategoryService
) {
@ -37,7 +41,8 @@ export class BillService {
productId: i.product.id,
isHappyHour: i.isHappyHour,
isPrinted: true,
info: `${i.product.name} (${i.product.units}) @ ${i.price}`,
info: `${i.product.name} (${i.product.units}) @ ${i.price} - ${i.discount * 100}%`,
price: i.price,
quantity: i.quantity,
discount: i.discount,
taxRate: i.taxRate,
@ -61,7 +66,7 @@ export class BillService {
product: product,
productId: product.id,
isHappyHour: product.hasHappyHour,
info: `${product.name} (${product.units}) @ ${product.price}`,
info: `${product.name} (${product.units}) @ ${product.price} - ${0}%`,
price: product.price,
quantity: 1,
discount: 0,
@ -128,8 +133,18 @@ export class BillService {
this.showModifier(item);
}
printKot(guest_book_id: string): void {
const nk = new Kot({
discount(discounts:{id: string, name: string, discount: number}[]): void {
this.data.forEach(x=> {
if (!x.isKot) {
x.discount = discounts.find(d => d.id === x.product.saleCategory.id).discount / 100;
x.info = `${x.product.name} (${x.product.units}) @ ${x.price} - ${x.discount * 100}%`;
}
});
this.dataObs.next(this.data);
}
private getKot(): Kot {
return new Kot({
inventories: this.data.filter(x => !x.isKot && !x.isPrinted).map(y => new Inventory({
product: y.product,
quantity: y.quantity,
@ -141,15 +156,32 @@ export class BillService {
tax: y.tax
}))
});
let item = JSON.parse(JSON.stringify(this.bill))
item.kots.push(nk);
this.ser.saveOrUpdate(item, PrintType.Kot, guest_book_id, true).subscribe(x =>
console.log(x)
}
printKot(guest_book_id: string): Observable<Bill> {
let item = JSON.parse(JSON.stringify(this.bill));
let newKot = this.getKot();
if (newKot.inventories.length == 0) {
this.toaster.show('Error', 'Cannot print a blank KOT\nPlease add some products!');
}
item.kots.push(newKot);
return this.ser.saveOrUpdate(item, PrintType.Kot, guest_book_id, true).pipe(
tap(x => console.log(x))
);
}
printBill(): boolean {
return false;
printBill(guest_book_id: string): Observable<Bill> {
let item = JSON.parse(JSON.stringify(this.bill));
item.kots.forEach(k => {
k.inventories.forEach(i => {
i.discount = this.data.find(x => !x.isKot && x.id === i.id).discount;
})
});
console.log(item);
item.kots.push(this.getKot());
return this.ser.saveOrUpdate(item, PrintType.Bill, guest_book_id, true).pipe(
tap(x => console.log(x))
);
}
}