Showing posts with label Vendor Address.. Show all posts
Showing posts with label Vendor Address.. Show all posts

Thursday, April 4, 2024

Code to create Vendor using Entites in D365f&o x++

public static void main(Args _args)

   {

       VendAccount                         returnAccount;

       VendVendorBankAccountEntity         vendVendorBankAccountEntity;

       DirParty                            dirParty;

       DirPartyPostalAddressView           dirPartyPostalAddressView;

       LogisticsLocationRole               logisticsLocationRole;

       LogisticsLocationRoleTranslation    locationRoleTransl;

       VendTable                           vendTable;

       VendVendorV2Entity                  vendEntity;

       LogisticsAddressCountryRegionEntity logisticsAddressCountryRegionEntity;

       LogisticsAddressStateEntity         logisticsAddressStateEntity;

       LOGISTICSADDRESSPOSTALCODEV2ENTITY  logisticsAddressPostalCodeV2Entity;

       LOGISTICSADDRESSCITYENTITY          logisticsAddressCityEntity;

       LogisticsPostalAddressBaseEntity    logisticsPostalAddressBaseEntity;

       LogisticsLocation                   logisticsLocation;

       TaxInformation_IN                   taxInformation_IN;

       TaxRegistrationNumbers_IN            taxRegistrationNumber_IN;

       TaxGSTRegistrationNumberEntity   taxGSTRegistrationNumberEntity;

 

       changecompany("INMF")

       {

           vendEntity.initValue();

           

           select vendEntity

           where vendEntity.VendorAccountNumber == "000001";

 

           select locationRoleTransl

           join logisticsLocationRole

           where logisticsLocationRole.RecId == locationRoleTransl.LocationRole

           && locationRoleTransl.Description == "Delivery";

 

           vendEntity.VendorAccountNumber = "000001";

           vendEntity.VendorOrganizationName = "Fabrikam Brasil Ltda";

           vendEntity.VendorPartyType = "Organization";

           vendEntity.VendorSearchName = "Priyanka";

           vendEntity.VendorGroupId ="40";

           vendEntity.AddressLocationRoles = "Delivery";

           vendEntity.AddressDescription = "dax";

           vendEntity.AddressCountryRegionId = "ADF";

       

           select logisticsAddressCountryRegionEntity

               where logisticsAddressCountryRegionEntity.CountryRegion ==  "ADF";

           if(!logisticsAddressCountryRegionEntity)

           {

               logisticsAddressCountryRegionEntity.AddressFormat = "0001";

               logisticsAddressCountryRegionEntity.CountryRegion =   "ADF";

               logisticsAddressCountryRegionEntity.insert();

           }

           vendEntity.AddressStateId = "TS";

           select  logisticsAddressStateEntity

           where logisticsAddressStateEntity.State ==  "TS"

           && logisticsAddressStateEntity.CountryRegionId ==   "ADF";

           if(!logisticsAddressStateEntity)

           {

               logisticsAddressStateEntity.CountryRegionID =  "ADF";

               logisticsAddressStateEntity.State = "TS";

               logisticsAddressStateEntity.insert();

           }

           vendEntity.AddressCity = "MGLL";

           select * from logisticsAddressCityEntity

               where logisticsAddressCityEntity.Name ==  "MGLL"

               && logisticsAddressCityEntity.CountryRegionId ==   "ADF"

               && logisticsAddressCityEntity.StateId == "TS";

           if(!logisticsAddressCityEntity)

           {

               logisticsAddressCityEntity.CountryRegionId ="ADF";

               logisticsAddressCityEntity.StateId =  "TS";

               logisticsAddressCityEntity.Name = "MGLL";

               logisticsAddressCityEntity.CityKey =  "MGLL, TS, ADF";

               logisticsAddressCityEntity.insert();

           }

           vendEntity.AddressZipCode = "506006";

 

           select logisticsAddressPostalCodeV2Entity

           where logisticsAddressPostalCodeV2Entity.ZipCode ==  vendEntity.AddressZipCode;

           if(!logisticsAddressPostalCodeV2Entity)

           {

               logisticsAddressPostalCodeV2Entity.CountryRegionId =  logisticsAddressCountryRegionEntity.CountryRegion;

               logisticsAddressPostalCodeV2Entity.ZipCode = vendEntity.AddressZipCode;

               logisticsAddressPostalCodeV2Entity.insert();

           }

   

           vendEntity.PrimaryPhoneNumber = "1234567689";

           vendEntity.PrimaryPhoneNumberDescription = "test";

           vendEntity.PrimaryPhoneNumberPurpose = "Business";

           vendEntity.PrimaryEmailAddress = "test@gmail.com";

           vendEntity.PrimaryEmailAddressDescription = "test mail";

           vendEntity.PANNumber = "BAAAA1234a";

           

           if(vendEntity)

           {

               vendEntity.selectForUpdate(true);

               ttsbegin;

               vendEntity.update();

               ttscommit;

           }

           else

           {

               vendEntity.insert();

           }

           select vendVendorBankAccountEntity

               where vendVendorBankAccountEntity.VendorBankAccountId =="012";

          

           vendVendorBankAccountEntity.initValue();

           vendVendorBankAccountEntity.VendorBankAccountId = "012";

           vendVendorBankAccountEntity.BankName = "HDFC";

           vendVendorBankAccountEntity.BankAccountNumber = "9876543210";

           vendVendorBankAccountEntity.VendorAccountNumber = vendEntity.VendorAccountNumber;

 

           if(vendVendorBankAccountEntity)

           {

               vendVendorBankAccountEntity.selectForUpdate(true);

               vendVendorBankAccountEntity.update();

           }

           else

           {

               vendVendorBankAccountEntity.insert();

           }

           dirParty = DirParty::constructFromCommon(vendEntity);

           dirPartyPostalAddressView.City = 'MGLL';

           dirPartyPostalAddressView.Street = 'Dover Street';

           dirPartyPostalAddressView.StreetNumber = '123';

           dirPartyPostalAddressView.CountryRegionId = 'ADF';

           dirPartyPostalAddressView.LocationName = "JNTUHW";   

           container   _roles = [logisticsLocationRole.RecId,locationRoleTransl.Description,locationRoleTransl.RecId];

           dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView,_roles);

         

           select  taxGSTRegistrationNumberEntity

               where taxGSTRegistrationNumberEntity.RegistrationNumber == '29AGNPB4831B1Z4';

           if(!taxGSTRegistrationNumberEntity)

           {

               taxGSTRegistrationNumberEntity.RegistrationNumber = '29AGNPB4831B1Z4';

               taxGSTRegistrationNumberEntity.Description = 'CodeTax';

               taxGSTRegistrationNumberEntity.RegistrationNumberType = TaxRegistrationType_IN::Vendors;

               taxGSTRegistrationNumberEntity.insert();

           }

           select logisticsLocation

                order by logisticsLocation.recid desc

               where logisticsLocation.Description == "JNTUHW";

              

           select taxInformation_IN

               where taxInformation_IN.RegistrationLocation == logisticsLocation.RecId;

           if(!taxInformation_IN)

           {

               taxInformation_IN.RegistrationLocation = logisticsLocation.RecId;

               taxInformation_IN.GSTIN = taxGSTRegistrationNumberEntity.RecId;

               taxInformation_IN.Name =taxGSTRegistrationNumberEntity.Description;

               taxInformation_IN.insert();

           }

           returnAccount = vendEntity.VendorAccountNumber;

           Info(strFmt("%1",returnAccount));

       }

   }

.....................

OutPut:








Wednesday, March 29, 2023

How to get vendor addresses in lookup

 internal final class DaxPurchTableForm_EventHandler

{            

/// <summary> 

/// </summary>    

/// <param name="sender"></param>      

/// /// <param name="e"></param>      

/// <summary>    ///    

/// </summary>    

/// <param name="sender"></param>    

/// <param name="e"></param>    

[FormControlEventHandler(formControlStr(PurchTable, PurchTable_Address), FormControlEventType::Lookup)]

    public static void PurchTable_Address_OnLookup(FormControl sender, FormControlEventArgs e)

    {        

PurchTable              purchTable;

        Query           query = new Query();

        QueryBuildDataSource    dsDirPartyPostalAddressView;

        FormRun                 formRun;

         formRun             =   sender.formRun();

         purchTable     = formRun.dataSource().cursor();

         // Instantiate sysTableLookup object using table which will provide the visible fields

          QueryBuildDataSource    qbds, qbds2, qbds3;

          QueryBuildDataSource    QbdsJoin;

          SysTableLookup          sysTableLookup =                  sysTableLookup::newParameters(tableNum(DirPartyPostalAddressView), sender);

          qbds = query.addDataSource(tableNum(DirPartyPostalAddressView));

          qbds.addGroupByField(fieldnum(DirPartyPostalAddressView, Address));

          qbds.orderMode(OrderMode::GroupBy);

          qbds2 = qbds.addDataSource(tableNum(vendtable));

          qbds2.addLink(fieldNum(DirPartyPostalAddressView, Party), fieldNum(VendTable, Party));

          qbds2.joinMode(JoinMode::ExistsJoin);

         qbds2.addRange(fieldNum(vendtable, AccountNum)).value(purchTable.OrderAccount);

          sysTableLookup.parmQuery(query);

          sysTableLookup.addLookupfield(fieldNum(DirPartyPostalAddressView, Address));

          sysTableLookup.performFormLookup();

         }

  }




....................................................................................................................................................................


How to get vendor location and tax name of vendor by selecting vendor address in lookup


 internal final class DaxPurchTableFormAddress_EventHandler
{       
 /// <summary>    ///    
/// </summary>    
/// <param name="sender"></param>    
/// <param name="e"></param>    
[FormControlEventHandler(formControlStr(PurchTable, PurchTable_Address), FormControlEventType::Modified)]
public static void PurchTable_Address_OnModified(FormControl sender, FormControlEventArgs e)
{        
VendTable               vendTable;
        PurchTable              purchTable;
        TaxInformation_IN       taxInformation_IN;
        LogisticsLocation       logisticsLocation;
        DirPartyTable           dirPartyTable;
        LogisticsPostalAddress  logisticsPostalAddress;
        Query           query = new Query();
        QueryBuildDataSource    queryBuildDataSource;
        QueryBuildRange         queryBuildRange;
        FormRun                 formRun;
         formRun = sender.formRun();
        FormDataSource purchtable_ds =  formRun.dataSource();
        purchTable     = formRun.dataSource().cursor();
          select logisticsPostalAddress where logisticsPostalAddress.Address == purchTable.Address;
        select logisticsLocation where logisticsLocation.RecId == logisticsPostalAddress.Location;
        select taxInformation_IN             
where taxInformation_IN.RegistrationLocation == logisticsLocation.RecId
            && taxInformation_IN.IsPrimary == NoYes::Yes;
          ttsbegin;
            purchTable.Name = taxInformation_IN.Name;
            purchTable.Description = logisticsLocation.Description;
            purchTable.selectForUpdate(true);
            purchTable.update();
        ttscommit;
    }
}




......................................................................................................................................

How to update the purchline vendor tax information based on selected vendor address.

My Requirement is to update the purchline vendor tax information. As in previous step select the address from lookup , a dialouge form should be opened. If user click ok address should be updated in purchline line of vendpor tax information. If  user click cancel it should not update.

[ExtensionOf(FormDataSourcestr(PurchTable,PurchTable))]
internal final class DaxPurchTableForm_Extension
{    
void  write()    
{        
PurchTable          purchTable;
        PurchLine           purchLine;
        VendTable           vendTable;
        TaxInformation_IN   taxInformation_IN;
        Dialog              dialog;
        TransTaxInformation transTaxInformationloc;
        DialogField         field;
        next write();
                purchTable = this.formRun().dataSource().cursor();
        FormDataSource purchTable_ds = this.formRun().dataSource();
        vendTable = VendTable::find(purchTable.OrderAccount);
        dialog = new Dialog("My Dialog");
        dialog.addText("Do you want to save");
        dialog.run();
            if (dialog.closedOk())
            {                
while select purchLine where purchLine.PurchId == purchTable.PurchId
                {
                    transTaxInformationloc = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(purchLine.TableId, purchLine.RecId);                   
                    if(transTaxInformationloc)
                    {
                        ttsbegin;
                        transTaxInformationloc.selectForUpdate(true);
                        TransTaxInformationHelper_IN::initFromCustVend(transTaxInformationloc, vendTable);
                        transTaxInformationloc.Update();
                        ttscommit;
                    }
                }
            }
    }
 }




..........................................................................................................................................

If new line created in purchline. A dialouge form should be opened, with ok and cancel buttons.

If user clicks ok, the updated address in purchaseorder header should be populated to current newly created line.If  user clicks cancel the purcline vendor tax information should be empty.


[ExtensionOf(formDataSourceStr(PurchTable,PurchLine))]
internal final class DaxPurchTable_Extension
{
    void  write()
    {
        PurchTable          purchTable;
        PurchLine           purchLine,purchLineloc,purchLineloc1;
        VendTable           vendTable;
        TaxInformation_IN   taxInformation_IN;
        Dialog              dialog;

        TransTaxInformation transTaxInformationloc;
        DialogField         field;
          next write();
         FormDataSource purchLine_ds = this.formRun().dataSource();
        purchLine = purchLine_ds.cursor();
        select purchTable where purchTable.PurchId == purchLine.PurchId;
        vendTable = VendTable::find(purchTable.OrderAccount);
        if(purchLine.RecId)
        {
        dialog = new Dialog("My Dialog");
        dialog.addText("Do you want to save");
        dialog.run();
        if (dialog.closedOk())
        {
                     transTaxInformationloc = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(purchLine.TableId, purchLine.RecId);
                if(transTaxInformationloc)
                {
                    ttsbegin;
                    transTaxInformationloc.selectForUpdate(true);                    TransTaxInformationHelper_IN::initFromCustVend(transTaxInformationloc, vendTable);
                    transTaxInformationloc.update();
                    ttscommit;
                }
        }
        else
         {
                       transTaxInformationloc = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(purchLine.TableId, purchLine.RecId);            if(transTaxInformationloc)
            {
                ttsbegin;
                transTaxInformationloc.selectForUpdate(true);
                transTaxInformationloc.VendorLocation =str2Int64("");
                transTaxInformationloc.VendorTaxInformation =str2Int64("");
                transTaxInformationloc.update();
                ttscommit;
            }
        }
        }
          
}  
}