Below method can be used to mark the Invoice amounts for settlement in very easy way.
In your code to loop through ledgerjournaltrans(assuming you already created payment lines for respective Customer/vendor, if not, then create payment record either by X++ or direct entry through payment screens).
Just for reference, i am creating payment via x++ and marked the invoices for settlement.
I am posting full process (create & Post SO, Create Payment entry, Mark invoice for settlement, post payment entry)
form class Declaration.
Below method can be used for SO creation and Payment entry.
Below method can be used for settlement of required amount
yes, I am done here. Thanks!!!
In your code to loop through ledgerjournaltrans(assuming you already created payment lines for respective Customer/vendor, if not, then create payment record either by X++ or direct entry through payment screens).
Just for reference, i am creating payment via x++ and marked the invoices for settlement.
I am posting full process (create & Post SO, Create Payment entry, Mark invoice for settlement, post payment entry)
form class Declaration.
public class FormRun extends ObjectRun { CustTable custtable_g; CustInvoiceJour bitcustInvoiceJour; }
Below method can be used for SO creation and Payment entry.
public void TestReceipt() { SalesTable salesTable; NumberSeq NumberSeq; SalesLine salesLine; SalesFormLetter formLetterObj; InventTable inventTable; Ledgerjournalname ledgerjournalname; LedgerjournalTable LedgerjournalTable; LedgerjournalTrans LedgerjournalTrans; LedgerJournalCheckPost ledgerJournalCheckPost; ; try { ttsBegin; //Create sales header NumberSeq = NumberSeq::newGetNumFromId(SalesParameters::numRefSalesId().NumberSequenceId); salesTable.SalesId = NumberSeq.num(); salesTable.initValue(); salesTable.CustAccount = custtable_g.AccountNum; //custtable_g is already initialized salesTable.initFromCustTable(); salesTable.insert(); //Create Sales lines salesLine.clear(); salesLine.SalesId = salesTable.SalesId; salesLine.ItemId = ItemId.valueStr(); inventTable = InventTable::find(ItemId.valueStr()); salesLine.initFromInventTable(inventTable); salesLine.SalesQty = Quantity.value(); salesLine.createLine(NoYes::Yes, // Validate NoYes::Yes, // initFromSalesTable NoYes::Yes, // initFromInventTable NoYes::Yes, // calcInventQty NoYes::Yes, // searchMarkup NoYes::Yes); // searchPrice //confirmation //formLetterObj = SalesFormLetter::construct(DocumentStatus::Confirmation); //formLetterObj.update(salesTable,Selldate.dateValue()); //Packing Slip formLetterObj = SalesFormLetter::construct(DocumentStatus::PackingSlip); formLetterObj.update(salesTable,Selldate.dateValue()); //Post Invoice formLetterObj = SalesFormLetter::construct(DocumentStatus::Invoice); formLetterObj.update(salesTable,Selldate.dateValue()); ttsCommit; // ttsBegin; bitcustInvoiceJour = formLetterObj.parmJournalRecord(); //Generate and post receipt select ledgerjournalname where ledgerjournalname.JournalName == "PayJ"; //use correct payment journal name //ttsBegin; LedgerjournalTable.JournalName = ledgerjournalname.JournalName; LedgerjournalTable.initFromLedgerJournalName(); LedgerjournalTable.JournalNum = JournalTableData::newTable(LedgerjournalTable).nextJournalId(); LedgerjournalTable.insert(); numberSeq = NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable)); LedgerjournalTrans.Voucher = numberSeq.voucher(); LedgerjournalTrans.JournalNum = LedgerjournalTable.JournalNum; LedgerjournalTrans.AccountType = LedgerJournalACType::Cust; LedgerjournalTrans.Company = curext(); LedgerjournalTrans.parmAccount(custtable_g.AccountNum,LedgerjournalTrans.AccountType); LedgerjournalTrans.initFromCustTable(custtable_g); LedgerjournalTrans.TransDate = Selldate.dateValue(); LedgerjournalTrans.ExchRate = Currency::exchRate(LedgerjournalTrans.CurrencyCode); LedgerjournalTrans.Txt = strFmt('Payment for item sale for sales id : %1',salestable.SalesId); LedgerjournalTrans.DefaultDimension = custtable_g.DefaultDimension; LedgerjournalTrans.OffsetDefaultDimension = custtable_g.DefaultDimension; LedgerjournalTrans.TransactionType = LedgerTransType::Payment; LedgerjournalTrans.AmountCurCredit = bitcustInvoiceJour.InvoiceAmount; LedgerjournalTrans.PaymMode = CustPaymMode.valueStr(); LedgerjournalTrans.SettleVoucher = SettlementType::SelectedTransact; LedgerjournalTrans.modifiedField(fieldNum(LedgerjournalTrans,PaymMode)); LedgerjournalTrans.insert(); element.settlement(LedgerjournalTrans,LedgerjournalTrans.AmountCurCredit); //look for method //Post Journal ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(LedgerjournalTable,NoYes::Yes); ledgerJournalCheckPost.run(); ttsCommit; info(strFmt("Journal %1 created for item sales Id %2 to Student id %3",LedgerjournalTable.JournalNum,salestable.SalesId,custtable_g.AccountNum)); } catch { error("error in generating receipt for sale."); } }
Below method can be used for settlement of required amount
void settlement(ledgerJournalTrans _ledgerJournalTrans,real _amounttoSettle) { SpecTrans insertSpecTrans; ; insertSpecTrans.SpecCompany = _ledgerJournalTrans.Company; insertSpecTrans.SpecTableId = TableNum(ledgerJournalTrans); insertSpecTrans.SpecRecId = _ledgerJournalTrans.RecId; insertSpecTrans.RefCompany = _ledgerJournalTrans.Company; insertSpecTrans.RefTableId = TableNum(custTransOPen); insertSpecTrans.RefRecId = custTransOPen::findRefId(bitcustInvoiceJour.custTrans().RecId).RecId; insertSpecTrans.Balance01 = _amounttoSettle; insertSpecTrans.Code = _ledgerJournalTrans.CurrencyCode; insertSpecTrans.Payment = NoYes::No; insertSpecTrans.LineNum = 1; insertSpecTrans.insert(); }
yes, I am done here. Thanks!!!