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.fp.document.web.struts; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import javax.servlet.http.HttpServletRequest; 022 023 import org.apache.commons.lang.StringUtils; 024 import org.apache.struts.util.LabelValueBean; 025 import org.kuali.kfs.fp.businessobject.CapitalAssetInformation; 026 import org.kuali.kfs.fp.businessobject.CashDrawer; 027 import org.kuali.kfs.fp.businessobject.Check; 028 import org.kuali.kfs.fp.document.CapitalAssetEditable; 029 import org.kuali.kfs.fp.document.CashManagementDocument; 030 import org.kuali.kfs.fp.document.CashReceiptDocument; 031 import org.kuali.kfs.fp.document.service.CashManagementService; 032 import org.kuali.kfs.fp.document.service.CashReceiptCoverSheetService; 033 import org.kuali.kfs.fp.document.service.CashReceiptService; 034 import org.kuali.kfs.fp.service.CashDrawerService; 035 import org.kuali.kfs.sys.KFSConstants; 036 import org.kuali.kfs.sys.KFSKeyConstants; 037 import org.kuali.kfs.sys.KFSConstants.DocumentStatusCodes.CashReceipt; 038 import org.kuali.kfs.sys.context.SpringContext; 039 import org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase; 040 import org.kuali.rice.kns.service.KualiConfigurationService; 041 import org.kuali.rice.kns.util.KualiDecimal; 042 import org.kuali.rice.kns.web.format.SimpleBooleanFormatter; 043 044 /** 045 * This class is the action form for Cash Receipts. 046 */ 047 public class CashReceiptForm extends KualiAccountingDocumentFormBase implements CapitalAssetEditable{ 048 protected static final long serialVersionUID = 1L; 049 protected static final String CAN_PRINT_COVERSHEET_SIG_STR = "isCoverSheetPrintingAllowed"; 050 051 protected Check newCheck; 052 053 protected KualiDecimal checkTotal; 054 055 protected String checkEntryMode; 056 protected List checkEntryModes; 057 058 protected List baselineChecks; 059 060 protected CapitalAssetInformation capitalAssetInformation; 061 062 /** 063 * Constructs a CashReceiptForm.java. 064 */ 065 public CashReceiptForm() { 066 super(); 067 setFormatterType(CAN_PRINT_COVERSHEET_SIG_STR, SimpleBooleanFormatter.class); 068 setNewCheck(getCashReceiptDocument().createNewCheck()); 069 070 checkEntryModes = new ArrayList(); 071 checkEntryModes.add(new LabelValueBean("Individual Checks/Batches", CashReceiptDocument.CHECK_ENTRY_DETAIL)); 072 checkEntryModes.add(new LabelValueBean("Total Only", CashReceiptDocument.CHECK_ENTRY_TOTAL)); 073 074 baselineChecks = new ArrayList(); 075 076 this.setCapitalAssetInformation(new CapitalAssetInformation()); 077 } 078 079 @Override 080 protected String getDefaultDocumentTypeName() { 081 return "CR"; 082 } 083 084 @Override 085 public void populate(HttpServletRequest request) { 086 super.populate(request); 087 088 setCheckEntryMode(getCashReceiptDocument().getCheckEntryMode()); 089 } 090 091 /** 092 * @return CashReceiptDocument 093 */ 094 public CashReceiptDocument getCashReceiptDocument() { 095 return (CashReceiptDocument) getDocument(); 096 } 097 098 /** 099 * @return Check 100 */ 101 public Check getNewCheck() { 102 return newCheck; 103 } 104 105 /** 106 * @param newCheck 107 */ 108 public void setNewCheck(Check newCheck) { 109 this.newCheck = newCheck; 110 } 111 112 /** 113 * @param checkTotal 114 */ 115 public void setCheckTotal(KualiDecimal checkTotal) { 116 this.checkTotal = checkTotal; 117 } 118 119 /** 120 * @return KualiDecimal 121 */ 122 public KualiDecimal getCheckTotal() { 123 return checkTotal; 124 } 125 126 /** 127 * @return List of LabelValueBeans representing all available check entry modes 128 */ 129 public List getCheckEntryModes() { 130 return checkEntryModes; 131 } 132 133 /** 134 * @return String 135 */ 136 public String getCheckEntryMode() { 137 return checkEntryMode; 138 } 139 140 /** 141 * @param checkEntryMode 142 */ 143 public void setCheckEntryMode(String checkEntryMode) { 144 this.checkEntryMode = checkEntryMode; 145 } 146 147 /** 148 * @return boolean 149 */ 150 public boolean isCheckEntryDetailMode() { 151 return CashReceiptDocument.CHECK_ENTRY_DETAIL.equals(getCheckEntryMode()); 152 } 153 154 /** 155 * @return current List of baseline checks for use in update detection 156 */ 157 public List getBaselineChecks() { 158 return baselineChecks; 159 } 160 161 /** 162 * Sets the current List of baseline checks to the given List 163 * 164 * @param baselineChecks 165 */ 166 public void setBaselineChecks(List baselineChecks) { 167 this.baselineChecks = baselineChecks; 168 } 169 170 /** 171 * @param index 172 * @return true if a baselineCheck with the given index exists 173 */ 174 public boolean hasBaselineCheck(int index) { 175 boolean has = false; 176 177 if ((index >= 0) && (index < baselineChecks.size())) { 178 has = true; 179 } 180 181 return has; 182 } 183 184 /** 185 * Implementation creates empty Checks as a side-effect, so that Struts' efforts to set fields of lines which haven't been 186 * created will succeed rather than causing a NullPointerException. 187 * 188 * @param index 189 * @return baseline Check at the given index 190 */ 191 public Check getBaselineCheck(int index) { 192 while (baselineChecks.size() <= index) { 193 baselineChecks.add(getCashReceiptDocument().createNewCheck()); 194 } 195 return (Check) baselineChecks.get(index); 196 } 197 198 /** 199 * Gets the financialDocumentStatusMessage which is dependent upon document state. 200 * 201 * @return Returns the financialDocumentStatusMessage. 202 */ 203 public String getFinancialDocumentStatusMessage() { 204 String financialDocumentStatusMessage = ""; 205 CashReceiptDocument crd = getCashReceiptDocument(); 206 String financialDocumentStatusCode = crd.getDocumentHeader().getFinancialDocumentStatusCode(); 207 if (financialDocumentStatusCode.equals(CashReceipt.VERIFIED)) { 208 financialDocumentStatusMessage = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashReceipt.MSG_VERIFIED_BUT_NOT_AWAITING_DEPOSIT); 209 } 210 else if (financialDocumentStatusCode.equals(CashReceipt.INTERIM) || financialDocumentStatusCode.equals(CashReceipt.FINAL)) { 211 CashManagementDocument cmd = SpringContext.getBean(CashManagementService.class).getCashManagementDocumentForCashReceiptId(crd.getDocumentNumber()); 212 if (cmd != null) { 213 String cmdFinancialDocNbr = cmd.getDocumentNumber(); 214 215 String loadCMDocUrl = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashManagement.URL_LOAD_DOCUMENT_CASH_MGMT); 216 loadCMDocUrl = StringUtils.replace(loadCMDocUrl, "{0}", cmdFinancialDocNbr); 217 218 financialDocumentStatusMessage = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashReceipt.MSG_VERIFIED_AND_AWAITING_DEPOSIT); 219 financialDocumentStatusMessage = StringUtils.replace(financialDocumentStatusMessage, "{0}", loadCMDocUrl); 220 } 221 } 222 else if (financialDocumentStatusCode.equals(KFSConstants.DocumentStatusCodes.APPROVED)) { 223 CashManagementDocument cmd = SpringContext.getBean(CashManagementService.class).getCashManagementDocumentForCashReceiptId(crd.getDocumentNumber()); 224 if (cmd != null) { 225 String cmdFinancialDocNbr = cmd.getDocumentNumber(); 226 227 String loadCMDocUrl = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashManagement.URL_LOAD_DOCUMENT_CASH_MGMT); 228 loadCMDocUrl = StringUtils.replace(loadCMDocUrl, "{0}", cmdFinancialDocNbr); 229 230 financialDocumentStatusMessage = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashReceipt.MSG_VERIFIED_AND_DEPOSITED); 231 financialDocumentStatusMessage = StringUtils.replace(financialDocumentStatusMessage, "{0}", loadCMDocUrl); 232 } 233 } 234 return financialDocumentStatusMessage; 235 } 236 237 /** 238 * This method will build out a message in the case the document is ENROUTE and the cash drawer is closed. 239 * 240 * @return String 241 */ 242 public String getCashDrawerStatusMessage() { 243 String cashDrawerStatusMessage = ""; 244 CashReceiptDocument crd = getCashReceiptDocument(); 245 246 // first check to see if the document is in the appropriate state for this message 247 if (crd != null && crd.getDocumentHeader() != null && crd.getDocumentHeader().getWorkflowDocument() != null) { 248 if (crd.getDocumentHeader().getWorkflowDocument().stateIsEnroute()) { 249 CashDrawer cd = SpringContext.getBean(CashDrawerService.class).getByCampusCode(crd.getCampusLocationCode()); 250 if (cd != null && crd.getDocumentHeader().getWorkflowDocument().isApprovalRequested() && cd.isClosed() && !crd.getDocumentHeader().getWorkflowDocument().isAdHocRequested()) { 251 cashDrawerStatusMessage = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSKeyConstants.CashReceipt.MSG_CASH_DRAWER_CLOSED_VERIFICATION_NOT_ALLOWED); 252 cashDrawerStatusMessage = StringUtils.replace(cashDrawerStatusMessage, "{0}", crd.getCampusLocationCode()); 253 } 254 } 255 } 256 257 return cashDrawerStatusMessage; 258 } 259 260 /** 261 * determines if the <code>{@link CashReceiptDocument}</code> is in a state that allows printing of the cover sheet. 262 * 263 * @return boolean 264 */ 265 public boolean isCoverSheetPrintingAllowed() { 266 return SpringContext.getBean(CashReceiptCoverSheetService.class).isCoverSheetPrintingAllowed(getCashReceiptDocument()); 267 } 268 269 /** 270 * @see org.kuali.kfs.fp.document.CapitalAssetEditable#getCapitalAssetInformation() 271 */ 272 public CapitalAssetInformation getCapitalAssetInformation() { 273 return this.capitalAssetInformation; 274 } 275 276 /** 277 * @see org.kuali.kfs.fp.document.CapitalAssetEditable#setCapitalAssetInformation(org.kuali.kfs.fp.businessobject.CapitalAssetInformation) 278 */ 279 public void setCapitalAssetInformation(CapitalAssetInformation capitalAssetInformation) { 280 this.capitalAssetInformation = capitalAssetInformation; 281 } 282 283 /** 284 * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase#getExcludedmethodToCall() 285 */ 286 protected List<String> getExcludedmethodToCall() { 287 List<String> execludedMethodToCall = super.getExcludedmethodToCall(); 288 execludedMethodToCall.add("printCoverSheet"); 289 290 return execludedMethodToCall; 291 } 292 }