<link rel="stylesheet" href="../css/sweet-alert.css" /> 
<?php
include("../connection.php");
include("../user.php");
$cur_date=date('Y-m-d H:i:s');
$sys_date=date('Y-m-d');
$user=$_SESSION['user'];
$ho_access=$_SESSION['ha'];
$branch=$_SESSION['branch_id'];


$issue_date=$_REQUEST['from_date'];
$issue_date1=date("Y-m-d",strtotime($issue_date));
$issue_type=$_REQUEST['q1'];

$emp_name=$_REQUEST['emp_name'];
$emp_code=$_REQUEST['emp_code'];
$emp_dept=$_REQUEST['emp_dept'];
$location=$_REQUEST['location'];
$in_name=$_REQUEST['in_name'];

 $counter=$_REQUEST['counter'];
	   $cnt=count($counter);
if($issue_type=="Individual")
{
	
$asset_query=mysqli_query($con,"INSERT INTO `non_consumable_issue`(`issue_type`, `issue_date`, `emp_name`, `emp_code`, `emp_dept`, `location`,`created_by`) VALUES('$issue_type','$issue_date1','$emp_name','$emp_code','$emp_dept','$location','$user')");


//echo "INSERT INTO `non_consumable_issue`(`issue_type`, `issue_date`, `emp_name`, `emp_code`, `emp_dept`, `location`,`created_by`) VALUES('$issue_type','$issue_date1','$emp_name','$emp_code','$emp_dept','$location','$user')";
}
else{
	
	$asset_query=mysqli_query($con,"INSERT INTO `non_consumable_issue`(`issue_type`, `issue_date`,  `location`,  `incharge_name`, `created_by`) VALUES('$issue_type','$issue_date1','$location','$in_name','$user')");
	
//echo	"INSERT INTO `non_consumable_issue`(`issue_type`, `issue_date`,  `location`,  `incharge_name`, `created_by`) VALUES('$issue_type','$issue_date1','$location','$in_name','$user')";
	}
	

 $get_issue_id=mysqli_query($con,"select id from `non_consumable_issue` order by id desc limit 1");
 $iss_id=mysqli_fetch_array($get_issue_id);
 $in_id=$iss_id['id'];
for($r=1;$r<=$cnt;$r++)
			{
			$category="category".$r;
			$asset_code="asset_code".$r;
			$remark="remark".$r;
			echo "hello";
				$category1=$_REQUEST[$category];
				$asset_code1=$_REQUEST[$asset_code];
				 $remark1=$_REQUEST[$remark];
				
			$asset_table=mysqli_query($con,"INSERT INTO `non_consumable_issue_master`(`issue_master_id`, `category`, `item_code`, `remarks`, `created_by`) VALUES('$in_id','$category1','$asset_code1','$remark1','$user')");
			
			//echo "INSERT INTO `non_consumable_issue_master`(`issue_master_id`, `category`, `item_code`, `remarks`, `created_by`) VALUES('$in_id','$category1','$asset_code1','$remark1','$user')";
			$item_update=mysqli_query($con,"update item_master set status=1 where asset_id='$asset_code1'");
			 
			}

if($asset_query)
	{
	?>
	<script>
	setTimeout(function() {
        swal({
            title: "Successfully",
            text: "issued!",
            type: "success"
        }, function() {
     window.location = "non_consumable_issue_master.php";
        });
    }, 100);
</script>  
    <?php
	}	
	else
	{
	?>
	<script>
    setTimeout(function() {
        swal({
            title: "Not",
            text: "issued!",
            type: "error"
        }, function() {
     window.location = "non_consumable_issue_master.php";
        });
    }, 100);
</script> 	  
	<?Php
	}	
?>
<script src="../js/sweet-alert.js"></script>