1 package org.kuali.ole.select.document.service.impl;
2
3 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
4 import org.kuali.ole.docstore.common.document.BibTree;
5 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
6 import org.kuali.ole.docstore.model.bo.WorkItemDocument;
7 import org.kuali.ole.module.purap.PurapConstants;
8 import org.kuali.ole.select.bo.OLELinkPurapDonor;
9 import org.kuali.ole.select.businessobject.*;
10 import org.kuali.ole.select.document.service.OleCopyHelperService;
11 import org.kuali.ole.select.document.service.OleDocstoreHelperService;
12 import org.kuali.ole.sys.OLEConstants;
13 import org.kuali.ole.sys.context.SpringContext;
14 import org.kuali.rice.core.api.util.type.KualiDecimal;
15 import org.kuali.rice.core.api.util.type.KualiInteger;
16 import org.kuali.rice.krad.service.KRADServiceLocator;
17 import org.kuali.rice.krad.util.GlobalVariables;
18 import org.kuali.ole.docstore.common.document.Item;
19
20 import java.util.*;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24
25
26
27
28
29
30
31 public class OleCopyHelperServiceImpl implements OleCopyHelperService {
32
33 private DocstoreClientLocator docstoreClientLocator;
34 public DocstoreClientLocator getDocstoreClientLocator() {
35 if (null == docstoreClientLocator) {
36 return SpringContext.getBean(DocstoreClientLocator.class);
37 }
38 return docstoreClientLocator;
39 }
40
41 @Override
42 public HashMap<String, List<OleCopy>> getCopyListBasedOnLocation(List<OleCopy> copyList, String bibId) {
43 HashMap<String, List<OleCopy>> copyMap = new HashMap<>();
44 for (OleCopy oleCopy : copyList) {
45 Map map = new HashMap();
46 map.put(OLEConstants.OleCopy.BIB_ID, bibId);
47 map.put(OLEConstants.OleCopy.LOC, oleCopy.getLocation());
48 if (oleCopy.getInstanceId() != null)
49 map.put(OLEConstants.OleCopy.INSTANCE_ID, oleCopy.getInstanceId());
50 if (oleCopy.getReqItemId() != null)
51 map.put(OLEConstants.OleCopy.REQ_ITM_ID, oleCopy.getReqItemId());
52 if (oleCopy.getPoDocNum() != null && oleCopy.getPoItemId() != null) {
53 map.put(OLEConstants.OleCopy.PO_DOC_NUM, oleCopy.getPoDocNum());
54 map.put(OLEConstants.OleCopy.PO_ITM_ID, oleCopy.getPoItemId());
55 }
56 List<OleCopy> oleCopyList = (List<OleCopy>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCopy.class, map);
57 List<OleCopy> modCopyList = new ArrayList<>();
58 for(OleCopy copy : copyList){
59 for(OleCopy modCopy : oleCopyList){
60 if(modCopy.getCopyId().equals(copy.getCopyId())){
61 if(!modCopyList.contains(modCopy)){
62 modCopyList.add(modCopy);
63 }
64
65 }
66 }
67 }
68 if (copyMap.containsKey(oleCopy.getLocation())) {
69 List<OleCopy> oleCopiesList = copyMap.get(oleCopy.getLocation());
70 for (int modCopies=0;modCopies<modCopyList.size();modCopies++) {
71 if (!oleCopiesList.contains(modCopyList.get(modCopies))) {
72 copyMap.get(oleCopy.getLocation()).add(modCopyList.get(modCopies));
73 }
74 }
75 } else {
76 copyMap.put(oleCopy.getLocation(), modCopyList);
77 }
78 }
79 return copyMap;
80 }
81
82 @Override
83 public HashMap<String, List<OleCopy>> getCopyListBasedOnCopyNumber(List<OleCopy> copyList,Integer noOfParts) {
84 HashMap<String, List<OleCopy>> copyMap = new HashMap<>();
85 for (OleCopy oleCopy : copyList) {
86 Map map = new HashMap();
87 if(oleCopy.getCopyNumber()!=null)
88 map.put(OLEConstants.OleCopy.COPY_NUM, oleCopy.getCopyNumber());
89 map.put(OLEConstants.OleCopy.LOC, oleCopy.getLocation());
90 map.put(OLEConstants.OleCopy.INSTANCE_ID, oleCopy.getInstanceId());
91 if (oleCopy.getReqItemId() != null)
92 map.put(OLEConstants.OleCopy.REQ_ITM_ID, oleCopy.getReqItemId());
93 if (oleCopy.getPoDocNum() != null && oleCopy.getPoItemId() != null) {
94 map.put(OLEConstants.OleCopy.PO_DOC_NUM, oleCopy.getPoDocNum());
95 map.put(OLEConstants.OleCopy.PO_ITM_ID, oleCopy.getPoItemId());
96 }
97 List<OleCopy> oleCopyList = (List<OleCopy>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCopy.class, map);
98 String location = oleCopy.getLocation()!=null?oleCopy.getLocation():"";
99 String copyNum = oleCopy.getCopyNumber()!=null?"-"+oleCopy.getCopyNumber():"";
100 if(copyNum.isEmpty()){
101 int i=0;
102 List<OleCopy> copies = new ArrayList<>();
103 for(OleCopy copy : oleCopyList){
104 copies.add(copy);
105 if(noOfParts!=null &&( noOfParts==1 || copy.getPartNumber().equalsIgnoreCase(noOfParts.toString()))){
106 copyMap.put(location+i++, copies);
107 copies = new ArrayList<>();
108 }
109 }
110 }else{
111 copyMap.put(location+copyNum, oleCopyList);
112 }
113 }
114 return copyMap;
115 }
116
117
118
119
120
121
122
123
124 @Override
125 public List<OleCopies> setCopiesToLineItem(List<OleCopy> copyList, KualiInteger noOfParts, String bibId) {
126 List<OleCopies> copies = new ArrayList<OleCopies>();
127 HashMap<String, List<OleCopy>> copyListBasedOnLocation = getCopyListBasedOnLocation(copyList, bibId);
128 Iterator<Map.Entry<String, List<OleCopy>>> entries = copyListBasedOnLocation.entrySet().iterator();
129 while (entries.hasNext()) {
130 Map.Entry<String, List<OleCopy>> entry = entries.next();
131 List<OleCopy> oleCopyList = entry.getValue();
132 String caption = "";
133 LinkedHashMap<String, String> volumeNumbers = new LinkedHashMap<>();
134 String location = "";
135 int i = 0;
136 KualiInteger staringCopyNumber = oleCopyList != null && oleCopyList.size() > 0 && oleCopyList.get(0).getCopyNumber() != null ?
137 new KualiInteger(oleCopyList.get(0).getCopyNumber()) : null;
138 for (OleCopy copy : oleCopyList) {
139 i++;
140 location = copy.getLocation();
141 String[] enums = copy.getEnumeration() != null ? copy.getEnumeration().split("\\s") : new String[0];
142 if (enums != null && enums.length > 0) {
143 caption = enums[0];
144 if (caption.equals(OLEConstants.OlePersonRequestorLookupable.NULLSTRING)){
145 caption="";
146 }
147 if( enums.length > 1) {
148 volumeNumbers.put(enums[1], enums[1]);
149 }
150 if(enums.length==1 && isNumber(enums[0])){
151 volumeNumbers.put(enums[0], enums[0]);
152 caption="";
153 }
154 }
155 }
156 if (i > 0) {
157 OleRequisitionCopies oleRequisitionCopies = new OleRequisitionCopies();
158 StringBuffer volumeNumber = new StringBuffer();
159 Iterator<Map.Entry<String, String>> volumeEntries = volumeNumbers.entrySet().iterator();
160 int j = 0;
161 while (volumeEntries.hasNext()) {
162 Map.Entry<String, String> volumeEntry = volumeEntries.next();
163 if (j > 0)
164 volumeNumber.append(",");
165 j++;
166 volumeNumber.append(volumeEntry.getValue());
167 }
168 KualiDecimal copyCount = noOfParts.isGreaterThan(KualiInteger.ZERO) ? new KualiDecimal(new KualiInteger(i).divide(noOfParts)) : new KualiDecimal(oleCopyList.size());
169 oleRequisitionCopies.setItemCopies(copyCount);
170 oleRequisitionCopies.setParts(noOfParts);
171 oleRequisitionCopies.setLocationCopies(location);
172 oleRequisitionCopies.setCaption(caption);
173 oleRequisitionCopies.setVolumeNumber(volumeNumber.toString());
174 oleRequisitionCopies.setStartingCopyNumber(staringCopyNumber);
175 copies.add(oleRequisitionCopies);
176 }
177 }
178 return copies;
179 }
180
181 public static boolean isNumber(String value) {
182 for (int i = 0; i < value.length(); i++) {
183 if (!Character.isDigit(value.charAt(i)))
184 return false;
185 }
186 return true;
187 }
188
189
190
191
192
193
194
195
196 public List<OleCopy> setCopyValues(OleRequisitionCopies itemCopy, String bibId, List<String> volChar) {
197 KualiInteger noOfItems = KualiInteger.ZERO;
198 KualiInteger noOfCopies = new KualiInteger(itemCopy.getItemCopies().intValue());
199 if (noOfCopies.isGreaterThan(KualiInteger.ZERO)) {
200 if (itemCopy.getParts().isGreaterThan(KualiInteger.ZERO)) {
201 noOfItems = itemCopy.getParts().multiply(noOfCopies);
202 } else {
203 noOfItems = new KualiInteger(itemCopy.getItemCopies().intValue());
204 }
205 }
206 int itemCount = volChar.size();
207 if(itemCopy.getParts().equals(new KualiInteger(1)) && volChar.size()==0){
208 itemCount = 1;
209 }
210 List<OleCopy> copyList = new ArrayList<>();
211 Integer copyNum = itemCopy.getStartingCopyNumber() != null ? itemCopy.getStartingCopyNumber().intValue() : null;
212 if (itemCount == itemCopy.getParts().intValue()) {
213 String volNum = "";
214 for (int i = 0, partNumCount = 1, enumCount = 0; i < noOfItems.intValue(); i++) {
215 OleCopy oleCopy = new OleCopy();
216 oleCopy.setLocation(itemCopy.getLocationCopies());
217 volNum = volChar.size()>enumCount ? volChar.get(enumCount):"";
218 oleCopy.setEnumeration(itemCopy.getCaption() + " " + volNum);
219 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
220 oleCopy.setCopyNumber(copyNum!=null?copyNum.toString():null);
221 oleCopy.setPartNumber(partNumCount + "");
222 oleCopy.setBibId(bibId);
223 if (partNumCount == itemCopy.getParts().intValue()) {
224 partNumCount = 1;
225 if(copyNum != null){
226 copyNum++;
227 }
228 enumCount = 0;
229 } else {
230 enumCount++;
231 partNumCount++;
232 }
233 copyList.add(oleCopy);
234 }
235 }
236 return copyList;
237 }
238
239
240
241
242
243
244
245
246
247 public List<OleCopy> setCopyValuesForList(List<OleCopies> itemCopies, String bibId) {
248 List<OleCopy> copyList = new ArrayList<>();
249 for (OleCopies itemCopy : itemCopies) {
250 KualiInteger noOfItems = KualiInteger.ZERO;
251 KualiInteger noOfCopies = new KualiInteger(itemCopy.getItemCopies().intValue());
252 if (noOfCopies.isGreaterThan(KualiInteger.ZERO)) {
253 if (itemCopy.getParts().isGreaterThan(KualiInteger.ZERO)) {
254 noOfItems = itemCopy.getParts().multiply(noOfCopies);
255 } else {
256 noOfItems = new KualiInteger(itemCopy.getItemCopies().intValue());
257 }
258 }
259 List<String> volChar = new ArrayList<>();
260 String[] volNumbers = itemCopy.getVolumeNumber() != null ? itemCopy.getVolumeNumber().split(",") : new String[0];
261 for (String volStr : volNumbers) {
262 volChar.add(volStr);
263 }
264 int itemCount = volChar.size();
265 if(itemCopy.getParts().equals(new KualiInteger(1)) && volChar.size()==0){
266 itemCount = 1;
267 }
268 Integer copyNum = itemCopy.getStartingCopyNumber() != null ? itemCopy.getStartingCopyNumber().intValue() : null;
269 if (itemCount == itemCopy.getParts().intValue()) {
270 String volNum="";
271 for (int i = 0, partNumCount = 1, enumCount = 0; i < noOfItems.intValue(); i++) {
272 OleCopy oleCopy = new OleCopy();
273 String caption = itemCopy.getCaption()!=null?itemCopy.getCaption():"";
274 oleCopy.setLocation(itemCopy.getLocationCopies());
275 volNum = volChar.size()>enumCount ? volChar.get(enumCount):"";
276 oleCopy.setEnumeration(caption + " " + volNum);
277 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
278 oleCopy.setCopyNumber(copyNum!=null?copyNum.toString():null);
279 oleCopy.setPartNumber(partNumCount + "");
280 oleCopy.setBibId(bibId);
281 if (partNumCount == itemCopy.getParts().intValue()) {
282 partNumCount = 1;
283 if(copyNum != null){
284 copyNum++;
285 }
286 enumCount = 0;
287 } else {
288 enumCount++;
289 partNumCount++;
290 }
291 copyList.add(oleCopy);
292 }
293 }
294 }
295 return copyList;
296 }
297
298 public boolean checkCopyEntry(KualiDecimal noOfCopies, String location, Integer itemCount, KualiDecimal noOfCopiesOrdered,
299 KualiInteger noOfPartsOrdered, List<OleCopies> copiesList, String volumeNumber, boolean isRoute) {
300 boolean isValid = true;
301 isValid &= checkForCopiesAndLocation(noOfCopies, location);
302 isValid &= checkForItemCopiesGreaterThanQuantity(noOfCopies, noOfCopiesOrdered);
303 if (!isRoute)
304 isValid &= checkForTotalCopiesGreaterThanQuantity(copiesList, noOfCopies, noOfCopiesOrdered);
305 isValid &= volumeNumberValidation(itemCount, noOfPartsOrdered, volumeNumber, copiesList, isRoute);
306 return isValid;
307 }
308
309 public boolean checkForCopiesAndLocation(KualiDecimal noOfCopies, String location) {
310 boolean isValid = true;
311 if (null == noOfCopies || null == location) {
312 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
313 OLEConstants.ITEM_ITEMCOPIES_OR_LOCATIONCOPIES_SHOULDNOT_BE_NULL, new String[]{});
314 isValid = false;
315 }
316 return isValid;
317 }
318
319 public boolean checkForItemCopiesGreaterThanQuantity(KualiDecimal noOfCopies, KualiDecimal noOfCopiesOrdered) {
320 boolean isValid = true;
321 if (noOfCopies != null && noOfCopiesOrdered != null && noOfCopies.isGreaterThan(noOfCopiesOrdered)) {
322 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
323 OLEConstants.ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
324 isValid = false;
325 }
326 return isValid;
327 }
328
329
330 public boolean checkForTotalCopiesGreaterThanQuantity(List<OleCopies> copyList, KualiDecimal noOfCopies, KualiDecimal noOfCopiesOrdered) {
331 boolean isValid = true;
332 int copies = 0;
333 if (copyList.size() > 0) {
334 for (int itemCopies = 0; itemCopies < copyList.size(); itemCopies++) {
335 copies = copies + copyList.get(itemCopies).getItemCopies().intValue();
336 }
337 if (noOfCopies != null && noOfCopiesOrdered != null && noOfCopiesOrdered.isLessThan(noOfCopies.add(new KualiDecimal(copies)))) {
338 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
339 OLEConstants.TOTAL_OF_ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
340 isValid = false;
341 }
342 }
343 return isValid;
344 }
345
346 public boolean checkForTotalCopiesGreaterThanQuantityAtSubmit(List<OleCopies> copyList, KualiDecimal noOfCopiesOrdered) {
347 boolean isValid = true;
348 int copies = 0;
349 if (copyList.size() > 0) {
350 for (int itemCopies = 0; itemCopies < copyList.size(); itemCopies++) {
351 copies = copies + copyList.get(itemCopies).getItemCopies().intValue();
352 }
353 if (noOfCopiesOrdered != null && !noOfCopiesOrdered.equals(new KualiDecimal(copies))) {
354 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
355 OLEConstants.TOTAL_OF_ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
356 isValid = false;
357 }
358 } else {
359 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
360 OLEConstants.TOTAL_OF_ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
361 isValid = false;
362 }
363 return isValid;
364 }
365
366 public boolean volumeNumberValidation(Integer itemCount, KualiInteger noOfPartsOrdered, String volumeNumber, List<OleCopies> copiesList, boolean isRoute) {
367 boolean isValid = true;
368 int noOfParts = noOfPartsOrdered != null ? noOfPartsOrdered.intValue() : 0;
369 if(noOfParts > 1){
370 if (isRoute) {
371 for (OleCopies oleCopies : copiesList) {
372 if (!isValidVolumeNumber(oleCopies.getVolumeNumber(), OLEConstants.VOLUME_NUMBER_PATTERN)) {
373 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
374 OLEConstants.VOLUME_NUMBER_REGEX_VALIDATIONS, new String[]{});
375 isValid = false;
376 }
377 }
378 } else {
379 if (!isValidVolumeNumber(volumeNumber, OLEConstants.VOLUME_NUMBER_PATTERN)) {
380 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
381 OLEConstants.VOLUME_NUMBER_REGEX_VALIDATIONS, new String[]{});
382 isValid = false;
383 }
384 }
385 if (itemCount != noOfParts) {
386 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
387 OLEConstants.VOLUME_NUMBER_VALIDATIONS, new String[]{});
388 isValid = false;
389 }
390 }
391 return isValid;
392 }
393
394 public void updateRequisitionAndPOItems(OlePurchaseOrderItem olePurchaseOrderItem,
395 OleLineItemReceivingItem oleLineItemReceivingItem, OleCorrectionReceivingItem oleCorrectionReceivingItem, boolean isReceiving) {
396
397 List<OleCopy> copyList = null;
398 try{
399 if (!isReceiving && oleCorrectionReceivingItem != null) {
400 copyList = oleCorrectionReceivingItem.getCopyList() != null ? oleCorrectionReceivingItem.getCopyList() : new ArrayList<OleCopy>();
401 olePurchaseOrderItem.setOleDonors(oleCorrectionReceivingItem.getOleDonors());
402 } else {
403 copyList = oleLineItemReceivingItem.getCopyList() != null ? oleLineItemReceivingItem.getCopyList() : new ArrayList<OleCopy>();
404 olePurchaseOrderItem.setOleDonors(oleLineItemReceivingItem.getOleDonors());
405 }
406 }
407 catch (Exception e){
408 throw new RuntimeException(e);
409 }
410 Integer receivedCount = 0;
411 for (OleCopy oleCopy : copyList) {
412 if (!isReceiving && oleCorrectionReceivingItem != null)
413 oleCopy.setCorrectionItemId(oleCorrectionReceivingItem.getReceivingItemIdentifier());
414 if (oleCopy.getReceiptStatus().equalsIgnoreCase(OLEConstants.OleLineItemReceiving.RECEIVED_STATUS)) {
415 receivedCount++;
416 }
417 }
418 if (receivedCount == 0) {
419 oleLineItemReceivingItem
420 .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_NOT_RECEIVED));
421 } else if (receivedCount == copyList.size()) {
422 oleLineItemReceivingItem
423 .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED));
424 } else {
425 oleLineItemReceivingItem
426 .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_PARTIALLY_RECEIVED));
427 }
428 olePurchaseOrderItem.setReceiptStatusId(oleLineItemReceivingItem.getReceiptStatusId());
429 if (olePurchaseOrderItem.getItemQuantity().equals(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
430 olePurchaseOrderItem.setNoOfCopiesReceived(OLEConstants.OleLineItemReceiving.NOT_APPLICABLE);
431 olePurchaseOrderItem.setNoOfPartsReceived(receivedCount.toString());
432 } else if (olePurchaseOrderItem.getItemQuantity().isGreaterThan(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().equals(new KualiInteger(1))) {
433 olePurchaseOrderItem.setNoOfCopiesReceived(receivedCount.toString());
434 olePurchaseOrderItem.setNoOfPartsReceived(OLEConstants.OleLineItemReceiving.NOT_APPLICABLE);
435 } else if (olePurchaseOrderItem.getItemQuantity().isGreaterThan(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
436 olePurchaseOrderItem.setNoOfCopiesReceived(OLEConstants.OleLineItemReceiving.SEE_COPIES_SECTION);
437 olePurchaseOrderItem.setNoOfPartsReceived(OLEConstants.OleLineItemReceiving.SEE_COPIES_SECTION);
438 } else {
439 olePurchaseOrderItem.setNoOfCopiesReceived(receivedCount.toString());
440 olePurchaseOrderItem.setNoOfPartsReceived(receivedCount.toString());
441 }
442
443 Integer reqsItemId = copyList.size() > 0 ? copyList.get(0).getReqItemId() : null;
444 Map reqItemMap = new HashMap();
445 reqItemMap.put(OLEConstants.LN_ITM_IDN, reqsItemId);
446 OleRequisitionItem oleRequisitionItem = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OleRequisitionItem.class, reqItemMap);
447 if (oleRequisitionItem != null) {
448 oleRequisitionItem.setNoOfCopiesReceived(olePurchaseOrderItem.getNoOfCopiesReceived());
449 oleRequisitionItem.setNoOfPartsReceived(olePurchaseOrderItem.getNoOfPartsReceived());
450 oleRequisitionItem.setOleDonors(olePurchaseOrderItem.getOleDonors());
451 oleRequisitionItem.setReceiptStatusId(olePurchaseOrderItem.getReceiptStatusId());
452 KRADServiceLocator.getBusinessObjectService().save(oleRequisitionItem);
453 }
454 if (isReceiving) {
455 HashMap<Integer, String> receiptStatusMap = new HashMap<Integer, String>();
456 for (OleCopy oleCopy : oleLineItemReceivingItem.getCopyList()) {
457 receiptStatusMap.put(oleCopy.getCopyId(), oleCopy.getReceiptStatus());
458 }
459 updateReceivedCountFromRCVL(oleLineItemReceivingItem, receiptStatusMap);
460 for (OleCopy purCopy : olePurchaseOrderItem.getCopyList()) {
461 if (oleLineItemReceivingItem.getItemReceivedTotalQuantity().compareTo(KualiDecimal.ZERO) > 0) {
462 purCopy.setReceiptStatus(receiptStatusMap.get(purCopy.getCopyId()));
463 purCopy.setReceivingItemId(oleLineItemReceivingItem.getReceivingItemIdentifier());
464 }
465 }
466 } else {
467 if (oleCorrectionReceivingItem != null) {
468 HashMap<Integer, String> receiptStatusMap = new HashMap<Integer, String>();
469 for (OleCopy oleCopy : oleCorrectionReceivingItem.getCopyList()) {
470 receiptStatusMap.put(oleCopy.getCopyId(), oleCopy.getReceiptStatus());
471 }
472 updateReceivedCountFromRCVC(oleLineItemReceivingItem, receiptStatusMap);
473 oleCorrectionReceivingItem.setItemReceivedTotalQuantity(oleLineItemReceivingItem.getItemReceivedTotalQuantity());
474 oleCorrectionReceivingItem.setItemReceivedTotalParts(oleLineItemReceivingItem.getItemReceivedTotalParts());
475 oleCorrectionReceivingItem.setItemReturnedTotalQuantity(oleLineItemReceivingItem.getItemReturnedTotalQuantity());
476 oleCorrectionReceivingItem.setItemReturnedTotalParts(oleLineItemReceivingItem.getItemReturnedTotalParts());
477 for (OleCopy purCopy : olePurchaseOrderItem.getCopyList()) {
478 purCopy.setReceiptStatus(receiptStatusMap.get(purCopy.getCopyId()));
479 purCopy.setCorrectionItemId(oleCorrectionReceivingItem.getReceivingItemIdentifier());
480 }
481 }
482 }
483
484 KRADServiceLocator.getBusinessObjectService().save(olePurchaseOrderItem);
485 }
486
487 public int getReceiptStatusDetails(String receiptStatusCd) {
488 int receiptStatusId = 0;
489 Map<String, String> receiptStatusCdMap = new HashMap<String, String>();
490 receiptStatusCdMap.put(OLEConstants.RCPT_STATUS_CD, receiptStatusCd);
491 List<OleReceiptStatus> oleReceiptStatusList = (List) KRADServiceLocator.getBusinessObjectService().findMatching(
492 OleReceiptStatus.class, receiptStatusCdMap);
493 for (OleReceiptStatus oleReceiptStatus : oleReceiptStatusList) {
494 receiptStatusId = oleReceiptStatus.getReceiptStatusId().intValue();
495 }
496 return receiptStatusId;
497 }
498
499 private void updateReceivedCountFromRCVL(OleLineItemReceivingItem oleLineItemReceivingItem, HashMap<Integer, String> receiptStatusMap) {
500 HashMap<String, List<OleCopy>> copyListBasedOnCopyNumber = getCopyListBasedOnCopyNumber(oleLineItemReceivingItem.getCopyList(),oleLineItemReceivingItem.getItemOrderedParts().intValue());
501 Iterator<Map.Entry<String, List<OleCopy>>> entries = copyListBasedOnCopyNumber.entrySet().iterator();
502 Integer receivedCopyCount = 0;
503 Integer receivedParts=0;
504 while (entries.hasNext()) {
505 Map.Entry<String, List<OleCopy>> entry = entries.next();
506 List<OleCopy> copyMap = entry.getValue();
507 Integer copyCount = 0;
508 for (OleCopy copy : copyMap) {
509 if (receiptStatusMap.get(copy.getCopyId()) != null &&
510 receiptStatusMap.get(copy.getCopyId()).equalsIgnoreCase(OLEConstants.OleLineItemReceiving.RECEIVED_STATUS)) {
511 copyCount++;
512 receivedParts++;
513 }
514 }
515 if (copyCount != 0 &©Count <=oleLineItemReceivingItem.getItemOrderedParts().intValue()) {
516 receivedCopyCount++;
517 }
518 }
519 if (receivedCopyCount > 0) {
520 oleLineItemReceivingItem.setItemReceivedTotalQuantity(new KualiDecimal(receivedCopyCount));
521 oleLineItemReceivingItem.setItemReceivedTotalParts(new KualiDecimal(receivedParts));
522 } else {
523 oleLineItemReceivingItem.setItemReceivedTotalQuantity(KualiDecimal.ZERO);
524 oleLineItemReceivingItem.setItemReceivedTotalParts(KualiDecimal.ZERO);
525 }
526 }
527
528 private void updateReceivedCountFromRCVC(OleLineItemReceivingItem oleLineItemReceivingItem, HashMap<Integer, String> receiptStatusMap) {
529 HashMap<String, List<OleCopy>> copyListBasedOnCopyNumber = getCopyListBasedOnCopyNumber(oleLineItemReceivingItem.getCopyList(),oleLineItemReceivingItem.getItemOrderedParts().intValue());
530 Iterator<Map.Entry<String, List<OleCopy>>> entries = copyListBasedOnCopyNumber.entrySet().iterator();
531 Integer receivedCopyCount = 0;
532 Integer unReceivedCopyCount = 0;
533 while (entries.hasNext()) {
534 Map.Entry<String, List<OleCopy>> entry = entries.next();
535 List<OleCopy> copyMap = entry.getValue();
536 Integer copyCount = 0;
537 for (OleCopy copy : copyMap) {
538 if (receiptStatusMap.get(copy.getCopyId()) != null &&
539 receiptStatusMap.get(copy.getCopyId()).equalsIgnoreCase(OLEConstants.OleLineItemReceiving.RECEIVED_STATUS)) {
540 copyCount++;
541 }
542 }
543 if (copyCount == oleLineItemReceivingItem.getItemOrderedParts().intValue()) {
544 receivedCopyCount++;
545 } else {
546 unReceivedCopyCount++;
547 }
548 }
549 if (receivedCopyCount > 0) {
550 oleLineItemReceivingItem.setItemReceivedTotalQuantity(new KualiDecimal(receivedCopyCount));
551 oleLineItemReceivingItem.setItemReceivedTotalParts(new KualiDecimal(oleLineItemReceivingItem.getItemOrderedParts().intValue()));
552 } else {
553 oleLineItemReceivingItem.setItemReceivedTotalQuantity(KualiDecimal.ZERO);
554 oleLineItemReceivingItem.setItemReceivedTotalParts(KualiDecimal.ZERO);
555 }
556 if (unReceivedCopyCount > 0) {
557 oleLineItemReceivingItem.setItemReturnedTotalQuantity(new KualiDecimal(unReceivedCopyCount));
558 oleLineItemReceivingItem.setItemReturnedTotalParts(new KualiDecimal(oleLineItemReceivingItem.getItemOrderedParts().intValue()));
559 } else {
560 oleLineItemReceivingItem.setItemReturnedTotalQuantity(KualiDecimal.ZERO);
561 oleLineItemReceivingItem.setItemReturnedTotalParts(KualiDecimal.ZERO);
562 }
563 }
564
565 public boolean isValidVolumeNumber(String volumeNumber, String pattern) {
566
567 boolean valid = false;
568
569 if (pattern != null && volumeNumber != null) {
570 Pattern p = Pattern.compile(pattern);
571 Matcher m = p.matcher(volumeNumber);
572 StringBuffer sb = new StringBuffer();
573 boolean result = m.matches();
574
575 if (result) {
576 valid = true;
577 }
578 }
579 return valid;
580 }
581
582 }