Link to: header | record viewer
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CPaymentTermViewer
This class manages payment terms for the Goldenseal accounting software,
small business management software, construction
project management software and
construction estimating software.
a generic viewer for payment terms. This is the parent of CProjectPTViewer
and similar viewers.
SUPERCLASS = DB_RecordViewer
Constructor
/*********************************************************************************
constructor
*********************************************************************************/
CPaymentTermViewer::CPaymentTermViewer(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo)
: DB_RecordViewer(inPaneInfo, inViewInfo)
{
}
Source Code
/*********************************************************************************
GetReadyToUpdateFields split TCS 4/17/00
Do prep work before updating fields
*********************************************************************************/
void CPaymentTermViewer::GetReadyToUpdateFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
// before we start, update the date array
CPaymentTerm *term = TCS_SAFE_CAST(viewerObject, CPaymentTerm);
TCS_FailNILMsg(term, TCS_GetErrString(errID_BadObject));
// update the date array, or fill it in for a new record
if (term->IsInDatabase())
{
DB_ObjectTempRemover remover (term); // TCS 2/6/04
if (remover.WasRemoved())
term->UpdateDateArray();
}
else
term->UpdateDateArray();
// the superclass handles basic field updating
THE_SUPERCLASS::GetReadyToUpdateFields(creationMethod, viewerObject);
}
/*********************************************************************************
FinishUpdatingFields split TCS 4/17/00
Finish prep work after updating fields from an object, but before displaying them
*********************************************************************************/
void CPaymentTermViewer::FinishUpdatingFields(const UInt8 creationMethod,
DB_PersistentObject *viewerObject)
{
TCS_FailNILMsg(viewerObject, TCS_GetErrString(errID_BadObject));
// the superclass handles basic field updating
THE_SUPERCLASS::FinishUpdatingFields(creationMethod, viewerObject);
// format the interest field
SInt32 interestType;
if (viewerObject->GetMemberValue(tag_intorpenaltytype, type_long, &interestType))
FormatInterestField(interestType);
// format the discount field
SInt32 discountType;
if (viewerObject->GetMemberValue(tag_discounttype, type_long, &discountType))
FormatDiscountField(discountType);
// format the discount period field
SInt32 discountPeriodType;
if (viewerObject->GetMemberValue(tag_discountperiodtype, type_long, &discountPeriodType))
FormatDiscountPeriodField(discountPeriodType);
// format the due date field
SInt32 dueType;
if (viewerObject->GetMemberValue(tag_paydueperiod, type_long, &dueType))
FormatDueField(dueType);
// format the retainage field
SInt32 retainageType;
if (viewerObject->GetMemberValue(tag_retainagetype, type_long, &retainageType))
FormatRetainageField(retainageType);
// format the table TCS 3/3/99
SetTablePanes(GetPopupValue(tag_billperiodtype));
}
/*********************************************************************************
HandlePopupChanged
a popup menu has been clicked, act accordingly
*********************************************************************************/
void CPaymentTermViewer::HandlePopupChanged(CTCS_StdPopupMenu *popupMenu)
{
TCS_FailNILMsg(popupMenu, TCS_GetErrString(errID_BadPopup));
switch (popupMenu->GetPaneID())
{
case tag_retainagetype:
FormatRetainageField(popupMenu->GetValue());
break;
case tag_intorpenaltytype:
FormatInterestField(popupMenu->GetValue());
break;
case tag_discounttype:
FormatDiscountField(popupMenu->GetValue());
break;
case tag_discountperiodtype:
FormatDiscountPeriodField(popupMenu->GetValue());
break;
case tag_paydueperiodtype:
FormatDueField(popupMenu->GetValue());
break;
case tag_billperiodtype:
FillNewBillingDates();
break;
default:
break;
}
// pass it along
THE_SUPERCLASS::HandlePopupChanged(popupMenu);
}/*********************************************************************************
HandleEditChanged TCS 3/4/99
an edit field has changed, act accordingly
*********************************************************************************/
void CPaymentTermViewer::HandleEditChanged(CTCS_EditField *editField)
{
TCS_FailNILMsg(editField, TCS_GetErrString(errID_BadField));
// now process the field
SInt32 fieldID = editField->GetPaneID();
switch (fieldID)
{
case tag_basedate:
FillNewBillingDates();
break;
default:
break;
}
// pass it along
THE_SUPERCLASS::HandleEditChanged(editField);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FormatInterestField
format the interest/finance charge field as dollar or percent
according to the setting
*********************************************************************************/
void CPaymentTermViewer::FormatInterestField(const SInt32 interestType)
{
CTCS_EditField *interestField =
TCS_SAFE_CAST(FindMemberField(tag_intorpenalty), CTCS_EditField);
if (interestType == calc_dollarpermonth || interestType == calc_dollarperday)
{
SetFieldEnabled(tag_mininterest, false);
SetFieldValue(tag_mininterest, 0);
SetFieldType(tag_intorpenalty, fieldtype_money);
}
else
{
SetFieldEnabled(tag_mininterest, true);
SetFieldType(tag_intorpenalty, fieldtype_percent);
}
}/*********************************************************************************
FormatDiscountField
format the number format of the discount field
*********************************************************************************/
void CPaymentTermViewer::FormatDiscountField(const SInt32 discountType)
{
if (discountType == discount_percent || discountType == calc_percentperyear ||
discountType == calc_percentpermonth) // rev TCS 3/20/02
SetFieldType(tag_discount, fieldtype_percent);
else
SetFieldType(tag_discount, fieldtype_money);
}/*********************************************************************************
FormatDiscountPeriodField
format the enablement of the discount period field
*********************************************************************************/
void CPaymentTermViewer::FormatDiscountPeriodField(const SInt32 discountPeriodType)
{
Boolean showIt = !(discountPeriodType == date_anytime);
// we don't have to check if the field is there, since
// SetFieldEnabled will do that
SetFieldEnabled(tag_discountperiod, showIt);
}/*********************************************************************************
FormatRetainageField
a check box has been clicked, act accordingly
*********************************************************************************/
void CPaymentTermViewer::FormatRetainageField(const SInt32 retainageType)
{
SetFieldType(tag_retainage, retainageType == calc_dollars ?
fieldtype_money : fieldtype_percent);
}
/*********************************************************************************
FormatDueField
format the enablement of the due date field
*********************************************************************************/
void CPaymentTermViewer::FormatDueField(const SInt32 dueType)
{
Boolean showIt = !(dueType == date_anytime);
// we don't have to check if the field is there, since
// SetFieldEnabled will do that
SetFieldEnabled(tag_paydueperiod, showIt);
SetFieldEnabled(tag_graceperiod, showIt);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FillNewBillingDates
fill in a new set of billing dates
*********************************************************************************/
void CPaymentTermViewer::FillNewBillingDates()
{
UInt8 period = GetPopupValue(tag_billperiodtype);
if (period == time_custom)
{
// for a custom schedule, no need to do anything
}
else
{ // if another bill period type, let's fill in values
CDate currBillDate = GetFieldDateValue(tag_basedate);
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));
CPaymentTerm *term = TCS_SAFE_CAST(mCurrViewerObject, CPaymentTerm);
TCS_FailNILMsg(term, TCS_GetErrString(errID_BadObject));
// we also need to fill dates into the table
TagType tableTag = term->GetDateTableTag();
CMemberTable *table =
TCS_SAFE_CAST(FindPaneByID(tableTag), CMemberTable);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
term->FillDateTable(period, currBillDate, table);
}
// now format table editability
SetTablePanes(period);
}
/*********************************************************************************
SetTablePanes TCS 3/3/99
set the editability of table panes, based on payment term period
*********************************************************************************/
void CPaymentTermViewer::SetTablePanes(const SInt32 period)
{
TCS_FailNILMsg(mCurrViewerObject, TCS_GetErrString(errID_BadObject));
CPaymentTerm *term = TCS_SAFE_CAST(mCurrViewerObject, CPaymentTerm);
TCS_FailNILMsg(term, TCS_GetErrString(errID_BadObject));
TagType tableTag = term->GetDateTableTag();
CMemberTable *table =
TCS_SAFE_CAST(FindPaneByID(tableTag), CMemberTable);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));
if (period == time_custom)
{
table->SetColType(CPaymentTerm::col_date, coltype_edit, true);
table->SetFieldType(CPaymentTerm::col_date, fieldtype_date, true);
}
else
{
table->SetColType(CPaymentTerm::col_date, coltype_caption, true);
table->SetFieldType(CPaymentTerm::col_date, fieldtype_date, true);
}
} |