Jump to content

Same informaton, used by different POST results?


phpstuck

Recommended Posts

I am building an invoice of sorts, when the form is filled out there will be one to 10 mechanical repairs to the same automobile on the same invoice... Each job will have labor performed to complete the repairs... There are several types of labor ops including one on a sliding scale based on the number of hours a repair takes... If I have 10 jobs on one invoice can I refer to the same formula under different post returns IE:

 

$labor1 = $_POST['labor1'];

$labor2 = $_POST['labor2']; etc...

 

Then draw out of the same formulary without having to post the whole information section and rename for each post in the else if statement?

 

Here is the php estimate handler set up for one POSTlabor, how would I handle the other 9 labor posts and get the correct amount calculated? I have looked at this every way but I keep coming up with having to change all the labor1's to labor 2', labor3's etc and do this while thing over and over 10 times... Is there a better way?

 

<?
$laborrate = 79.36;
$fleetrate = 70.00;
$diag = $_POST["diagtime"];
$ronum1 =$_POST["ronum"];
$plname =$_POST["custlname"];
$pfname =$_POST["custfname"];
$advisor =$_POST["advisor"];


$laborhours1 =$_POST["laborhours"];

$item1 = $_POST["item1"];

$part1a = $_POST["part1a"];
$desc1a = $_POST["desc1a"];
$amnt1a = $_POST["amnt1a"];

$part1b = $_POST["part1b"];
$desc1b = $_POST["desc1b"];
$amnt1b = $_POST["amnt1b"];

$part1c = $_POST["part1c"];
$desc1c = $_POST["desc1c"];
$amnt1c = $_POST["amnt1c"];

$part1d = $_POST["part1d"];
$desc1d = $_POST["desc1d"];
$amnt1d = $_POST["amnt1d"];

$part1e = $_POST["part1e"];
$desc1e = $_POST["desc1e"];
$amnt1e = $_POST["amnt1e"];

$part1f = $_POST["part1f"];
$desc1f = $_POST["desc1f"];
$amnt1f = $_POST["amnt1f"];

$overamnt1 = $_POST["overamnt1"];

//$laborcost1 = (($laborhours1)*(79.36));
$diagposted = (($diag)*(79.95));

$onepointone = (($laborrate+.1*10)*(1+.1));
$onepointtwo =(($laborrate+.2*10)*(1+.2));
$onepointthree =(($laborrate+.3*10)*(1+.3));
$onepointfour =(($laborrate+.4*10)*(1+.4));
$onepointfive =(($laborrate+.5*10)*(1+.5));
$onepointsix =(($laborrate+.6*10)*(1+.6));
$onepointseven =(($laborrate+.7*10)*(1+.7));
$onepointeight =(($laborrate+.8*10)*(1+.);
$onepointnine =(($laborrate+.9*10)*(1+.9));

$twohours=(($laborrate+10)*(2));
$twopointone=(($laborrate+.1*110)*(2.1));
$twopointtwo=(($laborrate+12)*(2.2));
$twopointthree=(($laborrate+13)*(2.3));
$twopointfour=(($laborrate+14)*(2.4));
$twopointfive=(($laborrate+15)*(2.5));
$twopointsix=(($laborrate+14.5)*(2.6));
$twopointseven=(($laborrate+14)*(2.7));
$twopointeight=(($laborrate+13.5)*(2.);
$twopointnine=(($laborrate+13)*(2.9));

$threehours=(($laborrate+12.5)*(3));
$threepointone=(($laborrate+12)*(3.1));
$threepointtwo=(($laborrate+11.5)*(3.2));
$threepointthree=(($laborrate+11)*(3.3));
$threepointfour=(($laborrate+10.5)*(3.4));
$threepointfive=(($laborrate+10)*(3.5));
$threepointsix=(($laborrate+9.5)*(3.6));
$threepointseven=(($laborrate+9)*(3.7));
$threepointeight=(($laborrate+8.5)*(3.);
$threepointnine=(($laborrate+*(3.9));

$fourhours=(($laborrate+7.5)*(4));
$fourpointone=(($laborrate+7)*(4.1));
$fourpointtwo=(($laborrate+6.5)*(4.2));
$fourpointthree=(($laborrate+6)*(4.3));
$fourpointfour=(($laborrate+5.5)*(4.4));
$fourpointfive=(($laborrate+5)*(4.5));
$fourpointsix=(($laborrate+4.5)*(4.6));
$fourpointseven=(($laborrate+4)*(4.7));
$fourpointeight=(($laborrate+3.5)*(4.);
$fourpointnine=(($laborrate+2.5)*(4.9));
$fivehours=(($laborrate+2)*(5));
$fivepointone=(($laborrate+1.5)*(5.1));
$fivepointtwo=(($laborrate+1)*(5.2));
$fivepointthree=(($laborrate+.5)*(5.3));
$fivepointfour=(($laborrate+.5)*(5.4));

$radiolabor= $_POST['paymnttype'];

if ($radiolabor == 'Extwarr1') {
$laborcost1 = (($laborhours1)*($laborrate));
$labordesc = "Extended Warranty";
}
else if ($radiolabor == 'Fleet1') {
$laborcost1 = (($laborhours1)*($fleetrate));
$labordesc = "Fleet";
}
else if ($radiolabor == 'Ovrde1') {
$laborcost1 = (($laborhours1)*($overamnt1));
$labordesc = "Special";
}

else if ($radiolabor == 'cash1') {

if (($laborhours1 < 1.1)){

$laborcost1 = (($laborhours1)*(79.36)); 
  
}else if (($laborhours1 == 1.1)){
$laborcost1 = ($onepointone);

}else if (($laborhours1 == 1.2)){
$laborcost1 = ($onepointtwo);

}else if (($laborhours1 == 1.3)){
$laborcost1 = ($onepointthree);

}else if (($laborhours1 == 1.4)){
$laborcost1 = ($onepointfour);

}else if (($laborhours1 == 1.5)){
$laborcost1 = ($onepointfive);

}else if (($laborhours1 == 1.6)){
$laborcost1 = ($onepointsix);

}else if (($laborhours1 == 1.7)){
$laborcost1 = ($onepointseven);

}else if (($laborhours1 == 1.){
$laborcost1 = ($onepointeight);

}else if (($laborhours1 == 1.9)){
$laborcost1 = ($onepointnine);

}else if (($laborhours1 == 2)){
$laborcost1 = ($twohours);

}else if (($laborhours1 == 2.1)){
$laborcost1 = ($twopointone);

}else if (($laborhours1 == 2.2)){
$laborcost1 = ($twopointtwo);

}else if (($laborhours1 == 2.3)){
$laborcost1 = ($twopointthree);

}else if (($laborhours1 == 2.4)){
$laborcost1 = ($twopointfour);

}else if (($laborhours1 == 2.5)){
$laborcost1 = ($twopointfive);

}else if (($laborhours1 == 2.6)){
$laborcost1 = ($twopointsix);

}else if (($laborhours1 == 2.7)){
$laborcost1 = ($twopointseven);

}else if (($laborhours1 == 2.){
$laborcost1 = ($twopointeight);

}else if (($laborhours1 == 2.9)){
$laborcost1 = ($twopointnine);

}else if (($laborhours1 == 3)){
$laborcost1 = ($threehours);

}else if (($laborhours1 == 3.1)){
$laborcost1 = ($threepointone);

}else if (($laborhours1 == 3.2)){
$laborcost1 = ($threepointtwo);

}else if (($laborhours1 == 3.3)){
$laborcost1 = ($threepointthree);

}else if (($laborhours1 == 3.4)){
$laborcost1 = ($threepointfour);

}else if (($laborhours1 == 3.5)){
$laborcost1 = ($threepointfive);

}else if (($laborhours1 == 3.6)){
$laborcost1 = ($threepointsix);

}else if (($laborhours1 == 3.7)){
$laborcost1 = ($threepointseven);

}else if (($laborhours1 == 3.){
$laborcost1 = ($threepointeight);

}else if (($laborhours1 == 3.9)){
$laborcost1 = ($threepointnine);

}else if (($laborhours1 == 4)){
$laborcost1 = ($fourhours);

}else if (($laborhours1 == 4.1)){
$laborcost1 = ($fourpointone);

}else if (($laborhours1 == 4.2)){
$laborcost1 = ($fourpointtwo);

}else if (($laborhours1 == 4.3)){
$laborcost1 = ($fourpointthree);

}else if (($laborhours1 == 4.4)){
$laborcost1 = ($fourpointfour);

}else if (($laborhours1 == 4.5)){
$laborcost1 = ($fourpointfive);

}else if (($laborhours1 == 4.6)){
$laborcost1 = ($fourpointsix);

}else if (($laborhours1 == 4.7)){
$laborcost1 = ($fourpointseven);

}else if (($laborhours1 == 4.){
$laborcost1 = ($fourpointeight);

}else if (($laborhours1 == 4.9)){
$laborcost1 = ($fourpointnine);

}else if (($laborhours1 == 5)){
$laborcost1 = ($fivehours);

}else if (($laborhours1 == 5.1)){
$laborcost1 = ($fivepointone);

}else if (($laborhours1 == 5.2)){
$laborcost1 = ($fivepointtwo);

}else if (($laborhours1 == 5.3)){
$laborcost1 = ($fivepointthree);

}else if (($laborhours1 == 5.4)){
$laborcost1 = ($fivepointfour);

}else if (($laborhours1 > 5.4)){
$laborcost1 = (($laborhours1)*(79.36));



}
$labordesc = "Cash payment";
}Else{
echo "<BR><BR><B><font size = +3 color = red>WARNING! No labor added, labor type not set-up!</font></B>";
}

$partsttla = ($amnt1a+$amnt1b+$amnt1c+$amnt1d+$amnt1e+$amnt1f);

$shopttl = (($laborcost1)*(.10));
//$shopdefault = 15.00;

//ECHO '<br>'."Labor cost $".number_format($laborcost1,2);
ECHO '<hr>';
ECHO '<i><font face = arial>'."Estimate prepared by: &nbsp ".$advisor.'</i>';
ECHO '<u><br>'.date("l F d, Y").'</u>';
ECHO '<br><font face = arial>'."Repair order number: ".$ronum1;
ECHO '<br><B>'.$plname.", ".$pfname.'</b><BR>';
ECHO '<br><b>'.$diag .'</b> &nbsp '."Vehicle Diagnosis $".number_format($diagposted,2)."<BR>";

if ($item1 != NULL){


ECHO '<BR><B>'.$item1.'</B><font face = arial size = -3> Parts total for this repair  $'.number_format($partsttla,2).'</font>' ;

}ELSE{

ECHO "<B><font face = tahoma color = red>No description entered for estimate!</font></B>";


}

if ($desc1a != null){
ECHO '<BR>&nbsp &nbsp &nbsp '.$desc1a." - $".number_format($amnt1a,2);
}
if ($desc1b != null){
ECHO '<BR>&nbsp &nbsp &nbsp '.$desc1b." - $".number_format($amnt1b,2);
}
if ($desc1c != null){
ECHO '<BR>&nbsp &nbsp &nbsp '.$desc1c." - $".number_format($amnt1c,2);
}
if ($desc1d != null){
ECHO '<BR>&nbsp &nbsp &nbsp '.$desc1d." - $".number_format($amnt1d,2);
}
if ($desc1e != null){
ECHO '<BR>&nbsp &nbsp &nbsp '.$desc1e." - $".number_format($amnt1e,2);
}
if ($desc1f != null){
ECHO '<BR>&nbsp &nbsp &nbsp '.$desc1f." - $".number_format($amnt1f,2);
}

//}


//ECHO '<br>'."Parts Amount $".number_format($amnt1a,2);
ECHO '<br><br><b>'.$laborhours1.'</b> &nbsp '.$labordesc.' '."Labor $".number_format($laborcost1,2);
ECHO '<hr>';

if (($shopttl > 14.99)){

$shopcharge = "15.00";

ECHO "Shop / misc charges - $".$shopcharge;
  
}else if (($shopttl < 15.00)){

$shopcharge = (($laborcost1)*(.10));

ECHO "Shop / misc charges - $".number_format($shopcharge,2);
}
$tax1 = (($partsttla+$diagposted+$laborcost1+$shopcharge)*(.06));
$ttl = (($partsttla+$diagposted+$laborcost1+$shopcharge)+($tax1));
ECHO '<br>'."Sales Tax $".number_format($tax1,2);
ECHO '<br><B>'."Total $".number_format($ttl,2);








?>

When you build the form, whether by hand or script use the return as an array

$laborhours =$_POST["laborhours"];

repair #1

<input type="text"name="laborhours[]" value="">

 

repair #2

<input type="text"name="laborhours[]" value="">

 

you can use this multiple times.

To access the return treat $laborhours as an array

$labothours1=$laborhours['0'];

$laborhours2=$laborhours['1'];

etc.

 

You can even tell how many repairs were submitted: $num_repairs=count($laborhours);

 

 

HTH

Teamatomic

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.