Search This Blog

Showing posts with label PROSPECT. Show all posts
Showing posts with label PROSPECT. Show all posts

Tuesday, 9 June 2015

PROSPECT INTEGRATION UPDATION AX 2012 X++ CUSTOM WEB SERVICE

PROSPECT INTEGRATION UPDATION AX 2012 
X++ CUSTOM WEB SERVICE

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


{


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

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

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

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

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

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



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

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

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

      ttsCommit;
      log =  'Prospect Updated Successfully';


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

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


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

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



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

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

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

        }

         ttsCommit;
      log =  'Prospect Updated Successfully';

       }

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

    }
     return log ;
 }

PROSPECT INTEGRATION CREATION AX 2012 X++ CUSTOM WEB SERVICE

PROSPECT INTEGRATION CREATION AX 2012 
X++ CUSTOM WEB SERVICE

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

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

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

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

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

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

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

            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_6);
        }

      }
      else
      {
           changeCompany('HYUT')

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

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

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

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

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

            log = strFmt("%1\n%2\n%3\n%4\n%5\n%6",log_1,log_2,log_3,log_4,log_5,log_6);
        }



      }

     return log ;
    }