Search This Blog

Showing posts with label CREATION. Show all posts
Showing posts with label CREATION. Show all posts

Tuesday, 9 June 2015

PROSPECT INTEGRATION UPDATION AX 2012 X++ CUSTOM WEB SERVICE

PROSPECT INTEGRATION UPDATION AX 2012 
X++ CUSTOM WEB SERVICE

Prospect Integration Update
[AifCollectionTypeAttribute('return', Types::String), SysEntryPointAttribute(true)]
public str UpdateProspect(smmBusRelAccount _prospectId,DirPartyName _name,CurrencyCode _currency,smmDlvTermId _term,smmDlvModeId _mode,
                          LogisticsAddressCountryRegionId _country1,LogisticsAddressZipCodeId _zipCode1,LogisticsAddressStreet  _street1,
                          LogisticsAddressBuildingCompliment  _building,LogisticsAddressPostBox  _street3,LogisticsAddressCity _city,LogisticsAddressStateId  _state,
                          LogisticsAddressDistrictName _district,LogisticsElectronicAddressLocator _phone,LogisticsElectronicAddressLocator _extension,LogisticsElectronicAddressLocator _email,LogisticsElectronicAddressLocator _fax,
                          LogisticsAddressCountryRegionId _country2,LogisticsAddressZipCodeId _zipCode2,LogisticsAddressStreet  _street2,
                          LogisticsAddressBuildingCompliment  _building2,LogisticsAddressPostBox  _street32,LogisticsAddressCity _city2,LogisticsAddressStateId  _state2,
                          LogisticsAddressDistrictName _district2,
                          CustGroupId _groupId,TaxGroup _salesTax)


{


    DirPartyTable                   _DirPartyTable;
    smmBusRelTable                  prospect;
    DirPartyContactInfoView         contactView;
    container                       roles_delivery,roles_invoice;
    DirParty                        dirParty;
    DirPartyPostalAddressView       postaladdressView,dirPartyPostalAddressView;
    str                             log_1,log_2,log_3,log_4,log_5,log_6;
    str                             log;

    if(_groupId != 'del')
            changeCompany('DEL')
    {
        if( smmBusRelTable::exist(_prospectId) && _name !="" && CustGroup::exist(_groupId) && (DlvTerm::exist(_term) || _term == "")
        && (DlvMode::exist(_mode) || _mode == "") )
     {
        prospect.clear();
        ttsBegin;
        select forUpdate prospect where prospect.BusRelAccount == _prospectId;

        if(prospect)
        {
            prospect.DlvTerm       = _term;
            prospect.DlvMode       = _mode;
            prospect.TaxGroup      = _salesTax;
            prospect.CustGroup     = _groupId;
            if(_Currency == "")
            {
                prospect.Currency = "INR";
            }
            else
            {
                prospect.Currency  = _Currency;
            }

            select forUpdate _DirPartyTable where _DirPartyTable.RecId == prospect.Party;
                _DirPartyTable.NameAlias        = _name;
                _DirPartyTable.Name             = _name;
                _DirPartyTable.update();
            prospect.update();
         }

            postaladdressView.clear();
            select postaladdressView where postaladdressView.Party == prospect.Party && postaladdressView.IsPrimary == NoYes::Yes ;
            DirParty = DirParty::constructFromPartyRecId(_DirPartyTable.RecId);
            postaladdressView.LocationName           = _name;
            postaladdressView.CountryRegionId        = _country1;
            postaladdressView.ZipCode                = _zipCode1;
            postaladdressView.Street                 = _street1;
            postaladdressView.BuildingCompliment     = _building;
            postaladdressView.PostBox                = _street3;
            postaladdressView.City                   = _city;
            postaladdressView.State                  = _state;
            postaladdressView.DistrictName           = _district;
            postaladdressView.IsPrimary              = NoYes::Yes;
            roles_delivery = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];
            DirParty.createOrUpdatePostalAddress(postaladdressView,roles_delivery);

            select postaladdressView where postaladdressView.Party == prospect.Party && postaladdressView.IsPrimary == NoYes::No ;
            postaladdressView.LocationName           =  _name;
            postaladdressView.CountryRegionId        = _country2;
            postaladdressView.ZipCode                = _zipCode2;
            postaladdressView.Street                 = _street2;
            postaladdressView.BuildingCompliment     = _building2;
            postaladdressView.PostBox                = _street32;
            postaladdressView.City                   = _city2;
            postaladdressView.State                  = _state2;
            postaladdressView.DistrictName           = _district2;
            postaladdressView.IsPrimary              = NoYes::No;
            roles_invoice = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
            dirParty.createOrUpdatePostalAddress(postaladdressView,roles_invoice);



            if(_Phone)
            {
                 contactView.clear();
                select contactView where contactView.Party == prospect.Party && contactView.Type == LogisticsElectronicAddressMethodType::Phone;
                dirParty = dirParty::constructFromPartyRecId(contactView.Party);
                contactView.LocationName                 =  _name;
                contactView.Locator = _Phone;
                contactView.LocatorExtension = _Extension;
                contactView.Type = LogisticsElectronicAddressMethodType::Phone;
                contactView.Party = _DirPartyTable.RecId;
                contactView.IsPrimary = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);

            }
            if(_email)
            {
                contactView.clear();
                select contactView where contactView.Party == prospect.Party && contactView.Type == LogisticsElectronicAddressMethodType::Email;
                dirParty = dirParty::constructFromPartyRecId(contactView.Party);
                contactView.LocationName                 =  _name;
                contactView.Locator = _email;
                contactView.Type = LogisticsElectronicAddressMethodType::Email;
                contactView.Party = _DirPartyTable.RecId;
                contactView.IsPrimary = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);

            }
            if(_fax)
            {
                contactView.clear();
                select contactView where contactView.Party == prospect.Party && contactView.Type == LogisticsElectronicAddressMethodType::Fax;
                dirParty = dirParty::constructFromPartyRecId(contactView.Party);
                contactView.LocationName                 =  _name;
                contactView.Locator = _fax;
                contactView.Type = LogisticsElectronicAddressMethodType::Fax;
                contactView.Party = _DirPartyTable.RecId;
                contactView.IsPrimary = NoYes::Yes;
                dirParty.createOrUpdateContactInfo(contactView);
            }

      ttsCommit;
      log =  'Prospect Updated Successfully';


     }
    else
    {
        if(!smmBusRelTable::exist(_prospectId))
        {
            log_1 = ('Prospect Id does not exist');
        }
        if(_name == '')
        {
            log_2 = ('Name cannot be blank');
        }
        if(!CustGroup::exist(_groupId))
        {
            log_3 = ('Customer GroupId does not exist');
        }
        if(!DlvTerm::exist(_term) || _term == "")
        {
            log_4= ('Terms of Delivery does not exist');
        }
        if(!DlvMode::exist(_mode) || _mode == "")
        {
            log_5= ('Mode of Delivery does not exist');
        }
        log = strFmt("%1\n%2\n%3\n%4\n%5",log_1,log_2,log_3,log_4,log_5);
      }
    }
    else
   {
    changeCompany('HYUT')
    if( smmBusRelTable::exist(_prospectId) && _name !="" && CustGroup::exist(_groupId) && (DlvTerm::exist(_term) || _term == "")
        && (DlvMode::exist(_mode) || _mode == "") )
    {
        prospect.clear();
        ttsBegin;
        select forUpdate prospect where prospect.BusRelAccount == _prospectId;

        if(prospect)
        {
            prospect.DlvTerm       = _term;
            prospect.DlvMode       = _mode;
            prospect.TaxGroup      = _salesTax;
            prospect.CustGroup     = _groupId;
            if(_Currency == "")
            {
                prospect.Currency = "INR";
            }
            else
            {
                prospect.Currency  = _Currency;
            }
            prospect.update();
        }
            select forUpdate _DirPartyTable where _DirPartyTable.RecId == prospect.Party;
                _DirPartyTable.NameAlias        = _name;
                _DirPartyTable.Name             = _name;
                _DirPartyTable.update();


            postaladdressView.clear();
            select postaladdressView where postaladdressView.Party == prospect.Party && postaladdressView.IsPrimary == NoYes::Yes ;
            DirParty = DirParty::constructFromPartyRecId(_DirPartyTable.RecId);
            postaladdressView.CountryRegionId        = _country1;
            postaladdressView.ZipCode                = _zipCode1;
            postaladdressView.Street                 = _street1;
            postaladdressView.BuildingCompliment     = _building;
            postaladdressView.PostBox                = _street3;
            postaladdressView.City                   = _city;
            postaladdressView.State                  = _state;
            postaladdressView.DistrictName           = _district;
            postaladdressView.IsPrimary              = NoYes::Yes;
            roles_delivery = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];
            DirParty.createOrUpdatePostalAddress(postaladdressView,roles_delivery);

            select postaladdressView where postaladdressView.Party == prospect.Party && postaladdressView.IsPrimary == NoYes::No ;
            postaladdressView.CountryRegionId        = _country2;
            postaladdressView.ZipCode                = _zipCode2;
            postaladdressView.Street                 = _street2;
            postaladdressView.BuildingCompliment     = _building2;
            postaladdressView.PostBox                = _street32;
            postaladdressView.City                   = _city2;
            postaladdressView.State                  = _state2;
            postaladdressView.DistrictName           = _district2;
            postaladdressView.IsPrimary              = NoYes::No;
            roles_invoice = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
            dirParty.createOrUpdatePostalAddress(postaladdressView,roles_invoice);



        if(_Phone)
        {
            select contactView where contactView.Party == prospect.Party && contactView.Type == LogisticsElectronicAddressMethodType::Phone;
            dirParty = dirParty::constructFromPartyRecId(_DirPartyTable.RecId);
            contactView.Locator = _Phone;
            contactView.locatorextension = _Extension;
            contactView.Type = LogisticsElectronicAddressMethodType::Phone;
            contactView.Party = dirParty.getPartyRecId();
            contactView.IsPrimary = NoYes::Yes;
            dirParty.createOrUpdateContactInfo(contactView);

        }
        if(_email)
        {
            select contactView where contactView.Party == prospect.Party && contactView.Type == LogisticsElectronicAddressMethodType::Email;
            contactView.Locator = _email;
            contactView.Type = LogisticsElectronicAddressMethodType::Email;
            contactView.Party = _DirPartyTable.RecId;
            contactView.IsPrimary = NoYes::Yes;
            dirParty.createOrUpdateContactInfo(contactView);

        }
        if(_fax)
        {
            select contactView where contactView.Party == prospect.Party && contactView.Type == LogisticsElectronicAddressMethodType::Fax;
            contactView.Locator = _fax;
            contactView.Type = LogisticsElectronicAddressMethodType::Fax;
            contactView.Party = _DirPartyTable.RecId;
            contactView.IsPrimary = NoYes::Yes;
            dirParty.createOrUpdateContactInfo(contactView);

        }

         ttsCommit;
      log =  'Prospect Updated Successfully';

       }

   else
   {
       if(!smmBusRelTable::exist(_prospectId))
       {
           log_1 = ('Prospect Id does not exist');
       }
       if(_name == '')
       {
         log_2 = ('Name cannot be blank');
       }
       if(!CustGroup::exist(_groupId))
       {
           log_3 = ('Customer GroupId does not exist');
       }
       if(!DlvTerm::exist(_term) || _term == "")
       {
            log_4= ('Terms of Delivery does not exist');
       }
       if(!DlvMode::exist(_mode) || _mode == "")
       {
            log_5= ('Mode of Delivery does not exist');
       }
      log = strFmt("%1\n%2\n%3\n%4\n%5",log_1,log_2,log_3,log_4,log_5);
    }

    }
     return log ;
 }

PROSPECT INTEGRATION CREATION AX 2012 X++ CUSTOM WEB SERVICE

PROSPECT INTEGRATION CREATION AX 2012 
X++ CUSTOM WEB SERVICE

Prospect Integration create
[AifCollectionTypeAttribute('return', Types::String), SysEntryPointAttribute(true)]
public str CreateProspect(smmBusRelAccount _prospectId,DirPartyName _name,CurrencyCode _currency,smmDlvTermId _term,smmDlvModeId _mode,
                          LogisticsAddressCountryRegionId _country1,LogisticsAddressZipCodeId _zipCode1,LogisticsAddressStreet  _street1,
                          LogisticsAddressBuildingCompliment  _building,LogisticsAddressPostBox  _street3,LogisticsAddressCity _city,LogisticsAddressStateId  _state,
                          LogisticsAddressDistrictName _district,LogisticsElectronicAddressLocator _phone,LogisticsElectronicAddressLocator _extension,LogisticsElectronicAddressLocator _email,LogisticsElectronicAddressLocator _fax,
                          LogisticsAddressCountryRegionId _country2,LogisticsAddressZipCodeId _zipCode2,LogisticsAddressStreet  _street2,
                          LogisticsAddressBuildingCompliment  _building2,LogisticsAddressPostBox  _street32,LogisticsAddressCity _city2,LogisticsAddressStateId  _state2,
                          LogisticsAddressDistrictName _district2,
                          CustGroupId _groupId,TaxGroup _salesTax)
{

    DirPartyTable                   partyRecord;
    DirPersonName                   person;
    DirPerson                       pers;
    smmBusRelTable                  prospect;
    DirPartyContactInfoView         contactinfo,dirPartyContactInfoEmail,dirPartyContactInfoFax;
    str                             log;
    container                       roles_delivery,roles_invoice;
    DirParty                        dirParty;
    DirPartyPostalAddressView       dirPartyPostalAddressView;
    str                             log_1,log_2,log_3,log_4,log_5,log_6;

   if(_groupId != 'del')
            changeCompany('DEL')
    {
      if(!smmBusRelTable::exist(_prospectId) && _prospectId != ''&& _name !="" && CustGroup::exist(_groupId) && (DlvTerm::exist(_term) || _term == "")
            && (DlvMode::exist(_mode) || _mode == ""))
        //Creating record  in
        {

            //Creating record  in Prospect master
          //  errorlog = 'done';
            ttsBegin;
            prospect.clear();
            prospect.BusRelAccount = _prospectId;
            prospect.CustGroup = _groupId;
            prospect.BusRelTypeId = 'Prospect';
            if(_Currency == "")
            {
                prospect.Currency = "INR";
            }
            else
            {
               prospect.Currency  = _Currency;
            }

            prospect.DlvMode  = _mode;
            prospect.DlvTerm  = _term;
            prospect.TaxGroup = _salesTax;
            partyRecord            = DirPartyTable::createNew(DirPartyType::Organization, _name);
            partyRecord.update();
            prospect.Party = partyRecord.RecId;
            prospect.insert();
            dirParty = DirParty::constructFromCommon(prospect);
        //  creating Address
            dirPartyPostalAddressView.CountryRegionId        = _country1;
            dirPartyPostalAddressView.ZipCode                = _zipCode1;
            dirPartyPostalAddressView.Street                 = _street1;
            dirPartyPostalAddressView.BuildingCompliment     = _building;
            dirPartyPostalAddressView.PostBox                = _street3;
            dirPartyPostalAddressView.City                   = _city;
            dirPartyPostalAddressView.State                  = _state;
            dirPartyPostalAddressView.DistrictName           = _district;
            dirPartyPostalAddressView.LocationName           = _name;
            dirPartyPostalAddressView.IsPrimary              = NoYes::Yes;
            roles_delivery = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,roles_delivery);
            //second address
            dirPartyPostalAddressView.CountryRegionId        = _country2;
            dirPartyPostalAddressView.ZipCode                = _zipCode2;
            dirPartyPostalAddressView.Street                 = _street2;
            dirPartyPostalAddressView.BuildingCompliment     = _building2;
            dirPartyPostalAddressView.PostBox                = _street32;
            dirPartyPostalAddressView.City                   = _city2;
            dirPartyPostalAddressView.State                  = _state2;
            dirPartyPostalAddressView.DistrictName           = _district2;
            dirPartyPostalAddressView.LocationName           = _name;
            dirPartyPostalAddressView.IsPrimary              = NoYes::No;
            roles_invoice = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,roles_invoice);
                // Update address

            if(_phone || _extension)
            {
                if(_Phone)
                {
                    contactinfo.LocationName                 =  _name;
                    contactinfo.Locator                      =  _Phone;
                    contactinfo.Type                         =  LogisticsElectronicAddressMethodType::Phone;
                    contactinfo.IsPrimary                    =  NoYes::Yes;
                }
                if(_Extension)
                {
                    contactinfo.LocatorExtension             =  _Extension;
                }
               dirParty.createOrUpdateContactInfo(contactinfo);
            }
            //Fax
            if(_Fax)
            {
                dirPartyContactInfofax.Type                         = LogisticsElectronicAddressMethodType::Fax;
                dirPartyContactInfofax.Locator                         = _Fax;
                dirPartyContactInfofax.LocationName              = _name;
                dirParty.createOrUpdateContactInfo(dirPartyContactInfofax);
            }
            //Email
            if(_email)
            {
                dirPartyContactInfoemail.Type                    = LogisticsElectronicAddressMethodType::Email;
                dirPartyContactInfoemail.Locator            = _email;
                dirPartyContactInfoemail.LocationName              =_name;
                dirParty.createOrUpdateContactInfo(dirPartyContactInfoemail);
            }
            // Updating contacts

            ttsCommit;
            log = 'Prospect created successfully';
         }
        else
        {
            if(smmBusRelTable::exist(_prospectId))
            {
               log_1 = 'Prospect  already exist' ;
            }
            if(_prospectId == '')
            {
                log_2 = 'Prospect Id cannot be blank';
            }
            if(_name == '')
            {
                log_3 = 'Name cannot be blank';
            }
            if(!CustGroup::exist(_groupId))
            {
                log_4 = 'Customer Group is not valid';
            }
            if((!DlvTerm::exist(_term) && _term != ""))
            {
                log_5 = 'Term of delivery is not valid';
            }
            if((!DlvMode::exist(_mode) && _mode != ""))
            {
                log_6 = 'Mode of delivery is invalid';
            }

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

      }
      else
      {
           changeCompany('HYUT')

      if(!smmBusRelTable::exist(_prospectId) && _prospectId != ''&& _name !="" && CustGroup::exist(_groupId) && (DlvTerm::exist(_term) || _term == "")
            && (DlvMode::exist(_mode) || _mode == ""))
        //Creating record  in
        {

            //Creating record  in Prospect master
          //  errorlog = 'done';
            ttsBegin;
            prospect.clear();
            prospect.BusRelAccount = _prospectId;
            prospect.CustGroup = _groupId;
            prospect.BusRelTypeId = 'Prospect';
            if(_Currency == "")
            {
                prospect.Currency = "INR";
            }
            else
            {
               prospect.Currency  = _Currency;
            }

            prospect.DlvMode  = _mode;
            prospect.DlvTerm  = _term;
            prospect.TaxGroup = _salesTax;
            partyRecord            = DirPartyTable::createNew(DirPartyType::Organization, _name);
            partyRecord.update();
            prospect.Party = partyRecord.RecId;
            prospect.insert();
            dirParty = DirParty::constructFromCommon(prospect);
        //  creating Address
            dirPartyPostalAddressView.CountryRegionId        = _country1;
            dirPartyPostalAddressView.ZipCode                = _zipCode1;
            dirPartyPostalAddressView.Street                 = _street1;
            dirPartyPostalAddressView.BuildingCompliment     = _building;
            dirPartyPostalAddressView.PostBox                = _street3;
            dirPartyPostalAddressView.City                   = _city;
            dirPartyPostalAddressView.State                  = _state;
            dirPartyPostalAddressView.DistrictName           = _district;
            dirPartyPostalAddressView.LocationName           = _name;
            dirPartyPostalAddressView.IsPrimary              = NoYes::Yes;
            roles_delivery = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery).RecId];
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,roles_delivery);
            //second address
            dirPartyPostalAddressView.CountryRegionId        = _country2;
            dirPartyPostalAddressView.ZipCode                = _zipCode2;
            dirPartyPostalAddressView.Street                 = _street2;
            dirPartyPostalAddressView.BuildingCompliment     = _building2;
            dirPartyPostalAddressView.PostBox                = _street32;
            dirPartyPostalAddressView.City                   = _city2;
            dirPartyPostalAddressView.State                  = _state2;
            dirPartyPostalAddressView.DistrictName           = _district2;
            dirPartyPostalAddressView.LocationName           = _name;
            dirPartyPostalAddressView.IsPrimary              = NoYes::No;
            roles_invoice = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,roles_invoice);
                // Update address

            if(_phone || _extension)
            {
                if(_Phone)
                {
                    contactinfo.LocationName                 =  'Phone No';
                    contactinfo.Locator                      =  _Phone;
                    contactinfo.Type                         =  LogisticsElectronicAddressMethodType::Phone;
                    contactinfo.IsPrimary                    =  NoYes::Yes;
                }
                if(_Extension)
                {
                    contactinfo.LocatorExtension             =  _Extension;
                }
               dirParty.createOrUpdateContactInfo(contactinfo);
            }
            //Fax
            if(_Fax)
            {
                dirPartyContactInfofax.Type                         = LogisticsElectronicAddressMethodType::Fax;
                dirPartyContactInfofax.Locator                         = _Fax;
                dirPartyContactInfofax.LocationName              = 'Fax';
                contactinfo.IsPrimary                    =  NoYes::Yes;
                dirParty.createOrUpdateContactInfo(dirPartyContactInfofax);
            }
            //Email
            if(_email)
            {
                dirPartyContactInfoemail.Type            = LogisticsElectronicAddressMethodType::Email;
                dirPartyContactInfoemail.Locator         = _email;
                dirPartyContactInfoemail.LocationName    = 'E Mail';
                contactinfo.IsPrimary                    =  NoYes::Yes;
                dirParty.createOrUpdateContactInfo(dirPartyContactInfoemail);
            }
            // Updating contacts

            ttsCommit;
            log = 'Prospect created successfully';
         }
        else
        {
            if(smmBusRelTable::exist(_prospectId))
            {
               log_1 = 'Prospect  already exist' ;
            }
            if(_prospectId == '')
            {
                log_2 = 'Prospect Id cannot be blank';
            }
            if(_name == '')
            {
                log_3 = 'Name cannot be blank';
            }
            if(!CustGroup::exist(_groupId))
            {
                log_4 = 'Customer Group is not valid';
            }
            if(!(DlvTerm::exist(_term) && _term == ""))
            {
                log_5 = 'Term of delivery is not valid';
            }
            if(!(DlvMode::exist(_mode) && _mode == ""))
            {
                log_6 = 'Mode of delivery is invalid';
            }

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



      }

     return log ;
    }

SALES QUOTE UPDATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE UPDATION AX 2012 
X++ CUSTOM WEB SERVICE
Sales Quote update
[AifCollectionTypeAttribute('return', Types::Container), SysEntryPointAttribute(true)]
public str updateQuote(QuotationIdBase _quoteId,CustCurrencyCode _currency, InventSiteName _site,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty   _saleTypeExcise,
                        String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{

    str                             log;
    str                             log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
    Inventsite                      site;
    InventLocation                  ware;
    SalesQuotationTable             quotation,quotationIdchk;
    SalesQuotationLine              line,line_2;
    InventDim                       dim;
    InventItemOrderSetupType        setupType   = InventItemOrderSetupType::Invent;
    InventTable                     inventTable;
    CustTable                       cust;
    InventDimCombination            comb;
    NoYes                           noyes;
    TmpTaxWorkTrans                 tmpTax;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationTotals_Sales      salesQuotationTotals;
    TaxTable                        taxtable;
    str                             component;
    container                       con;
    int                             i ;
    compProductMasterDefault         prodMasterDef;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDef;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDef.DealerCompany)
    {  // Validating from masters
         select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
     if(quotationIdchk.RecId && InventSite::exist(_site) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //updating header
            quotation.clear();
            select forupdate quotation where quotation.QuotationId ==  _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating line
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                               // && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
           trans.ModuleType  =  MarkupModuleType::Cust;
           trans.CurrencyCode = line.CurrencyCode;
           trans.MarkupCode    = markTab.MarkupCode;
           trans.Txt            = markTab.Txt;
           trans.MarkupCategory = MarkupCategory::Pcs;
           trans.Value = _Freight;
           Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
            while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
//             log_8 = num2str(abs(tmpTax.TaxAmount),0,2,1,1);
               log_8 =  num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
            //strFmt('Warehouse %1 is not valid for Sales Quote : %2',ware,_quoteId);
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
            if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);

        }

      }
      else
      {
           changeCompany(prodMasterDef.delCompany)
          {
       // validating masters
           select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;
      if( quotationIdchk.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)&&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            select forUpdate quotation where quotation.QuotationId == _quoteId;
            if(quotation.RecId)
            {
                quotation.QuotationStatus  = SalesQuotationStatus::Created;
                quotation.CurrencyCode = _currency;
                quotation.ShippingDateRequested = systemDateGet();
                quotation.LanguageId = SystemParameters::getSystemLanguageId();
                quotation.comp_OrderType = _orderType;
                quotation.comp_OrderCat  = _orderCategory;
                quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
                quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
                quotation.comp_Domestic = str2enum(NoYes,_domestic);
                quotation.comp_Export = str2enum(NoYes,_export);
                quotation.update();
            }
            //updating lines
            line.clear();
            select forUpdate line where line.QuotationId == quotation.QuotationId;
                      //  && line.ItemId == _item;

            if(line.RecId)
            {
                 //line.ItemId = _item;
                 line.initFromSalesQuotationLine(line);
                 line.SalesPrice = str2num(_price) - _freight;
                 line.TaxGroup = _taxGroup;
                 line.SalesQty = _qty;
                 line.CurrencyCode = _currency;
                 line.ShippingDateRequested = systemDateGet();
                 line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
                 line.ExciseTariffCodes_IN = Inventtable::find(line.ItemId).ExciseTariffCodes_IN;
            }
            line.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line.update();

             markTab = MarkupTable::find((MarkupModuleType::Cust),'6');

            select forupdate trans where Trans.TransTableId == line.TableId
                    && Trans.TransRecId == line.RecId;
               trans.ModuleType  =  MarkupModuleType::Cust;
               trans.CurrencyCode = line.CurrencyCode;
               trans.MarkupCode    = markTab.MarkupCode;
               trans.Txt            = markTab.Txt;
               trans.MarkupCategory = MarkupCategory::Pcs;
               trans.Value = _Freight;
               Trans.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');

         }
        else
        {
              if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for %2 for company %3',_item,_quoteId,curext());
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strFmt('SalesTax FormType %1 is not valid for %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is %1 not valid for %2',_taxGroup,_quoteId);
            }
             if(!quotationIdchk.RecId )
            {
                log_9 = strFmt('Quote %1 does not exist for company %2',_quoteId,curext());
            }
            log = strFmt("%1\n%2\n%3\n%4",log_3,log_4,log_5,log_9);
        }
      }
    }

     info(strFmt("Sales Quote Update: %1 - %2 ",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote Update',infolog.export());
     return log ;
    }

SALES QUOTE CREATION AX 2012 X++ CUSTOM WEB SERVICE

SALES QUOTE CREATION AX 2012 
X++ CUSTOM WEB SERVICE

[AifCollectionTypeAttribute('return', Types::String), SysEntryPointAttribute(true)]
public str CreateQuote(QuotationIdBase _quoteId,smmBusRelAccount _prospectId,CustAccount _customerId,LogisticsAddressing _billToAddress,LogisticsAddressing _shipToAddress,CustCurrencyCode _currency,
                        InventSiteName _site,InventLocationName _warehouse,ItemIdSmall _item,SalesQty _qty,comp_OrderType _orderType,comp_OrderCat _orderCategory,FormType_IN _saleTypeSalesTax,comp_SaleTypeExciseDuty   _saleTypeExcise,
                        String50 _domestic,String50 _export,String50 _e1Sale,string50 _price,TaxGroup _taxGroup,MarkupValue _freight)
{

    str                             log;
    str                             log_1,log_2,log_3,log_4,log_5,log_6,log_7,log_8,log_9;
    Inventsite                      site;
    InventLocation                  ware;
    SalesQuotationTable             quotation,quotationIdchk;
    SalesQuotationLine              line,line_2;
    InventDim                       dim;
    InventItemOrderSetupType        setupType   = InventItemOrderSetupType::Invent;
    InventTable                     inventTable;
    CustTable                       cust;
    InventDimCombination            comb;
    NoYes                           noyes;
    TmpTaxWorkTrans                 tmpTax;
    SalesQuotationTable             salesQuotationTable;
    SalesQuotationTotals_Sales      salesQuotationTotals;
    TaxTable                        taxtable;
    str                             component;
    container                       con;
    int                             i,k ;
    // changes
    compProductMasterDefault         prodMasterDefault;
    MarkupTable                             markTab;
    MarkupTrans                             trans;

    select * from prodMasterDefault;

   if(_orderCategory == 'Dealer-Customer')
            changeCompany(prodMasterDefault.DealerCompany)
    {  // Validating from masters
        select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;

     if(!quotationIdchk.RecId &&InventSite::exist(_site) && InventLocation::exist(_warehouse) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)  &&  TaxGroupHeading::exist(_taxGroup))

        {

            ttsBegin;
            //creating header
            quotation.clear();
            quotation.initValue();
            quotation.CustAccount = _customerId;
            quotation.QuotationName = _customerId;
            quotation.InvoiceAccount = _customerId;
            quotation.initFromCustTable(true);
            quotation.QuotationId = _quoteId;
            quotation.BusRelAccount = _prospectId;
            quotation.QuotationStatus  = SalesQuotationStatus::Created;
            quotation.CurrencyCode = _currency;
            quotation.InventSiteId = _site;
            quotation.InventLocationId = _warehouse;
            quotation.ShippingDateRequested = systemDateGet();
            quotation.LanguageId = SystemParameters::getSystemLanguageId();
            quotation.comp_OrderType = _orderType;
            quotation.comp_OrderCat  = _orderCategory;
            quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
            quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
            quotation.comp_Domestic = str2enum(NoYes,_domestic);
            quotation.comp_Export = str2enum(NoYes,_export);
            quotation.insert();
            //creating line
            line.initValue();
            line.initFromSalesQuotationTable(quotation);
            line.initFromCustTable();
            inventTable = InventTable::find(_item);
            line.initFromInventTable(inventTable);
            line.ItemId = _item;
            //creating Inventory Dimensions
            dim.InventSiteId = _site;
            dim.InventLocationId  =_warehouse;
           // dim.configId = InventTable::find(line.ItemId).StandardConfigId;
            dim.configId = prodMasterDefault.DefaultConfig;
            dim = InventDim::findOrCreate(dim);
            dim.write();
            line.SalesQty = _qty;
            line.CurrencyCode = _currency;
            line.ShippingDateRequested = systemDateGet();
            line.InventDimId = dim.inventDimId;
            line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
            line.initFromSalesQuotationLine_IN(line);
            comb = InventDimCombination::findByInventDim(line.ItemId,dim);
            line.RetailVariantId = comb.RetailVariantId  ;
            line.ExciseTariffCodes_IN = Inventtable::find(_item).ExciseTariffCodes_IN;
            line.createLine(true,true,false,false,false,false,'',false);


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
            trans.clear();
            trans.initFromSalesQuotationLine(line);
            trans.initFromMarkupTable(marktab);
            trans.MarkupCategory = MarkupCategory::Pcs;
            trans.Value = _Freight;
            trans.LineNum = k;
            trans.insert();
            k++;

            //updating line Price
            select forUpdate line_2 where line_2.QuotationId == line.QuotationId
                        && line_2.ItemId == line.ItemId
                        && line_2.LineNum == line.LineNum;
            if(line_2.RecId)
            {
             line_2.SalesPrice = str2num(_price) - _freight;
             line_2.TaxGroup = _taxGroup;
            }
            line_2.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line_2.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            i =0 ;
            log = con2StrUnlimited(con,'|');
            //info(strFmt('%1',log));
         }
        else
        {
            //InventSite::exist(_site) && InventLocation::exist(_warehouse)
            if(!InventSite::exist(_site))
            {
               log_1 = strFmt('Site %1 is not valid for Sales Quote - %2 for company %3',_site,_quoteId,curext());
            }
            if(!InventLocation::exist(_warehouse))
            {
                log_2 = strFmt('Warehouse %1 is not valid for Sales Quote - %2',_warehouse,_quoteId);
            }
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for Sales Quote - %2',_item,_quoteId);
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strfmt('SalesTax FormType %1 is not valid for Sales Quote - %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is not valid for Sales Quote - %2',_taxGroup,_quoteId);
            }
            if(quotationIdchk.RecId)
            {
                log_9 = strFmt('Sales Quote %1 already Exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_9);
        }

      }
      else
      {
           changeCompany(prodMasterDefault.delCompany)
          {
          select * from quotationIdchk where quotationIdchk.QuotationId == _quoteId;

       // validating masters
     // if(site.RecId && ware.RecId && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
     if(!quotationIdchk.RecId &&InventSite::exist(_site) && InventLocation::exist(_warehouse) && InventTable::exist(_item) && SalesTaxFormTypes_IN::exist(_saleTypeSalesTax)  &&  TaxGroupHeading::exist(_taxGroup))

        {
             ttsBegin;
            //creating header
            quotation.clear();
            quotation.initValue();
            quotation.CustAccount = _customerId;
            quotation.QuotationName = _customerId;
            quotation.InvoiceAccount = _customerId;
            quotation.initFromCustTable(true);
            quotation.QuotationId = _quoteId;
            quotation.BusRelAccount = _prospectId;
            quotation.QuotationStatus  = SalesQuotationStatus::Created;
            quotation.CurrencyCode = _currency;
            quotation.InventSiteId = _site;
            quotation.InventLocationId = _warehouse;
            quotation.ShippingDateRequested = systemDateGet();
            quotation.LanguageId = SystemParameters::getSystemLanguageId();
            quotation.comp_OrderType = _orderType;
            quotation.comp_OrderCat  = _orderCategory;
            quotation.comp_SaleTypeExciseDuty = _saleTypeExcise;
            quotation.comp_E1Sale = str2enum(noyes,_e1Sale);
            quotation.comp_Domestic = str2enum(NoYes,_domestic);
            quotation.comp_Export = str2enum(NoYes,_export);
            quotation.insert();
            //creating lines
            line.initValue();
            line.initFromSalesQuotationTable(quotation);
            line.initFromCustTable();
            inventTable = InventTable::find(_item);
            line.initFromInventTable(inventTable);
            line.ItemId = _item;
            //creating inventory dimension
            dim.InventSiteId = _site;
            dim.InventLocationId  =_warehouse;
            //dim.configId = InventTable::find(line.ItemId).StandardConfigId;
            dim.configId = prodMasterDefault.DefaultConfigdel;
            dim = InventDim::findOrCreate(dim);
            dim.write();
            line.SalesQty = _qty;
            line.CurrencyCode = _currency;
            line.ShippingDateRequested = systemDateGet();
            line.InventDimId = dim.inventDimId;
            line.SalesTaxFormTypes_IN = SalesTaxFormTypes_IN::findbyFormType(_saleTypeSalesTax).RecId;
            line.initFromSalesQuotationLine_IN(line);
            comb = InventDimCombination::findByInventDim(line.ItemId,dim);
            line.RetailVariantId = comb.RetailVariantId  ;
            line.ExciseTariffCodes_IN = Inventtable::find(_item).ExciseTariffCodes_IN;
            line.createLine(true,true,false,false,false,false,'',false);


            markTab = MarkupTable::find((MarkupModuleType::Cust),'6');
            trans.clear();
            trans.initFromSalesQuotationLine(line);
            trans.initFromMarkupTable(marktab);
            trans.MarkupCategory = MarkupCategory::Pcs;
            trans.Value = _Freight;
            trans.LineNum = k;
            trans.insert();
            K++;
            //updating price
             select forUpdate line_2 where line_2.QuotationId == line.QuotationId
                        && line_2.ItemId == line.ItemId
                        && line_2.LineNum == line.LineNum;
            if(line_2.RecId)
            {
             line_2.SalesPrice = str2num(_price)- _freight;
             line_2.TaxGroup = _taxGroup;

            }
            line_2.modifiedField(fieldnum(SalesQuotationLine,SalesPrice));
            line_2.update();
            ttsCommit;
            salesQuotationTable  = SalesQuotationTable::find(_quoteId);
            salesQuotationTotals = SalesQuotationTotals_Sales::construct(salesQuotationTable);

            // Calculate Tax
            salesQuotationTotals.calc();

            // Load tmpTaxWorkTrans
            tmpTax.setTmpData(salesQuotationTotals.tax().tmpTaxWorkTrans());

            // Showing taxes with tax value
             while
                select tmpTax
            {
                i++;
                select taxtable where taxtable.taxcode == tmpTax.TaxCode;
                component = TaxComponentTable_IN::find(taxtable.TaxComponentTable_IN).Name;
               log_7  = component;
               log_8 = num2str(abs((tmpTax.TaxAmount)/_qty),0,2,0,0);
               con = conins(Con,i,log_7+':'+log_8);


            }
            log = con2StrUnlimited(con,'|');
            i =0 ;
            //log = con2Str(con,'');

         }
        else
        {
            if(!InventSite::exist(_site))
            {
               log_1 = strFmt('Site %1 is not valid for Sales Quote - %2 for company %3',_site,_quoteId,curext());
            }
            if(!InventLocation::exist(_warehouse))
            {
                log_2 = strFmt('Warehouse %1 is not valid for Sales Quote - %2',_warehouse,_quoteId);
            }
            if(!InventTable::exist(_item))
            {
                log_3 = strFmt('Item %1 is not valid for Sales Quote - %2',_item,_quoteId);
            }
            if(!SalesTaxFormTypes_IN::exist(_saleTypeSalesTax))
            {
                log_4 = strfmt('SalesTax FormType %1 is not valid for Sales Quote - %2',_saleTypeSalesTax,_quoteId);
            }
            if(!TaxGroupHeading::exist(_taxGroup))
            {
                log_5 = strFmt('Tax Group is not valid for Sales Quote - %2',_taxGroup,_quoteId);
            }
             if(quotationIdchk.RecId)
            {
                log_9 = strFmt('Sales Quote %1 already Exist',_quoteId);
            }
            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_9);

        }
          }
      }
   //  info(strFmt(" Sales Quote
     info(strFmt("Sales Quote for %1 is created - %2",_quoteId,log));
     comp_RetailExceptionActivityLog::logEvent('Sales Quote',infolog.export());
     return log ;
    }