1 package org.kuali.ole.ingest;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.pojo.OleInvoiceRecord;
7 import org.kuali.ole.pojo.edi.*;
8 import org.kuali.ole.select.OleSelectConstant;
9 import org.kuali.ole.select.businessobject.OleInvoiceNote;
10 import org.kuali.ole.sys.context.SpringContext;
11 import org.kuali.ole.vnd.businessobject.OleCurrencyType;
12 import org.kuali.ole.vnd.businessobject.VendorAlias;
13 import org.kuali.rice.krad.service.BusinessObjectService;
14 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
15 import org.kuali.rice.krad.service.LookupService;
16
17 import java.text.NumberFormat;
18 import java.text.ParseException;
19 import java.text.ParsePosition;
20 import java.text.SimpleDateFormat;
21 import java.util.*;
22
23
24
25
26
27
28
29
30 public class OleInvoiceRecordBuilder {
31 private static final Logger LOG = Logger.getLogger(OleInvoiceRecordBuilder.class);
32 private static OleInvoiceRecordBuilder oleInvoiceRecordBuilder;
33 protected BusinessObjectService businessObjectService;
34
35
36
37
38
39 private OleInvoiceRecordBuilder(){
40
41 }
42
43
44
45
46
47
48 public static OleInvoiceRecordBuilder getInstance() {
49 if (null == oleInvoiceRecordBuilder) {
50 oleInvoiceRecordBuilder = new OleInvoiceRecordBuilder();
51 }
52 return oleInvoiceRecordBuilder;
53 }
54
55 protected BusinessObjectService getBusinessObjectService() {
56 if (businessObjectService == null) {
57 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
58 }
59 return businessObjectService;
60 }
61
62 private LookupService getLookupService() {
63 return KRADServiceLocatorWeb.getLookupService();
64 }
65
66
67 public OleInvoiceRecord build(LineItemOrder lineItemOrder, INVOrder invOrder) throws Exception {
68
69 OleInvoiceRecord oleInvoiceRecord = new OleInvoiceRecord();
70 String listPrice = getListPrice(lineItemOrder);
71 oleInvoiceRecord.setListPrice(listPrice!=null?listPrice:getPrice(lineItemOrder));
72 oleInvoiceRecord.setUnitPrice(populateUnitPrice(lineItemOrder));
73 oleInvoiceRecord.setQuantity(getQuantity(lineItemOrder));
74 oleInvoiceRecord.setVendorItemIdentifier(getVendorItemIdentifier(lineItemOrder)!=null?getVendorItemIdentifier(lineItemOrder):getVendorIdentifierByPIA(lineItemOrder));
75 oleInvoiceRecord.setBfnNumber(getBFNNumber(lineItemOrder));
76 oleInvoiceRecord.setVendorNumber(getVendorNumber(invOrder,oleInvoiceRecord));
77 if(StringUtils.isBlank(oleInvoiceRecord.getVendorNumber())){
78 oleInvoiceRecord.setVendorAlias(getVendorAlias(invOrder));
79 oleInvoiceRecord.setVendorNumber(getVendorNumberFromVendorAlias(oleInvoiceRecord,invOrder));
80 }
81 oleInvoiceRecord.setItemChartCode(OLEConstants.OleInvoiceImport.ITM_CHART_CODE);
82 oleInvoiceRecord.setInvoiceNumber(getInvoiceNumber(invOrder));
83 oleInvoiceRecord.setInvoiceDate(getInvoiceDate(invOrder));
84 oleInvoiceRecord.setVendorInvoiceAmount(getVendorInvoiceAmount(invOrder));
85
86
87 oleInvoiceRecord.setISBN(getISBN(lineItemOrder) == null? getLineItemISBN(lineItemOrder):getISBN(lineItemOrder));
88 oleInvoiceRecord.setISSN(getISSN(lineItemOrder));
89
90 oleInvoiceRecord.setBillToCustomerID(populateBillToCustomerId(invOrder));
91 oleInvoiceRecord.setItemDescription(getItemDescription(lineItemOrder));
92 oleInvoiceRecord.setItemNote(getItemNote(lineItemOrder));
93 oleInvoiceRecord.setNumberOfCopiesOrdered(oleInvoiceRecord.getQuantity());
94
95 oleInvoiceRecord.setSubscriptionPeriodFrom(getSubscriptionDateFrom(lineItemOrder));
96 oleInvoiceRecord.setSubscriptionPeriodTo(getSubscriptionDateTo(lineItemOrder));
97 oleInvoiceRecord.setSummaryAmount(getSummaryCharge(invOrder));
98 oleInvoiceRecord.setAdditionalChargeCode(getAdditionChargeCode(invOrder));
99 oleInvoiceRecord.setAdditionalCharge(getAdditionCharge(invOrder));
100 oleInvoiceRecord.setLineItemAdditionalChargeCode(populateLineItemChargeCode(lineItemOrder));
101 oleInvoiceRecord.setLineItemAdditionalCharge(populateLineItemAdditionalCharge(lineItemOrder));
102 oleInvoiceRecord.setPurchaseOrderNumber(getPurchaseOrderNumber(lineItemOrder));
103 setCurrencyDetails(invOrder,oleInvoiceRecord);
104 return oleInvoiceRecord;
105 }
106
107 private String getVendorNumberFromVendorAlias(OleInvoiceRecord oleInvoiceRecord,INVOrder invOrder) throws Exception{
108 if(StringUtils.isNotBlank(oleInvoiceRecord.getVendorAlias())){
109 Map vendorAliasMap = new HashMap();
110 vendorAliasMap.put(org.kuali.ole.sys.OLEConstants.VENDOR_ALIAS_NAME, oleInvoiceRecord.getVendorAlias());
111 List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
112 if (vendorAliasList != null && vendorAliasList.size() > 0) {
113 return vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier() + "-" + vendorAliasList.get(0).getVendorDetailAssignedIdentifier();
114
115 }else{
116 if(oleInvoiceRecord.getVendorItemIdentifier() == null)
117 throw new Exception("The vendor alias in Edifact file doesn't match in database for invoice number:: "+getInvoiceNumber(invOrder)+" and invoice date:: "+getInvoiceDate(invOrder));
118 }
119 }
120 return null;
121 }
122
123 private void setCurrencyDetails(INVOrder invOrder,OleInvoiceRecord oleInvoiceRecord){
124 if(invOrder.getMessage() != null && invOrder.getMessage().getCurrencyDetails() != null && invOrder.getMessage().getCurrencyDetails().getCurrencyDetailsSupplierInformation() != null){
125 if(!StringUtils.isBlank(invOrder.getMessage().getCurrencyDetails().getCurrencyDetailsSupplierInformation().getCurrencyType())){
126 Map<String,String> currencyTypeMap = new HashMap<>();
127 currencyTypeMap.put(OLEConstants.CURR_ALPHA_CD, invOrder.getMessage().getCurrencyDetails().getCurrencyDetailsSupplierInformation().getCurrencyType());
128 List<OleCurrencyType> currencyTypeList = (List) getBusinessObjectService().findMatching(OleCurrencyType.class, currencyTypeMap);
129 if(currencyTypeList != null && currencyTypeList.size() >0){
130 oleInvoiceRecord.setCurrencyTypeId(currencyTypeList.get(0).getCurrencyTypeId().toString());
131 oleInvoiceRecord.setCurrencyType(currencyTypeList.get(0).getCurrencyType());
132 if (!oleInvoiceRecord.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) {
133 oleInvoiceRecord.setForeignListPrice(oleInvoiceRecord.getListPrice());
134 }
135 }
136 }
137 }
138 }
139
140 private String populateBillToCustomerId(INVOrder invOrder){
141 if(invOrder.getMessage() != null && invOrder.getMessage().getPartyQualifier() != null && invOrder.getMessage().getPartyQualifier().size() > 0){
142 for(int i=0;i<invOrder.getMessage().getPartyQualifier().size();i++){
143 if(invOrder.getMessage().getPartyQualifier().get(i).getPartyCode()!=null && invOrder.getMessage().getPartyQualifier().get(i).getPartyCode().equalsIgnoreCase("BY")){
144 return invOrder.getMessage().getPartyQualifier().get(i).getPartyInformation().getCodeIdentification();
145 } else if(invOrder.getMessage() != null && invOrder.getMessage().getBuyerAdditionalPartyIdentifier() != null && invOrder.getMessage().getBuyerAdditionalPartyIdentifier().getBuyerIdentifier() != null &&
146 invOrder.getMessage().getBuyerAdditionalPartyIdentifier().getBuyerIdentifier().getBuyerReferenceQualifier().equalsIgnoreCase("API")){
147 return invOrder.getMessage().getBuyerAdditionalPartyIdentifier().getBuyerIdentifier().getBuyerReferenceNumber();
148 }
149 }
150 }
151 return null;
152 }
153
154 private Integer getPurchaseOrderNumber(LineItemOrder lineItemOrder)throws Exception{
155 if(lineItemOrder.getSupplierReferenceInformation() != null && lineItemOrder.getSupplierReferenceInformation().size() > 0){
156 for(int i=0;i<lineItemOrder.getSupplierReferenceInformation().size();i++){
157 if(lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference() != null &&
158 lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().size() >0){
159 for(int j=0;j<lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().size();j++){
160 if(lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getSuppliersOrderLine() != null &&
161 lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getSuppliersOrderLine().equals("ON")){
162 try{
163 if (lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getVendorReferenceNumber() != null &&
164 isNumeric(lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getVendorReferenceNumber())) {
165 return Integer.parseInt(lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getVendorReferenceNumber());
166 }
167 else {
168 return 0;
169 }
170
171
172 }catch(Exception e){
173 LOG.error("Purchase Order Number should be a number but invoice file has :"+lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getVendorReferenceNumber());
174 throw new Exception("Purchase Order Number should be a number but invoice file has :"+lineItemOrder.getSupplierReferenceInformation().get(i).getSupplierLineItemReference().get(j).getVendorReferenceNumber(),e);
175 }
176 }
177 }
178
179 }
180 }
181
182 }
183
184
185
186
187
188 return null;
189 }
190
191 private String populateUnitPrice(LineItemOrder lineItemOrder){
192 if(lineItemOrder.getMonetaryDetail() != null){
193 if(lineItemOrder.getMonetaryDetail().get(0).getMonetaryLineItemInformation() != null){
194 return lineItemOrder.getMonetaryDetail().get(0).getMonetaryLineItemInformation().get(0).getAmount();
195 }
196 }
197 return null;
198 }
199
200 private String populateLineItemChargeCode(LineItemOrder lineItemOrder){
201 if(lineItemOrder.getLineItemAllowanceOrCharge() != null){
202 if(lineItemOrder.getLineItemAllowanceOrCharge().get(0).getLineItemSpecialServiceIdentification()!= null){
203 return lineItemOrder.getLineItemAllowanceOrCharge().get(0).getLineItemSpecialServiceIdentification().get(0).getSpecialServiceCode();
204 }
205 }
206 return null;
207 }
208
209 private String populateLineItemAdditionalCharge(LineItemOrder lineItemOrder){
210 if(lineItemOrder.getAllowanceMonetaryDetail()!= null){
211 if(lineItemOrder.getAllowanceMonetaryDetail().get(0).getAllowanceMonetaryLineItemInformation() != null){
212 return "0";
213 }
214 }
215 return null;
216 }
217
218
219 private String getAdditionCharge(INVOrder invOrder) {
220 if(invOrder.getMessage().getMonetary() != null){
221 if(invOrder.getMessage().getMonetary().getMonetaryInformation() != null){
222 return invOrder.getMessage().getMonetary().getMonetaryInformation().getAmount();
223 }
224 }
225 return null;
226 }
227
228
229 private String getAdditionChargeCode(INVOrder invOrder) {
230 if(invOrder.getMessage().getAllowanceOrCharge() != null){
231 if(invOrder.getMessage().getAllowanceOrCharge().getSpecialServiceIdentification() != null){
232 return invOrder.getMessage().getAllowanceOrCharge().getSpecialServiceIdentification().getSpecialServiceCode();
233 }
234 }
235 return null;
236 }
237
238
239
240
241
242
243
244
245 private String getListPrice(LineItemOrder lineItemOrder) {
246
247 List<MonetaryDetail> monetaryDetails = lineItemOrder.getMonetaryDetail();
248 if(monetaryDetails != null && monetaryDetails.size() > 0){
249 if(monetaryDetails.get(0).getMonetaryLineItemInformation()!= null && monetaryDetails.get(0).getMonetaryLineItemInformation().size()>0){
250 if(monetaryDetails.get(0).getMonetaryLineItemInformation().get(0).getAmountType() != null && monetaryDetails.get(0).getMonetaryLineItemInformation().get(0).getAmountType().contains("2")){
251 return monetaryDetails.get(0).getMonetaryLineItemInformation().get(0).getAmount();
252 }
253 }
254 }
255 return null;
256 }
257
258 private String getPrice(LineItemOrder lineItemOrder){
259 List<PriceInformation> priceInformation = lineItemOrder.getPriceInformation();
260 if (priceInformation !=null && priceInformation.size() > 0) {
261 List<ItemPrice> itemPrice = priceInformation.get(0).getItemPrice();
262 if (itemPrice != null && itemPrice.size() > 0) {
263 String priceCode = itemPrice.get(0).getGrossPrice();
264 if(priceCode != null && (priceCode.equalsIgnoreCase("AAB") || priceCode.equalsIgnoreCase("CAL"))){
265 return itemPrice.get(0).getPrice();
266 }
267 }
268 }
269 return null;
270 }
271
272
273
274
275
276
277
278
279 private String getQuantity(LineItemOrder lineItemOrder) {
280 List<QuantityInformation> quantityInformation = lineItemOrder.getQuantityInformation();
281 if (quantityInformation != null && quantityInformation.size() > 0) {
282 List<Qunatity> qunatity = quantityInformation.get(0).getQunatity();
283 if (qunatity.size() > 0) {
284 return qunatity.get(0).getQuantity();
285 }
286 }
287 return null;
288 }
289
290 private String getVendorIdentifierByPIA(LineItemOrder lineItemOrder) {
291 List<ProductFunction> productFunction = lineItemOrder.getProductFunction();
292 if(productFunction != null && productFunction.size()>0){
293 for(int i=0;i<productFunction.size();i++){
294 if(productFunction.get(i).getProductArticleNumber() != null && productFunction.get(i).getProductArticleNumber().size()>0){
295 if(productFunction.get(i).getProductArticleNumber().get(0).getProductItemNumberType().equalsIgnoreCase("SA")){
296 return productFunction.get(i).getProductArticleNumber().get(0).getProductIsbn();
297 }
298 }
299 }
300 }
301 return null;
302 }
303
304 public String getVendorItemIdentifier(LineItemOrder lineItemOrder) {
305 List<SupplierReferenceInformation> supplierReferenceInformationList = lineItemOrder.getSupplierReferenceInformation();
306 if (supplierReferenceInformationList != null && supplierReferenceInformationList.size() > 0) {
307 for(int i=0;i<supplierReferenceInformationList.size();i++){
308 SupplierReferenceInformation supplierReferenceInformation = supplierReferenceInformationList.get(i);
309 List<SupplierLineItemReference> supplierLineItemReferenceList = supplierReferenceInformation.getSupplierLineItemReference();
310 if (supplierLineItemReferenceList != null && supplierLineItemReferenceList.size() > 0) {
311 SupplierLineItemReference supplierLineItemReferenceRef = supplierLineItemReferenceList.get(0);
312 String supplierOrderLine = supplierLineItemReferenceRef.getSuppliersOrderLine();
313 String vendorItemReference = supplierLineItemReferenceRef.getVendorReferenceNumber();
314 if (supplierOrderLine.equals("SNA")) {
315 return vendorItemReference;
316 }
317 }
318 }
319 }
320 return null;
321 }
322
323 public String getBFNNumber(LineItemOrder lineItemOrder) {
324 List<SupplierReferenceInformation> supplierReferenceInformationList = lineItemOrder.getSupplierReferenceInformation();
325 if (supplierReferenceInformationList != null && supplierReferenceInformationList.size() > 0) {
326 for(int i=0;i<supplierReferenceInformationList.size();i++){
327 SupplierReferenceInformation supplierReferenceInformation = supplierReferenceInformationList.get(i);
328 List<SupplierLineItemReference> supplierLineItemReferenceList = supplierReferenceInformation.getSupplierLineItemReference();
329 if (supplierLineItemReferenceList != null && supplierLineItemReferenceList.size() > 0) {
330 SupplierLineItemReference supplierLineItemReferenceRef = supplierLineItemReferenceList.get(0);
331 String supplierOrderLine = supplierLineItemReferenceRef.getSuppliersOrderLine();
332 String vendorItemReference = supplierLineItemReferenceRef.getVendorReferenceNumber();
333 if (supplierOrderLine.equals("BFN")) {
334 return vendorItemReference;
335 }
336 }
337 }
338 }
339 return null;
340 }
341
342 private String getVendorAlias(INVOrder invOrder) throws Exception{
343 if(invOrder.getMessage().getSupplierAdditionalPartyIdentifier() != null && invOrder.getMessage().getSupplierAdditionalPartyIdentifier().getSupplierIdentifier() != null && StringUtils.isNotEmpty(invOrder.getMessage().getSupplierAdditionalPartyIdentifier().getSupplierIdentifier().getReferenceQualifier()) && invOrder.getMessage().getSupplierAdditionalPartyIdentifier().getSupplierIdentifier().getReferenceQualifier().equalsIgnoreCase("API")){
344 return invOrder.getMessage().getSupplierAdditionalPartyIdentifier().getSupplierIdentifier().getReferenceNumber();
345 }
346 return null;
347 }
348
349
350
351
352
353
354 private String getVendorNumber(INVOrder invOrder,OleInvoiceRecord oleInvoiceRecord) throws Exception{
355 try{
356 for(int i=0;i<invOrder.getMessage().getPartyQualifier().size();i++){
357 if(invOrder.getMessage().getPartyQualifier().get(i).getPartyCode()!=null && (invOrder.getMessage().getPartyQualifier().get(i).getPartyCode().equalsIgnoreCase("SR") || invOrder.getMessage().getPartyQualifier().get(i).getPartyCode().equalsIgnoreCase("SU"))){
358 if(StringUtils.isNotEmpty(invOrder.getMessage().getPartyQualifier().get(i).getPartyInformation().getCodeIdentification())){
359 return invOrder.getMessage().getPartyQualifier().get(i).getPartyInformation().getCodeIdentification();
360 }
361 }
362 }
363 }catch (Exception e){
364 if(oleInvoiceRecord.getVendorItemIdentifier() == null)
365 throw new Exception("Edifact file has no vendor number for invoice number:: "+getInvoiceNumber(invOrder)+" and invoice date:: "+getInvoiceDate(invOrder),e);
366 }
367 return null;
368 }
369
370
371
372
373
374
375
376 private String getInvoiceNumber(INVOrder invOrder)throws Exception{
377 try{
378 return invOrder.getMessage().getMessageBeginning().getMessageBeginningInterchangeControlReference();
379 }catch (Exception e){
380 throw new Exception("Edifact file has no invoice number.",e);
381 }
382 }
383
384
385
386
387
388
389 private String getInvoiceDate(INVOrder invOrder) throws Exception{
390 try{
391 return invOrder.getMessage().getMessageCreationInformation().getMessageCreationInfoDetails().getMessageCreationInfoDate();
392 }catch (Exception e){
393 throw new Exception("Edifact file has no invoice date.",e);
394 }
395 }
396
397
398 private String getForeignInvoiceAmount(INVOrder invOrder){
399
400 return null;
401 }
402
403 private String getVendorInvoiceAmount(INVOrder invOrder){
404 if(invOrder.getSummary() != null && invOrder.getSummary().getMonetarySummary() != null && invOrder.getSummary().getMonetarySummary().size() > 0){
405 for(int i=0;i<invOrder.getSummary().getMonetarySummary().size();i++){
406 MonetarySummary monetarySummary = (MonetarySummary)invOrder.getSummary().getMonetarySummary().get(i);
407 if(monetarySummary.getMonetarySummaryInformation()!=null && monetarySummary.getMonetarySummaryInformation().size()>0){
408 for(int j=0;j<monetarySummary.getMonetarySummaryInformation().size();j++){
409 if(monetarySummary.getMonetarySummaryInformation().get(0).getAmountType().equalsIgnoreCase("86")){
410 return monetarySummary.getMonetarySummaryInformation().get(0).getAmount();
411 }
412 }
413 }
414 }
415 }
416 return null;
417 }
418
419 private String getLineItemISBN(LineItemOrder lineItemOrder){
420 if(lineItemOrder.getLineItem() != null && lineItemOrder.getLineItem().get(0)!= null){
421 if(lineItemOrder.getLineItem().get(0).getLineItemArticleNumber() != null && lineItemOrder.getLineItem().get(0).getLineItemArticleNumber().get(0)!=null){
422 return lineItemOrder.getLineItem().get(0).getLineItemArticleNumber().get(0).getLineItemIsbn();
423 }
424 }
425 return null;
426 }
427
428 private String getISBN(LineItemOrder lineItemOrder){
429 if(lineItemOrder.getProductFunction()!= null && lineItemOrder.getProductFunction().size() > 0){
430 if(lineItemOrder.getProductFunction().get(0).getProductArticleNumber() != null && lineItemOrder.getProductFunction().get(0).getProductArticleNumber().size() > 0){
431 if(lineItemOrder.getProductFunction().get(0).getProductArticleNumber().get(0).getProductItemNumberType() != null){
432 return lineItemOrder.getProductFunction().get(0).getProductArticleNumber().get(0).getProductIsbn();
433 }
434 if(lineItemOrder.getProductFunction().get(0).getProductArticleNumber().get(0).getProductItemNumberType() == null &&
435 lineItemOrder.getProductFunction().get(0).getProductArticleNumber().get(0).getProductIsbn() != null){
436 return lineItemOrder.getProductFunction().get(0).getProductArticleNumber().get(0).getProductIsbn();
437 }
438 }
439 }
440 return null;
441 }
442
443 private String getISSN(LineItemOrder lineItemOrder){
444 if (lineItemOrder.getProductFunction()!= null && lineItemOrder.getProductFunction().size() > 0){
445 if(lineItemOrder.getProductFunction().get(0).getSupplierArticleNumber() != null && lineItemOrder.getProductFunction().get(0).getSupplierArticleNumber().size() > 0){
446 return lineItemOrder.getProductFunction().get(0).getSupplierArticleNumber().get(0).getIsbn();
447 }
448 }
449 return null;
450 }
451
452
453 private String getItemDescription(LineItemOrder lineItemOrder){
454 String description = "";
455 if(lineItemOrder.getItemDescriptionList() != null && lineItemOrder.getItemDescriptionList().size() > 0){
456 for(int i=0;i<lineItemOrder.getItemDescriptionList().size();i++) {
457 if(lineItemOrder.getItemDescriptionList().get(i).getItemCharacteristicCode().equals("050")) {
458 if (StringUtils.isNotBlank(description)) {
459 description = description + lineItemOrder.getItemDescriptionList().get(i).getData();
460 } else {
461 description = lineItemOrder.getItemDescriptionList().get(i).getData();
462 }
463 }
464 }
465 return description;
466 }
467 return null;
468 }
469
470 private List getItemNote(LineItemOrder lineItemOrder){
471 List itemNoteList = new ArrayList();
472
473 if(lineItemOrder.getItemDescriptionList() != null && lineItemOrder.getItemDescriptionList().size() > 0){
474 for(int itemNote=0;itemNote<lineItemOrder.getItemDescriptionList().size();itemNote++){
475 if(lineItemOrder.getItemDescriptionList().get(itemNote).getItemCharacteristicCode() != null &&
476 lineItemOrder.getItemDescriptionList().get(itemNote).getItemCharacteristicCode().contains("08")){
477 OleInvoiceNote oleInvoiceNote = new OleInvoiceNote();
478 oleInvoiceNote.setNote(lineItemOrder.getItemDescriptionList().get(itemNote).getData());
479 itemNoteList.add(oleInvoiceNote);
480 }
481 }
482 }
483 if(lineItemOrder.getAllowanceMonetaryDetail()!= null){
484 if(lineItemOrder.getAllowanceMonetaryDetail().get(0).getAllowanceMonetaryLineItemInformation() != null){
485 OleInvoiceNote oleInvoiceNote = new OleInvoiceNote();
486 oleInvoiceNote.setNote("The service charge for this item is $" + lineItemOrder.getAllowanceMonetaryDetail().get(0).getAllowanceMonetaryLineItemInformation().get(0).getAmount());
487 itemNoteList.add(oleInvoiceNote);
488 }
489 }
490 return itemNoteList;
491 }
492
493 private String getSubscriptionDateFrom(LineItemOrder lineItemOrder){
494 if(lineItemOrder.getDateTimeDetail() != null && lineItemOrder.getDateTimeDetail().size() > 0){
495 if(lineItemOrder.getDateTimeDetail().get(0).getDateTimeInformationList() != null && lineItemOrder.getDateTimeDetail().get(0).getDateTimeInformationList().size() > 0){
496 if(lineItemOrder.getDateTimeDetail().get(0).getDateTimeInformationList().get(0).getPeriod().length() == 8) {
497 return lineItemOrder.getDateTimeDetail().get(0).getDateTimeInformationList().get(0).getPeriod();
498 }else{
499 return lineItemOrder.getDateTimeDetail().get(0).getDateTimeInformationList().get(0).getPeriod()+01;
500 }
501 }
502 }
503 return null;
504 }
505
506 private int getLastDayOfMonth(String date){
507 SimpleDateFormat dateFromRawFile = new SimpleDateFormat(org.kuali.ole.OLEConstants.DATE_FORMAT);
508 Date dt = null;
509 try {
510 dt = dateFromRawFile.parse(date);
511 } catch (ParseException e) {
512 LOG.error("Unable to parse Subscription End Date");
513 }
514
515 Calendar calendar = Calendar.getInstance();
516 calendar.setTime(dt);
517 calendar.add(Calendar.MONTH, 1);
518 calendar.set(Calendar.DAY_OF_MONTH, 1);
519 calendar.add(Calendar.DATE, -1);
520 Date lastDayOfMonth = calendar.getTime();
521 int day = lastDayOfMonth.getDate();
522 return day;
523 }
524
525 private String getSubscriptionDateTo(LineItemOrder lineItemOrder){
526 if(lineItemOrder.getDateTimeDetail()!= null && lineItemOrder.getDateTimeDetail().size() > 1){
527 if(lineItemOrder.getDateTimeDetail().get(1).getDateTimeInformationList() != null && lineItemOrder.getDateTimeDetail().get(1).getDateTimeInformationList().size() > 0){
528 if(lineItemOrder.getDateTimeDetail().get(1).getDateTimeInformationList().get(0).getPeriod().length() == 8) {
529 return lineItemOrder.getDateTimeDetail().get(1).getDateTimeInformationList().get(0).getPeriod();
530 }else{
531 String subscriptionDate = lineItemOrder.getDateTimeDetail().get(1).getDateTimeInformationList().get(0).getPeriod()+"01";
532 int day = getLastDayOfMonth(subscriptionDate);
533 return lineItemOrder.getDateTimeDetail().get(1).getDateTimeInformationList().get(0).getPeriod()+day;
534 }
535 }
536 }
537 return null;
538 }
539
540 private String getSummaryCharge(INVOrder invOrder){
541 if(invOrder.getSummary()!= null && invOrder.getSummary().getMonetarySummary() != null &&
542 invOrder.getSummary().getMonetarySummary().size()> 0){
543 if(invOrder.getSummary().getMonetarySummary().get(invOrder.getSummary().getMonetarySummary().size()-1).getMonetarySummaryInformation() != null && invOrder.getSummary().getMonetarySummary().get(invOrder.getSummary().getMonetarySummary().size()-1).getMonetarySummaryInformation().size() > 0){
544 invOrder.getSummary().getMonetarySummary().get(invOrder.getSummary().getMonetarySummary().size()-1).getMonetarySummaryInformation().get(0).getAmount();
545 }
546 }
547 return null;
548 }
549
550 private static boolean isNumeric(String str) {
551 NumberFormat formatter = NumberFormat.getInstance();
552 ParsePosition pos = new ParsePosition(0);
553 formatter.parse(str, pos);
554 return str.length() == pos.getIndex();
555 }
556
557 }