<?php 
require("../connection.php");
include("../user.php");
$user_id=$_SESSION['user'];
$username=$_SESSION['user_name'];
$branch_id=$_SESSION['branch_id'];
$ho_access=$_SESSION['ha'];


$field=$_REQUEST['field'];

?>
<script>
$(document).ready(function() {
		$('#example').DataTable();
		} );
</script>
<script>
$(document).ready(function() {
		$('#example1').DataTable();
		} );
</script>
<style>

div #first
{
	width:100%;
	height:100%;
	overflow:scroll;
}

div #second
{
	width:100%;
	height:100%;
	overflow:scroll;
}
</style>
<?php 
//$query=mysqli_query($con,"SELECT tm.type,fm.field,cm.category,cof.configuration FROM `category_master` cm left join `config_detail` cd on cm.id=cd.category_name join `configuration_master` cof on cof.id=cd.config_detail join `field_master` fm on cm.field_type=fm.id join `type_master` tm on tm.id=cm.category_type");
$query=mysqli_query($con,"SELECT DISTINCT cm.category,cm.field_type,fm.field FROM `item_master` im left join category_master cm on cm.id=im.category_id join field_master fm on fm.id=cm.field_type ");

if($field<>'all')
{
?>
<div class="row form-group">
<div class="col col-md-3"><label for="text-input" class=" form-control-label" style="color:blue;">Category</label><span style="color:red;">:</span></div>
<div class="col-12 col-md-9">
<select   id="asset" name="asset" onchange="his_report(this.value)"  class="form-control" autocomplete="off" required >
<option selected disabled>Select Category</option>
<?php
$get_code=mysqli_query($con,"SELECT DISTINCT cm.category,cm.prefix_name FROM `issue_master` im  join `issue_master_table` imt on im.id=imt.issue_master_id left join employee_master em on em.emp_no=im.emp_name left join location_master lm on lm.id=im.location join category_master cm on cm.id=imt.category where   cm.field_type='$field'");
while($code=mysqli_fetch_array($get_code))
{ ?>
<option value="<?php echo $code['category']; ?>"><?php echo $code['prefix_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div id="asset_his">
</div>
<?php 
} else
{ 

//$cus=mysqli_query($con,"select  n.id as id_no from issue_master n left join employee_master t  ON n.secondary_emp_name = t.emp_no  left join  employee_master r  ON n.emp_name = r.emp_no left join location_master lm on lm.id=n.location  ORDER BY n.id  DESC");

	$s=1;
		?>
			<div class="row form-group">
			<div class="col col-md-6"><center><span style="text-transform:uppercase;color:#00bcf5;"><b>IT ASSETS</b></span></center></div>
			<div class="col col-md-6"><center><span style="text-transform:uppercase;color:#00bcf5;"><b>NON IT ASSETS</b></span></center>
			</div>
			</div>
			
			<div class="row form-group" id="over">
			<div class="col col-md-6" id="first">
		<?php
						
			
				$cus=mysqli_query($con,"SELECT DISTINCT cm.category FROM issue_master im left join issue_master_table imt on im.id=imt.issue_master_id left join category_master cm on cm.id=imt.category left join item_master itm on itm.asset_id=imt.item_code where cm.field_type='1'   order by im.id desc");
				while($item=mysqli_fetch_array($cus))
			{
				 $ch_cat=$item['category'];
				 $first_q=mysqli_query($con,"SELECT imt.item_code FROM issue_master im left join issue_master_table imt on im.id=imt.issue_master_id left join category_master cm on cm.id=imt.category left join item_master itm on itm.asset_id=imt.item_code where cm.category='$ch_cat'   order by im.id desc");
				 while($f_query=mysqli_fetch_array($first_q))
			{
				 $rs1=$f_query['item_code'];
			}
			?>
			<span style="text-transform:uppercase;"><b><?php echo $ch_cat; ?></b></span>
			<table id="" class="table table-striped table-bordered">
			<thead style="color:#0033FF">
			<tr id="dark">	
			<th rowspan="1" id="dark">#</th>	
			
			<th rowspan="1" id="dark">Item Code</th>
			<?php $ravi1=mysqli_fetch_array(mysqli_query($con,"SELECT header FROM item_master where asset_id='$rs1'"));
			
			
			 $name1=$ravi1['header'];
			 $sss = explode(",",$name1);
			//print_r($sss);
			$cntt=count($sss);
			for($r=0;$r<$cntt;$r++)
			{
			$header_query=mysqli_fetch_array(mysqli_query($con,"select configuration from configuration_master where id=$sss[$r]"));
			
			?>
			<th rowspan="1" id="dark"><?php echo $header_query['configuration']; ?></th>
			<?php }   ?>
			</tr>
			</thead>
				<?php
			$cus1=mysqli_query($con,"SELECT im.created_by,imt.item_code,itm.value,cm.field_type FROM issue_master im left join issue_master_table imt on im.id=imt.issue_master_id left join category_master cm on cm.id=imt.category left join item_master itm on itm.asset_id=imt.item_code where cm.category='$ch_cat' and cm.field_type='1'   order by im.id desc");
			
			
			 $s=1;
			while($item2=mysqli_fetch_array($cus1))
			{	
			$creae=$item2['created_by'];
			$get_user=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM `user_master` where user_id='$creae'"));
			$crea=$get_user['user_name'];
			$Value=$item2['value'];
			$ssr = explode(",",$Value);
			$cntr=count($ssr);
			$rs1=$item2['item_code'];
			?>
			
			<tr>
			<td><?php echo $s; ?></td>
		
			<td><?php echo $item2['item_code']; ?></td>
			<?php for($a=0;$a<$cntr;$a++)
			{
			?>
		
			<td><?php echo $ssr[$a]; ?></td>
			<?php }   ?>
			</tr>


			<?php  $s++;
			
			?>
        <?php 
		}
					?>
		</table>
			<?php 
		}
					?>
		</div>
		
		<div class="col col-md-6" id="second">
		<?php
			$cus=mysqli_query($con,"SELECT DISTINCT cm.category FROM issue_master im left join issue_master_table imt on im.id=imt.issue_master_id left join category_master cm on cm.id=imt.category left join item_master itm on itm.asset_id=imt.item_code where cm.field_type='2'   order by im.id desc");
			
			while($item=mysqli_fetch_array($cus))
			{
				 $ch_cat=$item['category'];
				  $first_q=mysqli_query($con,"SELECT imt.item_code FROM issue_master im left join issue_master_table imt on im.id=imt.issue_master_id left join category_master cm on cm.id=imt.category left join item_master itm on itm.asset_id=imt.item_code where cm.category='$ch_cat'   order by im.id desc");
				 while($f_query=mysqli_fetch_array($first_q))
			{
				 $rs1=$f_query['item_code'];
			}
			?>
		<span style="text-transform:uppercase;"><b><?php echo $ch_cat; ?></b></span>
			<table id="" class="table table-hover table-bordered" style="font-family:'Times New Roman', Times, serif">
			<thead style="color:#0033FF">
			<tr id="dark">	
			<th rowspan="1" id="dark">#</th>	
			<th rowspan="1" id="dark">Item Code</th>
			<?php $ravi1=mysqli_fetch_array(mysqli_query($con,"SELECT header FROM item_master where asset_id='$rs1'"));

			 $name1=$ravi1['header'];
			 $sss = explode(",",$name1);
			//print_r($sss);
			$cntt=count($sss);
			for($r=0;$r<$cntt;$r++)
			{
			$header_query=mysqli_fetch_array(mysqli_query($con,"select configuration from configuration_master where id=$sss[$r]"));
			
			?>
			<th rowspan="1" id="dark"><?php echo $header_query['configuration']; ?></th>
			<?php }   ?>
			</tr>
			</thead>
				<?php
			$cus1=mysqli_query($con,"SELECT im.created_by,imt.item_code,itm.value,cm.field_type FROM issue_master im left join issue_master_table imt on im.id=imt.issue_master_id left join category_master cm on cm.id=imt.category left join item_master itm on itm.asset_id=imt.item_code where cm.category='$ch_cat' and cm.field_type='2'   order by im.id desc");
			
			 $s=1;
			while($item2=mysqli_fetch_array($cus1))
			{	
			$creae=$item2['created_by'];
			$get_user=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM `user_master` where user_id='$creae'"));
			$crea=$get_user['user_name'];
			$Value=$item2['value'];
			$ssr = explode(",",$Value);
			$cntr=count($ssr);
			$rs1=$item2['item_code'];
			?>
			<tr>
			<td><?php echo $s; ?></td>
			<td><?php echo $item2['item_code']; ?></td>
			<?php for($a=0;$a<$cntr;$a++)
			{
			?>
			<td><?php echo $ssr[$a]; ?></td>
			<?php }   ?>
			</tr>
			<?php  $s++;
			
			?>
        <?php 
		} ?>
		</table>
		
		<?php
			}?>
			</div>
		</div>
		
<div id="get_cat_asset" class="row form-group">
			
</div>
<?php } ?>


