<?php include("../../include/dbconnect.php"); 

$min_dt = substr($from_date,6,4).'-'.substr($from_date,3,2).'-'.substr($from_date,0,2);

$txresult = mysql_query("select account_year from company where compcode ='$compcode' ") or die(mysql_error());
$trow = mysql_fetch_row($txresult);
$account_year = $trow[0];


// UPDATE STOCK 
for($ind=0;$ind<10;$ind++)
{

	if($accepted_qty[$ind] >0 )
	{
	
	echo("Compcode : $compcode<br>");
	
		$query="insert into mat_purreg values ('$prodcode[$ind]','$po_no','$po_date','$bcode','$accepted_qty[$ind]','','$accepted_qty[$ind]','$rejected_qty','$invno','$min_dt','$compcode','$p_record','$account_year','$min_no','$min_dt','$tcno','$tc_date','$idno','$sample_size','$finish_spec','$finish_checking','$finish_observe','$burr_spec','$burr_checking','$burr_observe','$bend_spec','$bend_checking','$bend_observe','$thick_spec','$thick_checking','$thick_observe','$width_spec','$width_checking','$width_observe','$diameter_spec','$diameter_checking','$diameter_observe','$hard_spec','$hard_checking','$hard_observe','$carbon_spec','$carbon_checking','$carbon_observe','$inspector','$incharge_qc','$status','$accepted_qty_nos[$ind]','','$accepted_qty_nos[$ind]',NULL	)";
		mysql_query($query) or die (mysql_error());
	
		$resu = mysql_query("select max(record) from mat_purreg  ") or die(mysql_error());
		$row= mysql_fetch_row($resu);
		$mat_pur_record = $row[0];			
	
		$resu = mysql_query("select sum(balance) from mat_purreg where  prodcode = '$prodcode' and bcode = '$bcode'  ") or die(mysql_error());
		$row= mysql_fetch_row($resu);
		$qtyonhand = 0;
		
		if(is_array($row))
		{
		   $qtyonhand = $row[0];
		}
		if ($qtyonhand > 0)
		{
		   $opbal = $qtyonhand - $accepted_qty[$ind];
		}
		else
		{
			$opbal = 0;
		}
		$clbal = $qtyonhand;
	
		if ($qtyonhand==0)
		{
		   $clbal=$accepted_qty[$ind];
		}	
	
	
		$query="insert into stktrans values ('$prodcode[$ind]','$min_dt','$bcode','$opbal','$accepted_qty[$ind]','0','$clbal','$invno','$rate','$account_year','$compcode','$mat_pur_record',NULL)";
	
		mysql_query($query) or die (mysql_error());
	
	}
}
?>

<br>
<br>
<br>

<br><br><font size=1><center><a href= "matin.php">Make another MIN</center></font>
<br><br><font size=1><center><a href= "/wilson/stores.html">Return to index page</center></font>
