Link to: header | source
code | source 2 | source 3 | transactions
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Source Code
This class manages basic accounting transactions in the Goldenseal accounting software,
estimating software, project
management software
and construction
management software.
/*********************************************************************************
IsValidJobCost TCS 4/19/01
should we display this transaction in a job cost item breakdown?
*********************************************************************************/
Boolean CTransaction::IsValidJobCost(const UInt8 costType) const
{
if (costType)
return mMainAccountClass == costType;
else
return true;
}
/*********************************************************************************
IsInLocalUse TCS 10/23/01
is this object currently being shown in a viewer that has been changed?
*********************************************************************************/
Boolean CTransaction::IsInLocalUse() const
{
if (mDisplayingViewer)
{
return mDisplayingViewer->IsDirty();
}
else
return false;
}
/*********************************************************************************
IsBreakdownTransaction (static) TCS 9/27/00
return whether the given class id is for a breakdown transaction.
We special case for assemblies because they have a breakdown table but don't
have a breakdown popup.
*********************************************************************************/
Boolean CTransaction::IsBreakdownTransaction(const DBClass inClassID,
const Boolean includeAssemblies)
{
if (inClassID == id_Assembly) // TCS 3/22/02
{
return includeAssemblies;
}
else switch (inClassID)
{
case id_Allowance: // TCS 3/14/02
case id_BankCheck:
case id_BankDeposit:
case id_BankPayment:
case id_Bid:
case id_BillingRecord: // forgot TCS 10/9/00
case id_CashTransaction:
case id_ChangeOrder:
case id_CheckingTransaction:
case id_CostTransfer:
case id_CreditCardTransaction:
case id_EquipmentHours:
case id_EscrowTransaction:
case id_Estimate:
case id_InventoryTransfer:
case id_InventoryUsed:
case id_InvestmentTransaction:
case id_LaborHours:
case id_LoanTransaction:
case id_MaterialPurchase:
case id_OtherCost:
case id_PaymentReceipt: // forgot TCS 10/5/00
case id_PayrollRecord:
case id_PurchaseWorkOrder:
case id_Sale:
case id_SavingsTransaction:
case id_SubcontractorLog:
return true;
break;
default:
return false;
break;
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FillCostItemInfo rev TCS 12/4/00
fill in an item for detailed job costing.
*********************************************************************************/
void CTransaction::FillCostItemInfo(TJobCostItemArray &itemArray, const UInt8 costType,
const DBid /*accountID*/) const
{
SJobCostItemInfo itemInfo;
if (!IsValidJobCost(costType)) // rev TCS 4/17/01, 4/19/01
return;
// fetch some basic info from the transaction
itemInfo.id = GetDBID();
CTextString textString = GetMainAccountName();
TCS_BufferFromText(itemInfo.supplier, textString);
textString = GetName();
if (!textString.Length())
textString = GetMenuName(); // TCS 11/13/03
TCS_BufferFromText(itemInfo.item, textString);
itemInfo.costAmount = GetJobCostAmount(); // rev TCS 9/3/99
itemInfo.date = mDate;
itemInfo.type = GetJobCostClass();
// fetch category name
CTextString catName;
DBid catID = GetCategory();
if (catID)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
gDBFile->GetObjectName(id_Category, catID, catName);
}
else
catName.MakeNull();
TCS_BufferFromText(itemInfo.category, catName);
// compute billing and payment amounts using flags
if (HasBeenTandMBilled())
itemInfo.billedAmount = GetTandMAmount(true, false); // rev TCS 4/3/00
else
itemInfo.billedAmount = 0;
// compute the amount paid rev TCS 5/19/00, rev 10/8/02
itemInfo.paidAmount = TCS_MIN(GetAdjustedAmount(), GetAmountPaid());
itemArray.Append(itemInfo);
}
/*********************************************************************************
AddJobCostRefs TCS 9/11/98 rev 5/3/00
add the reference to a job cost item to a category info struct
*********************************************************************************/
/*Boolean CTransaction::AddJobCostRefs(SJobCostCategoryInfo &costInfo,
const UInt8 inCostType)
{
// sanity check and initialize
TCS_FailNILMsg(costInfo.itemArray, TCS_GetErrString(errID_BadArray));
SObjectInfo itemInfo;
itemInfo.itemID = GetDBID();
itemInfo.classID = GetDBClassID();
// add this transaction to the cat array
costInfo.itemArray->Append(itemInfo);
// figure the type of cost
UInt8 costType;
if (inCostType)
costType = inCostType;
else
costType = GetJobCostClass();
// add transaction totals to the basic cost info struct
switch (costType)
{
case costtype_equipment:
costInfo.equipmentAmount += GetJobCostAmount();
break;
case costtype_labor:
costInfo.laborAmount += GetJobCostAmount();
break;
case costtype_material:
costInfo.materialAmount += GetJobCostAmount();
break;
case costtype_subcontractor:
costInfo.subcontractorAmount += GetJobCostAmount();
break;
case costtype_other:
costInfo.otherAmount += GetJobCostAmount();
break;
case costtype_income:
costInfo.incomeAmount += GetAmount();
break;
}
return true;
}*/
/*********************************************************************************
FillCategoryArray TCS moved here & rev 7/18/99
fill in category cost info
*********************************************************************************/
void CTransaction::FillCategoryArray(TJobCostCategoryArray &catArray,
const UInt8 breakdownType,
const DBid matchCategory,
const UInt8 /*restrictions*/)
{
// start with the index at the default(last item)
SInt32 index = catArray.GetCount();
// we should have at least one category in the array
TCS_FailNILMsg(index, "Oops, no categories in CTransaction::FillCategoryArray!");
DBid refID = 0;
SJobCostCategoryInfo info;
// fetch the posting location
if (breakdownType == breakdown_location)
GetMemberValue(tag_location, type_long, &refID);
else
GetMemberValue(tag_category, type_long, &refID);
// is this an array of subcategories? TCS 7/30/01
if (matchCategory)
{
if (refID != matchCategory) // not a match
return;
else
GetMemberValue(tag_subcategory, type_long, &refID); // match to subcat instead
}
// find the category or location. Note that
// if we find nothing, index stays at the default(last) value,
// which means it will be included in the final 'unallocated' item
if (refID)
{
TJobCostCategoryArrayIterator iter(catArray);
while (iter.Next(info))
{
if (info.id == refID)
{
index = iter.GetCurrentIndex();
break;
}
}
}
// add info to the selected item
catArray.FetchItemAt(index, info);
if (FillJobCostCatInfo(info, GetJobCostAmount(), GetDBClassID(), GetJobCostClass()))
{
catArray.AssignItemAt(index, info);
}
}
/*********************************************************************************
FillCompareArray TCS 8/6/01
fill in job cost comparison array
*********************************************************************************/
void CTransaction::FillCompareArray(TJobCostCompareArray &compareArray,
const DBid reportID)
{
// start with the index at the default (last item)
SInt32 index = compareArray.GetCount();
// we should have at least one category in the array
TCS_FailNILMsg(index, "Oops, no categories in CTransaction::FillCompareArray!");
DBid refID = 0;
SJobCostCompareInfo info;
// fetch the posting category
if (reportID == id_JobCostLocationReport || reportID == id_JobCostLocationClassReport)
{
GetMemberValue(tag_location, type_long, &refID); // TCS 11/7/01
}
else
{
if (reportID == id_JobCostSubcatReport)
GetMemberValue(tag_subcategory, type_long, &refID);
if (!refID)
GetMemberValue(tag_category, type_long, &refID);
}
if (refID)
{
TJobCostCompareArrayIterator iter(compareArray);
while (iter.Next(info))
{
if (info.id == refID)
{
index = iter.GetCurrentIndex();
break;
}
}
}
// add info to the selected item
compareArray.FetchItemAt(index, info);
if (FillJobCostCompareInfo(info, GetJobCostAmount(), GetDBClassID(), GetJobCostClass(), false))
{
compareArray.AssignItemAt(index, info);
}
}
/*********************************************************************************
FillCatSubcatArray TCS 9/7/02
fill job cost info into a two-level array of cat/subcats
*********************************************************************************/
void CTransaction::FillCatSubcatArray(const DBid /*reportID*/, TTwoLevelArray *twoLevelArray,
const Boolean /*hideSoftCosts*/, CMoney &/*softCostAmount*/,
CMoney &/*hardCostAmount*/) const
{
if (CanBeJobCosted())
{
FillCatSubcatInfo(twoLevelArray, 0, 0);
}
}
/*********************************************************************************
FillCatItemArray TCS 1/25/03
fill job cost info into a two-level array of cat/subcats
*********************************************************************************/
void CTransaction::FillCatItemArray(const DBid /*reportID*/, TReportGroupArray *catArray) const
{
if (CanBeJobCosted())
{
FillCatItemInfo(catArray, 0);
}
}
/*********************************************************************************
FillProgressArray TCS 9/15/99 rev 9/17/99
fill in category cost info
*********************************************************************************/
void CTransaction::FillProgressArray(TJobCostProgressArray &catArray,
const UInt8 breakdownType) const
{
// start with the index at the default(last item)
SInt32 index = catArray.GetCount();
TCS_FailNILMsg(index, TCS_GetErrString(errID_BadArray));
DBid refID = 0;
SJobCostProgressInfo info;
// fetch the posting location
if (breakdownType == breakdown_location)
GetMemberValue(tag_location, type_long, &refID);
else
GetMemberValue(tag_category, type_long, &refID);
// find the category or location. Note that
// if we find nothing, index stays at the default(last) value
if (refID)
{
TJobCostProgressArrayIterator iter(catArray);
while (iter.Next(info))
{
if (info.id == refID)
{
index = iter.GetCurrentIndex();
break;
}
}
}
// add info to the selected item
catArray.FetchItemAt(index, info);
info.costAmount += GetJobCostAmount();
catArray.AssignItemAt(index, info);
}
/*********************************************************************************
FillDataReport TCS 9/5/02
fill in a diagnostic table that shows data field values.
*********************************************************************************/
void CTransaction::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);
// write the custom field count
const SInt32 numCustomFields = mCustomFieldData.GetCount();
FillFieldStockRow(table, stream, stockID_CustomFieldCount, cCharSize, numCustomFields);
// write values of any custom fields
if (numCustomFields > 0)
{
CTextString valueString, fieldName;
CCustomDataHolder *holder = nil;
TCustomDataArrayIterator iterator(mCustomFieldData);
while (iterator.Next(holder))
{
TCS_FailNILMsg(holder, TCS_GetErrString(errID_BadCustomField));
valueString = holder->GetCString();
fieldName = DB_ObjectClassInfo::GetCustomFieldName(GetDBClassID(), iterator.GetCurrentIndex());
fieldName.AppendWithParentheses(TCS_GetStockString(stockID_Custom));
FillFieldStringRow(table, stream, fieldName, valueString);
}
}
FillFieldStringRow(table, stream, tag_comments, mDescription);
FillFieldObjectIDRow(table, stream, tag_mainaccount, mMainAccount, mMainAccountClass);
FillFieldTagRow(table, stream, tag_date, cDateSize, mDate.GetCString());
FillFieldTagRow(table, stream, tag_refnum, cLongSize, mReferenceNum);
FillFieldBitRow(table, stream, "mFlagged", mFlagged, true);
FillFieldBitRow(table, stream, "mUseShortForm", mUseShortForm);
FillFieldBitRow(table, stream, "mUsedAsTemplate", mUsedAsTemplate);
FillFieldBitRow(table, stream, "mUsedAsRecurring", mUsedAsRecurring);
FillFieldBitRow(table, stream, "mIncludeInStarterFile", mIncludeInStarterFile);
FillFieldBitRow(table, stream, "mTransactionBit", mTransactionBit);
FillFieldBitRow(table, stream, "mTransactionBit2", mTransactionBit2);
FillFieldBitRow(table, stream, tag_needsattention, mNeedsAttention);
FillFieldStockRow(table, stream, stockID_Padding, cCharSize, SInt32(mTransCopiedPadding));
FillFieldTableRow(table, stream, "mTransFiller", -4, mTransFiller, true);
FillFieldBitRow(table, stream, "mPrintFlagged", mPrintFlagged);
FillFieldBitRow(table, stream, "mSalesTaxPaid", mSalesTaxPaid);
FillFieldBitRow(table, stream, "mBeenOverpaid", mBeenOverpaid);
FillFieldStockRow(table, stream, stockID_Padding, cBitSize, SInt32(transCalcFiller));
FillFieldStockRow(table, stream, stockID_Padding, cCharSize, SInt32(mTransPadding));
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
PayOnAccount TCS 1/26/00
credit a sum that has been paid on account. We pass it along to the main account.
*********************************************************************************/
void CTransaction::PayOnAccount(const CMoney &inAmount)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
DB_PersistentObject *account = gDBFile->GetOneObject(mMainAccountClass, mMainAccount);
if (account)
{
DB_ObjectWatcher watcher(account);
account->PayOnAccount(inAmount); // TCS removed removeItem param 8/15/01
}
else
ReportMissingObject(mMainAccountClass, mMainAccount, cAlwaysReport); // TCS 6/22/00
}
/*********************************************************************************
UpdateMainAccount TCS 5/17/02 rev, renamed & moved 11/3/02
change the main account for this transaction. This is currently used only
when we convert a prospect to a customer, but it may be useful for other
circumstances
*********************************************************************************/
void CTransaction::UpdateMainAccount(const DBClass classID, const DBid accountID)
{
UInt8 saveSuccess = PrepareViewerDisplay();
mMainAccountClass = classID;
mMainAccount = accountID;
MakeDirty();
DB_ListManager::ChangeMenuStatus(this); // TCS 4/4/04
UpdateViewerDisplay(saveSuccess);
}
/*********************************************************************************
ClearAmounts TCS 7/19/00
clear out the amount fields(after creating a template copy). Note that
we don't assert, since not all transactions have these fields
*********************************************************************************/
void CTransaction::ClearAmounts()
{
CMoney zeroMoney = 0;
SetMemberValue(tag_amount, type_money, &zeroMoney);
SetMemberValue(tag_taxamount, type_money, &zeroMoney);
SetMemberValue(tag_grossprice, type_money, &zeroMoney);
}
/*********************************************************************************
ClearJobCostInfo TCS 7/19/00
clear out the job cost fields(after creating a template copy). Note that
we don't assert, since not all transactions have these fields
*********************************************************************************/
void CTransaction::ClearJobCostInfo()
{
DBid zero = 0;
SetMemberValue(tag_job, type_objectid, &zero);
SetMemberValue(tag_category, type_objectid, &zero);
SetMemberValue(tag_subcategory, type_objectid, &zero);
SetMemberValue(tag_location, type_objectid, &zero);
}
|