Jump to content

Recommended Posts

Posted

I want to limit the number of monthly color printing for a specific group. I edited the daily color limit script but I'd like to make sure it's correct before testing. My concern is the !inputs.user.isInGroup() group code. I want the 200 monthly limit to apply to the group and not to the individual. So, if the group color count hits 200 then no one in the group can no longer print. I'd also like to know if I have the monthly code correct as well. Thanks!

 

/*

* Monthly color page limit

*

* Sometimes, a high price tag just isn't enough to discourage users from

* printing in color. This recipe imposes a fixed limit on the number of color

* pages a user can print per month.

*

* Imposing a color page quota is a better solution than separate balances for

* color and black & white. Separate balances are more confusing (two accounts

* to manage) and also can lead to waste. The user may for example run out of

* black and white credit, and therefore be forced to print in color wasting

* resources. This method (an overlayed color quota) solves these issues.

*/

function printJobHook(inputs, actions) {

// Modify this value to change the daily color page limit.

var MAX_COLOR_PAGES_PER_MONTH = 200;

if (!inputs.job.isAnalysisComplete) {

return;

}

if (!inputs.job.isColor) {

// Not color so no need to check and apply any limits.

return;

}

if (!inputs.user.isInGroup == "GroupName") {

//

return;

}

var currentColorCount = inputs.user.getNumberProperty("color-per-month");

if (currentColorCount == null) currentColorCount = 0;

var currentMonthIndex = inputs.job.date.getMonth();

var monthLastSeen = inputs.group.getProperty("color-month-last-seen");

if (monthLastSeen == null || monthLastSeen != currentMonthIndex) {

// It's a new month. Reset the current count value to zero.

currentColorCount = 0;

}

currentColorCount += inputs.job.totalColorPages;

if (currentColorCount > MAX_COLOR_PAGES_PER_MONTH) {

var deniedMessage = "This print job has been denied. You have exceeded"

+ " your monthly limit of " + MAX_COLOR_PAGES_PER_MONTH

+ " color pages per month. Please print in grayscale.";

actions.client.sendMessage(deniedMessage);

actions.job.cancelAndLog("This job was denied because you have exceeded"

+ " the monthly color quota.");

return;

}

// If we're here, then it's OK for the job to proceed.

// Save the current monthly count

actions.group.onCompletionSaveProperty("color-month-last-seen", currentMonthIndex);

// Note: Set is used for simplicity (see "Rate limit by department"

// for use of increment).

actions.group.onCompletionSaveProperty("color-per-month", currentColorCount);

}

Posted (edited)

Hiya, PaperCutter here. I asked the boffins to review your code and they replied with the following. Note: I'm rubbish at laying out the code correctly:

 

 

/*

* Monthly color page limit

*

* Sometimes, a high price tag just isn't enough to discourage users from

* printing in color. This recipe imposes a fixed limit on the number of color

* pages a user can print per month.

*

* Imposing a color page quota is a better solution than separate balances for

* color and black & white. Separate balances are more confusing (two accounts

* to manage) and also can lead to waste. The user may for example run out of

* black and white credit, and therefore be forced to print in color wasting

* resources. This method (an overlayed color quota) solves these issues.

*/

function printJobHook(inputs, actions) {

 

// Modify this value to change the daily color page limit.

var MAX_COLOR_PAGES_PER_MONTH = 200;

 

if (!inputs.job.isAnalysisComplete) {

return;

}

 

//Is the job color

if (inputs.job.isColor) {

//Yes so carry on....

if (inputs.user.isInGroup("Students") {

//Color, and Students - so carry on

 

//Create a variable to track the number of colour impressions done this month

var currentColorCount = inputs.user.getNumberProperty("color-per-month");

 

 

//Test to see if there is a current color count, or not (i.e. null)

if (currentColorCount == null){

//There is no current colour count, which says this is the first run of this script, so set it to zero

currentColorCount = 0;

}

 

//Create a variable to the current month number so we can track per month

var currentMonthIndex = inputs.job.date.getMonth();

 

//Retrieve the stored variable for the number month this script was last run so we can determine if we've had any prints this month...

var monthLastSeen = inputs.group.getProperty("color-month-last-seen");

 

//Test to see if the monthLastSeen has never been set (first run of this script) or doesn't equal the current month (first run this month)

if (monthLastSeen == null || monthLastSeen != currentMonthIndex) {

// It's a new month or never ran. Reset the current count value to zero.

currentColorCount = 0;

}

 

//Add the current number of pages from this job to the overall monthly count

currentColorCount += inputs.job.totalColorPages;

 

//Will it exceed the monthly limit

if (currentColorCount > MAX_COLOR_PAGES_PER_MONTH)

{

//It does - so cancel it

var deniedMessage = "This print job has been denied. You have exceeded"

+ " your monthly limit of " + MAX_COLOR_PAGES_PER_MONTH

+ " color pages per month. Please print in grayscale.";

 

actions.client.sendMessage(deniedMessage);

 

actions.job.cancelAndLog("This job was denied because you have exceeded"

+ " the monthly color quota.");

}

else{

//It will not exceed the limit so Let it Be John Lennon

 

// Save the current monthly count

actions.group.onCompletionSaveProperty("color-month-last-seen", currentMonthIndex);

// Note: Set is used for simplicity (see "Rate limit by department"

// for use of increment).

actions.group.onCompletionSaveProperty("color-per-month", currentColorCount);

}

 

 

 

 

}

else{

//Not in the group Students, nothing to do

}

}

else{

//Not color, nothing to do

}

 

 

 

}

Edited by PaperCutterAl
  • Thanks 1
Posted

Hi PaperCutterAI,

 

That worked with some tweaking. There was a missing closed parenthesis and I changed the remaining "group" to "user" and it was able to cancel the job after reaching the monthly group limit. Now, I need to test either sending a denied email or popup notification.

 

Thanks,

 

Judy

  • Thanks 1

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...