Thursday, December 7, 2017

Creating Payment journal and posting Payment journal ax2012 /D365 ax7 x++

Public static boolean processPayment(BAModule BAModule)
{
ledgerJournalName  JournalName ;
ledgerJournalCheckPost JournalCheckPost;

ledgerJournalTable JournalTable;
ledgerJournalTrans JournalTrans;
JournalCheckPost JournalCheckPost;

Common common;
NumberSeq numberseq;
CustTrans custTrans;
CustTransOpen custTransOpen;
Specification specOffsetVoucher;

BAParameters parameters = BAParameters::find();
CustTable custTable = CustTable::find(BAModule.CustAccount);
boolean return = false;
InvoiceId invoiceId;
;

while select custTransOpen
where custTransOpen.RefRecIdCheck == BaModule.RecId &&
custTransOpen.UseRefRecId
{
custTrans = custTransOpen.custTrans();
invoiceId = custTrans.Invoice;

try
{
ttsbegin;

select firstonly JournalName
where JournalName .JournalName == parameters.JournalName Id &&
JournalName .JournalType == LedgerJournalType::CustPayment;

if(!JournalName .RecId)
throw error("@11250");

if(JournalName )
{
JournalTable.JournalName = JournalName .JournalName;
JournalTable.Name = JournalName .Name;
JournalTable.insert();

if(JournalTable)
{
numberseq = NumberSeq::NewGetVoucherFromCode(JournalName .VoucherSeries);
JournalTrans.JournalNum = JournalTable.JournalNum;
JournalTrans.Voucher = numberseq.voucher();
JournalTrans.TransDate = today();
JournalTrans.Txt = CustTable::find(JournalTrans.AccountNum).Name;
JournalTrans.OffsetAccountType = JournalName .OffsetAccountType;
JournalTrans.OffsetAccount = JournalName .OffsetAccount;
JournalTrans.Dimension = JournalName .Dimension;
JournalTrans.CurrencyCode = JournalTable.CurrencyCode;
JournalTrans.AccountType = LedgerJournalACType::Cust;

JournalTrans.TransactionType = LedgerTransType::Payment;
JournalTrans.PaymMode = parameters.PaymMode;
JournalTrans.SettleVoucher = SettlementType::SelectedTransact;
JournalTrans.AccountNum = custTable.AccountNum;
JournalTrans.AmountCurCredit = custTransOpen.AmountCur;
JournalTrans.ExchRate = ExchRates::find(JournalTable.CurrencyCode, datenull(), NoYes::No, NoYes::No).ExchRate;
JournalTrans.insert();

select custTransOpen
where custTransOpen.AccountNum == custTable.AccountNum &&
custTransOpen.RefRecId == CustTrans::findFromInvoice(invoiceId).RecId;

if(custTransOpen)
{
common = JournalTrans;
specOffsetVoucher = Specification_OffsetVoucher::newCommon(common, true);
if (!specOffsetVoucher.isMarked(custTransOpen.TableId, custTransOpen.RecId))
if (JournalTrans.RecId)
specOffsetVoucher.create(custTransOpen.TableId, custTransOpen.RecId, custTransOpen.AmountCur, JournalTable.CurrencyCode);
}

JournalCheckPost = JournalCheckPost::newJournalTable(JournalTable, NoYes::Yes);
JournalCheckPost.run();
return = true;
}
}
ttscommit;
}
catch
{
ttsabort;
return = false;
}
}
return return;
}

No comments:

Post a Comment

D365FO. Dynamics 365 fiance and operation. Get and update contract of batch job on Controller run method. ax 2012

set Batch id in contract if batch isInBatch check is true in run method we will update the contract and set the batch id. class BrFunc...