Attendance and Employee Attendance done!!
Journal Done!! But there is issue of validation in purchase due to lack of proper journals when getting data from the frontend. The proposed solution is to create different schemas for various vouchers and then reexport and import them in a master schema for persisting Also, change "Supplier" to vendor in Purchase, etc. Also, convert all date field to date from datetime Rename "Salary Deduction" to "Employee Benefits" across the board
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {Attendance} from './attendance';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
|
||||
const url = '/api/voucher';
|
||||
const url = '/api';
|
||||
const serviceName = 'VoucherService';
|
||||
|
||||
@Injectable({
|
||||
@ -20,22 +20,23 @@ export class VoucherService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Voucher> {
|
||||
const options = {params: new HttpParams()};
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(`${url}/${id}`, options)
|
||||
get(id: string, type: string): Observable<Voucher> {
|
||||
const endpoint = type.replace(/ /g, '-').toLowerCase();
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(`${url}/${endpoint}/${id}`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
catchError(this.log.handleError(serviceName, 'get'))
|
||||
);
|
||||
}
|
||||
|
||||
getOfType(type: string, account?: string): Observable<Voucher> {
|
||||
const options = {params: new HttpParams().set('t', type)};
|
||||
const endpoint = type.replace(/ /g, '-').toLowerCase();
|
||||
const options = {};
|
||||
if (account !== undefined && account !== null) {
|
||||
options.params = options.params.set('a', account);
|
||||
options['params'] = new HttpParams().set('a', account);
|
||||
}
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(url, options)
|
||||
return <Observable<Voucher>>this.http.get<Voucher>(`${url}/${endpoint}`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
catchError(this.log.handleError(serviceName, 'getOfType'))
|
||||
);
|
||||
}
|
||||
|
||||
@ -63,18 +64,17 @@ export class VoucherService {
|
||||
}
|
||||
|
||||
save(voucher: Voucher): Observable<Voucher> {
|
||||
const options = {
|
||||
params: new HttpParams().set('t', voucher.type)
|
||||
};
|
||||
const endpoint = voucher.type.replace(/ /g, '-').toLowerCase();
|
||||
|
||||
const fd = new FormData();
|
||||
voucher.files.filter(x => !x.id).forEach((file, index) => {
|
||||
fd.append('f' + index, this.dataURLtoBlob(file.resized));
|
||||
fd.append('t' + index, this.dataURLtoBlob(file.thumbnail));
|
||||
voucher.files.filter(x => !x.id).forEach((file) => {
|
||||
fd.append('i' , this.dataURLtoBlob(file.resized));
|
||||
fd.append('t' , this.dataURLtoBlob(file.thumbnail));
|
||||
});
|
||||
voucher.files = voucher.files.filter(x => x.id);
|
||||
fd.append('model', JSON.stringify(voucher));
|
||||
const saveUrl: string = (voucher.id === undefined || voucher.id === null) ? url : `${url}/${voucher.id}`;
|
||||
return <Observable<Voucher>>this.http.post<Voucher>(saveUrl, fd, options)
|
||||
fd.append('data', JSON.stringify(voucher));
|
||||
const saveUrl: string = (voucher.id === undefined || voucher.id === null) ? `${url}/${endpoint}` : `${url}/${endpoint}/${voucher.id}`;
|
||||
return <Observable<Voucher>>this.http.post<Voucher>(saveUrl, fd)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
|
||||
@ -3,7 +3,6 @@ import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/rou
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {Voucher} from '../core/voucher';
|
||||
import {VoucherService} from '../core/voucher.service';
|
||||
import {tap} from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -18,7 +17,7 @@ export class EmployeeBenefitsResolver implements Resolve<Voucher> {
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Salary Deduction');
|
||||
} else {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Employee-Benefits');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ export class EmployeeFunctionsComponent implements OnInit {
|
||||
// this.toaster.show('Danger', 'Please choose a start and finish date.');
|
||||
return;
|
||||
}
|
||||
return '/attendance-report?StartDate=' + startDate + '&FinishDate=' + finishDate;
|
||||
return '/attendance-report?s=' + startDate + '&f=' + finishDate;
|
||||
}
|
||||
|
||||
detectFiles(event) {
|
||||
|
||||
@ -18,7 +18,7 @@ export class IncentiveResolver implements Resolve<Voucher> {
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Incentive');
|
||||
} else {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Incentive');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ export class IssueResolver implements Resolve<Voucher> {
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Issue');
|
||||
} else {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Issue');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ export class JournalResolver implements Resolve<Voucher> {
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Journal');
|
||||
} else {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Journal');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ export class PaymentResolver implements Resolve<Voucher> {
|
||||
const id = route.paramMap.get('id');
|
||||
const account = route.queryParamMap.get('a') || null;
|
||||
if (id !== null) {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Payment');
|
||||
} else if (account !== null) {
|
||||
return this.ser.getOfType('Payment', account);
|
||||
} else {
|
||||
|
||||
@ -17,7 +17,7 @@ export class PurchaseReturnResolver implements Resolve<Voucher> {
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Purchase Return');
|
||||
} else {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Purchase Return');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ export class PurchaseResolver implements Resolve<Voucher> {
|
||||
if (id === null) {
|
||||
return this.ser.getOfType('Purchase');
|
||||
} else {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Purchase');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ export class ReceiptResolver implements Resolve<Voucher> {
|
||||
const id = route.paramMap.get('id');
|
||||
const account = route.queryParamMap.get('a') || null;
|
||||
if (id !== null) {
|
||||
return this.ser.get(id);
|
||||
return this.ser.get(id, 'Receipt');
|
||||
} else if (account !== null) {
|
||||
return this.ser.getOfType('Receipt', account);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user