Link to: header | unit cost
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CCategory
This class manages cost categories in the Goldenseal accounting software,
estimating software, unit
cost software, job costing software and construction
estimating software.
a job cost category. We use categories in many parts of the Goldenseal
estimating software and accounting software-- it groups items in estimates,
classifies expenses for job costing, and 'narrows down' the choices in
breakdowns for estimating and sales. We also use it for progress payments,
reports and income tax reporting.
SUPERCLASS = DB_ArrayOwner
Constructor
/*********************************************************************************
default constructor
*********************************************************************************/
CCategory::CCategory()
{
mRefNum = 0;
mHierarchy = cat_Anywhere; // TCS rev 11/20/03
mIncomeTaxField = 0;
mBillable = true;
mIncludeInStarterFile = true; // TCS 12/5/02
catFiller = 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 CCategory::CopyFrom(DB_PersistentObject *source, const UInt8 copyFlags)
{
THE_SUPERCLASS::CopyFrom(source, copyFlags);
CCategory *src = TCS_SAFE_CAST(source, CCategory);
TCS_FailNILMsg(src, TCS_GetErrString(errID_BadRecord));
mFullName = src->mFullName; // TCS 8/5/03
TCS_BlockMove(&src->mRefNum, &mRefNum, cCopyFileLength);
}
/*********************************************************************************
GetFileLength
return the file length to reserve for this object
*********************************************************************************/
NeoSize CCategory::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
mFullName.FileLength(cFullNameTextLen) +
cFileLength;
}
/*********************************************************************************
GetMemberValue
return the value of the member with the given tag
*********************************************************************************/
Boolean CCategory::GetMemberValue(const NeoTag aTag, const NeoTag aType,
void *aValue) const
{
switch (aTag)
{
/*case tag_incometaxfield:
return ConvertObjectIDMember(mIncomeTaxField, id_IncomeTaxField,
aValue, aType);
break;*/
case tag_location:
case tag_status: // added TCS 4/21/00
return ConvertEnumMember(mHierarchy, MENU_CategoryLocation, aValue, aType);
break;
case tag_refnum:
return ConvertMember(&mRefNum, type_number, aValue, aType);
break;
case tag_fullname: // TCS 11/19/01
return ConvertMember(&mFullName, type_cstring, aValue, aType);
break;
case tag_billable: // TCS 3/27/02
return ConvertBitFieldMember(mBillable, aValue, aType);
break;
case tag_includeinstarter: // TCS 12/5/02
return ConvertBitFieldMember(mIncludeInStarterFile, aValue, aType);
break;
default:
return THE_SUPERCLASS::GetMemberValue(aTag, aType, aValue);
break;
}
}/*********************************************************************************
SetMemberValue
set the value of the member with the given tag
*********************************************************************************/
Boolean CCategory::SetMemberValue(const NeoTag aTag, const NeoTag aType,
const void *aValue)
{
switch (aTag)
{
/*case tag_incometaxfield:
return ConvertDataToObjectID(aValue, aType,
&mIncomeTaxField, id_IncomeTaxField);
break;*/
case tag_location:
return ConvertMember(aValue, aType, &mHierarchy, type_enum);
break;
case tag_refnum:
return ConvertMember(aValue, aType, &mRefNum, type_number);
break;
case tag_fullname: // TCS 11/19/01
return ConvertMember(aValue, aType, &mFullName, type_cstring);
break;
case tag_billable: // TCS 3/27/02
mBillable = ConvertDataToBitField(aValue, aType);
return true;
break;
case tag_includeinstarter: // TCS 12/5/02
mIncludeInStarterFile = ConvertDataToBitField(aValue, aType);
return true;
break;
default:
return THE_SUPERCLASS::SetMemberValue(aTag, aType, aValue);
break;
}
}/*********************************************************************************
ReadObject
read the persistent object's data in from a stream
*********************************************************************************/
void CCategory::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;
ReadIDArrayFromStream(aStream, mEntries, cHasSafetyTag); // TCS 5/31/03
ReadTextFromStream(aStream, &mFullName);
mRefNum.ReadFromStream(aStream); // mfs_sa 20feb2k3
mIncomeTaxField = aStream->ReadID();
mHierarchy = aStream->ReadChar();
*((UInt8*)&mHierarchy + sizeof(mHierarchy)) = aStream->ReadBits(2); // --Bitfield
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 CCategory::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);
WriteIDArrayToStream(aStream, mEntries, cHasSafetyTag);
WriteTextToStream(aStream, mFullName, cFullNameTextLen);
/// aStream->WriteChunk(&mRefNum, cFileLength);
mRefNum.WriteToStream(aStream); // mfs_sa rev 20feb2k3
aStream->WriteID(mIncomeTaxField);
aStream->WriteChar(mHierarchy);
aStream->WriteChar(*((UInt8*)&mHierarchy + sizeof(mHierarchy))); // --Bitfield
aStream->WriteEndSafetyTag(mEndSafetyTag, this);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
GetTableColInfo
return information about table columns
*********************************************************************************/
Boolean CCategory::CCategory_Desc::GetTableColInfo(const TagType tag,
const TableIndexT col,
STableColInfo *colInfo)
{
if (tag == tag_categorytable)
{
switch (col)
{
default:
TCS_BufferFromText(colInfo->colName,
TCS_GetStockString(stockID_CategorySystems), cTableColNameLength);
colInfo->colType = coltype_lookup;
colInfo->fieldType = fieldtype_cv;
colInfo->colData = id_CategorySystem;
return true;
break;
}
}
else
return false;
}/*********************************************************************************
FillRowFromEntry
fill the given table row with information from our entry
*********************************************************************************/
Boolean CCategory::FillRowFromEntry(CTCS_Table *aTable, const TableIndexT row,
const DBid &inID)
{
if (inID) // TCS 1/13/02
{
aTable->SetCVCellValue(row, 1, inID);
return true;
}
else
return false;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FinishImportCreate TCS 11/19/01
fill in values after creation from an import
*********************************************************************************/
void CCategory::FinishImportCreate()
{
// let the superclass do its stuff
THE_SUPERCLASS::FinishImportCreate();
// if there's no full/report name, use the regular name
if (!mFullName.Length())
mFullName = GetName();
}
/*********************************************************************************
GetFullName TCS 11/19/01
get the full name, for reports. Since this field is a recent addition,
we return the regular name if the full name is blank
*********************************************************************************/
CTextString CCategory::GetFullName() const
{
if (mFullName.Length())
return mFullName;
else
return GetName();
}
/*********************************************************************************
AddCatSystem TCS 12/14/98 rev TCS 9/8/99
add a category system to our array
*********************************************************************************/
void CCategory::AddCatSystem(const DBid inID)
{
DBid id;
TObjectIDArrayIterator iterator(mEntries);
while (iterator.Next(id))
{
if (id == inID)
{ // already there, no need to add
return;
}
}
// if we got this far, better add the item
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
id = inID;
DB_ObjectTempRemover remover (this); // TCS 8/26/03
if (remover.WasRemoved())
{
mEntries.AddItem(&id);
}
}
/*********************************************************************************
RemoveCatSystem TCS 12/14/98 rev TCS 9/8/99
remove a category system from our array
*********************************************************************************/
void CCategory::RemoveCatSystem(const DBid inID)
{
DBid id;
TObjectIDArrayIterator iterator(mEntries);
while (iterator.Next(id))
{
if (id == inID) // it's there, so remove it
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
DB_ObjectTempRemover remover (this); // TCS 8/26/03
if (remover.WasRemoved())
{
mEntries.RemoveItemAt(iterator.GetCurrentIndex());
}
return;
}
}
}
/*********************************************************************************
CanBeDeleted TCS 9/29/99
we can't be deleted if we are used in a cat system
*********************************************************************************/
Boolean CCategory::CanBeDeleted(const Boolean giveMessage) const
{
if (mEntries.GetCount() > 0)
{
if (giveMessage)
TCS_ErrorAlert(TCS_GetMsgString(msgID_CantDeleteItem));
return false;
}
else
return THE_SUPERCLASS::CanBeDeleted(giveMessage);
}
/*********************************************************************************
FillDataReport TCS 9/6/02
fill in a diagnostic table that shows data field values.
*********************************************************************************/
void CCategory::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);
FillFieldArrayRow(table, stream, "mEntries", mEntries);
FillFieldStringRow(table, stream, tag_fullname, mFullName);
FillFieldTagRow(table, stream, tag_refnum, cMoneySize, mRefNum.GetNumberString());
FillFieldStockRow(table, stream, stockID_Expansion, cLongSize, mIncomeTaxField);
FillFieldEnumRow(table, stream, tag_location, mHierarchy, MENU_CategoryLocation);
FillFieldBitRow(table, stream, tag_billable, mBillable, true);
FillFieldBitRow(table, stream, tag_includeinstarter, mIncludeInStarterFile); // TCS 12/5/02
FillFieldStockRow(table, stream, stockID_Padding, -6, SInt32(catFiller));
FillEndSafetyTag(table, stream, mEndSafetyTag);
}
|