<?php require_once('../auth/auth.php'); ?>
<div class="row">
	<div class="col-md-3 pr-0">
	<div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
        <div class="card-header" style="padding: 3px 8px;">
          <h3 class="card-title"><?php echo language(93);?></h3>
          <div class="card-tools m-0">
            <button type="button" class="btn btn-tool" data-card-widget="remove">
              <i class="fas fa-times"></i>
            </button>
          </div>
        </div>		
        <div class="card-header" style="padding: 3px 8px;">
         <div class="input-group input-group-sm float-left" style="width:165px;">
            <input type="text" name="table_search" class="form-control form-control-sm search" placeholder="Search">
         </div>
          <div class="card-tools m-0">
			<div class="btn-group">
				<button type="button" class="btn btn-success p-1" onclick="pagecall('../itemstock/item_select.php','#item_profile');"><?php echo language(94)?></button>
				<button type="button" class="btn btn-success p-1 dropdown-toggle" data-toggle="dropdown" aria-expanded="false"></button>
             
            <?php if(per('item_import')==1){ ?>
              <ul class="dropdown-menu">
                <li><a class="dropdown-item" title="Import" onclick="pagecall('../itemstock/csv_indexb.php','#item_profile');"><i class="fas fa-upload"></i> <?php echo language(96)?></a></li>
                <div class="dropdown-divider m-0"></div>
                <li><a class="dropdown-item" href="#">Another action</a></li>
                <div class="dropdown-divider m-0"></div>
                <li><a class="dropdown-item" href="#">Something else here</a></li>
              </ul>	
           <?php } ?>
              
              
			</div>
          </div>
        </div>
	           <div class="card-body table-responsive p-0 cscroll" style="max-height: 450px;">
	              <table class="ttable table-head-fixed text-nowrap table-hover">
	                 <thead>
	                    <tr>
	                       <th style="width:60%;padding: 10px 8px;"><?php echo language(77)?></th>
	                       <th style="width:30%;text-align:center;padding: 10px 8px;"><?php echo language(78)?></th>
	                       <th style="width:10%;text-align:center;padding: 10px 8px;"><?php echo language(80)?></th>
	                    </tr>
	                 </thead>
					<?php 
					  $itquery= mysqli_query($conn,"SELECT pro_id,item_name,item_code,item_qty FROM item WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND pro_type='P' AND active=1 ORDER BY pro_id DESC") or die (mysqli_error($conn));
					    $data = [];
					    while ($itro= mysqli_fetch_assoc($itquery)){ $data[]=$itro;}
					?>	                 
	                 <tbody class="actived" id="proshow"></tbody>
	              </table>
	           </div>	
	     </div>	
	</div>
	<div class="col-md-9" id="item_profile"></div>
</div>

<script type="text/javascript">
	$(document).ready(function(){
		var itdata = '';
		var i = 0;
		$.each(<?php echo json_encode($data) ?>, function(key,itr){
			itdata += '<tr onclick="itemprofile('+itr.pro_id+')">';
			itdata += '<td style="padding:8px 8px;">'+ itr.item_name +'</td>';
			itdata += '<td style="padding:8px 8px;text-align:center;">'+ itr.item_code +'</td>';
			itdata += '<td style="padding:8px 8px;text-align:center;">'+ bden.format(itr.item_qty) +'</td>';
			itdata += '</tr>';
		});
		$("#proshow").html(itdata);
	});

	function itemprofile(productid){    
		pagecall('../itemstock/item_profile.php?pro_id='+productid,'#item_profile');   
	}  
</script>

<script>
$(document).ready(function(){
	$('.search').on('keyup',function(){
		var searchTerm = $(this).val().toLowerCase();
		$('.actived tr').each(function(){
			var lineStr = $(this).text().toLowerCase();
			if(lineStr.indexOf(searchTerm) === -1){
				$(this).hide();
			}else{
				$(this).show();
			}
		});
	});
});
</script>