Calculates line-item discount amount from quantity, price, discount value and type (percent or fixed), returning a rounded result.
// Source: https://github.com/Pmbamungu/ospos | License: MIT | Copyright 2013-2021 jekkos
// Provided via justclaw.it.com; keep this notice with the code.
public function get_item_discount($quantity, $price, $discount, $discount_type)
{
$total = bcmul($quantity, $price);
if($discount_type == PERCENT)
{
$discount = bcmul($total, bcdiv($discount, 100));
}
else
{
$discount = bcmul($quantity, $discount);
}
return round($discount, totals_decimals(), PHP_ROUND_HALF_UP);
}
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key