<?
session_start();
include_once('top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
   print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
   return;
}
mysqli_query($db,"update khadidb1617.sparestock set opstk_dam = 0,curstk_dam = 0");
$res=mysqli_query($db,"select itemcode,sum(dam_qty) from khadidb.qtytransf group by itemcode");
while($res1=mysqli_fetch_array($res))
{
       $mopstk = $res1[1];
       $itemcode = $res1[0];
       $res2=mysqli_query($db,"select sum(qty) from khadidb.prod_invoice where itemtyp = 'D' and item_code = '$itemcode'");
       $res21=mysqli_fetch_array($res2);
       $mopstk = $mopstk  - $res21[0];
       $sql = "update khadidb1617.sparestock set opstk_dam = $mopstk,curstk_dam = $mopstk,opstk=opstk-$mopstk where itemcode = '".$itemcode."'";
       mysqli_query($db,$sql)or die(mysqli_error($db));
       print $sql."<br>";
}
?>
<style>

  td,th,body{font-size:14;font-family:'arial narrow';letter-spacing:1}
</style>
