/* DEC *DepreciateDeclining(depr, remval, book, salv,dbf,life,partial,time); * * ARGUMENT * DEC *depr, *remval, *book, *salv, *dbf, *partial; * int life, time; * * DESCRIPTION * Calculate a specific year's depreciation and remaining depreciable * value according to declining balance depreciation. * With a declining balance factor of dbf, 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 *DepreciateDeclining(depr, remval, book, salv,dbf,life, partial, time) DEC *depr, *remval, *book, *salv, *dbf, *partial; int life, time; { int i, plife; DEC drbv, *rbv=&drbv, dfol, *fol=&dfol; DEC dtemp, *temp=&dtemp, dnsalv, *nsalv=&dnsalv; _MacStart(GM_DPDB); if (!depr||!remval||!book||!salv||!partial||!dbf) { _MacErr(GM_NULLPOINTER); _MacRet(GM_NULL); } if (_MacBad(salv)||_MacBad(partial)||_MacBad(dbf)) { _MacErr(GM_INIT); _MacRet(GM_NULL); } plife=life+(_MacIsDecZ(partial)?0:1); if (time<0||life<1||_MacIsDecN(book)||_MacIsDecN(salv)||time>plife ||_MacIsDecN(dbf) ||_MacIsDecN(partial)||CompareDecimal(partial,&decOne)==1) { _MacDZero(depr); _MacDZero(remval); _MacErr(GM_ARGVAL); _MacRet(GM_NULL); } (void) _ScaleDec80Bit(rbv, book, 2); (void) _ScaleDec80Bit(nsalv, salv, 2); (void) _SubDec80Bit(remval, rbv, nsalv); if (time==0) { _MacDZero(depr); _MacRet(depr); } (void) ConvLongToDecimal(temp, (long) life * 100L); (void) _DivDec80Bit(fol, dbf, temp); /* handle partial first year */ if (_MacIsDecZ(partial)) { i=0; } else { (void) _MulDec80Bit(temp,rbv,fol); (void) _MulDec80Bit(depr, temp, partial); (void) _ScaleDec80Bit(depr,depr,2); (void) _SubDec80Bit(remval, remval, depr); /* remaining value can't be negative */ if (_MacIsDecN(remval)) { (void) _AddDec80Bit(depr, depr, remval); _MacDZero(remval); } (void) _SubDec80Bit(rbv, rbv, depr); i=1; } /* handle remaining years */ while (i