Search This Blog

Showing posts with label ax 2012. Show all posts
Showing posts with label ax 2012. Show all posts

Saturday, 24 October 2015

SQL CODE TO SCHEDULING SQL BACKUP SCHEDULING

SQL CODE TO SCHEDULING SQL BACKUP SCHEDULING
vikas mehta

DECLARE @FOLDERPATH VARCHAR(500)

DECLARE @FOLDERPATHWITHNAME VARCHAR(500)

Declare @NAME Varchar(200)

Declare @DATE Varchar(200)

Declare @TIME Varchar(200)

Declare @TIME1 Varchar(200)

--JUST NEED TO UPDATE BELOW PATH FOR DB BACKUP LOCATION

Set @FOLDERPATH = '\\path\'

select @TIME1 = Convert(time, getdate())

select @DATE = (select convert(varchar,getDate(),112))

select @TIME = ((select Convert(Varchar, DATEPART(mm, @TIME1))) + (Select CONVERT(Varchar, DATEPART(ss, @TIME1))))

Select @NAME = ax + '_' + @DATE --+ @TIME

Set @FOLDERPATHWITHNAME = @FOLDERPATH + @NAME + '.bak'

BACKUP DATABASE [ax] TO DISK = @FOLDERPATHWITHNAME WITH NOFORMAT, NOINIT, NAME = @NAME, SKIP, NOREWIND, NOUNLOAD, STATS = 10

**********script*******************************
USE [msdb]
GO

/****** Object:  Job [Ax Prod Backup Schedule]    Script Date: 6/12/2015 3:17:03 PM ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [[Uncategorized (Local)]]    Script Date: 6/12/2015 3:17:03 PM ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'Ax Prod Backup Schedule',
                                @enabled=1,
                                @notify_level_eventlog=0,
                                @notify_level_email=0,
                                @notify_level_netsend=0,
                                @notify_level_page=0,
                                @delete_level=0,
                                @description=N'No description available.',
                                @category_name=N'[Uncategorized (Local)]',
                                @owner_login_name=N'vikasvikas\axaosadmin', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [Ax prod Step 1]    Script Date: 6/12/2015 3:17:04 PM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Ax prod Step 1',
                                @step_id=1,
                                @cmdexec_success_code=0,
                                @on_success_action=1,
                                @on_success_step_id=0,
                                @on_fail_action=2,
                                @on_fail_step_id=0,
                                @retry_attempts=0,
                                @retry_interval=0,
                                @os_run_priority=0, @subsystem=N'TSQL',
                                @command=N'DECLARE @FOLDERPATH VARCHAR(500)

DECLARE @FOLDERPATHWITHNAME VARCHAR(500)

Declare @NAME Varchar(200)

Declare @DATE Varchar(200)

Declare @TIME Varchar(200)

Declare @TIME1 Varchar(200)

--JUST NEED TO UPDATE BELOW PATH FOR DB BACKUP LOCATION

Set @FOLDERPATH = ''\\sql bkup\''

select @TIME1 = Convert(time, getdate())

select @DATE = (select convert(varchar,getDate(),112))

select @TIME = ((select Convert(Varchar, DATEPART(mm, @TIME1))) + (Select CONVERT(Varchar, DATEPART(ss, @TIME1))))

Select @NAME = ''MicrosoftDynamicsAX'' + ''_'' + @DATE --+ @TIME

Set @FOLDERPATHWITHNAME = @FOLDERPATH + @NAME + ''.bak''

BACKUP DATABASE [MicrosoftDynamicsAX] TO DISK = @FOLDERPATHWITHNAME WITH NOFORMAT, NOINIT, NAME = @NAME, SKIP, NOREWIND, NOUNLOAD, STATS = 10

',
                                @database_name=N'master',
                                @flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'AX 2012 Prod Job Schedule',
                                @enabled=1,
                                @freq_type=4,
                                @freq_interval=1,
                                @freq_subday_type=1,
                                @freq_subday_interval=0,
                                @freq_relative_interval=0,
                                @freq_recurrence_factor=0,
                                @active_start_date=20150421,
                                @active_end_date=99991231,
                                @active_start_time=235900,
                                @active_end_time=235959,
                                @schedule_uid=N'cddf7f74-3c12-414c-ab66-c12b7bc4628f'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:

AX 2012 SALES TRADE AGGREMENTS UPLOAD FROM EXCEL X++ CODE

AX 2012 SALES TRADE AGGREMENTS UPLOAD FROM EXCEL X++ CODE

        class VIK_SalesMaster_ExcelImport extends RunBaseBatch
        {
             DialogField                         dialogfile;
             FilenameOpen                        fileName;
             localmacro.CurrentList
              fileName
            endmacro
        }
     
       dialog
        protected Object dialog()
        {
            DialogRunbase  _dialog = super();
       
            _dialog.caption("Sales : Trade Aggrement Upload");
            dialogfile = _dialog.addField("FilenameOpen","Enter file path : ");
            dialogfile.value(fileName);
       
            return _dialog;
        }
     
       getFromDialog
        public boolean getFromDialog()
        {
            ;
            fileName = dialogfile.value();
            return true;
        }
     
       run
        public void run()
        {
            SysExcelApplication excel;
            SysExcelWorkbooks workbooks;
            SysExcelWorkbook workbook;
            SysExcelWorksheets worksheets;
            SysExcelWorksheet worksheet;
            SysExcelCells cells;
            COMVariantType type;
            int row =1;
            int _noofprints;
            CustName name;
            int i,j;
            //sales price upload
            str queryPricingMaster,itemId,existingItemIdsList,tempValue;
            ResultSet resultSet;
            InventTable inventTable;
            AifEntityKeyList                        keys;
            DD_HI_RRP_Staging                       RRPStaging;
            PricePriceDiscJournalService            PriceDiscSvc;
            PricePriceDiscJournal                   PriceDiscJour;
            PricePriceDiscJournal_PriceDiscAdmTrans PriceDiscJourAdmTrans;
            PricePriceDiscJournal_InventDim         PriceDiscJourDim;
            PriceDiscAdmTrans   _PriceDiscAdmTrans;
            //vikas
            PriceDiscAdmTable                   priceDiscAdmTable;
            PriceDiscAdmTrans                   PriceDiscAdmTrans;
            PriceDiscAdmName                    PriceDiscAdmName;
            PriceDiscJournalName                pricediscjournalName;
            NumberSeq journalNum;
            //sales price upload//
            str _relation,_accountcode,_accountselection,_itemcode,_temrelation,_unit,_curcode;
            real _from,_amtincur;
            date _todate,_fromdate;
            PriceType _pricetype;
            itemId tempItemId;
            AviFiles
            SysOperationProgress progress1 = new SysOperationProgress();
            ;
       
        //excel
        define.filename(fileName)
        excel = SysExcelApplication::construct();
        workbooks = excel.workbooks();
        try
        {
        workbooks.open(filename);
        }
        catch (Exception::Error)
        {
        throw error("File cannot be opened");
        }
       
       
                workbook = workbooks.item(1);
                worksheets = workbook.worksheets();
                worksheet = worksheets.itemFromNum(1);
                cells = worksheet.cells();
                type = cells.item(row+1, 1).value().variantType();
       
            //progress1.setCaption("Updation of pricing master is in progress…");
            //progress1.setAnimation(AviUpdate);
       
       
       
         ttsBegin;
       
            Select firstOnly  PriceDiscAdmName;
            priceDiscAdmTable.clear();
            priceDiscAdmTable.initFromPriceDiscAdmName(PriceDiscAdmName);
            journalNum      = NumberSeq::newGetNum(SalesParameters::numRefPriceDiscJournalNum());
            pricediscjournalName        =   journalNum.num();
            priceDiscAdmTable.JournalNum = pricediscjournalName;
            priceDiscAdmTable.insert();
       
           while (type != COMVariantType::VT_EMPTY)
        {
            row++;
            tempItemId  = cells.item(Row,5).value().bStr();
                // Set PriceDiscJourAdmTrans
                  while select forUpdate * from inventTable where inventTable.ItemId == tempItemId
                {
       
                   // progress1.setText(strfmt("Item ID  %1", tempItemId));
                    PriceDiscAdmTrans.clear();
                    PriceDiscAdmTrans.JournalNum        = pricediscjournalName;
                    PriceDiscAdmTrans.relation          = real2int(cells.item(Row,1).value().double()) ;//relation
                    PriceDiscAdmTrans.InventDimId       = "Allblank";
                    PriceDiscAdmTrans.DisregardLeadTime = NoYes::Yes;
                    PriceDiscAdmTrans.AccountCode       = real2int(cells.item(Row,2).value().double()) ; //account code
                    PriceDiscAdmTrans.AccountRelation   = cells.item(Row,3).value().bStr();     //account relation
                    PriceDiscAdmTrans.ItemCode          = real2int(cells.item(Row,4).value().double());
                    PriceDiscAdmTrans.ItemRelation      = cells.item(Row,5).value().bStr();         //item realtaion item id
                    PriceDiscAdmTrans.QuantityAmountFrom= cells.item(Row,6).value().double();        //from quantity
                    PriceDiscAdmTrans.UnitId            = cells.item(Row,7).value().bStr();            //unit id
                    PriceDiscAdmTrans.Amount            = cells.item(Row,8).value().double();         //Amount in Curr
                    PriceDiscAdmTrans.Currency          = cells.item(Row,9).value().bStr();        //currency code
                    PriceDiscAdmTrans.FromDate          = cells.item(Row,10).value().date();        //from date
                    PriceDiscAdmTrans.ToDate            = cells.item(Row,11).value().date();         //todate
                    PriceDiscAdmTrans.insert();
                    itemId=inventTable.ItemId;
       
                }
                 type = cells.item(row+1, 1).value().variantType();
        }
            ttsCommit;
        excel.quit();
        }
     
       main
        public static void main(Args _args)
        {
            VIK_SalesMaster_ExcelImport    VIK_SalesMaster_ExcelImport = new VIK_SalesMaster_ExcelImport();
       
       
             if(VIK_SalesMaster_ExcelImport.prompt())
                VIK_SalesMaster_ExcelImport.run();
        }
      

AX 2012 MAP X++ FOR EXISTING RECORDS MAP INSERT MAP CHECK MAP LOOKUP

AX 2012 MAP X++ FOR EXISTING RECORDS

MAP for Exist in excel upload
public void run()
{
    SysExcelApplication     excel;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    SysExcelCell            cell;

    SysExcelStyles          styles;
    SysExcelStyle           estyle;
    SysExcelFont            font;


    int                     row = 1;

    //vikas
    ProdTable               prodTable,prodTableRef,prodtabledate;
    InventDim               inventDim;
    int                     total1,total2,total3,total4,total5,total6;
    SysExcelWorksheetHelper worksheetHelper;
    SysExcelRange           range;
    ItemId                  itemId;
    InventOnhand            inventonHand;
    inventDim               inventDimRef;
    InventDimParm           inventDimParm;
    WrkCtrCapRes            WrkCtrCapRes1,WrkCtrCapRes2,WrkCtrCapRes3;
    WrkCtrTable             wrkCtrTable1,wrkCtrTable2,wrkCtrTable3;
    int                     x,y,z,j,k,l,fordays,mapi,mapint;
    WrkCtrIdBase            machine;
    SchedFromDate           mindate,mindateLess,mapdatefind,fordate;
    SchedToDate             maxdate1;
    date               strdate;
    str                 dateinstring;
    TransDate               transdate;

    Map                     map = new Map(Types::String,Types::Integer);
    Map                     mapintkey = new Map(Types::Integer,Types::String);

    InventTrans            inventTransTable;
   
    int                     days;

    str itemOrginStatus;


    excel = SysExcelApplication::construct();
    workbooks = excel.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();

    styles = workbook.styles();
    estyle  = styles.add("Header");
    font = estyle.font();
    font.bold(true);

    cell = cells.item(1, 1);
    cell.font().bold(true);
    cell.value('MONTH PRODUCTION PLANNING');
    //ITEM    PLAN    OPN STK    BAL TO BE PRODUCED    MTD    Operation    M/C

    cell = cells.item(3, 1);
    cell.value('SIZE');
    cell = cells.item(3, 2);
    cell.value('TYPE');
    cell = cells.item(3, 3);
    cell.value('PLAN');
    cell = cells.item(3, 4);
    cell.value('OPN STK');
    cell = cells.item(3, 5);
    cell.value('BAL TO BE PRODUCED');
    cell = cells.item(3, 6);
    cell.value('MTD    Operation');//NO OF
    cell = cells.item(3, 7);
    cell.value('M/C');
    row = 3;
    select maxof(SchedStart) from prodtabledate where prodtabledate.InventRefId == 'P000179';
    maxdate1 = prodtabledate.schedstart;
    prodtabledate.clear();
    select minof(SchedStart) from prodtabledate where prodtabledate.InventRefId == 'P000179';
    mindate = prodtabledate.schedstart;
    mindateLess = mindate -1;
     days = date2num(maxdate1) - date2num(mindate);
     fordays = days+10;
    for(j=10;j<fordays;j++)
    {
        map.insert(mindateLess+1,j);
        mindateLess = mindateLess+1;
    }
    //mapintkey
    for(mapi=10;mapi<fordays;mapi++)
    {
        mapintkey.insert(mapi,mindateLess+1);
        mindateLess = mindateLess+1;
    }
    //mapdate = 2015/9/23  ...9/28/2015
    for(k=10;k<fordays;k++)
    {
        cell = cells.item(3, k);
         if (Mapintkey.exists(k))
        {
            strdate = Mapintkey.lookup(k);
            dateinstring = Mapintkey.lookup(k);
        }
       // strdate = date2str(transdate,321,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits1or2,dateSeparator::Slash, DateYear::Digits4);
        cell.value(Mapintkey.lookup(dateinstring));

    }

    //map.insert('2', 'ew');
    //info(strFmt("%1",map.lookup(2)));

 while select prodTable join InventDim   where prodTable.ProdId == 'P000179' && prodTable.InventDimId == InventDim.inventDimId
   {
           // itemId = prodTable.ItemId;
             row= row+1;
             cell = cells.item(row, 1);
             cell.value(InventDim.InventSizeId);
             cell = cells.item(row, 2);
             cell.value(InventDim.InventColorId);
    while select prodTableRef join inventDimRef where prodTableRef.InventRefId == prodTable.ProdId
       {
            //row = row+1;
            cell = cells.item(row, 3); //plan
            cell.value(prodTableRef.qtysched);

            itemId = prodTable.ItemId;
            InventDimParm.initFromInventDim(inventDimRef);
            inventonHand = inventonHand::newParameters(itemId,inventDimRef,InventDimParm);
            cell = cells.item(row, 4); //
            cell.value(inventonHand.availPhysical());
            itemId = prodTable.ItemId;

            cell = cells.item(row, 5); //plan
            cell.value(prodTableRef.qtysched - inventonHand.availPhysical());
           //cell = cells.item(row, 6); //plan
            //cell.value(prodTableRef.qtysched - inventonHand.availPhysical());

            cell = cells.item(row, 7); //pool
            cell.value(prodTableRef.ProdPoolId);


            while select WrkCtrCapRes1 order by WrkCtrId,transdate where WrkCtrCapRes1.RefId == prodTableRef.ProdId && WrkCtrCapRes1.RefType == 1 //&& WrkCtrCapRes1.WrkCtrId == "BREHM-1"
           {   x = 8;y =10;//z=2;
               wrkCtrTable1.clear();
               select wrkCtrTable1 where wrkCtrTable1.Name == WrkCtrCapRes1.WrkCtrId;
               machine = WrkCtrCapRes1.WrkCtrId;
               cell = cells.item(row,8 ); //machine
               cell.value(machine);
                cell = cells.item(row, 9); //actual
                cell.value('Actual');
                row = row +1;
                cell = cells.item(row, 9); //plan
                cell.value('Plan');
                 if (Map.exists(WrkCtrCapRes1.TransDate))
                {
                    mapint = Map.lookup(WrkCtrCapRes1.TransDate);
                }
                cell = cells.item(row,mapint);
                cell.value(WrkCtrCapRes1.WrkCtrHours()*wrkCtrTable1.capacity);
            }


       }
   
        }


    worksheet.columns().autoFit();
    excel.visible(true);

}

INVENTTABLE AND ECORESPRODUCT RELATION JOIN QUERY LINK ECORESCATEGORY

INVENTTABLE AND ECORESPRODUCT RELATION 
JOIN QUERY LINK ECORESCATEGORY

InventTable and ECORESPRODUCT
select ecorescategorygroc where ecorescategorygroc.Name == catgnames;
    while select * from inventTable join product where inventTable.Product == product.RecId
                    join    productCat  where productCat.Product  == product.RecId
                    join    category    where   category.RecId      == productCat.Category && category.Name == catgnames//category.ParentCategory == ecorescategorygroc.RecId// && category.Name == catgnames
                    join catHierarchy   where   catHierarchy.RecId  == category.CategoryHierarchy//
                             && inventTable.itemid like


PURCHASE ORDER CATEGORY PRODUCT RECEIPT CALLER CLASS

Purchase category
1.       PO invoice and product receipt

Changes have been done in the forms clicked ok methods of post and close ok
Blow is code for product receipt
// po category start

    VendPackingSlipJour         vendPackingSlipJour;
    Vik_PurchaseOrderCategory   poCategory;
    int                         daydiff,prodreceiptcount;
    PurchTable                  purchTableLocal;

    if(curext() == 'SDS')
    {
        if( classidget(purchFormLetter) == classnum(PurchFormLetter_PackingSlip)) //&& (purchTable.Vik_PurchaseCategory != Vik_PurchaseCategory::None))
        {
            select purchTableLocal where purchTableLocal.PurchId == purchFormLetter.purchTable().PurchId;
            select poCategory where poCategory.Vik_PurchaseCategory == purchTableLocal.Vik_PurchaseCategory;
            select count(RecId) from vendPackingSlipJour where vendPackingSlipJour.PurchId == purchTableLocal.PurchId;

            prodreceiptcount = int642int(vendPackingSlipJour.RecId);

            if(prodreceiptcount > poCategory.DeliveryTimes)
                throw error(strFmt(" The Product receipt for Purchase Order %1 has exceeded for the category %2",purchTableLocal.PurchId,purchTableLocal.Vik_PurchaseCategory));
        }

    }
 //   po category end

Below is code for Invoice

void clicked()
{
    // po category start

    Vik_PurchaseOrderCategory   poCategory;
    int                         daydiff,prodreceiptcount;
    PurchTable                  purchTableLocal;



    if(curext() == 'SDS')
    {
        select purchTableLocal where purchTableLocal.PurchId == purchFormLetter.purchTable().PurchId;
        if( classidget(purchFormLetter) == classnum(PurchFormLetter_Invoice) && (purchTable.Vik_PurchaseCategory != Vik_PurchaseCategory::None))
        {
           
            select poCategory where poCategory.Vik_PurchaseCategory == purchTableLocal.Vik_PurchaseCategory;
          //  daydiff = purchTableLocal.createdDateTime - DateTimeUtil::getSystemDateTime();
            daydiff = DateTimeutil::getDifference(DateTimeUtil::getSystemDateTime(), purchtablelocal.createddatetime) / 86400;
            if(daydiff > poCategory.ExpireDays)
                throw error(strFmt(" The Purchase Order %1 has exceeded the expire days for the category %2",purchTableLocal.PurchId,purchTableLocal.Vik_PurchaseCategory));
        }

    }
 //   po category end
    // <GEERU>
    if (SysCountryRegionCode::isLegalEntityInCountryRegion([ #isoRU ]) && ! purchFormLetter.checkBeforePost())
    {
        return;
    }
    // </GEERU>
    super();
}


Tuesday, 9 June 2015

SALES ORDER INTEGRATION WITH CRM : AX 2012

SALES ORDER INTEGRATION WITH CRM : AX 2012

SEND CONFIRMED SALES ORDER TO CRM

public void run()
{

    compSalesInvoicetoCRMUat.compSalesInvoiceReference.SalesInvoiceClient    service;
    compSalesInvoicetoCRMUat.compSalesInvoiceReference.ISalesInvoice         salesinvoice;

    CustInvoiceJour     custInvoiceJour,custInvoiceJourupd;
    CustInvoiceTrans    custInvoiceTrans;
    InventDim           inventDim;
    InventTrans         inventTrans;
    InventTable         inventTable,inventTablechar;
    ConfigChoice        configChoice;
    str                 success;
    int                 qty;
  //  int x=1;
    System.Exception        ex;
    System.Type             type;
    compProductMasterDefault prodMasterDef;

    select * from prodMasterDef;
    changeCompany(prodMasterDef.DealerCompany)
    {
    while select custInvoiceJour
                join custInvoiceTrans where   custInvoiceJour.SalesId           == custInvoiceTrans.SalesId
                                            && custInvoiceJour.comp_IsInvoiceSent == NoYes::No
                                            && custInvoiceJour.InvoiceId         == custInvoiceTrans.InvoiceId
                join inventTable    where inventTable.ItemId == custInvoiceTrans.ItemId
    {
   try
   {
        type    = CLRInterop::getType('compSalesInvoicetoCRMUat.compSalesInvoiceReference.SalesInvoiceClient');
        service = AifUtil::createServiceClient(type);

        inventDim.clear();
        select inventTrans where custInvoiceTrans.InvoiceId == inventTrans.InvoiceId;
        select inventDim   where inventTrans.InventDimId == inventDim.inventDimId;

        success = service.Synchronize_Invoice(custInvoiceJour.SalesId,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceAccount,custInvoiceTrans.ItemId,custInvoiceTrans.SalesPrice,inventDim.inventSerialId,real2int(custInvoiceTrans.Qty),custInvoiceJour.InvoiceAmount,custInvoiceJour.SumTax,custInvoiceJour.invoicedate);
info(strFmt("%1-%2-%3-%4-%5-%6-%7-%8-%9-%10",custInvoiceJour.SalesId,custInvoiceJour.InvoiceId,custInvoiceJour.InvoiceAccount,custInvoiceTrans.ItemId,custInvoiceTrans.SalesPrice,inventDim.inventSerialId,real2int(custInvoiceTrans.Qty),custInvoiceJour.InvoiceAmount,custInvoiceJour.SumTax,custInvoiceJour.invoicedate));
        if(success != "Success")
        {
            error(strFmt("Error %1 for SO %2",success,custInvoiceJour.SalesId));
        }
        else
        {
            ttsBegin;
            select forUpdate custInvoiceJourupd where custInvoiceJourupd.InvoiceId == custInvoiceJour.InvoiceId;
            custInvoiceJourupd.comp_IsInvoiceSent = NoYes::Yes;
            custInvoiceJourupd.update();
            ttsCommit;
            info(strFmt("Sales Invoice %1 is created in CRM",custInvoiceJour.SalesId));
        }
  }//try
  catch(Exception::CLRError)
    {
        ex = CLRInterop::getLastException();
        info(CLRInterop::getAnyTypeForObject(ex.ToString()));
    }
         comp_RetailExceptionActivityLog::logEvent(strFmt('Sales Invoice ID:',custInvoiceJour.SalesId),infolog.export());
     }//while
   // comp_RetailExceptionActivityLog::logEvent('Product Import',infolog.export());
    }
}



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());


}

CUSTOMER UPDATION AX 2012 X++ CUSTOM WEB SERVICE

CUSTOMER UPDATION AX 2012 
X++ CUSTOM WEB SERVICE

Customer Integration Update
[AifCollectionTypeAttribute('return', Types::String), SysEntryPointAttribute(true)]
public str UpdateCustomer(custAccount _custaccount,Name _name,CustGroupId _customerGroup,CustDlvTermId _delvTerms,CustPaymTermId _paymTerms,CustDlvModeId _delvMode,
                            CurrencyCode _currency,comp_AccountGroup _accountGroup, comp_CurrentFleetSize comp_CurrentFleetSize, comp_Dealer _dealer,comp_CurrentFleetSize _currentFleetSize,
                            comp_CustomerBusinessModel _customerBusinessModel,comp_CustomerSegment _customerSegment,comp_CustomerProfile _customerProfile,comp_DeliveringPlant _deliveringPlant ,comp_deliveryPriority _deliveryPriority,
                            comp_DistributionChannel _distributionChannel,comp_ExciseIndicator _exciseIndicator,comp_ExciseRegistrationNumber _exciseRegistrationNumber,comp_Industry _industry,comp_Jtx1 _jtx1,comp_Jtx2 _jtx2,comp_Jtx3 _jtx3,comp_Jtx4 _jtx4,
                            comp_Ownership _ownership, comp_PrimaryContact primarycontact,comp_SapCustomerCode _sapcustomercode,comp_SortKey _sortkey,  TaxGroup _salesTaxGroup,  VATNum _taxExemptionNo,
                            LogisticsElectronicAddressLocator _phone,  LogisticsElectronicAddressLocator _extension,LogisticsElectronicAddressLocator _fax, LogisticsElectronicAddressLocator _emailAddress ,TaxRegistrationNumber_IN _eccNumber,LogisticsAddressCountryRegionId     _countryRegion,LogisticsAddressZipCodeId  _postal,LogisticsAddressStreet  _street,
                            LogisticsAddressBuildingCompliment _buildingComponent, LogisticsAddressStreet _street3,LogisticsAddressCity  _city ,
                            LogisticsAddressStateId _state , LogisticsAddressDistrictName  _district,LogisticsAddressCountryRegionId  _countryRegion1,LogisticsAddressZipCodeId  _postal1,   LogisticsAddressStreet _street1,
                            LogisticsAddressBuildingCompliment _buildingComponent1,LogisticsAddressStreet _street31,LogisticsAddressCity  _city1,LogisticsAddressStateId _state1,
                            LogisticsAddressDistrictName  _district1,   TaxRegistrationNumber_IN _iecNumber,TaxRegistrationNumber_IN _salesTaxRegNumber,
                            TaxRegistrationNumber_IN _tanNumber,PANNumber_IN _panNumber )

{
    CustTable                       custtable;
    DirParty                        dirParty;
    DirPartyRecId                   partyRecId;
    DirPartyPostalAddressView       postaladdressView,dirPartyPostalAddressView;
    DirPartyContactInfoView         contactView,dirPartyContactInfo,dirPartyContactInfoEmail,dirPartyContactInfoFax;
    DirPartyLocation                dirpartylocation;
    TaxInformation_IN               TaxInformation_IN,TaxInformation_IN_exist,TaxInformation_IN_records,TaxInformation_IN_update;
    TaxInformationCustTable_IN      TaxInformationCustTable_IN,TIC_exist,TIC_count,tic_update;
    TaxRegistrationNumbers_IN       TaxRegistrationNumbers_IN_IEC,TaxRegistrationNumbers_IN_ecc,
                                    TaxRegistrationNumbers_IN_tan,TaxRegistrationNumbers_IN_salestax,TRN_exist,
                                    TRN_IN_IEC_upd,TRN_IN_ecc_upd,TRN_IN_tan_upd,TRN_IN_salestaxupd;
    int64                           _taxRecordcount;
    CustAccount                     custAccount;
    str                             namealias;
    DirPartyTable                   dirPartyTable;
    container                       roles_delivery,roles_invoice;
    str                             log,log_1,log_2,log_3,log_4,log_5,log_6,log_7;
    compProductMasterDefault         compMasterDefault;
    CustPaymTermId                  paymTermsstr;

    select * from compMasterDefault;
    _delvMode = "";
    paymTermsstr = _paymTerms;
    ttsBegin;
 if(_customerGroup != 'del')
    changeCompany(compMasterDefault.DealerCompany)
 {
     if((CustTable::exist(_custaccount) &&_custaccount != "") && _name !="" && CustGroup::exist(_customerGroup) && (DlvTerm::exist(_delvTerms) || _delvTerms == "")
            && (PaymTerm::exist(_paymTerms) || _paymTerms == "") && (DlvMode::exist(_delvMode) || _delvMode == "") )
      {
        select forUpdate custtable where custtable.AccountNum ==_custaccount;

        if(custtable)
        {
            ttsBegin;
            custtable.PaymTermId    = _paymTerms;
            custtable.DlvTerm       = _delvTerms;
            custtable.DlvMode       = _delvMode;
            custtable.TaxGroup      = _salesTaxGroup;//salestaxgroup
            custtable.VATNum        = _taxExemptionNo;
            custtable.comp_ExciseRegistrationNumber = _exciseRegistrationNumber;
            namealias = _name;
            postaladdressView.clear();
            select postaladdressView where postaladdressView.Party == custtable.Party && postaladdressView.IsPrimary == NoYes::Yes ;
            //{
                DirParty = DirParty::constructFromPartyRecId(postaladdressView.Party);
                postaladdressView.CountryRegionId   = _countryRegion;
                postaladdressView.State             = _state;
                postaladdressView.City              = _city;
                postaladdressView.ZipCode           = _postal;
                postaladdressView.Street            = _street;
                postaladdressView.BuildingCompliment= _buildingComponent;
                postaladdressView.PostBox           = _street3;
                postaladdressView.DistrictName      = _district;
                postaladdressView.LocationName      = _name;
                postaladdressView.Party             = custtable.Party;
                roles_invoice = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
                DirParty.createOrUpdatePostalAddress(postaladdressView,roles_invoice);

                //second address
                dirPartyPostalAddressView.clear();
            select dirPartyPostalAddressView where dirPartyPostalAddressView.Party == custtable.Party && dirPartyPostalAddressView.IsPrimary == NoYes::no ;
            {
                DirParty = DirParty::constructFromPartyRecId(dirPartyPostalAddressView.Party);
                dirPartyPostalAddressView.CountryRegionId        = _countryRegion1;
                dirPartyPostalAddressView.ZipCode                = _postal1;
                dirPartyPostalAddressView.Street                 = _street1;
                dirPartyPostalAddressView.BuildingCompliment     = _buildingComponent1;
                dirPartyPostalAddressView.PostBox                = _street31;
                dirPartyPostalAddressView.City                   = _city1;
                dirPartyPostalAddressView.State                  = _state1;
                dirPartyPostalAddressView.DistrictName           = _district1;
                dirPartyPostalAddressView.LocationName           = _name;//extra
                dirPartyPostalAddressView.IsPrimary              = NoYes::No;
                roles_delivery = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];
                dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,roles_delivery);

                select forUpdate dirPartyTable where dirPartyTable.RecId == custtable.Party;
                dirPartyTable.NameAlias        = _name;
                dirPartyTable.Name             = _name;
                dirPartyTable.update();
            }

              if(_Phone)
                {
                select  contactView where contactView.Party == custtable.Party && contactView.Type == LogisticsElectronicAddressMethodType::Phone;
                    {
                        dirParty = dirParty::constructFromPartyRecId(contactView.Party);
                        contactView.LocationName = "Phone";
                        contactView.Locator = _Phone;
                        contactView.locatorextension = _Extension;
                        contactView.Type = LogisticsElectronicAddressMethodType::Phone;
                        contactView.Party = custtable.Party;//dirParty.getPartyRecId();
                        contactView.IsPrimary = NoYes::Yes;
                        dirParty.createOrUpdateContactInfo(contactView);
                    }
                }
               if(_emailAddress)
                {   contactView.clear();
                    select contactView where contactView.Party == custtable.Party && contactView.Type == LogisticsElectronicAddressMethodType::Email;
                    {
                    DirParty = DirParty::constructFromPartyRecId(contactView.Party);
                    contactView.LocationName    = "Email Address";
                    contactView.Locator         = _emailAddress;
                    contactView.Type            = LogisticsElectronicAddressMethodType::Email;
                    contactView.Party           = custtable.Party;
                    contactView.IsPrimary       = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                    }
                }
             if(_Fax)
                {   dirPartyContactInfoFax.clear();
                    select dirPartyContactInfoFax where dirPartyContactInfoFax.Party == custtable.Party && dirPartyContactInfoFax.Type == LogisticsElectronicAddressMethodType::Fax;
                    {
                    DirParty = DirParty::constructFromPartyRecId(contactView.Party);
                    dirPartyContactInfoFax.LocationName = "Fax no update";
                    dirPartyContactInfofax.Type         = LogisticsElectronicAddressMethodType::Fax;
                    dirPartyContactInfofax.LocationName = _fax;
                    dirPartyContactInfofax.Party        = custtable.Party;
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfofax);
                    }
                }
             if(_panNumber)
                {//dealer
                //select TaxInformationCustTable_IN where TaxInformationCustTable_IN.PANNumber == _panNumber && TaxInformationCustTable_IN.CustTable == _custaccount;
                select TaxInformationCustTable_IN where TaxInformationCustTable_IN.CustTable == _custaccount;
                if(!TaxInformationCustTable_IN)
                    {
                        TaxInformationCustTable_IN.clear();
                        TaxInformationCustTable_IN.CustTable        = _custaccount;
                        TaxInformationCustTable_IN.PanStatus        = PANStatus_IN::Received;
                        TaxInformationCustTable_IN.PANNumber        = _panNumber;
                        TaxInformationCustTable_IN.NatureOfAssessee = NatureOfAssessee_IN::Company;
                        TaxInformationCustTable_IN.validateWrite();
                        {
                        TaxInformationCustTable_IN.insert();
                        }
                    }
                else
                    {
                    select forupdate tic_update where tic_update.CustTable == _custaccount;
                        tic_update.PANNumber = _panNumber;
                        tic_update.update();
                    }
                }//pan nuber
     if(_countryRegion == "IND")
       {
         select DirPartyLocation where DirPartyLocation.Party == custtable.Party && DirPartyLocation.IsPrimary == NoYes::Yes ;
         select TaxRegistrationNumbers_IN_IEC where TaxRegistrationNumbers_IN_IEC.RegistrationNumber == _IECNumber;
         select TaxRegistrationNumbers_IN_ecc where TaxRegistrationNumbers_IN_ecc.RegistrationNumber == _eccNumber;
         select TaxRegistrationNumbers_IN_tan where TaxRegistrationNumbers_IN_tan.RegistrationNumber == _tanNumber;
         select TaxRegistrationNumbers_IN_salestax where TaxRegistrationNumbers_IN_salestax.RegistrationNumber == _salesTaxRegNumber;

         select TaxInformation_IN_exist where  TaxInformation_IN_exist.RegistrationLocation == DirPartyLocation.Location
                                              && TaxInformation_IN_exist.ManECCRegistrationNumberTable == TaxRegistrationNumbers_IN_ecc.RecId
                                              && TaxInformation_IN_exist.SalesTaxRegistrationNumber ==  TaxRegistrationNumbers_IN_salestax.RecId
                                              && TaxInformation_IN_exist.TIN == TaxRegistrationNumbers_IN_tan.RecId
                                              && TaxInformation_IN_exist.IECRegistrationNumberTable == TaxRegistrationNumbers_IN_IEC.RecId ;
        if(!TaxInformation_IN_exist)
         {
             //changes for ta info TaxInformation_IN_exist
             select forUpdate TaxInformation_IN_exist
                where TaxInformation_IN_exist.RegistrationLocation == DirPartyLocation.Location
                        && TaxInformation_IN_exist.IsPrimary == NoYes::Yes;
             if(TaxInformation_IN_exist)
             {
                   {
                      TaxInformation_IN_exist.IsPrimary = NoYes::No;
                      TaxInformation_IN_exist.update();
                   }

             select count(RecId) from TaxInformation_IN_records where TaxInformation_IN_records.RegistrationLocation == DirPartyLocation.Location ;
                   _taxRecordcount = TaxInformation_IN_records.RecId;

             }

            if(_IECNumber)
            {
            //select TaxRegistrationNumbers_IN_IEC where TaxRegistrationNumbers_IN_IEC.RegistrationNumber == _IECNumber;
            if(!TaxRegistrationNumbers_IN_IEC)
                {
                TaxRegistrationNumbers_IN_IEC.RegistrationNumber = _IECNumber;
                TaxRegistrationNumbers_IN_IEC.IsGlobal           = NoYes::Yes;
                TaxRegistrationNumbers_IN_IEC.RefCompanyId       = "";
                TaxRegistrationNumbers_IN_IEC.TaxType            = TaxType_IN::Customs;
                TaxRegistrationNumbers_IN_IEC.RegistrationType   = TaxRegistrationType_IN::Customers;
                TaxRegistrationNumbers_IN_IEC.insert();
                }
            }

            if(_eccNumber)
            {
            if(!TaxRegistrationNumbers_IN_ecc)
                {
                    TaxRegistrationNumbers_IN_ecc.clear();
                    TaxRegistrationNumbers_IN_ecc.RegistrationNumber = _eccNumber;
                    TaxRegistrationNumbers_IN_ecc.IsGlobal           = NoYes::Yes;
                    TaxRegistrationNumbers_IN_ecc.RefCompanyId       = "";
                    TaxRegistrationNumbers_IN_ecc.TaxType            = TaxType_IN::Excise;
                    TaxRegistrationNumbers_IN_ecc.RegistrationType   = TaxRegistrationType_IN::Customers;
                    TaxRegistrationNumbers_IN_ecc.insert();
                }
            }

            if(_tanNumber)
            {
            if(!TaxRegistrationNumbers_IN_tan)
                {
                TaxRegistrationNumbers_IN_tan.clear();
                TaxRegistrationNumbers_IN_tan.RegistrationNumber = _tanNumber;
                TaxRegistrationNumbers_IN_tan.IsGlobal           = NoYes::Yes;
                TaxRegistrationNumbers_IN_tan.RefCompanyId       = "";
                TaxRegistrationNumbers_IN_tan.TaxType            = TaxType_IN::VAT;
                TaxRegistrationNumbers_IN_tan.RegistrationType   = TaxRegistrationType_IN::Customers;
                TaxRegistrationNumbers_IN_tan.insert();
                }
            }
            //_salesTaxRegistrationNumber
           if(_salesTaxRegNumber)
          {
            if(!TaxRegistrationNumbers_IN_salestax)
                {
                TaxRegistrationNumbers_IN_salestax.clear();
                TaxRegistrationNumbers_IN_salestax.RegistrationNumber = _salesTaxRegNumber;
                TaxRegistrationNumbers_IN_salestax.IsGlobal           = NoYes::Yes;
                TaxRegistrationNumbers_IN_salestax.RefCompanyId       = "";
                TaxRegistrationNumbers_IN_salestax.TaxType            = TaxType_IN::SalesTax;
                TaxRegistrationNumbers_IN_salestax.RegistrationType   = TaxRegistrationType_IN::Customers;
                TaxRegistrationNumbers_IN_salestax.insert();
                }
          }
        if(_IECNumber || _eccNumber || _tanNumber || _salesTaxRegNumber)
         {
           //  select forupdate TaxInformation_IN
            TaxInformation_IN.clear();
            TaxInformation_IN.Name = strFmt("%1 %2",_name,_taxRecordcount);
            TaxInformation_IN.IsPrimary = NoYes::Yes;
            if(_tanNumber)
            {
                TaxRegistrationNumbers_IN_tan.clear();
                select TaxRegistrationNumbers_IN_tan where TaxRegistrationNumbers_IN_tan.RegistrationNumber == _tanNumber;
                TaxInformation_IN.TIN = TaxRegistrationNumbers_IN_tan.recid;
            }
            if(_eccNumber)
            {
                TaxRegistrationNumbers_IN_ecc.clear();
                select TaxRegistrationNumbers_IN_ecc where TaxRegistrationNumbers_IN_ecc.RegistrationNumber == _tanNumber;
                TaxInformation_IN.ECCNumber = TaxRegistrationNumbers_IN_ecc.recid;
            }
            if(_IECNumber)
            {
                TaxRegistrationNumbers_IN_IEC.clear();
                select TaxRegistrationNumbers_IN_IEC where TaxRegistrationNumbers_IN_IEC.RegistrationNumber == _IECNumber;
                TaxInformation_IN.IECRegistrationNumberTable = TaxRegistrationNumbers_IN_IEC.recid;
            }
            if(_salesTaxRegNumber)
            {
                TaxRegistrationNumbers_IN_salestax.clear();
                select TaxRegistrationNumbers_IN_salestax where TaxRegistrationNumbers_IN_salestax.RegistrationNumber == _salesTaxRegNumber;
                TaxInformation_IN.SalesTaxRegistrationNumber = TaxRegistrationNumbers_IN_salestax.recid;
            }
            TaxInformation_IN.RegistrationLocation = DirPartyLocation.Location;
            TaxInformation_IN.insert();
         }//if all four tax  if(_IECNumber || _e
       }//if tax information exist
      }//if INR
     custtable.update();
     ttsCommit;
      log = strFmt("Success : Customer %1 updated successfully",_custaccount);
    }//if custtable
   }//if all exist
    else   //if all does not exist
    {

        if(!CustTable::exist(_custaccount))
            log_1 =  strFmt("The customer %1 already exist or cannot be blank",_custaccount);
        if(_name == "")
            log_2 =  strFmt("The customer name cannot be blank for Customer %1",_custaccount);
        if(!CustGroup::exist(_customerGroup) || _customerGroup == "")
            log_3 =  strFmt("The Customer group %1 does not exist or cannot be blank in AX for Customer %2",_customerGroup,_custaccount);
        if(!DlvTerm::exist(_delvTerms) && _delvTerms != "" )
            log_4 =  strFmt("The Delivery Terms %1 does not exist or cannot be blank in AX for Customer %2",_delvTerms,_custaccount);
        if(!PaymTerm::exist(_paymTerms) && _paymTerms != "" )
            log_5 =  strFmt("The Payment Terms %1 does not exist or cannot be blank in AX for Customer %2",_paymTerms,_custaccount);
        if((!DlvMode::exist(_delvMode) && _delvMode != ""))
            log_6 =  strFmt("The Delivery Mode %1 does not exist or cannot be blank in AX for Customer %2",_delvMode,_custaccount);
         log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_6);

    } //if customer exist
  } //change company if
     else
        {
            changeCompany(compMasterDefault.delCompany)

        if((CustTable::exist(_custaccount) &&_custaccount != "") && _name !="" && CustGroup::exist(_customerGroup) && (DlvTerm::exist(_delvTerms) || _delvTerms == "")
            && (PaymTerm::exist(_paymTerms) || _paymTerms == "") && (DlvMode::exist(_delvMode) || _delvMode == ""))
      {
        select forUpdate custtable where custtable.AccountNum ==_custaccount;

        if(custtable)
        {
            ttsBegin;
            custtable.PaymTermId    = _paymTerms;
            custtable.PaymTermId    = paymTermsstr;
            custtable.DlvTerm       = _delvTerms;
            custtable.DlvMode       = _delvMode;
            custtable.TaxGroup      = _salesTaxGroup;//salestaxgroup
            custtable.VATNum        = _taxExemptionNo;
            custtable.comp_ExciseRegistrationNumber = _exciseRegistrationNumber;
            namealias = _name;
            postaladdressView.clear();
            select postaladdressView where postaladdressView.Party == custtable.Party && postaladdressView.IsPrimary == NoYes::Yes ;
            //{
                DirParty = DirParty::constructFromPartyRecId(postaladdressView.Party);
                postaladdressView.CountryRegionId   =_countryRegion;
                postaladdressView.State             =_state;
                postaladdressView.City              =_city;
                postaladdressView.ZipCode           =_postal;
                postaladdressView.Street            =_street;
                postaladdressView.BuildingCompliment= _buildingComponent;
                postaladdressView.PostBox           = _street3;
                postaladdressView.DistrictName      = _district;
                postaladdressView.LocationName      = _name;
                postaladdressView.Party             = custtable.Party;
                roles_invoice = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
                DirParty.createOrUpdatePostalAddress(postaladdressView,roles_invoice);

                //second address
                dirPartyPostalAddressView.clear();
            select dirPartyPostalAddressView where dirPartyPostalAddressView.Party == custtable.Party && dirPartyPostalAddressView.IsPrimary == NoYes::no ;
            {
                DirParty = DirParty::constructFromPartyRecId(dirPartyPostalAddressView.Party);
                dirPartyPostalAddressView.CountryRegionId        = _countryRegion1;
                dirPartyPostalAddressView.ZipCode                = _postal1;
                dirPartyPostalAddressView.Street                 = _street1;
                dirPartyPostalAddressView.BuildingCompliment     = _buildingComponent1;
                dirPartyPostalAddressView.PostBox                = _street31;
                dirPartyPostalAddressView.City                   = _city1;
                dirPartyPostalAddressView.State                  = _state1;//"Delhi";// _state1;//'SP';
                dirPartyPostalAddressView.DistrictName           = _district1;
                dirPartyPostalAddressView.LocationName           = _name;//extra
                dirPartyPostalAddressView.IsPrimary              = NoYes::No;
                roles_delivery = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];
                dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,roles_delivery);

                select forUpdate dirPartyTable where dirPartyTable.RecId == custtable.Party;
                dirPartyTable.NameAlias        = _name;
                dirPartyTable.Name             = _name;
                dirPartyTable.update();
            }

              if(_Phone)
                {
                select  contactView where contactView.Party == custtable.Party && contactView.Type == LogisticsElectronicAddressMethodType::Phone;
                    {
                        dirParty = dirParty::constructFromPartyRecId(contactView.Party);
                        contactView.LocationName = "Phone";
                        contactView.Locator = _phone;
                        contactView.locatorextension = _extension;
                        contactView.Type = LogisticsElectronicAddressMethodType::Phone;
                        contactView.Party = custtable.Party;//dirParty.getPartyRecId();
                        contactView.IsPrimary = NoYes::Yes;
                        dirParty.createOrUpdateContactInfo(contactView);
                    }
                }
               if(_emailAddress)
                {   contactView.clear();
                    select contactView where contactView.Party == custtable.Party && contactView.Type == LogisticsElectronicAddressMethodType::Email;
                    {
                    DirParty = DirParty::constructFromPartyRecId(contactView.Party);
                    contactView.LocationName = "Email Address";
                    contactView.Locator = _emailAddress;
                    contactView.Type = LogisticsElectronicAddressMethodType::Email;
                    contactView.Party = custtable.Party;//dirParty.getPartyRecId();
                    contactView.IsPrimary = NoYes::Yes;
                    dirParty.createOrUpdateContactInfo(contactView);
                    }
                }
             if(_Fax)
                {   dirPartyContactInfoFax.clear();
                    select dirPartyContactInfoFax where dirPartyContactInfoFax.Party == custtable.Party && dirPartyContactInfoFax.Type == LogisticsElectronicAddressMethodType::Fax;
                    {
                    DirParty = DirParty::constructFromPartyRecId(contactView.Party);
                    dirPartyContactInfoFax.LocationName = "Fax number";
                    dirPartyContactInfofax.Type                      = LogisticsElectronicAddressMethodType::Fax;
                    dirPartyContactInfofax.LocationName              = _fax;
                    dirPartyContactInfofax.Party = custtable.Party;
                    dirParty.createOrUpdateContactInfo(dirPartyContactInfofax);
                    }
                }
             if(_panNumber)
                {//del
                     select TaxInformationCustTable_IN where TaxInformationCustTable_IN.CustTable == _custaccount;
                if(!TaxInformationCustTable_IN)
                    {
                        TaxInformationCustTable_IN.clear();
                        TaxInformationCustTable_IN.CustTable        = _custaccount;
                        TaxInformationCustTable_IN.PanStatus        = PANStatus_IN::Received;
                        TaxInformationCustTable_IN.PANNumber        = _panNumber;
                        TaxInformationCustTable_IN.NatureOfAssessee = NatureOfAssessee_IN::Company;
                        TaxInformationCustTable_IN.validateWrite();
                        {
                        TaxInformationCustTable_IN.insert();
                        }
                    }
                else
                    {
                    select forupdate tic_update where tic_update.CustTable == _custaccount;
                        tic_update.PANNumber = _panNumber;
                        tic_update.update();
                    }
                }//pan nuber
     if(_countryRegion == "IND")
       {
         select DirPartyLocation where DirPartyLocation.Party == custtable.Party && DirPartyLocation.IsPrimary == NoYes::Yes ;
         select TaxRegistrationNumbers_IN_IEC where TaxRegistrationNumbers_IN_IEC.RegistrationNumber == _IECNumber;
         select TaxRegistrationNumbers_IN_ecc where TaxRegistrationNumbers_IN_ecc.RegistrationNumber == _eccNumber;
         select TaxRegistrationNumbers_IN_tan where TaxRegistrationNumbers_IN_tan.RegistrationNumber == _tanNumber;
         select TaxRegistrationNumbers_IN_salestax where TaxRegistrationNumbers_IN_salestax.RegistrationNumber == _salesTaxRegNumber;

         select TaxInformation_IN_exist where  TaxInformation_IN_exist.RegistrationLocation == DirPartyLocation.Location
                                              && TaxInformation_IN_exist.ManECCRegistrationNumberTable == TaxRegistrationNumbers_IN_ecc.RecId
                                              && TaxInformation_IN_exist.SalesTaxRegistrationNumber ==  TaxRegistrationNumbers_IN_salestax.RecId
                                              && TaxInformation_IN_exist.TIN == TaxRegistrationNumbers_IN_tan.RecId
                                              && TaxInformation_IN_exist.IECRegistrationNumberTable == TaxRegistrationNumbers_IN_IEC.RecId ;

        if(!TaxInformation_IN_exist)
         {
             //changes for ta info TaxInformation_IN_exist
             select forUpdate TaxInformation_IN_exist
                        where TaxInformation_IN_exist.RegistrationLocation == DirPartyLocation.Location
                                && TaxInformation_IN_exist.IsPrimary == NoYes::Yes;
             if(TaxInformation_IN_exist)
             {
                   {
                      TaxInformation_IN_exist.IsPrimary = NoYes::No;
                      TaxInformation_IN_exist.update();
                   }

             select count(RecId) from TaxInformation_IN_records where TaxInformation_IN_records.RegistrationLocation == DirPartyLocation.Location ;
                   _taxRecordcount = TaxInformation_IN_records.RecId;

             }
          //   select TIC_count
            if(_IECNumber)
            {
            //select TaxRegistrationNumbers_IN_IEC where TaxRegistrationNumbers_IN_IEC.RegistrationNumber == _IECNumber;
            if(!TaxRegistrationNumbers_IN_IEC)
                {
                TaxRegistrationNumbers_IN_IEC.RegistrationNumber = _IECNumber;
                TaxRegistrationNumbers_IN_IEC.IsGlobal           = NoYes::Yes;
                TaxRegistrationNumbers_IN_IEC.RefCompanyId       = "";
                TaxRegistrationNumbers_IN_IEC.TaxType            = TaxType_IN::Customs;
                TaxRegistrationNumbers_IN_IEC.RegistrationType   = TaxRegistrationType_IN::Customers;
                TaxRegistrationNumbers_IN_IEC.insert();
                }
            }

            if(_eccNumber)
            {
            if(!TaxRegistrationNumbers_IN_ecc)
                {
                    TaxRegistrationNumbers_IN_ecc.clear();
                    TaxRegistrationNumbers_IN_ecc.RegistrationNumber = _eccNumber;
                    TaxRegistrationNumbers_IN_ecc.IsGlobal           = NoYes::Yes;
                    TaxRegistrationNumbers_IN_ecc.RefCompanyId       = "";
                    TaxRegistrationNumbers_IN_ecc.TaxType            = TaxType_IN::Excise;
                    TaxRegistrationNumbers_IN_ecc.RegistrationType   = TaxRegistrationType_IN::Customers;
                    TaxRegistrationNumbers_IN_ecc.insert();
                }
            }

            if(_tanNumber)
            {
            if(!TaxRegistrationNumbers_IN_tan)
                {
                TaxRegistrationNumbers_IN_tan.clear();
                TaxRegistrationNumbers_IN_tan.RegistrationNumber = _tanNumber;
                TaxRegistrationNumbers_IN_tan.IsGlobal           = NoYes::Yes;
                TaxRegistrationNumbers_IN_tan.RefCompanyId       = "";
                TaxRegistrationNumbers_IN_tan.TaxType            = TaxType_IN::VAT;
                TaxRegistrationNumbers_IN_tan.RegistrationType   = TaxRegistrationType_IN::Customers;
                TaxRegistrationNumbers_IN_tan.insert();
                }
            }
            //_salesTaxRegistrationNumber
           if(_salesTaxRegNumber)
          {
            if(!TaxRegistrationNumbers_IN_salestax)
                {
                TaxRegistrationNumbers_IN_salestax.clear();
                TaxRegistrationNumbers_IN_salestax.RegistrationNumber = _salesTaxRegNumber;
                TaxRegistrationNumbers_IN_salestax.IsGlobal           = NoYes::Yes;
                TaxRegistrationNumbers_IN_salestax.RefCompanyId       = "";
                TaxRegistrationNumbers_IN_salestax.TaxType            = TaxType_IN::SalesTax;
                TaxRegistrationNumbers_IN_salestax.RegistrationType   = TaxRegistrationType_IN::Customers;
                TaxRegistrationNumbers_IN_salestax.insert();
                }
          }
        if(_IECNumber || _eccNumber || _tanNumber || _salesTaxRegNumber)
         {
           //  select forupdate TaxInformation_IN
            TaxInformation_IN.clear();
            TaxInformation_IN.Name = strFmt("%1 %2",_name,_taxRecordcount);
            TaxInformation_IN.IsPrimary = NoYes::Yes;
            if(_tanNumber)
            {
                TaxRegistrationNumbers_IN_tan.clear();
                select TaxRegistrationNumbers_IN_tan where TaxRegistrationNumbers_IN_tan.RegistrationNumber == _tanNumber;
                TaxInformation_IN.TIN = TaxRegistrationNumbers_IN_tan.recid;
            }
            if(_eccNumber)
            {
                TaxRegistrationNumbers_IN_ecc.clear();
                select TaxRegistrationNumbers_IN_ecc where TaxRegistrationNumbers_IN_ecc.RegistrationNumber == _tanNumber;
                TaxInformation_IN.ECCNumber = TaxRegistrationNumbers_IN_ecc.recid;
            }
            if(_IECNumber)
            {
                TaxRegistrationNumbers_IN_IEC.clear();
                select TaxRegistrationNumbers_IN_IEC where TaxRegistrationNumbers_IN_IEC.RegistrationNumber == _IECNumber;
                TaxInformation_IN.IECRegistrationNumberTable = TaxRegistrationNumbers_IN_IEC.recid;
            }
            if(_salesTaxRegNumber)
            {
                TaxRegistrationNumbers_IN_salestax.clear();
                select TaxRegistrationNumbers_IN_salestax where TaxRegistrationNumbers_IN_salestax.RegistrationNumber == _salesTaxRegNumber;
                TaxInformation_IN.SalesTaxRegistrationNumber = TaxRegistrationNumbers_IN_salestax.recid;
            }
            TaxInformation_IN.RegistrationLocation = DirPartyLocation.Location;
            TaxInformation_IN.insert();
         }//if all four tax  if(_IECNumber || _e
       }//if tax information exist
      }//if INR
     custtable.update();
     ttsCommit;
        log = strFmt("Success : Customer %1 updated successfully",_custaccount);
    }//if custtable
   }//if all exist
    else   //if all does not exist
    {
        if(!CustTable::exist(_custaccount))
            log_1 =  strFmt("The customer %1 already exist or cannot be blank",_custaccount);
        if(_name == "")
            log_2 =  strFmt("The customer name cannot be blank for Customer %1",_custaccount);
        if(!CustGroup::exist(_customerGroup) || _customerGroup == "")
            log_3 =  strFmt("The Customer group %1 does not exist or cannot be blank in AX for Customer %2",_customerGroup,_custaccount);
        if(!DlvTerm::exist(_delvTerms) && _delvTerms != "" )
            log_4 =  strFmt("The Delivery Terms %1 does not exist or cannot be blank in AX for Customer %2",_delvTerms,_custaccount);
        if(!PaymTerm::exist(_paymTerms) && _paymTerms != "" )
            log_5 =  strFmt("The Payment Terms %1 does not exist or cannot be blank in AX for Customer %2",_paymTerms,_custaccount);
        if((!DlvMode::exist(_delvMode) && _delvMode != ""))
            log_6 =  strFmt("The Delivery Mode %1 does not exist or cannot be blank in AX for Customer %2",_delvMode,_custaccount);
         log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_6);

    } //if customer exist
        }
            ttsCommit;
  return log;
}