Commit bbf76717 authored by Md Suleman's avatar Md Suleman

Changes in Resource allocation to projects add allocation and update allocation

parent c046bc6c
...@@ -52,7 +52,7 @@ public class LeaveNotificationScheduler { ...@@ -52,7 +52,7 @@ public class LeaveNotificationScheduler {
private IFunctionalGroupService functionalGroupService; private IFunctionalGroupService functionalGroupService;
@Scheduled(cron = "${email.leave.notification.shift1.cron}") // @Scheduled(cron = "${email.leave.notification.shift1.cron}")
public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift1Empls() throws IOException, MessagingException, MyTeamException {
//Shift 1(9:00 AM - 6:00 PM) //Shift 1(9:00 AM - 6:00 PM)
logger.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); logger.info(Shifts.SHIFT1.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -60,7 +60,7 @@ public class LeaveNotificationScheduler { ...@@ -60,7 +60,7 @@ public class LeaveNotificationScheduler {
} }
@Scheduled(cron = "${email.leave.notification.shift2.cron}") // @Scheduled(cron = "${email.leave.notification.shift2.cron}")
public void scheduleLeaveMailForShift2Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift2Empls() throws IOException, MessagingException, MyTeamException {
//Shift-2(2:00 PM - 11:00 PM)--General Shift //Shift-2(2:00 PM - 11:00 PM)--General Shift
logger.info(Shifts.SHIFT2.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); logger.info(Shifts.SHIFT2.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -68,7 +68,7 @@ public class LeaveNotificationScheduler { ...@@ -68,7 +68,7 @@ public class LeaveNotificationScheduler {
} }
@Scheduled(cron = "${email.leave.notification.shift3.cron}") // @Scheduled(cron = "${email.leave.notification.shift3.cron}")
public void scheduleLeaveMailForShift3Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift3Empls() throws IOException, MessagingException, MyTeamException {
//Shift 3(10:00 PM - 6:00 AM) //Shift 3(10:00 PM - 6:00 AM)
logger.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); logger.info(Shifts.SHIFT3.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -76,7 +76,7 @@ public class LeaveNotificationScheduler { ...@@ -76,7 +76,7 @@ public class LeaveNotificationScheduler {
} }
@Scheduled(cron = "${email.leave.notification.shift4.cron}") //@Scheduled(cron = "${email.leave.notification.shift4.cron}")
public void scheduleLeaveMailForShift4Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift4Empls() throws IOException, MessagingException, MyTeamException {
//Shift 4(7:30 AM - 3:30 PM) //Shift 4(7:30 AM - 3:30 PM)
logger.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); logger.info(Shifts.SHIFT4.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
...@@ -84,7 +84,7 @@ public class LeaveNotificationScheduler { ...@@ -84,7 +84,7 @@ public class LeaveNotificationScheduler {
} }
@Scheduled(cron = "${email.leave.notification.shift5.cron}") //@Scheduled(cron = "${email.leave.notification.shift5.cron}")
public void scheduleLeaveMailForShift5Empls() throws IOException, MessagingException, MyTeamException { public void scheduleLeaveMailForShift5Empls() throws IOException, MessagingException, MyTeamException {
//Shift 5(11:30 AM - 7:30 PM) //Shift 5(11:30 AM - 7:30 PM)
logger.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now())); logger.info(Shifts.SHIFT5.getShiftType() + " :: Execution Time - {}", dateTimeFormatter.format(LocalDateTime.now()));
......
...@@ -70,25 +70,43 @@ public class ResourceService implements IResourceService { ...@@ -70,25 +70,43 @@ public class ResourceService implements IResourceService {
public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException { public Resource addResource(Resource resourceReq, String loginEmpId) throws MyTeamException {
List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId()); List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
Resource prevAllocation = this.getLatestAllocation(resourceAllocList); Resource prevAllocation = this.getLatestAllocation(resourceAllocationList);
if (prevAllocation != null) {
if (prevAllocation.getBillingEndDate().compareTo(new Date()) == 0) { if(prevAllocation != null){
prevAllocation.setBillingEndDate(new Date()); if(prevAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID) &&
} else { prevAllocation.getBillingStartDate().compareTo(employeeService.getEmployeeById(prevAllocation.getEmployeeId()).getDateOfJoining()) != 0){
prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource. Resource projectPrevAllocation = this.getLatestAllocation(resourceAllocationList.stream().
} filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
this.updateExistedResource(prevAllocation); projectPrevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
} updateExistedResource(projectPrevAllocation);
if (resourceAllocList.isEmpty()) { prevAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
List<Resource> resourceBenchList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), MyTeamUtils.BENCH_PROJECT_ID); updateExistedResource(prevAllocation);
if (!resourceBenchList.isEmpty()) { }else {
Resource resourceBench = resourceBenchList.get(0); prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
resourceBench.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); updateExistedResource(prevAllocation);
resourceRepo.save(resourceBench);
} }
} }
// List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceReq.getEmployeeId(), resourceReq.getProjectId());
//
// Resource prevAllocation = this.getLatestAllocation(resourceAllocList);
// if (prevAllocation != null) {
// if (prevAllocation.getBillingEndDate().compareTo(new Date()) == 0) {
// prevAllocation.setBillingEndDate(new Date());
// } else {
// prevAllocation.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate())); //adding resource.
// }
// this.updateExistedResource(prevAllocation);
// } else {
// List<Resource> resourceAllocationList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
// if (!resourceAllocationList.isEmpty()) {
// Resource resourceBench = resourceAllocationList.get(0);
// resourceBench.setBillingEndDate(MyTeamDateUtils.getDayLessThanDate(resourceReq.getBillingStartDate()));
// resourceRepo.save(resourceBench);
// }
// }
return resourceRepo.save(resourceReq); return resourceRepo.save(resourceReq);
} }
...@@ -137,6 +155,22 @@ public class ResourceService implements IResourceService { ...@@ -137,6 +155,22 @@ public class ResourceService implements IResourceService {
Resource resource = resourceRepo.findById(resourceReq.getId()); Resource resource = resourceRepo.findById(resourceReq.getId());
if (resource != null) { if (resource != null) {
this.updateExistedResource(resourceReq); this.updateExistedResource(resourceReq);
Resource latestAllocation = this.getLatestAllocation(resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()));
if(latestAllocation != null && latestAllocation.getId().equals(resourceReq.getId()) &&
!latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
Resource resourceBench = new Resource();
resourceBench.setProjectId(MyTeamUtils.BENCH_PROJECT_ID);
resourceBench.setEmployeeId(resourceReq.getEmployeeId());
resourceBench.setResourceRole(resourceReq.getResourceRole());
resourceBench.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
resourceBench.setBillingEndDate(projectService.getProjectByProjectId(MyTeamUtils.BENCH_PROJECT_ID).getProjectEndDate());
resourceBench.setBillableStatus(MyTeamUtils.BENCH_BILLABILITY_STATUS);
resourceBench.setAuditFields(loginEmpId, MyTeamUtils.CREATE);
resourceRepo.save(resourceBench);
}else if(latestAllocation != null && latestAllocation.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)){
latestAllocation.setBillingStartDate(MyTeamDateUtils.getDayMoreThanDate(resourceReq.getBillingEndDate()));
updateExistedResource(latestAllocation);
}
} else { } else {
respMap.put("statusCode", 801); respMap.put("statusCode", 801);
respMap.put("message", "Record Not Found"); respMap.put("message", "Record Not Found");
...@@ -246,22 +280,23 @@ public class ResourceService implements IResourceService { ...@@ -246,22 +280,23 @@ public class ResourceService implements IResourceService {
//List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceAllocReq.getEmployeeId(), resourceAllocReq.getProjectId()); //List<Resource> resourceAllocList = resourceRepo.findByEmployeeIdAndProjectId(resourceAllocReq.getEmployeeId(), resourceAllocReq.getProjectId());
List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId()); List<Resource> resourceAllocList = resourceRepo.findByEmployeeId(resourceReq.getEmployeeId());
List<Resource> resourceListWithLatestRecord = resourceAllocList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).collect(Collectors.toList()); Resource resourceLatestRecord = getLatestAllocation(resourceAllocList.stream().
filter(r -> !r.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID)).collect(Collectors.toList()));
// resourceAllocList.stream().filter(resource -> resource.getBillingEndDate().compareTo(new Date()) >= 0).collect(Collectors.toList());
if (resourceListWithLatestRecord != null && resourceListWithLatestRecord.size() > 0) { if (resourceLatestRecord != null &&
Resource resourcePrev = resourceListWithLatestRecord.get(0);//latest resource record. resourceLatestRecord.getBillableStatus().equalsIgnoreCase(MyTeamUtils.BILLABLE_TEXT) ) {
if(!resourceLatestRecord.getProjectId().equalsIgnoreCase(resourceReq.getProjectId())){
if (!resourcePrev.getProjectId().equalsIgnoreCase(MyTeamUtils.BENCH_PROJECT_ID) && !resourceReq.getProjectId().equalsIgnoreCase(resourcePrev.getProjectId())) { message = "Resource " + resourceLatestRecord.getEmployeeId() + " already Assigned to the "
message = "Resource " + resourcePrev.getEmployeeId() + " already Assigned to the " + projectService.getProjectByProjectId(resourceLatestRecord.getProjectId()).getProjectName()
+ projectService.getProjectByProjectId(resourcePrev.getProjectId()).getProjectName() + " Project" + " from " + resourceLatestRecord.getBillingStartDate() + "to " + resourceLatestRecord.getBillingEndDate();
+ " Project" + " from " + resourcePrev.getBillingStartDate() + "to " + resourcePrev.getBillingEndDate();
isAssigned = true; isAssigned = true;
respMap.put("statusCode", 815); respMap.put("statusCode", 815);
respMap.put("message", message); respMap.put("message", message);
} }
} }
return isAssigned; return isAssigned;
} }
......
...@@ -32,9 +32,19 @@ public class MyTeamDateUtils { ...@@ -32,9 +32,19 @@ public class MyTeamDateUtils {
return yesterday; return yesterday;
} }
//public static void main(String[] args) public static Date getDayMoreThanDate(Date date)
//{ {
// MyTeamDateUtils.getDayLessThanDate(new Date()); Calendar calendar = Calendar.getInstance();
// } calendar.setTime(date);
calendar.add(Calendar.DATE, +1);
Date yesterday = calendar.getTime();
log.info("Day after Date is::"+yesterday);
return yesterday;
}
// public static void main(String[] args)
// {
// MyTeamDateUtils.getDayMoreThanDate(new Date());
// }
} }
...@@ -131,6 +131,7 @@ public class MyTeamUtils { ...@@ -131,6 +131,7 @@ public class MyTeamUtils {
public final static String BENCH_ACCOUNT="Nisum India"; public final static String BENCH_ACCOUNT="Nisum India";
public final static String BENCH_PROJECT_ID="Nisum0000"; public final static String BENCH_PROJECT_ID="Nisum0000";
public final static String BENCH_BILLABILITY_STATUS="Non-Billable"; public final static String BENCH_BILLABILITY_STATUS="Non-Billable";
public final static String BILLABLE_TEXT = "Billable";
public final static int INT_ZERO = 0; public final static int INT_ZERO = 0;
public final static int INT_TWO = 2; public final static int INT_TWO = 2;
......
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