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.web.struts.form;
017:
018: import java.util.List;
019:
020: import javax.servlet.http.HttpServletRequest;
021:
022: import org.kuali.core.bo.user.UniversalUser;
023: import org.kuali.core.util.GlobalVariables;
024: import org.kuali.core.web.ui.ExtraButton;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.kfs.service.ParameterService;
027: import org.kuali.kfs.service.impl.ParameterConstants;
028: import org.kuali.module.purap.PurapParameterConstants;
029: import org.kuali.module.purap.bo.PurApItem;
030: import org.kuali.module.purap.document.AccountsPayableDocument;
031: import org.kuali.module.purap.service.PurchaseOrderService;
032: import org.kuali.module.purap.util.PurApItemUtils;
033:
034: /**
035: * Struts Action Form for Accounts Payable documents.
036: */
037: public class AccountsPayableFormBase extends
038: PurchasingAccountsPayableFormBase {
039:
040: private PurApItem newPurchasingItemLine;
041: private boolean calculated;
042: private int countOfAboveTheLine = 0;
043: private int countOfBelowTheLine = 0;
044:
045: /**
046: * Constructs an AccountsPayableForm instance and sets up the appropriately casted document.
047: */
048: public AccountsPayableFormBase() {
049: super ();
050: calculated = false;
051: }
052:
053: public PurApItem getNewPurchasingItemLine() {
054: return newPurchasingItemLine;
055: }
056:
057: public void setNewPurchasingItemLine(PurApItem newPurchasingItemLine) {
058: this .newPurchasingItemLine = newPurchasingItemLine;
059: }
060:
061: public PurApItem getAndResetNewPurchasingItemLine() {
062: PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
063: setNewPurchasingItemLine(setupNewPurchasingItemLine());
064: return aPurchasingItemLine;
065: }
066:
067: /**
068: * This method should be overriden (or see accountingLines for an alternate way of doing this with newInstance)
069: *
070: * @return - null, enforces overriding
071: */
072: public PurApItem setupNewPurchasingItemLine() {
073: return null;
074: }
075:
076: public boolean isCalculated() {
077: return calculated;
078: }
079:
080: public void setCalculated(boolean calculated) {
081: this .calculated = calculated;
082: }
083:
084: public int getCountOfAboveTheLine() {
085: return countOfAboveTheLine;
086: }
087:
088: public void setCountOfAboveTheLine(int countOfAboveTheLine) {
089: this .countOfAboveTheLine = countOfAboveTheLine;
090: }
091:
092: public int getCountOfBelowTheLine() {
093: return countOfBelowTheLine;
094: }
095:
096: public void setCountOfBelowTheLine(int countOfBelowTheLine) {
097: this .countOfBelowTheLine = countOfBelowTheLine;
098: }
099:
100: /**
101: * Determines if the current user is an AP user and returns true, false otherwise.
102: *
103: * @return - true if current user is AP user, false otherwise.
104: */
105: public boolean isApUser() {
106:
107: boolean apUser = false;
108: UniversalUser user = GlobalVariables.getUserSession()
109: .getUniversalUser();
110:
111: String apGroup = SpringContext
112: .getBean(ParameterService.class)
113: .getParameterValue(
114: ParameterConstants.PURCHASING_DOCUMENT.class,
115: PurapParameterConstants.Workgroups.WORKGROUP_ACCOUNTS_PAYABLE);
116:
117: if (user.isMember(apGroup)) {
118: apUser = true;
119: }
120:
121: return apUser;
122: }
123:
124: /**
125: * Adds a new button to the extra buttons collection.
126: *
127: * @param property - property for button
128: * @param source - location of image
129: * @param altText - alternate text for button if images don't appear
130: */
131: protected void addExtraButton(String property, String source,
132: String altText) {
133:
134: ExtraButton newButton = new ExtraButton();
135:
136: newButton.setExtraButtonProperty(property);
137: newButton.setExtraButtonSource(source);
138: newButton.setExtraButtonAltText(altText);
139:
140: extraButtons.add(newButton);
141: }
142:
143: /**
144: * @see org.kuali.kfs.web.struts.form.KualiAccountingDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
145: */
146: @Override
147: public void populate(HttpServletRequest request) {
148: super .populate(request);
149: AccountsPayableDocument apDoc = (AccountsPayableDocument) this
150: .getDocument();
151:
152: // update po doc
153: apDoc.setPurchaseOrderDocument(SpringContext.getBean(
154: PurchaseOrderService.class).getCurrentPurchaseOrder(
155: apDoc.getPurchaseOrderIdentifier()));
156:
157: // update counts after populate
158: updateItemCounts();
159: }
160:
161: /**
162: * Updates item counts for display
163: */
164: public void updateItemCounts() {
165: List<PurApItem> items = ((AccountsPayableDocument) this
166: .getDocument()).getItems();
167: countOfBelowTheLine = PurApItemUtils
168: .countBelowTheLineItems(items);
169: countOfAboveTheLine = items.size() - countOfBelowTheLine;
170: }
171:
172: }
|