


<?php require('includes/head.php');
  require 'connection/conn.php';
  $cond="`active`=1 and `cat`='d'";
  
  if((isset($_POST['search']))&&($_POST['search']!=""))
  {
	  $n=$_POST['n'];
	  $cond.=" and `customer_name` like '%$n%'";
  }
  
  
  $customer="select * from `customer` where $cond order by `customer_name`";
  $customer_r=$conn->query($customer);
  $customer_r=$conn->query($customer);
?>
<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>
	<tr bgcolor="skyblue">
		<th></th><th></th><th></th><th>ناو</th>
		<!--<th>ناو بە لاتینی</th>-->
		<th>مۆبایل</th>
		<th>ناونیشان</th>
		<th>ماوە</th>
		<!--<th>دوا ڕێکەوتی پارەدان</th>-->
	</tr>
	<tr>
  <form action="" method="post">
  <th></th><th></th><th></th>
   <th><input type="text" name="n" id="tag" class="form-control" style="width:250px"></th>
  <th><input type="submit" name="search" value="گەڕان" class="form-control" style="width:150px"></th>
  </form>
  </tr>
  </thead>
  <tbody>
  <?php 
  $c_date=date("Y-m-d");$count=1;$sum_dollar=0;$sum_dinar=0;
  while($row=mysqli_fetch_array($customer_r)) { 
	$c_id=$row['customer_id'];
	$last="select max(`get_date`) as `d` from `get` where `get_customer`=$c_id";
	$last_r=$conn->query($last);
	$last_row=mysqli_fetch_array($last_r);
	$d=$last_row['d'];
	$later = new DateTime(date("Y-m-d"));
	$earlier = new DateTime($d);
	$pos_diff = $earlier->diff($later)->format("%r%a");
	$l=$row['limit'];
	if($pos_diff>$l) $col="red"; else $col="white";	
  ?>
	<tr style="border: solid 1px red;">
	<th style=" background-color:<?php echo $col;?>"><?php echo $count; $count++;?></th>
	<th width=65px style=" background-color:<?php echo $col;?>">
	<?php if($pos==1){ ?>
	<a href="customer_statement.php?c_id=<?php echo $row['customer_id'];?>"><img src="icon/invoice.png" width=30px></a><?php }?></th>
	<td style=" background-color:<?php echo $col;?>"><?php echo $st=$row['statement'];?> <?php echo $cur=$row['currency'];if($cur=='$')$sum_dollar+=$st; else $sum_dinar+=$st;?></td>
	<td style="font-size:22pt;background-color:<?php echo $col;?>"><?php echo $row['customer_name'];?></td>
	<!--<td><?php echo $row['customer_name_latin'];?></td>-->
	<td style=" background-color:<?php echo $col;?>"><?php echo $row['customer_mobile'];?></td>
	<td style=" background-color:<?php echo $col;?>"><?php echo $num1=$row['customer_address'];?></td>
	<td><?php echo $row['limit'];?></td>
	<!--<td><?php echo $d;?></td>-->
	<th  width=65px>
	<?php if($pos==1){ ?>
	<a onclick='return confirm("دڵنیای لە سڕینەوە");' href="item_hide.php?customer_id=<?php echo $row['customer_id'];?>"><img src="icon/del.png" width=25px></a>
	<?php }?></th>
	<th  width=65px>
	<?php if($pos==1){ ?>
	<a href="customer_edit.php?id=<?php echo $row['customer_id'];?>"><img src="icon/edit.png" width=25px></a>
	<?php }?>
	</th>
	
	</tr>
  <?php } ?>
  <?php if(isset($_GET['show'])){ ?>
  <tr>
  <th colspan=2>کۆی قەرزی دۆلار</th>
  <th><?php echo $sum_dollar;?></th>
  </tr>
  <tr>
  <th colspan=2>کۆی قەرزی دینار</th>
  <th><?php echo $sum_dinar;?></th>
  </tr>
  <?php } else{?>
  <tr>
  <th colspan=2><a href="customer_list2.php?show=1">Show</a></th>
  
  </tr>
  <?php }?>
  </tbody>
</table>
</div>
                  </div>
                </div>
              </div>
			  
			  </div>
          </div>
        </div>
<?php require'includes/foot.php';?>

<style type="text/css"></style>
<link rel="stylesheet" type="text/css" href="search/jquery.autocomplete.css" />
<script type="text/javascript" src="search/jquery.js"></script>
<script type="text/javascript" src="search/jquery.autocomplete.js"></script>
<script>
$(document).ready(function(){
 $("#tag").autocomplete("search/autocomplete_customer2.php", {
		selectFirst: true
	});
});
</script>