These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Discount Calculation script based on qty ordered

karfarzel
Registered: Aug 13 2008
Posts: 10
Answered

Calculation script enquiry for an order form made in Acrobat 8

I Would like to know what the calculation script would be for an order form I'm starting to generate.
I can do simple addition calculations but this is little out of my scope.

I currently have a cell called Bottle_Total on the form which totals the qty of bottles ordered, when the (Bottle_Total) = 6 or more I would like to have a 10% discount applied to the final price, which is a called (Total) (this box is the sum price of several items ordered).

I really don't know how to achieve this, any help would be greatly appreciated.

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Are you saying you want to apply a 10% discount to the total order, or only to the cost of the bottles? If the latter, what are the field names that contain the total cost of the other items? The more information you provide the better.

George
karfarzel
Registered: Aug 13 2008
Posts: 10
George, This should make things a little clearer,

qty_01xprice_01=tot_01
qty_02xprice_02=tot_02
qty_03xprice_03=tot_03
qty_04xprice_04=tot_04
qty_05xprice_05=tot_05

tot_01+tot_02+tot_03+tot_04+tot_05=total (total price of all items)

I have a field called "tot_bots":

qty_01+qty_02+qty_03+qty_04+qty_05=tot_bots
tot_bots (shows the total number of bottles ordered)

if "tot_bots" has 6 or more a 10% discount is applied to a field called "total"

I would have a note on the form that say's a 10% discount applies
to the total price on orders of 6 or more bottles.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
There are 2 programs witnin Acrobat Professional that can create forms and their scripting languages are different. There is Acrobat that uses AcroForms and Acrobat JavaScript, and then there is LiveCycle Designer, formeryly JetForms, that uses FormCalc or another variation of JavaScript.

Assuming you are using LiveCycle Designer:

// FormCalc calculation script for total price of all items
// compute the total price
$.rawValue = (qty_01 * price_01) + (qty_02 *price_02) + (qty_03 * price_03) + a(qty_04 * price_04) + (qty_05 * price_05)

// FormCalc calculation script for total bottles
// compute the total bottles
$.rawValue = Sum(qty_01, qty_02, qty_03, qty_04, qty_05)

var disc = 1
if ($.rawValue gt 5) then

disc = 1 - 0.10
endif
$.rawValue = $.rawValue * disc

You might want to view the eSemminar on demand on the AUC home page and the "Scripting Reference" under LiveCycle Designer's menu "Help" option.

George Kaiser

karfarzel
Registered: Aug 13 2008
Posts: 10
Thankyou for the reply Gkaiseril,

I am currently using the form tools in Acrobat Pro version 8,
I have not tried Livecycle for making up pdf forms, maybe it's a good time for me to start.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
I would not necessarily change. You form and calculations are easy enough just different code.


// custom calculation script for total price and total bottles
// compute the total price
var sum = 0; // set sum to zero
var sumBottels = 0; // set sum to zero

// loop through the fields
for(i = 1, i < 6; i++) {
sum = Number(sum) + (this.getField("qty_0" + i).value * this.getField("price_0") + i).value);
sumBottels = Number(sumBottels) + this.getField("qty_0" + i).value;
}
// set the value for the total price
event.value = sum;

// set the value for the total bottles
this.getField("tot_bots").value = sumBottles;

// compute the discount
var disc = 0;
if (this.getField("total_bots").value > 5) {
disc = 0.10;
}
// assign the dismount value to the discount field
this.getField("BottleDiscount").value = disc;

// compute the discounted total
this.getField("DiscountTotal").value = sum - (disc * sum);

There is also a eSeminar on demand video for Acrobat Forms and [url=http://www.adobe.com/devnet/acrobat/javascript.php]JavaScript for Acrobat[/url] documentation.

George Kaiser

karfarzel
Registered: Aug 13 2008
Posts: 10
gkaiseril , I have tried the code, but the line "sum = Number(sum) + (this.getField("qty_0" + i).value * this.getField("price_0") + i).value);" is highlighted with an error:
missing ; after for-loop condition
7: at line 8

I have no idea when it comes to code bits like this. Thankyou for your help so far.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
That will teach me to post code without testing. The "for" statement uses ";' between elements. And then there was an issue with converting a string to a number.

// custom calculation script for total price and total bottles
// compute the total price
var sum = 0; // set sum to zero
var sumBottles = 0; // set sum to zero

// loop through the fields
for(i = 1; i < 6; i++) {
sum = Number(sum) + (this.getField("qty_0" + i).value * this.getField("price_0" + i).value);
sumBottles = Number(this.getField("qty_0" + i).value) + sumBottles;
} // end for all fields loop

// set the value for the total price
event.value = sum;

// set the value for the total bottles
this.getField("total_bots").value = sumBottles;

// compute the discount
var disc = 0;
if (this.getField("total_bots").value > 5) {
disc = 0.10;
}
// assign the dismount value to the discount field
this.getField("BottleDiscount").value = disc * sum;

// compute the discounted total
this.getField("DiscountTotal").value = sum - (disc * sum);

George Kaiser