cmgmyr Posted October 28, 2008 Share Posted October 28, 2008 Hey everyone, I'm having a little bit of trouble with a markup and markdown function. Here is the code: function priceMarkUp($price, $comp_data, $dir='up'){ $debug = TRUE; if($comp_data->kiosk->markup_cost1 > 0 && $comp_data->kiosk->markup_cost2 > 0){ //see which markup it is if($price >= $comp_data->kiosk->markup_cost2){ $markup = $comp_data->kiosk->markup_per3; }elseif($price <= $comp_data->kiosk->markup_cost1){ $markup = $comp_data->kiosk->markup_per1; }else{ $markup = $comp_data->kiosk->markup_per2; } if($debug) echo "<br />markup = $markup <br />"; $mod = 10; if($dir == 'up'){ if($markup > 0){ $total = round($price + ($price * ($markup / 100))); if($debug) echo "$total = round($price + ($price * ($markup / 100))) <br />"; }else{ $total = $price; } $mod_total = $total % $mod; if($debug) echo "$mod_total = $total % $mod <br />"; $add = $mod - $mod_total; if($debug) echo "$add = $mod - $mod_total <br />"; if($add == $mod) $add = 0; $total += $add; if($debug) echo "$total += $add <br />"; }else{ if($markup > 0){ $total = round($price - ($price / ($markup / 100))); if($debug) echo "$total = round($price - ($price / ($markup / 100))) <br />"; }else{ $total = $price; } $mod_total = $total % $mod; if($debug) echo "$mod_total = $total % $mod <br />"; $add = $mod_total; if($debug) echo "$add = $mod_total <br />"; if($add == $mod) $add = 0; $total -= $add; if($debug) echo "$total -= $add <br />"; } return $total; }else{ return $price; } } $comp_data is an array with different customer data in it. It has the start price and end price for different markups and the actual markups for those levels. Pretty much what I need help with is the actual formula for doing the markups or down. Let me know if you have any questions or if something doesn't make sense. Thanks in advance, -Chris Quote Link to comment https://forums.phpfreaks.com/topic/130490-solved-markup-and-markdown-functions/ Share on other sites More sharing options...
cmgmyr Posted October 29, 2008 Author Share Posted October 29, 2008 Ok, so after a few hours I finally figured it out. Here is the final code. Hope it helps someone out. function priceMarkUp($price, $comp_data, $dir='up'){ //$debug = TRUE; if($comp_data->kiosk->markup_cost1 > 0 && $comp_data->kiosk->markup_cost2 > 0){ //see which markup it is if($price >= $comp_data->kiosk->markup_cost2){ $markup = $comp_data->kiosk->markup_per3; }elseif($price <= $comp_data->kiosk->markup_cost1){ $markup = $comp_data->kiosk->markup_per1; }else{ $markup = $comp_data->kiosk->markup_per2; } if($debug) echo "<br />markup = $markup <br />"; $mod = 10; if($dir == 'up'){ if($markup > 0){ $total = round((($markup/100) + 1) * $price); if($debug) echo "$total = round((($markup/100) + 1) * $price) <br />"; }else{ $total = $price; } $mod_total = $total % $mod; if($debug) echo "$mod_total = $total % $mod <br />"; $add = $mod - $mod_total; if($debug) echo "$add = $mod - $mod_total <br />"; if($add == $mod) $add = 0; $total += $add; if($debug) echo "$total += $add <br />"; }else{ if($markup > 0){ $total = round($price/(($markup/100) + 1)); if($debug) echo "$total = round($price/(($markup/100) + 1)) <br />"; }else{ $total = $price; } $mod_total = $total % $mod; if($debug) echo "$mod_total = $total % $mod <br />"; $add = $mod_total; if($debug) echo "$add = $mod_total <br />"; if($add == $mod) $add = 0; $total -= $add; if($debug) echo "$total -= $add <br />"; } return $total; }else{ return $price; } } Quote Link to comment https://forums.phpfreaks.com/topic/130490-solved-markup-and-markdown-functions/#findComment-677179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.