Link to: header |
source 1 | source 2 | transactions
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Source Code
This class manages expense transactions for the Goldenseal accounting software,
small business management software, construction
project management software and
construction
accounting software.
/*********************************************************************************
HandlePaymentMade TCS 4/10/00
deal with a payment that has been made for this item. We override, since
we may need to update this item's presence in the account's array of unpaid items
*********************************************************************************/
void CExpenseTransaction::HandlePaymentMade(const CMoney &inAmount, const UInt8 sourceClass,
const DBid sourceID, const UInt8 transactionType, const Boolean removeItem)
{
TCS_ASSERTMsg(IS_TURTLE_CLASS_ID(mMainAccountClass), TCS_GetErrString(errID_BadClass));
TCS_ASSERTMsg(IS_TURTLE_CLASS_ID(sourceClass), TCS_GetErrString(errID_BadClass));
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
CMoney prevPaidAmount = GetAmountPaid(); // moved TCS 4/27/01
// the superclass handles most posting details- status, amount paid etc
THE_SUPERCLASS::HandlePaymentMade(inAmount, sourceClass, sourceID, transactionType, removeItem);
// update the account's unpaid item array
// TCS moved this here from CLaborLog 4/10/00
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
CMoney netAmount;
if (prevPaidAmount.IsZero() && mAdjustmentAmount.IsNegative()) // TCS rev 1/23/01
{ // first payment minus a discount, so post the full amount
netAmount = inAmount - mAdjustmentAmount;
}
else if (mAdjustmentAmount.IsNegative() && removeItem) // TCS 4/27/01
{ // cancelling a discounted payment
netAmount = inAmount + mAdjustmentAmount;
}
else
{ // second part payment or no discount, so post the actual payment amount
netAmount = inAmount;
}
DBid paymentTerms = 0;
// pass the payment along to the main account
DB_Account *account =
TCS_SAFE_CAST(gDBFile->GetOneObject(mMainAccountClass, mMainAccount), DB_Account);
if (account)
{
DB_ObjectWatcher watcher(account);
// adjust the account balance. Note that if removing, TCS rev 10/9/02
// net amount is already negative, so we don't need to branch here.
account->AdjustBalance(-netAmount);
// adjust the array
if (removeItem || !HasBeenPaid()) // TCS 9/2/99
account->AddToUnpaidCostArray(GetDBID());
else
account->AddToUnpaidCostArray(GetDBID(), cRemoveItem);
// fetch the payment terms (we will use this for later actions)
paymentTerms = account->GetPaymentTerm();
}
// we used to pass it along to any 'apply to' transactions TCS 10/27/00
// but that caused problems. They probably don't need to know about
// payments, so TCS removed this TCS rev 11/21/01
// if coming from an employee reimbursement, we need
// to change the payment method and terms TCS 1/3/01
if (sourceClass == id_PayrollRecord)
{
UInt8 saveSuccess = PrepareViewerDisplay();
if (removeItem) // cancelling payment, so revert to billed
{
SetPaymentMethod(method_billed);
SetPaymentTerm(paymentTerms);
}
else
{
DB_PersistentObject *source = gDBFile->GetOneObject(id_PayrollRecord, sourceID);
DBid employeeID = 0;
if (source)
{
DB_ObjectWatcher sourceWatcher(source);
employeeID = source->GetMainAccountID();
}
else
ReportMissingObject(id_PayrollRecord, sourceID);
SetPaymentMethod(method_emplpurchase);
SetPaymentTerm(employeeID);
}
UpdateViewerDisplay(saveSuccess);
}
// we've changed
MakeDirty();
}
/*********************************************************************************
HandlePaymentReceived TCS 11/22/00
we override, since this is a credit/refund payment, which is very different
from the usual income payment.
*********************************************************************************/
void CExpenseTransaction::HandlePaymentReceived(const CMoney &inAmount, const UInt8 sourceClass,
const DBid sourceID, const UInt8 transactionType,
const Boolean removeItem, const Boolean fromDeposit,
const Boolean /*fromBillRecord*/)
{
// we should never receive payment if void TCS 12/7/99
if (HasVoidStatus())
{
TCS_DebugAlert("Oops, invalid void payment in CExpenseTransaction:: HandlePaymentReceived!");
return;
}
// update payment amount
CMoney prevPaidAmount = GetAmountPaid();
CMoney amountPaid = prevPaidAmount - inAmount;
SetAmountPaid(amountPaid);
CMoney adjustedAmount = GetAdjustedAmount();
Boolean fullyPaid;
UInt8 saveSuccess = save_notvisible;
// are we changing an 'on account' balance? TCS 5/28/00
if (WasOverpaid() && PaysOnAccount())
{
CMoney prevExcess = adjustedAmount - prevPaidAmount;
CMoney changeAmount = TCS_MAX(inAmount, prevExcess);
changeAmount.ReverseSign();
PayOnAccount(changeAmount);
}
// if we are currently in a viewer, prepare to update it TCS 8/22/00
if (!fromDeposit)
saveSuccess = PrepareViewerDisplay();
if (!AcceptsPartialPayment()) // some classes are simply paid, or not TCS 5/29/00
{
if (removeItem)
{
SetPaidStatus(status_Unpaid);
fullyPaid = false;
}
else
{
SetPaidStatus(status_Paid);
fullyPaid = true;
}
SetBeenOverpaid(false);
}
else if (amountPaid < adjustedAmount) // OVERREFUND, so reduce 'on account' amount
{
// set payment details
fullyPaid = true;
// update the status
SetPaidStatus(status_Overpaid);
// if not already overpaid, post the excess on account rev TCS 5/29/00
if (!WasOverpaid())
{
CMoney excess = adjustedAmount - amountPaid;
excess.ReverseSign();
PayOnAccount(excess);
}
// now we are definitely overpaid
SetBeenOverpaid(true);
}
else if (amountPaid == adjustedAmount) // EXACT PAYMENT
{
fullyPaid = true;
SetBeenOverpaid(false);
SetPaidStatus(status_Paid);
}
else if (amountPaid.IsPositive()) // PARTIAL PAYMENT
{
fullyPaid = false;
SetBeenOverpaid(false);
SetPaidStatus(status_PartPaid);
}
else // NOT PAID AT ALL
{
fullyPaid = false;
SetBeenOverpaid(false);
// update the status
SetPaidStatus(status_Unpaid);
}
// mark the flag bit
SetPaidInFull(fullyPaid);
// now pass it along to all the breakdown entries TCS 3/22/00 rev 6/6/00
MarkBreakdownsPaid(mBreakdownArray, mBreakdownClassID, fullyPaid, inAmount, sourceClass,
sourceID, transactionType, removeItem, cPaymentReceived);
// we've changed
MakeDirty();
// update the payment transaction array TCS 6/6/00
AddToObjectInfoArray(mPaymentArray, sourceClass, sourceID, transactionType, removeItem, true);
// if we are currently in a viewer, need to update it TCS 3/21/00
UpdateViewerDisplay(saveSuccess);
// no need to pass it along from here
}
/*********************************************************************************
HandleDeposit TCS 12/6/00
we'll receive this for refunds that are deposited, but we don't need to do anything
*********************************************************************************/
void CExpenseTransaction::HandleDeposit(const CMoney &/*inAmount*/, const UInt8 /*sourceClass*/,
const DBid /*sourceID*/, const Boolean /*removeItem*/,
const Boolean /*fromBillRecord*/)
{
}
/*********************************************************************************
HandleTandMBilling TCS 7/21/99 rev TCS 5/5/00
deal with a t&m billing event. Subclasses may override if other things must be done.
*********************************************************************************/
void CExpenseTransaction::HandleTandMBilling(const DBid /*billID*/, const Boolean removeItem)
{
UInt8 saveType = PrepareViewerDisplay(); // TCS 8/22/00
if (removeItem)
{
SetBeenTandMBilled(false);
if (HasBeenPaid())
SetStatus(status_Paid);
else if (HasBeenPartPaid())
SetStatus(status_PartPaid);
else
SetStatus(status_Entered);
}
else
{
SetBeenTandMBilled(true);
if (HasBeenPaid())
SetStatus(status_BilledAndPaid);
else
SetStatus(status_TandMBilled);
}
// if there are cost breakdowns, set their billed status TCS 4/25/00
if (mBreakdownArray.GetCount() > 0)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
TObjectIDArrayIterator iterator(mBreakdownArray);
DBid breakdownID;
DBClass breakdownClass = GetBreakdownClassID();
CBreakdownEntry *breakdown = nil;
while (iterator.Next(breakdownID))
{
breakdown = TCS_SAFE_CAST(gDBFile->GetOneObject(breakdownClass, breakdownID),
CBreakdownEntry);
if (breakdown)
{
DB_ObjectWatcher watcher(breakdown);
breakdown->SetBeenTandMBilled(!removeItem);
breakdown->MakeDirty();
}
}
}
// update the display TCS 3/21/00 rev TCS 10/23/00
UpdateViewerDisplay(saveType);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
SetPaidInFull TCS 10/16/00
mark a payment.
*********************************************************************************/
void CExpenseTransaction::SetPaidInFull(const Boolean isPaid)
{
THE_SUPERCLASS::SetPaidInFull(isPaid);
// update the menu list
DB_ListManager::ChangeInMenus(this); // bugfix TCS 11/10/00(shouldn't delete from menu)
// update the payables account TCS 12/12/00
// note that labor expenses are NOT posted here, since they use
// two different utility accounts to track payables.
DBid payableAccountID = GetPayablesAccount();
if (payableAccountID) // TCS rev 4/30/01
CUtilityAccount::AddToActiveArray(payableAccountID, this, !isPaid);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
AdjustMainAccount rev TCS 8/12/99
post to the main account
*********************************************************************************/
void CExpenseTransaction::AdjustMainAccount(const CMoney &changeAmount,
const Boolean removeFromArray,
const Boolean jobCostOnly)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
DB_Account *account = nil;
if (mMainAccount)
{
account = TCS_SAFE_CAST(gDBFile->
GetOneObject(mMainAccountClass, mMainAccount), DB_Account);
}
if (account)
{
DB_ObjectWatcher watcher(account);
UInt8 saveType = account->PrepareViewerDisplay(); // TCS 5/17/04
// if a newly created account, add the transaction to the new account's array.
// we used to do this only by param, but we now adjust at any change TCS 10/25/00
account->AddToCostArray(GetDBID(), removeFromArray);
if (account->HasPayables() && !jobCostOnly) // TCS rev 12/28/01 rev 5/17/04
{
if (!HasBeenPaid() || removeFromArray)
account->AddToUnpaidCostArray(GetDBID(), removeFromArray);
// we always adjust the balance owed by the account. We do this after
// the array update, so payables total will display correctly TCS 4/27/01
account->AdjustBalance(changeAmount);
}
account->UpdateViewerDisplay(saveType);
}
}
/*********************************************************************************
AdjustJobCosts rev TCS 8/12/99
post job costs to a job. The default is to add the transaction to the array.
Set addToArray to FALSE if it doesn't need to be added. Set addToArray to TRUE
and removeFromArray to TRUE to remove the transaction from the array.
*********************************************************************************/
void CExpenseTransaction::AdjustJobCosts(const CMoney &changeAmount,
const Boolean adjustArrays, const Boolean removeFromArray)
{
// sanity check
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
// fetch the job
DB_Account *job = nil;
if (mJob && mJobClass)
{
job = TCS_SAFE_CAST(gDBFile->GetOneObject(mJobClass, mJob), DB_Account);
}
// if no listed job account, use the first overhead account
if (!job)
{
job = TCS_SAFE_CAST(gDBFile->GetFirstObject(id_OverheadAccount), DB_Account);
}
// we'd better have a job account by now
TCS_FailNILMsg(job, TCS_GetErrString(errID_BadAccount));
DB_ObjectWatcher watcher(job);
switch (GetDBClassID())
{
case id_LaborHours:
job->AddLaborCost(changeAmount);
if (adjustArrays)
{
job->AddToLaborHoursArray(GetDBID(), removeFromArray);
if (GetStatus() != status_JobCostOnly) // bugfix TCS 4/16/01
job->AddToUnbilledLaborArray(GetDBID(), removeFromArray);
}
break;
case id_EquipmentHours:
job->AddEquipmentCost(changeAmount);
if (adjustArrays)
{
job->AddToEquipmentLogArray(GetDBID(), removeFromArray);
if (GetStatus() != status_JobCostOnly) // bugfix TCS 4/16/01
job->AddToUnbilledEquipmentArray(GetDBID(), removeFromArray);
}
break;
case id_SubcontractorLog:
job->AddSubcontractorCost(changeAmount);
if (adjustArrays)
{
job->AddToSubcontractorLogArray(GetDBID(), removeFromArray);
if (GetStatus() != status_JobCostOnly) // bugfix TCS 4/16/01
job->AddToUnbilledSubcontractorArray(GetDBID(), removeFromArray);
}
break;
case id_MaterialPurchase:
job->AddMaterialCost(changeAmount);
if (adjustArrays)
{
job->AddToMaterialArray(GetDBID(), removeFromArray);
if (GetStatus() != status_JobCostOnly) // bugfix TCS 4/16/01
job->AddToUnbilledPurchaseArray(GetDBID(), removeFromArray);
}
break;
case id_OtherCost:
job->AddOtherCost(changeAmount);
if (adjustArrays)
{
job->AddToOtherCostArray(GetDBID(), removeFromArray);
if (GetStatus() != status_JobCostOnly) // bugfix TCS 4/16/01
job->AddToUnbilledOtherCostArray(GetDBID(), removeFromArray);
}
break;
case id_InventoryUsed: // TCS 10/30/01
job->AddMaterialCost(changeAmount);
if (adjustArrays)
{
job->AddToInventoryArray(GetDBID(), removeFromArray);
// we don't store unbilled inventory use in an array, due to its late addition.
}
break;
default:
TCS_DebugAlert("Oops, bad case in AdjustJobCosts!");
break;
}
// post change order or allowance if applicable TCS 12/20/98
// note-- this is obsolete, since allowance and CO cost allocate is not
// handled thru categories anymore TCS 1/18/00
/*if (job->GetDBClassID() == id_ProjectAccount && adjustArrays)
{
if (mCat == category_Allowance)
job->AddAllowanceCost(mSubcat, GetDBClassID(), GetDBID(), mAmount, removeFromArray);
else if (mCat == category_ChangeOrder)
job->AddChangeOrderCost(mSubcat, GetDBClassID(), GetDBID(), mAmount, removeFromArray);
}*/
// mark the job as dirty so changes are saved
job->MakeDirty(); // TCS 12/7/99
}
/*********************************************************************************
PostExpenseAccount TCS 9/5/99 rev TCS 6/26/00
post this transaction to a general ledger expense account
*********************************************************************************/
void CExpenseTransaction::PostExpenseAccount(const Boolean removeItem)
{
DBid expenseAccountID = GetExpenseAccount();
// validate the expense account and reset it if not valid
if (!CUtilityAccount::IsValidAccount(expenseAccountID, virtual_accruedexpense))
{
expenseAccountID = GetDefaultExpenseAccount();
SetExpenseAccount(expenseAccountID);
MakeDirty();
}
// post to it. We only store a permanent array. rev TCS 4/3/01
CUtilityAccount::AddToPermanentArray(expenseAccountID, this, removeItem);
// also post to the payables account rev TCS 4/25/01
PostPayablesAccount(removeItem);
// if a prepaid expense, post to the prepaid account TCS 8/17/01
UInt8 conditions = GetConditions();
if (conditions == condition_PrepaidMonth || conditions == condition_PrepaidQuarter ||
conditions == condition_PrepaidHalfYear || conditions == condition_PrepaidYear)
{
CUtilityAccount::AddToPermanentArray(account_PrepaidExpenses, this, removeItem);
}
}
/*********************************************************************************
PostPayablesAccount TCS moved 4/25/01
post this transaction to a payables utility account. Note that labor and
equipment logs override this.
*********************************************************************************/
void CExpenseTransaction::PostPayablesAccount(const Boolean removeItem)
{
if (IsVendorInvoiced())
{
DBid payableAccountID = GetPayablesAccount();
if (payableAccountID) // rev TCS 4/30/01
CUtilityAccount::AddToActiveArray(payableAccountID, this, removeItem);
}
}
/*********************************************************************************
AdjustExpenseTransaction TCS 1/18/00
post to any transactions in the Apply To section
*********************************************************************************/
void CExpenseTransaction::AdjustExpenseTransaction(const Boolean removeItem)
{
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
DBClass conditions = GetConditions();
if (DB_ClassDescriptor::IsTransaction(conditions)) // rev TCS 9/29/02
{
CTransaction *transaction =
TCS_SAFE_CAST(gDBFile->GetOneObject(conditions, mTransactionRef),
CTransaction);
if (transaction)
{
DB_ObjectWatcher watcher(transaction);
if (conditions == id_ChangeOrder || conditions == id_Allowance) // rev TCS 5/30/00
transaction->HandleExpenseTrans(GetTandMAmount(false, false), GetSalesTaxAmount(),
GetDBClassID(), GetDBID(), removeItem);
else // rev TCS 10/31/00
transaction->HandleExpenseTrans(GetGrossAmount(), GetSalesTaxAmount(),
GetDBClassID(), GetDBID(), removeItem);
}
}
}
/*********************************************************************************
FillPurchaseInfo TCS moved 3/13/02
fill in payables information, and return whether this item is billable.
This is called from Pay Bills, and also from viewer when breakdown changes.
Moved here from CCostAccount::FillPurchaseInfo so it's easier to have other
transactions fill in data.
*********************************************************************************/
Boolean CExpenseTransaction::FillPurchaseInfo(SVendorInfo &vendorInfo, const CDate cutoffDate,
const DBClass /*accountClass*/, const DBid /*accountID*/)
{
if (!ShouldBePaid())
return false;
CDate billingDate, discountDate, dueDate;
GetAllDueDates(&billingDate, &discountDate, &dueDate);
SPurchaseInfo purchaseInfo;
CCostAccount::FillDefaultPurchaseInfo(purchaseInfo);
purchaseInfo.id = GetDBID();
purchaseInfo.classID = GetDBClassID();
// fill in values depending on current billing status
if (cutoffDate.IsAfter(dueDate, false, false)) // it's overdue
{
purchaseInfo.overdueAmount = GetAmount() - GetAmountPaid(); // rev TCS 10/9/02
purchaseInfo.currentAmount = 0;
purchaseInfo.pendingAmount = 0;
}
else if (cutoffDate.IsAfter(billingDate)) // it's currently due
{
purchaseInfo.overdueAmount = 0;
purchaseInfo.currentAmount = GetAmount() - GetAmountPaid();
purchaseInfo.pendingAmount = 0;
}
else // it's not yet due
{
purchaseInfo.overdueAmount = 0;
purchaseInfo.currentAmount = 0;
purchaseInfo.pendingAmount = GetAmount() - GetAmountPaid();
}
// calculate discount or penalty TCS 3/8/99
purchaseInfo.adjustAmount = FetchDiscountOrPenalty(cutoffDate);
purchaseInfo.withholdAmount = GetWithholdingDeduction(); // TCS 10/4/02 rev 9/16/03
purchaseInfo.retainageAmount = GetRetainageAmount(); // TCS 10/9/02
// set up paying status
purchaseInfo.payingAmount = purchaseInfo.currentAmount +
purchaseInfo.overdueAmount;
purchaseInfo.pay = (purchaseInfo.payingAmount.IsNonZero()); // rev TCS 12/6/00
// adjust the vendor info
vendorInfo.pendingAmount += purchaseInfo.pendingAmount;
vendorInfo.currentAmount += purchaseInfo.currentAmount;
vendorInfo.overdueAmount += purchaseInfo.overdueAmount;
// if we're paying this item now, add it to the vendor due totals
if (purchaseInfo.pay)
{ // we only add adjustment if paying now
purchaseInfo.payingAmount += purchaseInfo.adjustAmount;
purchaseInfo.payingAmount -= purchaseInfo.withholdAmount; // TCS 10/5/02
purchaseInfo.payingAmount -= purchaseInfo.retainageAmount; // TCS 10/9/02
// also update the vendor info // moved TCS 10/5/02
vendorInfo.adjustAmount += purchaseInfo.adjustAmount;
vendorInfo.withholdAmount += purchaseInfo.withholdAmount; // TCS 10/5/02
vendorInfo.retainageAmount += purchaseInfo.retainageAmount; // TCS 10/9/02
vendorInfo.payingAmount += purchaseInfo.payingAmount;
}
// if the due date is older, adjust the vendor's due date
if (dueDate < vendorInfo.dueDate)
{
vendorInfo.dueDate = dueDate;
}
// add the current invoice info to the vendor array
vendorInfo.purchaseArray->Append(purchaseInfo);
return true;
}
/*********************************************************************************
FillDataReport TCS 9/5/02
fill in a diagnostic table that shows data field values.
*********************************************************************************/
void CExpenseTransaction::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);
FillFieldObjectIDRow(table, stream, tag_expenseaccount, mExpenseAccount, id_UtilityAccount);
FillFieldObjectIDRow(table, stream, tag_transactionref, mTransactionRef, GetConditions());
FillFieldTagRow(table, stream, tag_amountbilled, cMoneySize, mAmountBilled.GetCurrencyString());
FillFieldTagRow(table, stream, tag_amountpaid, cMoneySize, mAmountPaid.GetCurrencyString());
FillFieldTagRow(table, stream, tag_adjustment, cMoneySize, mAdjustmentAmount.GetCurrencyString());
FillFieldStockRow(table, stream, stockID_Expansion, cLongSize, SInt32(mExpenseExpansion));
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************
CreateOffsetTransaction TCS 10/17/99 rev TCS 6/10/00 rev TCS 11/10/00
create a bank transaction to offset a pre-paid expense transaction. Note that
this is called only by some subclasses(CPurchase and CSubcontractorLog).
*********************************************************************************/
void CExpenseTransaction::CreateOffsetTransaction()
{
UInt8 paymentMethod = GetPaymentMethod();
DBid paymentDetails = GetPaymentDetails();
// we used to call UpdateOffsetTransaction here, but that caused infinite loops!
// so TCS removed it 6/14/00.
if (paymentDetails && WasJustImported())
{
// importing, so we'll trust that the offset transact will arrive later
}
else if (paymentMethod == method_emplpurchase) // TCS 11/10/00
{
CreateEmployeeReimburse(paymentDetails);
}
else if (paymentMethod == method_barter) // TCS 11/10/00
{
CreateBarterOffset(paymentDetails);
}
else
{
CreateInstantPayment(paymentMethod, paymentDetails);
}
}
/*********************************************************************************
CreateInstantPayment TCS moved 11/10/00
create a bank transaction to pay for this item right now
*********************************************************************************/
void CExpenseTransaction::CreateInstantPayment(const UInt8 paymentMethod, const DBid paymentDetails)
{
// no compensating transaction, so let's create a bank payment
UInt8 bankAccountClass = GetPaymentDetailsClass(paymentMethod);
DBid bankTransClass = CBankTransaction::GetBankTransForAccount(bankAccountClass);
Boolean isRefund = (GetConditions() == condition_Credit || GetConditions() == condition_Return);
UInt8 paymentClass;
if (isRefund) // TCS 12/6/00
paymentClass = id_BankDeposit;
else if (paymentMethod == method_check || paymentMethod == method_escrowcheck) // TCS 12/17/00
paymentClass = id_BankCheck;
else
paymentClass = id_BankPayment;
CBankTransaction *bankTrans = nil;
SInt32 flags = flag_dontautoname;
bankTrans= TCS_SAFE_CAST(gDBFile->CreateObjectFromID(bankTransClass,
flags), CBankTransaction);
TCS_FailNILMsg(bankTrans, TCS_GetErrString(errID_BadTransaction));
DB_ObjectWatcher checkWatcher(bankTrans);
// fill in values
bankTrans->SetBankAccountID(paymentDetails); // TCS 3/6/00
bankTrans->SetTransactionType(paymentClass); // TCS 3/6/00
// fill in some values
bankTrans->SetMainAccountID(mMainAccount);
bankTrans->SetMainAccountClass(mMainAccountClass);
bankTrans->SetTransactionRef(GetDBID());
bankTrans->SetTransactionRefClass(GetDBClassID());
bankTrans->SetBankAccountID(paymentDetails); // TCS 3/6/00
bankTrans->SetCheckbookNumber(GetCheckbookNumber());
if (UseOneTimeName()) // TCS 1/23/01
{
bankTrans->SetUseOneTimeName(true);
bankTrans->SetOneTimeName(GetOneTimeName());
}
if (isRefund)
bankTrans->SetAmount(-mAmount); // TCS 12/6/00
else
bankTrans->SetAmount(mAmount);
// finish any other creation details. This is when
// running total and check number are filled in
bankTrans->FinishNonViewerCreate();
bankTrans->SetCreationType(record_autotransfer); // TCS 2/14/01
// set the date (must be after FinishNonViewerCreate!)
bankTrans->SetDate(mDate); // TCS 12/3/00 moved 3/25/03
// let the list know its found records may be out of whack TCS 10/24/00
DB_ListManager::SetChangedRemotely(bankTransClass);
// add the main transaction to the database
gDBFile->AddNewTransaction(bankTrans);
// mark as dirty
bankTrans->MakeDirty();
// post the object creation TCS 10/21/99 rev 5/23/00 rev TCS 12/14/00
bankTrans->PostNewRecord(record_fromprocess);
// update the running total TCS 2/12/01
bankTrans->UpdateRunningTotals();
// save everything so the viewer won't open as dirty
gDBFile->SaveAllChanges();
LWindow *frontWindow = DB_WindowManager::GetFrontWindow();
// we used to do a viewer update here, but TCS remove that 12/22/00
// show the bank transaction window TCS 10/25/00 rev 3/5/01
DB_Editor::ShowBankEditorWindow(bankTransClass, bankTrans, paymentDetails);
// put the the former active window in front. Usually this will be the purchase
// window, but it may be something else if this method is called remotely. TCS 10/25/00
if (frontWindow)
frontWindow->Select();
}
/*********************************************************************************
CreateEmployeeReimburse TCS 11/10/00
create an offsetting payroll record for an employee purchase
*********************************************************************************/
void CExpenseTransaction::CreateEmployeeReimburse(const DBid paymentDetails)
{
CPayrollRecord *record = nil;
SInt32 flags = flag_dontautoname;
record= TCS_SAFE_CAST(gDBFile->CreateObjectFromID(id_PayrollRecord,
flags), CPayrollRecord);
TCS_FailNILMsg(record, TCS_GetErrString(errID_BadTransaction));
DB_ObjectWatcher watcher(record);
// fill in some values
record->SetMainAccountID(paymentDetails);
record->SetTransactionRef(GetDBID());
record->SetConditions(GetDBClassID());
record->SetAmount(mAmount);
// finish any other creation details.
record->FinishNonViewerCreate();
record->SetCreationType(record_autotransfer); // TCS 6/25/03
record->SetDate(mDate); // TCS moved 3/25/03
// let the list know its found records may be out of whack TCS 10/24/00
DB_ListManager::SetChangedRemotely(id_PayrollRecord);
// add the record to the database
gDBFile->AddNewTransaction(record);
// mark as dirty
record->MakeDirty();
// post the object creation TCS 10/21/99 rev 5/23/00
record->PostNewRecord(record_autotransfer);
// save everything so the viewer won't open as dirty
gDBFile->SaveAllChanges();
// we used to do a viewer update here, but TCS remove that 12/22/00
LWindow *frontWindow = DB_WindowManager::GetFrontWindow();
// show the payroll record window TCS 10/25/00
DB_Editor::ShowEditor(id_PayrollRecord, paymentDetails);
// put the the former active window in front. Usually this will be the purchase
// window, but it may be something else if this method is called remotely. TCS 10/25/00
if (frontWindow)
frontWindow->Select();
}
/*********************************************************************************
CreateBarterOffset TCS 11/10/00
create an offsetting barter transfer for a barter purchase
*********************************************************************************/
void CExpenseTransaction::CreateBarterOffset(const DBid paymentDetails)
{
CBarterTransfer *record = nil;
SInt32 flags = flag_dontautoname;
record= TCS_SAFE_CAST(gDBFile->CreateObjectFromID(id_BarterTransfer,
flags), CBarterTransfer);
TCS_FailNILMsg(record, TCS_GetErrString(errID_BadTransaction));
DB_ObjectWatcher watcher(record);
// fill in some values
record->SetMainAccountID(paymentDetails);
record->SetAmount(mAmount);
// finish any other creation details.
record->FinishNonViewerCreate();
record->SetCreationType(record_autotransfer); // TCS 2/14/01
record->SetDate(mDate); // TCS 12/3/00 moved 3/25/03
// let the list know its found records may be out of whack TCS 10/24/00
DB_ListManager::SetChangedRemotely(id_BarterTransfer);
// add the record to the database
gDBFile->AddNewTransaction(record);
// mark as dirty
record->MakeDirty();
// post the object creation TCS 10/21/99 rev 5/23/00
record->PostNewRecord(record_autotransfer);
// save everything so the viewer won't open as dirty
gDBFile->SaveAllChanges();
// we used to do a viewer update here, but TCS remove that 12/22/00
LWindow *frontWindow = DB_WindowManager::GetFrontWindow();
// show the payroll record window TCS 10/25/00
DB_Editor::ShowEditor(id_BarterTransfer, paymentDetails);
// put the the former active window in front. Usually this will be the purchase
// window, but it may be something else if this method is called remotely. TCS 10/25/00
if (frontWindow)
frontWindow->Select();
}
|