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

$str=" ";

$error=0;

$edate=date("Y-m-d");
$userid=$_SESSION['hrm_id'];

$loc_id= trim($_POST['loc_id']);
$gdate= trim($_POST['gdate']);
$invref= trim($_POST['invref']);
$cus_id= trim($_POST['cus_id']);
$note= trim($_POST['note']);
//echo $gdate;
///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     Validation    !!!!!!!!!!
if (empty($gdate)){
	$gdate=0;
	$error=1;
	$error_des='Date Error';
}
else {

		if (empty($loc_id)){
			$loc_id=0;
			$error=1;
			$error_des='Location Error';
		}
}
///~~~~~~~~~~~~~~~~~~~~~~~~~~End of Validation ~~~~~~~~~~~~~~~~~~~

if ($error==1)  {  
	 echo "<script type='text/javascript'>alert('Please select The Item !');</script>";
	 echo "<script>document.location='srg_new.php'</script>";
}

else {


mysqli_begin_transaction($con);

/////!!!!!!!!!!!!!!!!!!  sequence   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$querydoc=mysqli_query($con,"select * from sequence where seq_id=8 ")or die(mysqli_error());
while($row=mysqli_fetch_array($querydoc)){  
$inv_no=$row['cno'];
}
///~~~~~~~~~~~~~~~~~~~~~~~~~~~   End of sequence ~~~~~~~~~~~~~~~~~~
//echo $grn_no;
//$kk="INSERT INTO grn_temp_header(grnd_no,grnd_date,grand_loc_id,refnote,sup_id,invoice_no,userid,edate) 
			// VALUES($grn_no,'$gdate','$loctype','$note','$sup_id','$supinv',$userid,'$edate' )  ";
			// echo $kk;
$loc_id= trim($_POST['loc_id']);
$gdate= trim($_POST['gdate']);
$invref= trim($_POST['invref']);
$cus_id= trim($_POST['cus_id']);
$note= trim($_POST['note']);



		if ( mysqli_query($con,"INSERT INTO inv_temp_header(invd_id,invd_date,cus_id,loc_id,invd_ref,note,discount,inv_type) 
			 VALUES($inv_no,'$gdate',$cus_id,$loc_id,'$invref','$note',0 ,3)  ")or die(mysqli_error($con)))
	        {

	        		//echo $grn_no;	
	        			if ( mysqli_query($con,"update sequence set cno =cno + 1  where seq_id=8 ")or die(mysqli_error($con)))			
						{   

							mysqli_commit($con);
							echo "<script>document.location='srg_new1.php?inv_no=$inv_no '</script>"; 

						}  
	        }






}  ///// end of else  ( $error==1)  { 











//echo $grn_no;


/////~~~~~~~~~~~~~~~~~~~~~~fundamentals~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//mysqli_begin_transaction($con);
//mysqli_commit($con);

//if (empty($invval)){
	//$invval=0;
//}

//if ( strlen($barcode)>10){
//$customer= trim($_POST['customer']);
//echo "auto";


 //$pno1=(explode("*",$pno));
 //$pono=$pno1[0];
 //$mid=$pno1[1];

//}

//$query=mysqli_query($con," select * from department_master where dep_name='$depname'  ")or die(mysqli_error($con));
//$count=mysqli_num_rows($query);

 //$querydoc=mysqli_query($con,"select * from sequence where id=4 ")or die(mysqli_error());

		//while($row=mysqli_fetch_array($querydoc)){  

		//$adj_no=$row['cno'];
//}

/////~~~~~~~~~~~~~~~~~~~~~~fundamentals~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	

?>