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.ar.document; 017 018 import java.util.ArrayList; 019 import java.util.HashMap; 020 import java.util.LinkedHashMap; 021 import java.util.List; 022 import java.util.Map; 023 024 import org.apache.commons.lang.StringUtils; 025 import org.apache.log4j.Logger; 026 import org.kuali.kfs.coa.businessobject.AccountingPeriod; 027 import org.kuali.kfs.fp.document.GeneralErrorCorrectionDocument; 028 import org.kuali.kfs.gl.service.EntryService; 029 import org.kuali.kfs.module.ar.ArConstants; 030 import org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader; 031 import org.kuali.kfs.module.ar.businessobject.CashControlDetail; 032 import org.kuali.kfs.module.ar.businessobject.PaymentMedium; 033 import org.kuali.kfs.module.ar.document.service.CashControlDocumentService; 034 import org.kuali.kfs.sys.KFSConstants; 035 import org.kuali.kfs.sys.KFSParameterKeyConstants; 036 import org.kuali.kfs.sys.businessobject.AccountingLine; 037 import org.kuali.kfs.sys.businessobject.Bank; 038 import org.kuali.kfs.sys.businessobject.ElectronicPaymentClaim; 039 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry; 040 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper; 041 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail; 042 import org.kuali.kfs.sys.context.SpringContext; 043 import org.kuali.kfs.sys.document.AmountTotaling; 044 import org.kuali.kfs.sys.document.ElectronicPaymentClaiming; 045 import org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource; 046 import org.kuali.kfs.sys.document.GeneralLedgerPostingDocument; 047 import org.kuali.kfs.sys.document.GeneralLedgerPostingDocumentBase; 048 import org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE; 049 import org.kuali.kfs.sys.service.BankService; 050 import org.kuali.kfs.sys.service.ElectronicPaymentClaimingService; 051 import org.kuali.kfs.sys.service.UniversityDateService; 052 import org.kuali.rice.kew.exception.WorkflowException; 053 import org.kuali.rice.kns.datadictionary.DocumentEntry; 054 import org.kuali.rice.kns.document.Document; 055 import org.kuali.rice.kns.service.BusinessObjectService; 056 import org.kuali.rice.kns.service.DataDictionaryService; 057 import org.kuali.rice.kns.service.DocumentService; 058 import org.kuali.rice.kns.service.ParameterService; 059 import org.kuali.rice.kns.util.KualiDecimal; 060 import org.kuali.rice.kns.web.format.CurrencyFormatter; 061 062 /** 063 * @author Kuali Nervous System Team (kualidev@oncourse.iu.edu) 064 */ 065 public class CashControlDocument extends GeneralLedgerPostingDocumentBase implements AmountTotaling, GeneralLedgerPendingEntrySource, ElectronicPaymentClaiming, GeneralLedgerPostingDocument { 066 protected static final String NODE_ASSOCIATED_WITH_ELECTRONIC_PAYMENT = "AssociatedWithElectronicPayment"; 067 protected static Logger LOG = org.apache.log4j.Logger.getLogger(CashControlDocument.class); 068 069 protected String referenceFinancialDocumentNumber; 070 protected Integer universityFiscalYear; 071 protected String universityFiscalPeriodCode; 072 protected String customerPaymentMediumCode; 073 protected KualiDecimal cashControlTotalAmount = KualiDecimal.ZERO; 074 protected String lockboxNumber; 075 protected String bankCode; 076 077 protected Bank bank; 078 protected PaymentMedium customerPaymentMedium; 079 protected AccountingPeriod universityFiscalPeriod; 080 protected AccountsReceivableDocumentHeader accountsReceivableDocumentHeader; 081 082 protected List<CashControlDetail> cashControlDetails; 083 084 protected List<GeneralLedgerPendingEntry> generalLedgerPendingEntries; 085 protected final static String GENERAL_LEDGER_POSTING_HELPER_BEAN_ID = "kfsGenericGeneralLedgerPostingHelper"; 086 protected List<ElectronicPaymentClaim> electronicPaymentClaims; 087 088 /** 089 * Default constructor. 090 */ 091 public CashControlDocument() { 092 super(); 093 accountsReceivableDocumentHeader = new AccountsReceivableDocumentHeader(); 094 customerPaymentMedium = new PaymentMedium(); 095 096 // Set the university fiscal year to the current values 097 UniversityDateService universityDateService = SpringContext.getBean(UniversityDateService.class); 098 universityFiscalYear = universityDateService.getCurrentUniversityDate().getUniversityFiscalYear(); 099 universityFiscalPeriod = universityDateService.getCurrentUniversityDate().getAccountingPeriod(); 100 101 cashControlDetails = new ArrayList<CashControlDetail>(); 102 generalLedgerPendingEntries = new ArrayList<GeneralLedgerPendingEntry>(); 103 electronicPaymentClaims = new ArrayList<ElectronicPaymentClaim>(); 104 // retrieve value from param table and set to default 105 try { 106 DataDictionaryService ddService = SpringContext.getBean(DataDictionaryService.class); 107 DocumentEntry docEntry = ddService.getDataDictionary().getDocumentEntry(ddService.getValidDocumentClassByTypeName("CTRL").getCanonicalName()); 108 String documentTypeCode = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass()); 109 if (SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) { 110 bankCode = SpringContext.getBean(ParameterService.class).getParameterValue(Bank.class, KFSParameterKeyConstants.DEFAULT_BANK_BY_DOCUMENT_TYPE, documentTypeCode); 111 } 112 } 113 catch (Exception x) { 114 LOG.error("Problem occurred setting default bank code for cash control document", x); 115 } 116 } 117 118 /** 119 * Gets the documentNumber attribute. 120 * 121 * @return Returns the documentNumber 122 */ 123 public String getDocumentNumber() { 124 return documentNumber; 125 } 126 127 /** 128 * Sets the documentNumber attribute. 129 * 130 * @param documentNumber The documentNumber to set. 131 */ 132 public void setDocumentNumber(String documentNumber) { 133 this.documentNumber = documentNumber; 134 } 135 136 137 /** 138 * Gets the referenceFinancialDocumentNumber attribute. 139 * 140 * @return Returns the referenceFinancialDocumentNumber 141 */ 142 public String getReferenceFinancialDocumentNumber() { 143 return referenceFinancialDocumentNumber; 144 } 145 146 /** 147 * Sets the referenceFinancialDocumentNumber attribute. 148 * 149 * @param referenceFinancialDocumentNumber The referenceFinancialDocumentNumber to set. 150 */ 151 public void setReferenceFinancialDocumentNumber(String referenceFinancialDocumentNumber) { 152 this.referenceFinancialDocumentNumber = referenceFinancialDocumentNumber; 153 } 154 155 156 /** 157 * Gets the universityFiscalYear attribute. 158 * 159 * @return Returns the universityFiscalYear 160 */ 161 public Integer getUniversityFiscalYear() { 162 return universityFiscalYear; 163 } 164 165 /** 166 * Sets the universityFiscalYear attribute. 167 * 168 * @param universityFiscalYear The universityFiscalYear to set. 169 */ 170 public void setUniversityFiscalYear(Integer universityFiscalYear) { 171 this.universityFiscalYear = universityFiscalYear; 172 } 173 174 175 /** 176 * Gets the universityFiscalPeriodCode attribute. 177 * 178 * @return Returns the universityFiscalPeriodCode 179 */ 180 public String getUniversityFiscalPeriodCode() { 181 return universityFiscalPeriodCode; 182 } 183 184 /** 185 * Sets the universityFiscalPeriodCode attribute. 186 * 187 * @param universityFiscalPeriodCode The universityFiscalPeriodCode to set. 188 */ 189 public void setUniversityFiscalPeriodCode(String universityFiscalPeriodCode) { 190 this.universityFiscalPeriodCode = universityFiscalPeriodCode; 191 } 192 193 194 /** 195 * Gets the customerPaymentMediumCode attribute. 196 * 197 * @return Returns the customerPaymentMediumCode 198 */ 199 public String getCustomerPaymentMediumCode() { 200 return customerPaymentMediumCode; 201 } 202 203 /** 204 * Sets the customerPaymentMediumCode attribute. 205 * 206 * @param customerPaymentMediumCode The customerPaymentMediumCode to set. 207 */ 208 public void setCustomerPaymentMediumCode(String customerPaymentMediumCode) { 209 this.customerPaymentMediumCode = customerPaymentMediumCode; 210 } 211 212 213 /** 214 * Gets the cashControlTotalAmount attribute. 215 * 216 * @return Returns the cashControlTotalAmount 217 */ 218 public KualiDecimal getCashControlTotalAmount() { 219 return cashControlTotalAmount; 220 } 221 222 /** 223 * Sets the cashControlTotalAmount attribute. 224 * 225 * @param cashControlTotalAmount The cashControlTotalAmount to set. 226 */ 227 public void setCashControlTotalAmount(KualiDecimal cashControlTotalAmount) { 228 this.cashControlTotalAmount = cashControlTotalAmount; 229 } 230 231 /** 232 * Gets the universityFiscalPeriod attribute. 233 * 234 * @return Returns the universityFiscalPeriod 235 */ 236 public AccountingPeriod getUniversityFiscalPeriod() { 237 return universityFiscalPeriod; 238 } 239 240 /** 241 * Sets the universityFiscalPeriod attribute. 242 * 243 * @param universityFiscalPeriod The universityFiscalPeriod to set. 244 * @deprecated 245 */ 246 public void setUniversityFiscalPeriod(AccountingPeriod universityFiscalPeriod) { 247 this.universityFiscalPeriod = universityFiscalPeriod; 248 } 249 250 /** 251 * Gets the accountsReceivableDocumentHeader attribute. 252 * 253 * @return Returns the accountsReceivableDocumentHeader. 254 */ 255 public AccountsReceivableDocumentHeader getAccountsReceivableDocumentHeader() { 256 return accountsReceivableDocumentHeader; 257 } 258 259 /** 260 * Sets the accountsReceivableDocumentHeader attribute value. 261 * 262 * @param accountsReceivableDocumentHeader The accountsReceivableDocumentHeader to set. 263 */ 264 public void setAccountsReceivableDocumentHeader(AccountsReceivableDocumentHeader accountsReceivableDocumentHeader) { 265 this.accountsReceivableDocumentHeader = accountsReceivableDocumentHeader; 266 } 267 268 /** 269 * Gets the cashControlDetails attribute. 270 * 271 * @return Returns the cashControlDetails. 272 */ 273 public List<CashControlDetail> getCashControlDetails() { 274 return cashControlDetails; 275 } 276 277 /** 278 * Sets the cashControlDetails attribute value. 279 * 280 * @param cashControlDetails The cashControlDetails to set. 281 */ 282 public void setCashControlDetails(List<CashControlDetail> cashControlDetails) { 283 this.cashControlDetails = cashControlDetails; 284 } 285 286 /** 287 * This method adds a new cash control detail to the list 288 * 289 * @param cashControlDetail 290 */ 291 public void addCashControlDetail(CashControlDetail cashControlDetail) { 292 prepareCashControlDetail(cashControlDetail); 293 if (cashControlDetail.getFinancialDocumentLineAmount() != null) { 294 this.cashControlTotalAmount = this.cashControlTotalAmount.add(cashControlDetail.getFinancialDocumentLineAmount()); 295 } 296 cashControlDetails.add(cashControlDetail); 297 } 298 299 /** 300 * This method removes a cash control detail from the list 301 * 302 * @param index 303 */ 304 public void deleteCashControlDetail(int index) { 305 CashControlDetail cashControlDetail = cashControlDetails.remove(index); 306 this.cashControlTotalAmount = this.cashControlTotalAmount.subtract(cashControlDetail.getFinancialDocumentLineAmount()); 307 } 308 309 /** 310 * This is a helper method that automatically populates document specfic information into the cash control detail deposit 311 * (CashControlDetail) instance. 312 */ 313 protected void prepareCashControlDetail(CashControlDetail cashControlDetail) { 314 cashControlDetail.setDocumentNumber(this.getDocumentNumber()); 315 } 316 317 /** 318 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper() 319 */ 320 @SuppressWarnings("unchecked") 321 protected LinkedHashMap toStringMapper() { 322 LinkedHashMap m = new LinkedHashMap(); 323 m.put("documentNumber", this.documentNumber); 324 return m; 325 } 326 327 /** 328 * Gets the customerPaymentMedium attribute. 329 * 330 * @return Returns the customerPaymentMedium 331 */ 332 public PaymentMedium getCustomerPaymentMedium() { 333 return customerPaymentMedium; 334 } 335 336 /** 337 * Sets the customerPaymentMedium attribute value. 338 * 339 * @param customerPaymentMedium The customerPaymentMedium to set. 340 */ 341 public void setCustomerPaymentMedium(PaymentMedium customerPaymentMedium) { 342 this.customerPaymentMedium = customerPaymentMedium; 343 } 344 345 /** 346 * @see org.kuali.kfs.sys.document.AmountTotaling#getTotalDollarAmount() 347 */ 348 public KualiDecimal getTotalDollarAmount() { 349 return getCashControlTotalAmount(); 350 } 351 352 /** 353 * This method returns the advance deposit total amount as a currency formatted string. 354 * 355 * @return String 356 */ 357 public String getCurrencyFormattedTotalCashControlAmount() { 358 return (String) new CurrencyFormatter().format(getCashControlTotalAmount()); 359 } 360 361 /** 362 * Retrieves a specific cash control detail from the list, by array index 363 * 364 * @param index the index of the cash control details to retrieve the cash control detail from 365 * @return a CashControlDetail 366 */ 367 public CashControlDetail getCashControlDetail(int index) { 368 if (index >= cashControlDetails.size()) { 369 for (int i = cashControlDetails.size(); i <= index; i++) { 370 cashControlDetails.add(new CashControlDetail()); 371 } 372 } 373 return cashControlDetails.get(index); 374 } 375 376 /** 377 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#addPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) 378 */ 379 public void addPendingEntry(GeneralLedgerPendingEntry entry) { 380 generalLedgerPendingEntries.add(entry); 381 382 } 383 384 /** 385 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#clearAnyGeneralLedgerPendingEntries() 386 */ 387 public void clearAnyGeneralLedgerPendingEntries() { 388 generalLedgerPendingEntries = new ArrayList<GeneralLedgerPendingEntry>(); 389 390 } 391 392 /** 393 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#customizeExplicitGeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail, 394 * org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) 395 */ 396 public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) { 397 if (explicitEntry.getFinancialDocumentTypeCode().equalsIgnoreCase(KFSConstants.FinancialDocumentTypeCodes.GENERAL_ERROR_CORRECTION)) { 398 explicitEntry.setTransactionLedgerEntryDescription(buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(postable)); 399 400 // Clearing fields that are already handled by the parent algorithm - we don't actually want 401 // these to copy over from the accounting lines b/c they don't belong in the GLPEs 402 // if the aren't nulled, then GECs fail to post 403 explicitEntry.setReferenceFinancialDocumentNumber(null); 404 explicitEntry.setReferenceFinancialSystemOriginationCode(null); 405 explicitEntry.setReferenceFinancialDocumentTypeCode(null); 406 } 407 408 } 409 410 /** 411 * Builds an appropriately formatted string to be used for the <code>transactionLedgerEntryDescription</code>. It is built 412 * using information from the <code>{@link AccountingLine}</code>. Format is "01-12345: blah blah blah". 413 * 414 * @param line accounting line 415 * @param transactionalDocument submitted accounting document 416 * @return String formatted string to be used for transaction ledger entry description 417 */ 418 protected String buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(GeneralLedgerPendingEntrySourceDetail line) { 419 String description = ""; 420 description = line.getReferenceOriginCode() + "-" + line.getReferenceNumber(); 421 422 if (StringUtils.isNotBlank(line.getFinancialDocumentLineDescription())) { 423 description += ": " + line.getFinancialDocumentLineDescription(); 424 } 425 else { 426 description += ": " + getDocumentHeader().getDocumentDescription(); 427 } 428 429 if (description.length() > GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH) { 430 description = description.substring(0, GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH - 3) + "..."; 431 } 432 433 return description; 434 } 435 436 public boolean customizeOffsetGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail accountingLine, GeneralLedgerPendingEntry explicitEntry, GeneralLedgerPendingEntry offsetEntry) { 437 return false; 438 } 439 440 /** 441 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#generateDocumentGeneralLedgerPendingEntries(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) 442 */ 443 public boolean generateDocumentGeneralLedgerPendingEntries(GeneralLedgerPendingEntrySequenceHelper sequenceHelper) { 444 boolean success = true; 445 CashControlDocumentService cashControlDocumentService = SpringContext.getBean(CashControlDocumentService.class); 446 447 if (this.getCustomerPaymentMediumCode().equalsIgnoreCase(ArConstants.PaymentMediumCode.CHECK)) { 448 success &= cashControlDocumentService.createCashReceiptGLPEs(this, sequenceHelper); 449 success &= cashControlDocumentService.createBankOffsetGLPEs(this, sequenceHelper); 450 } 451 else if (this.getCustomerPaymentMediumCode().equalsIgnoreCase(ArConstants.PaymentMediumCode.WIRE_TRANSFER)) { 452 success &= cashControlDocumentService.createDistributionOfIncomeAndExpenseGLPEs(this, sequenceHelper); 453 } 454 else if (this.getCustomerPaymentMediumCode().equalsIgnoreCase(ArConstants.PaymentMediumCode.CREDIT_CARD)) { 455 success &= cashControlDocumentService.createGeneralErrorCorrectionGLPEs(this, sequenceHelper); 456 } 457 458 return success; 459 } 460 461 /** 462 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#getGeneralLedgerPendingEntryAmountForGeneralLedgerPostable(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail) 463 */ 464 public KualiDecimal getGeneralLedgerPendingEntryAmountForDetail(GeneralLedgerPendingEntrySourceDetail postable) { 465 return postable.getAmount().abs(); 466 } 467 468 /** 469 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#getGeneralLedgerPostables() 470 */ 471 public List<GeneralLedgerPendingEntrySourceDetail> getGeneralLedgerPendingEntrySourceDetails() { 472 return new ArrayList<GeneralLedgerPendingEntrySourceDetail>(); 473 } 474 475 476 /** 477 * The Cash Control document doesn't generate general ledger pending entries based off of the accounting lines on the document 478 * 479 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#generateGeneralLedgerPendingEntries(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail, 480 * org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper) 481 */ 482 public boolean generateGeneralLedgerPendingEntries(GeneralLedgerPendingEntrySourceDetail glpeSourceDetail, GeneralLedgerPendingEntrySequenceHelper sequenceHelper) { 483 return true; 484 } 485 486 /** 487 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#getPostingYear() 488 */ 489 public Integer getPostingYear() { 490 return SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear(); 491 } 492 493 /** 494 * @see org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource#isDebit(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail) 495 */ 496 public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) { 497 AccountingLine accountingLine = (AccountingLine) postable; 498 return (accountingLine.getDebitCreditCode().equalsIgnoreCase(KFSConstants.GL_DEBIT_CODE)); 499 } 500 501 /** 502 * This method gets the glpes 503 * 504 * @return a list of glpes 505 */ 506 public List<GeneralLedgerPendingEntry> getGeneralLedgerPendingEntries() { 507 return generalLedgerPendingEntries; 508 } 509 510 /** 511 * This method sets the glpes 512 * 513 * @param generalLedgerPendingEntries 514 */ 515 public void setGeneralLedgerPendingEntries(List<GeneralLedgerPendingEntry> generalLedgerPendingEntries) { 516 this.generalLedgerPendingEntries = generalLedgerPendingEntries; 517 } 518 519 /** 520 * This method set glpes status to approved 521 */ 522 public void changeGeneralLedgerPendingEntriesApprovedStatusCode() { 523 for (GeneralLedgerPendingEntry glpe : getGeneralLedgerPendingEntries()) { 524 glpe.setFinancialDocumentApprovedCode(KFSConstants.DocumentStatusCodes.APPROVED); 525 } 526 } 527 528 /** 529 * This method gets an glpe by it's index in the list of glpes 530 * 531 * @param index the glpe index 532 * @return the glpe 533 */ 534 public GeneralLedgerPendingEntry getGeneralLedgerPendingEntry(int index) { 535 while (generalLedgerPendingEntries.size() <= index) { 536 generalLedgerPendingEntries.add(new GeneralLedgerPendingEntry()); 537 } 538 return generalLedgerPendingEntries.get(index); 539 } 540 541 public String getLockboxNumber() { 542 CashControlDocumentService cashControlDocumentService = SpringContext.getBean(CashControlDocumentService.class); 543 this.lockboxNumber = cashControlDocumentService.getLockboxNumber(this); 544 return lockboxNumber; 545 } 546 547 /** 548 * @see org.kuali.rice.kns.document.DocumentBase#populateDocumentForRouting() 549 */ 550 @Override 551 public void populateDocumentForRouting() { 552 553 CashControlDocumentService cashControlDocumentService = SpringContext.getBean(CashControlDocumentService.class); 554 this.lockboxNumber = cashControlDocumentService.getLockboxNumber(this); 555 super.populateDocumentForRouting(); 556 557 } 558 559 /** 560 * @see org.kuali.kfs.sys.document.ElectronicPaymentClaiming#declaimElectronicPaymentClaims() 561 */ 562 public void declaimElectronicPaymentClaims() { 563 SpringContext.getBean(ElectronicPaymentClaimingService.class).declaimElectronicPaymentClaimsForDocument(this); 564 } 565 566 /** 567 * This method gets electronicPaymentClaims 568 * 569 * @return electronicPaymentClaims 570 */ 571 public List<ElectronicPaymentClaim> getElectronicPaymentClaims() { 572 return electronicPaymentClaims; 573 } 574 575 /** 576 * This method sets electronicPaymentClaims 577 * 578 * @param electronicPaymentClaims 579 * @deprecated 580 */ 581 public void setElectronicPaymentClaims(List<ElectronicPaymentClaim> electronicPaymentClaims) { 582 this.electronicPaymentClaims = electronicPaymentClaims; 583 } 584 585 public String getFinancialDocumentTypeCode() { 586 // TODO Auto-generated method stub 587 return null; 588 } 589 590 public Document getReferenceFinancialDocument() { 591 DocumentService documentService = SpringContext.getBean(DocumentService.class); 592 Document document = null; 593 try { 594 document = documentService.getByDocumentHeaderId(getReferenceFinancialDocumentNumber()); 595 } 596 catch (WorkflowException we) { 597 598 } 599 return document; 600 } 601 602 /** 603 * Gets the bankCode attribute. 604 * 605 * @return Returns the bankCode. 606 */ 607 public String getBankCode() { 608 return bankCode; 609 } 610 611 /** 612 * Sets the bankCode attribute value. 613 * 614 * @param bankCode The bankCode to set. 615 */ 616 public void setBankCode(String bankCode) { 617 this.bankCode = bankCode; 618 } 619 620 621 /** 622 * Answers true when document payment medium is WIRE transfer 623 * 624 * @see org.kuali.kfs.sys.document.FinancialSystemTransactionalDocumentBase#answerSplitNodeQuestion(java.lang.String) 625 */ 626 @Override 627 public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException { 628 if (NODE_ASSOCIATED_WITH_ELECTRONIC_PAYMENT.equals(nodeName)) { 629 if (ArConstants.PaymentMediumCode.WIRE_TRANSFER.equals(getCustomerPaymentMediumCode())) { 630 return true; 631 } 632 else { 633 return false; 634 } 635 } 636 throw new UnsupportedOperationException("answerSplitNodeQuestion('" + nodeName + "') called, but no handler setup to deal with this nodeName."); 637 } 638 639 /** 640 * This is a helper method added to support workflow attribute configuration. This method helps to avoid attribute name mismatch 641 * between ProcessingChartOfAccountCode and chartOfAccountsCode 642 * 643 * @return ProcessingChartOfAccountCode 644 */ 645 public String getChartOfAccountsCode() { 646 if (getAccountsReceivableDocumentHeader() != null) { 647 return getAccountsReceivableDocumentHeader().getProcessingChartOfAccountCode(); 648 } 649 return null; 650 } 651 652 /** 653 * This is a helper method added to support workflow attribute configuration. This method helps to avoid attribute name mismatch 654 * between ProcessingOrganizationCode and organizationCode 655 * 656 * @return ProcessingOrganizationCode 657 */ 658 public String getOrganizationCode() { 659 if (getAccountsReceivableDocumentHeader() != null) { 660 return getAccountsReceivableDocumentHeader().getProcessingOrganizationCode(); 661 } 662 return null; 663 } 664 665 public Bank getBank() { 666 return bank; 667 } 668 669 public void setBank(Bank bank) { 670 this.bank = bank; 671 } 672 673 public void recalculateTotals() { 674 KualiDecimal total = KualiDecimal.ZERO; 675 for (CashControlDetail cashControlDetail : getCashControlDetails()) { 676 total = total.add(cashControlDetail.getFinancialDocumentLineAmount()); 677 } 678 cashControlTotalAmount = total; 679 getDocumentHeader().setFinancialDocumentTotalAmount(total); 680 } 681 682 @Override 683 public void prepareForSave() { 684 685 // remove all the cash control detail records from the db in prep for the save, 686 // where they'll get re-persisted. This is necessary to make sure that details 687 // deleted on the form are actually deleted, as OJB does a terrible job at this 688 // by itself. 689 deleteCashControlDetailsFromDB(); 690 recalculateTotals(); 691 } 692 693 protected void deleteCashControlDetailsFromDB() { 694 BusinessObjectService boService = SpringContext.getBean(BusinessObjectService.class); 695 Map<String, String> pkMap = new HashMap<String, String>(); 696 pkMap.put("documentNumber", getDocumentNumber()); 697 boService.deleteMatching(CashControlDetail.class, pkMap); 698 } 699 700 /** 701 * This is a method to check the count of gl entries according to the input fields and values 702 * 703 * @return totalGLRecordsCreated returns the count of the gl entries 704 */ 705 public Integer getGeneralLedgerEntriesPostedCount() { 706 Map<String, Object> pkMap = new HashMap<String, Object>(); 707 pkMap.put("documentNumber", this.getDocumentNumber()); 708 pkMap.put("universityFiscalYear", this.getPostingYear().toString()); 709 pkMap.put("universityFiscalPeriodCode", this.getPostingPeriodCode()); 710 pkMap.put("chartOfAccountsCode", this.getChartOfAccountsCode()); 711 712 Integer totalGLRecordsCreated = SpringContext.getBean(EntryService.class).getEntryRecordCount(pkMap); 713 714 return totalGLRecordsCreated; 715 } 716 }