Commit c5b5d564 authored by Vijay Akula's avatar Vijay Akula

Merge branch 'FEATURE/REPORTS_ENHANCEMENTS' of...

Merge branch 'FEATURE/REPORTS_ENHANCEMENTS' of https://gitlab.mynisum.com/hr/mytime into FEATURE/REPORTS_ENHANCEMENTS
parents 17c1b523 055fb8dc
package com.nisum.myteam.controller;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
......@@ -66,7 +67,7 @@ public class EmployeeController {
@RequestMapping(value = "/employees/{empId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateEmployee(@RequestBody Employee employeeReq,
@PathVariable(value = "empId") String loginEmpId, HttpServletRequest request) throws MyTeamException {
@PathVariable(value = "empId") String loginEmpId, HttpServletRequest request) throws MyTeamException, ParseException {
if (empService.isEmployeeExistsById(loginEmpId)) {
Employee employeeUpdated = empService.updateEmployee(employeeReq, loginEmpId);
......
......@@ -94,7 +94,7 @@ public class Employee implements Serializable {
private String empStatus;
@ExcelCellName("Employment Sub Status")
private String empSubStatus;
private Object empSubStatus;
@ExcelCellName("Employment Type")
private String employmentType;
......
package com.nisum.myteam.repository;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface EmployeeSubStatusRepo extends MongoRepository<EmployeeSubStatus, String> {
public List<EmployeeSubStatus> findByEmployeeID(String employeeId);
}
......@@ -118,7 +118,7 @@ public class LeaveNotificationScheduler {
mail.setSubject(mailSubject);
employee = employeeService.getEmployeeById(absentee.getEmployeeId());
empSubStatus = employee.getEmpSubStatus();
empSubStatus = (String)employee.getEmpSubStatus();
if (empSubStatus == null)
empSubStatus = "";
......
......@@ -5,6 +5,7 @@ import com.nisum.myteam.model.dao.Account;
import com.nisum.myteam.model.dao.Employee;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
......@@ -16,7 +17,7 @@ public interface IEmployeeService {
Employee createEmployee(Employee employeeRoles, String empId) throws MyTeamException;
Employee updateEmployee(Employee employeeRoles, String empId);
Employee updateEmployee(Employee employeeRoles, String empId) throws ParseException;
Employee deleteEmployee(String empId);
......
package com.nisum.myteam.service;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
public interface ISubStatusService {
public EmployeeSubStatus getLatestEmployeeSubStatus(String empId);
public EmployeeSubStatus updateExistingEmplyeeSubStatus(EmployeeSubStatus employeeSubStatusReq);
public EmployeeSubStatus addEmployeeSubStatus(EmployeeSubStatus employeeSubStatus);
public EmployeeSubStatus getCurrentSubStatus(String employeeId);
}
package com.nisum.myteam.service.impl;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.nisum.myteam.model.dao.*;
import com.nisum.myteam.service.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
......@@ -20,19 +18,7 @@ import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import com.nisum.myteam.exception.handler.MyTeamException;
import com.nisum.myteam.model.dao.Account;
import com.nisum.myteam.model.dao.Domain;
import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.Project;
import com.nisum.myteam.model.dao.Resource;
import com.nisum.myteam.repository.EmployeeRepo;
import com.nisum.myteam.service.IAccountService;
import com.nisum.myteam.service.IDomainService;
import com.nisum.myteam.service.IEmployeeLocationService;
import com.nisum.myteam.service.IEmployeeRoleService;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IProjectService;
import com.nisum.myteam.service.IResourceService;
import com.nisum.myteam.statuscodes.ResourceStatus;
import com.nisum.myteam.utils.MyTeamUtils;
import com.nisum.myteam.utils.constants.ApplicationRole;
......@@ -69,6 +55,9 @@ public class EmployeeService implements IEmployeeService {
@Autowired
private IResourceService resourceService;
@Autowired
private ISubStatusService subStatusService;
@Override
public Employee createEmployee(Employee employee, String loginEmpId) throws MyTeamException {
employee.setCreatedOn(new Date());
......@@ -85,7 +74,7 @@ public class EmployeeService implements IEmployeeService {
}
@Override
public Employee updateEmployee(Employee employeeReq, String loginEmpId) {
public Employee updateEmployee(Employee employeeReq, String loginEmpId) throws ParseException {
// update all emp details to inactive if employee is inactive
Query query = new Query(Criteria.where("employeeId").is(employeeReq.getEmployeeId()));
Update update = new Update();
......@@ -95,7 +84,7 @@ public class EmployeeService implements IEmployeeService {
update.set("gender", employeeReq.getGender());
update.set("functionalGroup", employeeReq.getFunctionalGroup());
update.set("empStatus", employeeReq.getEmpStatus());
update.set("empSubStatus", employeeReq.getEmpSubStatus());
// update.set("empSubStatus", employeeReq.getEmpSubStatus());
update.set("employmentType", employeeReq.getEmploymentType());
update.set("empLocation", employeeReq.getEmpLocation());
// update.set("domain", employeeReq.getDomain());
......@@ -112,8 +101,7 @@ public class EmployeeService implements IEmployeeService {
if (employeeReq.getEmpStatus().equalsIgnoreCase(MyTeamUtils.IN_ACTIVE_SPACE)) {
update.set("endDate", employeeReq.getEndDate());
update.set("empSubStatus", null);
// update.set("empSubStatus", null);
}
// update employee location
if (employeeReq.getEmpLocation() != null && !employeeReq.getEmpLocation().equals("")) {
......@@ -124,6 +112,34 @@ public class EmployeeService implements IEmployeeService {
}
//update substatus
if(employeeReq.getEmpSubStatus()!=null) {
HashMap<String,Object> substatus = (LinkedHashMap)employeeReq.getEmpSubStatus();
EmployeeSubStatus latestSubStatus = new EmployeeSubStatus();
latestSubStatus.setEmployeeID(substatus.get("employeeID").toString());
latestSubStatus.setSubStatus(substatus.get("subStatus").toString());
latestSubStatus.setFromDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(substatus.get("fromDate").toString()));
latestSubStatus.setToDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(substatus.get("toDate").toString()));
EmployeeSubStatus currentSubStatus = subStatusService.getCurrentSubStatus(employeeReq.getEmployeeId());
if (currentSubStatus != null ){
if(currentSubStatus.getSubStatus().equals(latestSubStatus.getSubStatus())) {
latestSubStatus.setId(currentSubStatus.getId());
subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
}else{
subStatusService.addEmployeeSubStatus(latestSubStatus);
}
}else{
currentSubStatus = subStatusService.getLatestEmployeeSubStatus(employeeReq.getEmployeeId());
if(currentSubStatus == null)
subStatusService.addEmployeeSubStatus(latestSubStatus);
else {
latestSubStatus.setId(currentSubStatus.getId());
subStatusService.updateExistingEmplyeeSubStatus(latestSubStatus);
}
}
}
// update employee details
FindAndModifyOptions options = new FindAndModifyOptions();
options.returnNew(true);
......
package com.nisum.myteam.service.impl;
import com.nisum.myteam.model.dao.EmployeeSubStatus;
import com.nisum.myteam.repository.EmployeeSubStatusRepo;
import com.nisum.myteam.service.ISubStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class SubStatusService implements ISubStatusService {
@Autowired
private EmployeeSubStatusRepo employeeSubStatusRepo;
@Override
public EmployeeSubStatus getLatestEmployeeSubStatus(String empId) {
List<EmployeeSubStatus> employeeSubStatusList = employeeSubStatusRepo.findByEmployeeID(empId);
EmployeeSubStatus latestSubStatus = null;
if(!employeeSubStatusList.isEmpty()){
latestSubStatus = employeeSubStatusList.get(0);
for(EmployeeSubStatus s:employeeSubStatusList) {
if(s.getToDate().after(latestSubStatus.getToDate())){
latestSubStatus = s;
}
}
}
return latestSubStatus;
}
@Override
public EmployeeSubStatus updateExistingEmplyeeSubStatus(EmployeeSubStatus employeeSubStatusReq) {
return employeeSubStatusRepo.save(employeeSubStatusReq);
}
@Override
public EmployeeSubStatus addEmployeeSubStatus(EmployeeSubStatus employeeSubStatus) {
return employeeSubStatusRepo.insert(employeeSubStatus);
}
@Override
public EmployeeSubStatus getCurrentSubStatus(String employeeId){
List<EmployeeSubStatus> currentEmployeeSubStatusList = employeeSubStatusRepo.findByEmployeeID(employeeId).stream().filter(
s -> s.getFromDate().compareTo(new Date())<=0 && s.getToDate().compareTo(new Date())>=0).collect(Collectors.toList());
if(!currentEmployeeSubStatusList.isEmpty()){
return currentEmployeeSubStatusList.get(0);
}else
return null;
}
}
......@@ -465,6 +465,18 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
var passportExpiryDate = $scope.passportExpiryDate;
var subStatusStartDate = $scope.subStatusStartDate;
var subStatusEndDate = $scope.subStatusEndDate;
var empSubStatusObj = {
employeeID: $scope.empId,
subStatus : $scope.empSubStatus,
fromDate: $scope.subStatusStartDate,
toDate: $scope.subStatusEndDate
};
var prevEmpSubStatusObj = {
employeeID: dataToPass.employeeId,
subStatus : dataToPass.empSubStatus,
fromDate: dataToPass.subStatusStartDate,
toDate: dataToPass.subStatusEndDate
};
if(searchId == ""){
$scope.alertMsg = "Employee Id is mandatory";
document.getElementById('empId').focus();
......@@ -561,9 +573,9 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
$scope.alertMsg = "";
var record = {"employeeId":$scope.empId, "employeeName": $scope.empName, "gender": $scope.gender,"emailId": $scope.empEmail,
"role": $scope.empRole, "empLocation": $scope.empLocation,"designation": $scope.designation,"functionalGroup": $scope.functionalGroup,
"empStatus": $scope.empStatus,"empSubStatus":$scope.empSubStatus,"employmentType": $scope.employmentType,"dateOfJoining":$scope.dateOfJoining,
"empStatus": $scope.empStatus,"employmentType": $scope.employmentType,"dateOfJoining":$scope.dateOfJoining,
"dateOfBirth":$scope.dateOfBirth,"hasPassort":$scope.hasPassort,"hasB1":$scope.hasB1,"passportExpiryDate":$scope.passportExpiryDate,
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate, "subStatusStartDate":$scope.subStatusStartDate,"subStatusEndDate":$scope.subStatusEndDate
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate,"empSubStatus":empSubStatusObj
};
if($scope.templateTitle == "Add"){
addOrUpdateRole(record, $scope.templateTitle);
......@@ -574,7 +586,7 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
"role": dataToPass.role, "empLocation": dataToPass.empLocation,"designation": dataToPass.designation,"functionalGroup": dataToPass.functionalGroup,
"empStatus": dataToPass.empStatus,"empSubStatus":dataToPass.empSubStatus, "employmentType": dataToPass.employmentType,"dateOfJoining":new Date(dataToPass.dateOfJoining),
"dateOfBirth":new Date(dataToPass.dateOfBirth),"hasPassort":dataToPass.hasPassort,"hasB1":dataToPass.hasB1,"passportExpiryDate":new Date(dataToPass.passportExpiryDate),
"b1ExpiryDate":new Date(dataToPass.b1ExpiryDate), "endDate":new Date(dataToPass.endDate) , "subStatusStartDate": new Date(dataToPass.subStatusStartDate) ,"subStatusEndDate": new Date(dataToPass.subStatusEndDate)
"b1ExpiryDate":new Date(dataToPass.b1ExpiryDate), "endDate":new Date(dataToPass.endDate) ,"empSubStatus": prevEmpSubStatusObj
};
objectConstructionBasedOnParameters(recordFromDb);
objectConstructionBasedOnParameters(record);
......@@ -626,19 +638,31 @@ myApp.controller("assignRoleController",function($scope, myFactory, $mdDialog, $
}
$scope.cancel = function() {
var empSubStatusObj = {
employeeID: $scope.empId,
subStatus : $scope.empSubStatus,
fromDate: $scope.subStatusStartDate,
toDate: $scope.subStatusEndDate
};
var prevEmpSubStatusObj = {
employeeID: dataToPass.employeeId,
subStatus : dataToPass.empSubStatus,
fromDate: dataToPass.subStatusStartDate,
toDate: dataToPass.subStatusEndDate
};
var record = {
"employeeId":$scope.empId, "employeeName": $scope.empName, "gender": $scope.gender,"emailId": $scope.empEmail,
"role": $scope.empRole, "empLocation": $scope.empLocation,"designation": $scope.designation,"functionalGroup": $scope.functionalGroup,
"empStatus": $scope.empStatus, "empSubStatus":$scope.empSubStatus, "employmentType": $scope.employmentType,"dateOfJoining":$scope.dateOfJoining,
"dateOfBirth":$scope.dateOfBirth,"hasPassort":$scope.hasPassort,"hasB1":$scope.hasB1,"passportExpiryDate":$scope.passportExpiryDate,
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate , "subStatusStartDate":$scope.subStatusStartDate,"subStatusEndDate":$scope.subStatusEndDate
"b1ExpiryDate":$scope.b1ExpiryDate, "endDate":$scope.exitDate ,"empSubStatus":empSubStatusObj
};
var recordFromDb = {
"employeeId":dataToPass.employeeId, "employeeName": dataToPass.employeeName, "gender": dataToPass.gender,"emailId": dataToPass.emailId,
"role": dataToPass.role, "empLocation": dataToPass.empLocation,"designation": dataToPass.designation,"functionalGroup": dataToPass.functionalGroup,
"empStatus": dataToPass.empStatus, "empSubStatus":dataToPass.empSubStatus, "employmentType": dataToPass.employmentType,"dateOfJoining":new Date(dataToPass.dateOfJoining),
"dateOfBirth":new Date(dataToPass.dateOfBirth),"hasPassort":dataToPass.hasPassort,"hasB1":dataToPass.hasB1,"passportExpiryDate":new Date(dataToPass.passportExpiryDate),
"b1ExpiryDate":new Date(dataToPass.b1ExpiryDate), "endDate":new Date(dataToPass.endDate) ,"subStatusStartDate": new Date(dataToPass.subStatusStartDate) ,"subStatusEndDate": new Date(dataToPass.subStatusEndDate)
"b1ExpiryDate":new Date(dataToPass.b1ExpiryDate), "endDate":new Date(dataToPass.endDate) , "empSubStatus":prevEmpSubStatusObj
};
objectConstructionBasedOnParameters(recordFromDb);
objectConstructionBasedOnParameters(record);
......
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