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 017 package org.kuali.kfs.sys.businessobject; 018 019 import java.util.LinkedHashMap; 020 021 import org.apache.commons.lang.StringUtils; 022 import org.kuali.kfs.coa.businessobject.AccountingPeriod; 023 import org.kuali.kfs.fp.businessobject.AdvanceDepositDetail; 024 import org.kuali.kfs.fp.document.AdvanceDepositDocument; 025 import org.kuali.kfs.sys.KFSPropertyConstants; 026 import org.kuali.kfs.sys.context.SpringContext; 027 import org.kuali.rice.kew.exception.WorkflowException; 028 import org.kuali.rice.kns.bo.DocumentHeader; 029 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase; 030 import org.kuali.rice.kns.service.DocumentService; 031 import org.kuali.rice.kns.util.ObjectUtils; 032 033 /** 034 * This class is used to represent an electronic payment claim. 035 */ 036 public class ElectronicPaymentClaim extends PersistableBusinessObjectBase { 037 038 public final static class ClaimStatusCodes { 039 public final static String CLAIMED = "C"; 040 public final static String UNCLAIMED = "U"; 041 } 042 043 private String documentNumber; 044 private Integer financialDocumentLineNumber; 045 private String referenceFinancialDocumentNumber; 046 private Integer financialDocumentPostingYear; 047 private String financialDocumentPostingPeriodCode; 048 private String paymentClaimStatusCode; 049 050 private AdvanceDepositDocument generatingDocument; 051 private SourceAccountingLine generatingAccountingLine; 052 private AccountingPeriod financialDocumentPostingPeriod; 053 private DocumentHeader generatingDocumentHeader; 054 055 /** 056 * Default constructor. It constructs. 057 */ 058 public ElectronicPaymentClaim() {} 059 060 /** 061 * Gets the documentNumber attribute. 062 * 063 * @return Returns the documentNumber 064 */ 065 public String getDocumentNumber() { 066 return documentNumber; 067 } 068 069 /** 070 * Sets the documentNumber attribute. 071 * 072 * @param documentNumber The documentNumber to set. 073 */ 074 public void setDocumentNumber(String documentNumber) { 075 this.documentNumber = documentNumber; 076 } 077 078 079 /** 080 * Gets the financialDocumentLineNumber attribute. 081 * 082 * @return Returns the financialDocumentLineNumber 083 */ 084 public Integer getFinancialDocumentLineNumber() { 085 return financialDocumentLineNumber; 086 } 087 088 /** 089 * Sets the financialDocumentLineNumber attribute. 090 * 091 * @param financialDocumentLineNumber The financialDocumentLineNumber to set. 092 */ 093 public void setFinancialDocumentLineNumber(Integer financialDocumentLineNumber) { 094 this.financialDocumentLineNumber = financialDocumentLineNumber; 095 } 096 097 098 /** 099 * Gets the referenceFinancialDocumentNumber attribute. 100 * 101 * @return Returns the referenceFinancialDocumentNumber 102 */ 103 public String getReferenceFinancialDocumentNumber() { 104 return referenceFinancialDocumentNumber; 105 } 106 107 /** 108 * Sets the referenceFinancialDocumentNumber attribute. 109 * 110 * @param referenceFinancialDocumentNumber The referenceFinancialDocumentNumber to set. 111 */ 112 public void setReferenceFinancialDocumentNumber(String referenceFinancialDocumentNumber) { 113 this.referenceFinancialDocumentNumber = referenceFinancialDocumentNumber; 114 } 115 116 117 /** 118 * Gets the financialDocumentPostingYear attribute. 119 * 120 * @return Returns the financialDocumentPostingYear 121 */ 122 public Integer getFinancialDocumentPostingYear() { 123 return financialDocumentPostingYear; 124 } 125 126 /** 127 * Sets the financialDocumentPostingYear attribute. 128 * 129 * @param financialDocumentPostingYear The financialDocumentPostingYear to set. 130 */ 131 public void setFinancialDocumentPostingYear(Integer financialDocumentPostingYear) { 132 this.financialDocumentPostingYear = financialDocumentPostingYear; 133 } 134 135 136 /** 137 * Gets the financialDocumentPostingPeriodCode attribute. 138 * 139 * @return Returns the financialDocumentPostingPeriodCode 140 */ 141 public String getFinancialDocumentPostingPeriodCode() { 142 return financialDocumentPostingPeriodCode; 143 } 144 145 /** 146 * Sets the financialDocumentPostingPeriodCode attribute. 147 * 148 * @param financialDocumentPostingPeriodCode The financialDocumentPostingPeriodCode to set. 149 */ 150 public void setFinancialDocumentPostingPeriodCode(String financialDocumentPostingPeriodCode) { 151 this.financialDocumentPostingPeriodCode = financialDocumentPostingPeriodCode; 152 } 153 154 /** 155 * Gets the paymentClaimStatusCode attribute. 156 * @return Returns the paymentClaimStatusCode. 157 */ 158 public String getPaymentClaimStatusCode() { 159 return paymentClaimStatusCode; 160 } 161 162 /** 163 * Sets the paymentClaimStatusCode attribute value. 164 * @param paymentClaimStatusCode The paymentClaimStatusCode to set. 165 */ 166 public void setPaymentClaimStatusCode(String paymentClaimStatusCode) { 167 this.paymentClaimStatusCode = paymentClaimStatusCode; 168 } 169 170 /** 171 * Gets the generatingDocument attribute. 172 * @return Returns the generatingDocument. 173 */ 174 public AdvanceDepositDocument getGeneratingDocument() { 175 final boolean docNumbersAreDifferentAndNotNull = (generatingDocumentHeader != null && !documentNumber.equals(this.generatingDocumentHeader.getDocumentNumber())); 176 if (StringUtils.isNotBlank(documentNumber) && (this.generatingDocument == null || docNumbersAreDifferentAndNotNull)) { 177 try { 178 generatingDocument = (AdvanceDepositDocument)SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentNumber); 179 } 180 catch (WorkflowException we) { 181 throw new RuntimeException("Could not retrieve Document #"+documentNumber, we); 182 } 183 } 184 return this.generatingDocument; 185 } 186 187 /** 188 * Gets the generatingDocumentHeader attribute. 189 * @return Returns the generatingDocumentHeader. 190 */ 191 public DocumentHeader getGeneratingDocumentHeader() { 192 return generatingDocumentHeader; 193 } 194 195 /** 196 * Sets the generatingDocumentHeader attribute value. 197 * @param generatingDocumentHeader The generatingDocumentHeader to set. 198 * @deprecated 199 */ 200 public void setGeneratingDocumentHeader(DocumentHeader generatingDocumentHeader) { 201 this.generatingDocumentHeader = generatingDocumentHeader; 202 } 203 204 /** 205 * Returns the accounting line on the generating Advance Deposit document for the transaction which generated this record 206 * @return the accounting line that describes the transaction responsible for the creation of this record 207 */ 208 public SourceAccountingLine getGeneratingAccountingLine() { 209 if (generatingAccountingLine == null) { 210 final AdvanceDepositDocument generatingDocument = getGeneratingDocument(); 211 if (generatingDocument != null && generatingDocument.getSourceAccountingLines() != null) { 212 int count = 0; 213 214 while (generatingAccountingLine == null && count < generatingDocument.getSourceAccountingLines().size()) { 215 if (generatingDocument.getSourceAccountingLine(count).getSequenceNumber().equals(getFinancialDocumentLineNumber())) { 216 generatingAccountingLine = generatingDocument.getSourceAccountingLine(count); 217 } 218 count += 1; 219 } 220 221 } 222 } 223 return generatingAccountingLine; 224 } 225 226 /** 227 * Returns the AdvanceDepositDetail for the first deposit detail on this document 228 * @return the advance deposit detail that describes the transaction responsible for the creation of this record 229 */ 230 public AdvanceDepositDetail getGeneratingAdvanceDepositDetail() { 231 final AdvanceDepositDocument generatingDocument = getGeneratingDocument(); 232 if (generatingDocument != null && !ObjectUtils.isNull(generatingDocument.getAdvanceDeposits()) && !generatingDocument.getAdvanceDeposits().isEmpty()) { 233 return generatingDocument.getAdvanceDepositDetail(0); 234 } 235 return null; 236 } 237 238 /** 239 * Gets the financialDocumentPostingPeriod attribute. 240 * @return Returns the financialDocumentPostingPeriod. 241 */ 242 public AccountingPeriod getFinancialDocumentPostingPeriod() { 243 return financialDocumentPostingPeriod; 244 } 245 246 /** 247 * Sets the financialDocumentPostingPeriod attribute value. 248 * @param financialDocumentPostingPeriod The financialDocumentPostingPeriod to set. 249 */ 250 public void setFinancialDocumentPostingPeriod(AccountingPeriod financialDocumentPostingPeriod) { 251 this.financialDocumentPostingPeriod = financialDocumentPostingPeriod; 252 } 253 254 /** 255 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 256 */ 257 protected LinkedHashMap toStringMapper() { 258 LinkedHashMap m = new LinkedHashMap(); 259 m.put(KFSPropertyConstants.DOCUMENT_NUMBER, this.documentNumber); 260 if (this.financialDocumentLineNumber != null) { 261 m.put("financialDocumentLineNumber", this.financialDocumentLineNumber.toString()); 262 } 263 return m; 264 } 265 266 /** 267 * Returns the String representation for an Electronic Payment Claim record, to be used by the claimed 268 * checkbox 269 * @param claim a claim to get a String representation for 270 * @return the representation in the form of "{generating document number}::{generating document accounting line sequence number}" 271 */ 272 public String getElectronicPaymentClaimRepresentation() { 273 StringBuilder representation = new StringBuilder(); 274 representation.append(getDocumentNumber()); 275 representation.append("::"); 276 representation.append(getFinancialDocumentLineNumber()); 277 return representation.toString(); 278 } 279 280 /** 281 * @return a descriptive version of the paymentClaimStatusCode field 282 */ 283 public String getPaymentClaimStatus() { 284 return getPaymentClaimStatusCode().equals("C") ? "Claimed" : "Unclaimed"; 285 } 286 }