In between internal training on <a href="https://staging.selectec.com/products/presto-v2/" target="_blank" rel="noopener noreferrer">Presto</a> and <a href="https://staging.selectec.com/products/kpax/" target="_blank" rel="noopener noreferrer">KPAX</a> I sat down with <a href="https://staging.selectec.com/team/jonathan-bennetts/" target="_blank" rel="noopener noreferrer">John</a> and collaborated on the next idea for our famous PaperCut Print Script Of The Month.

Is it always left to the last minute? No, yes, maybe...sometimes real work gets in the way of the fun things and if we do not get any inspiration from support emails/calls for SOTM we have to start using our imagination.

With <a href="https://staging.selectec.com/team/paul-baggus/" target="_blank" rel="noopener noreferrer">Paul</a> enjoying £30 off a Sonos Play:1 from <a href="http://www.johnlewis.com/brand/sonos/_/N-1z13xxf?&amp;s_kwcid=1dx43700015359186439&amp;tmad=c&amp;tmcampid=1&amp;gclid=COP9-LeixNACFUG4Gwod444NyA&amp;gclsrc=aw.ds" target="_blank" rel="noopener noreferrer">John Lewis</a> and some of the support team buying cheap Amazon <a href="https://www.amazon.co.uk/dp/B01DFKBL68/ref=fs_bis" target="_blank" rel="noopener noreferrer">Echo Dots</a> to play their Spotify playlists at home we thought a Black Friday themed Script Of The Month should be made (long live consumerism)!

Grab a cup of coffee and a biscuit (we suggest <a href="http://www.tesco.com/groceries/product/details/?id=252108977" target="_blank" rel="noopener noreferrer">these</a>) and we shall begin. The idea behind this script is to offer (but not advertise) discounted printing in a "flash sale" style. With different discounts applied throughout the day.

First thing to do is create a bunch of variables these will cover the discount to give, messages to show and the time to start the "flash sale".
<pre class="">// Normal Discount Amount - default 5%
var DISCOUNT_PERCENT = 0.95;
// Discount Amount for "Flash sales" - default 10%
var FLASH_SALE_PERCENT = 0.90;
// Comment to show in job log
var JOB_COMMENT = "Black Friday Discount";
// Message to show the users for normal sale
var SALE_MESSAGE = "Black Friday Deal - This print job will only cost you '" + inputs.job.cost * DISCOUNT_PERCENT + "'";
// Message to show the users when the flash sale is on
var FLASH_SALE_MESSAGE = "Black Friday Flash Sale - This print job will only cost you '" + inputs.job.cost * FLASH_SALE_PERCENT + "'";
// Hour to start flash sale - Default 12pm
var FLASH_START = 16;
// Hour to end flash sale - Default 1pm
var FLASH_END = 17;
// Set flash sale to false
var FLASH_SALE = false;</pre>
Now we will need to work out if the “flash sale” is on by checking the hour the job was sent and making sure it isn’t over the end hour. To do this we will use inputs.job.date.getHours() you can also use getDays() and getMinutes() if you really wanted to. Once we have worked that out, we can change the value of FLASH_SALE to true for the next part.
<pre class="">// Work out if it is time for a flash sale
if (inputs.job.date.getHours() &gt;= FLASH_START &amp;&amp; inputs.job.date.getHours() &lt; FLASH_END) {
  // Enable the flash sale
  FLASH_SALE = true;
}</pre>
We have a variable set that we can use to tell us if the "flash sale" is on so we can put that in an if statement then use actions.client.prompOK() to inform the user and change the cost of the job to the discounted rate using inputs.job.cost().
<pre class="">// If flash sale time
if (FLASH_SALE) {
  // Display the Flash Sale Message
  actions.client.promptOK(FLASH_SALE_MESSAGE,{'hideJobDetails': true});
  // Set the new cost of the job
  actions.job.setCost(inputs.job.cost * FLASH_SALE_PERCENT);
} else {
  // Display normal deal Message
  actions.client.promptOK(SALE_MESSAGE,{'hideJobDetails': true});
  // Set the new cost of the job
  actions.job.setCost(inputs.job.cost * DISCOUNT_PERCENT);
}</pre>
All that is left to do now is to add a note to the job so that we don't forget why the discount was applied, to do this we use actions.job.addComment().
<pre class="">// Add comment to job so we remember why there was as discount
actions.job.addComment(JOB_COMMENT);</pre>
That is it for this month and as always the complete print script is below. If you have your own requirements for a print script and you don’t have the time or in-house experience to make it then simply <a href="/contact/">contact us</a>.
<div class="well well-lg">
<h3 style="text-align: center;">Get in touch today | <a href="mailto:sales@selectec.com">sales@selectec.com</a></h3>
</div>
<pre class="">/*
* Black Friday
*
* Read more at https://staging.selectec.com/papercut-print-script-of-the-month-14-black-friday/
*/

function printJobHook(inputs, actions) {
  
  // Make sure analysis is complete
  if (!inputs.job.isAnalysisComplete) {return;}
  
  // Normal Discount Amount - default 5%
  var DISCOUNT_PERCENT = 0.95;
  // Discount Amount for "Flash sales" - default 10%
  var FLASH_SALE_PERCENT = 0.90;
  // Comment to show in job log
  var JOB_COMMENT = "Black Friday Discount";
  // Message to show the users for normal sale
  var SALE_MESSAGE = "Black Friday Deal - This print job will only cost you '" + inputs.job.cost * DISCOUNT_PERCENT + "'";
  // Message to show the users when the flash sale is on
  var FLASH_SALE_MESSAGE = "Black Friday Flash Sale - This print job will only cost you '" + inputs.job.cost * FLASH_SALE_PERCENT + "'";
  // Hour to start flash sale - Default 12pm
  var FLASH_START = 16;
  // Hour to end flash sale - Default 1pm
  var FLASH_END = 17;
  // Set flash sale to false
  var FLASH_SALE = false;
  
  // Work out if it is time for a flash sale
  if (inputs.job.date.getHours() &gt;= FLASH_START &amp;&amp; inputs.job.date.getHours() &lt; FLASH_END) {
    // Enable the flash sale
    FLASH_SALE = true;
  }
  
  // If flash sale time
  if (FLASH_SALE) {
    // Display the Flash Sale Message
    actions.client.promptOK(FLASH_SALE_MESSAGE,{'hideJobDetails': true});
    // Set the new cost of the job
    actions.job.setCost(inputs.job.cost * FLASH_SALE_PERCENT);
  } else {
    // Display normal deal Message
    actions.client.promptOK(SALE_MESSAGE,{'hideJobDetails': true});
    // Set the new cost of the job
    actions.job.setCost(inputs.job.cost * DISCOUNT_PERCENT);
  }
  
  // Add comment to job so we remember why there was as discount
  actions.job.addComment(JOB_COMMENT);
  
}
</pre>