Skip to main content
Inspiring
March 13, 2023
Question

GIVING FREE BRODUCT BASE ON DATE & NUMBER OF PRODUCT BOUGHT

  • March 13, 2023
  • 1 reply
  • 465 views

Below is a script i need help modifying.

function calcTVI() {
var rowNumber = event.target.name.replace("TVI.", "");
var startDateString = "01-08-2022";
var endDateString = "01-09-2022";
var discountedProducts = ["ORANGE", "APPLE", "BANANA", "GRAPES", "MELON"];

var startDate = util.scand("dd-mm-yyyy", startDateString);
var endDate = util.scand("dd-mm-yyyy", endDateString);
var now = new Date();
event.value = "";

var qty = Number(this.getField("QTY."+rowNumber).valueAsString);
var product = this.getField("Products."+rowNumber).valueAsString;
if (discountedProducts.indexOf(product)!=-1) {
if (now.getTime()<startDate.getTime() || now.getTime()>endDate.getTime())
event.value = "N/A";
else if (qty>10)
event.value = Math.floor(qty/10) + " Free Ctns";
}
}

 

  • each product should have its own promo start and end date.
  • Number of free product for a set number bought to vary as well

e.g., orange promo date start 13-03-2023 & end 28-03-2023. for every 25 oranges, the customer gets 1 free. 

Same thing goes for the other fruits; different dates, different numbers to buy for a free product.

 

Thanks

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
March 13, 2023

You need to modify more than just the script.

The first thing that needs to be done is to work out the field/data structure that organizes the discount data, i.e., item name, dates, quantities, and amounts.  Once this is done then the script can be modified to fit this structure.

 

For example, if this is being done purely with fields, then  I would suggest the stratigic use of grouped field names. For example, "product1.name", "product1.startDate", etc.    

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often