Link to: header | unit cost
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CCalcPayrollTax
This class manages payroll tax calculations in the Goldenseal accounting software,
payroll software and project management software.
Each record is a field used for payroll tax reporting. These handle things like
state payroll withholding amounts for W-2 reports.
SUPERCLASS = DB_ArrayOwner
Constructor
/*********************************************************************************
default constructor
*********************************************************************************/
CCalcPayrollTax::CCalcPayrollTax()
{
mCalcMethod = calc_deduction;
mTimePeriod = time_lastyear;
mStartDate.SetToToday();
mStartDate.SetToFirstOfYear();
mStartDate.AddYears(-1);
mEndDate.SetToToday();
mEndDate.SetToLastOfYear();
mEndDate.AddYears(-1);
mExpansion = 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 CCalcPayrollTax::CopyFrom(DB_PersistentObject *source, const UInt8 copyFlags)
{
THE_SUPERCLASS::CopyFrom(source, copyFlags);
CCalcPayrollTax *src = TCS_SAFE_CAST(source, CCalcPayrollTax);
TCS_FailNILMsg(src, TCS_GetErrString(errID_BadRecord));
TCS_BlockMove(&src->mCalcMethod, &mCalcMethod, cCopyFileLength);
}
/*********************************************************************************
GetFileLength TCS 8/16/00
return the file length used by this object
*********************************************************************************/
NeoSize CCalcPayrollTax::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
cFileLength;
}
/*********************************************************************************
GetMemberValue
return the value of the member with the given tag
*********************************************************************************/
Boolean CCalcPayrollTax::GetMemberValue(const NeoTag aTag, const NeoTag aType,
void *aValue) const
{
switch (aTag)
{
case tag_calcmethod:
return ConvertEnumMember(mCalcMethod, MENU_PayFieldCalcMethods, aValue, aType);
break;
case tag_timeperiod: // TCS 11/22/01
return ConvertEnumMember(mTimePeriod, MENU_TaxReportDateRanges, aValue, aType);
break;
case tag_startdate: // TCS 11/22/01
return ConvertMember(&mStartDate, type_date, aValue, aType);
break;
case tag_enddate: // TCS 11/22/01
return ConvertMember(&mEndDate, type_date, aValue, aType);
break;
default:
return THE_SUPERCLASS::GetMemberValue(aTag, aType, aValue);
break;
}
}
/*********************************************************************************
SetMemberValue
set the value of the member with the given tag
*********************************************************************************/
Boolean CCalcPayrollTax::SetMemberValue(const NeoTag aTag, const NeoTag aType,
const void *aValue)
{
switch (aTag)
{
case tag_calcmethod:
return ConvertMember(aValue, aType, &mCalcMethod, type_enum);
break;
case tag_timeperiod: // TCS 11/22/01
return ConvertMember(aValue, aType, &mTimePeriod, type_enum);
break;
case tag_startdate: // TCS 11/22/01
return ConvertMember(aValue, aType, &mStartDate, type_date);
break;
case tag_enddate: // TCS 11/22/01
return ConvertMember(aValue, aType, &mEndDate, type_date);
break;
default:
return THE_SUPERCLASS::SetMemberValue(aTag, aType, aValue);
break;
}
}
/*********************************************************************************
ReadObject 9/8/99
read the persistent object's data in from a stream
*********************************************************************************/
void CCalcPayrollTax::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;
ReadInfoArrayFromStream(aStream, mEntries, cHasSafetyTag); // TCS 5/31/03
mCalcMethod = aStream->ReadChar(); // mfs_sa 20feb2k3
mTimePeriod = aStream->ReadChar();
mStartDate.ReadFromStream(aStream);
mEndDate.ReadFromStream(aStream);
mExpansion = aStream->ReadID();
mEndSafetyTag = aStream->ReadEndSafetyTag(this);
if (!IsValidEndTag(mEndSafetyTag)) // TCS 9/8/02
ReportDamagedObject(GetDBClassID(), GetDBID());
}
/*********************************************************************************
WriteObject 9/8/99
write the persistent object's data to a stream
*********************************************************************************/
void CCalcPayrollTax::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);
WriteInfoArrayToStream(aStream, mEntries, cHasSafetyTag);
aStream->WriteChar(mCalcMethod); // mfs_sa 20feb2k3
aStream->WriteChar(mTimePeriod);
mStartDate.WriteToStream(aStream);
mEndDate.WriteToStream(aStream);
aStream->WriteID(mExpansion);
aStream->WriteEndSafetyTag(mEndSafetyTag, this);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
GetTableColInfo
return information about table columns
*********************************************************************************/
Boolean CCalcPayrollTax::CCalcPayrollTaxTable_Desc::GetTableColInfo(const TagType tag,
const TableIndexT col,
STableColInfo *colInfo)
{
if (tag == tag_calctaxtable)
{ // it's the tax field table
switch (col)
{
case col_class:
TCS_BufferFromText(colInfo->colName,
TCS_GetStockString(stockID_Class), cTableColNameLength);
colInfo->colType = coltype_menucv;
colInfo->fieldType = fieldtype_cv;
colInfo->colData = MENU_PayrollTaxFieldTypes;
return true;
break;
case col_id:
TCS_BufferFromText(colInfo->colName,
TCS_GetStockString(stockID_Item), cTableColNameLength);
colInfo->colType = coltype_cv;
colInfo->fieldType = fieldtype_cv;
colInfo->colData = id_TaxItem;
return true;
break;
default:
return false;
break;
}
}
else
return false;
}
/*********************************************************************************
FillMemberTable TCS 1/15/02
fill values into a table. We override since we only fill values in for
some calc methods
*********************************************************************************/
Boolean CCalcPayrollTax::FillMemberTable(CTCS_Table *aTable)
{
if (mCalcMethod == calc_deduction || mCalcMethod == calc_base ||
mCalcMethod == calc_cutoff)
{
return DB_ArrayOwner::FillMemberTable(aTable);
}
else
return true;
}
/*********************************************************************************
GetEntryFromRow TCS 1/13/02
fill in the given percent data structure with info from the table
*********************************************************************************/
Boolean CCalcPayrollTax::GetEntryFromRow(const CTCS_Table &aTable,
const TableIndexT row,
SObjectInfo *outInfo)
{
outInfo->classID = aTable.GetCellValue(row, col_class);
outInfo->itemID = aTable.GetCellValue(row, col_id);
return true;
}
/*********************************************************************************
FillRowFromEntry
fill the given table row with information from our entry
*********************************************************************************/
Boolean CCalcPayrollTax::FillRowFromEntry(CTCS_Table *aTable, const TableIndexT row,
const SObjectInfo &inInfo)
{
if (inInfo.itemID) // TCS 1/13/02
{
aTable->SetCVCellValue(row, col_class, inInfo.classID);
aTable->SetCVCellValue(row, col_id, inInfo.itemID, inInfo.classID);
return true;
}
else
return false;
}
/*********************************************************************************
ExportColumnCString TCS 1/13/02
return the value of a column element from our struct
*********************************************************************************/
CTextString CCalcPayrollTax::ExportColumnCString(const TableIndexT col,
const SObjectInfo &outInfo)
{
switch (col)
{
case col_class:
{
CTextString menuText;
if (FetchCVMenuText(col, outInfo.classID, &menuText))
return menuText.AppendCVExportString(outInfo.classID);
else
return cEmptyString;
}
break;
case col_id:
{
CTextString menuText;
if (FetchCVMenuText(col, outInfo.itemID, &menuText))
return menuText.AppendCVExportString(outInfo.itemID);
else
return cEmptyString;
}
break;
default:
return cEmptyString;
break;
}
}
/*********************************************************************************
ImportColumnCString TCS 1/13/02
fill a column element in our struct
*********************************************************************************/
Boolean CCalcPayrollTax::ImportColumnCString(const TableIndexT col,
const CTextString &inString, SObjectInfo *inInfo)
{
switch (col)
{
case col_class:
inInfo->classID = inString.ParseID();
return true;
break;
case col_id:
inInfo->itemID = inString.ParseID();
return true;
break;
default:
return false;
break;
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
AddTaxItem TCS 12/14/98
add a tax report item to our array.
This probably won't be used- as of 1/13/02 we will probably just enter
items directly into the tax field window.
*********************************************************************************/
void CCalcPayrollTax::AddTaxItem(const UInt8 inClassID, const DBid inID)
{
SObjectInfo info;
CTCS_ArrayIterator iterator(mEntries);
while (iterator.Next(&info))
{
if (info.classID == inClassID && info.itemID == inID)
{ // already there, no need to add
return;
}
}
// if we got this far, better add the item
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
info.classID = inClassID;
info.itemID = inID;
info.transactionType = 0;
// add the item
DB_ObjectTempRemover remover (this); // TCS 8/26/03
if (remover.WasRemoved())
{
mEntries.AddItem(&info);
}
}
/*********************************************************************************
RemoveTaxItem TCS 12/14/98
remove a tax item from our array
This probably won't be used- as of 1/13/02 we will probably just enter
items directly into the tax field window.
*********************************************************************************/
void CCalcPayrollTax::RemoveTaxItem(const UInt8 inClassID, const DBid inID)
{
SObjectInfo info;
CTCS_ArrayIterator iterator(mEntries);
while (iterator.Next(&info))
{
if (info.classID == inClassID && info.itemID == 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;
}
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
GetStartDate TCS 1/14/02
get the start date for this calculator
*********************************************************************************/
CDate CCalcPayrollTax::GetStartDate() const
{
CDate outDate = CDate::Today();
switch (mTimePeriod)
{
case time_week:
case time_lastweek:
case time_month:
case time_lastmonth:
case time_quarter:
case time_lastquarter:
case time_year:
case time_lastyear:
return outDate.GetPeriodStart(mTimePeriod);
break;
case time_custom:
return mStartDate;
break;
}
return outDate;
}
/*********************************************************************************
GetEndDate TCS 1/14/02
get the end date for this calculator
*********************************************************************************/
CDate CCalcPayrollTax::GetEndDate() const
{
CDate outDate = CDate::Today();
switch (mTimePeriod)
{
case time_week:
case time_lastweek:
case time_month:
case time_lastmonth:
case time_quarter:
case time_lastquarter:
case time_year:
case time_lastyear:
return outDate.GetPeriodEnd(mTimePeriod);
break;
case time_custom:
return mStartDate;
break;
}
return outDate;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FillDataReport TCS 9/7/02
fill in a diagnostic table that shows data field values.
*********************************************************************************/
void CCalcPayrollTax::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);
FillFieldEnumRow(table, stream, tag_calcmethod, mCalcMethod, MENU_PayFieldCalcMethods);
FillFieldEnumRow(table, stream, tag_timeperiod, mTimePeriod, MENU_TaxReportDateRanges);
FillFieldTagRow(table, stream, tag_startdate, cDateSize, mStartDate.GetCString());
FillFieldTagRow(table, stream, tag_enddate, cDateSize, mEndDate.GetCString());
FillFieldStockRow(table, stream, stockID_Expansion, cLongSize, mExpansion);
FillEndSafetyTag(table, stream, mEndSafetyTag);
}
|