Your IP : 216.73.216.40


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

<h3>Meter Reading</h3>
<center>

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

$flatnos = $_POST["flatno"];
$readings = $_POST["reading"];
$refresh = $_REQUEST["refresh"];
$datereadings = $_POST["datereading"];
if (!$datereading) $datereading = date("Y-m-d");
$dated = date("Y-m-d");

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

echo "<table width='100%'>
<tr><td width='25%'>
</td><th>
Select month <select name='month'>";

if (!mysql_num_rows(mysql_query("select distinct month from $tbl where month='$month'")))
        echo "<option value='$month'>$month</option>";

$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'>
</th><td width='25%' align='right'>
<font size='+1'>[ </font><a href='?pg=$pg&month=$month&refresh=1'>Refresh</a> <font size='+1'>]</font>
</td></tr>
</table>";
?>

<table width='80%' border='1' style='border-collapse: collapse'>
<tr><th rowspan='2'>No</th><th rowspan='2'>SiteNo</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>

<?php
//if ($refresh) {
	$rs = mysql_query("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 el_flats where status='Online' 
	order by left(flatno, pos-1), mid(flatno, pos, length(flatno)-pos+1)+0");
        while ($o = mysql_fetch_object($rs)) {
                $i++;
                $flatno = $o->flatno;
                $meterno = $o->meterno;
                $prevreading = $o->reading;
                //get category of licensee
                $sr = mysql_query("select * from el_licensee where flatno='$flatno'");
                if (mysql_num_rows($sr)) {
                        $q = mysql_fetch_object($sr);
                        $fullname = $q->fullname;
                        $category = $q->category;
                        $sharing = $q->sharing;
                        $external = $q->external;
		} else {
			$fullname = 'VACANT';
			$category = 'None';
			$external = '--';
			$sharing = 'No';
                }
                //get current reading
                $sr = mysql_query("select reading from $tbl where flatno='$flatno' and month='$month' order by id limit 0,1");
                if (mysql_num_rows($sr)) {
                        $q = mysql_fetch_object($sr);
                        $curreading = $q->reading;
		}
                //get previous reading
                $sr = mysql_query("select reading from $tbl where flatno='$flatno' and id<$id order by id desc limit 0,1");
                if (mysql_num_rows($sr)) {
                        $q = mysql_fetch_object($sr);
                        $prevreading = $q->reading;
		}
                echo "<tr><td>$i</td><th>$flatno <input type='hidden' name='flatno[]' value='$flatno'></th>
                <td>$fullname</td><td>$meterno</td><td>$prevreading</td>
                <td><input type='text' name='reading[]' size='10' value='$curreading'></td>
                <td><input type='text' name='datereading[]' size='15' value='$dated'></td></tr>";
        }

//}
/*
if (mysql_num_rows(mysql_query("select * from $tbl where month='$month'"))) {
	$rs = mysql_query("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' order by left(flatno, pos-1), mid(flatno, pos, length(flatno)-pos+1)+0");

        while ($o = mysql_fetch_object($rs)) {
                $i++;
		$id = $o->id;
                $flatno = $o->flatno;
                $sr = mysql_query("select * from el_flats where flatno='$flatno'");
                if (mysql_num_rows($sr)) {
                        $q = mysql_fetch_object($sr);
                        $meterno = $q->meterno;
                        $prevreading = $q->reading;
                }
                //get category of licensee
                $sr = mysql_query("select * from el_licensee where flatno='$flatno'");
                if (mysql_num_rows($sr)) {
                        $q = mysql_fetch_object($sr);
                        $fullname = $q->fullname;
                        $category = $q->category;
                        $sharing = $q->sharing;
                        $external = $q->external;
		} else {
			$fullname = 'VACANT';
			$category = 'None';
			$external = '--';
			$sharing = 'No';
                }
                //get previous reading
                $sr = mysql_query("select reading from $tbl where flatno='$flatno' and id<$id order by id desc limit 0,1");
                if (mysql_num_rows($sr)) {
                        $q = mysql_fetch_object($sr);
                        $prevreading = $q->reading;
		}
                echo "<tr><td>$i</td><th>$flatno <input type='hidden' name='flatno[]' value='$flatno'></th>
                <td>$fullname (".($external == 'Yes' ? 'External' : 'Internal').")</td><td>$meterno</td><td>";
		if ($prevreading >= $o->reading) echo "<font color='red'>$prevreading</font>";
		else echo $prevreading;
		echo "</td>
                <td><input type='text' name='reading[]' size='10' value='$o->reading'></td>
                <td><input type='text' name='datereading[]' size='15' value='$o->datereading' readonly></td></tr>";
        }

} else { // first time reading entry
	$rs = mysql_query("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 el_flats where status='Online' 
	order by left(flatno, pos-1), mid(flatno, pos, length(flatno)-pos+1)+0");


	while ($o = mysql_fetch_object($rs)) {
		$i++;
		$flatno = $o->flatno;
		$meterno = $o->meterno;
		$prevreading = $o->reading;
		//get category of licensee
		$sr = mysql_query("select * from el_licensee where flatno='$flatno'");
		if (mysql_num_rows($sr)) {
			$q = mysql_fetch_object($sr);
			$fullname = $q->fullname;
			$category = $q->category;
			$external = $q->external;
			$sharing = $q->sharing;
		} else {
			$fullname = 'VACANT';
			$category = 'None';
			$external = '--';
			$sharing = 'No';
		}	
		//get previous reading
		$sr = mysql_query("select * from $tbl where flatno='$flatno' order by id desc limit 0,1");
		if (mysql_num_rows($sr)) {
			$q = mysql_fetch_object($sr);
			$prevreading = $q->reading;
		}
		echo "<tr><td>$i</td><th>$flatno <input type='hidden' name='flatno[]' value='$flatno'></th>
		<td>$fullname (".($external == 'Yes' ? 'External' : ($external == 'No' ? 'Internal' : $external)).")</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='$dated'></td></tr>";
	}

}
*/
?>

<tr><th colspan='7'><input type='submit' name='submit' value='SAVE'></th></tr>
</table>
</center>