Monday, April 17, 2023

How to update purchline vendor tax information based on selected location in header.

 My requirement is to add a tab page on purchase order header same as like punchline vendor tax information. Instead of updating vendor tax in each punchline , if i update in header it should update to all the punchlines at a time.

Add Fields and relations in purchtable :




Add Controls in PurchTable Form:


Code to get lookup for location:

[FormControlEventHandler(formControlStr(PurchTable, VendorLocation), FormControlEventType::Lookup)] 
public static void VendorLocation_OnLookup(FormControl sender, FormControlEventArgs e)    
{        
DirPartyTable               dirPartyTable;
        VendTable                   VendTable;
        LogisticsLocationRoleType  _roleType = LogisticsLocationRoleType::None;
        PurchTable                  purchTable = sender.dataSourceObject().cursor();
        select * from dirPartyTable
         join vendTable
           where dirPartyTable.RecId  == VendTable.Party
           &&   VendTable.AccountNum == purchTable.OrderAccount;
        TaxInformation_IN::locationLookup(sender,dirPartyTable.RecId,_roleType);
        FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;
        cancelableSuperEventArgs.CancelSuperCall();
}

Code to get Tax lookup :

[FormControlEventHandler(formControlStr(PurchTable, VendorTaxInfo), FormControlEventType::Lookup)]
public static void VendorTaxInfo_OnLookup(FormControl sender, FormControlEventArgs e)    
{        
PurchTable purchTable = sender.dataSourceObject().cursor();
        TaxInformation_IN::lookup(sender,purchTable.vendorLocation);
        FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;
        cancelableSuperEventArgs.CancelSuperCall();  
}

Code for Modifying location :

[FormControlEventHandler(formControlStr(PurchTable, VendorLocation), FormControlEventType::Modified)]    
public static void VendorLocation_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;
        TransTaxInformation     transTaxInformation;
        FormRun                 formRun;
          formRun = sender.formRun();
        FormDataSource purchtable_ds =  formRun.dataSource();
        purchTable     = formRun.dataSource().cursor();
        select logisticsLocation where logisticsLocation.RecId == purchTable.VendorLocation;
        select logisticsPostalAddress where logisticsPostalAddress.Location == logisticsLocation.RecId;
        select taxInformation_IN
             where taxInformation_IN.RegistrationLocation == logisticsLocation.RecId
            && taxInformation_IN.IsPrimary == NoYes::Yes;
          ttsbegin;
        purchTable.Address = logisticsPostalAddress.Address;
        purchTable.VendorTaxInformation = taxInformation_IN.RecId;
        purchTable.selectForUpdate(true);
        purchTable.update();
        ttscommit; 
}

Code for JumpRef of Location and Tax fields:

[ExtensionOf(formStr(PurchTable))]
internal  final class DaxPurchTableForm_Extension
{   
public TransTaxInformation  transTaxInformationloc;
    private void initControls()    
{        
List              list = new List(Types::Class);
        #ISOCountryRegionCodes
        TransTaxInformationVendorTaxInfoCtrl_IN     transTaxInformationVendorTaxInfoCtrl = new TransTaxInformationVendorTaxInfoCtrl_IN();        transTaxInformationVendorTaxInfoCtrl.parmVendorTaxInformation(VendorTaxInformation);
        transTaxInformationVendorTaxInfoCtrl.parmVendorTaxInfo(VendorTaxInfo);
        transTaxInformationVendorTaxInfoCtrl.parmVendorLocation(VendorLocation);
        list.addEnd(transTaxInformationVendorTaxInfoCtrl);
    }
      public void  init()
    {
        PurchTable          purchTable;
        VendTable           vendTable;
        DirPartyTable       dirPartyTable;
        LogisticsLocation   logisticLocation;
        TaxInformation_IN   taxInformation_IN;
        TransTaxInformation transTaxInformation;
        List                list = new List(Types::Class);
          TransTaxInformationVendorTaxInfoCtrl_IN     transTaxInformationVendorTaxInfoCtrl = new TransTaxInformationVendorTaxInfoCtrl_IN();
        TransTaxInformationUIController     transTaxInformationUIController;
        next init();
                FormDataSource fds = this.dataSource(formDataSourceStr(PurchTable,PurchTable));
                  this.initControls();
         fds.object(fieldNum(PurchTable, VendorLocation)).registerOverrideMethod(methodStr(FormReferenceGroupControl, jumpRef),methodStr(TransTaxInformationUIController, jumpRefOfVendorLocation), this);
        fds.object(fieldNum(PurchTable, VendorTaxInformation)).registerOverrideMethod(methodstr(FormReferenceGroupControl, jumpRef), FormmethodStr(PurchTable, jumpRefOfVendTaxInfo), this);
    }
      protected void jumpRefOfVendorLocation(FormReferenceObject _formReferenceObject)
    {
        FormDataSource fds = this.dataSource(formDataSourceStr(PurchTable,PurchTable));
        TaxInformation_IN::jumpRefLocationAddressForm(purchTable.VendorLocation, fds.formRun());
    }
      protected void jumpRefOfVendTaxInfo(FormReferenceObject _formReferenceObject)
    {
        TaxInformation_IN::jumpRef(purchTable.VendorTaxInformation, _formReferenceObject);
    }
  }

Code in Validatewrite of purchtable form :

[ExtensionOf(FormDataSourcestr(PurchTable,PurchTable))]
internal final class DaxPurchTableFormDatasource_Extension
{
    public boolean Validatewrite()
    {
        boolean             ret;
        PurchTable          purchTable,purchTableloc;
        PurchLine           purchLine;
        VendTable           vendTable;
        TaxInformation_IN   taxInformation_IN;
        Dialog              dialog;
        TransTaxInformation transTaxInformationloc;
        DialogField         field;
        DialogButton        copyTaxGroupToMarkupTrans;
        PurchTable2LineUpdatePrompt     purchTable2LineUpdatePrompt;
        LogisticsLocation   logisticsLocation;
            FormDataSource purchTable_ds = this.formRun().dataSource();
              purchTable = this.formRun().dataSource().cursor();
           vendTable = VendTable::find(purchTable.OrderAccount);
        ret =next Validatewrite();
        purchTable2LineUpdatePrompt = PurchTable2LineUpdatePrompt::newExecuteExtendedPrompt(purchTable, copyTaxGroupToMarkupTrans);
        if(ret)
        {
            if (purchTable.VendorLocation != purchTable.VendorLocationCopy1)
            {
            dialog = new Dialog("My Dialog");
            dialog.addText("Do you want to transfer the vendor tax information to lines ?");
            dialog.run();
            if (dialog.closedOk())
                {
                    while select purchLine where purchLine.PurchId == purchTable.PurchId
                    {
                                transTaxInformationloc = TransTaxInformationHelper::findOrCreateTransTaxInformation(purchLine.TableId,purchLine.RecId);
                        select logisticsLocation where logisticsLocation.RecId == purchTable.VendorLocation;
                        select taxInformation_IN where taxInformation_IN.RecId == purchTable.VendorTaxInformation;
                            ttsbegin;
                            transTaxInformationloc.selectForUpdate(true);
                            transTaxInformationloc.VendorLocation = logisticsLocation.RecId;
                            transTaxInformationloc.VendorTaxInformation = taxInformation_IN.RecId;
                            transTaxInformationloc.Update();
                            purchTable.VendorLocationCopy1 = purchTable.VendorLocation;//I need to open dialog form when location is modified and saved ,so created a dummy field for storing.
                            purchTable.selectForUpdate(true);
                            ttscommit;
                    }
                }
            }
        }
        return ret;
      }
 }















































No comments:

Post a Comment