Saturday, March 8, 2014

X++ code to create Project Invoice Proposal and Posting in AX 2012

static void ProjectInvoiceProposalCreateAndPost(Args _args)
{
    ProjInvoiceProjId       _ProjectContractId = "";    //Project Contract Id for which we want to create Invoice Proposal
    ProjProposalJour        projProposalJour;           //Table which will store journal records after creating Invoice Proposal
    ProjInvoiceChoose       m_oProjInvoiceChooseNormal; //Class for creating Invoice Proposal
    ProjFormLetter          projFormLetter;             //Class for Posting Invoice Proposal
    ProjTable               projTable;

    ttsBegin;


    projTable = projTable::find("10001");
    //Creation of Invoice Proposal
    m_oProjInvoiceChooseNormal = ProjInvoiceChoose::PSANew_InvoiceChoose(projTable.ProjInvoiceProjId);
    m_oProjInvoiceChooseNormal.run();

    while select forUpdate projProposalJour where projProposalJour.ProjInvoiceProjId == projTable.ProjInvoiceProjId
    {
        //For approving Invoice proposals
        projProposalJour.LineProperty = ProjLinePropertyCode::Approved;
        projProposalJour.update();
        //For Posting Invoice Proposals
        projFormLetter = ProjFormLetter::construct(DocumentStatus::ProjectInvoice);
        projFormLetter.createParmLine(projProposalJour);
        projFormLetter.run();
        //To get latest record
        projProposalJour = projProposalJour::find(projProposalJour.ProposalId);

        info(strFmt("Invoice ProposalId: %1 \t InvoiceId: %2",projProposalJour.ProposalId,projProposalJour.ProjInvoiceId));

    }

    ttsCommit;

}

1 comment:

  1. This code is not working, if contract have billing rules. Could you please help

    ReplyDelete