Tuesday 29 December 2015

post PO by code in ax 2012


please find the code for posting PO here the code is some what lengthy it is doing some other functionality too.

public void InvoicePO(PurchTable _purchTable)
{
    PurchTable                      purchTable,purchTableCurr;
    int                             seq;
    PurchFormLetter_PackingSlip     packingSlip;
    PurchFormLetter_Invoice         invoice;

    PurchFormLetter                 confirm;
    VendInvoiceJour                 vendInvoiceJour;
    InvoiceId                       invoiceId;
    PurchLine                       purchLine;
    SalesTable                      salesTable;

    CustInvoiceJour                 custInvoiceJour;
    CustInvoiceId                   custInvoiceId;
    CustPackingSlipJour             custPackingSlipJour;
    PackingSlipId                   packingSlipId;
    VendPurchOrderJour              vendPurchOrderJour;
    DmsInterCompanySO               interCompanySO = new DmsInterCompanySO();
    DmsSOAutoPost                   dmsSOAutoPost = new DmsSOAutoPost();
    DmsCreateSalesOrder             CreateSalesOrder = new DmsCreateSalesOrder();

    purchTable  = _purchTable;//_args.record();
    seq         = this.invoiceCount(purchTable.PurchId);
    seq++;


    try
    {
        select recid from purchLine where purchLine.PurchId == purchTable.PurchId
            && purchLine.PurchReceivedNow != 0;

        if(!purchLine.RecId)
        {
            throw error("@DMS2537");
        }

        ttsBegin;
        if (VendTable::find(purchTable.OrderAccount).DmsSalesKittingEnabled && (purchTable.PurchaseType == PurchaseType::Purch || purchTable.PurchaseType == PurchaseType::ReturnItem))
        {
            DmsPopulateSupplementaryItems::createSupplementaryItemLinesPurch(purchTable);
        }
        if(PurchTable.DmsIsDropShipment)
        {
            CreateSalesOrder.run(PurchTable);
        }

        confirm = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
        confirm.update( purchTable,
                        strFmt('Conf-%1-%2',purchTable.PurchId,seq));

        if(purchTable.InterCompanySalesId && purchTable.PurchaseType == PurchaseType::Purch)
        {
            changeCompany(purchTable.InterCompanyCompanyId)
            {
                select firstonly InvoiceId from custInvoiceJour
                    where custInvoiceJour.SalesId == purchTable.InterCompanySalesId;

                custInvoiceId = custInvoiceJour.InvoiceId;

                select firstonly PackingSlipId from CustPackingSlipJour
                    where CustPackingSlipJour.SalesId == purchTable.InterCompanySalesId;

                packingSlipId = CustPackingSlipJour.PackingSlipId;
            }

            packingSlip = PurchFormLetter::construct(DocumentStatus::PackingSlip);
            packingSlip.showQueryForm(false);
            packingSlip.update( purchTable,
                                packingSlipId,
                                today(),
                                PurchUpdate::ReceiveNow,
                                AccountOrder::None,
                                false,
                                false);

            invoice = PurchFormLetter::construct(DocumentStatus::Invoice);
            invoice.showQueryForm(false);
            invoice.parmDmsReArrangeNow(false);

            invoice.update( purchTable,
                        custInvoiceId,
                        today(),
                        PurchUpdate::PackingSlip,
                        AccountOrder::None,
                        false,
                        false);
        }
        else
        {

            if( purchTable.PurchaseType == PurchaseType::ReturnItem )
            {
                // partner blocking
                //purchTable.DmsPartnerBlockingPurchaseReturnVolume();
                //purchTable.DmsPartnerBlockingPurchaseReturnValue();
                // partner blocking
                confirm = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
                confirm.update(purchTable,'',today(),PurchUpdate::All,AccountOrder::None,NoYes::No,NoYes::Yes);

                if( PurchTable.PurchaseType == PurchaseType::ReturnItem )  //07112015
                {
                    select count(RecId) from vendPurchOrderJour where vendPurchOrderJour.PurchId == PurchTable.PurchId;
                    if(vendPurchOrderJour.RecId > 0)
                    {
                        if( !PurchTable.InterCompanySalesId )
                        {
                            interCompanySO.run(PurchTable.PurchId);
                        }
                    }
                }
            }

            packingSlip= PurchFormLetter::construct(DocumentStatus::PackingSlip);
            packingSlip.showQueryForm(false);
            packingSlip.update( purchTable,
                                strFmt('PS-%1-%2',purchTable.PurchId,seq),
                                today(),
                                PurchUpdate::ReceiveNow,
                                AccountOrder::None,
                                false,
                                false);

            invoice = PurchFormLetter::construct(DocumentStatus::Invoice);
            invoice.showQueryForm(false);
            invoice.parmDmsReArrangeNow(false);

            invoice.update(purchTable,
                        strFmt('INV-%1-%2',purchTable.PurchId,seq),
                        today(),
                        PurchUpdate::PackingSlip,
                        AccountOrder::None,
                        false,
                        false);

        }


        select firstOnly purchTableCurr
            where purchTableCurr.PurchId == PurchTable.PurchId;

        if( purchTableCurr.DmsIsDropShipment && purchTableCurr.DmsDropShipmentSalesId )
        {
            salesTable = SalesTable::find(purchTableCurr.DmsDropShipmentSalesId);
            this.postSO(salesTable);
        }

        ttsCommit;

        invoiceId = strFmt('INV-%1-%2',purchTable.PurchId,seq);

        select LedgerVoucher from vendInvoiceJour where vendInvoiceJour.PurchId && vendInvoiceJour.InvoiceId == invoiceId;

        if(vendInvoiceJour.LedgerVoucher && purchTable.DmsDOReferenceNumber && !purchTable.DmsIsInterCompanyTransfer)
            info(strFmt("@DMS2536",purchTable.PurchId, purchTable.DmsDOReferenceNumber));

    }
    catch
    {
        ttsAbort;
        error("@DMS1832");
    }
}

No comments:

Post a Comment

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...