1 package org.kuali.ole.select.document.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.coa.businessobject.Account;
7 import org.kuali.ole.coa.businessobject.Chart;
8 import org.kuali.ole.coa.businessobject.ObjectCode;
9 import org.kuali.ole.coa.service.AccountService;
10 import org.kuali.ole.describe.bo.OleLocation;
11 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
12
13 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
14 import org.kuali.ole.select.businessobject.*;
15 import org.kuali.ole.select.document.OLEPurchaseOrderBatchDocument;
16 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
17 import org.kuali.ole.select.document.service.OLEPurchaseOrderBatchService;
18 import org.kuali.ole.select.document.service.OlePurchaseOrderService;
19 import org.kuali.ole.sys.context.SpringContext;
20 import org.kuali.ole.vnd.businessobject.VendorAddress;
21 import org.kuali.ole.vnd.businessobject.VendorDetail;
22 import org.kuali.rice.core.api.config.property.ConfigContext;
23
24 import org.kuali.rice.core.api.util.type.KualiDecimal;
25 import org.kuali.rice.core.api.util.type.KualiInteger;
26 import org.kuali.rice.kew.api.KewApiConstants;
27 import org.kuali.rice.kew.api.exception.WorkflowException;
28 import org.kuali.rice.krad.bo.AdHocRoutePerson;
29 import org.kuali.rice.krad.exception.ValidationException;
30 import org.kuali.rice.krad.service.BusinessObjectService;
31 import org.kuali.rice.krad.service.DocumentService;
32 import org.kuali.rice.krad.service.NoteService;
33 import org.springframework.transaction.UnexpectedRollbackException;
34
35 import java.io.*;
36 import java.math.BigDecimal;
37 import java.text.SimpleDateFormat;
38 import java.util.*;
39
40
41
42
43
44
45
46
47 public class OLEPurchaseOrderBatchServiceImpl implements OLEPurchaseOrderBatchService {
48
49 protected static final Logger LOG = Logger.getLogger(OLEPurchaseOrderBatchServiceImpl.class);
50 DocumentService documentService = (DocumentService) SpringContext.getService("documentService");
51 OlePurchaseOrderService olePurchaseOrderService = (OlePurchaseOrderService) SpringContext.getService("olePurchaseOrderService");
52 protected NoteService noteService = (NoteService) SpringContext.getService("noteService");
53 private final String FILE_HEADER = "documentNumber,documentDescription,purapDocumentIdentifier,vendorHeaderGeneratedIdentifier,vendorDetailAssignedIdentifier,assignedUserPrincipalName,recurringPaymentTypeCode,poBeginDate,poEndDate,deliveryCampusCode,deliveryBuildingCode,deliveryBuildingLine1Address,deliveryBuildingLine2Address,deliveryBuildingRoomNumber,deliveryStateCode,deliveryPostalCode,deliveryCountryCode,deliveryToEmailAddress,deliveryToName,deliveryToPhoneNumber,deliveryBuildingCode,deliveryInstructionText,itemLineNumber,itemCopyNumber,format,category,itemPriceSource,requestSource,itemQuantity,itemNoOfParts,itemListPrice,itemPublicViewIndicator,doNotClaim,itemRouteToRequestorIndicator,itemLocation,vendorItemPoNumber,accountingLineIndex,chartOfAccountsCode,accountNumber,financialObjectCode,accountLinePercent";
54 List<Chart> charts = new ArrayList<>();
55 List<Account> accounts = new ArrayList<>();
56 List<ObjectCode> objects = new ArrayList<>();
57 List<VendorDetail> vendorDetails = new ArrayList<VendorDetail>();
58 List<OleCategory> categories = new ArrayList<OleCategory>();
59 List<OleFormatType> formatTypes = new ArrayList<OleFormatType>();
60 List<OleItemPriceSource> itemPriceSources = new ArrayList<OleItemPriceSource>();
61 List<OleRequestSourceType> requestSourceTypes = new ArrayList<OleRequestSourceType>();
62 List<OleLocation> locations = new ArrayList<OleLocation>();
63 List<String> chartList = new ArrayList<>();
64 List<String> accountList = new ArrayList<>();
65 List<String> objectCodeList = new ArrayList<>();
66 List<String> vendorDetailList = new ArrayList<>();
67 List<String> categoryList = new ArrayList<>();
68 List<String> formatList = new ArrayList<>();
69 List<String> requestSourceList = new ArrayList<>();
70 List<String> priceSourceList = new ArrayList<>();
71 List<String> locationList = new ArrayList<>();
72 StringBuffer message;
73 public Integer poNumber = 0;
74
75 public void readFile(OLEPurchaseOrderBatchDocument olePurchaseOrderBatchDocument) {
76 charts = (List<Chart>) SpringContext.getBean(BusinessObjectService.class).findAll(Chart.class);
77 accounts = (List<Account>) SpringContext.getBean(BusinessObjectService.class).findAll(Account.class);
78 objects = (List<ObjectCode>) SpringContext.getBean(BusinessObjectService.class).findAll(ObjectCode.class);
79 vendorDetails = (List<VendorDetail>)SpringContext.getBean(BusinessObjectService.class).findAll(VendorDetail.class);
80 categories = (List<OleCategory>)SpringContext.getBean(BusinessObjectService.class).findAll(OleCategory.class);
81 formatTypes = (List<OleFormatType>)SpringContext.getBean(BusinessObjectService.class).findAll(OleFormatType.class);
82 itemPriceSources = (List<OleItemPriceSource>)SpringContext.getBean(BusinessObjectService.class).findAll(OleItemPriceSource.class);
83 requestSourceTypes = (List<OleRequestSourceType>)SpringContext.getBean(BusinessObjectService.class).findAll(OleRequestSourceType.class);
84 locations = (List<OleLocation>)SpringContext.getBean(BusinessObjectService.class).findAll(OleLocation.class);
85 for (Chart chart : (List<Chart>) charts) {
86 chartList.add(chart.getChartOfAccountsCode());
87 }
88 for (Account account : (List<Account>) accounts) {
89 accountList.add(account.getAccountNumber()+account.getChartOfAccountsCode());
90 }
91 for (ObjectCode objectCode : (List<ObjectCode>) objects) {
92 objectCodeList.add(objectCode.getFinancialObjectCode()+objectCode.getChartOfAccountsCode());
93 }
94 for(VendorDetail vendorDetail : vendorDetails) {
95 vendorDetailList.add(vendorDetail.getVendorHeaderGeneratedIdentifier().toString());
96 }
97 for(OleCategory category : categories) {
98 categoryList.add(category.getCategory());
99 }
100 for(OleFormatType formatType : formatTypes) {
101 formatList.add(formatType.getFormatTypeName());
102 }
103 for(OleItemPriceSource itemPriceSource : itemPriceSources) {
104 priceSourceList.add(itemPriceSource.getItemPriceSource());
105 }
106 for(OleRequestSourceType requestSourceType : requestSourceTypes) {
107 requestSourceList.add(requestSourceType.getRequestSourceType());
108 }
109 for(OleLocation location : locations) {
110 locationList.add(location.getLocationCode());
111 }
112 try {
113 message = new StringBuffer();
114 String fileDirectory = ConfigContext.getCurrentContextConfig().getProperty(org.kuali.ole.OLEConstants.STAGING_DIRECTORY);
115 List<Map> list = new ArrayList<>();
116 BufferedReader br = null;
117 if(olePurchaseOrderBatchDocument.getIngestedFile() != null){
118 BufferedWriter documentOut = new BufferedWriter(new FileWriter(fileDirectory + "/" + olePurchaseOrderBatchDocument.getIngestedFile().getOriginalFilename()));
119 String documentFileContent = new String(olePurchaseOrderBatchDocument.getIngestedFile().getBytes());
120 documentOut.write(documentFileContent);
121 documentOut.close();
122 br = new BufferedReader(new FileReader(fileDirectory + "/" + olePurchaseOrderBatchDocument.getIngestedFile().getOriginalFilename()));
123 } else {
124 br = new BufferedReader(new FileReader(fileDirectory + "/" +olePurchaseOrderBatchDocument.getUploadFileName()));
125 }
126
127 String text = null;
128 String[] lines = null;
129 String[] header = FILE_HEADER.split(",");
130 while ((text = br.readLine()) != null) {
131 if (StringUtils.isNotEmpty(text)) {
132 lines = text.split(",");
133 if (!lines[0].equals(OLEConstants.OLEPurchaseOrderBulkAmendment.DOC_NO)) {
134 Map map = new HashMap();
135 for (int i = 0; i < lines.length; i++) {
136 map.put(header[i], lines[i]);
137 }
138 list.add(map);
139 }
140 }
141 }
142
143 message.append("\n");
144 message.append("Starting Purchase Order Bulk Amendment Document :" + olePurchaseOrderBatchDocument.getDocumentNumber());
145 message.append("\n");
146 message.append("\n");
147 OlePurchaseOrderDocument purchaseOrderDocument = null;
148 String poId = "";
149 for (int index = 0; index < list.size(); index++) {
150 if (index == 0) {
151 poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
152 }
153 if (list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString().equals(poId)) {
154 poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
155 if (validatePOFields(list.get(index))) {
156 message.append("Started creating POA document for PO# : " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID));
157 message.append("\n");
158 purchaseOrderDocument = createPurchaseOrderAmendmentDocument(list.get(index), olePurchaseOrderBatchDocument.getDocumentNumber());
159 } else {
160 message.append("Creation of POA Document failed for PO# " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID) + " and Item Line Number :" + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO));
161 message.append("\n");
162 message.append("\n");
163 }
164 } else if (purchaseOrderDocument != null) {
165
166 try {
167 if(!(poNumber.equals(purchaseOrderDocument.getPurapDocumentIdentifier()))) {
168 String errorMessage = getOlePurchaseOrderService().createPurchaseOrderAmendmentDocument(purchaseOrderDocument, olePurchaseOrderBatchDocument.getDocumentNumber());
169 if (StringUtils.isNotEmpty(errorMessage)) {
170 message.append(errorMessage);
171 message.append("Failed to create POA document for PO# : " +purchaseOrderDocument.getPurapDocumentIdentifier());
172 message.append("\n");
173 } else {
174 message.append("Successfully created POA document for PO# : " + purchaseOrderDocument.getPurapDocumentIdentifier());
175 message.append("\n");
176 }
177 }
178 } catch (Exception e){
179 message.append("Creation of POA Document failed for PO Doc# "+purchaseOrderDocument.getDocumentNumber());
180 message.append("\n");
181 }
182 purchaseOrderDocument = null;
183 poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
184 if (list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString().equals(poId)) {
185 if (validatePOFields(list.get(index))) {
186 message.append("Started creating POA document for PO# : " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID));
187 message.append("\n");
188 purchaseOrderDocument = createPurchaseOrderAmendmentDocument(list.get(index), olePurchaseOrderBatchDocument.getDocumentNumber());
189
190 } else {
191 message.append("Creation of POA Document failed for PO# " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID) + " and Item Line Number :" + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO));
192 message.append("\n");
193 message.append("\n");
194 }
195 }
196
197
198 } else {
199 if(purchaseOrderDocument == null) {
200 poId = list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
201 if (list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString().equals(poId)) {
202 if (validatePOFields(list.get(index))) {
203 message.append("Started creating POA document for PO# : " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID));
204 message.append("\n");
205 purchaseOrderDocument = createPurchaseOrderAmendmentDocument(list.get(index), olePurchaseOrderBatchDocument.getDocumentNumber());
206
207 } else {
208 message.append("Creation of POA Document failed for PO# " + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID) + " and Item Line Number :" + list.get(index).get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO));
209 message.append("\n");
210 message.append("\n");
211 }
212 }
213
214 }
215 }
216 }
217 if(purchaseOrderDocument != null) {
218 try {
219 if (!(poNumber.equals(purchaseOrderDocument.getPurapDocumentIdentifier()))) {
220 String errorMessage = getOlePurchaseOrderService().createPurchaseOrderAmendmentDocument(purchaseOrderDocument, olePurchaseOrderBatchDocument.getDocumentNumber());
221 if (StringUtils.isNotEmpty(errorMessage)) {
222 message.append(errorMessage);
223 message.append("\n");
224 message.append("Failed to create POA document for PO# : "+purchaseOrderDocument.getPurapDocumentIdentifier());
225 message.append("\n");
226 } else {
227 message.append("Successfully created POA document for PO# : " + purchaseOrderDocument.getPurapDocumentIdentifier());
228 message.append("\n");
229 }
230 }
231 } catch(Exception e) {
232 LOG.info("Error Occurred "+e.getMessage());
233 }
234 }
235 br.close();
236 writeFile();
237 } catch (Exception e) {
238 message.append("Error Occurred while creating POA Document");
239 message.append("\n");
240 }
241
242 }
243
244 public OlePurchaseOrderDocument createPurchaseOrderAmendmentDocument(Map map, String docNumber) {
245 String purapDocumentIdentifier = (String) map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID);
246 OlePurchaseOrderDocument purchaseOrderDocument = null;
247 if (purapDocumentIdentifier != null) {
248 if(purchaseOrderDocument == null) {
249 Map poMap = new HashMap();
250 poMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID, purapDocumentIdentifier);
251 purchaseOrderDocument = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OlePurchaseOrderDocument.class, poMap);
252 }
253
254 try {
255 purchaseOrderDocument = updateDocument(purchaseOrderDocument, map);
256 purchaseOrderDocument = updateVendor(purchaseOrderDocument, map);
257 int lineNumber = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO).toString());
258 purchaseOrderDocument = updateItem(purchaseOrderDocument, lineNumber, map);
259 purchaseOrderDocument = updateAccount(purchaseOrderDocument, lineNumber, map);
260 } catch (UnexpectedRollbackException re) {
261 message.append(re.getMessage());
262 message.append("\n");
263 } catch (ValidationException ve) {
264 message.append(ve.getMessage());
265 message.append("\n");
266 } catch (Exception ex) {
267 message.append("Failed to create POA document for PO document number : " + purchaseOrderDocument.getDocumentNumber());
268 message.append("\n");
269
270 }
271 }
272 sendFyiForAccount(purchaseOrderDocument);
273 return purchaseOrderDocument;
274 }
275
276
277 public OlePurchaseOrderDocument updateItem(OlePurchaseOrderDocument purchaseOrderDocument, int itemLineNumber, Map map) throws Exception{
278 for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderDocument.getItemsActiveOnly()) {
279 if (olePurchaseOrderItem.getItemLineNumber() != null && olePurchaseOrderItem.getItemLineNumber() == itemLineNumber) {
280 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_ITEM_NO).equals("null")) {
281 olePurchaseOrderItem.setVendorItemPoNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_ITEM_NO).toString());
282 } else {
283 olePurchaseOrderItem.setVendorItemPoNumber("");
284 }
285 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC) != null) {
286 olePurchaseOrderItem.setItemLocation(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC).toString());
287 }
288 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIST_PRC).equals("null")) {
289 olePurchaseOrderItem.setItemListPrice(new KualiDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIST_PRC).toString()));
290 }
291 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_QTY).equals("null")) {
292 olePurchaseOrderItem.setItemQuantity(new KualiDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_QTY).toString()));
293 }
294 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).equals("null")) {
295 olePurchaseOrderItem.setItemNoOfParts(new KualiInteger(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).toString()));
296 }
297 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_PUB_VIEW_IND).equals("null")) {
298 boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_PUB_VIEW_IND).toString());
299 olePurchaseOrderItem.setItemPublicViewIndicator(indicator);
300 }
301 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DO_NOT_CLAIM).equals("null")) {
302 boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DO_NOT_CLAIM).toString());
303 olePurchaseOrderItem.setDoNotClaim(indicator);
304 }
305 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_ROUTE_IND).equals("null")) {
306 boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_ROUTE_IND).toString());
307 olePurchaseOrderItem.setItemRouteToRequestorIndicator(indicator);
308 }
309 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).equals("null")) {
310 olePurchaseOrderItem.setItemNoOfParts(new KualiInteger(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).toString()));
311 }
312 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_COPY_NO).equals("null")) {
313 olePurchaseOrderItem.setCopyNumber((map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_COPY_NO).toString()));
314 }
315 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).equals("null")) {
316 if (getFormatId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).toString()) != null) {
317 olePurchaseOrderItem.setFormatTypeId(getFormatId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).toString()));
318 }
319 }
320 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).equals("null")) {
321 if (getCategoryId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).toString()) != null) {
322 olePurchaseOrderItem.setCategoryId(getCategoryId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).toString()));
323 }
324 }
325 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).equals("null")) {
326 if (getItemPriceSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).toString()) != null) {
327 olePurchaseOrderItem.setItemPriceSourceId(getItemPriceSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).toString()));
328 }
329 }
330 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).equals("null")) {
331 if (getRequestSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).toString()) != null) {
332 olePurchaseOrderItem.setRequestSourceTypeId(getRequestSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).toString()));
333 }
334 }
335 }
336 }
337 return purchaseOrderDocument;
338
339 }
340
341 public OlePurchaseOrderDocument updateAccount(OlePurchaseOrderDocument purchaseOrderDocument, int itemLineNumber, Map map) {
342 for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderDocument.getItemsActiveOnly()) {
343 if (olePurchaseOrderItem.getItemLineNumber() != null && olePurchaseOrderItem.getItemLineNumber() == itemLineNumber) {
344
345 if(!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LINE_INDEX).equals("null")) {
346 int index = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LINE_INDEX).toString()) - 1;
347 PurApAccountingLine accountingLine = olePurchaseOrderItem.getSourceAccountingLines().get(index);
348 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).equals("null")) {
349 accountingLine.setChartOfAccountsCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString());
350 }
351 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).equals("null")) {
352 accountingLine.setAccountNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).toString());
353 }
354 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).equals("null")) {
355 accountingLine.setFinancialObjectCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).toString());
356 }
357 if(!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LIN_PERC).equals("null")) {
358 accountingLine.setAccountLinePercent(new BigDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LIN_PERC).toString()));
359 }
360
361 }
362 }
363 }
364 return purchaseOrderDocument;
365 }
366
367 public OlePurchaseOrderDocument updateDocument(OlePurchaseOrderDocument purchaseOrderDocument, Map map) {
368
369 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ST_CD).equals("null")) {
370 purchaseOrderDocument.setDeliveryStateCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ST_CD).toString());
371 }
372 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ROOM_NO).equals("null")) {
373 purchaseOrderDocument.setDeliveryBuildingRoomNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ROOM_NO).toString());
374 }
375 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE1_ADDR).equals("null")) {
376 purchaseOrderDocument.setDeliveryBuildingLine1Address(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE1_ADDR).toString());
377 }
378 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE2_ADDR).equals("null")) {
379 purchaseOrderDocument.setDeliveryBuildingLine2Address(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE2_ADDR).toString());
380 }
381 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_CAMPUS_CD).equals("null")) {
382 purchaseOrderDocument.setDeliveryCampusCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_CAMPUS_CD).toString());
383 }
384 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_COUNTRY_CD).equals("null")) {
385 purchaseOrderDocument.setDeliveryCountryCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_COUNTRY_CD).toString());
386 }
387 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_POSTAL_CD).equals("null")) {
388 purchaseOrderDocument.setDeliveryPostalCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_POSTAL_CD).toString());
389 }
390 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_BUL_CD).equals("null")) {
391 purchaseOrderDocument.setDeliveryBuildingCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_BUL_CD).toString());
392 }
393 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_EMAIL_ADDR).equals("null")) {
394 purchaseOrderDocument.setDeliveryToEmailAddress(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_EMAIL_ADDR).toString());
395 }
396 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_NAME).equals("null")) {
397 purchaseOrderDocument.setDeliveryToName(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_NAME).toString());
398 }
399 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_PHONE_NO).equals("null")) {
400 purchaseOrderDocument.setDeliveryToPhoneNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_PHONE_NO).toString());
401 }
402 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_INST_NT).equals("null")) {
403 purchaseOrderDocument.setDeliveryInstructionText(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_INST_NT).toString());
404 }
405
406 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DOCUMENT_DESC).equals("null")) {
407 purchaseOrderDocument.getDocumentHeader().setDocumentDescription(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DOCUMENT_DESC).toString());
408 }
409 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ASSIGN_TO_PRCPL_NM).equals("null")) {
410 purchaseOrderDocument.setAssignedUserPrincipalName(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ASSIGN_TO_PRCPL_NM).toString());
411 }
412 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).equals("")) {
413 purchaseOrderDocument.setRecurringPaymentTypeCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).toString());
414 } else {
415 purchaseOrderDocument.setRecurringPaymentTypeCode(null);
416 }
417 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).equals("")){
418 SimpleDateFormat format = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.TIMESTAMP_FORMAT);
419 purchaseOrderDocument.setPurchaseOrderBeginDate(java.sql.Date.valueOf(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).toString()));
420 } else {
421 purchaseOrderDocument.setPurchaseOrderBeginDate(null);
422 }
423 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).equals("")) {
424 SimpleDateFormat format = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.TIMESTAMP_FORMAT);
425 purchaseOrderDocument.setPurchaseOrderEndDate(java.sql.Date.valueOf(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).toString()));
426 } else{
427 purchaseOrderDocument.setPurchaseOrderEndDate(null);
428 }
429
430 return purchaseOrderDocument;
431 }
432
433 public OlePurchaseOrderDocument updateVendor(OlePurchaseOrderDocument purchaseOrderDocument,Map map) {
434 Map vendorMap = new HashMap();
435 vendorMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER, map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER));
436 vendorMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.VEN_DTL_ASSIGN_ID, map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VEN_DTL_ASSIGN_ID));
437 VendorDetail vendorDetail = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(VendorDetail.class, vendorMap);
438 if (vendorDetail != null) {
439 purchaseOrderDocument.setVendorName(vendorDetail.getVendorName());
440 purchaseOrderDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier());
441 purchaseOrderDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier());
442 purchaseOrderDocument.setVendorAliasName("");
443 purchaseOrderDocument.setVendorPaymentTermsCode(vendorDetail.getVendorPaymentTermsCode());
444 purchaseOrderDocument.setVendorShippingPaymentTermsCode(vendorDetail.getVendorShippingPaymentTermsCode());
445 for (VendorAddress vendorAddress : vendorDetail.getVendorAddresses()) {
446 if (vendorAddress.isActive() && vendorAddress.isVendorDefaultAddressIndicator()) {
447 purchaseOrderDocument.setVendorCityName(vendorAddress.getVendorCityName());
448 purchaseOrderDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address());
449 purchaseOrderDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address());
450 purchaseOrderDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode());
451 purchaseOrderDocument.setVendorStateCode(vendorAddress.getVendorStateCode());
452 purchaseOrderDocument.setVendorPostalCode(vendorAddress.getVendorZipCode());
453 }
454 }
455 }
456 return purchaseOrderDocument;
457 }
458
459 public void writeFile() {
460 String fileName = OLEConstants.OLEPurchaseOrderBulkAmendment.FILE_NM;
461 String filePath = ConfigContext.getCurrentContextConfig().getProperty(org.kuali.ole.OLEConstants.STAGING_DIRECTORY) + OLEConstants.POBA_DIRECTORY;
462 try {
463 BufferedWriter writer = new BufferedWriter(new FileWriter(filePath + fileName));
464 writer.write(message.toString());
465 writer.close();
466
467 LOG.info("POBA output file created successfully");
468 } catch (IOException ioException) {
469 ioException.printStackTrace();
470 }
471 }
472
473 public Set<String> createFileForPOBA(OLEPurchaseOrderBatchDocument olePurchaseOrderBatchDocument) throws Exception {
474
475 String fileDirectory = ConfigContext.getCurrentContextConfig().getProperty(org.kuali.ole.OLEConstants.STAGING_DIRECTORY);
476 BufferedWriter documentOut = new BufferedWriter(new FileWriter(fileDirectory + "/" + olePurchaseOrderBatchDocument.getDocIdIngestFile().getOriginalFilename()));
477 String documentFileContent = new String(olePurchaseOrderBatchDocument.getDocIdIngestFile().getBytes());
478 documentOut.write(documentFileContent);
479 documentOut.close();
480 BufferedReader br = new BufferedReader(new FileReader(fileDirectory + "/" + olePurchaseOrderBatchDocument.getDocIdIngestFile().getOriginalFilename()));
481 String text = null;
482 Set<String> poIds = new TreeSet<String>();
483 while ((text = br.readLine()) != null) {
484 if (StringUtils.isNotEmpty(text)) {
485 poIds.add(text);
486 }
487 }
488 br.close();
489 return poIds;
490 }
491
492 public boolean validatePOFields(Map map) {
493 String poId = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString();
494 Map invMap = new HashMap();
495
496 boolean result = true;
497 if (!vendorDetailList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER))) {
498 message.append("Invalid Vendor Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER));
499 message.append("\n");
500 result = result & false;
501 }
502 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).equals("null") && !categoryList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD))) {
503 message.append("Invalid Category Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD));
504 message.append("\n");
505 result = result & false;
506 }
507 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).equals("null") && !formatList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD))) {
508 message.append("Invalid Format Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD));
509 message.append("\n");
510 result = result & false;
511 }
512 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).equals("null") && !priceSourceList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE))) {
513 message.append("Invalid Item Price Source Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE));
514 message.append("\n");
515 result = result & false;
516 }
517 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).equals("null") && !requestSourceList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE))) {
518 message.append("Invalid Request Source Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE));
519 message.append("\n");
520 result = result & false;
521 }
522 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC).equals("null") && !locationList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC))) {
523 message.append("Invalid Location code : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC));
524 message.append("\n");
525 result = result & false;
526 }
527 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD) != null && !chartList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD))) {
528 message.append("Invalid Chart code : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD));
529 message.append("\n");
530 result = result & false;
531 }
532 String accountNumber = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).toString()+map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString();
533 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO) != null && !accountList.contains(accountNumber)){
534 message.append("Invalid Account Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO));
535 message.append("\n");
536 result = result & false;
537 }
538 String objectCode = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).toString()+map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString();
539 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD) != null && !objectCodeList.contains(objectCode)) {
540 message.append("Invalid Financial Object Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD));
541 message.append("\n");
542 result = result & false;
543 }
544 if(!result) {
545 poNumber = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID).toString());
546 }
547 return result;
548 }
549
550
551 public void downloadCSV(Set<String> poIds) {
552
553 String fileDirectory = ConfigContext.getCurrentContextConfig().getProperty(org.kuali.ole.OLEConstants.STAGING_DIRECTORY);
554 FileWriter fileWriter = null;
555 String NEW_LINE_SEPARATOR = "\n";
556 String COMMA_DELIMITER = ",";
557 try {
558 Date date = new java.util.Date();
559 String fileCreationDate = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.DATE_FORMAT).format(date);
560 fileWriter = new FileWriter(fileDirectory + OLEConstants.OLEPurchaseOrderBulkAmendment.POBA+fileCreationDate+OLEConstants.OLEPurchaseOrderBulkAmendment.OUTPUT_FILE_NAME);
561 fileWriter.append(FILE_HEADER.toString());
562 fileWriter.append(NEW_LINE_SEPARATOR);
563 for (String poid : poIds) {
564 Map poMap = new HashMap();
565 poMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_ID, poid);
566 poMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.PUR_AP_CUR_IND, true);
567 OlePurchaseOrderDocument purchaseOrderDocument = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OlePurchaseOrderDocument.class, poMap);
568 for (OlePurchaseOrderItem item : (List<OlePurchaseOrderItem>) purchaseOrderDocument.getItems()) {
569 Integer accountingLineNumber = 1;
570 if (item.getItemLineNumber() != null) {
571 for (PurApAccountingLine accountingLine : (List<PurApAccountingLine>) item.getSourceAccountingLines()) {
572 fileWriter.append(purchaseOrderDocument.getDocumentNumber());
573 fileWriter.append(COMMA_DELIMITER);
574 fileWriter.append(purchaseOrderDocument.getDocumentHeader().getDocumentDescription());
575 fileWriter.append(COMMA_DELIMITER);
576 fileWriter.append(purchaseOrderDocument.getPurapDocumentIdentifier().toString());
577 fileWriter.append(COMMA_DELIMITER);
578 fileWriter.append(purchaseOrderDocument.getVendorHeaderGeneratedIdentifier().toString());
579 fileWriter.append(COMMA_DELIMITER);
580 fileWriter.append(purchaseOrderDocument.getVendorDetailAssignedIdentifier().toString());
581 fileWriter.append(COMMA_DELIMITER);
582 fileWriter.append(purchaseOrderDocument.getAssignedUserPrincipalName());
583 fileWriter.append(COMMA_DELIMITER);
584 fileWriter.append(purchaseOrderDocument.getRecurringPaymentTypeCode());
585 fileWriter.append(COMMA_DELIMITER);
586 fileWriter.append(purchaseOrderDocument.getPurchaseOrderBeginDate() != null ? purchaseOrderDocument.getPurchaseOrderBeginDate().toString() : null);
587 fileWriter.append(COMMA_DELIMITER);
588 fileWriter.append(purchaseOrderDocument.getPurchaseOrderEndDate() != null ? purchaseOrderDocument.getPurchaseOrderEndDate().toString() : null);
589 fileWriter.append(COMMA_DELIMITER);
590 fileWriter.append(purchaseOrderDocument.getDeliveryCampusCode());
591 fileWriter.append(COMMA_DELIMITER);
592 fileWriter.append(purchaseOrderDocument.getDeliveryBuildingCode());
593 fileWriter.append(COMMA_DELIMITER);
594 fileWriter.append(purchaseOrderDocument.getDeliveryBuildingLine1Address());
595 fileWriter.append(COMMA_DELIMITER);
596 fileWriter.append(purchaseOrderDocument.getDeliveryBuildingLine2Address());
597 fileWriter.append(COMMA_DELIMITER);
598 fileWriter.append(purchaseOrderDocument.getDeliveryBuildingRoomNumber());
599 fileWriter.append(COMMA_DELIMITER);
600 fileWriter.append(purchaseOrderDocument.getDeliveryStateCode());
601 fileWriter.append(COMMA_DELIMITER);
602 fileWriter.append(purchaseOrderDocument.getDeliveryPostalCode());
603 fileWriter.append(COMMA_DELIMITER);
604 fileWriter.append(purchaseOrderDocument.getDeliveryCountryCode());
605 fileWriter.append(COMMA_DELIMITER);
606 fileWriter.append(purchaseOrderDocument.getDeliveryToEmailAddress());
607 fileWriter.append(COMMA_DELIMITER);
608 fileWriter.append(purchaseOrderDocument.getDeliveryToName().replace(",", ""));
609 fileWriter.append(COMMA_DELIMITER);
610 fileWriter.append(purchaseOrderDocument.getDeliveryToPhoneNumber());
611 fileWriter.append(COMMA_DELIMITER);
612 fileWriter.append(purchaseOrderDocument.getDeliveryBuildingCode());
613 fileWriter.append(COMMA_DELIMITER);
614 fileWriter.append(purchaseOrderDocument.getDeliveryInstructionText());
615 fileWriter.append(COMMA_DELIMITER);
616 fileWriter.append(item.getItemLineNumber().toString());
617 fileWriter.append(COMMA_DELIMITER);
618 fileWriter.append(item.getCopyNumber());
619 fileWriter.append(COMMA_DELIMITER);
620 fileWriter.append(item.getFormatTypeName() != null ? item.getFormatTypeName().getFormatTypeName():null);
621 fileWriter.append(COMMA_DELIMITER);
622 fileWriter.append(item.getCategory() != null ? item.getCategory().getCategory() : null);
623 fileWriter.append(COMMA_DELIMITER);
624 fileWriter.append(item.getItemPriceSource() != null ?item.getItemPriceSource().getItemPriceSource() : null);
625 fileWriter.append(COMMA_DELIMITER);
626 fileWriter.append(item.getOleRequestSourceType() != null ? item.getOleRequestSourceType().getRequestSourceType() : null);
627 fileWriter.append(COMMA_DELIMITER);
628 fileWriter.append(item.getItemQuantity().toString());
629 fileWriter.append(COMMA_DELIMITER);
630 fileWriter.append(item.getItemNoOfParts().toString());
631 fileWriter.append(COMMA_DELIMITER);
632 fileWriter.append(item.getItemListPrice().toString());
633 fileWriter.append(COMMA_DELIMITER);
634 Boolean publicViewIndicator = item.isItemPublicViewIndicator();
635 fileWriter.append(publicViewIndicator.toString());
636 fileWriter.append(COMMA_DELIMITER);
637 Boolean doNotClaimIndicator = item.isDoNotClaim();
638 fileWriter.append(doNotClaimIndicator.toString());
639 fileWriter.append(COMMA_DELIMITER);
640 Boolean routeToRequestorIndicator = item.isItemRouteToRequestorIndicator();
641 fileWriter.append(routeToRequestorIndicator.toString());
642 fileWriter.append(COMMA_DELIMITER);
643 fileWriter.append(item.getItemLocation());
644 fileWriter.append(COMMA_DELIMITER);
645 fileWriter.append(item.getVendorItemPoNumber());
646 fileWriter.append(COMMA_DELIMITER);
647 fileWriter.append(accountingLineNumber.toString());
648 fileWriter.append(COMMA_DELIMITER);
649 fileWriter.append(accountingLine.getChartOfAccountsCode());
650 fileWriter.append(COMMA_DELIMITER);
651 fileWriter.append(accountingLine.getAccountNumber());
652 fileWriter.append(COMMA_DELIMITER);
653 fileWriter.append(accountingLine.getFinancialObjectCode());
654 fileWriter.append(COMMA_DELIMITER);
655 fileWriter.append(accountingLine.getAccountLinePercent().toString());
656 fileWriter.append(NEW_LINE_SEPARATOR);
657 ++accountingLineNumber;
658 }
659 }
660 }
661 }
662 fileWriter.flush();
663 fileWriter.close();
664 } catch (Exception e) {
665 LOG.info(e.getMessage());
666 }
667 }
668
669 public void createPOBADirectory() {
670 String stagingDirectory = ConfigContext.getCurrentContextConfig().getProperty(org.kuali.ole.sys.OLEConstants.STAGING_DIRECTORY_KEY);
671 String fileLocation = stagingDirectory + org.kuali.ole.sys.OLEConstants.POBA_DIRECTORY;
672 File fileLocationDir = new File(fileLocation);
673 if (!(fileLocationDir.exists())) {
674 fileLocationDir.mkdir();
675 }
676 }
677
678 public DocumentService getDocumentService() {
679 if (documentService == null) {
680 documentService = (DocumentService) SpringContext.getService("documentService");
681 }
682 return documentService;
683 }
684
685 public OlePurchaseOrderService getOlePurchaseOrderService() {
686 if (olePurchaseOrderService == null) {
687 olePurchaseOrderService = (OlePurchaseOrderService) SpringContext.getService("olePurchaseOrderService");
688 }
689 return olePurchaseOrderService;
690 }
691
692
693 public void sendFyiForAccount(PurchaseOrderDocument po) {
694
695 List<AdHocRoutePerson> fyiList = createFyiFiscalOfficerListForAmendGlEntries(po);
696 String annotation = "Amendment to Purchase Order " + po.getPurapDocumentIdentifier() + "( Document id " + po.getDocumentNumber() + ")" +
697 " in the batch process(POBA).";
698 String responsibilityNote = " ";
699 if(fyiList != null && fyiList.size() > 0) {
700 for (AdHocRoutePerson adHocPerson : fyiList) {
701 try {
702 po.appSpecificRouteDocumentToUser(
703 po.getDocumentHeader().getWorkflowDocument(),
704 adHocPerson.getPerson().getPrincipalId(),
705 annotation,
706 responsibilityNote);
707 } catch (WorkflowException e) {
708 throw new RuntimeException("Error routing fyi for document with id " + po.getDocumentNumber(), e);
709 }
710 }
711 }
712 }
713
714 protected List<AdHocRoutePerson> createFyiFiscalOfficerListForAmendGlEntries(PurchaseOrderDocument po) {
715
716 List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
717 Map fiscalOfficers = new HashMap();
718 AdHocRoutePerson adHocRoutePerson = null;
719 for (PurApAccountingLine account : (List<PurApAccountingLine>)po.getSourceAccountingLines()) {
720 Account acct = SpringContext.getBean(AccountService.class).getByPrimaryId(account.getChartOfAccountsCode(),
721 account.getAccountNumber());
722 if (acct != null) {
723 String principalName = acct.getAccountFiscalOfficerUser().getPrincipalName();
724
725 if (fiscalOfficers.containsKey(principalName) == false) {
726 fiscalOfficers.put(principalName, principalName);
727 adHocRoutePerson = new AdHocRoutePerson();
728 adHocRoutePerson.setId(principalName);
729 adHocRoutePerson.setActionRequested(KewApiConstants.ACTION_REQUEST_FYI_REQ);
730 adHocRoutePersons.add(adHocRoutePerson);
731 }
732 }
733 }
734 return adHocRoutePersons;
735 }
736
737 public Integer getCategoryId(String name) {
738 Integer id = null;
739 Map idMap = new HashMap();
740 idMap.put("category",name);
741 OleCategory category = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleCategory.class,idMap);
742 if(category != null) {
743 return category.getCategoryId().intValue();
744 }
745 return id;
746 }
747
748 public Integer getFormatId(String name) {
749 Integer id = null;
750 Map idMap = new HashMap();
751 idMap.put("formatTypeName",name);
752 OleFormatType formatType = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleFormatType.class,idMap);
753 if(formatType != null) {
754 return formatType.getFormatTypeId().intValue();
755 }
756 return id;
757 }
758
759 public Integer getItemPriceSourceId(String name) {
760 Integer id = null;
761 Map idMap = new HashMap();
762 idMap.put("itemPriceSource",name);
763 OleItemPriceSource itemPriceSource = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleItemPriceSource.class,idMap);
764 if(itemPriceSource != null) {
765 return itemPriceSource.getItemPriceSourceId().intValue();
766 }
767 return id;
768 }
769
770 public Integer getRequestSourceId(String name) {
771 Integer id = null;
772 Map idMap = new HashMap();
773 idMap.put("requestSourceType",name);
774 OleRequestSourceType requestSourceType = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleRequestSourceType.class,idMap);
775 if(requestSourceType != null) {
776 return requestSourceType.getRequestSourceTypeId().intValue();
777 }
778 return id;
779 }
780
781
782
783 }