Jump to content

[SOLVED] Markup and Markdown functions


cmgmyr

Recommended Posts

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

Link to comment
Share on other sites

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;
	}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.