double discount in percent

65 views Asked by At

I have a script for calculating discounts in percent, then I want to add a second discount, what is the script formula?

<td>Rp<?= number_format((($r->jual * $r->jumlah) - ($r->jual*$r->jumlah*$r->diskon/100)) ?? 0);?>,-</td>

This works for the first discount, how to calculate the second discount

1

There are 1 answers

7
Chirag Ashara On

You can do something like this

Example

    function finalDiscount($_originalPrice_of_one_quantity,$quantity,$_firstDiscountPercentage,$_secondDiscountPercentage){

        $_originalPrice = $_originalPrice_of_one_quantity*$quantity;

        // Calculate the final discounted price
        $_finalDiscountedPrice = $_originalPrice * (1 - ($_firstDiscountPercentage / 100)) * (1 - ($_secondDiscountPercentage / 100));

       
        return $_finalDiscountedPrice;


}

finalDiscount(3500,2,10,10); 

//parameter 1 : price of product of 1 quantity
//parameter 2 : quantity of product
//parameter 3 : first discount percentage
//parameter 4 : second discount percentage

Notes : Put above function in your code and just call this function in td by passing argument as above said.