As explained in our Using an Infoplus Script to Customize 3PL Billing Invoice Worksheets article, Infoplus scripts can be used to customize 3PL Billing Invoice worksheets.  Please refer to that article for the general variables and objects that are available when creating this script type.  


The content that follows in this article is an example script that looks at input rows that have a Receipt Quantity Per Case value that would go into an Invoice Worksheet & corresponding backup file.  For rows that have this value, the script is calculating what the Estimated Cases value should be, then rounds the Estimated Cases up to the nearest whole number.  This is useful when you want to consider partial cases as full cases when producing invoice worksheets.


The script starts by using a for loop to loop through all input rows, calculating the estimated cases for each row.  It then uses the Math.ceil method to round the estimated cases value up to the nearest whole number.  After the loop is finished, these changes are applied to the invoice worksheet by using utils.setOutputLines();


utils.log("Running Invoice Worksheet Script..."); 
utils.log(""); 

utils.log("Consider a partial case a full case in the estimated cases field"); 
var totalEstimatedCases = 0;
var outputLine = utils.originalLines.get(0);
for(var i=0; i<utils.inputEntities.size(); i++) 
{
  var inputEntity = utils.inputEntities.get(i); 
  
  if(inputEntity.getReceiptQuantityPerCase())  
  {  
    var lineQty = inputEntity.getQuantity();
    var qtyPerCase = inputEntity.getReceiptQuantityPerCase();
    var roundedEstmatedCases = Math.ceil(lineQty/qtyPerCase);

    utils.log("lineQty: " + lineQty);
    utils.log("qtyPerCase: " + qtyPerCase);
    utils.log("Rounded Estimated Cases: " + roundedEstmatedCases);
    utils.log(""); 
    var thisQuantity = parseInt(roundedEstmatedCases);
    inputEntity.setEstimatedCases(thisQuantity);
    totalEstimatedCases += thisQuantity;
  }
}

utils.log("Manipulate data in the original lines..."); 
var outputLines = utils.originalLines; 

outputLine.quantity = totalEstimatedCases;

utils.log("Putting new list as output to be used when generating invoice..."); 
utils.setOutputLines(outputLines);