Search This Blog

Showing posts with label UPDATION. Show all posts
Showing posts with label UPDATION. Show all posts

Tuesday, 9 June 2015

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

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