Check Processing: Order Number

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
dlerickson
Posts: 80
Joined: Tue Jan 21, 2014 11:35 am
Location: Austin, TX

Check Processing: Order Number

Post by dlerickson »

Is it possible to trace a check to an Order Number in a Print Job Handler? This works well with other document types, but I see no properties in the PrintJob items on a check that would directly point back to an Order. The closest I can find that has any promise is to pull the Document ID out of the Context URI and trace from there, but I'm not even sure about that.
yatin.t
Posts: 24
Joined: Tue Jan 07, 2014 9:40 am
Location: Raleigh, NC

Re: Check Processing: Order Number

Post by yatin.t »

Please see my reply to this post. Hope it helps.

Thanks.
Yatin Tawde
Softpro
Software Engineer
dlerickson
Posts: 80
Joined: Tue Jan 21, 2014 11:35 am
Location: Austin, TX

Re: Check Processing: Order Number

Post by dlerickson »

Actually, that was a response to the PM on our team. We've implemented that code successfully for most of the documents, but when trying to update this to include check documents, no Properties item keyed with "Order" exists, and there appears to be no way to trace back to it.
yatin.t
Posts: 24
Joined: Tue Jan 07, 2014 9:40 am
Location: Raleigh, NC

Re: Check Processing: Order Number

Post by yatin.t »

Understood. Could you post a snippet of your code that grabs the DocumentID from the Report Uri? Are you using the IReportContext<T> interface to get that information?
Yatin Tawde
Softpro
Software Engineer
dlerickson
Posts: 80
Joined: Tue Jan 21, 2014 11:35 am
Location: Austin, TX

Re: Check Processing: Order Number

Post by dlerickson »

We actually don't do any of that. It's pretty simple code (irrelevant bits redacted):

Code: Select all

   class BarcodePrintJobHandler : PrintJobHandler
    {
        ...

        protected override PrintJobHandlerResult OnProcess(IPrintJob printJob)
        {
            var firstItem = printJob.Items.First();

            if (firstItem != null && printJob.Properties.ContainsKey("Order") && printJob.Properties["Order"] != null)
            {
                dynamic order = printJob.Properties["Order"];

                foreach (var item in printJob.Items)
                {
                    // (do some processing using order.Number)
                }
            }

            return PrintJobHandlerResult.Continue;
        }
    }
In the case of printing a check, printJob.Properties["Order"] does not exist anywhere in the object tree.
yatin.t
Posts: 24
Joined: Tue Jan 07, 2014 9:40 am
Location: Raleigh, NC

Re: Check Processing: Order Number

Post by yatin.t »

Thanks for the snippet. "The closest I can find that has any promise is to pull the Document ID out of the Context URI" - that somehow told me that you have a handle on the Report Context Uri and that you can parse Document ID from it? I ask because if such is the case, you could potentially grab the ledger ID from the Uri and I can show you a way to find the order from that point on.

Let me know.
Yatin Tawde
Softpro
Software Engineer
dlerickson
Posts: 80
Joined: Tue Jan 21, 2014 11:35 am
Location: Austin, TX

Re: Check Processing: Order Number

Post by dlerickson »

Ah, right. That was just from visually inspecting the IPrintJob instance at a breakpoint in a debug session. Sorry that I wasn't clear on that. I did copy the value of the Context URI during one of the debug inspections and it was as follows:

Code: Select all

{[Context, sp-select://./reporting/report?instance=ea0d0227-6180-4152-907d-f126ddf399dc&documentid=3741f38b-7303-4f11-bf91-904bf64a65e2&target=printer&autoprint=false&contextid=0d3e6235-3ecc-e411-b733-00155de06a66&rootid=cb2cca5a-8bc3-e411-b614-00155de06a66]}
If you could walk me through from there as you mentioned, I'd appreciate it.
yatin.t
Posts: 24
Joined: Tue Jan 07, 2014 9:40 am
Location: Raleigh, NC

Re: Check Processing: Order Number

Post by yatin.t »

The GUID value encoded in "&rootid=cb2cca5a-8bc3-e411-b614-00155de06a66" would be the ledger ID if it's a check document that's going through the print job pipeline. I'd parse the ledger ID and try the following code to get the order number.

Code: Select all

using SoftPro.Accounting.Client;
using SoftPro.Accounting.Client.Ledgers;
using SoftPro.OrderTracking.Client.Orders;

var server = GetService<SelectServer>(); // or your preferred way to get an instance of SelectServer

// get the ledger info
var ledgerInfo = server.GetService<ILedgersManager>().Ledgers.Where(l => l.ID == ledgerId).FirstOrDefault();

// make sure it's an order ledger
if (ledgerInfo.Kind == LedgerKind.Order)
{
    // get order ID from the tag
    var orderIdTag = ledgerInfo.Tags.FirstOrDefault(t => t.Name == "OrderID");
    if (orderIdTag != null)
    {
        var orderId = new Guid(orderIdTag.Value);
        var identifier = new OrderIdentifier(orderId);

        // query the server and get the order info object
        var orderInfo = server.GetService<IOrderStore>()
                                .Orders
                                .Where(o => o.Identifier == identifier) // The Where clause is required for efficient querying on the server side
                                .FirstOrDefault(); // Do not specify the filtering predicate in FirstOrDefault()
        if (orderInfo != null)
        {
            var number = orderInfo.Number; // this is the order number
        }
    }
}
Unfortunately, there's no cleaner way to do this because documents or reports that are sent to the print pipeline from the order's Documents tab have an instance of IOrder baked into the IPrintJob instance but the same is not true for checks or any other documents that may be sent through the "Accounting area" of the product.

Let me know if you have questions.
Yatin Tawde
Softpro
Software Engineer
dlerickson
Posts: 80
Joined: Tue Jan 21, 2014 11:35 am
Location: Austin, TX

Re: Check Processing: Order Number

Post by dlerickson »

Thanks much, that should do the trick. One other question: is there a way to isolate only checks from other types of ledger documents? Or is that even a relevant question (again, I'm unfamiliar with this area of Select)?
yatin.t
Posts: 24
Joined: Tue Jan 07, 2014 9:40 am
Location: Raleigh, NC

Re: Check Processing: Order Number

Post by yatin.t »

Try this in your custom print job handler - the same approach applies to other ledger document types.

Code: Select all

var item = printJob.Items.FirstOrDefault();
if (item != null && item.Properties.ContainsKey("Document"))
{
    var document = item.Properties["Document"] as IDocument;
    if (document != null)
    {
        // look for the PT Report Type tag
        var tag = document.Tags.FirstOrDefault(t => t.Name == SoftPro.Documents.Client.Constants.DocumentTag.ProTrustReportType);
        if (tag != null)
        {
            // see if the PT report type ID matches the one defined for a check
            if (new Guid(tag.Value) == SoftPro.Documents.Client.Constants.ProTrustReportType.Check)
            {
                // it's a check document
            }
        }
    }
}
Yatin Tawde
Softpro
Software Engineer
Post Reply