Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/ilight.bak/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/ilight.bak/elcsummary.inc

<h1><img src='images/bulb7.jpg' height='12'> Consumption Chart</h1>
<?php
$tbl = "el_billing";

$month = $_REQUEST["month"];
if (!$month) $month = previous_month();//date("M-Y");

echo "<b>Consumption chart of</b> <select name='month'>";
$rs = mysql_query("select distinct month from $tbl order by id desc");
while ($o = mysql_fetch_object($rs)) {
	echo "<option value='$o->month'";
	if ($o->month == $month) echo " selected";
	echo ">$o->month</option>";
}
echo "</select> <input type='submit' name='submit' value='OK'>";

$rs = mysql_query("select * from el_config");
if (mysql_num_rows($rs)) {
	$o = mysql_fetch_object($rs);
	$unitrate = $o->unitrate;
	$receipt = $o->receipt;
	$receiptto = $o->receiptto;
	$summary = $o->summary;
	$summaryto = $o->summaryto;
}

if ($month) {
	//$rs = mysql_query("select * from $tbl where month='$month' order by flatno");
	$rs = mysql_query("select * from (select *,
    least(
      case when locate('0', flatno)>0 then locate('0', flatno) else length(flatno)+1 end,
      case when locate('1', flatno)>0 then locate('1', flatno) else length(flatno)+1 end,
      case when locate('2', flatno)>0 then locate('2', flatno) else length(flatno)+1 end,
      case when locate('3', flatno)>0 then locate('3', flatno) else length(flatno)+1 end,
      case when locate('4', flatno)>0 then locate('4', flatno) else length(flatno)+1 end,
      case when locate('5', flatno)>0 then locate('5', flatno) else length(flatno)+1 end,
      case when locate('6', flatno)>0 then locate('6', flatno) else length(flatno)+1 end,
      case when locate('7', flatno)>0 then locate('7', flatno) else length(flatno)+1 end,
      case when locate('8', flatno)>0 then locate('8', flatno) else length(flatno)+1 end,
      case when locate('9', flatno)>0 then locate('9', flatno) else length(flatno)+1 end) pos
  from $tbl where month='$month') el_cbilling
  order by external,left(flatno, pos-1), mid(flatno, pos, length(flatno)-pos+1)+0");
	while ($o = mysql_fetch_object($rs)) {
		$i++;
		$flatno = $o->flatno;
		$licensee = $o->licensee;
		$curreading = $o->curreading;
		$prevreading = $o->prevreading;
		$consumedunit = $curreading - $prevreading;
		$unitrate = $o->unitrate;
		$amount = $consumedunit * $unitrate;
		$subsidy = $o->subsidy;
		$external = $o->external;
		if ($consumedunit > $subsidy) {
			$excessunit = $consumedunit - $subsidy;
			$payable = $excessunit * $unitrate;
		} else
			$payable = 0.00;

		$tunits += $consumedunit;
		$tamount += $amount;
		$tsubsidy += $subsidy;
		$tpayable += $payable;

		$data .= "<tr><td>$i</td><td>$flatno</td><td>$licensee (".($external == 'Yes' ? 'External' : 'Internal').")</td>
		<td align='right'>".number_format($consumedunit,2)."</td><td align='right'>Rs.".number_format($amount,2)."</td>
		<td align='right'>$subsidy</td><td align='right'>Rs.".number_format($payable,2)."</td>
		</tr>";
	}
	echo "<p>
	<table width='100%' border='1' style='border-collapse: collapse'>
	<thead>
	<tr><th colspan='7'>Electricity consumption chart for the month of $month</th></tr>
	<tr><th rowspan='2'>No</th><th rowspan='2'>FlatNo</th><th rowspan='2'>Licensee</th><th colspan='4'>Consumption & Charges (@ Rs. $unitrate)</th></tr>
	<tr><th>Units</th><th>Amount</th><th>Admissibility</th><th>Payable</th></tr>
	</thead>
	<tfoot>
	<tr><th colspan='3'>Total</th><th align='right'>".number_format($tunits,2,'.','')."</th><th align='right'>Rs.".number_format($tamount,2)."</th>
	<th></th><th align='right'>Rs.".number_format($tpayable,2)."</th></tr>
	<tr><th colspan='7'>Above readings have been taken on the last dates of this and previous month.</th></tr>
	</tfoot>
	<tbody>$data</tbody>
	</table></p>
	<b>To-<br>
	<dir>$summaryto</dir><p>$summary</p>";
}

?>