Showing posts with label CustTable::find. Show all posts
Showing posts with label CustTable::find. Show all posts

Monday, June 13, 2011

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.

Thursday, March 10, 2011

Email Invoices based on customer setup options - Microsoft Dynamics Ax 2009

Today I had a requirement that said to add a CheckBox control to the Customer Form to decide weather to print or email an invoice automatically.


NOTE: I will no go over the actual logic on how to email the invoice as I have already written a post about it, you can find it here http://axwonders.blogspot.com/2011/02/save-microsoft-dynamics-ax-2009-report_23.html


The following is the new control added to the CustTable form under the setup Tab:





 Now the logic is very simple. If the a customer account has this checkbox checked then set the Document destination value automatically to Email. Otherwise set the value of the control to Printer. In the picture above we can see that this specific customer has the checkbox checked.


Then the expected result will be to see the Document destination value to Email when a sales order record needs to be invoiced or acknowledged.


Please see the following sequence: