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


$code=$_REQUEST['code'];

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


<?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.category='$code'   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 

?>

