1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.ole.module.purap.PurapConstants;
21 import org.kuali.ole.module.purap.document.service.BulkReceivingService;
22 import org.kuali.ole.module.purap.document.service.RequisitionService;
23 import org.kuali.ole.module.purap.document.validation.event.AttributedContinuePurapEvent;
24 import org.kuali.ole.module.purap.util.PurapSearchUtils;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.vnd.VendorConstants;
27 import org.kuali.ole.vnd.businessobject.VendorAddress;
28 import org.kuali.ole.vnd.businessobject.VendorDetail;
29 import org.kuali.ole.vnd.document.service.VendorService;
30 import org.kuali.rice.core.api.datetime.DateTimeService;
31 import org.kuali.rice.kim.api.identity.Person;
32 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33 import org.kuali.rice.kns.service.DataDictionaryService;
34 import org.kuali.rice.krad.bo.DocumentHeader;
35 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
36 import org.kuali.rice.krad.util.GlobalVariables;
37 import org.kuali.rice.krad.util.KRADPropertyConstants;
38 import org.kuali.rice.location.api.country.Country;
39 import org.kuali.rice.location.api.country.CountryService;
40
41 import java.util.LinkedHashMap;
42 import java.util.List;
43
44 public class BulkReceivingDocument extends ReceivingDocumentBase {
45
46 protected static final Logger LOG = Logger.getLogger(BulkReceivingDocument.class);
47
48 protected String shipmentWeight;
49 protected Integer noOfCartons;
50 protected String trackingNumber;
51 protected String vendorAddressInternationalProvinceName;
52 protected String vendorNoteText;
53
54
55
56
57 protected Integer goodsDeliveredVendorHeaderGeneratedIdentifier;
58 protected Integer goodsDeliveredVendorDetailAssignedIdentifier;
59 protected String goodsDeliveredVendorNumber;
60 protected String deliveryAdditionalInstructionText;
61
62 protected String requestorPersonName;
63 protected String requestorPersonPhoneNumber;
64 protected String requestorPersonEmailAddress;
65
66 protected String preparerPersonName;
67 protected String preparerPersonPhoneNumber;
68
69 protected String deliveryCampusName;
70 protected String institutionContactName;
71 protected String institutionContactPhoneNumber;
72 protected String institutionContactEmailAddress;
73
74 protected VendorDetail alternateVendorDetail;
75
76
77
78
79 protected String goodsDeliveredVendorName;
80 protected String vendorContact;
81
82 public BulkReceivingDocument() {
83 super();
84 }
85
86 @Override
87 public void initiateDocument() {
88 setShipmentReceivedDate(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate());
89 }
90
91 public void populateBulkReceivingFromPurchaseOrder(PurchaseOrderDocument po) {
92
93 setPurchaseOrderIdentifier(po.getPurapDocumentIdentifier());
94 getDocumentHeader().setOrganizationDocumentNumber(po.getDocumentHeader().getOrganizationDocumentNumber());
95 setAccountsPayablePurchasingDocumentLinkIdentifier(po.getAccountsPayablePurchasingDocumentLinkIdentifier());
96
97
98 setVendorHeaderGeneratedIdentifier(po.getVendorHeaderGeneratedIdentifier());
99 setVendorDetailAssignedIdentifier(po.getVendorDetailAssignedIdentifier());
100 setVendorName(po.getVendorName());
101 setVendorNumber(po.getVendorNumber());
102 setVendorLine1Address(po.getVendorLine1Address());
103 setVendorLine2Address(po.getVendorLine2Address());
104 setVendorCityName(po.getVendorCityName());
105 setVendorStateCode(po.getVendorStateCode());
106 setVendorPostalCode(po.getVendorPostalCode());
107 setVendorCountryCode(po.getVendorCountryCode());
108 setVendorDetail(po.getVendorDetail());
109 setVendorNumber(po.getVendorNumber());
110 setVendorAddressInternationalProvinceName(po.getVendorAddressInternationalProvinceName());
111 setVendorNoteText(po.getVendorNoteText());
112 setVendorAddressGeneratedIdentifier(po.getVendorAddressGeneratedIdentifier());
113
114
115 setAlternateVendorName(po.getAlternateVendorName());
116 setAlternateVendorNumber(StringUtils.isEmpty(po.getAlternateVendorNumber()) ? null : po.getAlternateVendorNumber());
117 setAlternateVendorDetailAssignedIdentifier(po.getAlternateVendorDetailAssignedIdentifier());
118 setAlternateVendorHeaderGeneratedIdentifier(po.getAlternateVendorHeaderGeneratedIdentifier());
119
120
121 setDeliveryBuildingCode(po.getDeliveryBuildingCode());
122 setDeliveryBuildingLine1Address(po.getDeliveryBuildingLine1Address());
123 setDeliveryBuildingLine2Address(po.getDeliveryBuildingLine2Address());
124 setDeliveryBuildingName(po.getDeliveryBuildingName());
125 setDeliveryBuildingRoomNumber(po.getDeliveryBuildingRoomNumber());
126 setDeliveryCampusCode(po.getDeliveryCampusCode());
127 setDeliveryCityName(po.getDeliveryCityName());
128 setDeliveryCountryCode(po.getDeliveryCountryCode());
129 setDeliveryInstructionText(po.getDeliveryInstructionText());
130 setDeliveryPostalCode(po.getDeliveryPostalCode());
131 setDeliveryStateCode(po.getDeliveryStateCode());
132 setDeliveryToEmailAddress(po.getDeliveryToEmailAddress());
133 setDeliveryToName(po.getDeliveryToName());
134 setDeliveryToPhoneNumber(po.getDeliveryToPhoneNumber());
135 setInstitutionContactName(po.getInstitutionContactName());
136 setInstitutionContactPhoneNumber(po.getInstitutionContactPhoneNumber());
137 setInstitutionContactEmailAddress(po.getInstitutionContactEmailAddress());
138
139
140 setRequestorPersonName(po.getRequestorPersonName());
141 setRequestorPersonPhoneNumber(po.getRequestorPersonPhoneNumber());
142 setRequestorPersonEmailAddress(po.getRequestorPersonEmailAddress());
143
144 RequisitionDocument reqDoc = SpringContext.getBean(RequisitionService.class).getRequisitionById(po.getRequisitionIdentifier());
145 if (reqDoc != null) {
146 String requisitionPreparer = reqDoc.getFinancialSystemDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
147
148
149
150 Person initiatorUser = KimApiServiceLocator.getPersonService().getPerson(requisitionPreparer);
151 setPreparerPersonName(initiatorUser.getName());
152 }
153
154 if (getVendorNumber() != null) {
155 setGoodsDeliveredVendorHeaderGeneratedIdentifier(getVendorHeaderGeneratedIdentifier());
156 setGoodsDeliveredVendorDetailAssignedIdentifier(getVendorDetailAssignedIdentifier());
157 setGoodsDeliveredVendorNumber(getVendorNumber());
158 setGoodsDeliveredVendorName(getVendorName());
159 }
160
161 populateVendorDetails();
162 populateDocumentDescription(po);
163
164 }
165
166 protected void populateVendorDetails() {
167
168 if (getVendorHeaderGeneratedIdentifier() != null &&
169 getVendorDetailAssignedIdentifier() != null) {
170 VendorDetail tempVendor = new VendorDetail();
171 tempVendor.setVendorHeaderGeneratedIdentifier(getVendorHeaderGeneratedIdentifier());
172 tempVendor.setVendorDetailAssignedIdentifier(getVendorDetailAssignedIdentifier());
173 setVendorNumber(tempVendor.getVendorNumber());
174 }
175
176 if (getAlternateVendorHeaderGeneratedIdentifier() != null &&
177 getAlternateVendorDetailAssignedIdentifier() != null) {
178
179 VendorDetail vendorDetail = SpringContext.getBean(VendorService.class).getVendorDetail(getAlternateVendorHeaderGeneratedIdentifier(),
180 getAlternateVendorDetailAssignedIdentifier());
181
182 String userCampus = GlobalVariables.getUserSession().getPerson().getCampusCode();
183 VendorAddress vendorAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(getAlternateVendorHeaderGeneratedIdentifier(),
184 getAlternateVendorDetailAssignedIdentifier(),
185 VendorConstants.AddressTypes.REMIT,
186 userCampus);
187 if (vendorAddress == null) {
188
189 vendorAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(getAlternateVendorHeaderGeneratedIdentifier(),
190 getAlternateVendorDetailAssignedIdentifier(),
191 VendorConstants.AddressTypes.PURCHASE_ORDER,
192 userCampus);
193 }
194
195 if (vendorAddress != null) {
196 setAlternateVendorName(vendorDetail.getVendorName());
197 setAlternateVendorNumber(vendorDetail.getVendorNumber());
198 vendorDetail.setDefaultAddressLine1(vendorAddress.getVendorLine1Address());
199 vendorDetail.setDefaultAddressLine2(vendorAddress.getVendorLine2Address());
200 vendorDetail.setDefaultAddressCity(vendorAddress.getVendorCityName());
201 vendorDetail.setDefaultAddressCountryCode(vendorAddress.getVendorCountryCode());
202 vendorDetail.setDefaultAddressPostalCode(vendorAddress.getVendorZipCode());
203 vendorDetail.setDefaultAddressStateCode(vendorAddress.getVendorStateCode());
204 vendorDetail.setDefaultAddressInternationalProvince(vendorAddress.getVendorAddressInternationalProvinceName());
205 }
206
207 setAlternateVendorDetail(vendorDetail);
208 }
209
210 if (getGoodsDeliveredVendorHeaderGeneratedIdentifier() != null &&
211 getGoodsDeliveredVendorDetailAssignedIdentifier() != null) {
212 VendorDetail tempVendor = new VendorDetail();
213 tempVendor.setVendorHeaderGeneratedIdentifier(getGoodsDeliveredVendorHeaderGeneratedIdentifier());
214 tempVendor.setVendorDetailAssignedIdentifier(getGoodsDeliveredVendorDetailAssignedIdentifier());
215 setGoodsDeliveredVendorNumber(tempVendor.getVendorNumber());
216 if (StringUtils.equals(getVendorNumber(), getGoodsDeliveredVendorNumber())) {
217 setGoodsDeliveredVendorName(getVendorName());
218 } else {
219 setGoodsDeliveredVendorName(getAlternateVendorName());
220 }
221 }
222 }
223
224
225
226
227 public void clearInitFields() {
228
229 getDocumentHeader().setDocumentDescription(null);
230 getDocumentHeader().setExplanation(null);
231 getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(null);
232 getDocumentHeader().setOrganizationDocumentNumber(null);
233
234 setPurchaseOrderIdentifier(null);
235
236 setShipmentReceivedDate(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate());
237 setShipmentPackingSlipNumber(null);
238 setShipmentBillOfLadingNumber(null);
239 setCarrierCode(null);
240 }
241
242
243 @Override
244 public void processAfterRetrieve() {
245 super.processAfterRetrieve();
246 refreshNonUpdateableReferences();
247 populateVendorDetails();
248 }
249
250 @Override
251 public void prepareForSave(KualiDocumentEvent event) {
252
253 if (event instanceof AttributedContinuePurapEvent) {
254 SpringContext.getBean(BulkReceivingService.class).populateBulkReceivingFromPurchaseOrder(this);
255 if (getPurchaseOrderIdentifier() == null) {
256 getDocumentHeader().setDocumentDescription(PurapConstants.BulkReceivingDocumentStrings.MESSAGE_BULK_RECEIVING_DEFAULT_DOC_DESCRIPTION);
257 ;
258 }
259 } else {
260 if (getGoodsDeliveredVendorNumber() != null) {
261 VendorDetail tempVendor = new VendorDetail();
262 tempVendor.setVendorNumber(getGoodsDeliveredVendorNumber());
263 setGoodsDeliveredVendorHeaderGeneratedIdentifier(tempVendor.getVendorHeaderGeneratedIdentifier());
264 setGoodsDeliveredVendorDetailAssignedIdentifier(tempVendor.getVendorDetailAssignedIdentifier());
265 }
266 }
267
268 super.prepareForSave(event);
269 }
270
271 protected void populateDocumentDescription(PurchaseOrderDocument poDocument) {
272 String description = "PO: " + poDocument.getPurapDocumentIdentifier() + " Vendor: " + poDocument.getVendorName();
273 int noteTextMaxLength = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(DocumentHeader.class, KRADPropertyConstants.DOCUMENT_DESCRIPTION).intValue();
274 if (noteTextMaxLength < description.length()) {
275 description = description.substring(0, noteTextMaxLength);
276 }
277 getDocumentHeader().setDocumentDescription(description);
278 }
279
280 @Override
281 public String getDeliveryCountryName() {
282 if (StringUtils.isNotBlank(getDeliveryCountryCode())) {
283 Country country = SpringContext.getBean(CountryService.class).getCountry(getDeliveryCountryCode());
284 if (country != null) {
285 return country.getName();
286 }
287 }
288 return null;
289 }
290
291 public String getGoodsDeliveredVendorNumber() {
292 return goodsDeliveredVendorNumber;
293 }
294
295 public void setGoodsDeliveredVendorNumber(String goodsDeliveredVendorNumber) {
296 this.goodsDeliveredVendorNumber = goodsDeliveredVendorNumber;
297 }
298
299 public Integer getNoOfCartons() {
300 return noOfCartons;
301 }
302
303 public void setNoOfCartons(Integer noOfCartons) {
304 this.noOfCartons = noOfCartons;
305 }
306
307 public String getVendorContact() {
308 return vendorContact;
309 }
310
311 public void setVendorContact(String vendorContact) {
312 this.vendorContact = vendorContact;
313 }
314
315 public VendorDetail getAlternateVendorDetail() {
316 return alternateVendorDetail;
317 }
318
319 public void setAlternateVendorDetail(VendorDetail alternateVendorDetail) {
320 this.alternateVendorDetail = alternateVendorDetail;
321 }
322
323 public String getShipmentWeight() {
324 return shipmentWeight;
325 }
326
327 public void setShipmentWeight(String shipmentWeight) {
328 this.shipmentWeight = shipmentWeight;
329 }
330
331 public String getGoodsDeliveredVendorName() {
332 return goodsDeliveredVendorName;
333 }
334
335 public void setGoodsDeliveredVendorName(String goodsDeliveredVendorName) {
336 this.goodsDeliveredVendorName = goodsDeliveredVendorName;
337 }
338
339 public String getVendorAddressInternationalProvinceName() {
340 return vendorAddressInternationalProvinceName;
341 }
342
343 public void setVendorAddressInternationalProvinceName(String vendorAddressInternationalProvinceName) {
344 this.vendorAddressInternationalProvinceName = vendorAddressInternationalProvinceName;
345 }
346
347 public String getDeliveryCampusName() {
348 return deliveryCampusName;
349 }
350
351 public void setDeliveryCampusName(String deliveryCampusName) {
352 this.deliveryCampusName = deliveryCampusName;
353 }
354
355 public String getRequestorPersonName() {
356 return requestorPersonName;
357 }
358
359 public void setRequestorPersonName(String requestorPersonName) {
360 this.requestorPersonName = requestorPersonName;
361 }
362
363 public String getRequestorPersonPhoneNumber() {
364 return requestorPersonPhoneNumber;
365 }
366
367 public void setRequestorPersonPhoneNumber(String requestorPersonPhoneNumber) {
368 this.requestorPersonPhoneNumber = requestorPersonPhoneNumber;
369 }
370
371 public String getPreparerPersonName() {
372 return preparerPersonName;
373 }
374
375 public void setPreparerPersonName(String preparerPersonName) {
376 this.preparerPersonName = preparerPersonName;
377 }
378
379 public String getPreparerPersonPhoneNumber() {
380 return preparerPersonPhoneNumber;
381 }
382
383 public void setPreparerPersonPhoneNumber(String preparerPersonPhoneNumber) {
384 this.preparerPersonPhoneNumber = preparerPersonPhoneNumber;
385 }
386
387 public String getTrackingNumber() {
388 return trackingNumber;
389 }
390
391 public void setTrackingNumber(String trackingNumber) {
392 this.trackingNumber = trackingNumber;
393 }
394
395 public String getVendorNoteText() {
396 return vendorNoteText;
397 }
398
399 public void setVendorNoteText(String vendorNoteText) {
400 this.vendorNoteText = vendorNoteText;
401 }
402
403 public String getRequestorPersonEmailAddress() {
404 return requestorPersonEmailAddress;
405 }
406
407 public void setRequestorPersonEmailAddress(String requestorPersonEmailAddress) {
408 this.requestorPersonEmailAddress = requestorPersonEmailAddress;
409 }
410
411 public String getInstitutionContactEmailAddress() {
412 return institutionContactEmailAddress;
413 }
414
415 public void setInstitutionContactEmailAddress(String institutionContactEmailAddress) {
416 this.institutionContactEmailAddress = institutionContactEmailAddress;
417 }
418
419 public String getInstitutionContactName() {
420 return institutionContactName;
421 }
422
423 public void setInstitutionContactName(String institutionContactName) {
424 this.institutionContactName = institutionContactName;
425 }
426
427 public String getInstitutionContactPhoneNumber() {
428 return institutionContactPhoneNumber;
429 }
430
431 public void setInstitutionContactPhoneNumber(String institutionContactPhoneNumber) {
432 this.institutionContactPhoneNumber = institutionContactPhoneNumber;
433 }
434
435 public String getDeliveryAdditionalInstructionText() {
436 return deliveryAdditionalInstructionText;
437 }
438
439 public void setDeliveryAdditionalInstructionText(String deliveryAdditionalInstructionText) {
440 this.deliveryAdditionalInstructionText = deliveryAdditionalInstructionText;
441 }
442
443 public Integer getGoodsDeliveredVendorDetailAssignedIdentifier() {
444 return goodsDeliveredVendorDetailAssignedIdentifier;
445 }
446
447 public void setGoodsDeliveredVendorDetailAssignedIdentifier(Integer goodsDeliveredVendorDetailAssignedIdentifier) {
448 this.goodsDeliveredVendorDetailAssignedIdentifier = goodsDeliveredVendorDetailAssignedIdentifier;
449 }
450
451 public Integer getGoodsDeliveredVendorHeaderGeneratedIdentifier() {
452 return goodsDeliveredVendorHeaderGeneratedIdentifier;
453 }
454
455 public void setGoodsDeliveredVendorHeaderGeneratedIdentifier(Integer goodsDeliveredVendorHeaderGeneratedIdentifier) {
456 this.goodsDeliveredVendorHeaderGeneratedIdentifier = goodsDeliveredVendorHeaderGeneratedIdentifier;
457 }
458
459 @Override
460 public boolean isBoNotesSupport() {
461 return true;
462 }
463
464 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
465 LinkedHashMap m = new LinkedHashMap();
466 m.put("documentNumber", this.documentNumber);
467 m.put("PO", getPurchaseOrderIdentifier());
468 return m;
469 }
470
471 @Override
472 public String getWorkflowStatusForResult() {
473 return PurapSearchUtils.getWorkFlowStatusString(getDocumentHeader());
474 }
475
476
477
478
479
480
481
482 @Override
483 public Class getItemClass() {
484 throw new UnsupportedOperationException("Items are not being handled in Bulk Receiving document");
485 }
486
487
488
489
490
491
492
493 @Override
494 public <T> T getItem(int pos) {
495 throw new UnsupportedOperationException("Items are not being handled in Bulk Receiving document");
496 }
497
498
499
500
501
502
503
504 @Override
505 public List getItems() {
506 throw new UnsupportedOperationException("Items are not being handled in Bulk Receiving document");
507 }
508
509
510
511
512
513
514
515 @Override
516 public void setItems(List items) {
517 throw new UnsupportedOperationException("Items are not being handled in Bulk Receiving document");
518 }
519
520 }