<?php 

session_start();

include('../includes/dbcon.php');

$str=" ";
$error=0;
$edate=date("Y-m-d");
$userid=$_SESSION['rm_id'];



$loc_id= trim($_POST['loc']);
$gdate= trim($_POST['gdate']);
$cus_id= trim($_POST['cus_id']);
$note= trim($_POST['note']);
$invoice_number= trim($_POST['invoice_number']);
$emp_id= trim($_POST['emp']);

//echo $invoice_number;

///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     Validation    !!!!!!!!!!

if (empty($gdate)){
	$gdate=0;
	$error=1;
	$error_des='Date Error';
}



///~~~~~~~~~~~~~~~~~~~~~~~~~~End of Validation ~~~~~~~~~~~~~~~~~~~



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



else {

//echo "a";


mysqli_begin_transaction($con);

$sqlvat="select * from inv_header where inv_id='$invoice_number' ";

$queryvat=mysqli_query($con,$sqlvat)or die(mysqli_error());

while($rowvat=mysqli_fetch_array($queryvat)){ 
$vat_inv=$rowvat['vat_inv'];
//echo $vat_inv;
}
//echo $queryvat;
//echo "ddd";
//echo $vat_inv;
/////!!!!!!!!!!!!!!!!!!  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'];

}









		if ( mysqli_query($con,"INSERT INTO inv_temp_header(invd_id,invd_date,cus_id,loc_id,invd_ref,note,discount,inv_type,inv_id_sr,emp_id,vat_inv) 

 VALUES($inv_no,'$gdate',$cus_id,$loc_id,'$invoice_number','$note',0 ,2,'$invoice_number',$emp_id,$vat_inv)  ")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='sri_new1_inv.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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	



?>