The account type enum is not stored in the database as an enum. The voucher_type enum is now a table in the database. Feature: Closing stock can now be saved and in each department.
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs/internal/Observable';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
|
import { Voucher } from '../core/voucher';
|
|
|
|
import { ClosingStock } from './closing-stock';
|
|
|
|
const url = '/api/closing-stock';
|
|
const serviceName = 'ClosingStockService';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class ClosingStockService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
|
|
|
list(date: string | null, costCentre: string | null): Observable<ClosingStock> {
|
|
const listUrl = date === null ? url : `${url}/${date}`;
|
|
const options = { params: new HttpParams() };
|
|
if (costCentre !== null) {
|
|
options.params = options.params.set('d', costCentre);
|
|
}
|
|
return this.http
|
|
.get<ClosingStock>(listUrl, options)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<ClosingStock>;
|
|
}
|
|
|
|
save(closingStock: ClosingStock): Observable<ClosingStock> {
|
|
return this.http
|
|
.post<ClosingStock>(url, closingStock)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<ClosingStock>;
|
|
}
|
|
|
|
post(date: string, costCentre: string): Observable<ClosingStock> {
|
|
const options = { params: new HttpParams().set('d', costCentre) };
|
|
return this.http
|
|
.post<ClosingStock>(`${url}/${date}`, {}, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'Post Voucher')),
|
|
) as Observable<ClosingStock>;
|
|
}
|
|
|
|
delete(date: string, costCentre: string): Observable<ClosingStock> {
|
|
const options = { params: new HttpParams().set('d', costCentre) };
|
|
return this.http
|
|
.delete<ClosingStock>(`${url}/${date}`, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'Delete Voucher')),
|
|
) as Observable<ClosingStock>;
|
|
}
|
|
}
|