001/* 002 * Copyright 2008 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.module.purap.service.impl; 017 018import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItem; 019import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItemMapping; 020import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceRejectItem; 021import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem; 022import org.kuali.ole.module.purap.util.ElectronicInvoiceUtils; 023import org.kuali.rice.core.api.util.type.KualiDecimal; 024 025import java.math.BigDecimal; 026import java.util.Map; 027 028public class ElectronicInvoiceItemHolder { 029 030 private ElectronicInvoiceOrderHolder orderHolder; 031 private ElectronicInvoiceRejectItem rejectItem; 032 private ElectronicInvoiceItem invoiceItem; 033 private PurchaseOrderItem poItem; 034 private Map<String, ElectronicInvoiceItemMapping> itemTypeMappings; 035 036 private boolean isRejectItemHolder; 037 private boolean validateHeader; 038 039 public ElectronicInvoiceItemHolder(ElectronicInvoiceRejectItem rejectItem, 040 Map itemTypeMappings, 041 PurchaseOrderItem poItem, 042 ElectronicInvoiceOrderHolder orderHolder) { 043 044 if (rejectItem == null) { 045 throw new NullPointerException("ElectronicInvoiceRejectItem should not be null"); 046 } 047 048 this.rejectItem = rejectItem; 049 this.poItem = poItem; 050 this.orderHolder = orderHolder; 051 052 isRejectItemHolder = true; 053 } 054 055 public ElectronicInvoiceItemHolder(ElectronicInvoiceItem invoiceItem, 056 Map itemTypeMappings, 057 PurchaseOrderItem poItem, 058 ElectronicInvoiceOrderHolder orderHolder) { 059 060 if (invoiceItem == null) { 061 throw new NullPointerException("ElectronicInvoiceItem should not be null"); 062 } 063 064 this.invoiceItem = invoiceItem; 065 this.poItem = poItem; 066 this.orderHolder = orderHolder; 067 068 isRejectItemHolder = false; 069 } 070 071 public Integer getInvoiceItemLineNumber() { 072 if (isRejectItemHolder()) { 073 return rejectItem.getInvoiceReferenceItemLineNumber(); 074 } else { 075 return invoiceItem.getReferenceLineNumberInteger(); 076 } 077 } 078 079 public String getInvoiceItemDescription() { 080 if (isRejectItemHolder()) { 081 return rejectItem.getInvoiceReferenceItemDescription(); 082 } else { 083 return invoiceItem.getReferenceDescription(); 084 } 085 } 086 087 public PurchaseOrderItem getPurchaseOrderItem() { 088 return poItem; 089 } 090 091 public String getCatalogNumberStripped() { 092 if (isRejectItemHolder()) { 093 return ElectronicInvoiceUtils.stripSplChars(rejectItem.getInvoiceItemCatalogNumber()); 094 } else { 095 return ElectronicInvoiceUtils.stripSplChars(invoiceItem.getCatalogNumber()); 096 } 097 } 098 099 public BigDecimal getUnitPrice() { 100 if (isRejectItemHolder()) { 101 return rejectItem.getInvoiceItemUnitPrice(); 102 } else { 103 return invoiceItem.getInvoiceLineUnitCostBigDecimal(); 104 } 105 } 106 107 public String getUnitPriceCurrency() { 108 if (isRejectItemHolder()) { 109 return rejectItem.getInvoiceItemUnitPriceCurrencyCode(); 110 } else { 111 return invoiceItem.getUnitPriceCurrency(); 112 } 113 } 114 115 public BigDecimal getQuantity() { 116 if (isRejectItemHolder()) { 117 return rejectItem.getInvoiceItemQuantity(); 118 } else { 119 return invoiceItem.getInvoiceLineQuantityBigDecimal(); 120 } 121 } 122 123 public KualiDecimal getSubTotalAmount() { 124 if (isRejectItemHolder()) { 125 return new KualiDecimal(rejectItem.getInvoiceItemSubTotalAmount().setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)); 126 } else { 127 return new KualiDecimal(invoiceItem.getInvoiceLineSubTotalAmountBigDecimal()); 128 } 129 } 130 131 public boolean isRejectItemHolder() { 132 return isRejectItemHolder; 133 } 134 135 public ElectronicInvoiceItemMapping getItemMapping(String invoiceItemTypeCode) { 136 if (itemTypeMappings == null) { 137 return null; 138 } else { 139 return itemTypeMappings.get(invoiceItemTypeCode); 140 } 141 } 142 143 public String getItemTypeCode(String invoiceItemTypeCode) { 144 145 ElectronicInvoiceItemMapping itemMapping = getItemMapping(invoiceItemTypeCode); 146 147 if (itemMapping != null) { 148 return itemMapping.getItemTypeCode(); 149 } else { 150 return null; 151 } 152 } 153 154 public String getInvoiceItemCatalogNumber() { 155 if (isRejectItemHolder()) { 156 return rejectItem.getInvoiceItemCatalogNumber(); 157 } else { 158 return invoiceItem.getReferenceItemIDSupplierPartID(); 159 } 160 } 161 162 public String getInvoiceItemUnitOfMeasureCode() { 163 if (isRejectItemHolder()) { 164 return rejectItem.getInvoiceItemUnitOfMeasureCode(); 165 } else { 166 return invoiceItem.getUnitOfMeasure(); 167 } 168 } 169 170 public boolean isUnitOfMeasureAcceptIndicatorEnabled() { 171 if (isRejectItemHolder()) { 172 return rejectItem.isUnitOfMeasureAcceptIndicator(); 173 } else { 174 return false; 175 } 176 } 177 178 public boolean isCatalogNumberAcceptIndicatorEnabled() { 179 if (isRejectItemHolder()) { 180 return rejectItem.isCatalogNumberAcceptIndicator(); 181 } else { 182 return false; 183 } 184 } 185 186 public BigDecimal getInvoiceItemUnitPrice() { 187 if (isRejectItemHolder()) { 188 return rejectItem.getInvoiceItemUnitPrice(); 189 } else { 190 return invoiceItem.getInvoiceLineUnitCostBigDecimal(); 191 } 192 } 193 194 public BigDecimal getInvoiceItemQuantity() { 195 if (isRejectItemHolder()) { 196 return rejectItem.getInvoiceItemQuantity(); 197 } else { 198 return invoiceItem.getInvoiceLineQuantityBigDecimal(); 199 } 200 } 201 202 public BigDecimal getInvoiceItemSubTotalAmount() { 203 if (isRejectItemHolder()) { 204 return rejectItem.getInvoiceItemSubTotalAmount(); 205 } else { 206 return invoiceItem.getInvoiceLineSubTotalAmountBigDecimal(); 207 } 208 } 209 210 public BigDecimal getTaxAmount() { 211 if (isRejectItemHolder()) { 212 return rejectItem.getInvoiceItemTaxAmount(); 213 } else { 214 return invoiceItem.getInvoiceLineTaxAmountBigDecimal(); 215 } 216 } 217 218 public ElectronicInvoiceOrderHolder getInvoiceOrderHolder() { 219 return orderHolder; 220 } 221}