• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script for calculating Quantity Discounts based on quantity of products

Explorer ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

I have created an order form for our products and got through most of the calculations but I am not quite smart enough to get my last one.

 

The way my form is setup I have products priced each and multiplied by quantity per line.

I need a discount script based on the Quantity so our prices are full price 1-20, $5 off each 21-50, $10 off each 51-100, $15 off each 100+ 

 

Is there a simple solution to make this happen?

 

Thanks in advance for any help you can offer.

TOPICS
JavaScript , PDF forms

Views

868

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Aug 28, 2022 Aug 28, 2022

Got it now this is the code that worked for my purpose Quantity only discounts.

 

var qty = Number(this.getField("Quantity").valueAsString);
var total = 0;
if(qty>100)
total = qty*(-15);
else if(qty>50)
total = qty*(-10);
else if(qty>20)
total = qty*(-5);
event.value = total;

 

Thanks for the help!

Votes

Translate

Translate
Explorer ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

I am also using multiple quantities boxes and need them to all work together with the quantity discounts.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

Some of all quantities then $5 off per tier level any one out there any help?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

You can use something like this to achieve it:

 

var qty = Number(this.getField("Qty1").valueAsString);
var price = Number(this.getField("Price1").valueAsString);
var total = qty*price;
var discount = 0;
while (qty>100) {discount+=15; qty--};
while (qty>50) {discount+=10; qty--};
while (qty>20) {discount+=5; qty--};
event.value = total-discount;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

This is working with my form only thing that needs to change is I need it to give off  $100 at 21+ then the $5 so the previous items get the discount they added as well.  Thanks for the help!

 

var qty = Number(this.getField("Quantity").valueAsString);
var price = Number(this.getField("Line Total").valueAsString);
var total = 0;
var discount = 0;
while (qty>100) {discount+=15; qty--};
while (qty>50) {discount+=10; qty--};
while (qty>20) {discount+=5; qty--};
event.value = total-discount;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

How do you discount the previous qauantity with the newest discounted price based on the volume? so at 21 it should give them $105 off then an Addtional $5 per product added until 51 where all the previous added should get this new discount of $10 off or $510 off then $10 for each there after until 100...?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

any help out there please!?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2022 Aug 27, 2022

Copy link to clipboard

Copied

From your description, I understood that you want to discount all quantity depending on quantity number?

I personally wouldn't do it like that, but if that's what you want, try this:

var qty = Number(this.getField("Qty1").valueAsString);
var price = Number(this.getField("Price1").valueAsString);
var total = qty*price;
if(qty>20)
total = qty*(price-5);
else if(qty>50)
total = qty*(price-10);
else if(qty>100)
total = qty*(price-15);
event.value = total;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 28, 2022 Aug 28, 2022

Copy link to clipboard

Copied

Still not quite what I am looking for so I have multiple products in a drop menu and they are all various prices they calculate with the quantity to get the line total so when you use the QTY*Total this does not work to get the correct discount I want the discount only based on the quantity and when there is 20 I want them all regular price once they hit 21 I want a $5 discount for all 21+ Same With 51 I want all 51+ to have a $10 discount..? etc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 28, 2022 Aug 28, 2022

Copy link to clipboard

Copied

Got it now this is the code that worked for my purpose Quantity only discounts.

 

var qty = Number(this.getField("Quantity").valueAsString);
var total = 0;
if(qty>100)
total = qty*(-15);
else if(qty>50)
total = qty*(-10);
else if(qty>20)
total = qty*(-5);
event.value = total;

 

Thanks for the help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 28, 2022 Aug 28, 2022

Copy link to clipboard

Copied

Like Nesa said, you shouldn't be using discount on all quantity.

If clients order 20 items they will pay full price but if they order 21 they will get $105 discount? That doesn't make much sense.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 28, 2022 Aug 28, 2022

Copy link to clipboard

Copied

LATEST

For what we are selling it does. How our price sheets are layed out we offer bulk discounts on volume. I understand you thought process but this is our model. We would like to only sell 20+ but we do not want to leave out the smaller customers so that is an incentitive to buy 21+.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines