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

No comments:

Post a Comment

AZURE INTERVIEW QUESTIONS AND ANSWERS

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