Page 1 of 1

SOH Transaction Detail. Sort date DESC

PostPosted: Wed Aug 27, 2025 5:41 pm
by DannyC
Client wants the SOH transaction Detail to always sort with most recent on top.

What would I need in a plugin to have it sorted by DateIn descending?

Cheers

Re: SOH Transaction Detail. Sort date DESC

PostPosted: Thu Aug 28, 2025 7:32 am
by SBarnes
If I am understanding you request correctly you don't need a plugin.

In the system settings under inventory there is a setting called StoredProcForInventoryTransactionHistoryGrid this points to a stored procedure that works like custom form tabs do, i.e. two datasets returned one for the schema and one for the data.

Just copy the procedure to one with a different name add your order by clause, and repoint the setting to your new procedure. :D

Re: SOH Transaction Detail. Sort date DESC

PostPosted: Thu Aug 28, 2025 10:40 am
by Mike.Sheen
SBarnes wrote:If I am understanding you request correctly you don't need a plugin.

In the system settings under inventory there is a setting called StoredProcForInventoryTransactionHistoryGrid this points to a stored procedure that works like custom form tabs do, i.e. two datasets returned one for the schema and one for the data.

Just copy the procedure to one with a different name add your order by clause, and repoint the setting to your new procedure. :D


Wrong grid.

The tab captioned Transaction History on the Order tab of the Inventory Maintenance form uses the stored proc you mentioned, StoredProcForInventoryTransactionHistoryGrid.
InventoryMaint_Order_TransactionHistory.png


What Danny is asking about is the Transaction Detail of the SOH tab of the Inventory Maintenance form.
InventoryMaint_SOH_TransactionDetail.png


That grid does not used a stored proc. As a general rule, if there are user editable fields on a grid, then we cannot use a stored proc - and that is the case with the grid on the Transaction Detail tab of the SOH tab of the Inventory Maintenance form.

To see an example of how we sort grids programmatically, in Demo Data there is a plugin - Sort Notes - which changes the sort order of the notes grids for Debtors and Creditors and Contacts maintenance forms - just do the same as that - the grid on the Inventory Maintenance form is named grdSOH.

Re: SOH Transaction Detail. Sort date DESC

PostPosted: Thu Aug 28, 2025 11:03 am
by DannyC
in Demo Data there is a plugin - Sort Notes - which changes the sort order of the notes grids


Awesome. I'll review that plugin. Should be able to work it out.

Re: SOH Transaction Detail. Sort date DESC

PostPosted: Thu Aug 28, 2025 2:29 pm
by DannyC
I have basically deciphered the Sort Notes plugin and tried to apply the relevant code to sort the inventory trans details by DateIn.

Something isn't right because the grid remains sorted by ascending DateIn.
Just as an aside, I have also added a line (now removed) to get SOHGrid.RowCount and it always returns 0.
Could it be that the grid isn't committed until after the ReadEnd event?

Here's my code
Code: Select all
#region "FormPlugin"
public class FormPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaFormPlugin
{

    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void SetupBeforeHandlers(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      if (JiwaForm is JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm)
      {
         JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm InventoryMainForm = (JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm)JiwaForm;
         InventoryMainForm.Inventory.ReadEnd += Inventory_SortSOH;         
      }   
    }
   
   private void Inventory_SortSOH(object sender, System.EventArgs e)
   {
      JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory = (JiwaFinancials.Jiwa.JiwaInventory.Inventory)sender;
      JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm InventoryMainForm = (JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm)inventory.Client;
      //System.Diagnostics.Debugger.Launch();
      JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid SOHGrid = (JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid)(null);
      SOHGrid = InventoryMainForm.grdSOH;      
      SOHGrid.ActiveSheet.Columns["DateIn"].ShowSortIndicator = true;
      SOHGrid.ActiveSheet.SortRows(SOHGrid.ActiveSheet.Columns["DateIn"].Index, false, true);      

   }
}
#endregion

Re: SOH Transaction Detail. Sort date DESC  Topic is solved

PostPosted: Thu Aug 28, 2025 3:08 pm
by Mike.Sheen
DannyC wrote:Something isn't right because the grid remains sorted by ascending DateIn.


Instead of sorting in a handler for the ReadEnd event, add a handler for the Inventory.SOHCollection.ReadEnd event instead and sort then.

That collection is lazy loaded, so it will only be read if the user clicks on the tab, or if the tab is already selected and a read or copy or new action takes place.