1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.kuali.ole.module.purap.businessobject;
22
23 import org.apache.commons.lang.builder.ToStringBuilder;
24 import org.kuali.ole.module.purap.service.ElectronicInvoiceMappingService;
25 import org.kuali.ole.module.purap.util.ElectronicInvoiceUtils;
26 import org.kuali.ole.module.purap.util.cxml.CxmlHeader;
27
28 import java.math.BigDecimal;
29 import java.util.ArrayList;
30 import java.util.Date;
31 import java.util.Iterator;
32 import java.util.List;
33
34 public class ElectronicInvoice {
35 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoice.class);
36
37 private static BigDecimal zero = new BigDecimal(0.00);
38
39 public static String INVOICE_AMOUNT_TYPE_CODE_ITEM = "ITEM";
40 public static String INVOICE_AMOUNT_TYPE_CODE_TAX = "TAX";
41 public static String INVOICE_AMOUNT_TYPE_CODE_SPECIAL_HANDLING = "SPHD";
42 public static String INVOICE_AMOUNT_TYPE_CODE_SHIPPING = "SHIP";
43 public static String INVOICE_AMOUNT_TYPE_CODE_DISCOUNT = "DISC";
44 public static String INVOICE_AMOUNT_TYPE_CODE_DEPOSIT = "DPST";
45 public static String INVOICE_AMOUNT_TYPE_CODE_DUE = "DUE";
46 public static String INVOICE_AMOUNT_TYPE_CODE_EXMT = "EXMT";
47
48 public static boolean FILE_REJECTED = true;
49 public static boolean FILE_NOT_REJECTED = false;
50 public static boolean FILE_DOES_CONTAIN_REJECTS = true;
51 public static boolean FILE_DOES_NOT_CONTAIN_REJECTS = false;
52
53 private CxmlHeader cxmlHeader;
54 private String customerNumber;
55
56 private String fileName;
57 private String dunsNumber;
58 private Integer vendorHeaderID = null;
59 private Integer vendorDetailID = null;
60 private String vendorName = null;
61 private boolean fileRejected = FILE_NOT_REJECTED;
62 private boolean containsRejects = FILE_DOES_NOT_CONTAIN_REJECTS;
63 private List fileRejectReasons = new ArrayList();
64
65 private ElectronicInvoiceDetailRequestHeader invoiceDetailRequestHeader;
66 private List invoiceDetailOrders = new ArrayList();
67 private ElectronicInvoiceDetailRequestSummary invoiceDetailRequestSummary;
68
69
70
71
72 private String version = "1.2.019";
73 private String timestamp;
74 private String payloadID;
75 private String locale;
76 private String deploymentMode = "production";
77
78
79
80
81 public ElectronicInvoice() {
82 super();
83 }
84
85 private boolean containsLineLevelAmounts() {
86 return invoiceDetailRequestHeader.isShippingInLine() || invoiceDetailRequestHeader.isSpecialHandlingInLine() || invoiceDetailRequestHeader.isTaxInLine() || invoiceDetailRequestHeader.isDiscountInLine();
87 }
88
89 public void addFileRejectReasonToList(ElectronicInvoiceRejectReason reason) {
90 this.fileRejectReasons.add(reason);
91 }
92
93
94
95
96 public ElectronicInvoicePostalAddress getCxmlPostalAddress(ElectronicInvoiceOrder eio, String roleID, String addressName) {
97 if (this.invoiceDetailRequestHeader.isShippingInLine()) {
98 return eio.getCxmlPostalAddressByRoleID(roleID, addressName);
99 } else {
100 return this.invoiceDetailRequestHeader.getCxmlPostalAddressByRoleID(roleID, addressName);
101 }
102 }
103
104 public ElectronicInvoiceContact getCxmlContact(ElectronicInvoiceOrder eio, String roleID) {
105 if (this.invoiceDetailRequestHeader.isShippingInLine()) {
106 return eio.getCxmlContactByRoleID(roleID);
107 } else {
108 return this.invoiceDetailRequestHeader.getCxmlContactByRoleID(roleID);
109 }
110 }
111
112 public String getShippingDateDisplayText(ElectronicInvoiceOrder eio) {
113 Date date = null;
114 String dateString = "";
115 if (this.invoiceDetailRequestHeader.isShippingInLine()) {
116 date = eio.getInvoiceShippingDate();
117 dateString = eio.getInvoiceShippingDateString();
118 } else {
119 date = this.invoiceDetailRequestHeader.getShippingDate();
120 dateString = this.invoiceDetailRequestHeader.getShippingDateString();
121 }
122 if (date != null) {
123 return ElectronicInvoiceUtils.getDateDisplayText(date);
124 } else {
125 return dateString;
126 }
127 }
128
129 public String getMasterAgreementIDInfoDateDisplayText(ElectronicInvoiceOrder eio) {
130 Date date = eio.getMasterAgreementIDInfoDate();
131 if (date != null) {
132 return ElectronicInvoiceUtils.getDateDisplayText(date);
133 } else {
134 return eio.getMasterAgreementIDInfoDateString();
135 }
136 }
137
138 public String getMasterAgreementReferenceDateDisplayText(ElectronicInvoiceOrder eio) {
139 Date date = eio.getMasterAgreementReferenceDate();
140 if (date != null) {
141 return ElectronicInvoiceUtils.getDateDisplayText(date);
142 } else {
143 return eio.getMasterAgreementReferenceDateString();
144 }
145 }
146
147 public String getOrderIDInfoDateDisplayText(ElectronicInvoiceOrder eio) {
148 Date date = eio.getOrderIDInfoDate();
149 if (date != null) {
150 return ElectronicInvoiceUtils.getDateDisplayText(date);
151 } else {
152 return eio.getOrderIDInfoDateString();
153 }
154 }
155
156 public String getInvoiceDateDisplayText() {
157 Date date = this.invoiceDetailRequestHeader.getInvoiceDate();
158 if (date != null) {
159 return ElectronicInvoiceUtils.getDateDisplayText(date);
160 } else {
161 return this.invoiceDetailRequestHeader.getInvoiceDateString();
162 }
163 }
164
165
166
167
168 public String getInvoiceShippingDescription(ElectronicInvoiceOrder eio) {
169 if (this.invoiceDetailRequestHeader.isShippingInLine()) {
170 return eio.getInvoiceShippingDescription();
171 } else {
172 return invoiceDetailRequestSummary.getShippingDescription();
173 }
174 }
175
176 public String getInvoiceTaxDescription(ElectronicInvoiceOrder eio) {
177 if (this.invoiceDetailRequestHeader.isTaxInLine()) {
178 return eio.getInvoiceTaxDescription();
179 } else {
180 return invoiceDetailRequestSummary.getTaxDescription();
181 }
182 }
183
184 public String getInvoiceSpecialHandlingDescription(ElectronicInvoiceOrder eio) {
185
186 if (this.invoiceDetailRequestHeader.isSpecialHandlingInLine()) {
187 return eio.getInvoiceSpecialHandlingDescription();
188
189 } else {
190 return invoiceDetailRequestSummary.getSpecialHandlingAmountDescription();
191 }
192 }
193
194
195
196
197 public BigDecimal getFileTotalAmountForInLineItems(String invoiceLineItemType) {
198 BigDecimal total = zero;
199 for (Iterator orderIter = this.invoiceDetailOrders.iterator(); orderIter.hasNext(); ) {
200 ElectronicInvoiceOrder eio = (ElectronicInvoiceOrder) orderIter.next();
201 if (INVOICE_AMOUNT_TYPE_CODE_TAX.equalsIgnoreCase(invoiceLineItemType)) {
202 total = total.add(eio.getInvoiceTaxAmount());
203 } else if (INVOICE_AMOUNT_TYPE_CODE_SPECIAL_HANDLING.equalsIgnoreCase(invoiceLineItemType)) {
204 total = total.add(eio.getInvoiceSpecialHandlingAmount());
205 } else if (INVOICE_AMOUNT_TYPE_CODE_SHIPPING.equalsIgnoreCase(invoiceLineItemType)) {
206 total = total.add(eio.getInvoiceShippingAmount());
207 } else if (INVOICE_AMOUNT_TYPE_CODE_DISCOUNT.equalsIgnoreCase(invoiceLineItemType)) {
208 total = total.add(eio.getInvoiceDiscountAmount());
209 }
210 }
211 return total;
212 }
213
214 public BigDecimal getInvoiceSubTotalAmount(ElectronicInvoiceOrder eio) {
215 if (this.containsLineLevelAmounts()) {
216 return eio.getInvoiceSubTotalAmount();
217 } else {
218 return invoiceDetailRequestSummary.getInvoiceSubTotalAmount();
219 }
220 }
221
222 public BigDecimal getInvoiceTaxAmount(ElectronicInvoiceOrder eio) {
223 if (this.invoiceDetailRequestHeader.isTaxInLine()) {
224 return eio.getInvoiceTaxAmount();
225 } else {
226 return invoiceDetailRequestSummary.getInvoiceTaxAmount();
227 }
228 }
229
230 public BigDecimal getInvoiceSpecialHandlingAmount(ElectronicInvoiceOrder eio) {
231 if (this.invoiceDetailRequestHeader.isSpecialHandlingInLine()) {
232 return eio.getInvoiceSpecialHandlingAmount();
233 } else {
234 return invoiceDetailRequestSummary.getInvoiceSpecialHandlingAmount();
235 }
236 }
237
238 public BigDecimal getInvoiceShippingAmount(ElectronicInvoiceOrder eio) {
239 if (this.invoiceDetailRequestHeader.isShippingInLine()) {
240 return eio.getInvoiceShippingAmount();
241 } else {
242 return invoiceDetailRequestSummary.getInvoiceShippingAmount();
243 }
244 }
245
246 public BigDecimal getInvoiceGrossAmount(ElectronicInvoiceOrder eio) {
247 if (this.containsLineLevelAmounts()) {
248 return eio.getInvoiceGrossAmount();
249 } else {
250 return invoiceDetailRequestSummary.getInvoiceGrossAmount();
251 }
252 }
253
254 public BigDecimal getInvoiceDiscountAmount(ElectronicInvoiceOrder eio) {
255 if (this.invoiceDetailRequestHeader.isDiscountInLine()) {
256 return eio.getInvoiceDiscountAmount();
257 } else {
258 return invoiceDetailRequestSummary.getInvoiceDiscountAmount();
259 }
260 }
261
262 public BigDecimal getInvoiceNetAmount(ElectronicInvoiceOrder eio) {
263 if (this.containsLineLevelAmounts()) {
264 return eio.getInvoiceNetAmount();
265 } else {
266 return invoiceDetailRequestSummary.getInvoiceNetAmount();
267 }
268 }
269
270 public BigDecimal getInvoiceDepositAmount() {
271 return invoiceDetailRequestSummary.getInvoiceDepositAmount();
272 }
273
274 public BigDecimal getInvoiceDueAmount() {
275 return invoiceDetailRequestSummary.getInvoiceDueAmount();
276 }
277
278
279
280
281 public String getCodeOfLineItemThatContainsInvalidCurrency(String invoiceLineItemType) {
282 for (Iterator orderIter = this.invoiceDetailOrders.iterator(); orderIter.hasNext(); ) {
283 ElectronicInvoiceOrder eio = (ElectronicInvoiceOrder) orderIter.next();
284 for (Iterator itemIter = eio.getInvoiceItems().iterator(); itemIter.hasNext(); ) {
285 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) itemIter.next();
286 if (INVOICE_AMOUNT_TYPE_CODE_TAX.equalsIgnoreCase(invoiceLineItemType)) {
287 if (!(this.isCodeValidCurrency(eii.getTaxAmountCurrency()))) {
288 return eii.getTaxAmountCurrency();
289 }
290 } else if (INVOICE_AMOUNT_TYPE_CODE_SPECIAL_HANDLING.equalsIgnoreCase(invoiceLineItemType)) {
291 if (!(this.isCodeValidCurrency(eii.getInvoiceLineSpecialHandlingAmountCurrency()))) {
292 return eii.getInvoiceLineSpecialHandlingAmountCurrency();
293 }
294 } else if (INVOICE_AMOUNT_TYPE_CODE_SHIPPING.equalsIgnoreCase(invoiceLineItemType)) {
295 if (!(this.isCodeValidCurrency(eii.getInvoiceLineShippingAmountCurrency()))) {
296 return eii.getInvoiceLineShippingAmountCurrency();
297 }
298 } else if (INVOICE_AMOUNT_TYPE_CODE_DISCOUNT.equalsIgnoreCase(invoiceLineItemType)) {
299 if (!(this.isCodeValidCurrency(eii.getInvoiceLineDiscountAmountCurrency()))) {
300 return eii.getInvoiceLineDiscountAmountCurrency();
301 }
302 }
303 }
304 }
305 return null;
306 }
307
308
309
310
311 public String checkCodeForValidCurrency(String code) {
312 if (!(this.isCodeValidCurrency(code))) {
313 return code;
314 } else {
315 return null;
316 }
317 }
318
319
320
321
322 public boolean isCodeValidCurrency(String code) {
323 if (code != null) {
324 for (int i = 0; i < ElectronicInvoiceMappingService.CXML_VALID_CURRENCY_CODES.length; i++) {
325 String validCode = ElectronicInvoiceMappingService.CXML_VALID_CURRENCY_CODES[i];
326 if (code.equalsIgnoreCase(validCode)) {
327 return true;
328 }
329 }
330 }
331 return false;
332 }
333
334 public String getInvoiceSubTotalCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
335 if (this.containsLineLevelAmounts()) {
336 for (Iterator iter = eio.getInvoiceItems().iterator(); iter.hasNext(); ) {
337 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) iter.next();
338 String currentCode = this.checkCodeForValidCurrency(eii.getSubTotalAmountCurrency());
339 if (currentCode != null) {
340 return currentCode;
341 }
342 }
343 return null;
344 } else {
345 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getSubTotalAmountCurrency());
346 }
347 }
348
349 public String getInvoiceTaxCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
350 if (this.invoiceDetailRequestHeader.isTaxInLine()) {
351 for (Iterator iter = eio.getInvoiceItems().iterator(); iter.hasNext(); ) {
352 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) iter.next();
353 String currentCode = this.checkCodeForValidCurrency(eii.getTaxAmountCurrency());
354 if (currentCode != null) {
355 return currentCode;
356 }
357 }
358 return null;
359 } else {
360 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getTaxAmountCurrency());
361 }
362 }
363
364 public String getInvoiceSpecialHandlingCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
365 if (this.invoiceDetailRequestHeader.isSpecialHandlingInLine()) {
366 for (Iterator iter = eio.getInvoiceItems().iterator(); iter.hasNext(); ) {
367 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) iter.next();
368 String currentCode = this.checkCodeForValidCurrency(eii.getInvoiceLineSpecialHandlingAmountCurrency());
369 if (currentCode != null) {
370 return currentCode;
371 }
372 }
373 return null;
374 } else {
375 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getSpecialHandlingAmountCurrency());
376 }
377 }
378
379 public String getInvoiceShippingCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
380 if (this.invoiceDetailRequestHeader.isShippingInLine()) {
381 for (Iterator iter = eio.getInvoiceItems().iterator(); iter.hasNext(); ) {
382 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) iter.next();
383 String currentCode = this.checkCodeForValidCurrency(eii.getInvoiceLineShippingAmountCurrency());
384 if (currentCode != null) {
385 return currentCode;
386 }
387 }
388 return null;
389 } else {
390 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getShippingAmountCurrency());
391 }
392 }
393
394 public String getInvoiceGrossCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
395 if (this.containsLineLevelAmounts()) {
396 for (Iterator iter = eio.getInvoiceItems().iterator(); iter.hasNext(); ) {
397 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) iter.next();
398 String currentCode = this.checkCodeForValidCurrency(eii.getInvoiceLineGrossAmountCurrency());
399 if (currentCode != null) {
400 return currentCode;
401 }
402 }
403 return null;
404 } else {
405 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getGrossAmountCurrency());
406 }
407 }
408
409 public String getInvoiceDiscountCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
410 if (this.invoiceDetailRequestHeader.isDiscountInLine()) {
411 for (Iterator iter = eio.getInvoiceItems().iterator(); iter.hasNext(); ) {
412 ElectronicInvoiceItem eii = (ElectronicInvoiceItem) iter.next();
413 String currentCode = this.checkCodeForValidCurrency(eii.getInvoiceLineDiscountAmountCurrency());
414 if (currentCode != null) {
415 return currentCode;
416 }
417 }
418 return null;
419 } else {
420 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getDiscountAmountCurrency());
421 }
422 }
423
424 public String getInvoiceNetCurrencyIfNotValid(ElectronicInvoiceOrder eio) {
425 if (this.containsLineLevelAmounts()) {
426 for (ElectronicInvoiceItem eii : eio.getInvoiceItems()) {
427 String currentCode = this.checkCodeForValidCurrency(eii.getInvoiceLineNetAmountCurrency());
428 if (currentCode != null) {
429 return currentCode;
430 }
431 }
432 return null;
433 } else {
434 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getNetAmountCurrency());
435 }
436 }
437
438 public String getInvoiceDepositCurrencyIfNotValid() {
439 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getDepositAmountCurrency());
440 }
441
442 public String getInvoiceDueCurrencyIfNotValid() {
443 return this.checkCodeForValidCurrency(invoiceDetailRequestSummary.getDueAmountCurrency());
444 }
445
446
447
448
449
450
451
452
453 public boolean isContainsRejects() {
454 return containsRejects;
455 }
456
457
458
459
460 public void setContainsRejects(boolean containsRejects) {
461 this.containsRejects = containsRejects;
462 }
463
464
465
466
467 public String getCustomerNumber() {
468 return customerNumber;
469 }
470
471
472
473
474 public void setCustomerNumber(String customerNumber) {
475 this.customerNumber = customerNumber;
476 }
477
478
479
480
481 public CxmlHeader getCxmlHeader() {
482 return cxmlHeader;
483 }
484
485
486
487
488 public void setCxmlHeader(CxmlHeader cxmlHeader) {
489 this.cxmlHeader = cxmlHeader;
490 }
491
492
493
494
495 public String getDunsNumber() {
496 return dunsNumber;
497 }
498
499
500
501
502 public void setDunsNumber(String dunsNumber) {
503 this.dunsNumber = dunsNumber;
504 }
505
506
507
508
509 public String getFileName() {
510 return fileName;
511 }
512
513
514
515
516 public void setFileName(String fileName) {
517 this.fileName = fileName;
518 }
519
520
521
522
523 public boolean isFileRejected() {
524 return fileRejected;
525 }
526
527
528
529
530 public void setFileRejected(boolean fileRejected) {
531 this.fileRejected = fileRejected;
532 }
533
534
535
536
537 public List<ElectronicInvoiceRejectReason> getFileRejectReasons() {
538 return fileRejectReasons;
539 }
540
541
542
543
544 public void setFileRejectReasons(List<ElectronicInvoiceRejectReason> fileRejectReasons) {
545 this.fileRejectReasons = fileRejectReasons;
546 }
547
548
549
550
551 public List<ElectronicInvoiceOrder> getInvoiceDetailOrders() {
552 return invoiceDetailOrders;
553 }
554
555
556
557
558 public void setInvoiceDetailOrders(List<ElectronicInvoiceOrder> invoiceDetailOrders) {
559 this.invoiceDetailOrders = invoiceDetailOrders;
560 }
561
562
563
564
565 public ElectronicInvoiceDetailRequestHeader getInvoiceDetailRequestHeader() {
566 return invoiceDetailRequestHeader;
567 }
568
569
570
571
572 public void setInvoiceDetailRequestHeader(ElectronicInvoiceDetailRequestHeader invoiceDetailRequestHeader) {
573 this.invoiceDetailRequestHeader = invoiceDetailRequestHeader;
574 }
575
576
577
578
579 public ElectronicInvoiceDetailRequestSummary getInvoiceDetailRequestSummary() {
580 return invoiceDetailRequestSummary;
581 }
582
583
584
585
586 public void setInvoiceDetailRequestSummary(ElectronicInvoiceDetailRequestSummary invoiceDetailRequestSummary) {
587 this.invoiceDetailRequestSummary = invoiceDetailRequestSummary;
588 }
589
590
591
592
593 public Integer getVendorDetailID() {
594 return vendorDetailID;
595 }
596
597
598
599
600 public void setVendorDetailID(Integer vendorDetailID) {
601 this.vendorDetailID = vendorDetailID;
602 }
603
604
605
606
607 public Integer getVendorHeaderID() {
608 return vendorHeaderID;
609 }
610
611
612
613
614 public void setVendorHeaderID(Integer vendorHeaderID) {
615 this.vendorHeaderID = vendorHeaderID;
616 }
617
618
619
620
621 public String getVendorName() {
622 return vendorName;
623 }
624
625
626
627
628 public void setVendorName(String vendorName) {
629 this.vendorName = vendorName;
630 }
631
632 public String getPayloadID() {
633 return payloadID;
634 }
635
636 public void setPayloadID(String payloadID) {
637 this.payloadID = payloadID;
638 }
639
640 public String getTimestamp() {
641 return timestamp;
642 }
643
644 public void setTimestamp(String timestamp) {
645 this.timestamp = timestamp;
646 }
647
648 public String getVersion() {
649 return version;
650 }
651
652 public void setVersion(String version) {
653 this.version = version;
654 }
655
656 public String getLocale() {
657 return locale;
658 }
659
660 public void setLocale(String locale) {
661 this.locale = locale;
662 }
663
664 public void addInvoiceDetailOrder(ElectronicInvoiceOrder electronicInvoiceOrder) {
665 invoiceDetailOrders.add(electronicInvoiceOrder);
666 }
667
668 public ElectronicInvoiceOrder[] getInvoiceDetailOrdersAsArray() {
669 if (invoiceDetailOrders.size() > 0) {
670 ElectronicInvoiceOrder[] tempOrders = new ElectronicInvoiceOrder[invoiceDetailOrders.size()];
671 invoiceDetailOrders.toArray(tempOrders);
672 return tempOrders;
673 }
674 return null;
675 }
676
677 public String getDeploymentMode() {
678 return deploymentMode;
679 }
680
681 public void setDeploymentMode(String deploymentMode) {
682 this.deploymentMode = deploymentMode;
683 }
684
685 public String toString() {
686 ToStringBuilder toString = new ToStringBuilder(this);
687 toString.append("version", getVersion());
688 toString.append("timestamp", getTimestamp());
689 toString.append("payloadID", getPayloadID());
690 toString.append("locale", getLocale());
691 toString.append("customerNumber", getCustomerNumber());
692 toString.append("fileName", getFileName());
693 toString.append("deploymentMode", getDeploymentMode());
694
695 toString.append("dunsNumber", getDunsNumber());
696 toString.append("vendorHeaderID", getVendorHeaderID());
697 toString.append("vendorDetailID", getVendorDetailID());
698 toString.append("vendorName", getVendorName());
699 toString.append("cxmlHeader", getCxmlHeader());
700 toString.append("invoiceDetailRequestHeader", getInvoiceDetailRequestHeader());
701 toString.append("invoiceDetailOrders", getInvoiceDetailOrders());
702 toString.append("invoiceDetailRequestSummary", getInvoiceDetailRequestSummary());
703
704
705 return toString.toString();
706
707 }
708
709
710 }