Showing posts with label custConfirmJour. Show all posts
Showing posts with label custConfirmJour. 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.

Tuesday, February 22, 2011

Save a Microsoft Dynamics AX 2009 report to a PDF file (First Part)

The following code saves an Axapta report to a PDF file. This is the first article of 3. The next article will show how to save the file into a network share and pass a Sales Order dynamically, and the last part will be about attaching the PDF to an Outlook instance and create a dynamic subject. So, the titles of the three articles will be the same foe exception of the text in parenthesis.

In my case, I'm having a lot of problems saving the file to a network file and then to attach it to Outlook. The code below saves the report to a local palce in your computer.

static void Job10(Args _args)
{
   custConfirmJour     custInvoiceJour;
  SalesFormLetter     salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation,  false);
   PrintJobSettings    printJobSettings = new PrintJobSettings();
   Args                args = new Args();
   boolean             prompt = false;
   boolean             printIt = true;
   ;

    printJobSettings.setTarget(PrintMedium::File);
    printJobSettings.format(PrintFormat::PDF);
    printJobSettings.fileName(@'c:\temp\myfile2.pdf');
  
   salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings());

   select firstOnly custInvoiceJour
       where custInvoiceJour.salesid == '18-062467';

   args.record(custInvoiceJour);
   args.caller(salesFormLetter);

   new MenuFunction(menuitemoutputstr(SalesConfirmation), MenuItemType::Output).run(args);

}