From 7b03f6adffab5ac7ce264fdb615ffca8a7f4832f Mon Sep 17 00:00:00 2001 From: piratefinn Date: Tue, 19 Sep 2017 15:38:35 +0100 Subject: [PATCH 1/2] 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() ); } From 089e7f7a97ead8864fc298993890a01942d863ea Mon Sep 17 00:00:00 2001 From: piratefinn Date: Tue, 19 Sep 2017 17:22:19 +0100 Subject: [PATCH 2/2] Functionality fully added --- CHANGELOG.md | 1 + src/app/dashboard/dashboard.module.ts | 4 ++++ src/app/dashboard/dashboard.routing.ts | 7 ++++++ src/app/dashboard/payroll-log.component.html | 8 +++---- src/app/layouts/full-layout.component.html | 5 +++++ src/app/layouts/full-layout.component.ts | 2 ++ src/app/shared/payroll-result.component.html | 3 +++ src/app/shared/payroll-result.component.ts | 22 +++++++++++++++++++ .../shared/transaction-result.component.ts | 2 +- 9 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 src/app/shared/payroll-result.component.html create mode 100644 src/app/shared/payroll-result.component.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 84ec5f1..83a368e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # Next Release +* Payroll Log Data added * Fixed register box view on login page * Made the form reset properly if adding a new one * Added better error messages on register and account edit diff --git a/src/app/dashboard/dashboard.module.ts b/src/app/dashboard/dashboard.module.ts index 55bb110..134d8bd 100644 --- a/src/app/dashboard/dashboard.module.ts +++ b/src/app/dashboard/dashboard.module.ts @@ -13,6 +13,7 @@ import { AccountEditComponent } from './account-edit.component'; import { AddDataComponent } from './add-data.component'; import { FeedbackComponent } from './feedback.component'; import { TransactionLogComponent } from './transaction-log.component'; +import { PayrollLogComponent } from './payroll-log.component'; import { GraphWidget } from '../widgets/graph-widget.component'; import { OrgBarSnippetComponent } from '../snippets/org-snippet-bar.component'; @@ -22,6 +23,7 @@ import { DashboardRoutingModule } from './dashboard.routing'; import { OrgResultComponent } from '../shared/org-result.component'; import { OrgTableComponent } from '../shared/org-table.component'; import { TransactionResultComponent } from '../shared/transaction-result.component'; +import { PayrollResultComponent } from '../shared/payroll-result.component'; @NgModule({ imports: [ @@ -43,6 +45,8 @@ import { TransactionResultComponent } from '../shared/transaction-result.compone OrgTableComponent, TransactionLogComponent, TransactionResultComponent, + PayrollLogComponent, + PayrollResultComponent, FeedbackComponent, GraphWidget, OrgBarSnippetComponent, diff --git a/src/app/dashboard/dashboard.routing.ts b/src/app/dashboard/dashboard.routing.ts index acb81b7..c36cfb2 100644 --- a/src/app/dashboard/dashboard.routing.ts +++ b/src/app/dashboard/dashboard.routing.ts @@ -12,6 +12,7 @@ import { AccountEditComponent } from './account-edit.component'; import { AddDataComponent } from './add-data.component'; import { FeedbackComponent } from './feedback.component'; import { TransactionLogComponent } from './transaction-log.component'; +import { PayrollLogComponent } from './payroll-log.component'; // Using child path to allow for FullLayout theming const routes: Routes = [ @@ -48,6 +49,12 @@ const routes: Routes = [ component: TransactionLogComponent, data: { title: 'Transaction Log' }, }, + { + path: 'payroll-log', + component: PayrollLogComponent, + data: { title: 'Payroll Log' }, + canActivate: [OrgGuard], + }, { path: 'feedback', component: FeedbackComponent, diff --git a/src/app/dashboard/payroll-log.component.html b/src/app/dashboard/payroll-log.component.html index 68ec8af..0b08ed8 100644 --- a/src/app/dashboard/payroll-log.component.html +++ b/src/app/dashboard/payroll-log.component.html @@ -10,13 +10,13 @@ - - - + + + - +
SellerValuePurchase TimeEntry PeriodGross PayrollEmployees
Transaction Log +
diff --git a/src/app/layouts/full-layout.component.ts b/src/app/layouts/full-layout.component.ts index af6b9bf..453a8df 100644 --- a/src/app/layouts/full-layout.component.ts +++ b/src/app/layouts/full-layout.component.ts @@ -8,6 +8,7 @@ import { Router } from '@angular/router'; }) export class FullLayoutComponent implements OnInit { public displayName: string; + public accountType: any; public disabled = false; public status: {isopen: boolean} = {isopen: false}; @@ -29,6 +30,7 @@ export class FullLayoutComponent implements OnInit { // getDisplayName function from api didnt work ngOnInit(): void { this.displayName = localStorage.getItem('displayname') || 'User'; + this.accountType = localStorage.getItem('usertype'); } userLogout() { diff --git a/src/app/shared/payroll-result.component.html b/src/app/shared/payroll-result.component.html new file mode 100644 index 0000000..6d891c6 --- /dev/null +++ b/src/app/shared/payroll-result.component.html @@ -0,0 +1,3 @@ +{{payrollDate}} +{{payroll.gross_payroll | currency:'GBP':true:'1.2-2' }} +{{payroll.employee_amount}} diff --git a/src/app/shared/payroll-result.component.ts b/src/app/shared/payroll-result.component.ts new file mode 100644 index 0000000..fdf3fa7 --- /dev/null +++ b/src/app/shared/payroll-result.component.ts @@ -0,0 +1,22 @@ +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import * as moment from 'moment'; + +interface PayrollData { + entry_period: string; + gross_payroll: number; + employee_amount: number; +} + +@Component({ + // tslint:disable-next-line + selector: '[payroll-result]', + templateUrl: 'payroll-result.component.html', +}) +export class PayrollResultComponent implements OnInit { + @Input() public payroll: PayrollData; + public payrollDate: string; + + ngOnInit(): void { + this.payrollDate = moment(this.payroll.entry_period).format('MMMM YYYY'); + } +} diff --git a/src/app/shared/transaction-result.component.ts b/src/app/shared/transaction-result.component.ts index ed76a56..a293b72 100644 --- a/src/app/shared/transaction-result.component.ts +++ b/src/app/shared/transaction-result.component.ts @@ -3,7 +3,7 @@ import * as moment from 'moment'; interface TransactionData { seller: number; - value: string; + value: number; purchase_time: string; }