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 java.util.ArrayList;
019 import java.util.List;
020
021 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionLine;
022 import org.kuali.kfs.module.endow.businessobject.EndowmentTransactionTaxLotLine;
023 import org.kuali.rice.kew.exception.WorkflowException;
024
025
026 public abstract class EndowmentTaxLotLinesDocumentBase extends EndowmentSecurityDetailsDocumentBase implements EndowmentTaxLotLinesDocument {
027
028 /**
029 * @see org.kuali.kfs.module.endow.document.EndowmentTaxLotLinesDocument#getTaxLotLinesNumber()
030 */
031 public int getTaxLotLinesNumber() {
032 int taxLotLinesNbr = 0;
033
034 for (int i = 0; i < getTargetTransactionLines().size(); i++) {
035 EndowmentTransactionLine transactionLine = (EndowmentTransactionLine) getTargetTransactionLines().get(i);
036 taxLotLinesNbr += transactionLine.getTaxLotLines().size();
037 }
038
039 for (int i = 0; i < getSourceTransactionLines().size(); i++) {
040 EndowmentTransactionLine transactionLine = (EndowmentTransactionLine) getSourceTransactionLines().get(i);
041 taxLotLinesNbr += transactionLine.getTaxLotLines().size();
042 }
043
044 return taxLotLinesNbr;
045 }
046
047
048 /**
049 * @see org.kuali.kfs.sys.document.Correctable#toErrorCorrection()
050 */
051 @Override
052 public void toErrorCorrection() throws WorkflowException, IllegalStateException {
053 super.toErrorCorrection();
054
055 // Negate the Taxlot lines Amount, Units, Short term gain & long term gain values.
056 List<EndowmentTransactionLine> lines = new ArrayList<EndowmentTransactionLine>();
057 lines.addAll(sourceTransactionLines);
058 lines.addAll(targetTransactionLines);
059
060 for (EndowmentTransactionLine line : lines) {
061 for (EndowmentTransactionTaxLotLine taxLotLine : line.getTaxLotLines()) {
062 taxLotLine.setLotHoldingCost(taxLotLine.getLotHoldingCost().negate());
063 taxLotLine.setLotUnits(taxLotLine.getLotUnits().negate());
064 if (null != taxLotLine.getLotLongTermGainLoss() && 0 != taxLotLine.getLotLongTermGainLoss().intValue())
065 taxLotLine.setLotLongTermGainLoss(taxLotLine.getLotLongTermGainLoss().negate());
066 if (null != taxLotLine.getLotShortTermGainLoss() && 0 != taxLotLine.getLotShortTermGainLoss().intValue())
067 taxLotLine.setLotShortTermGainLoss(taxLotLine.getLotShortTermGainLoss().negate());
068 }
069 }
070 }
071
072 /**
073 * @see org.kuali.kfs.module.endow.document.EndowmentTransactionLinesDocumentBase#buildListOfDeletionAwareLists()
074 */
075 @Override
076 public List buildListOfDeletionAwareLists() {
077 List managedList = super.buildListOfDeletionAwareLists();
078
079 for (EndowmentTransactionLine endowmentTransactionLine : getTargetTransactionLines()) {
080 managedList.add(endowmentTransactionLine.getTaxLotLines());
081 }
082
083 for (EndowmentTransactionLine endowmentTransactionLine : getSourceTransactionLines()) {
084 managedList.add(endowmentTransactionLine.getTaxLotLines());
085 }
086
087 return managedList;
088 }
089
090 }