| Current Path : /var/www/html/mmishra/icure/doctor/ |
| Current File : /var/www/html/mmishra/icure/doctor/monthly_medications.inc.bak |
<h3 align='left'>Monthly Medications</h3>
<center>
<?php
$tbl = 'medicines';
$monthyear = $_POST["monthyear"];
if (!$monthyear) $monthyear = date("Y-m");
$cal = explode("-", $monthyear);
$m = $cal[1];
$y = $cal[0];
echo "Select month <select name='monthyear'>";
$rs = mysql_query("select distinct concat(year(dis_datetime),'-',month(dis_datetime)) as monthyear
from medications order by dis_datetime desc");
while ($o = mysql_fetch_object($rs)) {
if (strlen($o->monthyear) == 6) $myear = str_replace("-","-0",$o->monthyear);
else $myear = $o->monthyear;
echo "<option value='$myear'";
if ($myear == $monthyear) echo " selected";
echo ">$myear</option>";
}
echo "</select> <input type='submit' name='submit' value='OK'>";
$no = cal_days_in_month(CAL_GREGORIAN, $m, $y);
echo "<table border='1' width='90%'>
<tr><th rowspan='2'>Sr</th><th rowspan='2'>Dates =><br>Medicines v</th>
<th colspan='$no'>Quantity used date-wise</th><th rowspan='2'>Total<br>Qty</th></tr>
<tr>";
for ($i=1; $i <= $no; $i++) {
echo "<th>".($i < 10 ? '0' : '')."$i</th>";
}
echo "</tr>";
$sl = 0;
$rs = mysql_query("select med_id,med_name from $tbl order by med_name");
while ($o = mysql_fetch_object($rs)) {
$sl++;
echo "<tr><td>$sl</td><td>$o->med_name</td>";
$tot = 0;
for ($i=1; $i <= $no; $i++) {
$d = ($i<10 ? '0'.$i : $i);
$sr = mysql_query("select date(dis_datetime) as dated, sum(qty) as iq from medications
group by med_id,dated having med_id=$o->med_id and dated='${monthyear}-$d'");
echo '<td>';
if (mysql_num_rows($sr)) {
$q = mysql_fetch_object($sr);
$tot += $q->iq;
echo $q->iq;
} else {
echo '';
}
echo '</td>';
}
echo "<td>$tot</td></tr>";
}
?>
</table>
</center>