Primary vs Packaging UOM

Navigation:  Customer > Billing Wizard > Per Transaction Billing Setup > AutoBilling Scripts >

Primary vs Packaging UOM

Previous pageReturn to chapter overviewNext page

Description: Charge based on shipping primary inventory or packaged inventory for each SKU

Script: (don't let the size of this one scare you)

Customer-BillingWizard-PerTransBill-AutoBill-Script121

User Input:

Customer-BillingWizard-PerTransBill-AutoBill-Script121Setup

Explanation: Longest Script yet, by far…    The first thing this script depends on is the wt.OrderItems collection having something in it.  That means there have to be OrderItems attached to this Order for this script to work.  It won't work for other types of Transactions at all.            The next thing we do is set up base values for this script.  First an empty Charge Detail object.  Next we create a group of items by ItemID, called groupby_itemId.  Then we create a sorted list (kinda) with ItemID as the key, and each of the grouped order items as values.  We also create a value called itemQty and append a value that's the Sum of the PrimaryInvQty on all the OrderItems with that ItemID in them.  Whew.

Next, (yes, there's lots more) we pull in the script parameters, which include Rate per Primary Unit, Rate per Packaging Unit, Rate per Primary Unit (ItemID Specific), Rate per Packaging Unit (ItemID Specific).  The last two, the ItemID specific ones, can be added multiple times to cover multiple ItemIDs.

So, now we're actually ready to do something.  We loop through the itemId list, which has an ID and a Qty.  We use the ID to get a Description out of other list (with order items in it).  We get a value called pack from InvUnits/LablUnit, if it exists and is non-zero.  Otherwise pack = 0.  eachCharge = the eachCharge default (from script) unless the ID is in the list of ID Specific charges, then it uses that.  Same for the CartonCharge.  We also get types for each and package from the itemDescription (which is the Item, now that I look closer)

Next we calculate how many packages we have, if applicable, or just how many individual items we have if there are no packages.  It looks like we handle left-overs as well.  So, we loop and if eachQty > 0 we create a charge for eaches with the each charge (default or specific) and add it to our charges list.  If pack > 0, we do the same thing there.  The total charge is the charge per unit times the number of units, either eaches or packages.  This is done for each item in the Order.