Link to: header | unit cost
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CCalcUtilityAccounts
This class manages calculated utility account quantities in the Goldenseal accounting software,
estimating software, project management software
and construction estimating software.
a list of utility account calculators
SUPERCLASS = CCalculatorList
Constructor
/*********************************************************************************
default constructor
*********************************************************************************/
CCalcUtilityAccounts::CCalcUtilityAccounts()
{
mAccount = account_UndepositedCashSales;
mCalculationType = calc_totalinrange;
mRoundingType = calc_roundpennies;
mTimeRange = date_standard;
mCurrentValue = 0; // TCS 9/26/02
mPadding = mMorePadding = 0;
mExpansionMoney = 0;
mEndSafetyTag = tag_endsafetytag; // TCS 9/8/02
}
Source Code
/*********************************************************************************
CopyFrom
copy the data members from the passed object. This is used to implement
duplicate. source should be an object of the same class as this object
*********************************************************************************/
void CCalcUtilityAccounts::CopyFrom(DB_PersistentObject *source, const UInt8 copyFlags)
{
THE_SUPERCLASS::CopyFrom(source, copyFlags);
CCalcUtilityAccounts *src = TCS_SAFE_CAST(source, CCalcUtilityAccounts);
TCS_FailNILMsg(src, TCS_GetErrString(errID_BadRecord));
TCS_BlockMove(&src->mCurrentValue, &mCurrentValue, cCopyFileLength);
}/*********************************************************************************
GetFileLength
return the file length used by this object
*********************************************************************************/
NeoSize CCalcUtilityAccounts::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
cFileLength;
}/*********************************************************************************
GetMemberValue
return the value of the member with the given tag
*********************************************************************************/
Boolean CCalcUtilityAccounts::GetMemberValue(const NeoTag aTag, const NeoTag aType,
void *aValue) const
{
switch (aTag)
{
case tag_account:
return ConvertObjectIDMember(mAccount, id_UtilityAccount, aValue, aType);
break;
case tag_timerange:
return ConvertEnumMember(mTimeRange, MENU_CalcTimeRanges, aValue, aType);
break;
case tag_rounding:
return ConvertEnumMember(mRoundingType, MENU_RoundingTypes, aValue, aType);
break;
case tag_calculationtype:
return ConvertEnumMember(mCalculationType, MENU_CalcUtilityFields, aValue, aType);
break;
case tag_currentvalue:
return ConvertMember(&mCurrentValue, type_money, aValue, aType);
break;
case tag_isdirty:
return ConvertBitFieldMember(mCalcDirty, aValue, aType);
break;
case tag_layouttag: // TCS 4/30/01
{
CTextString outString =
CCalculatorList::GetCalculatorTagString(id_CalcUtilityAccount, GetDBID());
return ConvertMember(&outString, type_cstring, aValue, aType);
}
break;
default:
return THE_SUPERCLASS::GetMemberValue(aTag, aType, aValue);
break;
}
}/*********************************************************************************
SetMemberValue
set the value of the member with the given tag
*********************************************************************************/
Boolean CCalcUtilityAccounts::SetMemberValue(const NeoTag aTag, const NeoTag aType,
const void *aValue)
{
switch (aTag)
{
case tag_account:
return ConvertMember(aValue, aType, &mAccount, type_objectid);
break;
case tag_timerange:
return ConvertMember(aValue, aType, &mTimeRange, type_enum);
break;
case tag_rounding:
return ConvertMember(aValue, aType, &mRoundingType, type_enum);
break;
case tag_calculationtype:
return ConvertMember(aValue, aType, &mCalculationType, type_enum);
break;
case tag_currentvalue:
return ConvertMember(aValue, aType, &mCurrentValue, type_money);
break;
case tag_layouttag: // calculated, no need to set TCS 4/30/01
return true;
break;
default:
return THE_SUPERCLASS::SetMemberValue(aTag, aType, aValue);
break;
}
}/*********************************************************************************
ReadObject
read the persistent object's data in from a stream
*********************************************************************************/
void CCalcUtilityAccounts::ReadObject(CNeoStream *aStream, const TagType aTag)
{
TCS_FailNILMsg(aStream, TCS_GetErrString(errID_BadStream));
CNeoDebugImport checker(aStream, this, cCheckTooSmall); // TCS 2/24/00
THE_SUPERCLASS::ReadObject(aStream, aTag);
if (!IsIOValid()) // TCS 2/5/02
return;
/// aStream->ReadChunk(&mCurrentValue, cFileLength);
mCurrentValue.ReadFromStream(aStream); // mfs_sa rev 20feb2k3
mAccount = aStream->ReadID();
mCalculationType = aStream->ReadChar();
mRoundingType = aStream->ReadChar();
mTimeRange = aStream->ReadChar();
mPadding = aStream->ReadChar();
*((UInt8*)&mPadding + sizeof(mPadding)) = aStream->ReadBits(2); // --Bitfield
mMorePadding = aStream->ReadChar();
mExpansionMoney.ReadFromStream(aStream);
mEndSafetyTag = aStream->ReadEndSafetyTag(this);
if (!IsValidEndTag(mEndSafetyTag)) // TCS 9/8/02
ReportDamagedObject(GetDBClassID(), GetDBID());
}/*********************************************************************************
WriteObject
write the persistent object's data to a stream
*********************************************************************************/
void CCalcUtilityAccounts::WriteObject(CNeoStream *aStream, const TagType aTag)
{
TCS_FailNILMsg(aStream, TCS_GetErrString(errID_BadStream));
// make sure we have valid data to write TCS 9/8/02
if (!IsValidEndTag(mEndSafetyTag))
{
ReportDamagedObject(GetDBClassID(), GetDBID());
mEndSafetyTag = tag_endsafetytag; // TCS 11/26/02
}
CNeoDebugExport checker(aStream, this, cCheckTooSmall);
THE_SUPERCLASS::WriteObject(aStream, aTag);
/// aStream->WriteChunk(&mCurrentValue, cFileLength);
mCurrentValue.WriteToStream(aStream); // mfs_sa rev 20feb2k3
aStream->WriteID(mAccount);
aStream->WriteChar(mCalculationType);
aStream->WriteChar(mRoundingType);
aStream->WriteChar(mTimeRange);
aStream->WriteChar(mPadding);
aStream->WriteChar(*((UInt8*)&mPadding + sizeof(mPadding))); // --Bitfield
aStream->WriteChar(mMorePadding);
mExpansionMoney.WriteToStream(aStream);
aStream->WriteEndSafetyTag(mEndSafetyTag, this);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
GetDisplayCString TCS 6/14/00
return the calculated text
*********************************************************************************/
CTextString CCalcUtilityAccounts::GetDisplayCString(const FormatType format, const Boolean alwaysUpdate)
{
SInt32 runLimit = 0;
UpdateCalculatorValue(runLimit, format, alwaysUpdate);
return mCurrentValue.GetCurrencyString();
}
/*********************************************************************************
GetCalculatorMoney
return the calculated money value.
*********************************************************************************/
CMoney CCalcUtilityAccounts::GetCalculatorMoney()
{
SInt32 runLimit = 0;
UpdateCalculatorValue(runLimit, CMoney::GetDefaultMoneyFormat());
return mCurrentValue;
}
/*********************************************************************************
GetStarterCString TCS 12/18/00
return a starter value
*********************************************************************************/
CTextString CCalcUtilityAccounts::GetStarterCString(const FormatType format) const
{
CMoney zero = 0;
return zero.GetFormatString(format); // rev TCS 5/7/04
}/*********************************************************************************
UpdateCalculatorValue TCS 1/27/99 rev TCS 4/5/01
calculate a value for the display string.
*********************************************************************************/
void CCalcUtilityAccounts::UpdateCalculatorValue(SInt32 &/*runLimit*/, const FormatType /*format*/,
const Boolean alwaysUpdate)
{
if (mCalcDirty || mDisplayDirty || alwaysUpdate) // rev TCS 4/5/01
{
mCurrentValue = GetCalculation(mAccount, mCalculationType, mRoundingType, mTimeRange);
mCalcDirty = false;
mDisplayDirty = false;
}
}
/*********************************************************************************
GetCalculation (static) TCS rev 6/8/99
the static method that fills in a calculated value for calculator objects
and the calculator viewer.
*********************************************************************************/
CMoney CCalcUtilityAccounts::GetCalculation(const DBid accountID, const UInt8 calcType,
const UInt8 rounding, const UInt8 timeRange)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
#if TCS_MULTIUSER
if (gIsClient)
{
// a client fetches a value from the server TCS 6/7/03
// so we don't need to access a zillion objects
CTCS_NetworkMessage ioMessage(msg_GetUtilityCalculation);
ioMessage.SetLongValue(accountID);
ioMessage.SetFirstByte(calcType);
ioMessage.SetSecondByte(rounding);
ioMessage.SetThirdByte(timeRange);
ioMessage.SetNeedsReply();
if (gApplication->BroadcastNetworkMessage(&ioMessage, cGiveWarning))
{
// fetch the string
return ioMessage.GetMoneyValue();
}
else
return 0;
}
#endif
CMoney amount = 0;
DB_Account *account =
TCS_SAFE_CAST(gDBFile->GetOneObject(id_UtilityAccount, accountID),
DB_Account);
if (account)
{
CDate startDate, endDate;
DB_ObjectWatcher watcher(account);
switch (calcType)
{
case calc_currbalance:
amount = account->GetCurrentBalance();
break;
case calc_startdatebalance:
startDate = CDate::GetRangeStart(timeRange);
amount = account->GetValueAtDate(startDate);
break;
case calc_enddatebalance:
endDate = CDate::GetRangeEnd(timeRange);
amount = account->GetValueAtDate(endDate);
break;
case calc_totalinrange:
startDate = CDate::GetRangeStart(timeRange);
endDate = CDate::GetRangeEnd(timeRange);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_activeinrange:
startDate = CDate::GetRangeStart(timeRange);
endDate = CDate::GetRangeEnd(timeRange);
amount = account->GetActiveInRange(startDate, endDate);
break;
case calc_changeinrange:
startDate = CDate::GetRangeStart(timeRange);
endDate = CDate::GetRangeEnd(timeRange);
amount = account->GetValueChangeInRange(startDate, endDate);
break;
case calc_startday: // total for basic start date TCS 12/19/00
startDate = gDBFile->GetStartDate();
endDate = startDate;
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_startweek: // total for week after start date TCS 12/19/00
startDate = gDBFile->GetStartDate();
endDate = startDate;
endDate.AddDays(7);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_startmonth: // total for month after start date TCS 12/19/00
startDate = gDBFile->GetStartDate();
endDate = startDate;
endDate.AddSafeMonths(1);
endDate.AddDays(-1);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_startquarter: // total for quarter after start date TCS 12/19/00
startDate = gDBFile->GetStartDate();
endDate = startDate;
endDate.AddSafeMonths(3);
endDate.AddDays(-1);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_startyear: // total for year after start date TCS 12/19/00
startDate = gDBFile->GetStartDate();
endDate = startDate;
endDate.AddSafeYears(1);
endDate.AddDays(-1);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_endday: // total for basic end date TCS 12/19/00
startDate = gDBFile->GetEndDate();
endDate = startDate;
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_endweek: // total for week after end date TCS 12/19/00
startDate = gDBFile->GetEndDate();
endDate = startDate;
endDate.AddDays(7);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_endmonth: // total for month after end date TCS 12/19/00
startDate = gDBFile->GetEndDate();
endDate = startDate;
endDate.AddSafeMonths(1);
endDate.AddDays(-1);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_endquarter: // total for quarter end start date TCS 12/19/00
startDate = gDBFile->GetEndDate();
endDate = startDate;
endDate.AddSafeMonths(3);
endDate.AddDays(-1);
amount = account->GetTotalInRange(startDate, endDate);
break;
case calc_endyear: // total for year after end date TCS 12/19/00
startDate = gDBFile->GetEndDate();
endDate = startDate;
endDate.AddSafeYears(1);
endDate.AddDays(-1);
amount = account->GetTotalInRange(startDate, endDate);
break;
}
}
else
ReportMissingObject(id_UtilityAccount, accountID);
amount = amount.GetRoundedValue(rounding);
return amount;
}
/*********************************************************************************
SetDisplayDirty TCS 12/19/00
respond to a change in report conditions, and return whether a recalc is needed
*********************************************************************************/
Boolean CCalcUtilityAccounts::SetDisplayDirty(const UInt8 source)
{
switch (source)
{
case calc_startup: // we may have changed
case calc_datefieldchange:
case calc_matchchange:
case calc_recordrange:
case calc_daterange:
case calc_accountchange:
mDisplayDirty = true;
return true;
break;
case calc_completed: // just recalculated, so we can turn off the flag
mDisplayDirty = false;
return true;
break;
case calc_breakdownchange: // no need to be dirty
default:
return false;
break;
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FillDataReport TCS 9/7/02
fill in a diagnostic table that shows data field values.
*********************************************************************************/
void CCalcUtilityAccounts::FillDataReport(CTCS_Table *table, CNeoStream *stream) const
{
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
TCS_FailNILMsg(stream, TCS_GetErrString(errID_BadStream));
THE_SUPERCLASS::FillDataReport(table, stream);
FillFieldTagRow(table, stream, tag_currentvalue, cMoneySize, mCurrentValue.GetCurrencyString());
FillFieldObjectIDRow(table, stream, tag_account, mAccount, id_UtilityAccount);
FillFieldEnumRow(table, stream, tag_calculationtype, mCalculationType, MENU_CalcUtilityFields);
FillFieldEnumRow(table, stream, tag_rounding, mRoundingType, MENU_RoundingTypes);
FillFieldEnumRow(table, stream, tag_timerange, mTimeRange, MENU_CalcTimeRanges);
FillFieldStockRow(table, stream, stockID_Padding, cCharSize, SInt32(mPadding));
FillFieldBitRow(table, stream, "mCalcDirty", mCalcDirty, true);
FillFieldBitRow(table, stream, "mDisplayDirty", mDisplayDirty);
FillFieldStockRow(table, stream, stockID_Padding, -6, SInt32(filler));
FillFieldStockRow(table, stream, stockID_Padding, cCharSize, SInt32(mMorePadding));
FillFieldStockRow(table, stream, stockID_Expansion, cMoneySize, mExpansionMoney.GetCurrencyString());
FillEndSafetyTag(table, stream, mEndSafetyTag);
}
|