Page 1 of 1

Recurring Orders Processing - how to hook in on processing

PostPosted: Wed Mar 21, 2018 11:15 am
by neil.interactit
Hey guys,

I can't quite see under the hood to work out how to correctly hook in with some extra business logic.

The requirement is to influence the quote creation on "Save" on the Recurring Orders Processing form. So in essence, given a sales quote with a line item description "Rent up to [DATE]", after processing the created sales order will have a line item description "Rent up to 21-Mar-2018" the supplied date being based on the "next activated" date of the quote.

Could you point me in the right direction to be able to hook in at the correct step of the processing?

Cheers,
Neil.

Re: Recurring Orders Processing - how to hook in on processi

PostPosted: Wed Mar 21, 2018 7:33 pm
by Mike.Sheen
Hi Neil,

I think this should be fairly easy - if you could impart which version of Jiwa you're wanting this for, and your preferred language (C# or VB.Net), I can spend a few minutes whipping up a sample plugin for you.

I can't guide you with complete confidence without trying it out myself - so in order to answer your query I will make a plugin myself - but it'd be nice if I knew the Jiwa version and language you prefer so I can just offer you whatever plugin I conjured as part of the answer.

Mike

Re: Recurring Orders Processing - how to hook in on processi

PostPosted: Thu Mar 22, 2018 8:04 am
by neil.interactit
Great! Many thanks Mike. It's for Jiwa 175 in C#.
Cheers,
Neil.

Re: Recurring Orders Processing - how to hook in on processi  Topic is solved

PostPosted: Thu Mar 22, 2018 11:43 am
by Mike.Sheen
Plugin attached.

This was a bit trickier than it needed to be - our recurring batch in sales orders doesn't have events in place for when the sales order is being created - so I've added improvement DEV-6540 to address this.



Mike

Re: Recurring Orders Processing - how to hook in on processi

PostPosted: Thu Mar 22, 2018 3:31 pm
by neil.interactit
Thanks Mike. It actually makes me feel better that the events weren't there - as I couldn't find them and my wife would accuse me of a "man look"! I'll have a play with this. Thanks again!

Re: Recurring Orders Processing - how to hook in on processi

PostPosted: Tue Mar 27, 2018 6:51 pm
by Mike.Sheen
Just so this is clear - the plugin I provided works around the missing events and does what you wanted.

I raise this point because I note you've not download the sample plugin I attached to my post yet.

Re: Recurring Orders Processing - how to hook in on processi

PostPosted: Wed Mar 28, 2018 10:05 am
by neil.interactit
All good - I've been swamped with work for other clients - back on this today. Thanks again!

Re: Recurring Orders Processing - how to hook in on processi

PostPosted: Wed Mar 28, 2018 2:18 pm
by neil.interactit
Hi Mike,

Works a treat!

I've tweaked slightly to accommodate offsets, so [DATE-3] and [DATE+6] are now also valid. For interest, here's the updated code ...

Code: Select all
        public void SalesOrder_SaveStart(object sender, System.EventArgs e, JiwaFinancials.Jiwa.JiwaSales.RecurringBatch.RecurringBatch recurringBatch)
        {
            var salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;

            if (salesOrder.QuoteID == null || salesOrder.QuoteID.Trim().Length <= 0) return;
            // find the matching line in the recurring batch for this sales order using the QuoteID
            var batchLine = recurringBatch.BatchLines.Cast<JiwaFinancials.Jiwa.JiwaSales.RecurringBatch.BatchLine>().FirstOrDefault(x => x.SourceQuoteID == salesOrder.QuoteID);
            if (batchLine == null) return;
            // Replace the [DATE+/-XX] text on each line description to be the batch lines quote activation date
            foreach (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine salesOrderLine in salesOrder.SalesOrderLines)
                foreach (Match match in Regex.Matches(salesOrderLine.Description, @"\[DATE([\+-]*)(\d*)\]"))
                {
                    var realdate = match.Groups[0].Value == "[DATE]" ? batchLine.QuoteNextActivateDate : batchLine.QuoteNextActivateDate.AddDays((match.Groups[1].Value == "-" ? -1 : 1) * int.Parse(match.Groups[2].Value));
                    salesOrderLine.Description = salesOrderLine.Description.Replace(match.Groups[0].Value, realdate.ToString("dd-MMM-yyyy"));
                }
        }
    }

Thanks,
Neil