Hi All,
I saw some similar posts about creating Papercut printer scripts here so I'm hoping you can help me out. I'm looking to create a printer script in Papercut that will discount any job sent to any printer during off-peak hours (M-R 4-8pm and Sunday 12-5pm). I asked for Papercut's assistance but all I was told was that I'm missing some semicolons and I should be all set. Can someone take a look at whet we've written and offer any insight?
/** Discount printing during off-peak
*
* Encourage users to print during periods of low
* activity by offering a discount of 20% during
* the period between 4:00pm and 8:00pm M-R, and
* the period between 12:00pm and 5:00pm on Sundays.
*/
var SUNDAY = 0;
var MONDAY = 1;
var TUESDAY = 2;
var WEDNESDAY = 3;
var THURSDAY = 4;
function getMinutesSinceMidnight(hours, minutes) {
return 60 * hours + minutes;
}
function printJobHook(inputs, actions) {
//Set times for discounts.
var START_OF_DISC = getMinutesSinceMidnight(16, 00); //4:00pm
var END_OF_DISC = getMinutesSinceMidnight(20, 00); //8:00pm
var SUN_DISC_START = getMinutesSinceMidnight(12, 00); //12:00pm
var SUN_DISC_END = getMinutesSinceMidnight(17, 00);//5:00pm
var day = inputs.job.date.getDay();
var hours = inputs.job.date.getHours();
var minutes = inputs.job.date.getMinutes();
var timeOfJob = getMinutesSinceMidnight(hours, minutes);
var inDiscountDays = (SUNDAY >= day && day <= THURSDAY);
var inDiscountTimes = ((timeOfJob >= START_OF_DISC && timeOfJob <= END_OF_DISC) || (timeOfJob >= SUN_DISC_START && timeOfJob <= SUN_DISC_END));
if (inDiscountDays && inDiscountTimes) {
//Apply 20% discount:
var newCost = inputs.job.cost * 0.80;
actions.job.setCost(newCost);
// Record that as discount was applied in the job comment.
actions.job.addComment("20% off-peak discount applied");
}
}
Thanks,
Max