Unverified Commit 324a252b authored by mshaik-nisum-com's avatar mshaik-nisum-com Committed by GitHub

Merge pull request #182 from nisum-inc/FEATURE/Get_LoginReport_Based_On_DateTime

MT-175:Login Report Based On Selected Time and Date
parents 856aa6c9 337f8970
package com.nisum.mytime.controller;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
......@@ -46,24 +47,6 @@ public class AttendanceController {
return new ResponseEntity<>(message, HttpStatus.OK);
}
@RequestMapping(value = "employeeLoginReportBasedOnDateTime",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<EmpLoginData>> employeeLoginReportBasedOnDateTime(
@RequestParam("empId") long id,
@RequestParam("fromDate") String fromDate,
@RequestParam("toDate") String toDate,
@RequestParam("fromTime") String fromTime,
@RequestParam("toTime") String toTime) throws MyTimeException {
List<EmpLoginData> message = new ArrayList<>();
try {
message = attendanceService.employeeLoginReportBasedOnDateTime(id, fromDate, toDate,fromTime,toTime);
} catch (Exception e) {
e.printStackTrace();
}
return new ResponseEntity<>(message, HttpStatus.OK);
}
@RequestMapping(value = "generatePdfReport/{id}/{fromDate}/{toDate}",
method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> generatePdfReport(@PathVariable("id") long id,
......@@ -73,6 +56,17 @@ public class AttendanceController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@RequestMapping(value = "generatePdfReport/{id}/{fromDate}/{toDate}/{fromTime}/{toTime}",
method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> generatePdfReport(@PathVariable("id") long id,
@PathVariable("fromDate") String fromDate,
@PathVariable("toDate") String toDate,
@PathVariable("fromTime") String fromTime,
@PathVariable("toTime") String toTime) throws MyTimeException, ParseException {
String result = userService.generatePdfReport(id, fromDate, toDate,fromTime,toTime);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@RequestMapping(value = "attendanciesReport/{reportDate}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
......
......@@ -75,15 +75,12 @@ public class AttendanceServiceImpl implements AttendanceService {
int hoursFrom=Integer.parseInt(timeFrom.substring(0,2));
int hoursTo=Integer.parseInt(timeTo.substring(0,2));
if(hoursTo<=hoursFrom && timeSignFrom.equals(timeSignTo) || hoursTo<=hoursFrom) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/d");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-d");
LocalDate newtoDate = (LocalDate.parse(fromDate,formatter)).plusDays(1);
nextDate=newtoDate.toString();
nextDate=nextDate.replace("-", "/");
}
return employeeDataBaseService.fetchEmployeeLoginsBasedOnDatesTime(id, fromDate,nextDate, toDate,timeFrom,timeTo);
}
@Override
public String generatePdfReport(long id, String fromDate, String toDate, String fromTime, String toTime)
throws MyTimeException {
......
......@@ -87,7 +87,7 @@ public class EmployeeDataService {
}
public List<EmpLoginData> fetchEmployeeLoginsBasedOnDatesTime(long employeeId, String fromDate, String nextDate,String toDate,String fromTime,String toTime) throws MyTimeException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate formatedFromDate=LocalDate.parse(fromDate,formatter);
LocalDate formatedNextDate=LocalDate.parse(nextDate,formatter);
LocalDate formatedToDate=LocalDate.parse(toDate,formatter);
......@@ -148,5 +148,4 @@ public class EmployeeDataService {
}
return listOfEmpLoginData;
}
}
\ No newline at end of file
package com.nisum.mytime.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -35,6 +36,9 @@ public interface UserService {
String generatePdfReport(long id, String fromDate, String toDate)
throws MyTimeException;
String generatePdfReport(long id, String fromDate, String toDate,String fromTime,String toTime)
throws MyTimeException, ParseException;
EmployeeRoles getEmployeesRole(String emailId);
void deleteEmployee(String empId);
......
package com.nisum.mytime.service;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
......@@ -133,6 +134,12 @@ public class UserServiceImpl implements UserService {
return pdfReportGenerator.generateEmployeeReport(id, fromDate, toDate);
}
@Override
public String generatePdfReport(long id, String fromDate, String toDate,String fromTime,String toTime)
throws MyTimeException, ParseException {
return pdfReportGenerator.generateEmployeeReport(id, fromDate, toDate,fromTime,toTime);
}
@Override
public List<EmployeeRoles> getEmployeeRoles() throws MyTimeException {
//return employeeRolesRepo.findAll();
......
......@@ -2,6 +2,7 @@ package com.nisum.mytime.utils;
import java.io.File;
import java.io.FileOutputStream;
import java.text.ParseException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -23,6 +24,7 @@ import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.EmpLoginData;
import com.nisum.mytime.service.AttendanceService;
import com.nisum.mytime.service.EmployeeDataService;
@Component
......@@ -34,6 +36,9 @@ public class PdfReportGenerator {
@Autowired
private EmployeeDataService employeeDataBaseService;
@Autowired
private AttendanceService attendanceService;
public String generateEmployeeReport(long employeeId, String startDate, String endDate) throws MyTimeException {
String fileName = employeeId + "_" + startDate + "_" + endDate + ".pdf";
List<EmpLoginData> empLoginDetails = getEmployeeData(employeeId, startDate, endDate);
......@@ -44,11 +49,26 @@ public class PdfReportGenerator {
}
}
public String generateEmployeeReport(long employeeId, String startDate, String endDate,String fromTime,String toTime) throws MyTimeException, ParseException {
String fileName = employeeId + "_" + startDate + "_" + endDate + ".pdf";
List<EmpLoginData> empLoginDetails = getEmployeeData(employeeId, startDate, endDate,fromTime,toTime);
if (empLoginDetails.isEmpty()) {
return "No data available";
} else {
return createPDF(fileName, empLoginDetails, employeeId);
}
}
private List<EmpLoginData> getEmployeeData(long employeeId, String fromDate, String toDate) throws MyTimeException {
return employeeDataBaseService.fetchEmployeeLoginsBasedOnDates(employeeId, fromDate, toDate);
}
private List<EmpLoginData> getEmployeeData(long employeeId, String fromDate, String toDate,String fromTime,String toTime) throws MyTimeException, ParseException {
return attendanceService.employeeLoginReportBasedOnDateTime(employeeId, fromDate, toDate,fromTime,toTime);
}
private String createPDF(String pdfFilename, List<EmpLoginData> empLoginDatas, long employeeId)
throws MyTimeException {
Document doc = null;
......
......@@ -200,7 +200,7 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
empId = data.empId;
}
var defaultURL= appConfig.appUri + "attendance/generatePdfReport/" + empId + "/" + data.fromDate + "/" +data.toDate;
var overrideURL= appConfig.appUri +"attendance/employeeLoginReportBasedOnDateTime?empId=" + empId + "&fromDate=" + data.fromDate + "&toDate=" +data.toDate +"&fromTime=" +data.fromTime +"&toTime="+data.toTime;
var overrideURL= appConfig.appUri +"attendance/generatePdfReport/" + empId + "/" + data.fromDate + "/" +data.toDate+ "/" +data.fromTime +"/"+data.toTime;
var url = data.isOverride ? overrideURL:defaultURL;
$http({
method : "GET",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment