Bojensen Blogs

AX WONDERS: Create Axapta Payment Journal

The following code creates a payment journal in AX.

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);

}

NOTE: I’m using accessory methods for most of the variables in this code (this is a class), so remember to declare them in the classDeclaration and create your own properties.

AX WONDERS: Create Axapta Payment Journal

Comments are closed.