Hi all

First time posting in here. I am trying to create a basic sale form and here is how I am doing it:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>



<body>
<form name="calculator" method="post" action="">

  <p>Price list:
    <input name="pricecost" type="text" class="txtfields" id="costprice4" value="<?php echo $pricecost; ?>" size="10" />
  </p>
  <p>Additinal rooms: <span class="WARNING">
    <input name="additionalrooms" type="text" class="txtfields" id="additionalrooms" value="<?php echo $additionalrooms; ?>" size="10" />
  </span></p>
  <p>Price per room: <span class="WARNING">
    <input name="ppr" type="text" class="txtfields" id="ppr" value="<?php echo $ppr; ?>" size="10" />
  </span></p>
  <p>Discount (15% max): <span class="WARNING">
    <input name="discountz" type="text" class="txtfields" id="discountz" value="<?php echo $discountz; ?>" size="10" />
  </span></p>
  <p>Further 5% discount: 
    <select name="discount" class="txtfields" id="discount3">
      <option value="0" <?php if (!(strcmp(0, $discount))) {echo "selected=\"selected\"";} ?>>No</option>
      <option value="1" <?php if (!(strcmp(1, $discount))) {echo "selected=\"selected\"";} ?>>Yes</option>
    </select>
  </p>
</form>
</body>
</html>

 

And this is the php code I am using

<?php



$discount = strip_tags($_POST['discount']);
$pricecost = $_POST['pricecost'];
$additionalrooms = $_POST['additionalrooms'];
$discountz = $_POST['discountz'];
$ppr = $_POST['ppr'];


// Calculating 15% discount
$percentdiscount = $discountz / 100;
$percentdiscount1 = $pricecost * $percentdiscount;
$totalpriceNEW = $pricecost - $percentdiscount1;

// Calculating additional rooms
$additionalroomsADD = $additionalrooms * $ppr;
$additionalroomsRESULT = $additionalroomsADD + $totalpriceNEW;

// Calculating 5% cash discount
$cashDISCOUNTcalc = $additionalroomsRESULT * 0.05;
$cashDISCOUNTRESULT = $additionalroomsRESULT - $cashDISCOUNTcalc;



if ($send) {

	if($discount == "1")
			{
			 echo $cashDISCOUNTRESULT;
			}

	else {

		echo $additionalroomsRESULT;

	}

}




?>

For the results, I am always getting an additional 10. So if the result should be 300, I am getting 310.

What am I doing wrong?

Thanks

    what numbers are you populating the form to get 310(when you expect 300) ?

      dagon;10991830 wrote:

      what numbers are you populating the form to get 310(when you expect 300) ?

      price list = 100
      additonal rooms = 2
      price per room = 50
      additonal discount = 10
      further 5% discount = Yes

      For that, I should have 171

      I am getting 180.5

        180.5 is the value I got by calculating the price by hand.

        (100 + (2 50) - 10) 95&#37; = 180.5

          bradgrafelman;10991845 wrote:

          180.5 is the value I got by calculating the price by hand.

          (100 + (2 50) - 10) 95% = 180.5

          Hi bradgrafelman

          the 10 is mean to be in percentage.

          price list = 100
          additonal rooms = 2
          price per room = 50
          additonal discount = 10%
          further 5% discount = Yes

          For that, I should have 171

          I am getting 180.5

            In that case, the next question is wether they get a 15&#37; discount or 0.9 * 0.95 = 0,855 => 14,5% discount.

              johanafm;10991851 wrote:

              In that case, the next question is wether they get a 15% discount or 0.9 * 0.95 = 0,855 => 14,5% discount.

              It should basically be whatever the user enters in additonal discount + if they qualify for additional 5% discount

                Yes, but if the user enters 10&#37; discount and they also are qualified for additonal 5% discount, should that be total of 14,5% or 15% discount?

                  johanafm;10991861 wrote:

                  Yes, but if the user enters 10% discount and they also are qualified for additonal 5% discount, should that be total of 14,5% or 15% discount?

                  Hi johanafm

                  it should be 15%

                  thanks

                    Ok so here's the thing:

                    15&#37; = 170
                    14.5% = 171

                    In order to get the proper order of operations you need to be absolutely sure which it is. But basically you want:
                    ( price list + ( additonal rooms price per room ) ) ( (100 - ( additonal discount + further discount ) ) / 100 ) = 170
                    OR
                    ( price list + ( additonal rooms price per room ) ) ( (100 - additonal discount)/100) *( (100 - further discount ) ) / 100 ) = 171

                    So you see: You say it should be 15% but you say the price it should be is 171... these are conflicting targets.

                      Write a Reply...