### How can I calculate the Array of Discounts against Base Price in initial then calculate against the Amount After Discount?
This [screenshot
My PHP script here;
`<tbody>
<div class=”form-group”>
<label class=”col-sm-3″ style=’color: green’><strong>Base Price</strong></label>
<div class=’col-sm-8′>
<input type=’number’ class=’form-control’ id=’basePrice’ name=”basePrice” value=’5985′>
</div>
</div>
<?php
$query = $connect->prepare(“SELECT * FROM
$query->execute();
$query->store_result();
$rows = $query->num_rows;
$rows = $rows + 1;
$arrayDiscountNumber = 0;
for ($y = 1; $y < $rows; $y++) { ?>
<tr id=”row<?php echo $y; ?>” class=”<?php echo $arrayDiscountNumber; ?>”>
<td style=”margin-left:20px;”>
<div class=”form-group”>
<select class=”form-control” name=”discountName[]” id=”discountName<?php echo $y; ?>” onchange=”getDiscountData(<?php echo $y; ?>)”>
<option value=””>~~SELECT~~</option>
<?php
$discountSql = “SELECT * FROM `manage_customers_discount` WHERE status = 1 AND company_id = ‘1’ AND discount_is_deleted = 0 ORDER BY discount_order ASC”;
$discountData = $connect->query($discountSql);
while ($row = $discountData->fetch_array()) {
echo “<option value='” . $row[‘id’] . “‘ id=’changeDiscount” . $row[‘id’] . “‘>” . $row[‘discount_name’] . “</option>”;
} // /while
?>
</select>
</div>
</td>
<td style=”padding-left:20px;”>
<input type=”text” name=”rateDiscount[]” id=”rateDiscount<?php echo $y; ?>” autocomplete=”off” disabled=”true” class=”form-control” />
<input type=”hidden” name=”rateDiscountValue[]” id=”rateDiscountValue<?php echo $y; ?>” autocomplete=”off” class=”form-control” />
</td>
<td style=”padding-left:20px;”>
<input type=”text” name=”totalDiscount[]” id=”totalDiscount<?php echo $y; ?>” autocomplete=”off” class=”form-control” disabled=”true” />
<input type=”hidden” name=”totalDiscountValue[]” id=”totalDiscountValue<?php echo $y; ?>” autocomplete=”off” class=”form-control” />
</td>
<td style=”padding-left:20px;”>
<input type=”text” name=”amountAfterDiscount[]” id=”amountAfterDiscount<?php echo $y; ?>” autocomplete=”off” class=”form-control” disabled=”true” />
<input type=”hidden” name=”amountAfterDiscountValue[]” id=”amountAfterDiscountValue<?php echo $y; ?>” autocomplete=”off” class=”form-control” />
</td>
<td>
<button class=”btn btn-default removeDiscountRowBtn” type=”button” id=”removeDiscountRowBtn” onclick=”removeDiscountRow(<?php echo $y; ?>)”><i class=”glyphicon glyphicon-trash”></i></button>
</td>
</tr>
<?php
$arrayDiscountNumber++;
} // /for
?>
</tbody>`
As you can see in the screenshot, I have calculated the base price which has given me the first Amount after Discount Base Price * 15%. In the second discount, I need to calculate the First Amount After Discount * 10%. Same with the 3rd discount. The last Amount after Discount will display in the Sub Discount Amount.
Below is my JS,
`var subTotalValue = $(‘#basePrice’).val();
$(“#rateDiscount” + row).val(response.percentage);
$(“#rateDiscountValue” + row).val(response.percentage);
var total = Number(response.percentage) * Number(subTotalValue);
total = total.toFixed(2);
$(“#totalDiscount” + row).val(total);
$(“#totalDiscountValue” + row).val(total);
var total = Number(subTotalValue) – Number(total);
total = total.toFixed(2);
$(“#amountAfterDiscount” + row).val(total);
$(“#amountAfterDiscountValue” + row).val(total);`
PROBLEM: It is calculating all the percentage against the Base Price