Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/ilight/
Upload File :
Current File : /var/www/html/mmishra/ilight/elconsumption.inc

<h3>Group Payable</h3>
<?php
$tbl = "el_billing";

$recal = $_REQUEST["recal"];
$external = $_REQUEST["external"];
$cats = $_REQUEST["cat"];
$month = $_REQUEST["month"];

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

echo "<table width='100%'>
<tr><td width='25%'><font size='+1'>[ </font>";
if ($external == 'Yes') {
        echo "<a href='?pg=$pg&month=$month&external=No'>Internal</a> | <font color='red' size='+1'>External</font>";
} else {
        echo "<font color='red' size='+1'>Internal</font> | <a href='?pg=$pg&month=$month&external=Yes'>External</a>";
}
echo "<font size='+1'> ]</font>
</td><th nowrap>
Month <select name='month' onchange=\"javascript: document.location.href='?pg=$pg&month='+this.value\">";
$rs = mysql_query("select distinct month from el_reading 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>
</th><td width='25%' align='right'>
<font size='+1'>[ </font>
<a href='?pg=$pg&month=$month'>Refresh</a>
<font size='+1'> ] </font>
<input type='hidden' name='ext' value='$external'>
</td></tr>
</table>
<b>Group</b> ";

//get categories for report
$rs = mysql_query("select * from el_subsidy");
while ($o = mysql_fetch_object($rs)) {
       	$i = 0;
	echo "<input type='checkbox' name='cat[]' value='$o->category'";
       	foreach ($cats as $cat) {
		if ($cat == $o->category) {
			echo " checked";
       			$i = 1;
			$catlist .= ($catlist ? ',' : '')."'$cat'";
		}
	}
	if ($i) echo "><font size='+1'>$o->category</font>";
	else echo ">$o->category";
}
echo " <input type='submit' name='submit' value='FILTER'>";
	
//fetch rates
$rs = mysql_query("select * from el_config");
if (mysql_num_rows($rs)) {
	$o = mysql_fetch_object($rs);
	$unitrate = $o->unitrate;
	$fixedrate = $o->fixedrate;
	$plrate = $o->plrate;
	$edrate = $o->edrate;
	$rscrate = $o->rscrate;
	$subsidymode = $o->subsidymode;
}
$i = 0;
$sql = "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'";
	$sql .= ($external ? " and external='$external'" : '');
	$sql .= ($catlist ? " and category in ($catlist)" : '');
  	$sql .= " order by left(flatno, pos-1), mid(flatno, pos, length(flatno)-pos+1)+0";

$rs = mysql_query($sql);
while ($o = mysql_fetch_object($rs)) {
        $i++;
        $id = $o->id;
        $flatno = $o->flatno;
        $licensee = $o->licensee;
        $userfees = $o->userfees;
        $meterno = $o->meterno;
        $contactedload = $o->contactedload;
        $unitrate = $o->unitrate;
        $fixedrate = $o->fixedrate;
        $plrate = $o->plrate;
        $edrate = $o->edrate;
        $rscrate = $o->rscrate;
        $subsidy = $o->subsidy;
        $external = $o->external;
        $category = $o->category;

        $prevreading = $o->prevreading;
        $curreading = $o->curreading;
        $addunits = $o->addunits;

        $consumedunit = $curreading - $prevreading + $addunits;
        $consumedcharge = $consumedunit * $unitrate;

        $excessunit =  $consumedunit - $subsidy;

        if ($external == 'Yes') {
                $fixedcharge = $contactedload * $fixedrate;
                $subtotal = $consumedcharge + $fixedcharge;

                $plcharge = $contactedload * $plrate;
                $edcharge = $subtotal * $edrate/100;
                $rscharge = $subtotal * $rscrate/100;

                $totalamount = $subtotal + $plcharge + $edcharge + $rscharge;

                $payable = $totalamount;
        } else {
                if ($excessunit > 0) {
                        $excesscharge = $excessunit * $unitrate;
                } else {
                        $excessunit =  0;
                        $excesscharge = 0;
                }
                $payable = $excesscharge;
        }
        //payable with userfees
        $payable += $userfees;
        //summarized figures
/*
	$i++;
	$flatno = $o->flatno;
	$userfees = $o->userfees;
	$licensee = $o->licensee;
	$meterno = $o->meterno;
	$contactedload = $o->contactedload;
	$unitrate = $o->unitrate;
	$fixedrate = $o->fixedrate;
	$plrate = $o->plrate;
	$edrate = $o->edrate;
	$rscrate = $o->rscrate;
	$subsidy = $o->subsidy;
	$external = $o->external;

	$prevreading = $o->prevreading;
	$curreading = $o->curreading;
	$addunits = $o->addunits;

	$consumedunit = $curreading - $prevreading + $addunits;;
	$consumedcharge = $consumedunit * $unitrate;

        $fixedcharge = $contactedload * $fixedrate;
        $plcharge = $contactedload * $plrate;
        $edcharge = $subtotal * $edrate/100;
        $rscharge = $subtotal * $rscrate/100;
        $subtotal = $consumedcharge + $fixedcharge;
                
	$excessunit =  $consumedunit - $subsidy;
	        
	if ($external == 'Yes') {
               	$totalamount = $subtotal + $plcharge + $edcharge + $rscharge;
               	$payable = $totalamount;
       	} else {
               	if ($excessunit > 0) {
                       	$totalamount = $excessunit * $unitrate;
                       	$payable = $totalamount;
               	} else {
                       	$excessunit =  0;
                       	$payable = 0;
               	}
       	}

	//payable with userfees
	$payable = $payable + $userfees;
*/
	//sumarized figures
	$tunit += $consumedunit;
	$tcharge += $consumedcharge;
	$tamount += $totalamount;
	$tsubsidy += $subsidy;
	$tpayable += $payable;
	
	$data .= "<tr><td><a href='?pg=elreceipt&id=$o->id'>$i</a></td>
	<th>$flatno</th><td nowrap>$licensee</td><td>$meterno</td><td>$contactedload</td><td>$prevreading</td><td>$curreading</td>
	<td align='right'>".number_format($consumedunit,2)."</td>
	<td align='right'>Rs.".number_format($consumedcharge,2)."</td>
	<td align='right'>Rs.".number_format($fixedcharge,2)."</td>
	<td align='right'>Rs.".number_format($subtotal,2)."</td>
	<td align='right'>Rs.".number_format($plcharge,2)."</td>
	<td align='right'>Rs.".number_format($edcharge,2)."</td>
	<td align='right'>Rs.".number_format($rscharge,2)."</td>
	<td align='right'>Rs.".number_format($totalamount,2)."</td>
	<td align='right'>".($subsidymode == 'Rupees' ? 'Rs.' : '').number_format($subsidy,2).
	($subsidymode == 'Units' ? ' units': '')."</td>
	<td align='right'>".number_format($excessunit,2)."</td>
	<td align='right'>Rs.".number_format($userfees,2)."</td>
	<td align='right'>Rs.".number_format($payable,2)."</td></tr>";
}

echo "<table width='100%' border='1' style='border-collapse: collapse'>
<thead>
<tr><th colspan='19'><h3>Electricity bill for the month of $month</h3> 
(Unit rate: Rs. $unitrate, Fixed rate: $fixedrate/KVA/month, P.Load rate: $plrate/KVA/month, 
ED rate: $edrate%, Reg. Surcharge: $rscrate%)</th></tr>
<tr><th rowspan='2'>No</th>
<th rowspan='2'>SiteNo</th>
<th rowspan='2'>Licensee</th>
<th rowspan='2'>MeterNo</th>
<th rowspan='2'>Contacted<br>Load</th>
<th colspan='2'>KWH Meter Reading</th>
<th colspan='2'>Consumption</th>
<th colspan='6'>Connection Charges</th>
<th rowspan='2'>Admissibility</th><th rowspan='2'>Excess<br>Units</th>
<th rowspan='2'>User<br>Charges</th>
<th rowspan='2'>Payable<br>Amount</th></tr>
<tr><th>Previous</th><th>Current</th><th>Units</th><th>Charge</th>
<th>Fixed</th><th>SubTotal</th><th>PLC</th><th>ED</th><th>Sur</th><th>Total</th>
</tr>
</thead>
<tfoot>
<tr><th colspan='18'>Total</th><th>Rs.".number_format($tpayable,2)."</th></tr>
<tr><th colspan='19'>Above readings have been taken on the last dates of this and previous month.</th></tr>
</tfoot>
<tbody>$data</tbody>
</table></p>";

?>