Page 1 of 2

Add Sort Order to purchase orders

PostPosted: Fri Feb 16, 2018 10:03 am
by DannyC
In sales orders, we can use the direction arrows to scroll forward and back according to the sort order which includes the debtor account no, or debtor name.

I've tried to add sort order to Purchase Orders so we can forward/back by creditor account no or creditor name, but I failed.
Can you assist?

For version 7.0.175

Cheers

Re: Add Sort Order to purchase orders

PostPosted: Fri Feb 16, 2018 10:29 am
by SBarnes
Hi Danny

Seeing we've been working on this together the following code kind of works, when added as a business logic plugin, when I say kind of it adds the sort and will scroll to first and last but produces an error on next and previous. Maybe Mike or Scott can resolve it.

Code: Select all
 public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      //System.Diagnostics.Debugger.Launch();
      
      if(JiwaBusinessLogic.GetType() == typeof(JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder))
      {
      JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder purchaseorder  =(JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder) JiwaBusinessLogic;
      purchaseorder.SortOrders.Add(new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey {
                               Description = "Creditor Name",
                               FieldName = "CR_Main.Name+PO_Main.OrderNo"
                              });   
      //salesorder.TableName = "";
      purchaseorder.BaseFindSQLQuery = "SELECT TOP 1 PO_Main.OrderID FROM  PO_Main INNER JOIN CR_Main ON PO_Main.CreditorID = CR_Main.CreditorID";

      }      
    }


The error its producing is attached.

Re: Add Sort Order to purchase orders

PostPosted: Fri Feb 16, 2018 2:06 pm
by Mike.Sheen
Hi Danny & Stuart,

This is a limitation of the Maintenance business logic design.

The problem occurs because the SortFieldValue property of the purchase order business logic is used by the base Maintenance.UserInterface class and this method has hard-coded return values, and cannot be modified via external code.

I've logged an improvement to address this DEV-6483 - it'd mean just adding a parameter to the Add of the SortOrders collection to allow a delegate function be supplied to return the desired SortFieldValue.

Mike

Re: Add Sort Order to purchase orders

PostPosted: Fri Feb 16, 2018 2:19 pm
by SBarnes
Hi Mike,

Am I right in assuming this improvement would then work for all maintenance screens not just the purchase order screen?

Re: Add Sort Order to purchase orders

PostPosted: Fri Feb 16, 2018 2:20 pm
by Mike.Sheen
SBarnes wrote:Am I right in assuming this improvement would then work for all maintenance screens not just the purchase order screen?


Yes!

Re: Add Sort Order to purchase orders

PostPosted: Fri Feb 16, 2018 2:24 pm
by SBarnes
Brilliant :D

Re: Add Sort Order to purchase orders

PostPosted: Wed Feb 28, 2018 6:52 pm
by Mike.Sheen
FYI - 7.00.175.00 Service Release 5 has this improvement included and had been released.

Re: Add Sort Order to purchase orders

PostPosted: Mon Jun 04, 2018 4:43 pm
by DannyC
Mike,

Can you let me know why this doesn't work? There is a compile error on the SortFieldValueMethod line. "Cannot convert anonymous method to delegate type JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortFieldValue Delegate"
Code: Select all
    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
    if(JiwaBusinessLogic.GetType() == typeof(JiwaFinancials.Jiwa.JiwaInvReceival.Receival))
      {
      JiwaFinancials.Jiwa.JiwaInvReceival.Receival GRN  =(JiwaFinancials.Jiwa.JiwaInvReceival.Receival) JiwaBusinessLogic;
      GRN.SortOrders.Add(new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey{
         Description = "Slip Date",
         FieldName = "RE_Main.SlipDate",
         SortFieldValueMethod = delegate() {return GRN.SlipDate; }
         });
      GRN.BaseFindSQLQuery = "SELECT TOP 1 RE_Main.SlipDate FROM RE_Main ORDER BY RE_Main.SlipDate DESC";
       }
   }

Re: Add Sort Order to purchase orders

PostPosted: Mon Jun 04, 2018 4:59 pm
by SBarnes
Hi Danny,

I believe your issue may well be solved by making

Code: Select all
 SortFieldValueMethod = delegate() {return GRN.SlipDate; }


be

Code: Select all
 SortFieldValueMethod = delegate() {return GRN.SlipDate.ToString(); }


The delegate must return a string not a date.

Re: Add Sort Order to purchase orders

PostPosted: Mon Jun 04, 2018 5:10 pm
by DannyC
Bingo!
This is the final code.
Code: Select all
    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
    if(JiwaBusinessLogic.GetType() == typeof(JiwaFinancials.Jiwa.JiwaInvReceival.Receival))
      {
      JiwaFinancials.Jiwa.JiwaInvReceival.Receival GRN  =(JiwaFinancials.Jiwa.JiwaInvReceival.Receival) JiwaBusinessLogic;
      GRN.SortOrders.Insert(0, new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey{
      //GRN.SortOrders.Add(new JiwaFinancials.Jiwa.JiwaApplication.IJiwaNavigable.SortKey{
         Description = "Slip Date",
         FieldName = "RE_Main.SlipDate",
         SortFieldValueMethod = delegate() {return GRN.SlipDate.ToString("yyyyMMdd"); }
         });
      GRN.BaseFindSQLQuery = "SELECT TOP 1 RE_Main.PackSlipID FROM RE_Main ";
       }
   }


I remmed out the Add and used Insert so I can put in a index in the hope that will be the first option which appears when opening the module.
And I also made the SlipDate return a string as per Stuart's suggestion but formatted to yyyyMMdd. Without that formatting, it throws an error using the green Previous/Next buttons.

Seems to work but It only works when 1 GRN has been done on any day.
If there are mutiple GRNs on the same day, it doesn't scroll previous/next to the next GRN. I suspect I need it to recognise hours & minutes but have tried all kinds of syntax tweaks but none work.

Suggestions?