| Current Path : /var/www/html/mmishra/irp/icure/doctor/ |
| Current File : /var/www/html/mmishra/irp/icure/doctor/stockbook.inc.bak |
<h3 align='left'>Stockbook</h3>
<table border='1' width='90%'>
<tr><th>Sr</th><th>Dated</th><th>Medicine Name</th><th>Opening Stock</th><th>Received Qty</th><th>Total Qty</th><th>Used Qty</th><th>Balance Qty</th></tr>
<?php
$tbl = 'medicines';
$medid = $_REQUEST["medid"];
$rs = mysql_query("select *,date(date_creation) as dated from $tbl order by med_name");
while ($o = mysql_fetch_object($rs)) {
$i++;
$opening_stock = $o->qty_receipt;
$qty_total = $opening_stock;
$qty_balance = $opening_stock;
echo "<tr>
<td><a name='$i'></a>$i</td>
<td>$o->dated</td>
<td><a href='doctor/?pg=$pg&medid=$o->med_id#$i'>$o->med_name</a></td>
<td align='right'>$opening_stock</td>";
//receipt on opening day
$sr = mysql_query("select med_id,date(rec_datetime) as rec_date,sum(qty_receipt) as qty_receipts from receipts
where med_id=$o->med_id and date(rec_datetime)=$o->dated group by med_id,date(rec_datetime)");
if (mysql_num_rows($sr)) {
while ($q = mysql_fetch_object($sr)) {
$qty_total = $qty_total + $q->qty_receipts;
echo "<td align='right'>$q->qty_receipts</td>
<td align='right'>$qty_total</td>";
}
} else {
echo "<td></td>
<td align='right'>$qty_total</td>";
}
//consumption on opening day
$rr = mysql_query("select med_id,date(dis_datetime) as dis_date,sum(qty) as qty_used from medications
where med_id=$o->med_id and date(dis_datetime)=$o->dated group by med_id,date(dis_datetime)");
if (mysql_num_rows($rr)) {
while ($r = mysql_fetch_object($rr)) {
$qty_balance = $qty_total - $qty_used;
echo "<td align='right'>$r->qty_used</td>
<td align='right'>$r->qty_balance</td>";
}
} else {
echo "<td></td>
<td align='right'>$qty_balance</td>";
}
echo "</tr>";
$dated = $o->dated;
$j = 0;
//consumption after opening date
$sr = mysql_query("select med_id,date(dis_datetime) as dis_date,sum(qty) as qty_used from medications
where med_id=$o->med_id and date(dis_datetime)>$dated group by med_id,date(dis_datetime)");
if (mysql_num_rows($sr)) {
while ($q = mysql_fetch_object($sr)) {
//purchase receipts after opening date
$rr = mysql_query("select med_id,date(rec_datetime) as rec_date,sum(qty_receipt) as qty_receipts from receipts
where med_id=$o->med_id and date(rec_datetime)<=$q->dis_date group by med_id,date(rec_datetime)");
if (mysql_num_rows($rr)) {
while ($r = mysql_fetch_object($rr)) {
$j++;
$qty_total = $qty_total + $r->qty_receipts;
$qty_balance = $qty_total;
echo "<tr>
<td>$i . $j</td>
<td>$r->rec_date</td>
<td></td>
<td></td>
<td align='right'>$r->qty_receipts</td>
<td align='right'>$qty_total</td>
<td></td>
<td align='right'>$qty_balance</td>
</tr>";
}
}
$qty_balance = $qty_total - $q->qty_used;
$j++;
echo "<tr>
<td>$i . $j</td>
<td>$q->dis_date</td>
<td></td>
<td></td>
<td></td>
<td align='right'>$qty_total</td>
<td align='right'>$q->qty_used</td>
<td align='right'>$qty_balance</td>";
$qty_total = $qty_total - $q->qty_used;
}
} else {
echo "<td>x</td>
<td align='right'>$qty_balance</td>";
}
echo "</tr>";
$qty_total = $qty_total + $q->qty_receipts;
$qty_balance = $qty_total;
echo "<tr>
<td>$i . $j</td>
<td>$q->rec_date</td>
<td></td>
<td></td>
<td align='right'>$q->qty_receipts</td>
<td align='right'>$qty_total</td>";
//purchase receipts after opening date
$rr = mysql_query("select med_id,date(rec_datetime) as rec_date,sum(qty_receipt) as qty_receipts from receipts
where med_id=$o->med_id and date(rec_datetime)>$dated group by med_id,date(rec_datetime)");
if (mysql_num_rows($rr)) {
while ($r = mysql_fetch_object($rr)) {
$j++;
$qty_balance = $qty_total - $r->qty_used;
echo "<td align='right'>$r->qty_used</td>
<td align='right'>$qty_balance</td>";
$qty_total = $qty_total - $r->qty_used;
}
} else {
echo "<td>x</td>
<td align='right'>$qty_balance</td>";
}
echo "</tr>";
$dated = $q->rec_date;
}
}
$rr = mysql_query("select med_id,date(dis_datetime) as dis_date,sum(qty) as qty_used from medications
where med_id=$o->med_id and date(dis_datetime)>$dated group by med_id,date(dis_datetime)");
if (mysql_num_rows($rr)) {
while ($r = mysql_fetch_object($rr)) {
$j++;
$qty_balance = $qty_total - $r->qty_used;
echo "<tr>
<td>$i . $j</td>
<td>$r->dis_date</td>
<td></td>
<td></td>
<td></td>
<td align='right'>$qty_total</td>
<td align='right'>$r->qty_used</td>
<td align='right'>$qty_balance</td>
</tr>";
$qty_total = $qty_total - $r->qty_used;
}
}
}
?>
</table>