<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");


$cntres=mysqli_query($db,"select max(cntr) from sparetrinwartel where brcode='$brcode'");
$cntrow=mysqli_fetch_row($cntres);
if($cntrow[0]<=0)
 $cnt=1;
else
 $cnt=($cntrow[0]+1);

$i=0;
foreach($partcode as $a)
{
 $partcode[$i]=$a; 
 $i++;
}

$i=0;
foreach($partname as $a)
{
 $partname[$i]=$a; 
 $i++;
}

$i=0;
foreach($stono as $a)
{
 $stono[$i]=$a; 
 $i++;
}


$i=0;
foreach($preqno as $a)
{
 $preqno[$i]=$a; 
 $i++;
}

$i=0;
foreach($invno as $a)
{
 $invno[$i]=$a; 
 $i++;
}

$i=0;
foreach($invdate as $a)
{
 $invdate[$i]=parsedate($a); 
 $i++;
}
$i=0;
foreach($stat as $a)
{
 $stat[$i]=($a); 
 $i++;
}
$i=0;
foreach($psnqty as $a)
{
 $psnqty[$i]=($a); 
 $i++;
}
$i=0;
foreach($recqty as $a)
{
 $recqty[$i]=($a); 
 $i++;
}
$i=0;
foreach($servord as $a)
{
 $servord[$i]=($a); 
 $i++;
}

$dt=date("Y-m-d");
$entrydate=$ey.'-'.$em.'-'.$ed;
for($j=0;$j<$i;$j++)
{
	if(strlen($stono[$j])>0)
	{
$amtres=mysqli_query($db,"select lstprice from spareprmast where partcode='$partcode[$j]'");
$amtrow=mysqli_fetch_row($amtres);
 $amt=($amtrow[0]*$recqty[$j]);
	  $sql="insert into sparetrinwartel values('$warno','$partcode[$j]','$partname[$j]','$preqno[$j]','$invno[$j]','$invdate[$j]','$frombr','$user','$dt','$brcode','$msno','$stono[$j]','$telcqty[$j]','$amt','$recqty[$j]','$cnt','$cust','$servord[$j]','$jvno')";

          mysqli_query($db,$sql) or die(mysqli_error());
	$sql="update warsparetransout set preqno='$preqno[$j]',invno='$invno[$j]',invdate='$invdate[$j]',stat='$stat[$j]',stono='$stono[$j]' where warno='$warno' and partcode='$partcode[$j]'";
       mysqli_query($db,$sql)or die(mysqli_error());

        }
}
?>
<center>
<input type=button value='Done. Close this window' onClick=window.close()>
