Create a Hardcopy Invoice Fee Using Workflows

This article describes how to create Workflows to charge for invoices hardcopies.

Implementation Overview

There are several Workflows that are run for hardcopy invoice charges to be applied properly. First a workflow called ‘Hardcopy Invoice Charge Initial Update’ needs to be manually run to add a ‘Hardcopy Invoice Surcharge’ package to any existing users that are set to receive a hardcopy invoice (this package is used to apply the charge for the hardcopy, more on this below). This ‘Hardcopy Invoice Charge Initial Update’ workflow can be deleted after being run because it is no longer required.

Note: users are set to receive invoice hardcopies based on their Invoice Configuration, specifically the ‘Default Invoice Delivery Type’ setting. For more information on how to configure invoices in the AdminPortal see the Invoice Configuration KB article.

After Configuration is complete the application of invoice charges will be automated. Going forward when user updates occur another workflow will run that checks the users invoice delivery type. The surcharge package is added or canceled on the users account as needed based on the invoice delivery type setting (i.e. whether or not the user is set to receive a hardcopy invoice).

Configuration

  1. Create a Package and Service called “Hardcopy Invoice Surcharge” and configure as needed. If the name is changed the Actions within the XML (see below) will have to be updated as well

  2. Load the Setup page

  3. Under the Configuration heading click Import

  4. Copy the Workflow XML below, paste it into the XML Data textbox, check off Create Workflow Event and click Save

<Export> <Workflow Name="Hardcopy Invoice Charge Initial Update" Description="Hardcopy Invoice Charge Initial Update" Valid="True" StartDate="12/19/2008 3:12:43 PM" Internal="False" ReferenceName="WORKFLOW18" /> <Action Name='Hardcopy Invoice Inital Update' Script=' int emailAndHardcopy = InvoiceDeliveryType.GetByName("Email &amp Hardcopy").ID; //note the escape sequence for ampersand int hardcopy = InvoiceDeliveryType.GetByName("Hardcopy").ID; //you will want to get all the delivery types receieve a hardcopy Owner owner = Owner.GetByID(Convert.ToInt32(context["OwnerID"])); Package package = owner.SearchPackageByName("Hardcopy Invoice Surcharge")[0]; //change this to the name of the package that charges for the invoice ViewUserParentByInvoicerQuery invoiceQuery = new ViewUserParentByInvoicerQuery(); foreach (ViewUserParentByInvoicer v in ViewUserParentByInvoicer.GetCollection(" WHERE OwnerID = " + owner.ID + " AND Top_UserID IS NULL")) { User user = User.GetByID(v.InvoiceUserID); int userInvoiceDeliveryType = user.GetInvoiceConfiguration().Default_InvoiceDeliveryTypeID; if (userInvoiceDeliveryType == hardcopy || userInvoiceDeliveryType== emailAndHardcopy) { UserBillCycle billCycle = user.GetUserBillCycle(); DateTime dateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, billCycle.Day).AddMonths(-1); Logisense.Boss.Logic.Core.Package.AddPackage(user.ID, package.ID, dateTime, true); } } return true;' ReferenceName="ACTION24" /> <WorkflowTransition Workflow="@WORKFLOW18" WorkflowTransitionTriggerType="/WorkflowTransitionTriggerType=Auto" Action="@ACTION24" Name="Hardcopy Invoice Inital Update" Description="Update existing users" ReferenceName="WORKFLOWTRANSITION18" /> <WorkflowPlace Workflow="@WORKFLOW18" WorkflowPlaceType="/WorkflowPlaceType=Start" Name="Start" ReferenceName="WORKFLOWPLACE35" /> <WorkflowArc Workflow="@WORKFLOW18" WorkflowTransition="@WORKFLOWTRANSITION18" WorkflowPlace="@WORKFLOWPLACE35" WorkflowArcDirectionType="/WorkflowArcDirectionType=In" Name="35" ReferenceName="WORKFLOWARC35" /> <WorkflowPlace Workflow="@WORKFLOW18" WorkflowPlaceType="/WorkflowPlaceType=End" Name="End" ReferenceName="WORKFLOWPLACE36" /> <WorkflowArc Workflow="@WORKFLOW18" WorkflowTransition="@WORKFLOWTRANSITION18" WorkflowPlace="@WORKFLOWPLACE36" WorkflowArcDirectionType="/WorkflowArcDirectionType=Out" Name="36" ReferenceName="WORKFLOWARC36" /> <WorkflowEvent Name="User Changed" EventCode="User.Create,User.Update" ReferenceName="WORKFLOWEVENT18" /> <Workflow WorkflowEvent="@WORKFLOWEVENT18" Name="Hardcopy Invoice Charge Update" Description="Hardcopy Invoice Charge Update" Valid="True" StartDate="12/19/2008 3:13:27 PM" Internal="False" ReferenceName="WORKFLOW19" /> <Action Name="Hardcopy Invoice Update" Script=' int emailAndHardCopy = InvoiceDeliveryType.GetByName("Email &amp Hardcopy").ID; int hardCopy = InvoiceDeliveryType.GetByName("Hardcopy").ID; Owner owner = Owner.GetByID(Convert.ToInt32(context["OwnerID"])); Package package = owner.SearchPackageByName("Hardcopy Invoice Surcharge")[0]; User user = User.GetByID(Convert.ToInt32(context["UserID"])); UserPackage[] userPackages = user.SearchUserPackageByPackageID(package.ID); int userInvoiceDeliveryType = user.GetInvoiceConfiguration().Default_InvoiceDeliveryTypeID; if (userInvoiceDeliveryType == emailAndHardCopy || userInvoiceDeliveryType == hardCopy) { if (userPackages.Length == 0 || userPackages[0].GetStatusType().Name != "Active") { UserBillCycle billCycle = user.GetUserBillCycle(); DateTime dateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, billCycle.Day).AddMonths(-1); Logisense.Boss.Logic.Core.Package.AddPackage(user.ID, package.ID, dateTime, true); } } else { if (userPackages.Length > 0) { if (userPackages[0].GetStatusType().Name == "Active") { Logisense.Boss.Logic.Core.UserPackage userPackage = userPackages[0] as Logisense.Boss.Logic.Core.UserPackage; userPackage.StatusTypeID = StatusType.GetByName("Canceled").ID; userPackage.Refund = Logisense.Boss.Logic.Core.UserPackage.RefundOptions.Full; userPackage.Update(); } } } return true;' ReferenceName="ACTION25" /> <WorkflowTransition Workflow="@WORKFLOW19" WorkflowTransitionTriggerType="/WorkflowTransitionTriggerType=Auto" Action="@ACTION25" Name="Hardcopy Invoice Update" Description="Update user" ReferenceName="WORKFLOWTRANSITION19" /> <WorkflowPlace Workflow="@WORKFLOW19" WorkflowPlaceType="/WorkflowPlaceType=Start" Name="Start" ReferenceName="WORKFLOWPLACE37" /> <WorkflowArc Workflow="@WORKFLOW19" WorkflowTransition="@WORKFLOWTRANSITION19" WorkflowPlace="@WORKFLOWPLACE37" WorkflowArcDirectionType="/WorkflowArcDirectionType=In" Name="37" ReferenceName="WORKFLOWARC37" /> <WorkflowPlace Workflow="@WORKFLOW19" WorkflowPlaceType="/WorkflowPlaceType=End" Name="End" ReferenceName="WORKFLOWPLACE38" /> <WorkflowArc Workflow="@WORKFLOW19" WorkflowTransition="@WORKFLOWTRANSITION19" WorkflowPlace="@WORKFLOWPLACE38" WorkflowArcDirectionType="/WorkflowArcDirectionType=Out" Name="38" ReferenceName="WORKFLOWARC38" /> </Export>
  1. On the Setup page under Extensibility Click on Workflows

  2. Click on the Hardcopy Invoice Charge Initial Update workflow and then Run. Executing this Workflow will add the ‘Hardcopy Invoice Surcharge’ package to any existing users that are currently set to hardcopy. You have to put something in the “Context”, use “Junk=1″

  3. Wait for the workflow to finish running. Note: the Event Manager Service must be running for Workflows to execute

  4. Verify the package was added to a user that is set to hardcopy. There should also be an appropriate charge on the users account

  5. Delete the “Hardcopy Invoice Charge Initial Update” workflow as it is only ever used once