1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.leave.adjustment.web;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.joda.time.LocalDate;
20 import org.kuali.kpme.core.api.principal.PrincipalHRAttributes;
21 import org.kuali.kpme.core.bo.HrBusinessObject;
22 import org.kuali.kpme.core.bo.HrBusinessObjectMaintainableImpl;
23 import org.kuali.kpme.core.service.HrServiceLocator;
24 import org.kuali.kpme.core.util.HrConstants;
25 import org.kuali.kpme.core.util.HrContext;
26 import org.kuali.kpme.core.util.TKUtils;
27 import org.kuali.kpme.tklm.common.LMConstants;
28 import org.kuali.kpme.tklm.leave.adjustment.LeaveAdjustment;
29 import org.kuali.kpme.tklm.leave.block.LeaveBlockBo;
30 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
31 import org.kuali.rice.kns.document.MaintenanceDocument;
32
33 import java.util.Map;
34
35 public class LeaveAdjustmentMaintainableServiceImpl extends HrBusinessObjectMaintainableImpl{
36
37 private static final long serialVersionUID = 2500485054776792764L;
38
39 @Override
40 public HrBusinessObject getObjectById(String id) {
41
42 return null;
43 }
44
45 @Override
46 public void saveBusinessObject() {
47 super.saveBusinessObject();
48
49
50 LeaveAdjustment la = (LeaveAdjustment) this.getBusinessObject();
51 LeaveBlockBo aLeaveBlock = new LeaveBlockBo();
52 aLeaveBlock.setPrincipalId(la.getPrincipalId());
53 aLeaveBlock.setLeaveDate(la.getEffectiveDate());
54 aLeaveBlock.setEarnCode(la.getEarnCode());
55 aLeaveBlock.setAccrualCategory(la.getAccrualCategory());
56 aLeaveBlock.setDescription("Leave Adjustment");
57 aLeaveBlock.setLeaveAmount(la.getAdjustmentAmount());
58 aLeaveBlock.setAccrualGenerated(false);
59 aLeaveBlock.setLeaveBlockType(LMConstants.LEAVE_BLOCK_TYPE.LEAVE_ADJUSTMENT_MAINT);
60 aLeaveBlock.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
61 aLeaveBlock.setBlockId(0L);
62
63 LmServiceLocator.getLeaveBlockService().saveLeaveBlock(LeaveBlockBo.to(aLeaveBlock), HrContext.getPrincipalId());
64 }
65
66 @SuppressWarnings("rawtypes")
67 @Override
68 public Map populateBusinessObject(Map<String, String> fieldValues,
69 MaintenanceDocument maintenanceDocument, String methodToCall) {
70 if (fieldValues.containsKey("principalId")
71 && StringUtils.isNotEmpty(fieldValues.get("principalId"))
72 && fieldValues.containsKey("effectiveDate")
73 && StringUtils.isNotEmpty(fieldValues.get("effectiveDate"))) {
74 LocalDate effDate = TKUtils.formatDateString(fieldValues.get("effectiveDate"));
75 PrincipalHRAttributes principalHRAttrObj = HrServiceLocator.getPrincipalHRAttributeService()
76 .getPrincipalCalendar(fieldValues.get("principalId"), effDate);
77 String lpString = (principalHRAttrObj != null) ? principalHRAttrObj.getLeavePlan() : "";
78 fieldValues.put("leavePlan", lpString);
79 }
80 return super.populateBusinessObject(fieldValues, maintenanceDocument,
81 methodToCall);
82 }
83
84
85 }