001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: */
016: package org.kuali.module.purap.fixtures;
017:
018: import java.math.BigDecimal;
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.kuali.core.util.KualiDecimal;
023: import org.kuali.core.util.ObjectUtils;
024: import org.kuali.module.purap.PurapConstants.ItemTypeCodes;
025: import org.kuali.module.purap.bo.PurApAccountingLine;
026: import org.kuali.module.purap.bo.PurchaseOrderAccount;
027: import org.kuali.module.purap.bo.PurchaseOrderItem;
028: import org.kuali.module.purap.fixtures.PurapTestConstants.ItemsAccounts;
029:
030: /**
031: * Fixture class for Purchase Order Item and its Accounts.
032: */
033: public enum PurchaseOrderItemAccountsFixture {
034:
035: WITH_DESC_WITH_UOM_WITH_PRICE_WITH_ACCOUNT(ItemsAccounts.ITEM_DESC, // itemDescription
036: ItemsAccounts.ITEM_UOM, // itemUnitOfMeasure
037: ItemsAccounts.UNIT_PRICE, // unitPrice
038: ItemsAccounts.PO_ACCOUNT, // poAccount
039: ItemsAccounts.PERCENTAGE, // percent
040: ItemTypeCodes.ITEM_TYPE_ITEM_CODE), // itemTypeCode
041: WITH_DESC_WITH_UOM_WITH_PRICE_WITH_ACCOUNT_NO_PERCENT(
042: ItemsAccounts.ITEM_DESC, ItemsAccounts.ITEM_UOM,
043: ItemsAccounts.UNIT_PRICE, ItemsAccounts.PO_ACCOUNT, null,
044: ItemTypeCodes.ITEM_TYPE_ITEM_CODE), WITH_DESC_NULL_UOM_WITH_PRICE_WITH_ACCOUNT(
045: ItemsAccounts.ITEM_DESC, null, ItemsAccounts.UNIT_PRICE,
046: ItemsAccounts.PO_ACCOUNT, ItemsAccounts.PERCENTAGE,
047: ItemTypeCodes.ITEM_TYPE_ITEM_CODE), WITH_DESC_EMPTY_UOM_WITH_PRICE_WITH_ACCOUNT(
048: ItemsAccounts.ITEM_DESC, "", ItemsAccounts.UNIT_PRICE,
049: ItemsAccounts.PO_ACCOUNT, ItemsAccounts.PERCENTAGE,
050: ItemTypeCodes.ITEM_TYPE_ITEM_CODE), WITH_DESC_WITH_UOM_WITH_PRICE_NULL_ACCOUNT(
051: ItemsAccounts.ITEM_DESC, ItemsAccounts.ITEM_UOM,
052: ItemsAccounts.UNIT_PRICE, null, ItemsAccounts.PERCENTAGE,
053: ItemTypeCodes.ITEM_TYPE_ITEM_CODE), NULL_DESC_NULL_UOM_NULL_PRICE_WTIH_ACCOUNT(
054: null, null, null, ItemsAccounts.PO_ACCOUNT,
055: ItemsAccounts.PERCENTAGE, ItemTypeCodes.ITEM_TYPE_ITEM_CODE), EMPTY_DESC_EMPTY_UOM_NULL_PRICE_WITH_ACCOUNT(
056: "", "", null, ItemsAccounts.PO_ACCOUNT,
057: ItemsAccounts.PERCENTAGE, ItemTypeCodes.ITEM_TYPE_ITEM_CODE), APO_ACCOUNT_1(
058: ItemsAccounts.ITEM_DESC, ItemsAccounts.ITEM_UOM,
059: ItemsAccounts.UNIT_PRICE_APO_1, ItemsAccounts.PO_ACCOUNT,
060: ItemsAccounts.PERCENTAGE, ItemTypeCodes.ITEM_TYPE_ITEM_CODE), APO_ACCOUNT_2(
061: ItemsAccounts.ITEM_DESC, ItemsAccounts.ITEM_UOM,
062: ItemsAccounts.UNIT_PRICE_APO_2, ItemsAccounts.PO_ACCOUNT,
063: ItemsAccounts.PERCENTAGE,
064: ItemTypeCodes.ITEM_TYPE_SERVICE_CODE), ;
065:
066: private PurchaseOrderItem poItem;
067: private String itemDescription;
068: private String itemUnitOfMeasure;
069: private BigDecimal unitPrice;
070: private BigDecimal percent;
071: private String itemTypeCode;
072: private PurchaseOrderAccount poAccount;
073:
074: /**
075: * Private Constructor.
076: */
077: private PurchaseOrderItemAccountsFixture(String itemDesc,
078: String itemUOM, BigDecimal unitPrice,
079: PurchaseOrderAccount acct, BigDecimal percent,
080: String itemTypeCode) {
081: this .poItem = ItemsAccounts.PO_ITEM;
082: this .itemDescription = itemDesc;
083: this .itemUnitOfMeasure = itemUOM;
084: this .unitPrice = unitPrice;
085: this .percent = percent;
086: this .itemTypeCode = itemTypeCode;
087: this .poAccount = acct;
088: }
089:
090: /**
091: * Populates the Purchase Order Item using the info contained in this fixture.
092: *
093: * @return the populated Purchase Order Item.
094: */
095: public PurchaseOrderItem populateItem() {
096: this .poItem.setItemDescription(this .itemDescription);
097: this .poItem.setItemUnitOfMeasureCode(this .itemUnitOfMeasure);
098: this .poItem.setItemUnitPrice(this .unitPrice);
099: this .poItem.setItemTypeCode(itemTypeCode);
100: this .poItem.setItemQuantity(new KualiDecimal(1));
101: this .poItem.setItemLineNumber(new Integer(1));
102: this .poItem.refreshNonUpdateableReferences();
103:
104: if (ObjectUtils.isNotNull(this .poAccount)) {
105: this .poAccount
106: .setAccountNumber(ItemsAccounts.ACCOUNT_NUMBER);
107: this .poAccount.setAccountLinePercent(this .percent);
108: this .poAccount
109: .setChartOfAccountsCode(ItemsAccounts.CHART_CODE);
110: this .poAccount
111: .setFinancialObjectCode(ItemsAccounts.OBJECT_CODE);
112: List<PurApAccountingLine> lines = new ArrayList<PurApAccountingLine>();
113: lines.add((PurApAccountingLine) this.poAccount);
114: this.poItem.setSourceAccountingLines(lines);
115: }
116:
117: return this.poItem;
118: }
119: }
|