Location: PHPKode > projects > Computer Service Company Database > SOLOCMS/dogbert/searchprofit.php
<? // setup connection to mysql
     include("db.php"); ?>
<? include ('header.php'); ?>

<? // form is not submitted grab the info for the choose invoice dropdownbox.  Need to change this to a search feature but it works for now
    if (empty($_POST)) {  
?>
<table width="600" border="0" align="center">
  <tr>
    <td><p align="center" class="invoice"> Choose date range<br>
<form action="searchprofit.php" method="POST">
	 Start date and end date, with end date popup defaulting to same date as start date<br>
<script language="JavaScript" id="js13">
var cal13 = new CalendarPopup();
</script>
Start: <input name="date13" value="" size="25" type="text">
<a href="#" onclick="cal13.select(document.forms[0].date13,'anchor13','yyyy-MM-dd'); return false;" title="cal13.select(document.forms[0].date13,'anchor13','yyyy-MM-dd'); return false;" name="anchor13" id="anchor13">select</a>
&nbsp;&nbsp;&nbsp;</td>
  </tr>
<tr>
    <td>
End: <input name="date14" value="" size="25" type="text">
<a href="#" onclick="cal13.select(document.forms[0].date14,'anchor14','yyyy-MM-dd',(document.forms[0].date14.value=='')?document.forms[0].date13.value:null); return false;" title="cal13.select(document.forms[0].date14,'anchor14','yyyy-MM-dd',(document.forms[0].date14.value=='')?document.forms[0].date13.value:null); return false;" name="anchor14" id="anchor14">select</a>
<input type="submit">
</form>
</p></td>
  </tr></table>


<? } 
else {
?>
<?
$result2 = mysql_query("SELECT clientid, SUM(total) AS client_total
FROM invoice
WHERE date  BETWEEN '$date13' AND '$date14'
GROUP BY clientid");

$sql = "select * from invoice
where date >= '$date13'
and date <= '$date14'";

$result=mysql_query($sql);
$total_bill = 0;
$total_hw = 0;
$total_solocost = 0;
$total_labor = 0;

while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
//    echo $row["date"]."<br>";
//  echo $row["total"]."<br>";
     $total_bill += $row["total"];
	 $total_labor += (($row['rate'] * $row['hours']) +  $row['flatrate']);

//does the subtotal calculations that display on the invoice
$hwsubtotal1 = ($row['qty1'] * $row['unitcost1']);
$hwsubtotal2 = ($row['qty2'] * $row['unitcost2']);
$hwsubtotal3 = ($row['qty3'] * $row['unitcost3']);
$hwsubtotal4 = ($row['qty4'] * $row['unitcost4']);
$hwsubtotal5 = ($row['qty5'] * $row['unitcost5']);
$hwsubtotal6 = ($row['qty6'] * $row['unitcost6']);
//subtotal all the harware types
$hwsub = ($hwsubtotal1 + $hwsubtotal2 + $hwsubtotal3 + $hwsubtotal4 + $hwsubtotal5 + $hwsubtotal6);
//Add the state tax
$hwtax = $hwsub * $HWtaxrate;

$total_hw += $hwtax + $hwsub;
//does the subtotal calculations that display on the invoice
$ssubtotal1 = ($row['qty1'] * $row['solocost1']);
$ssubtotal2 = ($row['qty2'] * $row['solocost2']);
$ssubtotal3 = ($row['qty3'] * $row['solocost3']);
$ssubtotal4 = ($row['qty4'] * $row['solocost4']);
$ssubtotal5 = ($row['qty5'] * $row['solocost5']);
$ssubtotal6 = ($row['qty6'] * $row['solocost6']);

$solosub = ($ssubtotal1 + $ssubtotal2 + $ssubtotal3 + $ssubtotal4 + $ssubtotal5 + $ssubtotal6);
//Add the state tax
$solotax = $solosub * $HWtaxrate;

$total_solocost += $solotax + $solosub;

$hwprofit = $total_hw - $total_solocost;
$soloprofit = $total_bill - $total_solocost;

}
$total_solocost = sprintf("%0.2f",$total_solocost);
$total_hw = sprintf("%0.2f",$total_hw);
$total_bill = sprintf("%0.2f",$total_bill);
$total_labor = sprintf("%0.2f",$total_labor);
$soloprofit = sprintf("%0.2f",$soloprofit);
$hwprofit = sprintf("%0.2f",$hwprofit);
?>

<table width="600" border="0" align="center">
  <tr>
    <td colspan="2"><div align="center">
      <p><b>From: <? print $date13; ?> To: <? print $date14; ?><br>
      </b></p>
    </div></td>
  </tr>
  <tr>
    <td width="188"><span style="font-weight: bold">Total Billed:</span></td>
    <td width="402"><span style="font-weight: bold">$<? print $total_bill; ?></span></td>
    
  </tr>
  <tr>
    <td colspan="2"><hr></td>
  </tr>
  <tr>
    <td>Total Hardware Billed:</td>
    <td>$<? print $total_hw; ?></td>
  </tr>
  <tr>
    <td><span style="color: #FF0000; font-weight: bold">Total Hardware Cost:</span></td>
    <td><span style="color: #FF0000; font-weight: bold">$<? print $total_solocost; ?></span></td>
  </tr>
  <tr>
    <td colspan="2"><hr></td>
  </tr>
  <tr>
    <td>Total Hardware Profit:</td>
    <td>$<? print $hwprofit; ?></td>
  </tr>
  <tr>
    <td>Total Labor Invoiced:</td>
    <td>$<? print $total_labor; ?></td>
  </tr>
  <tr>
    <td colspan="2"><hr></td>
  </tr>
  <tr>
    <td><span style="font-weight: bold">Total SOLO Profit:</span></td>
    <td><span style="font-weight: bold">$<? print $soloprofit; ?></span></td>
  </tr>
</table>
 <hr>
 <table width="600" border="0" align="center">
   <tr>
     <td>Client ID</td>
     <td>Total Invoiced in Date Range</td>
   </tr>
  
   <? while ($row2 = mysql_fetch_array($result2)) 
   { 
   
   $result3 = mysql_query("select * from results
where id = '$row2[clientid]'");
$row3 = mysql_fetch_array($result3);
//print_r ($row3);

print "<tr><td> {$row2[clientid]} {$row3[firstname]} {$row3[lastname]}</td><td>{$row2[client_total]}</td></tr>";
}
  
  ?>
 </table>
  
 <? } ?>
<? include ('navigation.php'); ?>
<? include ('footer.php'); ?>
</body></html>
Return current item: Computer Service Company Database