Hi I am really hoping someone can help me understand the LedgerVoucher classes.
In the company currency conversion script there is some code that uses these classes that is giving some problems. Basically in the conversion script it sums up each existing voucher and if there is an amountMST remaining (i.e. voucher does not balance) then it tries to create a pennydiff part for the voucher using these classes. So my first questions are: 1)LedgerVoucher.addVoucher() - does this create the whole balanced voucher or just a single transaction? 2)LedgerVoucherObject.newtransRoundOff() - does this create the whole balanced voucher or just a single transactions? 3)LedgerVoucher.post() - the ledgervoucherlist and ledgertranslist used in here will include the already existing parts of the voucher as well as what was created using ledgervoucherobject.newtransRoundOff? Or will they only include the parts the ledgervoucherobject.newtransroundoff() has created (i.e. not including already posted ledtrans)? The reason I ask is in the ledgervoucher.post() method it is giving an imbalance error based on checks it makes to the ledgertranslist and I am guessing this imbalance is due to the ledgertranslist only containing the pennydiff part of the voucher. ledgervoucher object not being created fully (i.e. to balance) but rather only the penny diff part has been created and being checked to see if balances (which of course it wont) Can anyone help me to understand as I am not sure if I need to change the code with ledgervoucher classes in the conversion script or change the check in the post() method (because it seems to me during the conversion script the check in the post() should not be done since I assume it is only creating the pennydiff part of the voucher - which on its own will never balance) Really really really appreciate any help that can be offered as I have been struggling with this conversion for a week or so now. Below is the currency conversion method createLedgerTransDiff that uses the ledgervoucher classes and also the ledgervoucher.post() method Thanks James **************************************************************** private void createLedgerTransDiff() { LedgerTrans ledgerTrans; LedgerTrans tmpLedgerTrans; LedgerVoucher ledgerVoucher; LedgerVoucherTransObject ledgerVoucherTransObject; CurrencyCode secondaryCurrencyCode; TransactionTxt transactionTxt; TransTxt transTxt; Boolean mustLog; ; if (companyInfo::find().secondaryCurrencyCode != newCompanyCurrency) { secondaryCurrencyCode = companyInfo::find().secondaryCurrencyCode; } else { secondaryCurrencyCode = newCompanyCurrency; } // per voucher and transdate in the LedgerTrans are created new penny difference // postings in company currency and in secondary currency ttsBegin; ledgerVoucher = LedgerVoucher::newLedgerPostDiff(); while select sum(amountMST), sum(amountMSTSecond) from ledgerTrans index hint VoucherDateIdx group by voucher, transDate where ledgerTrans.PeriodCode == PeriodCode::Regular { if (ledgerTrans.amountMST || ledgerTrans.amountMSTSecond) { mustLog = true; tmpLedgerTrans = LedgerTrans::findVoucherDate(ledgerTrans.voucher, ledgerTrans.transDate); ledgerVoucher.AddVoucher(LedgerVoucherObject::newVoucher( ledgerTrans.Voucher, ledgerTrans.TransDate, SysModule::Ledger, tmpLedgerTrans.transType, tmpLedgerTrans.correct, tmpLedgerTrans.operationsTax)); if(ledgerTrans.amountMST) { transactionTxt = new TransactionTxt(LedgerTransTxt::LedgerMSTDIFF); transactionTxt.setVoucher(ledgerTrans.voucher); transTxt = transactionTxt.txt(); if (!transTxt) { transTxt = "@SYS9998"; } ledgerVoucherTransObject = ledgerVoucherTransObject::newTransRoundOff(LedgerPostingType::MSTDiff, ledgerTrans.Voucher, ledgerTrans.TransDate, LedgerSystemAccounts::accountNum(LedgerPostingType::MSTDiff), tmpLedgerTrans.dimension, newCompanyCurrency, -ledgerTrans.amountMST); ledgerVoucherTransObject.parmTransTxt(transTxt); ledgerVoucher.addTrans(ledgerVoucherTransObject); } if(ledgerTrans.amountMSTSecond) { transactionTxt = new TransactionTxt(LedgerTransTxt::LedgerMSTDIFFSecond); transactionTxt.setVoucher(ledgerTrans.voucher); transTxt = transactionTxt.txt(); if (!transTxt) { transTxt = "@SYS60706"; } ledgerVoucherTransObject = ledgerVoucherTransObject::newTransRoundOff(LedgerPostingType::MSTDiffSecond, ledgerTrans.Voucher, ledgerTrans.TransDate, LedgerSystemAccounts::accountNum(LedgerPostingType::MSTDiffSecond), tmpLedgerTrans.dimension, newCompanyCurrency, 0 -ledgerTrans.amountMSTSecond); ledgerVoucherTransObject.parmTransTxt(transTxt); ledgerVoucher.addTrans(ledgerVoucherTransObject); } } } ledgerVoucher.end(); //if (mustLog) // TransactionLog::create(TransactionLogType::ConvCompanyCurrency, strFmt("@SYS54524", oldCompanyCurrency, newCompanyCurrency)); ttsCommit; } ********************************************************** protected Boolean post() { boolean more; boolean ok = true; LedgerTrans ledgerTrans; AmountMST amountMST; AmountMSTSecondary amountMSTSecondary; TransDate transDateOld; Voucher voucherOld; LedgerPostingJournal ledgerPostingJournal; ; if (checkAuto) if (!this.check()) throw error("@SYS21533"); ledgerBalancesList = LedgerVoucherBalancesList::Construct(); ledgerBalancesDimList = LedgerVoucherBalancesList::ConstructDim(); this.InitLedgerTransList(); ttsBegin; for (more = ledgerVoucherList.first(); more; more = ledgerVoucherList.next()) { ok = ledgerVoucherList.item().post(this) && ok; } for (more = ledgerTransList.first(ledgerTrans); more; more = ledgerTransList.next(ledgerTrans)) { if (ledgerTrans.AmountCur || ledgerTrans.AmountMST || ledgerTrans.AmountMSTSecond || ledgerTrans.Qty) { /* This check is actually already being performed in LedgerVoucherObject.checkBalancePerDate(), but just to be on the safe side..... */ if (transDateOld != ledgerTrans.TransDate || voucherOld != ledgerTrans.Voucher) { if (amountMST || amountMSTSecondary) THE ERROR OF IMBALANCE IS COMING HERE!!!!! ok = checkFailed(strfmt("@SYS70033", voucherOld, transDateOld, amountMST, amountMSTSecondary)); transDateOld = ledgerTrans.TransDate; voucherOld = ledgerTrans.Voucher; amountMST = 0; amountMSTSecondary = 0; } if (ok) { if (ledgerTrans.LedgerPostingJournalId) { ledgerPostingJournal = LedgerPostingJournal::find(ledgerTrans.ledgerPostingJournalId); ledgerTrans.LedgerPostingJournalRegisterId = ledgerPostingJournal.LedgerPostingJournalRegisterId; ledgerTrans.LedgerTransReportType = ledgerPostingJournal.LedgerTransReportType; ledgerTrans.VoucherSequenceCode = voucherSeriesCode; if (!LedgerPostingJournalControl::checkLedgerTrans(ledgerTrans)) { throw Error("@SYS21628"); } } ledgerTrans.write(); } amountMST += ledgerTrans.AmountMST; amountMSTSecondary += ledgerTrans.AmountMSTSecond; } } ok = this.postBankAccountTrans() && ok; ok = this.checkDebCredBalanceDemand() && ok; /* This check is actually already being performed in LedgerVoucherObject.checkBalancePerDate(), but just to be on the safe side..... */ if (amountMST || amountMSTSecondary) ok = checkFailed(strfmt("@SYS70033", voucherOld, transDateOld, amountMST, amountMSTSecondary)); if (ok) { ledgerBalancesList.post(); ledgerBalancesDimList.post(); } else throw error("@SYS21533"); TransactionLog::create(transactionLogType, transactionLogTxt); ttsCommit; return ok; } [Non-text portions of this message have been removed] Sharing the knowledge on Axapta. Visit www.frappr.com/axapta for axapta friends. Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/Axapta-Knowledge-Village/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/