/* DEC *DepreciateStraightLine(depr, remval, book, salv, life, partial, time) * * ARGUMENT * DEC *depr, *remval, *book, *salv, *partial; * int time, life; * * DESCRIPTION * Calculate a particular year's depreciation and remaining depreciable * value according to straight line depreciation. The item has book value * book, salvage value salv, and lifetime life (which may include a partial * period). At year# time, the depreciation and remaining value are * computed and stored in depr and remval. The first year is always the * partial year. * * SIDE EFFECTS * depr and remval are changed. * * RETURNS * depr if successful, otherwise GM_NULL. * * POSSIBLE ERRORS * GM_NULLPOINTER * GM_ARGVAL * * AUTHOR * Jared Levy * Copyright (C) 1988-1990 Greenleaf Software Inc. All rights reserved. * * MODIFICATIONS * * */ #include #include "gm.h" #include "gmsystem.h" DEC *DepreciateStraightLine(depr, remval, book, salv, life, partial, time) DEC *depr, *remval, *book, *salv, *partial; int time, life; { int i, plife; DEC dtotlif, *totlif=&dtotlif; DEC dydep, *ydep=&dydep; _MacStart(GM_DPSL); if (!depr||!remval||!book||!salv||!partial) { _MacErr(GM_NULLPOINTER); _MacRet(GM_NULL); } if (_MacBad(book)||_MacBad(salv)||_MacBad(partial)) { _MacErr(GM_INIT); _MacRet(GM_NULL); } plife = life + (_MacIsDecZ(partial)?0:1); /* check time>=0, life>=1, time<=life, 0<=partial<=1 */ if (time<0||life<1||_MacIsDecN(book)||_MacIsDecN(salv)||time>plife ||_MacIsDecN(partial)||CompareDecimal(partial,&decOne)==1) { _MacDZero(depr); _MacDZero(remval); _MacErr(GM_ARGVAL); _MacRet(GM_NULL); } /* calculate yearly depreciation */ (void) _SubDec80Bit(remval,book,salv); (void) _ScaleDec80Bit(remval, remval, 2); (void) ConvLongToDecimal(totlif, (long) life); (void) _DivRndDec80Bit(ydep, remval, totlif, 2); _MacDZero(depr); if (time==0) _MacRet(depr); /* handle partial first year */ if (_MacIsDecZ(partial)) { i=0; } else { (void) _MulDec80Bit(depr,ydep,partial); (void) _ScaleDec80Bit(depr,depr,2); (void) _SubDec80Bit(remval, remval, depr); i=1; } /* handle remaining years */ if (time>i) _MacDCopy(depr, ydep); while (i