Email Invoice Due Reminder Using Workflows
The following describes a workflow that will send an email out to customers to remind them their invoice is going to be due (i.e. prior to the due date being reached).
Configuration
Add action (script below). The script needs to be updated to reflect the HTML for your email, etc. Name: Reminder Email
DateTime mydate = DateTime.Now.AddDays(10); //enter the number of days PRIOR to the due date you would like this to be sent DateTime myDateMin = new DateTime(mydate.Year, mydate.Month, mydate.Day, 0, 0, 0); DateTime myDateMax = new DateTime(mydate.Year, mydate.Month, mydate.Day, 23, 59, 59); ViewInvoiceQuery iq = new ViewInvoiceQuery(); iq.DueDateMin = myDateMin; iq.DueDateMax = myDateMax; iq.Paid = false;String invoiceName = ""; foreach (ViewInvoice invoice in ViewInvoice.GetCollection(ref iq)) { invoiceName = invoice.Name.ToString();Logisense.Boss.Logic.Core.User user = User.GetByID(invoice.UserID) as Logisense.Boss.Logic.Core.User; try { String pa = user.GetProfileAnswers("Recurring")[0]; //Logic.Core.Alert.Create(pa.Length.ToString(), 1); if (pa.Length > 0) { //Logic.Core.Alert.Create(user.Name.ToString(), 1); ContactTypeQuery ctq = new ContactTypeQuery(); int contactname = 0; ctq.Name = "Billing Contact"; ctq.OwnerIDMin = user.ActingOwnerID; ctq.OwnerIDMax = user.ActingOwnerID; foreach (ContactType ct in ContactType.GetCollection(ref ctq)) { contactname = ct.ID; } Contact contact = Contact.GetByID(user.SearchContactByContactTypeID(contactname)[0].ID); //Logic.Core.Alert.Create(contact.FirstName.ToString(), 1); String tableheader = ""; String body2 = ""; String table = ""; String bodybalance = ""; String body = " Dear " + contact.FirstName.ToString() + ",Please note that invoice #" + invoiceName + " is coming due on " + invoice.DueDate.ToLongDateString() + " If you have any questions or concerns about this bill please contact us immediately and at least 5 days prior to due date so we can help you rectify any issues. If payment has been sent, thank you very much! "; String footer = "Best regards, Company "; //User rkozub = User.GetByName("rkozub"); Logisense.Boss.Logic.Email.SendToBillingContacts(user, "Payment Reminder", body + " " + "" + footer + "", null); } } catch (Exception e) { //Logic.Core.Alert.Create(user.Name.ToString() + user.GetProfileAnswers()[0].ToString(), 1); //return false; } } return true;
2. Create a Workflow Event:
Name: 4am
Event Code: 4am
3. Create a Workflow:
Event: 4am
Trigger: Auto
Action Script: Reminder Email