Move / Merge KOT Done.

We need to check if it is the only kot and raise an error if it is.
Split Bill Done
This commit is contained in:
Amritanshu
2019-08-18 01:05:59 +05:30
parent dcaf23b390
commit e697631cd4
15 changed files with 539 additions and 295 deletions

View File

@ -11,6 +11,8 @@ const httpOptions = {
};
const url = '/v1/vouchers';
const urlMoveTable = '/v1/move-table';
const urlMoveKot = '/v1/move-kot';
const serviceName = 'VoucherService';
@Injectable({providedIn: 'root'})
@ -47,29 +49,29 @@ export class VoucherService {
);
}
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('p', printType).set('u', updateTable.toString())};
if (guest_book_id !== null) {
options.params = options.params.set('g', guest_book_id);
}
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, options)
return <Observable<boolean>>this.http.post<boolean>(`${url}/new`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('p', printType).set('u', updateTable.toString())};
if (guest_book_id !== null) {
options.params = options.params.set('g', guest_book_id);
}
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, options)
return <Observable<boolean>>this.http.put<boolean>(`${url}/${voucher.id}`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
if (!voucher.id) {
return this.save(voucher, printType, guest_book_id, updateTable);
} else {
@ -78,26 +80,75 @@ export class VoucherService {
}
receivePayment(id: string, amounts: { id: string; name: string; amount: number }[], updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('receive-payment', '').set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, amounts, options)
.pipe(
catchError(this.log.handleError(serviceName, 'receivePayment'))
);
}
moveTable(id: string, table: Table): Observable<boolean> {
const options = {params: new HttpParams().set('move-table', '')};
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {table: {id: table.id}}, options)
.pipe(
catchError(this.log.handleError(serviceName, 'moveTable'))
);
const options = {params: new HttpParams().set('receive-payment', '').set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(
`${url}/${id}`, amounts, options
).pipe(
catchError(this.log.handleError(serviceName, 'receivePayment'))
);
}
voidBill(id: string, reason: string, updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('void-bill', '').set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {reason: reason}, options)
.pipe(
catchError(this.log.handleError(serviceName, 'voidBill'))
);
const options = {params: new HttpParams().set('void-bill', '').set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(
`${url}/${id}`, {reason: reason}, options
).pipe(
catchError(this.log.handleError(serviceName, 'voidBill'))
);
}
moveTable(id: string, table: Table): Observable<boolean> {
const options = {params: new HttpParams().set('move', '')};
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
voucher: {id: id},
table: {id: table.id}
}, options).pipe(
catchError(this.log.handleError(serviceName, 'moveTable'))
);
}
mergeTable(id: string, table: Table): Observable<boolean> {
const options = {params: new HttpParams().set('merge', '')};
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
voucher: {id: id},
table: {id: table.id},
newVoucher: {id: table.voucherId}
}, options).pipe(
catchError(this.log.handleError(serviceName, 'mergeTable'))
);
}
moveKotToNewTable(id: string, kotId: string, table: Table): Observable<boolean> {
const options = {params: new HttpParams().set('move', '')};
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
voucher: {id: id},
kot: {id: kotId},
table: {id: table.id}
}, options).pipe(
catchError(this.log.handleError(serviceName, 'moveKotToNewTable'))
);
}
mergeKotWithOldBill(id: string, kotId: string, table: Table): Observable<boolean> {
const options = {params: new HttpParams().set('merge', '')};
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
voucher: {id: id},
kot: {id: kotId},
table: {id: table.id},
newVoucher: {id: table.voucherId}
}, options).pipe(
catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill'))
);
}
splitBill(id: string, inventoriesToMove: string[], table: Table) {
const options = {params: new HttpParams().set('split-bill', '').set('u', 'true')};
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {
voucher: {id: id},
inventories: inventoriesToMove,
table: {id: table.id}
}, options).pipe(
catchError(this.log.handleError(serviceName, 'splitBill'))
);
}
}