Accounting Software
Small Business Software Estimating Software
Construction Estimating SoftwareBookkeeping SoftwareInventory SoftwareInventory Control SoftwareInventory Tracking SoftwareInventory Management SoftwareBusiness Management Software

Subcontractor Account Viewer (Source Code)

Link to: header | record viewer directory

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

Comments

CSubcontractorAccountViewer

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

It's a viewer for subcontractor accounts. The accounts provide setup
for job costing and accounts payable. They also track expiration
of subcontractor insurance (liability and worker's comp).

SUPERCLASS = CAccountViewer

Constructor

/*********************************************************************************
constructor
*********************************************************************************/
CSubcontractorAccountViewer::CSubcontractorAccountViewer(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: CAccountViewer(inPaneInfo, inViewInfo)
{
}

Source Code

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

GetReadyToUpdateFields split TCS 4/17/00

Do prep work before updating fields

*********************************************************************************/
void CSubcontractorAccountViewer::GetReadyToUpdateFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
TCS_FailNILMsg(viewerObject, TCS_GetErrString(errID_BadViewer));

// format the wage amount field
// note that we always update the value if it's changed
FormatWageField(tag_wageamount, GetFieldValue(tag_wagerate), true);

// format the enablement of wc field
SInt32 termType;
TCS_ASSERTMsg(viewerObject->GetMemberValue(tag_wcexpiryaction,
type_long, &termType), TCS_GetErrString(errID_BadValue));
FormatCompField(termType);

// format liability field
SInt32 liabilityType;
TCS_ASSERTMsg(viewerObject->GetMemberValue(tag_liabexpiryaction,
type_long, &liabilityType), TCS_GetErrString(errID_BadValue));
FormatLiabilityField(liabilityType);

// the superclass handles basic field updating
THE_SUPERCLASS::GetReadyToUpdateFields(creationMethod, viewerObject);
}
/*********************************************************************************

FinishUpdatingFields TCS 10/30/02

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

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

// set enablement of the 'view contacts' buttons TCS 10/30/02
UpdateContactButton(id_SubcontractorLog, button_viewinvoices); // TCS 11/24/02
}
/*********************************************************************************

HandleCVChanged

Handle a changed value in a clairvoyant field.

*********************************************************************************/
void CSubcontractorAccountViewer::HandleCVChanged(CTCS_CVField *cvField)
{
// sanity check
TCS_FailNILMsg(cvField, TCS_GetErrString(errID_BadClairvoyant));
DBid value = cvField->GetValue();

// what we need to do depends on which cv changed
switch (cvField->GetPaneID())
{
case tag_wagerate:
FormatWageField(tag_wageamount, value, true);
break;

default:
break;
}
// also let the superclass have a chance
THE_SUPERCLASS::HandleCVChanged(cvField);

}
/*********************************************************************************

HandlePopupChanged

a popup menu has been clicked, act accordingly

*********************************************************************************/
void CSubcontractorAccountViewer::HandlePopupChanged(CTCS_StdPopupMenu *popupMenu)
{
TCS_FailNILMsg(popupMenu, TCS_GetErrString(errID_BadPopup));
switch (popupMenu->GetPaneID())
{
case tag_wcexpiryaction:
FormatCompField(popupMenu->GetValue());
break;

case tag_liabexpiryaction:
FormatLiabilityField(popupMenu->GetValue());
break;

default:
break;
}

THE_SUPERCLASS::HandlePopupChanged(popupMenu);
}
/*********************************************************************************

HandleDBButtonClicked TCS 11/24/02

a button in the layout was clicked.

*********************************************************************************/
void CSubcontractorAccountViewer::HandleDBButtonClicked(const TagType btnID)
{
if (btnID == button_viewinvoices)
{
DB_Account *account = TCS_SAFE_CAST(mCurrViewerObject, DB_Account);
TCS_FailNILMsg(account, TCS_GetErrString(errID_BadObject));

TObjectIDArray contactArray;

account->FetchMeetingArray(id_SubcontractorLog, contactArray);

if (contactArray.GetCount() > 0)
{
DB_Editor::ShowEditorArray(id_SubcontractorLog, contactArray, cShowLastRecord);
}
}
else
THE_SUPERCLASS::HandleDBButtonClicked(btnID);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

FormatWageField

format the display of a wage rate amount field.

*********************************************************************************/
void CSubcontractorAccountViewer::FormatWageField(const TagType fieldTag, const DBid rateID,
const Boolean updateValue)
{
CMoney rateValue = 0;
Boolean enableIt = false; // rev TCS 7/18/00
if (rateID)
enableIt = FetchVariableWage(rateID, rateValue);

SetFieldEnabled(fieldTag, enableIt, cSetItalic);

if (!enableIt && updateValue) // rev TCS 7/18/00
SetFieldMoneyValue(fieldTag, rateValue);
}
/*********************************************************************************

FormatRateField

format the display of a job cost or billing rate amount field

*********************************************************************************/
void CSubcontractorAccountViewer::FormatRateField(const TagType fieldTag, const DBid rateID,
const Boolean updateValue)
{
if (rateID)
{
CMoney rateValue = 0;
UInt8 calcMethod = FetchCalcMethod(rateID, rateValue);
SetFieldEnabled(fieldTag, calcMethod == rate_Variable);

switch (calcMethod)
{
case rate_Variable:
break;

case rate_Dollar:
if (updateValue)
SetFieldMoneyValue(fieldTag, rateValue);
break;

case rate_Net:
case rate_NetPlusPercent:
SetFieldCString(fieldTag, TCS_GetStockString(stockID_NetCost));
break;

case rate_Gross:
case rate_GrossPlusPercent:
SetFieldCString(fieldTag, TCS_GetStockString(stockID_GrossCost));
break;

default:
TCS_DebugAlert("Oops, bad case in CSubcontractorAccountViewer::FormatRateField!");
break;
}
}
else
{
SetFieldEnabled(fieldTag, false);

if (updateValue)
SetFieldMoneyValue(fieldTag, 0); // TCS 7/18/00
}
}
/*********************************************************************************
FetchCalcMethod renamed TCS 4/23/03

return the calculation method and fill in the billing rate.

**********************************************************************************/
UInt8 CSubcontractorAccountViewer::FetchCalcMethod(const DBid rateID, CMoney &rateValue)
{
if (rateID)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));

DBid accountClass = mCurrViewerObject->GetDBClassID();

CSubBillingRate *rate = TCS_SAFE_CAST(gDBFile->GetOneObject(id_SubBillingRate,
rateID), CSubBillingRate);
if (rate) // we found a billing rate, so it can decide whether there's a variable rate
{
DB_ObjectWatcher watcher(rate);
rateValue = rate->GetRate();

return rate->GetCalcMethod();
}
} // if no rate, then we'll not allow entry into variable rate field
rateValue = 0;
return rate_Dollar;
}
/*********************************************************************************
FetchVariableWage

return whether a wage rate is variable, and fetch the current rate

**********************************************************************************/
Boolean CSubcontractorAccountViewer::FetchVariableWage(const DBid rateID, CMoney &rateValue)
{
if (rateID)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));

DBid accountClass = mCurrViewerObject->GetDBClassID();

CSubChargeRate *rate = TCS_SAFE_CAST(gDBFile->GetOneObject(id_SubChargeRate,
rateID), CSubChargeRate);
if (rate) // we found a rate, so it can decide whether there's a variable rate
{
DB_ObjectWatcher watcher(rate);
rateValue = rate->GetRate();

return rate->HasVariableRate();
}
} // if no wage rate, then we do not allow entry into rate field
return false; // rev TCS 7/18/00
}/*********************************************************************************

FormatCompField

format the enablement of workers comp field

*********************************************************************************/
void CSubcontractorAccountViewer::FormatCompField(const SInt32 termType)
{
Boolean enableEm = (termType == action_deduct);
SetFieldEnabled(tag_wcrate, enableEm);
}/*********************************************************************************

FormatLiabilityField

format the enablement of workers comp field

*********************************************************************************/
void CSubcontractorAccountViewer::FormatLiabilityField(const SInt32 termType)
{
Boolean enableEm = (termType == action_deduct);
SetFieldEnabled(tag_liabrate, enableEm);
}