| Current Path : /var/www/html/mmishra/icure/staff/ |
| Current File : /var/www/html/mmishra/icure/staff/yearly_medications.inc |
<h3 align='left'>Yearly Medications</h3>
<?php
$tbl = 'medicines';
$fyear = $_POST["fyear"];
if (!$fyear) $fyear = date('Y');
echo "Select year <select name='fyear' onchange=\"javascript: document.location.href='?pg=$pg&fyear='+this.value\">
<option value=''></option>";
$rs = mysql_query("select year(dis_datetime) as fyear from medications group by fyear desc");
while ($o = mysql_fetch_object($rs)) {
$fyear1 = $o->fyear;
echo "<option value='$fyear1'";
if ($fyear1 == $fyear) echo " selected";
echo ">$fyear1</option>";
}
echo "</select>
<center>";
$no = 12;//cal_days_in_month(CAL_GREGORIAN, $m, $y);
echo "<table border='1' width='90%'>
<tr><th rowspan='2'>Sr</th><th rowspan='2'>Months =><br>Medicines v</th>
<th rowspan='2'>Open<br>Stock</th><th rowspan='2'>Receipt<br>Qty</th>
<th colspan='12'>Medicines used each month this year ($fyear)</th><th rowspan='2'>Used<br>Qty</th>
<th rowspan='2'>Expired<br>Qty</th><th rowspan='2'>Close<br>Stock</th></tr>
<tr>";
foreach ($months as $mth) {
echo "<th>$mth</th>";
}
echo "</tr>";
$sl = 0;
$rs = mysql_query("select med_id,med_name,opening_stock,qty_expired from $tbl order by med_name");
while ($o = mysql_fetch_object($rs)) {
$sl++;
$mid = $o->med_id;
$ostock0 = $o->opening_stock;
$xqty = $o->qty_expired;
echo "<tr><td align='center'>$sl</td><td>$o->med_name</td>";
// total receipt qty in previous years (INFLOW)
$rqty1 = 0;
$sr = mysql_query("select sum(qty_receipt) as rq from receipts where med_id=$mid and year(rec_date)<$fyear group by med_id");
$q = mysql_fetch_object($sr);
if ($q->rq) $rqty1 = $q->rq;
// total receipt qty in this year (INFLOW)
$rqty2 = 0;
$sr = mysql_query("select sum(qty_receipt) as rq from receipts where med_id=$mid and year(rec_date)=$fyear group by med_id");
$q = mysql_fetch_object($sr);
if ($q->rq) $rqty2 = $q->rq;
// total medication qty in previous years (OUTFLOW)
$uqty1 = 0;
$sr = mysql_query("select sum(qty) as uq from medications where med_id=$mid and year(dis_datetime)<$fyear group by med_id");
$q = mysql_fetch_object($sr);
if ($q->uq) $uqty1 = $q->uq;
// opening stock = (opening stock + total receipt - total used) before this year
$ostock = ($ostock0 + $rqty1) - $uqty1;
echo "<td align='center'>". ($ostock < 0 ? "<font color='red'>$ostock</font>" : $ostock). "</td><td align='center'>$rqty2</td>";
// total medication qty in this year (OUTFLOW)
$tot = 0;
for ($i=1; $i <= $no; $i++) {
$m = $i; //str_pad($i, 2, '0', STR_PAD_LEFT);
$sr = mysql_query("select sum(qty) as uq from medications where med_id=$mid and concat(year(dis_datetime),'-',month(dis_datetime))='$fyear-$m' group by med_id");
$q = mysql_fetch_object($sr);
$uqty2 = '';
if ($q->uq) {
$uqty2 = $q->uq;
$tot += $uqty2;
}
echo "<td align='center'>$uqty2</td>";
}
// total qty used this year
echo "<td align='center'>$tot</td><td align='center'>$xqty</td>";
//closing stock = (opening stock - total received - total used) this year
$cstock = ($ostock0 + $rqty1 + $rqty2) - ($uqty1 + $tot + $xqty);
echo "<td align='center'>". ($cstock < 0 ? "<font color='red'>$cstock</font>" : $cstock). "</td></tr>";
}
?>
</table>
</center>