From 7b03f6adffab5ac7ce264fdb615ffca8a7f4832f Mon Sep 17 00:00:00 2001 From: piratefinn Date: Tue, 19 Sep 2017 15:38:35 +0100 Subject: [PATCH] Initial addition of API for payroll log --- src/app/dashboard/add-data.component.html | 2 +- src/app/dashboard/payroll-log.component.html | 49 +++++++++++++ src/app/dashboard/payroll-log.component.ts | 77 ++++++++++++++++++++ src/app/providers/api-service.ts | 19 ++++- 4 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/app/dashboard/payroll-log.component.html create mode 100644 src/app/dashboard/payroll-log.component.ts diff --git a/src/app/dashboard/add-data.component.html b/src/app/dashboard/add-data.component.html index 91e8e42..3a78b96 100644 --- a/src/app/dashboard/add-data.component.html +++ b/src/app/dashboard/add-data.component.html @@ -72,7 +72,7 @@ -
+
Profile & Payroll Data Required Data marked in bold. diff --git a/src/app/dashboard/payroll-log.component.html b/src/app/dashboard/payroll-log.component.html new file mode 100644 index 0000000..68ec8af --- /dev/null +++ b/src/app/dashboard/payroll-log.component.html @@ -0,0 +1,49 @@ +
+
+
+
+
+ Log of Payroll submissions + Sorted descending from submission date. +
+
+ + + + + + + + + + + +
SellerValuePurchase Time
+ + + +
+
+ No Payroll data available. +
+
+
+
+
diff --git a/src/app/dashboard/payroll-log.component.ts b/src/app/dashboard/payroll-log.component.ts new file mode 100644 index 0000000..3e7a3ce --- /dev/null +++ b/src/app/dashboard/payroll-log.component.ts @@ -0,0 +1,77 @@ +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { Http, Response } from '@angular/http'; +import { ApiService } from '../providers/api-service'; +// import { PaginatePipe } from 'ngx-pagination'; +import {PaginationInstance} from 'ngx-pagination'; +// import { PaginationControlsComponent } from 'ngx-pagination'; +// import { PaginationControlsDirective } from 'ngx-pagination'; +// import { TransactionResultComponent } from '../shared/transaction-result.component'; +import * as moment from 'moment'; +import 'rxjs/add/operator/map'; + +@Component({ + templateUrl: 'payroll-log.component.html', +}) +export class PayrollLogComponent implements OnInit { + + payrollList; + noPayrollList = true; + myDate: any; + minDate: any; + + public paginateConfig: PaginationInstance = { + id: 'transpaginate', + itemsPerPage: 10, + currentPage: 1, + totalItems: 0 + }; + + constructor( + private http: Http, + private api: ApiService, + ) { + this.myDate = moment().format('YYYY-MM-DD[T]HH:mm'); + // this.myDate = new Date().toISOString().slice(0, 16); + } + + ngOnInit(): void { + this.getMinDate(); + this.loadPayrolls(1); + } + + getMinDate(){ + // gets the April 1st date of the current year + let aprilDate = moment().month(3).date(1); + let now = moment(); + // Checks if current time is before April 1st, if so returns true + let beforeApril = now.isBefore(aprilDate); + if ( beforeApril == true ) { + this.minDate = aprilDate.subtract(2, 'years').format('YYYY-MM-DD'); + } else { + this.minDate = aprilDate.subtract(1, 'years').format('YYYY-MM-DD'); + } + } + + loadPayrolls(logPage: number) { + console.log(logPage); + this.api.payrollList(logPage).subscribe( + result => { + if(result.payrolls.length > 0) { + this.payrollList = result.payrolls; + //TODO Rename in server + this.paginateConfig.totalItems = result.page_no; + this.paginateConfig.currentPage = logPage; + this.noPayrollList = false; + } else { + // handle the case when the payrollList is empty + this.payrollList = null; + this.noPayrollList = true; + } + }, + error => { + console.log(error); + } + ); + } + +} diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index e0f27a2..6c6ea47 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -136,12 +136,25 @@ export class ApiService { ).map( response => response.json() ); } + // gets payroll list for log + + public payrollList(data) { + const key = this.sessionKey; + return this.http.post( + this.apiUrl + '/v1/organisation/payroll', + { + session_key : key, + page : data + } + ).map( response => response.json() ); + } + // handles Org data added public orgPayroll(data) { data.session_key = this.sessionKey; return this.http.post( - this.apiUrl + '/org/payroll', + this.apiUrl + '/v1/organisation/payroll/add', data ).map( response => response.json() ); } @@ -149,7 +162,7 @@ export class ApiService { public orgSupplier(data) { data.session_key = this.sessionKey; return this.http.post( - this.apiUrl + '/org/supplier', + this.apiUrl + '/v1/organisation/supplier/add', data ).map( response => response.json() ); } @@ -157,7 +170,7 @@ export class ApiService { public orgEmployee(data) { data.session_key = this.sessionKey; return this.http.post( - this.apiUrl + '/org/employee', + this.apiUrl + '/v1/organisation/employee/add', data ).map( response => response.json() ); }