Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/mybp/
Upload File :
Current File : /var/www/html/mmishra/mybp/elreadingnext.inc

<h1><img src='images/bulb7.jpg' height='12'> Meter Reading+</h1>
Reading of newly installed meters

<?php
$tbl = "el_reading";
$month = $_POST["month"];
if (!$month) $month = previous_month();//date("M-Y");

$flatnos = $_POST["flatno"];
$readings = $_POST["reading"];
$datereadings = $_POST["datereading"];

$refresh = $_REQUEST["refresh"];

if ($_POST["submit"] == 'SAVE') {
	$no = 0;
	foreach ($flatnos as $flatno) {
		if (!$readings[$no]) $readings[$no] = 0; 
		if (mysql_num_rows(mysql_query("select * from $tbl where flatno='$flatno' and 
		    month='$month' and reading=".$readings[$no]."'"))) {
			mysql_query("update $tbl set reading=".$readings[$no].", 
			datereading='".$datereadings[$no]."' where flatno='$flatno' and 
			month='$month' and reading=$readings[$no]");
		} else {
                       	mysql_query("insert into $tbl(flatno,month,reading,datereading,dated) 
			values('$flatno','$month',".$readings[$no].",'".$datereadings[$no]."',now())");
		}
		$no++;
	}
}

echo "<p>
<table width='100%' border='1' style='border-collapse: collapse'>
<tr><th rowspan='2'>No</th><th rowspan='2'>FlatNo</th><th rowspan='2'>Licensee</th><th rowspan='2'>MeterNo</th><th colspan='2'>Readings</th><th rowspan='2'>Dated</th></tr>
<tr><th>Previous</th><th>Current</th></tr>";

$dated = date("Y-m-d");

$rs = mysql_query("select * from el_flats where meterno_new>''");
while ($p = mysql_fetch_object($rs)) {
	$flatno = $p->flatno;
        $meterno = $p->meterno_new;
        $prevreading = $p->reading_new;

        $sr = mysql_query("select * from el_licensee where flatno='$flatno'");
        while ($q = mysql_fetch_object($sr)) {
                $fullname = $q->fullname;
                $category = $q->category;
        }

	$rr = mysql_query("select * from $tbl where flatno='$flatno' and month='$month' order by id limit 0,1");
        while ($o = mysql_fetch_object($rr)) {
         	$i++;
                $reading = $o->reading;
                $datereading = $o->datereading;
        }
	if (!$reading) $reading = 0;
	if (!$datereading) $datereading = $dated;
        echo "<tr><td>$i</td><td>$flatno <input type='hidden' name='flatno[]' value='$flatno'></td>
        <td>$fullname</td><td>$meterno</td><td>$prevreading</td>
        <td><input type='text' name='reading[]' size='10' value='$reading'></td>
        <td><input type='text' name='datereading[]' size='15' value='$datereading'></td></tr>";
}
echo "<tr><td align='center' colspan='7'><input type='submit' name='submit' value='SAVE'></td></tr>
</table></p>";
?>