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.endow.document; 017 018 import org.apache.cxf.common.util.StringUtils; 019 import org.kuali.kfs.module.endow.EndowConstants.TransactionSourceTypeCode; 020 import org.kuali.kfs.module.endow.EndowConstants.TransactionSubTypeCode; 021 import org.kuali.kfs.module.endow.businessobject.EndowmentSourceTransactionSecurity; 022 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionSecurity; 023 import org.kuali.kfs.sys.document.AmountTotaling; 024 025 /** 026 * Endowment Unit/Share Adjustment (EUSA) transaction is available for those times when a number of units of a security held by the 027 * KEMID must be modified without affecting the original cost or carry value of the security tax lot(s). 028 */ 029 public class EndowmentUnitShareAdjustmentDocument extends EndowmentTaxLotLinesDocumentBase { 030 031 /** 032 * Constructs a EndowmentUnitShareAdjustmentDocument.java. 033 */ 034 public EndowmentUnitShareAdjustmentDocument() { 035 super(); 036 setTransactionSourceTypeCode(TransactionSourceTypeCode.MANUAL); 037 setTransactionSubTypeCode(TransactionSubTypeCode.NON_CASH); 038 039 initializeSubType(); 040 } 041 042 /** 043 * @see org.kuali.kfs.module.endow.document.EndowmentSecurityDetailsDocumentBase#prepareForSave() 044 */ 045 @Override 046 public void prepareForSave() { 047 if (this instanceof AmountTotaling) { 048 getDocumentHeader().setFinancialDocumentTotalAmount(((AmountTotaling) this).getTotalDollarAmount()); 049 } 050 051 sourceTransactionSecurities.clear(); 052 targetTransactionSecurities.clear(); 053 054 // functionality specific to the EndowmentUnitShareAdjustmentDocument. The document will have a source or target security 055 // detail depending on whether the user has entered source or target transaction lines (Decrease or Increase). The UI allows 056 // the user to enter a source security detail by default. This is adjusted before save so that the right security is saved 057 // in the DB. 058 if (this instanceof EndowmentUnitShareAdjustmentDocument) { 059 060 if (!StringUtils.isEmpty(sourceTransactionSecurity.getSecurityID())) { 061 062 if (this.getSourceTransactionLines() != null && this.getSourceTransactionLines().size() > 0) { 063 getSourceTransactionSecurities().add(0, sourceTransactionSecurity); 064 } 065 else if (this.getTargetTransactionLines() != null && this.getTargetTransactionLines().size() > 0) { 066 targetTransactionSecurity.setSecurityID(sourceTransactionSecurity.getSecurityID()); 067 targetTransactionSecurity.setRegistrationCode(sourceTransactionSecurity.getRegistrationCode()); 068 getTargetTransactionSecurities().add(0, targetTransactionSecurity); 069 } 070 } 071 } 072 } 073 074 /** 075 * @see org.kuali.kfs.module.endow.document.EndowmentSecurityDetailsDocumentBase#getSourceTransactionSecurity() 076 */ 077 @Override 078 public EndowmentTransactionSecurity getSourceTransactionSecurity() { 079 080 if (this.sourceTransactionSecurities.size() > 0) { 081 this.sourceTransactionSecurity = (EndowmentSourceTransactionSecurity) this.sourceTransactionSecurities.get(0); 082 } 083 // functionality specific to the EndowmentUnitShareAdjustmentDocument. The document will have a source or target security 084 // detail depending on whether the user has entered source or target transaction lines (Decrease or Increase). The UI 085 // display a source security detail by default so this code will return the target security saved to be displayed on the 086 // source security on the UI. 087 else if (this.targetTransactionSecurities.size() > 0) { 088 this.sourceTransactionSecurity.setSecurityID(this.targetTransactionSecurities.get(0).getSecurityID()); 089 090 this.sourceTransactionSecurity.setRegistrationCode(this.targetTransactionSecurities.get(0).getRegistrationCode()); 091 } 092 return this.sourceTransactionSecurity; 093 094 } 095 096 }