accounting software, Construction Accounting Software"> Goldenseal Accounting Software-- Account Viewers
Accounting Software
Small Business Software Estimating Software
Construction Estimating SoftwareBookkeeping SoftwareInventory SoftwareInventory Control SoftwareInventory Tracking SoftwareInventory Management SoftwareBusiness Management Software

Account Viewers (Source Code)

Link to: header | record viewer directory

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

Comments

CAccountViewer

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

This is a general viewer for accounts. Parent to all account viewers.

SUPERCLASS = DB_RecordViewer

Constructor

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

Source Code

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

FinishUpdatingFields moved TCS 4/13/00

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

*********************************************************************************/
void CAccountViewer::FinishUpdatingFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
THE_SUPERCLASS::FinishUpdatingFields(creationMethod, viewerObject);

if (IsPrinting()) // we can skip most setup if just printing a record TCS 6/21/00
return;

DB_Account *account = TCS_SAFE_CAST(viewerObject, DB_Account);
TCS_FailNILMsg(account, TCS_GetErrString(errID_BadAccount));

// if there's a billing rate field, set enablement of billing amount rev TCS 5/18/00
// note that we always show the latest value from the billing rate
if (FieldExists(tag_billingrate))
FormatRateField(tag_billingamount, GetFieldValue(tag_billingrate), true);

// if there's a job cost field, set enablement of job cost amount rev TCS 5/18/00
// note that we always show the latest value from the billing rate
if (FieldExists(tag_jobcostrate))
FormatRateField(tag_jobcostamount, GetFieldValue(tag_jobcostrate), true);

// set cat system field enablement based on prefs TCS 3/8/00
Boolean useCatSystem = gDBFile->UseCategorySystems();
SetCVFieldEnabled(tag_catsystem, useCatSystem);

// set location pkg enablement based on prefs TCS 3/8/00
Boolean useLocationPackage = gDBFile->UseLocationPackages();
SetCVFieldEnabled(tag_locationpackage, useLocationPackage);

// if prefs are set, lock the starting balance field TCS 3/29/01
if (creationMethod == record_loadexisting)
{
if (DB_PersistentObject::GetPrefsBoolean(id_DataPrefs, tag_lockstartbalances))
SetFieldEnabled(tag_startbal, false);
}

// update enablement of cost buttons TCS 2/24/03
UpdateCostButton(id_EquipmentHours, button_viewequipmenthours);
UpdateCostButton(id_InventoryUsed, button_viewinventoryused);
UpdateCostButton(id_LaborHours, button_viewlabor);
UpdateCostButton(id_MaterialPurchase, button_viewmaterials);
UpdateCostButton(id_OtherCost, button_viewothercosts);
UpdateCostButton(id_SubcontractorLog, button_viewsubcosts);

// update enablement of 'view contact' buttons TCS 10/30/02 moved 3/29/04
UpdateContactButton(id_ContactLog, button_viewcontactlog);
UpdateContactButton(id_Appointment, button_viewappointments);
UpdateContactButton(id_DocumentLog, button_viewdocumentlog);
UpdateContactButton(id_ProblemLog, button_viewproblemlog);

// update the transaction button TCS 4/3/03
if (account->HasMainTransactions())
SetFieldEnabled(button_viewtransactions, true);
else
SetFieldEnabled(button_viewtransactions, false);
}
/*********************************************************************************

PrepareCVForUpdating TCS 5/10/99, rev 5/17/00

prepare a cv field for updating. "Preparing" means setting the
class id and any other parameters, but NOT the value. This method
is called once, when the cv field is first created.

*********************************************************************************/
void CAccountViewer::PrepareCVForUpdating(DB_Clairvoyant &cvField, DB_PersistentObject *viewerObject,
const SMemberFieldInfo &fieldInfo)
{
switch (cvField.GetPaneID())
{
case tag_estimate:
// transaction cv's can be prepped here, since the account setup
// stuff is not needed for printing (it only affects items in
// selection lists). TCS 5/10/99
{
TCS_FailNILMsg(viewerObject, TCS_GetErrString(errID_BadViewer));

CTransactionCV *cv = TCS_SAFE_CAST(&cvField, CTransactionCV);
if (cv)
{
cv->SetAccountClassID(viewerObject->GetDBClassID());
cv->SetAccountID(viewerObject->GetDBID());
}
}
break;

default:
break;
}
// pass it along
THE_SUPERCLASS::PrepareCVForUpdating(cvField, viewerObject, fieldInfo);
}
/*********************************************************************************

HandleCVChanged

Handle a changed value in a clairvoyant field. Some frequently-used fields are
handled here. Subclasses can override to handle their own cv fields.

*********************************************************************************/
void CAccountViewer::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_billingrate:
FormatRateField(tag_billingamount, value, true);
break;

case tag_jobcostrate:
FormatRateField(tag_jobcostamount, value, true);
break;

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

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

HandleEditChanged

an edit field has changed, act accordingly

*********************************************************************************/
void CAccountViewer::HandleEditChanged(CTCS_EditField *editField)
{
TCS_FailNILMsg(editField, TCS_GetErrString(errID_BadField));
switch (editField->GetPaneID())
{
case tag_startbal: // TCS 2/9/00
{
DB_Account *account = TCS_SAFE_CAST(mCurrViewerObject, DB_Account);
TCS_FailNILMsg(account, TCS_GetErrString(errID_BadAccount));

CMoney startBalance = account->GetStartingBalance();
CMoney currentBalance = account->GetCurrentBalance();
CMoney currentStart = GetFieldMoneyValue(tag_startbal);

// update the curr balance field immediately
SetFieldMoneyValue(tag_currbalance, currentBalance - startBalance + currentStart);
}
break;

case tag_name: // TCS 6/20/01
{
CTextString shortName = editField->GetCString();
UpdateFullNameField(shortName);
}
break;

default:
break;
}
// be sure to pass it along to the superclass
THE_SUPERCLASS::HandleEditChanged(editField);
}
/*********************************************************************************

HandleDBButtonClicked TCS 10/13/02 moved TCS 10/30/02

a button in the layout was clicked.

*********************************************************************************/
void CAccountViewer::HandleDBButtonClicked(const TagType btnID)
{
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));
switch (btnID)
{
case button_enterappointment: // TCS 12/31/02
CreateTransactionRecord(id_Appointment);
break;

case button_entercontact: // TCS 12/31/02
CreateTransactionRecord(id_ContactLog);
break;

case button_viewtransactions: // TCS 4/3/03
{
DBClass accountClass = GetRecordClassID();
switch (accountClass)
{
case id_CashAccount:
case id_CheckingAccount:
case id_InvestmentAccount:
case id_SavingsAccount:
case id_CreditCardAccount:
case id_LoanAccount:
case id_EscrowAccount:
{
DBClass transClass = CBankTransaction::GetBankTransForAccount(accountClass);
DB_Editor::RemoteShowBankEditor(transClass, 0, GetCurrentViewerObjectID());
}
break;

default:
TCS_SysBeep();
break;
}
}
break;

default:
THE_SUPERCLASS::HandleDBButtonClicked(btnID);
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

FormatRateField

format the display of a rate amount field.

*********************************************************************************/
void CAccountViewer::FormatRateField(const TagType fieldTag, const DBid rateID,
const Boolean updateValue)
{
CMoney rateValue;
Boolean enableIt = false;

if (rateID)
enableIt = FetchVariableBillingRate(rateID, rateValue); // rev TCS 7/18/00

SetFieldEnabled(fieldTag, enableIt, cSetItalic);
if (!enableIt && updateValue) // rev TCS 7/18/00
SetFieldMoneyValue(fieldTag, rateValue);
}
/*********************************************************************************
FetchVariableBillingRate renamed TCS 4/23/03

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

**********************************************************************************/
Boolean CAccountViewer::FetchVariableBillingRate(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();

DBid rateClass = CBillingRate::GetBillingRateClass(accountClass);

CBillingRate *rate = nil;

if (rateClass)
{
rate = TCS_SAFE_CAST(gDBFile->GetOneObject(rateClass, rateID),
CBillingRate);
}
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 rate, then we allow entry into variable rate field
return true;
}
/*********************************************************************************

UpdateFullNameField TCS 6/20/01

if we have a blank full name field, fill in the short name text

*********************************************************************************/
void CAccountViewer::UpdateFullNameField(CTextString &shortName)
{
CTextString longName;
if (GetFieldCString(tag_fullname, &longName))
{
if (!longName.Length())
{
SetFieldCString(tag_fullname, shortName);
}
}
}
/*********************************************************************************

PrepareEstimateField TCS 1/27/00 moved 1/3/02

set up the estimate field. This only sets account params

*********************************************************************************/
void CAccountViewer::PrepareEstimateField(const DBClass accountClass,
const DBid accountID)
{
// set cv values in transaction field
CTransactionCV *cv = TCS_SAFE_CAST(FindPaneByID(tag_estimate), CTransactionCV);
if (cv)
{
cv->SetAccountClassID(accountClass);
cv->SetAccountID(accountID);
cv->SetMatchMainAccount(true);
cv->SetShowAllIfBlank(true);
}
// if the field doesn't exist, it's no big deal
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

CanShowMultipleDetails TCS 1/3/02

can this account show a list of transactions?

*********************************************************************************/
Boolean CAccountViewer::CanShowMultipleDetails() const
{
DBClass accountClass = GetRecordClassID();

switch (accountClass)
{
case id_CustomerAccount:
case id_ProjectAccount:

case id_InventoryAccount:

case id_EquipmentAccount:
case id_MaterialAccount:
case id_OtherCostAccount:
case id_SubcontractorAccount:
case id_EmployeeAccount:
return true;

default:
return false;
}
}
/*********************************************************************************

HasMultipleDetails TCS 1/3/02

does this account have items to display?

*********************************************************************************/
Boolean CAccountViewer::HasMultipleDetails() // can't be const
{
// we need to check with the viewer object
if (mCurrViewerObject)
{
DB_Account *account = TCS_SAFE_CAST(mCurrViewerObject, DB_Account);

if (account)
{
return account->HasMainTransactions();
}
}

// if we get this far, there are no items
return false;
}
/*********************************************************************************

ShowMultipleDetails TCS 1/3/02

show transactions for this account

*********************************************************************************/
void CAccountViewer::ShowMultipleDetails()
{
// fetch the cost item
DB_Account *account = TCS_SAFE_CAST(mCurrViewerObject, DB_Account);
TCS_FailNILMsg(account, TCS_GetErrString(errID_BadAccount));

// it can fill in an array of object ID's
TObjectIDArray selectArray = account->GetMainTransactionArray();

// have the editor show the transaction window with array selected
DB_Editor::RemoteShowEditor(GetDetailTransactionClass(), selectArray);
}
/*********************************************************************************

GetDetailTransactionClass TCS 1/3/02

get the transactions to show for this account

*********************************************************************************/
UInt8 CAccountViewer::GetDetailTransactionClass() const
{
switch (GetRecordClassID())
{
case id_CustomerAccount:
return id_Sale;
break;

case id_ProjectAccount:
return id_BillingRecord;
break;

case id_InventoryAccount:
return id_InventoryUsed;
break;

case id_EquipmentAccount:
return id_EquipmentHours;
break;

case id_MaterialAccount:
return id_MaterialPurchase;
break;

case id_OtherCostAccount:
return id_OtherCost;
break;

case id_SubcontractorAccount:
return id_SubcontractorLog;
break;

case id_EmployeeAccount:
return id_LaborHours;
break;

default:
return 0;
break;
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

CanShowUnpaidDetails TCS 1/3/02

can this account show a list of unpaid items?

*********************************************************************************/
Boolean CAccountViewer::CanShowUnpaidDetails() const
{
DBClass accountClass = GetRecordClassID();

switch (accountClass)
{
case id_CustomerAccount:
case id_ProjectAccount:
case id_MaterialAccount:
case id_OtherCostAccount:
case id_SubcontractorAccount:
case id_EmployeeAccount:
return true;

default:
return false;
}
}
/*********************************************************************************

HasUnpaidItems TCS 1/3/02

does this account have unpaid items to display?

*********************************************************************************/
Boolean CAccountViewer::HasUnpaidItems() const
{
// we need to check with the viewer object
if (mCurrViewerObject)
{
DB_Account *account = TCS_SAFE_CAST(mCurrViewerObject, DB_Account);

if (account)
{
return account->HasUnpaidItems();
}
}

// if we get this far, there are no items
return false;
}
/*********************************************************************************

ShowUnpaidDetails TCS 1/3/02

show unpaid items for this account

*********************************************************************************/
void CAccountViewer::ShowUnpaidDetails()
{
// fetch the cost item
DB_Account *account = TCS_SAFE_CAST(mCurrViewerObject, DB_Account);
TCS_FailNILMsg(account, TCS_GetErrString(errID_BadAccount));

// it can fill in an array of object ID's
TObjectIDArray selectArray;
account->FillUnpaidItemArray(selectArray);

// have the editor show the transaction window with array selected
DB_Editor::RemoteShowEditor(GetDetailTransactionClass(), selectArray);
}