<?php

include "../inc/sqlinf.php";
include "../inc/auth.php";
include "apple.inc";

$result = mysql_query("SELECT SUM(IG) AS totalearnings FROM CLIENTS");
while($row = mysql_fetch_assoc($result))
{$totalearnings = $row['totalearnings'];}

$sql = "SELECT count(*) FROM CLIENTS";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);

?>

<html>
<head>
<title>Earning Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="5" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF">
  <tr>
        <td>
          <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#FFFFFF" bordercolor="#FFFFFF">
                <tr bgcolor="#000066"> 
                  <td width="100%" colspan="2"> <font color="#FFFFFF">&raquo;</font><b><font color="#FFFFFF"> 
                        Total Company Earnings </font></b></td>
                </tr>
                <tr> 
                  <td bgcolor="#EEEEEE" width="10%"> <br>
                  </td>
                  <td bgcolor="#F9F9F9" width="90%"> <br>
                        <table cellspacing="1" cellpadding="2" border="2" bordercolor="#FFFFFF" bgcolor="#CCCCCC" width="100%">
                          <tr bgcolor="#FFFFFF"> 
                                <td bgcolor="#FCFCFC"> Total Company Earnings </td>
                                <td width="10%" bgcolor="#F9F9F9"> 
                                  <div align="center">$ 
                                        <?php echo $totalearnings; ?>
                                  </div>
                                </td>
                          </tr>
                        </table>
                    <br>
                  </td>
                </tr>
                <tr bgcolor="#000066"> 
                  <td width="100%" colspan="2"> <font color="#FFFFFF">&raquo;<b> Package 
                        Earnings</b></font></td>
                </tr>
                <tr> 
                  <td bgcolor="#EEEEEE" width="10%">&nbsp; </td>
                  <td bgcolor="#F9F9F9" width="90%"> <br>
                        <table cellspacing="1" cellpadding="2" border="2" bordercolor="#F9F9F9" bgcolor="#CCCCCC" width="100%">
                          <tr bgcolor="#FFFFFF"> 
                                <td bgcolor="#FCFCFC" width="40%"> Package</td>
                                <td width="10%" bgcolor="#F9F9F9"> 
                                  <div align="center"> Signups</div>
                                </td>
                                <td width="30%" bgcolor="#EEEEEE"> 
                                  <div align="center">Earnings Gross</div>
                                </td>
                          </tr>
                        </table>
                        <?php
$SQL = "SELECT * from HOSTINGPACKAGES";
$result = mysql_query( $SQL );
while( $row = mysql_fetch_array( $result ) ) {
$package = $row["NAME"];

$result1 = mysql_query("SELECT SUM(IG) AS ig FROM CLIENTS WHERE PACKAGE = '$package'");
while($row1 = mysql_fetch_assoc($result1)){
$ig = $row1['ig'];}

$sql = "SELECT count(*) FROM CLIENTS WHERE PACKAGE ='$package'";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);

?>
                        <table cellspacing="1" cellpadding="2" border="2" bordercolor="#F9F9F9" bgcolor="#CCCCCC" width="100%">
                          <tr bgcolor="#FFFFFF"> 
                                <td bgcolor="#FCFCFC" width="40%"> 
                                  <?php echo $package; ?>
                                </td>
                                <td width="10%" bgcolor="#F9F9F9"> 
                                  <div align="center"> 
                                        <?php echo $row[0]; ?>
                                  </div>
                                </td>
                                <td width="30%" bgcolor="#EEEEEE"> 
                                  <div align="center">$ 
                                        <?php echo $ig; ?>
                                  </div>
                                </td>
                          </tr>
                        </table>
                        <?php } ?>
                  </td>
                </tr>
          </table>
        </td>
  </tr>
</table>
</body>
</html>


