<?
session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}
include("opendb.php");
include("test.php");

$dt=date("Y-m-d");


if($upd){
 $j=$pos;
 $pos2=$j+1;
 }

if($upd1){

  $j=1;
 $pos2=$pos1;
 }

for($i=$j;$i<$pos2;$i++){

      



	$ch=mysqli_query($db,"select * from spareprmastparts where partcode='$part[$i]' and brcode='$brcode'");

	if(mysqli_num_rows($ch)>0)
	{

		mysqli_query($db,"update spareprmastparts set lstprice='$list[$i]',ndpcost='$ndp[$i]',price2='$list2[$i]' where partcode='$part[$i]' and brcode='$brcode'");
//echo "update spareprmast set lstprice='$list[$i]',ndpcost='$ndp[$i]',price2='$list2[$i]' where partcode='$part[$i]' and brcode='$brcode'";


	}
	else
	{

		$sql="insert into spareprmastparts values('$part[$i]','$dt','9999-12-31','$ndp[$i]','$list[$i]','$list[$i]',0,'$brcode','$list2[$i]')";
		mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));

	}

    


	$ch=mysqli_query($db,"select * from spareopstockparts where itemcode='$part[$i]' and brcode='$brcode'");

	if(mysqli_num_rows($ch)>0)
	{

		mysqli_query($db,"update spareopstockparts set qty='$op[$i]',rate='$ndp[$i]' where itemcode='$part[$i]' and brcode='$brcode'");


	}
	else
	{

		$sql="insert into spareopstockparts values('$part[$i]','$partname[$i]','1','$brcode','$op[$i]','$ndp[$i]')";
		mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));

	}


   mysqli_query($db,"update partmasterparts set partname='$partname[$i]',opening_stock='$op[$i]',group1='$gp[$i]',subgroup='$subgp[$i]',descr='$descr[$i]',brand='$brand[$i]',sub_brand='$subbrand[$i]',trim_name='$trim[$i]',category='$category[$i]',location='$pcat[$i]',brcode='$brcode' where partcode='$part[$i]'");

   //print $mysql=("update newpartmaster set partname='$partname[$i]' where partcode='$part[$i]'");




 }//for loop

?>
<script>
 alert('Updated');
 document.location='partmasterparts.php';
</script>
 
