Creating Payment Journal through X++ in Ax 2012

Hi All,

I want to create Payment journal through X++ code in Ax 2012,Can any one help me out with sample code/Suggestion

Thanks in advance!!!

Hi,

I think the below code will help you on your requirement.

public void PaymentJournalLineCreation()
{
boolean ret;
CustTable custTable;
LedgerJournalName LedgerJournalName;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalCheckPost ledgerJournalCheckPost;
NumberSeq numberseq;

;

//Get customer account
this.getCustomerAccount();

//Get currency
this.setCurrency();

//Set JournalNameId
this.setJournalNameId(LedgerJournalACType::Bank);

//Get table buffer
custTable = CustTable::find(customerAccount, false);

// Find a ledgerJournalName record
select firstonly LedgerJournalName
where LedgerJournalName.JournalName == journalNameId;

//Get next available voucher number
numberseq = NumberSeq::newGetVoucherFromCode(LedgerJournalName.VoucherSeries);
ledgerJournalTrans.Voucher = numberseq.voucher();

//Generate the transaction line
ledgerJournalTrans.JournalNum = ledgerJournalId;
ledgerJournalTrans.CurrencyCode = currencyCode;
ledgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.CurrencyCode);

ledgerJournalTrans.AccountNum = customerAccount;
ledgerJournalTrans.accountName();
ledgerJournalTrans.AccountType = LedgerJournalACType::Cust;

ledgerJournalTrans.Dimension[1] = custTable.Dimension[1];
LedgerJournalTrans.KUMTeamDescription();
ledgerJournalTrans.Dimension[2] = custTable.Dimension[2];
ledgerJournalTrans.KUMDetailDescription();
ledgerJournalTrans.Dimension[3] = custTable.Dimension[3];
ledgerJournalTrans.KUMEventDescription();

ledgerJournalTrans.AmountCurCredit = paymentAmount;
ledgerJournalTrans.TransDate = PaymentDate;
ledgerJournalTrans.Txt = ‘@COL1576’; //Payment, Thank you
ledgerJournalTrans.PaymMode = custTable.PaymMode;
ledgerJournalTrans.PostingProfile = ‘DFLT’;
ledgerJournalTrans.BankTransType = ‘Chck-rcpt’;
ledgerJournalTrans.Payment = custTable.PaymTermId;
ledgerJournalTrans.CustVendBankAccountId = this.GetCustomerBankAccountID(customerAccount);
ledgerJournalTrans.SettleVoucher = SettlementType::OpenTransact;
ledgerJournalTrans.TransactionType = LedgerTransType::Payment;
ledgerJournalTrans.Approved = NoYes::Yes;
ledgerJournalTrans.ApprovedBy = curUserId();
ledgerJournalTrans.Due = systemdateget();
ledgerJournalTrans.TaxGroup = ‘DFLT’;

ledgerJournalTrans.OffsetAccount = bankAccount;
ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Bank;
ledgerJournalTrans.offsetAccountName();

ledgerJournalTrans.PaymentStatus = CustVendPaymStatus::None;
ledgerJournalTrans.insert();

}

There are some methods calls in the previous code. These are the following:

//Find customer account based on Customer Reference Number
public CustAccount getCustomerAccount()
{
CustAccount custAccount;
CustBankAccount custBankAccount;
int countRecords = 0;
;

switch (JournalFormatType)
{
case KMN_CustPaymentJournalFormatType::mexico:
select * from custBankAccount where custBankAccount.MsgToBank == customerReference;
custAccount = custBankAccount.CustAccount;
this.parmCustAccount(custAccount);
break;
}

return custAccount;
}

//Sets the currency value to the property
public void setCurrency()
{
;
//Set property
this.parmCurrencyCode(CompanyInfo::standardCurrency());
}

public void setJournalNameId(LedgerJournalACType _journalType)
{
LedgerJournalNameId _journalNameId;
;
switch(_journalType)
{
case LedgerJournalACType::bank:
_journalNameId = ‘CR’;
break;

}

this.parmLedgerJournalNameId(_journalNameId);
}

Regards,

Muthu