Hi.
I want to post payment to LedgerJournal and mark invoice for payment.
Example: customer '1104' has invoice '10002' with Saldo (Balance) 1000 USD.
I want to pay this invoice with 0.25 USD, so in Not payed invoices with apper line with this invoice with Saldo 999.75
So I use this code:
void clicked()
{
LedgerJournalTable header;
LedgerJournalTrans trans;
LedgerJournalName ledgerJournalName;
CustTrans custTrans;
CustInvoiceJour custInvoiceJour;
NumberSeq numberseq;
LedgerJournalCheckPost ledgerJournalCheckPost;
;
select firstonly ledgerJournalName where ledgerJournalName.JournalType == LedgerJournalType::CustPayment;
select custInvoiceJour where custInvoiceJour.InvoiceAccount=='1104' && custInvoiceJour.InvoiceId=='10002';
print "custInvoiceJour=" + custInvoiceJour.InvoiceId;
custTrans = CustTrans::findFromInvoice(custInvoiceJour.InvoiceId);
if (!custTrans) print "custTrans not found";
print "custTrans.RecId=" + int2str(custTrans.RecId);
if (!CustTransOpen::findRefId(custTrans.RecId)) {
error(strfmt("Invoice already payed: %1", custInvoiceJour.InvoiceId));
return;
}
print "ledgerJournalName.Name=" + ledgerJournalName.Name;
header.JournalName = ledgerJournalName.Name;
header.JournalType = LedgerJournalType::Daily;
header.Name = "JOURNAL_1";
header.CurrencyCode = "USD";
header.insert();
print "journalNum = " + header.JournalNum;
//numberseq = NumberSeq::NewGetVoucherFromCode(ledgerJournalName.VoucherSeries);
trans.clear();
trans.initValue();
trans.JournalNum = header.JournalNum;
//trans.Voucher = numberseq.voucher();
trans.Voucher = "VOUCHER9";
trans.TransDate = today();
trans.AccountType = LedgerJournalACType::Cust;
trans.AccountNum = custInvoiceJour.InvoiceAccount;
trans.Txt = "COMMENT OF PAYMENT";
trans.OffsetAccountType = LedgerJournalACType::Bank;
trans.OffsetAccount = "USA OPER";
trans.Dimension = ledgerJournalName.Dimension;
trans.CurrencyCode = "USD";
trans.ExchRate = 1.0;//ExchRates::find(header.CurrencyCode, datenull(), NoYes::No, NoYes::No).ExchRate;
trans.TransactionType = LedgerTransType::Payment;
trans.PaymMode = "Cash";
trans.SettleVoucher = SettlementType::SelectedTransact;
trans.MarkedInvoice = custInvoiceJour.InvoiceId;
trans.AmountCurCredit = 0.25;
print "trans.MarkedInvoice=" + trans.MarkedInvoice;
trans.insert();
ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(header, NoYes::Yes);
ledgerJournalCheckPost.run();
}
In trans I use this two lines:
trans.SettleVoucher = SettlementType::SelectedTransact;
trans.MarkedInvoice = custInvoiceJour.InvoiceId;
which I expect to do this thing (mark invoice for payment). But I got error:
there are no marked transactions but for Settle type was chosen Selected Transactions (sorry for English, something like that)
Question is : what is wrong? How to mark invoice for payment in X++ code?