2017-09-19 15:38:35 +01:00
import { Component , OnInit , Input , Output , EventEmitter } from '@angular/core' ;
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' ;
2018-06-04 15:23:16 +01:00
2017-09-19 15:38:35 +01:00
@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 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 ) ;
}
2021-03-20 23:47:48 +00:00
getMinDate() {
2017-09-19 15:38:35 +01:00
// gets the April 1st date of the current year
2021-03-20 23:47:48 +00:00
const aprilDate = moment ( ) . month ( 3 ) . date ( 1 ) ;
const now = moment ( ) ;
2017-09-19 15:38:35 +01:00
// Checks if current time is before April 1st, if so returns true
2021-03-20 23:47:48 +00:00
const beforeApril = now . isBefore ( aprilDate ) ;
2017-09-19 15:38:35 +01:00
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 = > {
2021-03-20 23:47:48 +00:00
if ( result . payrolls . length > 0 ) {
2017-09-19 15:38:35 +01:00
this . payrollList = result . payrolls ;
2021-03-20 23:47:48 +00:00
// TODO Rename in server
2017-09-19 15:38:35 +01:00
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 ) ;
}
) ;
}
}