Hi,
we're trying to create settlements in code in order to settle customer transactions that have some minor amount of balance left. Doing this with tax transactions seems to be difficult in code using the LedgerVoucher*-objects. Settling using journals works, but that's not practical for single transactions (aka. a unique journal for each transaction).
Skipping journals aside, can you pass tax groups & tax item groups to LedgerVoucher objects, or do we have to use some Tax class and bind it to LedgerVoucher/LederPostingController in order to post tax transactions as well? E.g. a balance of 1,00e using a tax item group of 25 (25%) would do tax posts of 0,25e, 0,75e of sales and -1,00e balance.
Below is a snippet of the (part of) code to settle transactions without tax transactions and it works well in our case that doesn't include tax.
ledgerVoucher = LedgerVoucher::newLedgerPost(DetailSummary::Detail, SysModule::Cust, numberSequenceCode);
ledgerVoucherObject = LedgerVoucherObject::newVoucher(voucher, transDate, SysModule::Cust, LedgerTransType::Payment);
ledgerVoucher.AddVoucher(ledgerVoucherObject);
currencyExchangeHelper = currencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), ledgerVoucherObject.parmAccountingDate());
ledgerVoucherTransObject = LedgerVoucherTransObject::newTransactionAmountDefault(
ledgerVoucherObject
, LedgerPostingType::CustPayment
, ledgerDimension
, custTable.Currency
, _amountCur
, currencyExchangeHelper);
ledgerVoucher.addTrans(ledgerVoucherTransObject);
custVoucher = CustVendVoucher::construct(
SysModule::Cust
, custAccount
, _amountCur * -1
, custTable.Currency
, ledgerTransTxt::CustPaymentCust
, defaultDimension
, ''
, LedgerPostingType::CustPayment);
custVoucher.parmApprover(HcmWorker::userId2Worker(curUserId()));
custVoucher.parmApproved(NoYes::Yes);
custVoucher.parmTypeOfCreditmaxCheck(TypeOfCreditmaxCheck::None);
custVoucher.parmPaymMode(custTable.PaymMode);
custVoucher.parmPaymSpec(custTable.PaymSpec);
custVoucher.parmLanguageId(custTable.LanguageId());
custVoucher.parmPaymTermId(custTable.PaymTermId);
custVoucher.parmDueDate(systemDateGet());
custVoucher.parmExchRate(
ExchangeRateHelper::getExchangeRate1_Static(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), _custTrans.CurrencyCode, systemDateGet()));
custVoucher.parmExchRateSecondary(
ExchangeRateHelper::getExchangeRate2_Static(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), _custTrans.CurrencyCode, systemDateGet()));
custVoucher.parmTransRefType(CustTransRefType::Payment);
custVoucher.parmTransRefId(custTransTarget.Voucher);
custVoucher.parmThirdPartyBankAccountId(custTable.BankAccount);
custVoucher.post(ledgerVoucher, custTrans, NoYes::No, UnknownNoYes::No, NoYes::No, false );
ledgerVoucher.end();