| Current Path : /var/www/html/mmishra/ilight/ |
| Current File : /var/www/html/mmishra/ilight/elreadingnext.inc |
<h3>Additional Reading</h3>
Reading of newly installed meters
<?php
$tbl = "el_reading";
$month = $_POST["month"];
if (!$month) $month = previous_month();//date("M-Y");
$ids = $_POST["id"];
$flatnos = $_POST["flatno"];
$readings = $_POST["reading"];
$datereadings = $_POST["datereading"];
$wefdate = $_POST["wefdate"];
$refresh = $_REQUEST["refresh"];
if ($_POST["submit"] == 'SAVE') {
$no = 0;
foreach ($ids as $id) {
if (!$readings[$no]) $readings[$no] = 0;
if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
mysql_query("update $tbl set reading=".$readings[$no].",datereading='".$datereadings[$no]."'
where id=$id");
} else {
mysql_query("insert into $tbl(flatno,month,reading,datereading,dated)
values('".$flatnos[$no]."','$month',".$readings[$no].",'".$datereadings[$no]."',now())");
}
$no++;
}
}
echo "<center>
<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>";
$dated = date("Y-m-d");
$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 meterno_new>'' and 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_new;
$prevreading = $o->reading_new;
//licensee details
$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;
}
//reading
$sr = mysql_query("select * from $tbl where flatno='$flatno' and month='$month' order by id limit 1,1");
if (mysql_num_rows($sr)) {
$q = mysql_fetch_object($sr);
$id = $q->id;
$reading = $q->reading;
$datereading = $q->datereading;
} else {
$reading = 0;
$datereading = $dated;
}
if (!$reading) $reading = 0;
if (!$datereading) $datereading = $dated;
echo "<tr><td>$i</td><th>$flatno <input type='hidden' name='id[]' value='$id'></th>
<td>$fullname</td><td>$meterno</td><td>$prevreading<input type='hidden' name='flatno[]' value='$flatno'></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>
</center>";
?>