Save Bill Works

This commit is contained in:
Amritanshu
2019-07-13 21:32:18 +05:30
parent bcad4cdae3
commit 7d06a2f961
43 changed files with 660 additions and 349 deletions

View File

@ -3,7 +3,7 @@ import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { ErrorLoggerService } from '../../core/error-logger.service';
import {Bill} from "./bill";
import { Bill, PrintType } from './bill';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
@ -46,25 +46,33 @@ export class VoucherService {
);
}
save(voucher: Bill): Observable<Bill> {
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, httpOptions)
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
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)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(voucher: Bill): Observable<Bill> {
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, httpOptions)
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
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)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}
saveOrUpdate(voucher: Bill): Observable<Bill> {
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
if (!voucher.id) {
return this.save(voucher);
return this.save(voucher, printType, guest_book_id, updateTable);
} else {
return this.update(voucher);
return this.update(voucher, printType, guest_book_id, updateTable);
}
}
}