OK, after a lot of debugging and trial and error, here's what I came up with.
If anyone knows how to use this thing, please let me know if I'm going about
this the right way. Everything seems to be working correctly from what I can
tell:
......................................................................................
LedgerJournalEngine ledgerEngine;
LedgerJournalTable ledgerTable;
LedgerJournalTrans ledgerTrans;
LedgerJournalTrans_Asset ledgerTransAsset;
LedgerJournalTrans_Project ledgerTransProj;
;
ledgerTable.clear();
ledgerTable.initValue();
ledgerTable.journalName = importOrder.journalName;
ledgerTable.name = importOrder.name;
ledgerTable.currencyCode = importOrder.currencyCode;
ledgerTable.insert();
while select importLine
{
// setup the journal line
ledgerEngine = new LedgerJournalEngine_VendInvoice();
ledgerEngine.newJournalActive(ledgerTable);
ledgerTrans.initValue();
ledgerEngine.initValue(ledgerTrans);
ledgerEngine.initValueAsset(ledgerTransAsset);
ledgerEngine.active(ledgerTrans);
// set the account type
ledgerTrans.AccountType = importLine.AccountType;
ledgerEngine.accountTypeModified(ledgerTrans, ledgerTransProj,
ledgerTransAsset);
// set the account number
ledgerTrans.accountNum = importLine.AccountNum;
ledgerEngine.accountNumModified(ledgerTrans, ledgerTransProj);
ledgerEngine.accountModified(ledgerTrans, ledgerTransProj,
ledgerTransAsset);
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
if(ledgerTrans.AccountType == LedgerJournalACType::FixedAssets)
ledgerEngine.setAssetDepStartDate(ledgerTrans, ledgerTransAsset);
// set the offset account type
ledgerTrans.offsetAccountType = importLine.offsetAccountType;
ledgerTrans.offsetAccountTypeModified(ledgerTrans, ledgerTransProj,
ledgerTransAsset);
// set the offset account number
ledgerTrans.offsetAccount = importLine.offsetAccount;
ledgerEngine.offsetAccountModified(ledgerTrans, ledgerTransProj,
ledgerTransAsset);
ledgerEngine.initFromOffsetAccount(ledgerTrans, ledgerTransProj,
ledgerTransAsset);
ledgerEngine.clearTaxAmountCache(ledgerTrans);
ledgerEngine.cashDiscCodeModified(ledgerTrans, ledgerTransAsset);
if(ledgerTrans.isFixedAssetTransaction())
{
// link the ledgerTransAsset record to the ledgerTrans record
ledgerTransAsset.refRecId = ledgerTrans.recId;
// set the fixed asset transaction type
ledgerTransAsset.TransType = importLine.assetTransType;
ledgerEngine.assetTransTypeModified(ledgerTrans, ledgerTransAsset);
// set the fixed asset value model
ledgerTransAsset.BookId = importLine.assetBookId;
ledgerEngine.assetBookIdModified(ledgerTrans, ledgerTransAsset);
if(ledgerTrans.AccountType == LedgerJournalACType::FixedAssets)
ledgerEngine.initFromAssetTable(ledgerTrans, ledgerTransAsset);
ledgerEngine.setAssetDepStartDate(ledgerTrans, ledgerTransAsset);
ttsbegin;
ledgerTransAsset.write();
ttscommit;
}
if(ledgerTrans.isProjectTransaction())
{
ledgerTransProj.RefRecId = ledgerTrans.RecId;
ttsbegin;
ledgerTransProj.write();
ttscommit;
}
// set the credit amount
if(importLine.creditAmount)
{
ledgerTrans.amountCurCredit = importLine.creditAmount;
ledgerEngine.amountCurCreditModified(ledgerTrans, ledgerTransProj);
ledgerEngine.clearTaxAmountCache(ledgerTrans);
ledgerEngine.cashDiscCodeModified(ledgerTrans, ledgerTransAsset);
if(ledgerTrans.AccountType == LedgerJournalACType::Project ||
ledgerTrans.OffsetAccountType == LedgerJournalACType::Project &&
ledgerTrans.offsetAccount))
{
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
ledgerEngine.projCostPriceModified(ledgerTrans, ledgerTransProj);
}
}
// set the debit amount
if(importLine.debitAmount)
{
ledgerTrans.amountCurDebit = importLine.debitAmount;
ledgerEngine.amountCurDebitModified(ledgerTrans, ledgerTransProj);
ledgerEngine.clearTaxAmountCache(ledgerTrans);
ledgerEngine.cashDiscCodeModified(ledgerTrans, ledgerTransAsset);
if(ledgerTrans.AccountType == LedgerJournalACType::Project ||
ledgerTrans.OffsetAccountType == LedgerJournalACType::Project &&
ledgerTrans.offsetAccount))
{
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
ledgerEngine.projCostPriceModified(ledgerTrans, ledgerTransProj);
}
}
// set the currency
ledgerTrans.currencyCode = importLine.currencyCode;
ledgerEngine.clearTaxAmountCache(ledgerTrans);
ledgerEngine.currencyModified(ledgerTrans);
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
// set the invoice date
ledgerTrans.TransDate = importLine.TransDate;
ledgerEngine.transDateModified(ledgerTrans);
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
// set the invoice id
ledgerTrans.invoice = importLine.invoiceId;
ledgerEngine.invoiceModified(ledgerTrans, ledgerTransProj);
ledgerEngine.paymentModified(ledgerTrans);
ledgerEngine.cashDiscCodeModified(ledgerTrans, ledgerTransAsset);
// set the tax group
ledgerTrans.taxGroup = importLine.TaxGroup;
ledgerEngine.correctTaxAmount(ledgerTrans, 0);
ledgerEngine.paymentModified(ledgerTrans);
ledgerEngine.cashDiscCodeModified(ledgerTrans, ledgerTransAsset);
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
// set the item tax group
ledgerTrans.taxItemGroup = importLine.taxItemGroup;
ledgerEngine.correctTaxAmount(ledgerTrans, 0);
ledgerEngine.paymentModified(ledgerTrans);
ledgerEngine.cashDiscCodeModified(ledgerTrans, ledgerTransAsset);
ledgerEngine.setProjCostSalesPrice(ledgerTrans, ledgerTransProj);
// set other fields that don't require ledgerEngine.modified() methods
...
ledgerTrans.write();
ledgerEngine.write(ledgerTrans);
if(ledgerTrans.isFixedAssetTransaction())
{
// link the ledgerTransAsset record to the ledgerTrans record
ledgerTransAsset.refRecId = ledgerTrans.recId;
// set the fixed asset transaction type
ledgerTransAsset.TransType = importLine.assetTransType;
ledgerEngine.assetTransTypeModified(ledgerTrans, ledgerTransAsset);
// set the fixed asset value model
ledgerTransAsset.BookId = importLine.assetBookId;
ledgerEngine.assetBookIdModified(ledgerTrans, ledgerTransAsset);
if(ledgerTrans.AccountType == LedgerJournalACType::FixedAssets)
ledgerEngine.initFromAssetTable(ledgerTrans, ledgerTransAsset);
ledgerEngine.setAssetDepStartDate(ledgerTrans, ledgerTransAsset);
ttsbegin;
ledgerTransAsset.write();
ttscommit;
}
if(ledgerTrans.isProjectTransaction())
{
ledgerTransProj.RefRecId = ledgerTrans.RecId;
ttsbegin;
ledgerTransProj.write();
ttscommit;
}
}
......................................................................................
Some of these methods, I wasn't too sure if I needed to call, like the
clearTaxAmountCache(...) and cashDiscCodeModified(...) but as I was having
troubles getting things to behave properly after I imported my lines, I found
these methods being called in the modified field methods in the
LedgerJournalTransVendInvoice form. I know it's a lot to look over but if
anyone has experience using the ledgerJournalEngine class, please glance over
this and see if I'm missing anything or adding any extra unnecessary steps.
Thanks,
Adam