<?php require('includes/head.php');
  require 'connection/conn.php';
  if(isset($_POST['per_set']))
  {
	  $code1=$_POST['code'];
	  $per_set=$_POST['per_set'];
	  $barcode=$code1."-".$per_set;
	  
	  $check="select * from `item_set` where `i_s_barcode`='$barcode'";
	  $check_r=$conn->query($check);
	  $check_num=mysqli_num_rows($check_r);
	  //$check_num=0;
	  if($check_num==0)
	  {
	  $conn->query("INSERT INTO `item_set`(`i_s_code`, `i_s_per`,  `i_s_barcode`) VALUES ('$code1','$per_set','$barcode')");
	  }
  }
   if(isset($_GET['barcode_del']))
  {
	  $code1=$_GET['barcode_del'];
	  
	  $del="delete from `item_set` where `i_s_barcode`='$code1'";
	  $conn->query($del);
	 
  }
  
  if(isset($_POST['search']))
  {
	  $cond= "";
	  if((isset($_POST['g']))&&($_POST['g']!=NULL))
	  {
		  $g=$_POST['g']; 
		  $cond.=" and `group_code`='$g'";
	  }
	  if((isset($_POST['c']))&&($_POST['c']!=NULL))
	  {
		  $c=$_POST['c']; 
		  $cond.=" and `code`='$c'";
	  }
	   if((isset($_POST['n']))&&($_POST['n']!=NULL))
	  {
		  $n=$_POST['n']; 
		  $cond.=" and `name` like '%$n%'";
	  }
	  
	 $item="select * from `items` where `active`=1 $cond order by `d_t` desc"; 
  }
  else
  {
	$item="select * from `items` where `active`=1 order by `d_t` desc";  
  }
  
  
  
  $item_r=$conn->query($item);
?>
<div class="container">
          <div class="page-inner">
            <div class="page-header">
              <h3 class="fw-bold mb-3">کاڵاکان</h3>
              <ul class="breadcrumbs mb-3">
                <li class="nav-home">
                  <a href="home.php">
                    <i class="icon-home"></i>
                  </a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="#"></a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="#"></a>
                </li>
              </ul>
            </div>
            <div class="row">
              <div class="col-md-12">
                <div class="card">
                  
                  <div class="card-body">
                    <div class="table-responsive">
                      <table id="basic-datatables"  class="display table table-striped table-hover"  >
<thead>
<form action="" method="post">
<tr bgcolor="skyblue">
	<th></th><th></th>
	<th><input type="text" name="g" ></th>
	<th><input type="text" name="c" ></th>
	<th><input type="text" name="n" ></th>
	<th><input type="submit" name="search" value="گەڕان"></th>
	<th></th>
	<th></th>
	<th ></th>
	<th ></th>
</tr>
</form>

  <tr bgcolor="skyblue">
     <th></th><th></th>
     <th>گروپ</th>
	 <th>کۆد</th>
     <th>ناو</th>
	 <!--<th>ژمارەی سێت </th>
	 <th>ژمارە </th>-->
	 <th>نرخی کڕین</th>
	  <th>نرخی فرۆشتن</th>
	  <th></th>
	 <?php if($pos==1){ ?>
   <th ><a  href="item_new.php"><img src="icon/add.png" width=25px></a></th>
    <th ><a  href="item_list_hidden.php"><img src="icon/hidden.png" width=25px></a></th>
   <?php }?>
    
  </tr>
  </thead>
  <tbody>
  <?php $count=1;$p_sum=0;$c_sum=0;$j_sum=0; while($row=mysqli_fetch_array($item_r)) { ?>
    <tr>
	<td><?php echo $count; $count++;?></td>
	<td><a href="item_image/<?php echo $row['item_image'];?>"><img src="item_image/<?php echo $row['item_image'];?>" height=40px></a></td>
 <td><?php echo $g=$row['group_code'];?></td>    
	<td><?php echo $code=$row['code'];?></td>
	 <td style="font-size:16pt"><?php echo $n=$row['name'];?></td>
	<!--<td><?php echo $num1=$row['store_set_number'];?></td>
     <td><?php echo $num1=$row['store_number'];?></td>-->
	 <td><?php echo $p=$row['purchase_price'];?></td>
	 <td><?php echo $s=$row['sell_price'];?></td>
	 <td><form action="" method="post">
	 <input type="hidden" name="code" value="<?php echo $code;?>">
		<input type="number" name="per_set" required><input type="submit" name="per_set_submit"  value="زیادکردن">
		
		</form>
		<table border=1 width=250px>
		<?php
		$get_set="select * from `item_set` where `i_s_code`='$code'";
		$get_set_r=$conn->query($get_set);
		while($get_set_row=mysqli_fetch_array($get_set_r))
		{ $per=$get_set_row['i_s_per'];?>
		<tr >
			<td><?php echo $get_set_row['i_s_barcode'];?></td>
			<td><?php echo $get_set_row['i_set_number']."x".$get_set_row['i_s_per'];?></td>
			<td><a  href="qr.php?barcode=<?php echo $get_set_row['i_s_barcode'];?>&&price=<?php echo $s;?>&&n=<?php echo $n;?>&&per=<?php echo $per;?>"><img src='icon/qr.png' width=25px></a></td>
			<td><?php if($get_set_row['i_set_number']==0){ ?><a  href="item_list.php?barcode_del=<?php echo $get_set_row['i_s_barcode'];?>"><img src='icon/del.png' width=25px></a><?php } ?></td>
			</tr>
			<?php
			
		}
		?>
		</table>
		
	 </td>
	 
  
   
   
     <th  width=65px>
   <?php if($pos==1&&$num1==0){ ?>
   <a onclick='return confirm("دڵنیای لە سڕینەوە");' href="item_hide.php?id=<?php echo $row['code'];?>"><img src="icon/del.png" width=25px></a>
   <?php }?></th>
   <th  width=65px>
    <?php if($pos==1){ ?>
  <a href="item_edit.php?id=<?php echo $row['code'];?>"><img src="icon/edit.png" width=25px></a>
   <?php }?>
     </th></tr>
  <?php } ?>
  
  
  
 
  </tbody>
</table>

</div>
                  </div>
                </div>
              </div>
			  
			  </div>
          </div>
        </div>
<?php require'includes/foot.php';?>



  