Link to: header | lists directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CSalesBranch
This class manages sales branches for the Goldenseal accounting software,
retail sales software, project management software
and business management software.
a sales branch is used to assign locations from which sales
are made. Sales tax rates & cash deposit accounts are based on sales branches.
This class can also be used to classify sales in a general way (e.g. we
use it to indentify demos, program sales, training, etc).
SUPERCLASS = DB_DescribedPersistent
Constructor
/*********************************************************************************
default constructor
*********************************************************************************/
CSalesBranch::CSalesBranch()
{
mCatSystem = CCategorySystem::GetCurrentCatSystem();
mCashAccount = mInventoryAccount = 0;
mTaxRate = mCommission = 0;
mOverheadAccount = 0;
mUndepositedFundsAccount = account_UndepositedCashSales;
mExpansionID = 0; // TCS 9/16/02
mExpansionMoney = 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 CSalesBranch::CopyFrom(DB_PersistentObject *source, const UInt8 copyFlags)
{
THE_SUPERCLASS::CopyFrom(source, copyFlags);
CSalesBranch *src = TCS_SAFE_CAST(source, CSalesBranch);
TCS_FailNILMsg(src, TCS_GetErrString(errID_BadRecord));
TCS_BlockMove(&src->mCatSystem, &mCatSystem, cCopyFileLength);
}/*********************************************************************************
GetFileLength
return the file length used by this object
*********************************************************************************/
NeoSize CSalesBranch::GetFileLength(const CNeoFormat *aFormat) const
{
return THE_SUPERCLASS::GetFileLength(aFormat) +
ARRAY_FILE_SIZE(mUndepositedSaleArray) +
cFileLength;
}/*********************************************************************************
GetMemberValue
return the value of the member with the given tag
*********************************************************************************/
Boolean CSalesBranch::GetMemberValue(const NeoTag aTag, const NeoTag aType,
void *aValue) const
{
switch (aTag)
{
case tag_catsystem:
return ConvertObjectIDMember(mCatSystem, id_CategorySystem,
aValue, aType);
break;
case tag_cashaccount:
return ConvertObjectIDMember(mCashAccount, id_CashAccount, aValue, aType);
break;
case tag_inventoryaccount:
return ConvertObjectIDMember(mInventoryAccount, id_InventoryAccount,
aValue, aType);
break;
case tag_taxrate:
return ConvertObjectIDMember(mTaxRate, id_JobSalesTax, aValue, aType);
break;
case tag_commission:
return ConvertObjectIDMember(mCommission, id_Commission, aValue, aType);
break;
case tag_overheadaccount:
return ConvertObjectIDMember(mOverheadAccount, id_OverheadAccount,
aValue, aType);
break;
case tag_undepositedfundsaccount:
return ConvertObjectIDMember(mUndepositedFundsAccount, id_UtilityAccount,
aValue, aType);
break;
default:
return THE_SUPERCLASS::GetMemberValue(aTag, aType, aValue);
break;
}
}/*********************************************************************************
SetMemberValue
set the value of the member with the given tag
*********************************************************************************/
Boolean CSalesBranch::SetMemberValue(const NeoTag aTag, const NeoTag aType,
const void *aValue)
{
switch (aTag)
{
case tag_catsystem:
return ConvertDataToObjectID(aValue, aType,
&mCatSystem, id_CategorySystem);
break;
case tag_cashaccount:
return ConvertDataToObjectID(aValue, aType,
&mCashAccount, id_CashAccount);
break;
case tag_inventoryaccount:
return ConvertDataToObjectID(aValue, aType,
&mInventoryAccount, id_InventoryAccount);
break;
case tag_taxrate:
return ConvertDataToObjectID(aValue, aType, &mTaxRate, id_JobSalesTax);
break;
case tag_commission:
return ConvertDataToObjectID(aValue, aType, &mCommission, id_Commission);
break;
case tag_overheadaccount:
return ConvertDataToObjectID(aValue, aType, &mOverheadAccount,
id_OverheadAccount);
break;
case tag_undepositedfundsaccount: // currently does not support multiple choices.
return true; // the member is here so we can in the future
// return ConvertDataToObjectID(aValue, aType, &mUndepositedFundsAccount, id_UtilityAccount);
break;
default:
return THE_SUPERCLASS::SetMemberValue(aTag, aType, aValue);
break;
}
}/*********************************************************************************
ReadObject
read the persistent object's data in from a stream
*********************************************************************************/
void CSalesBranch::ReadObject(CNeoStream *aStream, const NeoTag 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;
ReadIDArrayFromStream(aStream, mUndepositedSaleArray, cHasSafetyTag);
/// aStream->ReadChunk(&mCatSystem, cFileLength);
mCatSystem = aStream->ReadID(); // mfs_sa rev 20feb2k3
mCashAccount = aStream->ReadID();
mTaxRate = aStream->ReadID();
mInventoryAccount = aStream->ReadID();
mOverheadAccount = aStream->ReadID();
mCommission = aStream->ReadID();
mUndepositedFundsAccount = aStream->ReadID();
mExpansionID = aStream->ReadID();
mExpansionMoney.ReadFromStream(aStream);
mEndSafetyTag = aStream->ReadEndSafetyTag(this);
if (!IsValidEndTag(mEndSafetyTag)) // TCS 9/8/02
ReportDamagedObject(GetDBClassID(), GetDBID());
}/*********************************************************************************
WriteObject
write the persistent object's data to a stream
*********************************************************************************/
void CSalesBranch::WriteObject(CNeoStream *aStream, const NeoTag 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);
WriteIDArrayToStream(aStream, mUndepositedSaleArray, cHasSafetyTag);
/// aStream->WriteChunk(&mCatSystem, cFileLength);
aStream->WriteID(mCatSystem); // mfs_sa rev 20feb2k3
aStream->WriteID(mCashAccount);
aStream->WriteID(mTaxRate);
aStream->WriteID(mInventoryAccount);
aStream->WriteID(mOverheadAccount);
aStream->WriteID(mCommission);
aStream->WriteID(mUndepositedFundsAccount);
aStream->WriteID(mExpansionID);
mExpansionMoney.WriteToStream(aStream);
aStream->WriteEndSafetyTag(mEndSafetyTag, this);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
PostNewRecord TCS 11/22/03
post info for a new record
*********************************************************************************/
void CSalesBranch::PostNewRecord(const UInt8 creationType)
{
PostUseCount(id_CategorySystem, mCatSystem);
PostUseCount(id_CashAccount, mCashAccount);
PostUseCount(id_JobSalesTax, mTaxRate);
PostUseCount(id_InventoryAccount, mInventoryAccount);
PostUseCount(id_OverheadAccount, mOverheadAccount);
PostUseCount(id_Commission, mCommission);
PostUseCount(id_UtilityAccount, mUndepositedFundsAccount);
// let the superclass do any posting
THE_SUPERCLASS::PostNewRecord(creationType);
}
/*********************************************************************************
PostDeletion TCS 11/22/03
post info from a deleted record
*********************************************************************************/
void CSalesBranch::PostDeletion(const Boolean postAudit)
{
PostUseCount(id_CategorySystem, mCatSystem, cRemoveItem);
PostUseCount(id_CashAccount, mCashAccount, cRemoveItem);
PostUseCount(id_JobSalesTax, mTaxRate, cRemoveItem);
PostUseCount(id_InventoryAccount, mInventoryAccount, cRemoveItem);
PostUseCount(id_OverheadAccount, mOverheadAccount, cRemoveItem);
PostUseCount(id_Commission, mCommission, cRemoveItem);
PostUseCount(id_UtilityAccount, mUndepositedFundsAccount, cRemoveItem);
// let the superclass do any posting
THE_SUPERCLASS::PostDeletion(postAudit);
}
/*********************************************************************************
PostRecordChanging TCS 11/22/03
a record will be changing. Post the change.
*********************************************************************************/
void CSalesBranch::PostRecordChanging(const Boolean accountChanging, const Boolean jobChanging)
{
PostUseCount(id_CategorySystem, mCatSystem, cRemoveItem);
PostUseCount(id_CashAccount, mCashAccount, cRemoveItem);
PostUseCount(id_JobSalesTax, mTaxRate, cRemoveItem);
PostUseCount(id_InventoryAccount, mInventoryAccount, cRemoveItem);
PostUseCount(id_OverheadAccount, mOverheadAccount, cRemoveItem);
PostUseCount(id_Commission, mCommission, cRemoveItem);
PostUseCount(id_UtilityAccount, mUndepositedFundsAccount, cRemoveItem);
// let the superclass do any posting
THE_SUPERCLASS::PostRecordChanging(accountChanging, jobChanging);
}
/*********************************************************************************
PostRecordChanged TCS 11/22/03
a record has changed. Post it.
*********************************************************************************/
void CSalesBranch::PostRecordChanged(const CMoney &oldAmount, const Boolean accountChanged,
const Boolean jobChanged)
{
PostUseCount(id_CategorySystem, mCatSystem);
PostUseCount(id_CashAccount, mCashAccount);
PostUseCount(id_JobSalesTax, mTaxRate);
PostUseCount(id_InventoryAccount, mInventoryAccount);
PostUseCount(id_OverheadAccount, mOverheadAccount);
PostUseCount(id_Commission, mCommission);
PostUseCount(id_UtilityAccount, mUndepositedFundsAccount);
// let the superclass do any posting
THE_SUPERCLASS::PostRecordChanged(oldAmount, accountChanged, jobChanged);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
FillDepositInfo TCS 1/5/99
fill in information about deposits of cash sales coming from this sales branch.
Note that the deposit of billed sales is handled by CCustomerAccount::FillDepositInfo
*********************************************************************************/
Boolean CSalesBranch::FillDepositInfo(SDepositInfo &depositInfo)
{
depositInfo.accountID = GetDBID();
depositInfo.accountClassID = id_SalesBranch;
depositInfo.transactionClassID = id_Sale;
TCS_BufferFromText(depositInfo.itemName, GetName());
FillDepositsFromArray(mUndepositedSaleArray, depositInfo);
// we always return true since we want all sales branches listed,
// even if there are no sales
return true;
}
/*********************************************************************************
InitializeDepositInfo (static) TCS 1/7/99
set up a deposit info struct. Note that this creates an array on the heap,
which callers must delete when the depositInfo struct is no longer needed.
*********************************************************************************/
void CSalesBranch::InitializeDepositInfo(SDepositInfo &depositInfo)
{
depositInfo.dueAmount = 0;
depositInfo.cashAmount = 0;
depositInfo.checkAmount = 0;
depositInfo.creditCardAmount = 0;
depositInfo.otherAmount = 0;
depositInfo.creditAmount = 0; // TCS 9/13/01
depositInfo.adjustAmount = 0; // TCS 10/31/01
depositInfo.paidAmount = 0;
depositInfo.deposit = true;
depositInfo.paymentMethod = 0; // 11/17/99
depositInfo.itemArray = NEW TDepositItemArray;
}
/*********************************************************************************
InitializeDepositItemInfo (static) TCS 11/13/02
set up a deposit item info struct
*********************************************************************************/
void CSalesBranch::InitializeDepositItemInfo(SDepositItem &itemInfo,
const UInt8 transClass)
{
itemInfo.transactionID = 0;
itemInfo.accountID = 0;
itemInfo.accountClassID = 0;
itemInfo.transactionClassID = transClass;
itemInfo.dueAmount = 0;
itemInfo.adjustAmount = 0;
itemInfo.paidAmount = 0;
itemInfo.paymentMethod = 0;
itemInfo.deposit = true;
itemInfo.modify = false;
}
/*********************************************************************************
FillDepositsFromArray (static) TCS 1/5/99
fill in information about deposits from an array of cash sales.
This is a static method, so it can be used by outside objects (e.g. for items
with no sales branch).
*********************************************************************************/
Boolean CSalesBranch::FillDepositsFromArray(const TObjectIDArray &array,
SDepositInfo &depositInfo)
{
Boolean success = false;
// initialize the depositInfo struct
// note that this creates a new array which should be deleted
// as soon as the struct is no longer needed.
InitializeDepositInfo(depositInfo);
// sanity check
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
TCS_FailNILMsg(depositInfo.itemArray, TCS_GetErrString(errID_BadArray));
// do we have any items to deposit?
if (array.GetCount() > 0)
{
// set up an item struct
SDepositItem item;
item.deposit = true;
item.transactionClassID = id_Sale;
item.accountClassID = id_CustomerAccount;
item.adjustAmount = 0; // TCS 10/31/01
// basic prep
CSale *sale = nil;
DBid saleID;
UInt8 status, paymentType;
// prepare to iterate thru array items
TObjectIDArrayIterator iterator(array);
while (iterator.Next(saleID))
{
sale = TCS_SAFE_CAST(gDBFile->GetOneObject(id_Sale, saleID), CSale);
if (sale)
{
DB_ObjectWatcher watcher(sale);
// do we have a valid status?
status = sale->GetStatus();
if (status == status_Sold && sale->IsPrepaid())
{
item.dueAmount = sale->GetAmount(); // prepaid sales so use basic amt
if (item.dueAmount.IsZero())
break;
// everything is valid, so fill in an item
item.paidAmount = item.dueAmount; // we'll probably deposit it now
item.paymentMethod = sale->GetPaymentMethod();
paymentType = CPaymentMethod::GetPaymentType(item.paymentMethod);
item.transactionID = saleID;
item.accountID = sale->GetMainAccountID(); // TCS 9/17/01
depositInfo.dueAmount += item.dueAmount;
if (item.dueAmount.IsNegative()) // TCS 9/13/01 bugfix 10/22/01
{
depositInfo.creditAmount += item.paidAmount;
}
else switch (paymentType) // TCS rev 10/12/99
{
case method_cash:
depositInfo.cashAmount += item.paidAmount;
break;
case method_check:
depositInfo.checkAmount += item.paidAmount;
break;
case method_creditcard:
depositInfo.creditCardAmount += item.paidAmount;
break;
default:
depositInfo.otherAmount += item.paidAmount;
break;
}
depositInfo.paidAmount += item.paidAmount;
depositInfo.itemArray->Append(item);
success = true;
}
}
}
}
return success;
}
/*********************************************************************************
FillDataReport TCS 9/6/02
fill in a diagnostic table that shows data field values.
*********************************************************************************/
void CSalesBranch::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, "mUndepositedSaleArray", mUndepositedSaleArray);
FillFieldObjectIDRow(table, stream, tag_catsystem, mCatSystem, id_CategorySystem);
FillFieldObjectIDRow(table, stream, tag_cashaccount, mCashAccount, id_CashAccount);
FillFieldObjectIDRow(table, stream, tag_taxrate, mTaxRate, id_JobSalesTax);
FillFieldObjectIDRow(table, stream, tag_inventoryaccount, mInventoryAccount, id_InventoryAccount);
FillFieldObjectIDRow(table, stream, tag_overheadaccount, mOverheadAccount, id_OverheadAccount);
FillFieldObjectIDRow(table, stream, tag_commission, mCommission, id_Commission);
FillFieldObjectIDRow(table, stream, tag_undepositedfundsaccount, mUndepositedFundsAccount, id_UtilityAccount);
FillFieldStockRow(table, stream, stockID_Expansion, cMoneySize, mExpansionMoney.GetCurrencyString());
FillFieldStockRow(table, stream, stockID_Expansion, cLongSize, mExpansionID);
FillEndSafetyTag(table, stream, mEndSafetyTag);
}
|