/* * Different costs for different user groups plus increased * copying costs for students during peak hours. */ function deviceJobLogHook(inputs, actions) { // If it's not a copy job we won't run the rest of this script. if (!inputs.job.isCopy) { return; } // staff get charged under a different cost model if (inputs.user.isInGroup("Staff")) { calculateCopyCostForStaff(inputs,actions); } // students can get charged extra for using the copier // during peak hour. if(inputs.user.isInGroup("Students")) { calculateCopyCostForPeakHour(inputs,actions); } } /** * This function adjusts the job cost if it's a staff member. */ function calculateCopyCostForStaff(inputs, actions) { // Using a customised pricing model here // We'll keep it simple and differentiate only by paper size - // we won't worry about duplex or color mode for this example. var staffSimpleModel = { A3: 0.3, A4: 0.15, Default: 0.15 // fall back to default if we can't find the right size }; // analyze the job var totalPages = inputs.job.totalPages; var paperSizeName = inputs.job.paperSizeName; // do a simple calculation var costPerPage = staffSimpleModel[paperSizeName] ? staffSimpleModel[paperSizeName] : staffSimpleModel["Default"]; var adjustedCost = costPerPage * totalPages; // change the job cost actions.job.setCost(adjustedCost); actions.job.addComment("Costs adjusted for staff member"); } /** * For this function we'll adjust the copy job pricing * if the job was done during peak hours. */ function calculateCopyCostForPeakHour(inputs, actions) { // Set the peak period var PEAK_PERIOD_START = 11; // 11am var PEAK_PERIOD_END = 15; // 3pm var PEAK_RATE = 10; // copying costs are an extra 10% during peak hour var cost = inputs.job.cost; var date = new Date(); var hour = date.getHours(); if (hour >= PEAK_PERIOD_START && hour < PEAK_PERIOD_END) { var peakCost = cost + (cost * (PEAK_RATE / 100)); actions.job.setCost(peakCost); actions.job.addComment("Costs adjusted for peak hour"); } }