From: Hirzel P. <ph...@us...> - 2007-06-13 20:21:38
|
Update of /cvsroot/tcotool/TCO-Tool/plugins/ch.softenvironment.tcotool.finance/source/ch/softenvironment/tcotool/finance In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30360/plugins/ch.softenvironment.tcotool.finance/source/ch/softenvironment/tcotool/finance Added Files: FinancialCalculator.java ReportDepreciation.java ReportPlugin.java Log Message: Release V1.4.4 --- NEW FILE: FinancialCalculator.java --- package ch.softenvironment.tcotool.finance; /* * Copyright (C) 2004-2006 Peter Hirzel softEnvironment (http://www.softenvironment.ch). * All rights reserved. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import java.util.ArrayList; import java.util.List; import org.tcotool.model.*; import org.tcotool.tools.Calculator; import org.tcotool.tools.ModelUtility; import ch.softenvironment.math.FinancialUtils; /** * Calculate Costs of TCO-Configuration by storing Depreciation-costs for each * Service individually. * * @author Peter Hirzel <i>soft</i>Environment * @version $Revision: 1.1 $ $Date: 2007/06/13 20:21:38 $ */ public class FinancialCalculator extends Calculator { // kind of costs public static final String DEPRECIATION_LINEAR = "DEPR_LIN_"; public static final String DEPRECIATION_GEOMETRIC_DEGRESSIVE = "DEPR_DEGR"; /** * @see #Calculator(ModelUtility, TcoObject, long, ServiceCategory, Responsibility) */ public FinancialCalculator(ModelUtility utility, TcoObject rootObject, long maxDurationMonths) { super(utility, rootObject, maxDurationMonths); } /** * Cummulate the Depreciation-Costs for given cost. * Consider FactCost's with a depreciationDuration > 1 year * * Overwrites. */ protected void calcFinances(Service service, CostDriver driver, Cost cost, double factor) { if (cost instanceof FactCost) { FactCost fCost = (FactCost)cost; if ((fCost.getDepreciationDuration() != null) && (fCost.getDepreciationDuration().longValue() > 12.0)) { // [0] total FactCost independent of depreciation double capital = fCost.getAmount().doubleValue() * factor; cummulateCodes(service, driver, cost, DEPRECIATION_LINEAR, INDEX_TOTAL, capital); cummulateCodes(service, driver, cost, DEPRECIATION_GEOMETRIC_DEGRESSIVE, INDEX_TOTAL, capital); // [1..fCost.depreciationYears] of first period of FactCost's depreciationDuration int year = calcDepreciation(service, driver, fCost, capital, INDEX_TOTAL); // [after fCost.depreciationYears years] repeatable periods if ((cost.getRepeatable() != null) && cost.getRepeatable().booleanValue() && (year < getDurationYears())) { // repeat the costs until maxDuration while (year < getDurationYears()) { //TODO Check: problably degressive depreciation costs from duration before are not calculated further on, which would go infinitely down to 0 year = calcDepreciation(service, driver, fCost, capital, year); } } } } } /** * Calc the <b>linear depreciation</b> over the whole FactCost-DepreciationDuration. * Algorithm: * - Linear Depreciation * @param costCapital * @param costDuration * @return year of last Cost-entry */ private int calcDepreciation(Service service, CostDriver driver, FactCost cost, double costCapital, int yearIndex) { int duration = cost.getDepreciationDuration().intValue(); int completeYears = duration / 12; if (duration % 12 > 0) { // consider a partial duration after last complete year as one more year completeYears++; } int year = 0; for (; year<completeYears; year++) { int period = year + 1; double amount /*[de] Buchwert*/ = FinancialUtils.calcDepreciationLinear(costCapital, completeYears, period); // depreciation over full year cummulateCodes(service, driver, cost, DEPRECIATION_LINEAR, yearIndex + period, amount); amount /*[de] Buchwert*/ = FinancialUtils.calcDepreciationGeometricDegressive(costCapital, utility.getInterestRate(), period); // depreciation over full year cummulateCodes(service, driver, cost, DEPRECIATION_GEOMETRIC_DEGRESSIVE, yearIndex + period, amount); } return year + yearIndex; } /** * Return cost-list over given object. * @param object null for all services * @return [FactCosts_Total; Depreciation_Year1;.. TCO_YearN] */ public List getDepreciationCostBlock(TcoObject object, final String type) { //TODO make method protected (@see DepreciationCalculatorTestCase) TcoObject costObject = (object == null ? rootObject : object); List costs = new ArrayList(); List totalFacts = getTotalCosts(costObject, type); costs.add(new Double(FinancialCalculator.getValue(totalFacts, FinancialCalculator.INDEX_TOTAL))); for (int i=0; i<getDurationYears(); i++) { // print Depreciation-Years int index = i + INDEX_TOTAL + 1; costs.add(new Double(FinancialCalculator.getValue(totalFacts, index))); } return costs; } } --- NEW FILE: ReportPlugin.java --- package ch.softenvironment.tcotool.finance; /* * Copyright (C) 2006 Peter Hirzel softEnvironment (http://www.softenvironment.ch). * All rights reserved. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import javax.swing.JComponent; import javax.swing.JMenuItem; import org.java.plugin.Plugin; import org.tcotool.application.LauncherView; import org.tcotool.core.runtime.ApplicationPlugin; import org.tcotool.model.TcoObject; import org.tcotool.model.TcoPackage; import org.tcotool.pluginsupport.PluginUtility; import org.tcotool.standard.report.ReportTool; /** * Free <i>soft</i>Environment Plugins (might serve as sample). * PLUGIN_ID = "ch.softenvironment.tcotool.finance"; * @author Peter Hirzel <i>soft</i>Environment * @version $Revision: 1.1 $ $Date: 2007/06/13 20:21:38 $ */ public final class ReportPlugin extends Plugin implements org.tcotool.pluginsupport.Menu { protected static final String REPORT_HEADER = "ReportHeader.png"; /** * Constructor. */ public ReportPlugin() { super(); } /** * @see org.java.plugin.Plugin#doStart() */ protected void doStart() throws Exception { } /** * @see org.java.plugin.Plugin#doStop() */ protected void doStop() throws Exception { } /** * Menu was clicked -> generate the report. * @see org.tcotool.pluginsupport.Menu#init(javax.swing.JComponent) */ public void actionPerform(final JComponent item, final Object object) { ApplicationPlugin.showBusy(new Runnable() { public void run() { try { String actionCommand = ((JMenuItem)item).getActionCommand(); if (actionCommand.equals("depreciation" /*@see plugin.xml=>id*/)) { reportFinancialTotal(getTcoPackage(object)); } } catch(Throwable e) { LauncherView.getInstance().handleException(e); } } }); } /** * Depreciation-Report. */ private void reportFinancialTotal(TcoObject root) throws Throwable { LauncherView.getInstance().addReport(ReportDepreciation.createBlockDepreciation(getTcoPackage(root), ReportTool.getDepreciationDuration(), PluginUtility.getClassLoader(this))); } private TcoPackage getTcoPackage(Object object) { if (object == null) { return (TcoPackage)LauncherView.getInstance().getUtility().getRoot(); } else { return (TcoPackage)object; } } } --- NEW FILE: ReportDepreciation.java --- package ch.softenvironment.tcotool.finance; /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.IOException; import java.util.*; import org.tcotool.model.*; import org.tcotool.standard.report.ReportTool; import org.tcotool.tools.Calculator; import org.tcotool.application.*; import ch.softenvironment.client.ResourceManager; import ch.softenvironment.jomm.DbObjectServer; import ch.softenvironment.jomm.serialize.AttributeList; /** * Utility to report financial depreciation (bookings) * Calculations as Plugin for TCO-Tool. * Design Pattern: Visitor * * @author Peter Hirzel <i>soft</i>Environment * @version $Revision: 1.1 $ $Date: 2007/06/13 20:21:38 $ */ class ReportDepreciation extends ReportTool { private ClassLoader loader = null; protected ReportDepreciation(String title) { super(title); } /** * Summarize all Depreciation-Costs within given object and subpackages. */ public static ReportTool createBlockDepreciation(TcoObject root, long maxDepreciation, ClassLoader loader) throws java.lang.Throwable { ReportDepreciation tool = new ReportDepreciation(ResourceManager.getResource(ReportPlugin.class, "MniReportFinancialTotal_text", loader)); tool.loader = loader; tool.calculator = new FinancialCalculator(LauncherView.getInstance().getUtility(), root, maxDepreciation); tool.totalCost(root); return tool; } /** * Overwrites. */ public void startBody(AttributeList list) throws IOException { super.startBody(list); java.net.URL url = loader.getResource(ReportPlugin.REPORT_HEADER); image(url, "", 0); } /** * Overwrites. */ protected void encodeCodes(DbObjectServer server, TcoObject root) throws Throwable { encodeDepreciation(root, ResourceManager.getResource(ReportPlugin.class, "CTLinearDepreciation", loader), FinancialCalculator.DEPRECIATION_LINEAR); encodeDepreciation(root, ResourceManager.getResource(ReportPlugin.class, "CTDegressiveDepreciation", loader), FinancialCalculator.DEPRECIATION_GEOMETRIC_DEGRESSIVE); } private void encodeDepreciation(TcoObject root, String title, final String type) throws IOException { startParagraph(); List totalCosts = ((FinancialCalculator)calculator).getDepreciationCostBlock(root, type); bold(title); simpleContent(" " + ResourceManager.getResource(ReportPlugin.class, "CQFactCostIncluded", loader) + ":" /*getRsc("CIFactCostOverAll")*/); breakLine(); startTable(1); startTableRow(); tableHeader("0. " + getRsc("CIYear")); for (int year=0; year<calculator.getDurationYears(); year++) { //TODO consider partial year /* String partialYear = ""; if ((calculator.getMaxDurationMonths() - year * 12) < 12) { partialYear = " [" + NlsUtils.formatMessage("<br>" + getRsc("CIPartialYear"), (int)calculator.getMaxDurationMonths() % 12) + "]"; } */ String tmp = (year + 1) + ". " + getRsc("CIYear"); tableHeader(tmp /*+ partialYear*/); } endTableRow(); startTableRow(); for (int i=0; i<totalCosts.size(); i++) { double amount = Calculator.getValue(totalCosts, i); tableDataAmount(amount, true); } endTableRow(); endTable(); String tmp = ""; if (type.equals(FinancialCalculator.DEPRECIATION_GEOMETRIC_DEGRESSIVE)) { tmp = "; " + ResourceManager.getResourceAsNonLabeled(SystemParameterDetailView.class, "LblDepreciationInterestRate_text") + " = " + LauncherView.getInstance().getUtility().getInterestRate() + "%"; } encodeCostUnit(tmp); endParagraph(); } } |