<?php require('includes/head.php');?>
<?php if($pos==1){ ?>
 <div class="container" >
          <div class="page-inner">
            
            <div class="row" dir=rtl>
              
			  <div class="col-sm-6 col-md-3">
                <div class="card card-stats card-round">
                  <div class="card-body">
                    <div class="row align-items-center">
                      <div class="col-icon">
                    <a href="sell_j.php">
					   <div class="icon-big text-center icon-primary bubble-shadow-small" style="margin-right:20px" >
                          <i class="fas fa-users" ></i>
                        </div>
					</a>
                      </div>
                      <div class="col col-stats ms-3 ms-sm-0">
                        <div class="numbers">
                          <p class="card-category"><h3>فرۆشتن</h3></p>
                          <h4 class="card-title">
						  <?php /*
						
						  $c="select count(`customer_id`) as c from customer where `active`=1 and cat='n'";
						  $c_r=$conn->query($c);
						  $c_row=mysqli_fetch_array($c_r);
						  echo $c_row['c']; */
						  ?>
						  </h4>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
			  
			    <div class="col-sm-6 col-md-3">
                <div class="card card-stats card-round">
                  <div class="card-body">
                    <div class="row align-items-center">
                      <div class="col-icon">
                       <a href="sell_j2.php"> <div
                          class="icon-big text-center icon-info bubble-shadow-small" style="margin-right:20px"
                        >
                          <i class="fas fa-user-check"></i>
                        </div>
						</a>
                      </div>
                      <div class="col col-stats ms-3 ms-sm-0">
                        <div class="numbers">
                          <p class="card-category"><h3>فرۆشتنی نقدی</h3></p>
                          <h4 class="card-title">
						    <?php
						 /* $c="select count(`customer_id`) as c from customer where `active`=1 and cat='d'";
						  $c_r=$conn->query($c);
						  $c_row=mysqli_fetch_array($c_r);
						  echo $c_row['c'];*/
						  ?>
						  </h4>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
			  
			  <?php
			   /*$items1=0;
				$d=date("Y-m-d");
				$d1=$d." 00:00:00";$d2=$d." 23:59:59";
				$get="select * from `get_money`,`fatura` where  `fatura_num`=`g_m_fatura` and`g_m_date` between '$d1' and '$d2' and `fat_type`='shop' ";
				$get_r=$conn->query($get);
				$sum_p=0;$sum_c=0;$sum_r=0;$count=1; 
				while($row2=mysqli_fetch_array($get_r)) { 
				$note=$row2['note'];$fat=$row2['g_m_fatura'];$am=$row2['g_m_amount'];
				if($note=="")
				{
					$items="select * from `sell`,`items` where `fatura_num`='$fat' and `sell`.`code`=`items`.`code`";
					$items_r=$conn->query($items);
					$col=mysqli_num_rows($items_r); 
					if($col>0){
					 $count++;
					 $fat=$row2['g_m_fatura'];
					 $jumla=0;
					 while($item_row=mysqli_fetch_array($items_r)) 
						{  
					
						$n=$item_row['number']; $items1+=$n;
						$j=$item_row['jumla_price']*$n;$sum_p+=$j;
						$c=$item_row['cost_price']*$n;$sum_c+=$c;
						$q=$j-$c; $sum_r+=$q;
						$jumla+=$j;
						} 
					if($jumla!=$am){ 
					$j=$am-$jumla;$sum_p+=$j;
					$q=$am-$jumla; $sum_r+=$q;
					}
					}}
  else{ 
  $count++;
  $fat=$row2['g_m_fatura'];
  $j=$row2['g_m_amount'];$sum_p+=$j;
  $c=$row2['g_m_amount']*0.66;$sum_c+=$c;
  $q=$j-$c; $sum_r+=$q;
  } } */
 //echo number_format($items1,0);
 //echo number_format($sum_p,0)
 //echo number_format($sum_c,0);
 //echo number_format($sum_r,0);
 ?>
	
    
  
			  
			  
              <div class="col-sm-6 col-md-3">
                <div class="card card-stats card-round">
                  <div class="card-body">
                    <div class="row align-items-center">
                      <div class="col-icon">
                        <a href="get.php">
						<div
                          class="icon-big text-center icon-success bubble-shadow-small" style="margin-right:20px"
                        >
                          <i class="fas fa-luggage-cart"></i>
                        </div>
						</a>
                      </div>
                      <div class="col col-stats ms-3 ms-sm-0">
                        <div class="numbers">
                          <p class="card-category"><h3>پارە وەرگرتن</h3></p>
                          <h4 class="card-title"><?php //echo number_format($sum_p,0);?></h4>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-sm-6 col-md-3">
                <div class="card card-stats card-round">
                  <div class="card-body">
                    <div class="row align-items-center">
                      <div class="col-icon">
						<a href="item_list.php">
					   <div
                          class="icon-big text-center icon-secondary bubble-shadow-small" style="margin-right:20px"
                        >
                          <i class="far fa-check-circle"></i>
                        </div>
						</a>
                      </div>
                      <div class="col col-stats ms-3 ms-sm-0">
                        <div class="numbers">
                          <p class="card-category"><h3>کاڵاکان</h3></p>
                          <h4 class="card-title"><?php //echo $count-1;?></h4>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
			
			
			
			
            <?php
			$item="select * from `items` where `active`=1 and `store_number`<0";
			$item_r=$conn->query($item);
			?>
			
			
			
            <div class="row">
              <div class="col-md-4">
                <div class="card card-round">
                  <div class="card-body">
                    <div class="card-head-row card-tools-still-right">
                      <div class="card-title">بابەتە کەم بووەکان</div>
                      
                    </div>
                    <div class="card-list py-4">
					<?php $count=0; while($row=mysqli_fetch_array($item_r)) { $count++; ?>
					
                      <div class="item-list">
					  <div style="width:30px"><?php echo $count;?></div>
                        <div class="avatar">
                          <img src="item_image/<?php echo $row['item_image'];?>" alt="..."class="avatar-img rounded-circle" />
                        </div>
                        <div class="info-user ms-3">
                          <div class="username"><?php echo $row['code'];?></div>
                          <div class="status"><?php echo $row['name'];?></div>
                        </div>
                        <button class="btn btn-icon btn-link op-8 me-1">
                          <?php echo $row['store_number'];?>
                        </button>
                        <button class="btn btn-icon btn-link btn-danger op-8">
                           <?php echo $row['target'];?>
                        </button>
                      </div>
					  
					<?php } ?>
					  
					  
					 
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-8">
                <div class="card card-round">
                  <div class="card-header">
                    <div class="card-head-row card-tools-still-right">
                      <div class="card-title">مۆعیدی پارەدان</div>
                      
                    </div>
                  </div>
                  <div class="card-body p-0">
                    <div class="table-responsive">
                      <!-- Projects table -->
                      <table class="table align-items-center mb-0">
                        <thead class="thead-light">
                          <tr>
						  <th scope="col"></th>
						   <th scope="col" class="text-end">بڕی قەرز</th>
                            <th scope="col">ناوی کڕیار</th>
                            <th scope="col" class="text-end">مۆبایل</th>
                            
                            <th scope="col" class="text-end"></th>
                          </tr>
                        </thead>
                        <tbody>
						
						<?php
						 $customer="select * from `customer` where active=1 order by `customer_name`";
						  $customer_r=$conn->query($customer);
						  $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) {
  ?>
    <tr >
	
	<th style=" background-color:<?php echo $col;?>" width=65px>
		 
		 <a href="customer_statement.php?c_id=<?php echo $row['customer_id'];?>"><img src="icon/invoice.png" width=30px></a>
		 </th>
		 <th style=" background-color:<?php echo $col;?>">
		  <button class="btn btn-icon btn-round btn-success btn-sm me-2"><i class="fa fa-check"></i></button>
		 <?php echo $st=$row['statement'];?> <?php echo $cur=$row['currency']; if($cur=='$')$sum_dollar+=$st; else $sum_dinar+=$st;?>
		 </th>
     <td class="text-end"><?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><?php echo $d;?></td>-->
	
	 
	
   
	 
	 	 

	 
	 
	 
	 </tr>
  <?php }} ?>

  
  
						
						
						
						
                         
						 
						 
						 
						 
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
<?php } else{ ?>


<div class="container" >
          <div class="page-inner">
            
            <div class="row" dir=rtl>
                
                    
                     
	<img src="icon/y.jpg" height=90% width=100%>		
			</div></div></div>
			
<?php } require'includes/foot.php';?>