Page 1 of 1

Batch Print / Emailing

PostPosted: Tue Feb 05, 2019 2:34 pm
by SBarnes
Can you give an example of how to use JiwaFinancials.Jiwa.JiwaSales.BatchPrinting.BatchPrint mainly to batch email invoices given a list of invoiceIDs that I already have to fill the candidates with?

Re: Batch Print / Emailing

PostPosted: Wed Feb 06, 2019 9:11 am
by DannyC
To add some clarity, we have a schedule running every n minutes which processes orders. This is running fine.
The client now wants an email sent to the customer with their invoice - as if they'd manually clicked the 'email' ribbon button but done when the orders are processed.

I've spent ages fiddling with the plugin code to try & get it to email but nothing I try is working.
What do you suggest is the best way to do it?

As a last resort I though we could use the batch print/email and pass in the processed orders.

Either way, the client just needs to see an email has been sent to the customer.
v 7.2. C#

Re: Batch Print / Emailing

PostPosted: Wed Feb 06, 2019 10:50 am
by Mike.Sheen
Do you have anything in the Candidates collection? And does each item in the Candidates collection have at least one item in the Actions collection?

Candidates are just the sales orders. Actions are either email or print, and the report type to use and a few other properties.

You can manually add to the candidates and actions collection, or you can add using a range (which is passed to a stored procedure defined in system settings - default is usp_JIWA_SalesOrders_SOBatchPrintGetActions).

Here's some code showing how to do that:

Code: Select all
using System;
using JiwaFinancials.Jiwa.JiwaApplication;
using JiwaFinancials.Jiwa.JiwaODBC;
using JiwaFinancials.Jiwa;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var manager = new Manager();
            manager.Logon("localhost", "JiwaDemo720", database.AuthenticationModes.JiwaAuthentication, "Admin", "password");

            var batchPrint = manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.BatchPrinting.BatchPrint>(null);
            // Add a range of invoices
            string minRunNo = "";
            string maxRunNo = "";
            batchPrint.GetDefaultRunNoRange(ref minRunNo, ref maxRunNo);

            string minDebtorName = "";
            string maxDebtorName = "";
            batchPrint.GetDefaultDebtorNameRange(ref minDebtorName, ref maxDebtorName);

            string minDebtorAccountNo = "";
            string maxDebtorAccountNo = "";
            batchPrint.GetDefaultDebtorAccountNoRange(ref minDebtorAccountNo, ref maxDebtorAccountNo);

            string minDebtorClassification = "";
            string maxDebtorClassification = "";
            batchPrint.GetDefaultDebtorClassificationRange(ref minDebtorClassification, ref maxDebtorClassification);

            string minDebtorGroup = "";
            string maxDebtorGroup = "";
            batchPrint.GetDefaultDebtorGroupRange(ref minDebtorGroup, ref maxDebtorGroup);

            batchPrint.GetActions("100500", "100500",
                                    1, batchPrint.GetMaximumSOHistoryNo(),
                                    minRunNo, maxRunNo,
                                    minDebtorName, maxDebtorName,
                                    minDebtorAccountNo, maxDebtorAccountNo,
                                    minDebtorClassification, maxDebtorClassification,
                                    minDebtorGroup, maxDebtorGroup,
                                    new DateTime(2000, 01, 01),
                                    DateTime.Now,
                                    new DateTime(2000, 01, 01),
                                    DateTime.Now,
                                    JiwaFinancials.Jiwa.JiwaSales.BatchPrinting.BatchPrint.BatchPrintOverrides.EmailOnly);
            batchPrint.Process();
        }
    }   
}


This will populate the candidates and actions collections - and then email.

Note that the email method is defined by a plugin - you need to have an email provider plugin enabled to send anything. Also note you cannot use Outlook as the provider when emailing from services. I provided a plugin in this forum post which adds to the staff member a drop-down field allowing you to specify how emails for that staff member should be sent - that may be of use if you have the requirement to mix email methods.

Re: Batch Print / Emailing

PostPosted: Fri Feb 08, 2019 9:30 am
by DannyC
I've managed to send an email when each candidate gets processed but not using the batch.

I get the SalesOrderReport via different means (setting up a System Configuration setting where the invoice CR is saved) and then instead of using candidate which looks like a trimmed down entity of a full sales order, I instantiated the full sales order object and just used
Code: Select all
salesOrder.Email(salesOrderReport,from, to, etc etc etc)


Anyway, took me about a week to nut out around 10 lines of code but seems to be working sweet.