<?php 
session_start();
include('../includes/dbcon.php');

$str=" ";

$data = array();

$edate=date("Y-m-d");
$userid=$_SESSION['hrm_id'];
$loc_id=1 ; //$_SESSION['loc_id'];
$discount_rate=0;

if (isset($_POST['category'])) {
 	$item = trim($_POST['category']);
 	$invref = trim($_POST['invref']);
 	$issue_qty= trim($_POST['issue_qty']);
 	//$item = 5;
 	//$invref = 200;
 	//$issue_qty= -3;

///Getting Item detil

	$sqlsp=mysqli_query($con,"SELECT  * from view_item_master where item_id=$item  ")or die(mysqli_error($con));
	        	$count=mysqli_num_rows($sqlsp);	
	        	if ($count>0) {
	        		while($row=mysqli_fetch_array($sqlsp)){			
					$sales_price =$row['sales_price'];
					$cost_price =$row['cost_price'];	
					$discount_rate =$row['discount_rate'];	
					//echo $discount_rate;		
				   }
				}
///////  end of Getting Item detil

//////getting item stock //////////////

	$sqlstock=mysqli_query($con,"SELECT  * from item_stocks where loc_id=$loc_id and item_id =$item ")or die(mysqli_error($con));
	        	$countst=mysqli_num_rows($sqlstock);	
	        	if ($countst>0) {
	        		while($rowst=mysqli_fetch_array($sqlstock)){			
					$loc_qoh =$rowst['loc_qoh'];
								
				   }

				}
 else { $loc_qoh=0;}

//////End of getting item stock
$sqlinv=mysqli_query($con,"SELECT  * from inv_temp_detail where item_id=$item and invd_id= $invref ")or die(mysqli_error($con));
	$countinv=mysqli_num_rows($sqlinv);	
	        	if ($countinv==0) {


//$ll="INSERT INTO inv_temp_detail(invd_id,item_id,qty,sales_price,cost_price,qoh,item_dis,loc_id) 
	//VALUES($invref,$item,$issue_qty,$sales_price,$cost_price,$loc_qoh,$discount_rate,$loc_id )  ";

//echo $ll;

		if ( mysqli_query($con,"INSERT INTO inv_temp_detail(invd_id,item_id,qty,sales_price,cost_price,qoh,item_dis,loc_id) 
	VALUES('$invref',$item,$issue_qty,$sales_price,$cost_price,$loc_qoh,$discount_rate,$loc_id )  ")or die(mysqli_error($con)))
	        {     	exit();    	 }

	}
} ///// if (isset($_POST['category'])) {

?>