Tuesday 9 June 2015

PURCHASE ORDER INTEGRATION AX 2012 X++ CUSTOM WEB SERVICE

PURCHASE ORDER INTEGRATION AX 2012 
X++ CUSTOM WEB SERVICE

public void sendPOtoCRM()
{

    compPurchaseOrdertoCRMUat.PurchaseOrderReference.PurchaseOrderClient    service2;
    PurchTable                  purchTable;
    PurchLine                   purchLine,purchLineupd;
    VendPurchOrderJour          vendPurchOrderJour,vendPurchOrderJourupd;
    InventDim                   inventDim;
    ConfigChoice                configChoice;
    InventTable                 inventTable;
    str                         _success;
    TaxTable                    taxtable;
    int                         qty;
    str                         component,sfilepath,sfilename,sfileext,sfullname;
    container                   conTax,conChar,concharges,confiledetails;
    int                         i,j,k,f;
    System.Exception            ex;
    System.Type                 type;
    str                         taxinfo,taxcomp,taxvalue,charname,charvalue,markupAmount;
    str                         conchargesinfo,contaxinfo,concharinfo,strfiledetails;
    TmpTaxWorkTrans             tmpTax;
    PurchTotals                 purchTotals;
    PurchLine_IN                purchLine_In;
    SalesTaxFormTypes_IN        salesTaxFormTypes_IN;
    Transtxt                    transTxt;
    MarkupAmount                markupAmounttest;
    MarkupTrans                 markupTrans;
    DocuRef                     docuRef;
    DocuValue                   docuValue;
    VendPackingSlipTrans        tempVPST;
    compProductMasterDefault     prodMasterDef;
    //changes for multiple PO lines
    TaxTmpWorkTransForm         taxTmpWorkTransForm;
    TaxPurch                    taxPurch;

    select * from prodMasterDef;

   while select purchLine
            join purchTable  where  purchTable.PurchId == purchLine.PurchId && purchLine.comp_IsPurchlineSend == NoYes::No
           // join vendPurchOrderJour where vendPurchOrderJour.PurchId == purchTable.PurchId
    {

     try
       {
            type    = CLRInterop::getType('compPurchaseOrdertoCRMUat.PurchaseOrderReference.PurchaseOrderClient');
            service2 = AifUtil::createServiceClient(type);

            //purchTable  = PurchTable::find(_purchTable.PurchId);
            purchTotals = purchTotals::newPurchTable(purchTable);

           select reverse vendPurchOrderJour where vendPurchOrderJour.PurchId == purchTable.PurchId;

         //   select purchLine where purchLine.PurchId == purchTable.PurchId;
            select purchLine_In where purchLine_In.PurchLine == purchLine.recid;
            select salesTaxFormTypes_IN where salesTaxFormTypes_IN.RecId == purchLine_In.SalesTaxFormTypes_IN;
            select inventDim where inventDim.inventDimId == purchLine.InventDimId;

            purchTotals.calc();
            tmpTax.setTmpData(purchTotals.tax().tmpTaxWorkTrans());

             // Showing taxes with tax value
             conTax = conNull();
             while   select tmpTax where tmpTax.sourcerecid ==purchline.recid && tmpTax.sourcetableid == purchline.tableid
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component   = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
                taxcomp     = component;
                taxvalue    = num2str(abs(tmpTax.TaxAmount/(purchline.PurchQty)),0,2,1,2); //changes
                conTax      = conins(conTax,i,taxcomp+':'+taxvalue);
            }
                contaxinfo = con2StrUnlimited(conTax,'|');
                i=0;

               // send characteristics value
                conchar = connull();
             while select configChoice  where configChoice.ConfigId == InventDim.configId && configChoice.ItemId == purchLine.itemid
            {
                inventTable.clear();
                select inventTable where inventTable.ItemId == configChoice.chosenitemid;
                j++;
                charname    = inventTable.comp_CharacteristicName;
                charvalue   = inventTable.comp_CharacteristicValue;
                conchar     = conIns(conchar,j,charname+':'+charvalue);
            }
               concharinfo = con2StrUnlimited(conchar,'|');
               j =0;

                concharges = conNull();
            while select * from MarkupTrans  where MarkupTrans.TransTableId == purchline.TableId
                                                && MarkupTrans.TransRecId == purchline.RecId
            {
                k++;
                transTxt     = MarkUpTrans.Txt;
                if(transTxt == "Cost of FOC Product")
                    markupAmount =  num2str((MarkUpTrans.Value*purchline.PurchQty),0,2,1,2);
                else
                    markupAmount =  num2str((abs(MarkUpTrans.Value)),0,2,1,2);
                //markupAmount =  num2str((MarkUpTrans.Value*purchline.PurchQty),0,2,1,2);  changes sameer

                concharges = conins(concharges,k,transTxt+':'+markupAmount);
            }

               conchargesinfo = con2StrUnlimited(concharges,'|');
               k=0;


                confiledetails = conNull();
           while select docuRef where  docuRef.refrecid == purchTable.RecId && docuRef.RefCompanyId == purchTable.dataAreaId
                                    && docuRef.RefTableId == purchTable.TableId
            {
                f++;
                select docuValue where docuValue.RecId == docuRef.ValueRecId;
                sfilename = docuValue.FileName;
                sfilepath = docuRef.path();
                sfileext  = docuValue.FileType;
                sfullname = sfilepath + sfilename + "." +sfileext;
                confiledetails = conins(confiledetails,f,sfullname+':'+enum2Value(docuRef.comp_FileOrderType)+':'+enum2value(docuRef.comp_FileType));
               // info(strFmt("%1\%2 %3 %4 %5",docuRef.path(),docuValue.FileName,docuRef.comp_FileOrderType,docuRef.comp_FileType));
            }
               strfiledetails = con2StrUnlimited(confiledetails,'|');
               f=0;

           _success = service2.Synchronize_PurchaseOrder(PurchTable.purchid,
           VendPurchOrderJour.PurchOrderDate,enum2str(PurchTable.DocumentState),inventdim.InventSiteId,inventdim.InventLocationId,purchLine.ItemId,
           concharinfo,real2int(purchLine.PurchQty),purchLine.PurchPrice,purchTable.CurrencyCode,purchTable.payment,purchTable.DlvTerm,
           purchTable.comp_IncoTerms,purchTable.comp_DoAmount,purchTable.comp_DoDate,conchargesinfo,conTaxinfo,purchTable.comp_ManualExcise,
        str2int(purchTable.comp_ExciseDutyRefund),VendPurchOrderJour.Amount,purchTable.comp_FocInformation,purchTable.comp_FinancerUnderHyp,
        purchLine.TaxGroup,purchTable.OrderAccount,strfiledetails,SalesTaxFormTypes_IN.FormType,enum2str(purchTable.comp_SalesTypeExciseDuty),enum2str(purchLine.comp_WarrantyCode));

           info(strFmt("%1-%2-%3-%4-%5-%6-%7-%8-%9-%10-%11-%12-%13-%14-%15-%16-%17-%18-%19-%20-%21-%22-%23-%24-%25-%26-%27-%28-%29",PurchTable.purchid,
           VendPurchOrderJour.PurchOrderDate,enum2str(PurchTable.DocumentState),inventdim.InventSiteId,inventdim.InventLocationId,purchLine.ItemId,
           concharinfo,real2int(purchLine.PurchQty),purchLine.PurchPrice,purchTable.CurrencyCode,purchTable.payment,purchTable.DlvTerm,
           purchTable.comp_IncoTerms,purchTable.comp_DoAmount,purchTable.comp_DoDate,conchargesinfo,conTaxinfo,purchTable.comp_ManualExcise,
        str2int(purchTable.comp_ExciseDutyRefund),VendPurchOrderJour.Amount,purchTable.comp_FocInformation,purchTable.comp_FinancerUnderHyp,
        purchLine.TaxGroup,purchTable.OrderAccount,strfiledetails,SalesTaxFormTypes_IN.FormType,enum2str(purchTable.comp_SalesTypeExciseDuty),enum2str(purchLine.comp_WarrantyCode)));
                  if(_success != "Success")
                {
                    error(strFmt("%1 for PO %2",_success,purchTable.PurchId));
                }
                else
                {
                    ttsBegin;
                    select forUpdate purchLineupd where purchLineupd.PurchId == purchTable.PurchId && purchLineupd.ItemId == purchLine.ItemId;
                    purchLineupd.comp_IsPurchlineSend = NoYes::Yes;
                    purchLineupd.update();
                    ttsCommit;
                    info(strFmt(" %1 is created in CRM",purchTable.PurchId));
                }
        }//try

        catch(Exception::CLRError)
        {
            ex = CLRInterop::getLastException();
            info(CLRInterop::getAnyTypeForObject(ex.ToString()));
        }
        comp_RetailExceptionActivityLog::logEvent(strFmt("Purch Order Creation %1:",PurchTable.purchid),infolog.export());
    }//while
    //comp_RetailExceptionActivityLog::logEvent('Purch Order Creation:',infolog.export());
  //  comp_RetailExceptionActivityLog::logEvent(strFmt("Purch Order Creation %1:",PurchTable.purchid),infolog.export());


}

No comments:

Post a Comment

AZURE INTERVIEW QUESTIONS AND ANSWERS

AZURE INTERVIEW QUESTIONS AND ANSWERES 2021 2. What is cloud computing? Explanation:  It is the use of servers on the internet to “store...