Jump to content

Recommended Posts

Posted

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

Posted

Max,

 

Have you looked at the sample script within papercut itself, that does the same job? That does it's calculations straight on hours rather than resorting to minutes from midnight. Plus you seem to be missing the is job analysis complete bit;

 

Your in discount days should probably read

var inDiscountDays = (day >= SUNDAY && day <= THURSDAY)

 

And the logic isn't there in your InDiscountTimes to say that sunday has different times, it will check the time of job versus both hour criteria i would break the logic down much further.

 

If today is sunday and job in sundaydiscount times =true then apply discount

if today is other discount day and job in discount times = true then apply discount

 

Sorry i'm only just looking at papercut scripts myself so cant be of much more use.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...