accounting software, Equipment Depreciation Software"> Goldenseal Accounting Software-- Depreciation Viewer
Accounting Software
Small Business Software Estimating Software
Construction Estimating SoftwareBookkeeping SoftwareInventory SoftwareInventory Control SoftwareInventory Tracking SoftwareInventory Management SoftwareBusiness Management Software

Depreciation Viewer (Source Code)

Link to: header | record viewer directory

Copyright Turtle Creek Software 1996-2006. All Rights Reserved.

Comments

CDepreciationViewer

This class manages depreciation viewers for the Goldenseal accounting software,
small business management software, construction project management software and
construction estimating software.

a viewer for the depreciation list. This class sets up the data entry
window for equipment depreciation and real estate depreciation.

SUPERCLASS = DB_RecordViewer

Constructor

/*********************************************************************************
constructor
*********************************************************************************/
CDepreciationViewer::CDepreciationViewer(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: DB_RecordViewer(inPaneInfo, inViewInfo)
{
mLastDivisor = 1; //BD 4/19/00
mYrsRemain = 0;
mFinal = 0;
}

Source Code

/*********************************************************************************

FinishUpdatingFields split TCS 4/17/00

Finish prep work after updating fields from an object, but before displaying them

*********************************************************************************/
void CDepreciationViewer::FinishUpdatingFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
// the superclass handles basic field updating
THE_SUPERCLASS::FinishUpdatingFields(creationMethod, viewerObject);

// check table editability
SInt32 calcType = GetFieldValue(tag_calcmethod);
SetLifetimeEnable(calcType);
SetTablePanes(calcType);
}
/*********************************************************************************

HandlePopupChanged

a popup menu has been clicked, act accordingly

*********************************************************************************/
void CDepreciationViewer::HandlePopupChanged(CTCS_StdPopupMenu *popupMenu)
{
TCS_FailNILMsg(popupMenu, TCS_GetErrString(errID_BadPopup));
switch (popupMenu->GetPaneID())
{
case tag_calcmethod:
SetLifetimeEnable(popupMenu->GetValue());
SetTablePanes(popupMenu->GetValue());
FillInTablePanes();
break;

case tag_firstlast:
FillInTablePanes();
break;

default:
break;
}
// be sure to pass it along
THE_SUPERCLASS::HandlePopupChanged(popupMenu);
}/*********************************************************************************

HandleEditChanged

an editfield has changed, act accordingly

*********************************************************************************/
void CDepreciationViewer::HandleEditChanged(CTCS_EditField *editField)
{
TCS_FailNILMsg(editField, TCS_GetErrString(errID_BadField));
switch (editField->GetPaneID())
{
case tag_lifetime:
{ // better bounds check
CMoney value = GetFieldMoneyValue(tag_lifetime);
if (value > 100)
SetFieldMoneyValue(tag_lifetime, 100); //BD 3/26/00
else if (value < 1)
SetFieldMoneyValue(tag_lifetime, 1);


// need to fill in depreciation values
FillInTablePanes();
}
break;

default:
break;
}
// be sure to pass it along to the superclass
THE_SUPERCLASS::HandleEditChanged(editField);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

SetTablePanes

set the editability of table panes, based on depreciation calc type

*********************************************************************************/
void CDepreciationViewer::SetTablePanes(const SInt32 calcType)
{
CMemberTable *table =
TCS_SAFE_CAST(FindPaneByID(tag_deptable), CMemberTable);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));

if (calcType == calc_custom) // rev TCS 3/31/99
table->SetColType(CDepreciation::col_percent, coltype_edit, true);
else
table->SetColType(CDepreciation::col_percent, coltype_caption, true);
}
/*********************************************************************************

SetLifetimeEnable

set the enablement of the lifetime field, based on the calculation type

*********************************************************************************/
void CDepreciationViewer::SetLifetimeEnable(const SInt32 calcType)
{
if (calcType == calc_capitalize || calcType == calc_expense ||
calcType == calc_notowned)
{
SetFieldCString(tag_lifetime, cOneString);
SetFieldEnabled(tag_lifetime, false);
}
else
SetFieldEnabled(tag_lifetime, true);
}
/*********************************************************************************

FillInTablePanes major revs TCS 3/31/99

fill in a set of values for depreciation years

*********************************************************************************/
void CDepreciationViewer::FillInTablePanes()
{
// get the table
CMemberTable *table =
TCS_SAFE_CAST(FindPaneByID(tag_deptable), CMemberTable);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));

// get the calculation method
CTCS_StdPopupMenu *calcPopup =
TCS_SAFE_CAST(FindPaneByID(tag_calcmethod), CTCS_StdPopupMenu);
TCS_FailNILMsg(calcPopup, TCS_GetErrString(errID_BadPopup));
UInt8 calcMethod = calcPopup->GetValue();

// get the handling of first year/ last year
CTCS_StdPopupMenu *firstLastPopup =
TCS_SAFE_CAST(FindPaneByID(tag_firstlast), CTCS_StdPopupMenu);
TCS_FailNILMsg(firstLastPopup, TCS_GetErrString(errID_BadPopup));
UInt8 firstLast = firstLastPopup->GetValue();

// get the entered lifetime
CTCS_EditField *lifetimeField =
TCS_SAFE_CAST(FindMemberField(tag_lifetime), CTCS_EditField);
TCS_FailNILMsg(lifetimeField, TCS_GetErrString(errID_BadField));
CMoney lifetime = GetFieldMoneyValue(tag_lifetime);

// get the entered Put in Service Date BD 3/28/00
CTCS_EditField *putInServiceField =
TCS_SAFE_CAST(FindMemberField(tag_putinservice), CTCS_EditField);
TCS_FailNILMsg(putInServiceField, TCS_GetErrString(errID_BadField));
CDate putInService = GetFieldDateValue(tag_putinservice);

CMoney percent, cumPercent, intLifetime = lifetime;
intLifetime.RoundDollarsDown(0); //gets integer value of lifetime
mYrsRemain = lifetime;
mLastDivisor = 1;
UInt8 startMonth = putInService.GetMonth();


// set the number of table rows
SInt32 numRows;
if ((firstLast == time_year && intLifetime == lifetime) || calcMethod == calc_custom ||
calcMethod == calc_expense || calcMethod == calc_capitalize || calcMethod == calc_notowned ||
calcMethod == calc_acrs || calcMethod == calc_sumofdigits)
{
numRows = lifetime.GetDollars();
}
//if lifetime is x.5 and convention is other than year or half year
//and putInService is after June 30, depreciation will be taken for 2 yrs past lifetime
else if (intLifetime != lifetime && (firstLast != time_year && firstLast != time_halfyear)
&& startMonth >= 7) //BD 4/11/00
{
numRows = lifetime.GetDollars() + 2;
}
else
{
numRows = lifetime.GetDollars() + 1;
}
table->SetNumRows(numRows);

// fill in table data
for (TableIndexT row = 1; row <= numRows; row++)
{
table->SetCellValue(row, CDepreciation::col_year, row);
if (calcMethod != calc_custom)
{
percent = GetDepreciationAmount(row, calcMethod, firstLast, lifetime, putInService).RoundPennies(3);
table->SetCellText(row, CDepreciation::col_percent, percent.GetPercentString(3));

percent.SetFromPercentDecimal(mLastDivisor);
cumPercent = 100 - percent.GetReal();
table->SetCellText(row, CDepreciation::col_cumpercent, cumPercent.GetPercentString(3));
}
}
table->Refresh();
}/*********************************************************************************

GetDepreciationAmount TCS 3/31/99

calculate depreciation value for the given year

*********************************************************************************/
CMoney CDepreciationViewer::GetDepreciationAmount(const SInt32 year, const UInt8 calcMethod,
const UInt8 firstLast, const CMoney &lifetime, const CDate putInService)
{
CMoney result = 0;
TCS_ASSERTMsg(lifetime > 0, TCS_GetErrString(errID_BadValue));

// set up the table, based on what's been entered so far
switch (calcMethod)
{
case calc_acrs: //ACRS method, based on declining balance method
result = Acrs(year, firstLast, lifetime, putInService);
break;

case calc_macrs: //200% MACRS declining balance method
case calc_macrs150: //150% MACRS declining balance method
case calc_declining: //150% declining balance
case calc_dbldeclining: //200% double declining balance
result = GetAcceleratedPercent(year, calcMethod, firstLast, lifetime, putInService);
break;

case calc_capitalize:
case calc_notowned: // TCS 7/26/00
result = 0;
break;

case calc_expense:
result = 100;
mLastDivisor = 0;
break;

case calc_straight:
result = StraightLine(year, firstLast, lifetime, putInService);
break;

case calc_sumofdigits:
result = SumOfDigits(year, firstLast, lifetime, putInService);
break;

default:
TCS_DebugAlert("Oops, invalid depreciation type!");
break;
}

return result;
}
/*********************************************************************************

StraightLine BD 3/17/00

fill in table values for straight line depreciation

*********************************************************************************/
CMoney CDepreciationViewer::StraightLine(const SInt32 year, const UInt8 firstLast,
const CMoney &lifetime, const CDate putInService)
{
CMoney result = 0, intLifetime = lifetime;
intLifetime.RoundDollarsDown(0).GetReal();
TCS_Real lifetimeValue = lifetime.GetReal();
TCS_Real divisor = 1 / lifetimeValue; //this is the base SL divisor for each year
mFinal = intLifetime + 1;

//apply the appropriate convention in year 1
if (year == 1)
divisor *= GetFirstFactor(firstLast, lifetime, putInService);

//mLastDivisor is remaining undepreciated percent
if (year == mFinal.GetDollars())
divisor = mLastDivisor.GetReal();

mLastDivisor -= divisor;
result.SetFromPercentDecimal(divisor);
return result;
}
/*********************************************************************************

SumOfDigits BD 4/12/00

fill in table values for Sum of Digits depreciation

*********************************************************************************/
CMoney CDepreciationViewer::SumOfDigits(const SInt32 year, const UInt8 firstLast,
const CMoney &lifetime, const CDate putInService)
{
TCS_Real divisor, factor;
SInt32 sumOfDigits, yearNumerator;
UInt8 startMonth;
CDate inServCopy = putInService;
CMoney result = 0, temp = lifetime;
TCS_Real intLifetime = temp.RoundDollarsDown(0).GetReal(); //gets integer value of lifetime
mFinal = intLifetime;
//calc the appropriate divisor, based on lifetime and current year. The
//denominator is 1 + 2 + 3 + ... + lifetime; we calculate this by the Gaussian
//method(see Principles of Accounting p. 359)
sumOfDigits = intLifetime/2 *(intLifetime + 1);
yearNumerator = intLifetime - (year - 1);
divisor = (TCS_Real) yearNumerator/sumOfDigits;

//apply the appropriate year 1 convention
switch (firstLast)
{
case time_year:
mLastDivisor -= divisor;
result.SetFromPercentDecimal(divisor);
return result;

case time_halfyear:
startMonth = 7;
break;

case time_quarter: //this is actually 1st of quarter, not mid-quarter; add this as an option
inServCopy.SetToFirstOfQuarter();
startMonth = inServCopy.GetMonth();
break;

case time_month:
startMonth = GetMonthInService(putInService);
break;

case time_halfmonth:
startMonth = putInService.GetMonth();
break;

case time_day:
break;

default:
TCS_DebugAlert("Oops, bad case in CDepreciationViewer::SumOfDigits");
break;
}

//get actual first year factor based on startMonth, if not already calculated
if (firstLast == time_day)
factor = GetDayDivisor(putInService);
else if (firstLast == time_halfmonth)
factor = 1 - (startMonth - 0.5)/12;
else
factor = (TCS_Real)(13 - startMonth)/12;

//calculate appropriate divisor based on the year
if (year == 1)
divisor *= factor;
else if (year == mFinal.GetDollars())
divisor = mLastDivisor.GetReal();
else
divisor = (yearNumerator + 1 - factor) / sumOfDigits;

mLastDivisor -= divisor;
result.SetFromPercentDecimal(divisor);
result.RoundPennies(2);
return result;
}
/*********************************************************************************

Acrs BD 4/19/00

Returns divisor for ACRS depreciation system

*********************************************************************************/
CMoney CDepreciationViewer::Acrs(const SInt32 year, const UInt8 firstLast,
const CMoney &lifetime, const CDate putInService)
{
CMoney result = 0;
//Acrs for tax purposes has only 4 official lifetime recovery periods(3, 5, 10 & 18 yrs).
//GetAcceleratedPercent calcs 2 of them, but 5 & 18-year classes are irregular, so we just
//display them as follows:
if (firstLast == time_halfyear)
{ if (lifetime == 5)
{
if (year == 1)
result = 15;
if (year == 2)
result = 22;
if (year >= 3 && year <= 5)
result = 21;
mLastDivisor -= result.GetPercentDecimal();
}

else if (lifetime == 18)
{
if (year == 1)
result = 4;
if (year == 2)
result = 8;
if (year == 3 || year == 4)
result = 7;
if (year >= 5 && year <= 8)
result = 6;
if (year >= 9 && year <= 18)
result = 5;
mLastDivisor -= result.GetPercentDecimal();
}

else
result = GetAcceleratedPercent(year, calc_acrs, firstLast, lifetime, putInService);
}
else
result = GetAcceleratedPercent(year, calc_acrs, firstLast, lifetime, putInService);

return result;
}
/*********************************************************************************

GetAcceleratedPercent BD 4/13/00, modified 4/17

Returns the appropriate divisor for the year and appropriate convention

*********************************************************************************/
CMoney CDepreciationViewer::GetAcceleratedPercent(const SInt32 year, const UInt8 calcMethod,
const UInt8 firstLast, const CMoney &lifetime, const CDate putInService)

{ TCS_Real firstFactor, mult, lifetimeValue = lifetime.GetReal();
CMoney divisor;
CMoney result = 0, intLifetime = lifetime;
intLifetime.RoundDollarsDown(0).GetReal(); //we need lifetime as an integer for many calcs


//assign appropriate multiplier value for the calcMethod. This will be
//either 1.5 or 2 times what the SL multiplier would be(1/lifetime)
switch (calcMethod)
{
case calc_dbldeclining:
case calc_macrs:
mult = 2/lifetimeValue;
break;

case calc_declining:
case calc_macrs150:
mult = 1.5/lifetimeValue;
break;

case calc_acrs:
mult = 1.5/lifetimeValue;
mFinal = intLifetime;
break;

default:
TCS_DebugAlert("Oops, bad case in CDepreciationViewer::GetAcceleratedPercent");
break;
}

//firstFactor adjusts depreciation % for year 1 according to what
//fraction of the year the property is in service
if (year == 1)
{
mFinal = intLifetime + 1;
firstFactor = GetFirstFactor(firstLast, lifetime, putInService);
divisor = mult * firstFactor;

//adjust how many years remain of the lifetime
if (calcMethod == calc_acrs) //Acrs doesn't use any fractional years;
mYrsRemain -= 1;
else
mYrsRemain -= firstFactor; //but other methods want to know exactly
}

//get divisor for years 2 through mFinal. Macrs and Acrs methods switch
//to SL when SL offers greater depreciation; we check for when to make
//the switch using CompareSLDB.
if (year >= 2 && year < mFinal.GetDollars())
{ if (calcMethod == calc_macrs || calcMethod == calc_macrs150 || calcMethod == calc_acrs)
divisor = CompareSLDB(CMoney(mLastDivisor * mult));
else
divisor = mLastDivisor * mult;

mYrsRemain -= 1;
}
if (year == mFinal.GetDollars())
{ if (calcMethod == calc_dbldeclining || calcMethod == calc_declining)
divisor = mLastDivisor * mult; //these methods don't go all the way to 100% depreciation
else
divisor = mLastDivisor;
}

//set divisor to percent; update mLastDivisor
result.SetFromPercentDecimal(divisor);
if (calcMethod == calc_acrs)
{ result.RoundDollarsUp(0); //Acrs does weird rounding stuff
mLastDivisor -= result.GetPercentDecimal();
}
else
mLastDivisor -= divisor;

return result;
}
/*********************************************************************************

GetFirstFactor BD 4/20/00

Get fraction of year property is in service, depending on the convention

*********************************************************************************/
TCS_Real CDepreciationViewer::GetFirstFactor(const UInt8 firstLast,
const CMoney &lifetime, const CDate putInService)
{
CMoney intLifetime = lifetime;
intLifetime.RoundDollarsDown(0);
UInt8 startMonth = putInService.GetMonth();
TCS_Real factor;
switch (firstLast)
{
case time_year:
factor = 1;
if (intLifetime == lifetime) //checks if lifetime is a whole year or a .5
mFinal = intLifetime;
break;

case time_halfyear:
factor = 0.5;
break;

case time_quarter:
if (intLifetime != lifetime && startMonth >= 7)
mFinal = intLifetime + 2;
factor = GetQuarterDivisor(putInService);
break;

case time_halfmonth:
if (intLifetime != lifetime && startMonth >= 7)
mFinal = intLifetime + 2;
factor = 1 - (startMonth - 0.5)/12;
break;

case time_month:
startMonth = GetMonthInService(putInService);
if (intLifetime != lifetime && startMonth >= 7)
mFinal = intLifetime + 2;
factor = (TCS_Real)(13 - startMonth)/12;
break;

case time_day:
factor = GetDayDivisor(putInService);
if (intLifetime != lifetime && factor < 0.5)
mFinal = intLifetime + 2;
break;

default:
break;
}
return factor;
}
/*********************************************************************************

GetQuarterDivisor BD 4/19/00

Returns the multiplication factor for the appropriate tax quarter placed in service.
The value is for the mid-quarter convention under the MACRS depreciation system.

*********************************************************************************/
TCS_Real CDepreciationViewer::GetQuarterDivisor(const CDate putInService)
{
UInt8 startMonth = putInService.GetMonth();

if (startMonth >= 1 && startMonth <= 3)
return 0.875;
if (startMonth >= 4 && startMonth <= 6)
return 0.625;
if (startMonth >= 7 && startMonth <= 9)
return 0.375;
if (startMonth >= 10 && startMonth <= 12)
return 0.125;
else
return 1;
}
/*********************************************************************************

GetDayDivisor BD 4/17/00

Returns the multiplication factor for the first year placed in service, based on
the date.

*********************************************************************************/
TCS_Real CDepreciationViewer::GetDayDivisor(const CDate putInService)
{
CDate temp = putInService;
UInt16 yearDays;

//calc # of days in year 1 that property will be in service
temp.SetToLastOfYear();
UInt16 daysInFirstYear = temp.GetTotalDays() - putInService.GetTotalDays() + 1;
if (IS_LEAP_YEAR(temp.GetYear()))
yearDays = 366;
else
yearDays = 365;

TCS_Real firstFactor = (TCS_Real) daysInFirstYear/yearDays;
return firstFactor;
}
/*********************************************************************************

CompareSLDB BD 4/11/00

Compare depreciation amounts for SL and DB method, return greater(for MACRS).

*********************************************************************************/
TCS_Real CDepreciationViewer::CompareSLDB(const CMoney &divisor)

{
CMoney slPercent, dbPercent;
if (mYrsRemain.IsNonZero()) // TCS bugfix 5/10/01
slPercent = (mLastDivisor/mYrsRemain);
else
slPercent = 0;

dbPercent = divisor;
if (dbPercent > slPercent)
return dbPercent.GetReal();
else
return slPercent.GetReal();
}
/*********************************************************************************

GetMonthInService BD 4/12/00

Returns the first of the month in service, given a start date

*********************************************************************************/
UInt8 CDepreciationViewer::GetMonthInService(const CDate putInService)
{ UInt16 monthDays, startDay;
CDate temp = putInService;
monthDays = temp.DaysInMonth();
startDay = temp.GetMonth();

if ((startDay/monthDays) > .5)
temp.SetToNextFirstOfMonth();
else
temp.SetToFirstOfMonth();
return temp.GetMonth();
}