<link rel="stylesheet" href="../css/sweet-alert.css" /> 
<?php
error_reporting(E_ALL ^ E_NOTICE);
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'];

if($ho_access=="yes")
{
$branch=$_REQUEST['branch'];
}
else {
$branch=$_SESSION['branch_id'];
}
$issue_date=$_REQUEST['from_date'];
$issue_date1=date("Y-m-d",strtotime($issue_date));
$issue_type=$_REQUEST['q1'];
$sharing_type=$_REQUEST['sharing_type'];

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

$type=$_REQUEST['type'];
$ex_date=$_REQUEST['ex_date'];
$ex_date1=date("Y-m-d",strtotime($ex_date));
$in_name=$_REQUEST['in_name'];
$s_emp_name=$_REQUEST['s_emp_name'];
$s_emp_code=$_REQUEST['s_emp_code'];
$s_emp_dept=$_REQUEST['s_emp_dept'];
 $counter=$_REQUEST['counter'];
	   $cnt=count($counter);
if($issue_type=="Individual")
{
	if($sharing_type=="Sharing")
	{

if($type=="Permanent")
{
$asset_query=mysqli_query($con,"INSERT INTO `issue_master`(`issue_type`, `issue_date`, `emp_name`, `emp_code`, `emp_dept`, `location`, `type`, `secondary_emp_name`, `secondary_emp_code`, `secondary_emp_dept`, `created_by`) VALUES('$issue_type','$issue_date1','$emp_name','$emp_code','$emp_dept','$location','$type','$s_emp_name','$s_emp_code','$s_emp_dept','$user')");
}else {
	$asset_query=mysqli_query($con,"INSERT INTO `issue_master`(`issue_type`, `issue_date`, `emp_name`, `emp_code`, `emp_dept`, `location`, `type`, `secondary_emp_name`, `secondary_emp_code`, `secondary_emp_dept`,`expire_date`, `created_by`) VALUES('$issue_type','$issue_date1','$emp_name','$emp_code','$emp_dept','$location','$type','$s_emp_name','$s_emp_code','$s_emp_dept','$ex_date1','$user')");
}
}
else{
	if($type=="Permanent")
	{
	$asset_query=mysqli_query($con,"INSERT INTO `issue_master`(`issue_type`, `issue_date`, `emp_name`, `emp_code`, `emp_dept`, `location`, `type`,`created_by`) VALUES('$issue_type','$issue_date1','$emp_name','$emp_code','$emp_dept','$location','$type','$user')");
	} else
	{
		$asset_query=mysqli_query($con,"INSERT INTO `issue_master`(`issue_type`, `issue_date`, `emp_name`, `emp_code`, `emp_dept`, `location`, `type`,`expire_date`,`created_by`) VALUES('$issue_type','$issue_date1','$emp_name','$emp_code','$emp_dept','$location','$type','$ex_date1','$user')");
	}
}
}
else{
	if($type=="Permanent")
	{
	$asset_query=mysqli_query($con,"INSERT INTO `issue_master`(`issue_type`, `issue_date`,  `location`, `type`, `emp_name`, `created_by`) VALUES('$issue_type','$issue_date1','$location','$type','$in_name','$user')");
	}
	else {
	$asset_query=mysqli_query($con,"INSERT INTO `issue_master`(`issue_type`, `issue_date`,  `location`, `type`, `expire_date`, `emp_name`, `created_by`) VALUES('$issue_type','$issue_date1','$location','$type','$ex_date1','$in_name','$user')");	
	}
}
 $get_issue_id=mysqli_query($con,"select id from `issue_master` 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;
			
				$category1=$_REQUEST[$category];
				$asset_code1=$_REQUEST[$asset_code];
				 $remark1=$_REQUEST[$remark];
			if($type=="Permanent")
			{
			$asset_table=mysqli_query($con,"INSERT INTO `issue_master_table`(`issue_master_id`, `category`, `item_code`, `remarks`,`created_by`) VALUES('$in_id','$category1','$asset_code1','$remark1','$user')");
			}
			else {
			$asset_table=mysqli_query($con,"INSERT INTO `issue_master_table`(`issue_master_id`, `category`, `item_code`, `remarks`, `expire_date`,`created_by`) VALUES('$in_id','$category1','$asset_code1','$remark1','$ex_date1','$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: "completed!",
            type: "success"
        }, function() {
     window.location = "issue_master.php";
        });
    }, 100);
</script>  
    <?php
	}	
	else
	{
	?>
	<script>
    setTimeout(function() {
        swal({
            title: "Not",
            text: "completed!",
            type: "error"
        }, function() {
     window.location = "issue_master.php";
        });
    }, 100);
</script> 	  
	<?Php
	}	
?>
<script src="../js/sweet-alert.js"></script>