001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.module.purap.document.web.struts;
017
018 import java.util.List;
019 import java.util.Map;
020 import java.util.Properties;
021
022 import javax.servlet.http.HttpServletRequest;
023
024 import org.kuali.kfs.module.purap.businessobject.PurApAccountingLine;
025 import org.kuali.kfs.module.purap.businessobject.PurApItem;
026 import org.kuali.kfs.module.purap.document.AccountsPayableDocument;
027 import org.kuali.kfs.module.purap.document.service.PurchaseOrderService;
028 import org.kuali.kfs.module.purap.util.PurApItemUtils;
029 import org.kuali.kfs.pdp.PdpPropertyConstants;
030 import org.kuali.kfs.pdp.businessobject.PaymentDetail;
031 import org.kuali.kfs.sys.KFSConstants;
032 import org.kuali.kfs.sys.KFSParameterKeyConstants;
033 import org.kuali.kfs.sys.KFSPropertyConstants;
034 import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
035 import org.kuali.kfs.sys.context.SpringContext;
036 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
037 import org.kuali.rice.kns.service.DataDictionaryService;
038 import org.kuali.rice.kns.service.KualiConfigurationService;
039 import org.kuali.rice.kns.service.ParameterService;
040 import org.kuali.rice.kns.util.KNSConstants;
041 import org.kuali.rice.kns.util.UrlFactory;
042
043 /**
044 * Struts Action Form for Accounts Payable documents.
045 */
046 public class AccountsPayableFormBase extends PurchasingAccountsPayableFormBase {
047
048 protected PurApItem newPurchasingItemLine;
049 protected boolean calculated;
050 protected int countOfAboveTheLine = 0;
051 protected int countOfBelowTheLine = 0;
052
053 /**
054 * Constructs an AccountsPayableForm instance and sets up the appropriately casted document.
055 */
056 public AccountsPayableFormBase() {
057 super();
058 calculated = false;
059 }
060
061 public PurApItem getNewPurchasingItemLine() {
062 return newPurchasingItemLine;
063 }
064
065 public void setNewPurchasingItemLine(PurApItem newPurchasingItemLine) {
066 this.newPurchasingItemLine = newPurchasingItemLine;
067 }
068
069 public PurApItem getAndResetNewPurchasingItemLine() {
070 PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
071 setNewPurchasingItemLine(setupNewPurchasingItemLine());
072 return aPurchasingItemLine;
073 }
074
075 /**
076 * This method should be overriden (or see accountingLines for an alternate way of doing this with newInstance)
077 *
078 * @return - null, enforces overriding
079 */
080 public PurApItem setupNewPurchasingItemLine() {
081 return null;
082 }
083
084 public boolean isCalculated() {
085 return calculated;
086 }
087
088 public void setCalculated(boolean calculated) {
089 this.calculated = calculated;
090 }
091
092 public int getCountOfAboveTheLine() {
093 return countOfAboveTheLine;
094 }
095
096 public void setCountOfAboveTheLine(int countOfAboveTheLine) {
097 this.countOfAboveTheLine = countOfAboveTheLine;
098 }
099
100 public int getCountOfBelowTheLine() {
101 return countOfBelowTheLine;
102 }
103
104 public void setCountOfBelowTheLine(int countOfBelowTheLine) {
105 this.countOfBelowTheLine = countOfBelowTheLine;
106 }
107
108 /**
109 * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
110 */
111 @Override
112 public void populate(HttpServletRequest request) {
113 super.populate(request);
114 AccountsPayableDocument apDoc = (AccountsPayableDocument) this.getDocument();
115
116 // update po doc
117 apDoc.setPurchaseOrderDocument(SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(apDoc.getPurchaseOrderIdentifier()));
118
119 // update counts after populate
120 updateItemCounts();
121 }
122
123 /**
124 * Updates item counts for display
125 */
126 public void updateItemCounts() {
127 List<PurApItem> items = ((AccountsPayableDocument) this.getDocument()).getItems();
128 countOfBelowTheLine = PurApItemUtils.countBelowTheLineItems(items);
129 countOfAboveTheLine = items.size() - countOfBelowTheLine;
130 }
131
132 }