1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.pdp.batch.service.impl;
17
18 import java.util.Date;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.pdp.PdpConstants.PayeeIdTypeCodes;
23 import org.kuali.ole.pdp.batch.service.InactivatePayeeAchAccountsService;
24 import org.kuali.ole.pdp.businessobject.PayeeACHAccount;
25 import org.kuali.ole.pdp.service.AchService;
26 import org.kuali.ole.sys.service.ReportWriterService;
27 import org.kuali.ole.vnd.businessobject.VendorDetail;
28 import org.kuali.ole.vnd.document.service.VendorService;
29 import org.kuali.rice.core.api.datetime.DateTimeService;
30 import org.kuali.rice.kim.api.identity.Person;
31 import org.kuali.rice.kim.api.identity.PersonService;
32 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
33 import org.kuali.rice.kim.api.services.IdentityManagementService;
34 import org.kuali.rice.krad.service.BusinessObjectService;
35 import org.kuali.rice.krad.util.ObjectUtils;
36
37
38
39
40 public class InactivatePayeeAchAccountsServiceImpl implements InactivatePayeeAchAccountsService {
41 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(InactivatePayeeAchAccountsServiceImpl.class);
42
43 private BusinessObjectService businessObjectService;
44 private DateTimeService dateTimeService;
45 private IdentityManagementService identityManagementService;
46 private PersonService personService;
47 private VendorService vendorService;
48 private AchService achService;
49 private ReportWriterService reportWriterService;
50
51
52
53
54 @Override
55 public boolean inactivatePayeeAchAccounts() {
56 LOG.info("Retrieving currently active Payee ACH Accounts ...");
57 List<PayeeACHAccount> accounts = achService.getActiveAchAccounts();
58
59 LOG.info("Inactivating ACH Accounts for inactive Payees and writing to the report ...");
60 reportWriterService.writeTableHeader(PayeeACHAccount.class);
61 int countEmployee = 0;
62 int countEntity = 0;
63 int countVendor = 0;
64 Date currentDate = dateTimeService.getCurrentDate();
65
66 for (PayeeACHAccount account : accounts) {
67 String idType = account.getPayeeIdentifierTypeCode();
68 String idNumber = account.getPayeeIdNumber();
69
70
71 if (StringUtils.equalsIgnoreCase(idType, PayeeIdTypeCodes.EMPLOYEE)) {
72 Person person = personService.getPersonByEmployeeId(idNumber);
73
74 if (ObjectUtils.isNull(person) || !person.isActive()) {
75 LOG.info("Inactivating Payee ACH account for employee with ID # " + idNumber);
76 account.setActive(false);
77 businessObjectService.save(account);
78 countEmployee++;
79 reportWriterService.writeTableRow(account);
80 }
81 }
82
83 else if (StringUtils.equalsIgnoreCase(idType, PayeeIdTypeCodes.ENTITY)) {
84 EntityDefault entity = identityManagementService.getEntityDefaultInfo(idNumber);
85
86 if (ObjectUtils.isNull(entity) || !entity.isActive()) {
87 LOG.info("Inactivating Payee ACH account for entity with ID # " + idNumber);
88 account.setActive(false);
89 businessObjectService.save(account);
90 countEntity++;
91 reportWriterService.writeTableRow(account);
92 }
93 }
94
95 else if (StringUtils.equalsIgnoreCase(idType, PayeeIdTypeCodes.VENDOR_ID)) {
96
97
98
99
100
101
102
103
104
105 VendorDetail vendor = vendorService.getVendorDetail(idNumber);
106
107 if (ObjectUtils.isNull(vendor) || !vendor.isActiveIndicator()) {
108 LOG.info("Inactivating Payee ACH account for vendor with vendor # " + idNumber);
109 account.setActive(false);
110 businessObjectService.save(account);
111 countVendor++;
112 reportWriterService.writeTableRow(account);
113 }
114 }
115 }
116
117 LOG.info("Total number of Employee Payee ACH accounts inacticated:" + countEmployee);
118 LOG.info("Total number of Entity Payee ACH accounts inacticated:" + countEntity);
119 LOG.info("Total number of Vendor Payee ACH accounts inacticated:" + countVendor);
120
121 reportWriterService.writeStatisticLine("%s %s", "TOTAL ACTIVE ACCOUNTS BEFORE RUNNING THE JOB:", accounts.size());
122 reportWriterService.writeStatisticLine("%s %s", "TOTAL ACCOUNTS INACTIVATED FOR EMPLOYEES: ", countEmployee);
123 reportWriterService.writeStatisticLine("%s %s", "TOTAL ACCOUNTS INACTIVATED FOR ENTITIES: ", countEntity);
124 reportWriterService.writeStatisticLine("%s %s", "TOTAL ACCOUNTS INACTIVATED FOR VENDORS: ", countVendor);
125 reportWriterService.writeStatisticLine("%s %s", "ACCOUNTS INACTIVATION DATE: ", currentDate);
126
127 return true;
128 }
129
130 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
131 this.businessObjectService = businessObjectService;
132 }
133
134 public void setDateTimeService(DateTimeService dateTimeService) {
135 this.dateTimeService = dateTimeService;
136 }
137
138 public void setIdentityManagementService(IdentityManagementService identityManagementService) {
139 this.identityManagementService = identityManagementService;
140 }
141
142 public void setPersonService(PersonService personService) {
143 this.personService = personService;
144 }
145
146 public void setVendorService(VendorService vendorService) {
147 this.vendorService = vendorService;
148 }
149
150 public void setAchService(AchService achService) {
151 this.achService = achService;
152 }
153
154 public void setReportWriterService(ReportWriterService reportWriterService) {
155 this.reportWriterService = reportWriterService;
156 }
157
158 }