Jump to content

PHP Calculation scripting question


medprogress

Recommended Posts

Hi,

 

We have a script that does simple mathematical calculations (addition) which we use to provide our clients with an instant quote for my services.  I am trying to expand that script to do an additional task -- (A+B+C) x D . Our current script only does (A+B+C).  I can't get it to work, here is how it looks:

 

Link to the page: http://medprogress.net/mail/mail_customize.php  (note: website is still under heavy constructions)

 

The form aspect in question is where customers input "Number of Mail pieces" and I would like that to be the "D" in my (A+B+C) x D equation. 

 

PHP calculations script:

 

// TURN ON ERROR PRINTING IF NEEDED

 

ini_set ('display_errors', 1);

error_reporting (E_ALL);

 

// SET VARIABLES FOR QUOTE NUMBER GENERATION

 

$time = time();

$qn = rand(1, 99);

$quote_num = $time . ' ' . $qn;

 

// CALCULATE PACKAGE PRICE AND SELECTION

 

If ( !empty($package) ) {

  switch ($package)  {

    case "Internal":

      $package_price = 0;

      break;

    case "External":

      $package_price = 0;

      break;

  }

} Else {

  $package      = "";

  $package_price = 0;

}

 

// CALCULATE ADD-ONS

 

If ( !empty($addon1) ) {

  $addon1_price = 0.14;

} Else {

  $addon1_price = 0;

  $addon1 = "";

}

If ( !empty($addon2) ) {

  $addon2_price = 0.10;

} Else {

  $addon2_price = 0;

  $addon2 = ""; 

}

If ( !empty($addon3) ) {

  $addon3_price = 0.13;

} Else {

  $addon3_price = 0;

  $addon3 = "";

}

If ( !empty($addon4) ) {

  $addon4_price = .30;

} Else {

  $addon4_price = 0;

  $addon4 = ""; 

}

 

// CALCULATE MAINTENANCE COSTS

 

If ( !empty($maintenance) ) {

  switch ($maintenance)  {

    case "Postcard":

      $maintenance_price = 1.00;

      break;

    case "Newsletter":

      $maintenance_price = 1.10;

      break;

  }

} Else {

  $maintenance      = "";

  $maintenance_price = 0;

}

 

$amount = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price * 10000; (This is were i'm stuck)

 

$total = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price;

 

If ($total > 0) {

  $select = "yes";

} Else {

  $select = "no";

}

 

$downpayment = $total / 2;

$total      = number_format ($total, 2);

$downpayment = number_format ($downpayment, 2);

 

$eitems = "";

$items = "";

 

 

 

Link to comment
Share on other sites

try adding a () ex.

 

$amount =( $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price )* 10000;

so after adding all the numbers it will them multiply to a given number

all the operation inside the () will be the first to be executed 

 

 

Link to comment
Share on other sites

Thanks for the reply

 

Ive added () and it does not affect the result. 

 

Just to expand on my question -- I want the number that is put into form field "Number of Mail Pieces" to be multiplied by [  ( $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price )  ].  Hope that clarifies it a bit more. 

Link to comment
Share on other sites

$amount =( $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price )* 10000;

i still dont fully understand im basing my answer on that code

 

heres what your code does.

add all this $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price  then multiply by 1000....

 

is that right?

Link to comment
Share on other sites

<a href="http://w3schools.com/php/php_post.asp">read this is what you need to know </a>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body>
<form action=" " method="post">
Enter price: <input type="text" name="price" />
<input type="submit" />
</form>

  </body>
</html>
<?php
if(isset($_POST['price'])){
  if(is_numeric(_POST['price'])){
  // TURN ON ERROR PRINTING IF NEEDED

ini_set ('display_errors', 1);
error_reporting (E_ALL);

// SET VARIABLES FOR QUOTE NUMBER GENERATION

$time = time();
$qn = rand(1, 99);
$quote_num = $time . ' ' . $qn;

// CALCULATE PACKAGE PRICE AND SELECTION

If ( !empty($package) ) {
  switch ($package)   {
    case "Internal":
      $package_price = 0;
      break;
    case "External":
      $package_price = 0;
      break;
  }
} Else {
  $package       = "";
  $package_price = 0;
}

// CALCULATE ADD-ONS

If ( !empty($addon1) ) {
  $addon1_price = 0.14;
} Else {
  $addon1_price = 0;
  $addon1 = "";
}
If ( !empty($addon2) ) {
  $addon2_price = 0.10;
} Else {
  $addon2_price = 0;
  $addon2 = ""; 
}
If ( !empty($addon3) ) {
  $addon3_price = 0.13;
} Else {
  $addon3_price = 0;
  $addon3 = "";
}
If ( !empty($addon4) ) {
  $addon4_price = .30;
} Else {
  $addon4_price = 0;
  $addon4 = ""; 
}

// CALCULATE MAINTENANCE COSTS

If ( !empty($maintenance) ) {
  switch ($maintenance)   {
    case "Postcard":
      $maintenance_price = 1.00;
      break;
    case "Newsletter":
      $maintenance_price = 1.10;
      break;
  }
} Else {
  $maintenance       = "";
  $maintenance_price = 0;
}

$amount = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price * 10000; (This is were i'm stuck)

$total = $package_price + $maintenance_price + $addon1_price + $addon2_price + $addon3_price + $addon4_price;

If ($total > 0) {
  $select = "yes";
} Else {
  $select = "no";
}

$downpayment = $total / 2;
$total       = number_format ($total, 2);
$downpayment = number_format ($downpayment, 2);

$eitems = "";
$items = "";
  
  }else{
    echo 'invalid input';
  }

}

?>

note not tested i dont have php in my machine now i just type that in note pad

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.