001: /*
002: * Copyright 2006-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.rules;
017:
018: import org.kuali.RicePropertyConstants;
019: import org.kuali.core.util.GlobalVariables;
020: import org.kuali.core.util.ObjectUtils;
021: import org.kuali.kfs.KFSConstants;
022: import org.kuali.module.purap.PurapConstants;
023: import org.kuali.module.purap.PurapKeyConstants;
024: import org.kuali.module.purap.PurapConstants.ItemFields;
025: import org.kuali.module.purap.PurapWorkflowConstants.PaymentRequestDocument.NodeDetailEnum;
026: import org.kuali.module.purap.bo.PaymentRequestItem;
027: import org.kuali.module.purap.bo.PurApItem;
028: import org.kuali.module.purap.document.AccountsPayableDocument;
029: import org.kuali.module.purap.document.PurchasingAccountsPayableDocument;
030: import org.kuali.module.purap.rule.CalculateAccountsPayableRule;
031: import org.kuali.module.purap.rule.CancelAccountsPayableRule;
032: import org.kuali.module.purap.rule.ContinueAccountsPayableRule;
033: import org.kuali.module.purap.rule.PreCalculateAccountsPayableRule;
034:
035: /**
036: * Business Rule(s) applicable to Accounts Payable documents.
037: */
038: public abstract class AccountsPayableDocumentRuleBase extends
039: PurchasingAccountsPayableDocumentRuleBase implements
040: ContinueAccountsPayableRule, CalculateAccountsPayableRule,
041: PreCalculateAccountsPayableRule, CancelAccountsPayableRule {
042:
043: /**
044: * Determines if approval at accounts payable review is allowed.
045: *
046: * @see org.kuali.module.purap.rules.PurchasingAccountsPayableDocumentRuleBase#processValidation(org.kuali.module.purap.document.PurchasingAccountsPayableDocument)
047: */
048: @Override
049: public boolean processValidation(
050: PurchasingAccountsPayableDocument purapDocument) {
051: boolean valid = super .processValidation(purapDocument);
052:
053: valid &= processApprovalAtAccountsPayableReviewAllowed((AccountsPayableDocument) purapDocument);
054:
055: return valid;
056: }
057:
058: /**
059: * If at the node accounts payable review, checks if approval at accounts payable review is allowed.
060: * Returns true if it is, false otherwise.
061: *
062: * @param apDocument - accounts payable document
063: * @return
064: */
065: private boolean processApprovalAtAccountsPayableReviewAllowed(
066: AccountsPayableDocument apDocument) {
067: boolean valid = true;
068: GlobalVariables.getErrorMap().clearErrorPath();
069: GlobalVariables.getErrorMap().addToErrorPath(
070: RicePropertyConstants.DOCUMENT);
071:
072: if (apDocument
073: .isDocumentStoppedInRouteNode(NodeDetailEnum.ACCOUNTS_PAYABLE_REVIEW)) {
074: if (!apDocument.approvalAtAccountsPayableReviewAllowed()) {
075: valid &= false;
076: GlobalVariables.getErrorMap().putError(
077: KFSConstants.GLOBAL_ERRORS,
078: PurapKeyConstants.ERROR_AP_REQUIRES_ATTACHMENT);
079: }
080: }
081: GlobalVariables.getErrorMap().clearErrorPath();
082: return valid;
083: }
084:
085: /**
086: * Performs additional validation on above the line indicator items.
087: *
088: * @see org.kuali.module.purap.rules.PurchasingAccountsPayableDocumentRuleBase#processItemValidation(org.kuali.module.purap.document.PurchasingAccountsPayableDocument)
089: */
090: @Override
091: public boolean processItemValidation(
092: PurchasingAccountsPayableDocument purapDocument) {
093: boolean valid = super .processItemValidation(purapDocument);
094:
095: for (PurApItem item : purapDocument.getItems()) {
096: String identifierString = (item.getItemType()
097: .isItemTypeAboveTheLineIndicator() ? "Item "
098: + item.getItemLineNumber().toString() : item
099: .getItemType().getItemTypeDescription());
100: if (item.getItemType().isItemTypeAboveTheLineIndicator()) {
101: valid &= validateAboveTheLineItems(
102: (PaymentRequestItem) item, identifierString);
103: }
104: }
105:
106: return valid;
107: }
108:
109: /**
110: * Performs validation for above the line item types.
111: *
112: * @param item - a payment request item to be validated
113: * @param identifierString - identifier used to add to error map
114: * @return
115: */
116: private boolean validateAboveTheLineItems(PaymentRequestItem item,
117: String identifierString) {
118: boolean valid = true;
119:
120: // Currently Invoice Unit Price is not allowed to be NULL on screen;
121: // must be either a positive number or NULL for DB
122: if (ObjectUtils.isNotNull(item.getItemUnitPrice())
123: && item.getItemUnitPrice().signum() == -1) {
124: // if unit price is negative give an error
125: valid = false;
126: GlobalVariables.getErrorMap().putError(
127: PurapConstants.ITEM_TAB_ERROR_PROPERTY,
128: PurapKeyConstants.ERROR_ITEM_AMOUNT_BELOW_ZERO,
129: ItemFields.UNIT_COST, identifierString);
130: }
131: if (ObjectUtils.isNotNull(item.getExtendedPrice())
132: && item.getExtendedPrice().isNegative()) {
133: valid = false;
134: GlobalVariables
135: .getErrorMap()
136: .putError(
137: PurapConstants.ITEM_TAB_ERROR_PROPERTY,
138: PurapKeyConstants.ERROR_ITEM_AMOUNT_BELOW_ZERO,
139: ItemFields.INVOICE_EXTENDED_PRICE,
140: identifierString);
141: }
142: return valid;
143: }
144:
145: /**
146: * @see org.kuali.module.purap.rule.CancelAccountsPayableRule#processCancelAccountsPayableBusinessRules(org.kuali.module.purap.document.AccountsPayableDocument)
147: */
148: public abstract boolean processCancelAccountsPayableBusinessRules(
149: AccountsPayableDocument document);
150:
151: }
|