<?
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 sparetroutwartel 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++;
}
$i=0;
foreach($amount as $a)
{
 $amount[$i]=($a); 
 $i++;
}

$dt=date("Y-m-d");
$entrydate=$ey.'-'.$em.'-'.$ed;
for($j=0;$j<$i;$j++)
{
	if($recqty[$j]>0)
	{
	  $sql="insert into sparetroutwartel values('$warno','$partcode[$j]','$partname[$j]','$preqno[$j]','$invno[$j]','$invdate[$j]','$frombr','$user','$dt','$brcode','$msno','$stono[$j]','$psnqty[$j]','$amount[$j]','$recqty[$j]','$cnt','$cust','$servord[$j]','')";

          mysqli_query($db,$sql) or die(mysqli_error());
        }
}
?>
<center>
<script>
alert('Done');
document.location='sparetroutwarTQ.php';
</script>

