/* DEC **DepreciateDecliningTable(depr, remval, book, salv,dbf,life,partial); * * ARGUMENT * DEC **depr, **remval, *book, *salv, *dbf, *partial; * int life; * * DESCRIPTION * Calculate several years' 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# i, the depreciation and remaining value are * computed and stored in depr[i] and remval[i]. The first year is always * the partial year. The results are calculated for the entire lifetime. * * SIDE EFFECTS * depr and remval are changed. * * RETURNS * depr if successful, otherwise GM_NULLARR. * * 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 **DepreciateDecliningTable(depr, remval, book, salv,dbf,life, partial) DEC **depr, **remval, *book, *salv, *dbf, *partial; int life; { int i, plife; DEC drbv, *rbv=&drbv, dfol, *fol=&dfol; DEC dtemp, *temp=&dtemp, dnsalv, *nsalv=&dnsalv; _MacStart(GM_DPDBTBL); if (!depr||!remval||!book||!salv||!partial||!dbf) { _MacErr(GM_NULLPOINTER); _MacRet(GM_NULLARR); } if (_MacBad(salv)||_MacBad(partial)||_MacBad(dbf)) { _MacErr(GM_INIT); _MacRet(GM_NULLARR); } plife=life+(_MacIsDecZ(partial)?0:1); for (i=0;i<=plife;i++) if(!depr[i]||!remval[i]) { _MacErr(GM_NULLPOINTER); _MacRet(GM_NULLARR); } /* check life>=1, 0<=partial<=1 */ if (life<1||_MacIsDecN(partial)||CompareDecimal(partial,&decOne)==1 ||_MacIsDecN(dbf) ||_MacIsDecN(book)||_MacIsDecN(salv)) { _MacErr(GM_ARGVAL); _MacRet(GM_NULLARR); } (void) _ScaleDec80Bit(rbv, book, 2); (void) _ScaleDec80Bit(nsalv, salv, 2); (void) _SubDec80Bit(remval[0],rbv,nsalv); _MacDZero(depr[0]); (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[1], temp, partial); (void) _ScaleDec80Bit(depr[1],depr[1],2); (void) _SubDec80Bit(remval[1], remval[0], depr[1]); /* remaining value can't be negative */ if (_MacIsDecN(remval[1])) { (void) _AddDec80Bit(depr[1], depr[1], remval[1]); _MacDZero(remval[1]); } (void) _SubDec80Bit(rbv,rbv,depr[1]); i=1; } /* handle remaining years */ while (i