myApp.controller("reservedReportsController",function($scope,exportUiGridService, myFactory, $mdDialog, $http, appConfig, $timeout, $element, $window){
	$scope.records = [];
	$scope.gridOptions = {
			paginationPageSizes : [ 10, 20, 30, 40, 50, 100],
			paginationPageSize : 10,
		    pageNumber: 1,
			pageSize:10,
			enableFiltering:true,
			columnDefs : [
				{field : 'employeeId',displayName: 'Employee Id', enableColumnMenu: false, enableSorting: false,enableFiltering: true},
				{field : 'employeeName',displayName: 'Employee Name', enableColumnMenu: false, enableSorting: true,enableFiltering: true,cellClass:function(grid,row,col){
					if(daysBetween(row.entity.reservedStartDate,row.entity.reservedEndDate) > '14') {
						 return 'red';
					 }
				}}, 
				{name : 'accountName', displayName: 'Client', enableColumnMenu: false, enableSorting: false, enableFiltering:false},
				{field : 'projectName',displayName: 'Project Name', enableColumnMenu: false, enableSorting: true,enableFiltering: true}, 
				{name : 'reservedStartDate', displayName: 'Reserved Start Date', enableColumnMenu: false,cellFilter: 'date:"dd-MMM-yyyy"', enableSorting: false, enableFiltering:false},
				{name : 'reservedEndDate', displayName: 'Reserved End Date', enableColumnMenu: false,cellFilter: 'date:"dd-MMM-yyyy"', enableSorting: false, enableFiltering:false} 
			],
		enableGridMenu: true,
	    enableSelectAll: true,
	    exporterMenuExcel:false,
	    exporterMenuCsv:false,
	    exporterCsvFilename: 'ReservedReport.csv',
	    exporterExcelFilename:'ReservedReport',
	    exporterPdfDefaultStyle: {fontSize: 9},
	    exporterPdfTableStyle: {margin: [15, 15, 15, 15]},
	    exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'},
	    exporterPdfHeader: { text: "Reserved Report", style: 'headerStyle' },
	    exporterPdfFooter: function ( currentPage, pageCount ) {
	      return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' };
	    },
	    exporterPdfCustomFormatter: function ( docDefinition ) {
	      docDefinition.styles.headerStyle = { fontSize: 22, bold: true };
	      docDefinition.styles.footerStyle = { fontSize: 10, bold: true };
	      return docDefinition;
	    },
	    exporterPdfOrientation: 'portrait',
	    exporterPdfPageSize: 'LETTER',
	    exporterPdfMaxGridWidth: 500,
	    exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
	    onRegisterApi: function(gridApi){
	      $scope.gridApi = gridApi;
	    },
	            gridMenuCustomItems: [{
	                    title: 'Export all data as EXCEL',
	                    action: function ($event) {
	                        exportUiGridService.exportToExcel('sheet 1', $scope.gridApi, 'all', 'all');
	                    },
	                    order: 110
	                },
	                {
	                    title: 'Export visible data as EXCEL',
	                    action: function ($event) {
	                        exportUiGridService.exportToExcel('sheet 1', $scope.gridApi, 'visible', 'visible');
	                    },
	                    order: 111
	                }
	            ]
		};
	$scope.gridOptions.data = [{employeeId:"16727",employeeName : "Prayas" , accountName : 'Nisum India' ,projectName : 'Bench',reservedStartDate:1559563534000 ,reservedEndDate:1559996723000},{employeeId:"16728",employeeName : "Abhijeet" , accountName : 'Macys' ,projectName : 'MyProject',reservedStartDate:1559563534000 ,reservedEndDate:1560860723000}];
	
/*	$scope.getReservedEnployeesData = function(){
		$http({
	        method : "GET",
	        url : appConfig.appUri + "employeeEfforts/getWeeklyReport?fromDate=" + fromDate + "&toDate=" +toDate
	    }).then(function mySuccess(response) {
	        $scope.gridOptions.data = response.data;
	        if(response.data.length > 10){
	    		$scope.gridOptions.enablePaginationControls = true;
	    	}
	    	else{
	    		$scope.gridOptions.enablePaginationControls = false;
	    	}
	    }, function myError(response) {
	    	showAlert("Something went wrong while fetching data!!!");
	    	$scope.gridOptions.data = [];
	    });
	}*/	
	function showAlert(message) {
		$mdDialog.show($mdDialog.alert().parent(
				angular.element(document.querySelector('#popupContainer')))
				.clickOutsideToClose(true).textContent(message).ariaLabel(
						'Alert Dialog').ok('Ok'));
	}

	function treatAsUTC(date) {
	    var result = new Date(date);
	    result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
	    return result;
	}

	function daysBetween(fromDate, toDate) {
	    var millisecondsPerDay = 24 * 60 * 60 * 1000;
	    return Math.round((treatAsUTC(toDate) - treatAsUTC(fromDate)) / millisecondsPerDay);
	}
	
});