I have 5 fields. Qty, Retail, discount, total discount and total. I want to display the total discount in 1 column and then the total with discount in the total column
Qty | Retail | Discount % | T Discount | Total |
---|---|---|---|---|
1 | 100 | .10 | $10 | $90 |
// Calculate discount function
function calculateDiscount() {
var qty = this.getField("QtyRow1").value;
var retailPrice = this.getField("RetailRow1").value;
var discountPercent = this.getField("DiscRow1").value;
// Convert retailPrice to a number if it's a string
retailPrice = parseFloat(retailPrice);
// Check if qty and retailPrice are valid numbers
if (!isNaN(qty) && !isNaN(retailPrice)) {
// Calculate the total price
var totalPrice = qty * retailPrice;
// Assume the discount percentage is 20% (0.20), change this value as needed
var discountPercentage = discountPercent;
// Calculate the discount amount
var discountAmount = totalPrice * discountPercentage;
// Display the discount amount in the DiscountRow1 field
this.getField("DiscountRow1").value = discountAmount.toFixed(2); // Fixed to 2 decimal places
} else {
// If qty or retailPrice is not a valid number, display an error message or handle it accordingly
app.alert("Please enter valid numbers for quantity and retail price.");
}
}
// Set up the calculation event trigger
this.getField("QtyRow1").setAction("Calculate", calculateDiscount);
this.getField("RetailRow1").setAction("Calculate", calculateDiscount);