We thought a simple way to achieve this would be to apply a 100% discount to jobs submitted to the queue based on a date range and give the user a little note to let them know how much they’d not been charged. As always, we put on our thinking caps, grabbed some roast ox crisps and came up with the following script.
To begin with, we need to declare our variables and work out what our date range is for the Exams.
var day = inputs.job.date.getDate(); var month = inputs.job.date.getMonth(); if ((day >= 19 && month == 5) || (day <= 23 && month == 5)) {
So in the above example, we will be looking for any jobs submitted between the 19th and 23rd of June, (Yes June is 5, we start counting with January = 0, remember developers invented this system and they work in mysterious ways).
Then we must declare the cost and saving variables.
var newCost = inputs.job.cost * 0.00; var saving = inputs.job.cost - newCost;
Once we have done this, we need to add the actions to set the new job cost and define the message we will send to the user.
actions.job.setCost(newCost); actions.job.addComment("100% Exam time discount applied.");
Finally, we’d like to send the message to the user via the PaperCut client tool.
actions.client.sendMessage("You saved " + inputs.utils.formatCost(saving) + " printing your exam related job.");
function printJobHook(inputs, actions) { if (!inputs.job.isAnalysisComplete) { return; } var day = inputs.job.date.getDate(); var month = inputs.job.date.getMonth(); if ((day >= 19 && month == 5) || (day <= 23 && month == 5)) { var newCost = inputs.job.cost * 0.00; var saving = inputs.job.cost - newCost; actions.job.setCost(newCost); actions.job.addComment("100% Exam time discount applied."); actions.client.sendMessage("You saved " + inputs.utils.formatCost(saving) + " printing your exam related job."); } }