Page 1 of 1

Scheduler to automate sales order processing  Topic is solved

PostPosted: Wed Mar 02, 2022 4:14 pm
by DannyC
Just wanted opinion on the best angle to attack setting up a schedule running every nn minutes to process sales orders.

I can either instantiate the Batch Processing object and simulate firing that. Sort of like
Code: Select all
JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess batch = Plugin.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess>(null);
batch.ProcessCandidates.Read();
batch.Process();


Or, I can knock up a SQL SELECT to get my candidate orders, basically like this forum topic viewtopic.php?f=26&t=1649
Populate a list as the attached plugin demonstrates (in that forum post, not this one).
Then just loop through the list and process one by one, like this:
Code: Select all
if (InvoiceIds.Count > 0)
{
   JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = Plugin.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder>(null);
   
   foreach (string invoiceID in InvoiceIds)
   {
      Plugin.Manager.LogEvent(String.Format("Processing invoice '{0}'", invoiceID), System.Diagnostics.EventLogEntryType.Information, 0, 0, true);   
      salesOrder.Read(invoiceID);

      salesOrder.Process() 
   }
}


I think my preference is the latter but would like to hear other thoughts.
And I can see the Process method has parameters for sales order report. Is that essential or can I leave the brackets blank?

EDIT: Re my last question about the brackets, I can see in the POS plugin that I can leave the .Process() brackets blank. :)

Re: Scheduler to automate sales order processing

PostPosted: Tue Mar 08, 2022 5:32 pm
by SBarnes
The problem with the latter is that it produces a batch number for every invoice.

Re: Scheduler to automate sales order processing

PostPosted: Wed Mar 09, 2022 10:40 pm
by DannyC
I think my preference is the latter but would like to hear other thoughts.


That works. Was easier than I thought.
Not instantiating a batch object at all, so it's not creating a new batch for each sales order. It's just grabbing candidate orders via my SQL SELECT.
Then populating the list.
Then processing each one using salesOrder.Process().

Re: Scheduler to automate sales order processing

PostPosted: Thu Mar 10, 2022 11:06 am
by SBarnes
So long as you understand you are creating a line in SO_Run for every order you process individually i.e. the sales order process code does it.

With the batch object you could add to the ProcessCandidates collection by filling in a JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.ProcessCandidate which is a Jiwa collection item object and then just adding it to process candidates and then just call process on the batch to get them all in one run.