Location: PHPKode > projects > T-77.com Operational Management System > omis/report_cum.php
<?php require_once('Connections/t77_connect.php'); ?>
<?php

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

mysql_select_db($database_t77_connect, $t77_connect);
$query_Typen = "SELECT * FROM t77_bill_types";
$Typen = mysql_query($query_Typen, $t77_connect) or die(mysql_error());
$row_Typen = mysql_fetch_assoc($Typen);
$totalRows_Typen = mysql_num_rows($Typen);

if(!isset($_GET['typeID'])) {
	$type = "3";
} else {
	$type = $_GET['typeID'];
}
$datax = array("","Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","October","November","December");

mysql_select_db($database_t77_connect, $t77_connect);
$query_settings = "SELECT * FROM t77_bill_settings";
$settings = mysql_query($query_settings, $t77_connect) or die(mysql_error());
$row_settings = mysql_fetch_assoc($settings);
$totalRows_settings = mysql_num_rows($settings);

mysql_select_db($database_t77_connect, $t77_connect);
$query_getyear = "SELECT DISTINCT YEAR(t77_bill_bills.bill_date) as jaar FROM t77_bill_bills";
$getyear = mysql_query($query_getyear, $t77_connect) or die(mysql_error());
$row_getyear = mysql_fetch_assoc($getyear);
$totalRows_getyear = mysql_num_rows($getyear);

$ubertotal = 0;

if(!isset($_GET['year'])) {
	$year = date('Y');
} else {
	$year = $_GET['year'];
}
?>
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />

</head>

<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="lineleft">
  <tr>
    <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="31" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="20"><img src="images/tabletopstart.gif" width="20" height="31" /></td>
                <td><table width="100%" height="30" border="0" cellpadding="5" cellspacing="0">
                    <tr>
                      <td><p><strong>Report</strong></p>
                      </td>
                      <td><table border="0" align="right" cellpadding="0" cellspacing="0">
                          <tr>
                            <td>&nbsp;</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="20">
            <tr>
              <td><form name="type" id="type" method="get" action="<? echo $_SERVER['PHP_SELF']; ?>">
              <select name="typeID" onChange="javascript:document.type.submit(this.form)">
                <?php
					do {  
					?>
                <option value="<?php echo $row_Typen['bill_type']?>"<?php if (!(strcmp($row_Typen['bill_type'], $type))) {echo "SELECTED";} ?>><?php echo $row_Typen['type_description']?></option>
                <?php
					} while ($row_Typen = mysql_fetch_assoc($Typen));
					  $rows = mysql_num_rows($Typen);
					  if($rows > 0) {
						  mysql_data_seek($Typen, 0);
						  $row_Typen = mysql_fetch_assoc($Typen);
					  }
					?>
              </select>
                    <select name="year" onChange="javascript:document.type.submit(this.form)">
                      <?php
do {  
?>
                      <option value="<?php echo $row_getyear['jaar']?>"<?php if (!(strcmp($row_getyear['jaar'], "$year"))) {echo "SELECTED";} ?>><?php echo $row_getyear['jaar']?></option>
                      <?php
} while ($row_getyear = mysql_fetch_assoc($getyear));
  $rows = mysql_num_rows($getyear);
  if($rows > 0) {
      mysql_data_seek($getyear, 0);
	  $row_getyear = mysql_fetch_assoc($getyear);
  }
?>
                    </select>
                  </form>
                  <p>&nbsp;</p>
                  <p><img src="cum_month.php?typeID=<? echo $type; ?>&year=<? echo $year; ?>&time=<? echo microtime(); ?>" alt="Loading the graph..." width="650" height="400" /></p>
                <p>&nbsp;</p><?

$colname_typen = "1";
if (isset($type)) {
  $colname_typen = (get_magic_quotes_gpc()) ? $type : addslashes($type);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_typen = sprintf("SELECT * FROM t77_bill_types WHERE t77_bill_types.bill_type = %s", $colname_typen);
$typen = mysql_query($query_typen, $t77_connect) or die(mysql_error());
$row_typen = mysql_fetch_assoc($typen);
$totalRows_typen = mysql_num_rows($typen);


mysql_select_db($database_t77_connect, $t77_connect);
$query_Companies = "SELECT * FROM t77_bill_companies";
$Companies = mysql_query($query_Companies, $t77_connect) or die(mysql_error());
$row_Companies = mysql_fetch_assoc($Companies);
$totalRows_Companies = mysql_num_rows($Companies);

$datax = array("","Jan","Feb","Mar","Apr","Mei","Jun","Jul","Aug","Sep","Okt","Nov","Dec");

$comi=0;
do {

	$i = 1;
	
	do {

		$datevar = $i;
		$comVar = $row_Companies['company_id'];
		
		$colname3_maanden = "3";
		if (isset($type)) {
		  $colname3_maanden = (get_magic_quotes_gpc()) ? $type : addslashes($type);
		}
		$colname2_maanden = "1";
		if (isset($comVar)) {
		  $colname2_maanden = (get_magic_quotes_gpc()) ? $comVar : addslashes($comVar);
		}
		$colname_maanden = "1";
		if (isset($datevar)) {
		  $colname_maanden = (get_magic_quotes_gpc()) ? $datevar : addslashes($datevar);
		}
		mysql_select_db($database_t77_connect, $t77_connect);
		$query_maanden = sprintf("SELECT * FROM t77_bill_bills, t77_bill_items, t77_bill_companies, t77_bill_contacts WHERE t77_bill_contacts.contact_id = t77_bill_bills.bill_contact AND t77_bill_contacts.contact_company_name = t77_bill_companies.company_id AND t77_bill_bills.bill_id = t77_bill_items.bill_id AND MONTH( t77_bill_bills.bill_date) = %s AND t77_bill_companies.company_id = %s AND t77_bill_bills.bill_type = %s", $colname_maanden,$colname2_maanden,$colname3_maanden);
		$maanden = mysql_query($query_maanden, $t77_connect) or die(mysql_error());
		$row_maanden = mysql_fetch_assoc($maanden);
		$totalRows_maanden = mysql_num_rows($maanden);

		$monthprice[$i] = 0;
		$stotal[0] = 0;
		$total[0] = 0;
		
			do {
			
				$monthprice[$i] = $row_maanden['item_price'];
				$stotal[$i] = $monthprice[$i] + $stotal[$i];
				
			} while ($row_maanden = mysql_fetch_assoc($maanden)); 
			
			$total[$i] = $total[$i-1] + $stotal[$i];
			
			$i++;
	
		} while ($i <= 12);

		$comi++; 
		
	} while ($row_Companies = mysql_fetch_assoc($Companies)); 
	
	$bla = 0;
	do {
		$ubertotal = $ubertotal + $stotal[$bla];
		$bla++;
	} while ($bla <= 12);
	
	?>
                <table width="100%" border="0" cellpadding="5" cellspacing="0" class="tableBorder">
                  <tr>
                    <td class="tableTop"><h1>Month</h1></td>
                    <td align="right" class="tableTop"><h1>Total</h1></td>
                    <td align="right" class="tableTop"><h1>cumulative</h1></td>
                    <td align="right" class="tableTop"><h1>% of total </h1></td>
                    <td align="right" class="tableTop"><h1>% cumulative</h1></td>
                  </tr>
				  <? 
				  $tablei = 0;
				  do { 
				 if(is_int($tablei/2)) {
					$bgcolor = "#eeeeee";
				} else {
					$bgcolor = "#ffffff";
				}
				 if(is_int($tablei/3) && ($tablei < 12)) {
					$tdclass = "quarter";
				} else {
					$tdclass = "";
				}
				  	if ($tablei > 0) {
						if($stotal[$tablei] < 0) {
							$fcolor = "#ff0000";
						} else {
							$fcolor = "#000033";
						}
					?>
                  <tr bgcolor="<? echo $bgcolor; ?>">
                    <td class="<? echo $tdclass; ?>"><h1><? echo $datax[$tablei]; ?></h1></td>
                    <td width="10%" align="right" class="<? echo $tdclass; ?>"><h1><font color="<? echo $fcolor; ?>"><? echo number_format($stotal[$tablei],2,',','.');?></font></h1></td>
                    <td width="10%" align="right" class="<? echo $tdclass; ?>"><h1><font color="<? echo $fcolor; ?>"><? echo number_format($total[$tablei],2,',','.');?></font></h1></td>
                    <td width="10%" align="right" class="<? echo $tdclass; ?>"><h1><? 
					$percentage = (($stotal[$tablei]/$ubertotal)*100);
					$totalpercentage = $totalpercentage + $percentage;
					echo number_format($percentage,2,',','.');?>%</h1></td>
                    <td width="10%" align="right" class="<? echo $tdclass; ?>"><h1><? 
					$cumpercentage = (($total[$tablei]/$ubertotal)*100);
					echo number_format($cumpercentage,2,',','.');
					$totalcumpercentage = $totalcumpercentage + $cumpercentage;?>%</h1></td>
                  </tr>
				  <? 
				  	} 
					$tablei++;
				  } while ($tablei <= 12); ?>
                </table>
                <p>&nbsp;</p>
                <table width="100%" border="0" cellpadding="5" cellspacing="0" class="tableBorder">
                          <tr>
                            <td><h1>Total:</h1></td>
                            <td width="10%" align="right"><h1><font color="<? 
							if($ubertotal < 0) {
									$fcolor = "#ff0000";
								} else {
									$fcolor = "#000033";
								}
							echo $fcolor; ?>"><? echo number_format($ubertotal,2,',','.'); ?></font></h1></td>
                            <td width="10%" align="right"><h1><font color="<? 
							if($ubertotal < 0) {
									$fcolor = "#ff0000";
								} else {
									$fcolor = "#000033";
								}
							echo $fcolor; ?>"><? echo number_format($ubertotal,2,',','.'); ?></font></h1></td>
                            <td width="10%" align="right"><h1><? echo number_format($totalpercentage,0,',','.');?>%</h1></td>
                            <td width="10%" align="right"><h1><? echo number_format($cumpercentage,0,',','.');?>%</h1></td>
                          </tr>
                  </table>
				</td>
            </tr>
          </table></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($maanden); 
mysql_free_result($Companies);

mysql_free_result($getyear);
mysql_free_result($settings);
mysql_free_result($Typen);
?>
Return current item: T-77.com Operational Management System