Link to: header | source 2 | source 3 | tables
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CCostBreakdownTable
This class manages cost breakdown tables for the Goldenseal accounting software,
small business management software, construction
project management software and
construction
accounting software.
It's an abstract table for breakdowns showing costs- used by item and category
breakdowns. There is a lot of code here since we do many different calculations
in the tables.
SUPERCLASS = CBreakdownTable
Constructor
/*********************************************************************************
constructor
*********************************************************************************/
CCostBreakdownTable::CCostBreakdownTable(const SPaneInfo &inPaneInfo, const SViewInfo &inViewInfo,
DB_ClassDescriptor *desc)
: CBreakdownTable(inPaneInfo, inViewInfo, desc)
{
mOnSale = false;
mHourlyRate = 0;
mAdjustPercent = 0;
mCustDiscount = 0;
mStartDate = CDate::Today();
}
Source Code
/*********************************************************************************
HandleCellTextChanged TCS 5/13/01 rev 11/5/02
handle change of a text cell.
*********************************************************************************/
void CCostBreakdownTable::HandleCellTextChanged(const TableIndexT row,
const TableIndexT col,
const Boolean sendMessage)
{
TagType colTag = GetColTag(col);
switch (colTag)
{
case tag_quantity: // we override completely because we have
if (!InFindMode()) // different calc order. We need to do schedule
{ // update before RecalcTotal so the viewer gets
// the correct finish date. TCS rev 11/5/02
RecalcBreakdownRow(row, colTag);
RecalcScheduleRow(row, colTag);
RefreshRow(row);
RecalcTotal();
}
break;
case tag_startdate: // do a schedule update
case tag_enddate:
case tag_crewsize:
case tag_date: // TCS 4/4/04
case tag_starttime:
case tag_endtime:
if (!InFindMode()) // TCS 12/13/01
{
RecalcScheduleRow(row, colTag);
RefreshRow(row);
RecalcTotal();
}
break;
case tag_discount: // TCS 1/5/03
if (!InFindMode())
{
RecalcBreakdownRow(row, colTag);
RefreshRow(row);
RecalcTotal();
}
break;
default:
THE_SUPERCLASS::HandleCellTextChanged(row, col, sendMessage);
break;
}
}
/*********************************************************************************
FillNewRowCells
fill a row with starter values
*********************************************************************************/
void CCostBreakdownTable::FillNewRowCells(TableIndexT row)
{
THE_SUPERCLASS::FillNewRowCells(row);
CMoney zeroValue = 0,
oneValue = 1;
CTextString blankString;
blankString.MakeNull();
// set location, cat and subcat default to blank
SetMemberCV(row, tag_location, 0); // rev TCS 9/27/01
SetMemberCV(row, tag_category, 0);
SetMemberCV(row, tag_subcategory, 0);
SetMemberColString(row, tag_unitsize, blankString);
// set cost item default to blank
SetMemberColString(row, tag_costitem, blankString);
// set quantity and unit cost rev TCS 1/17/00
if (mOwnerClass == id_LaborHours || mOwnerClass == id_EquipmentHours)
{
SetMemberColNumber(row, tag_quantity, zeroValue);
SetMemberColMoney(row, tag_unitcost, mHourlyRate);
if (row == 1) // TCS 7/21/01
{
CDate today = CDate::Today();
SetMemberColDate(row, tag_date, today);
}
else
{
CTextString dateString = GetMemberColString(row - 1, tag_date);
SetMemberColString(row, tag_date, dateString);
}
}
else
{
SetMemberColNumber(row, tag_quantity, oneValue);
SetMemberColMoney(row, tag_unitcost, zeroValue);
}
// set total cost default to zero
SetMemberColMoney(row, tag_amount, zeroValue);
// set taxable to taxable // TCS 8/14/01
SetMemberColString(row, tag_taxable, cCheckMarkString);
// fill in start dates
if (mOwnerClass == id_Estimate)
{
if (row == 1)
SetMemberColString(row, tag_date, mStartDate.GetCString());
else
{
CDate startDate = GetRowEndDate(row - 1);
SetMemberColString(row, tag_date, startDate.GetCString());
}
}
FinishRowFill(row); // TCS 5/13/03
}
/*********************************************************************************
FinishRowFill TCS 3/20/01 renamed 8/2/01 rev 11/25/03
finish up after filling a table from breakdown items. For estimates, we may need
to change some dollars to percents, and cancel out some cells that are
not used. This used to be FinishTableFill, but it now does each row individually.
*********************************************************************************/
void CCostBreakdownTable::FinishRowFill(const TableIndexT row)
{
if (mOwnerClass == id_Estimate)
{
CMoney amount;
TableIndexT unitCostCol = GetMemberCol(tag_unitcost);
UInt8 costArea = GetMemberColValue(row, tag_costarea);
if (CCostBreakdownEntry::CostItemIsPercent(costArea)) // rev TCS 11/8/02
{
// we need to set number formats for percent costs
amount = GetMemberColMoney(row, tag_quantity);
SetMemberColPercent(row, tag_quantity, amount);
SetMemberColString(row, tag_unitcost, cTwoDashString);
}
else if (costArea == costtype_delay || costArea == costtype_tool ||
costArea == costtype_reminder) // TCS 11/5/02 rev 3/31/03
{
// we don't show costs for a delay/tool/reminder
SetMemberColString(row, tag_unitcost, cTwoDashString);
SetMemberColString(row, tag_amount, cTwoDashString);
}
else if (costArea == costtype_assembly || costArea == costtype_assmlabor ||
costArea == costtype_assmmaterial) // TCS 3/31/03 rev 11/26/03
{
// we star the unit cost for items that include a 'fixed' item
// since it doesn't have a static unit cost amount
DBid id = GetMemberColValue(row, tag_costitem);
if (CUnitCost::HasFixedQuantity(id_Assembly, id)) // rev TCS 11/26/03
{
CMoney unitCost = GetCellMoneyValue(row, unitCostCol);
CTextString costString = unitCost.GetCurrencyString();
costString.Prepend(cStarString);
SetCellText(row, unitCostCol, costString);
}
}
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
GetColType
return the column type for the given column
*********************************************************************************/
SInt32 CCostBreakdownTable::GetColType(const TableIndexT row, const TableIndexT col) const
{
switch (GetColTag(col))
{
case tag_costarea:
return coltype_menucv;
break;
case tag_amount: // some tables override this to allow
return coltype_caption; // active entry
break;
case tag_taxable: // may also be a passive caption in
return coltype_checkmark; // some tables
break;
case tag_date: // TCS 1/6/00
case tag_enddate:
if (mOwnerClass == id_LaborHours || mOwnerClass == id_EquipmentHours ||
mOwnerClass == id_Estimate) // rev TCS 5/13/02
return coltype_edit;
else
return coltype_caption;
break;
case tag_discount: // TCS 2/22/02
return coltype_edit;
break;
case tag_comments: // TCS 1/28/02
return coltype_edit;
break;
default:
return THE_SUPERCLASS::GetColType(row, col);
break;
}
}
/*********************************************************************************
GetFieldType TCS 9/11/99 rev TCS 3/20/01
return the field type for the given col
*********************************************************************************/
UInt8 CCostBreakdownTable::GetFieldType(const TableIndexT row, const TableIndexT col) const
{
switch (GetColTag(col))
{
case tag_unitcost:
return fieldtype_emoney; // rev TCS 1/19/00
break;
case tag_date: // TCS 1/6/00
return fieldtype_date;
break;
case tag_taxable: // TCS 8/14/01
return fieldtype_checkbox;
break;
case tag_discount: // TCS 2/22/02
if (mOwnerClass == id_LaborHours || mOwnerClass == id_EquipmentHours)
return fieldtype_number;
else
return fieldtype_percent; // rev TCS 1/5/03
break;
case tag_quantity:
if (mOwnerClass == id_Estimate)
{
SInt32 costArea = GetMemberColValue(row, tag_costarea);
if (CCostBreakdownEntry::CostItemIsPercent(costArea))
return fieldtype_percent;
else
return fieldtype_number;
}
else
return THE_SUPERCLASS::GetFieldType(col);
break;
case tag_crewsize: // TCS 8/9/02
return fieldtype_number;
break;
default:
return THE_SUPERCLASS::GetFieldType(col);
break;
}
}
/*********************************************************************************
GetCostArea TCS 4/29/02
return the cost area for the given row
*********************************************************************************/
UInt8 CCostBreakdownTable::GetCostArea(const TableIndexT row) const
{
TableIndexT costTypeCol = GetMemberCol(tag_costarea);
if (costTypeCol)
{
return GetCellValue(row, costTypeCol);
}
else
return 0;
}
/*********************************************************************************
GetAmountCol TCS 9/11/99 rev 1/17/00
get the column used for table totals. We override since hours tables use
hours not dollars
*********************************************************************************/
TableIndexT CCostBreakdownTable::GetAmountCol()
{
if (mOwnerClass == id_LaborHours || mOwnerClass == id_EquipmentHours)
return GetMemberCol(tag_quantity);
else
return GetMemberCol(tag_amount);
}
/*********************************************************************************
GetDetailTransactionClass TCS 11/18/99
get the transaction object class id for a row
*********************************************************************************/
UInt8 CCostBreakdownTable::GetDetailTransactionClass(const TableIndexT row) const
{
SInt32 classCol = GetMemberCol(tag_costarea);
if (classCol)
{
UInt8 costArea = GetCellValue(row, classCol);
UInt8 costClassID = DB_ClassDescriptor::GetCostAreaClass(costArea);
if (DB_ClassDescriptor::IsTransaction(costClassID))
return costClassID;
else
return 0;
}
else
return 0;
}
/*********************************************************************************
GetHardCostTotal TCS 3/17/99
get the sum of hard costs from this table
*********************************************************************************/
CMoney CCostBreakdownTable::GetHardCostTotal()
{
CMoney theSum = 0;
TableIndexT amountCol = GetMemberCol(tag_amount);
SInt32 costTypeCol = GetMemberCol(tag_costarea);
UInt8 costArea = 0;
// if invalid columns, return zero
if (!amountCol || !costTypeCol)
return theSum;
// if we have a valid column, fetch the total
for ( TableIndexT row = 1 ; row <= GetNumRows() ; row++ )
{
costArea = GetCellValue(row, costTypeCol);
switch (costArea)
{
case costtype_labor: // we include these costs
case costtype_material:
case costtype_subcontractor:
case costtype_other:
case costtype_equipment:
case costtype_assembly: // TCS bugfix 8/13/02
case costtype_assmlabor: // TCS 11/26/03
case costtype_assmmaterial:
case costtype_bid:
case costtype_allowance:
case costtype_unlisted:
case costtype_unlistedlabor: // TCS 11/4/99
case costtype_unlistedmaterial:
case costtype_unlistedequip:
case costtype_unlistedsub:
case costtype_unlistedother:
case costtype_contingencies:
theSum += GetCellMoneyValue(row, amountCol);
break;
case costtype_profit: // we don't include these costs
case costtype_overhead:
case costtype_salestax:
case costtype_commission:
case costtype_delivery:
case costtype_softcost:
case costtype_percenthard:
case costtype_percenttotal:
case costtype_percentlabor: // TCS 11/8/02
case costtype_percentmaterial:
case costtype_percentsubs:
case costtype_delay: // TCS 3/31/03
case costtype_tool:
case costtype_reminder:
default:
break;
}
}
return theSum;
}
|