2 Replies Latest reply on Feb 27, 2016 6:59 AM by Jaxsee

# Script help needed for a difficult pricing structure

I have 2 fields on a pdf, one for quantity and one for subscription fee and depending on the quantity entered, you'd get the appropriate price appear. Should be simple, but my pricing structure is not straightforward and I have no idea how to make this work

Points to note

Quantity field could be entered as any number but,

Pricing is based on groups of 100, regardless of the actual quantity, so if you have 2 or 99, you'd still get charged for a full 100

Pricing structure

Any quantity between 1 - 300 would be £36 per 100

Any quantity from 301 - 700 would be £27 per 100

Any quantity from 701 - 1500 would be £18 per 100

Any quantity over 1501 would be £9 per 100

So if I had a total quanity of 899, it'd be broken down as follows

up to 300 @ £36 per 100 = £108 (3 x 36)

301 - 700 @ £27 per 100 = £108 (4 x 27)

701 - 1500 @ £18 per 100 = £36 (2 x 18)

Total subscription = £252

If it was a basic, the more buy, the cheaper the unit price gets I'd be fine but because its staggered pricing, I'm completely lost and have no idea where to start (please keep in mind I'm a newbie at all this!)

• ###### 1. Re: Script help needed for a difficult pricing structure

I hope I got it right... I tested it with your example and it produced the right answer, so I believe that I did.

Anyway, use this code as the custom calculation script of the total price field:

var quantity = Number(this.getField("quantity").value);
var totalPrice = 0;

if (quantity>=1501) {
totalPrice += Math.ceil((quantity-1500)/100) * 9;
quantity = 1500;
}
if (quantity<=1500 && quantity>=701) {
totalPrice += Math.ceil((quantity-700)/100) * 18;
quantity = 700;
}
if (quantity<=700 && quantity>=301) {
totalPrice += Math.ceil((quantity-300)/100) * 27;
quantity = 300;
}
if (quantity<=300) {
totalPrice += Math.ceil(quantity/100) * 36;
}

event.value = totalPrice;

• ###### 2. Re: Script help needed for a difficult pricing structure

Try67 you are a star - thank you so much, this worked perfectly!