
<!DOCTYPE html>
<html lang="en">
    <?php include("conn.php"); 
    $page='Customer Management';
    ?>
  <?php include("common/head.php");?>
<body>
<?php include("common/menu.php")?>
<!---side nav bar end-->
<?php include("common/tittle.php")?>
    
            <!--Nav menu end-->


            <!--Main body Start-->
            <div id="accordions" class="col-sm-12 mt-2">
              <?php
               $today= date("F j, Y ");
              $sql1="select * from customers ";
              $result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
               $total_customers = mysqli_num_rows($result1) ;

               
        $sql4="select * from customers where  date='$today' ";
        $result4 = mysqli_query($conn,$sql4)or die( mysqli_error($conn));
        $new_cus = mysqli_num_rows($result4) ;
              ?>
      <center>
        <div class="row">
            <div class="col-sm-12">
                <div id="filters" class="d-flex button-group">
                    <div class="col-sm-2 ">
                        <a data-toggle="collapse" href="#collapseOne"class=" btn-order  text-center btn ">
                            <span class="text-center order-text-order-managment">Total Customers</span> <br>
                            <span class="text-center order-text-order-managment"><?php echo $total_customers ?></span>
                        </a>
                    </div>
                  <div class="col-sm-2 ">
                        <a  data-toggle="collapse" href="#collapseTwo" class="collapsed btn-order text-center btn ">
                            <span class="text-center order-text-order-managment">New Customers</span><br>
                            <span class="text-center order-text-order-managment"><?php echo $new_cus ?></span>
                        </a>
                    </div>
                
                  <!---  <div class="col-sm-2 ">
                        <a data-toggle="collapse" href="#collapseThree"class=" btn-order  collapsed text-center btn ">
                            <span class="text-center order-text-order-managment">Top Customers</span><br>
                            <span class="text-center order-text-order-managment">nan</span>
                        </a>
                    </div>--->

                </div>
            </div>
        </div>
      
      </center> 
      <hr class="bg-success">
                <!--search section end-->
                <!--Orders start-->

                <!--order-items-->
                <!--order-items-one-->
               <div style="overflow: scroll;height:100vh;"  id="collapseOne" class="  col-sm-12  " data-parent="#accordions">
                    <h5 class="text-center">Customer Management</h5>
                    <table  id="example_table" class="table-customer  table-striped   w-100 table-bordered">
                        <thead>
                        <tr>
                            <th>Id</th>
                            <th>name</th>
                            <th>number</th>
                            <th>First Purchase</th>
                            <th>Last Purchase</th>
                            <th>Total order</th>
                            <th>Total Purchase</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php

$sql1="SELECT * FROM currency ";
$result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
$row1=mysqli_fetch_array($result1) ;
$currency=$row1['curency'];

$sql="select * from customers order by customer_id desc";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
 $data=$row['customer_id'];
   $fname=$row['fname'];

   $number=$row['number'];

   $date=$row['date'];

   $wha_number= substr($number, 1);


   $sql2="SELECT contact, sum(amount) FROM orders_details where contact='$number' ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $row2=mysqli_fetch_array($result2) ;
   $amount=$row2['sum(amount)'];




 $sql3="SELECT contact FROM orders_details where contact='$number' ";
 $result3 = mysqli_query($conn,$sql3)or die( mysqli_error($conn));
 $row3=mysqli_fetch_array($result3) ;
 $total_orders = mysqli_num_rows($result3);


 $sql4="select * from orders_details where contact='$number' order by date desc ";
 $result4 = mysqli_query($conn,$sql4)or die( mysqli_error($conn));
 $row4=mysqli_fetch_array($result4);
 $last_date=$row4['date'];
 

?>
                        <tr>

                            <td><?php echo $data ?></td>
                            <td><?php echo $fname?></td>
                            <td><?php echo $number ?></td>
                            <td><?php echo $date ?></td>
                            <td><?php echo $last_date ?></td>
                            <td><?php echo $total_orders ?></td>
                            <td><?php echo  $currency."".  number_format($amount,2)?></td>
                            <td>
                                <a href="https://api.whatsapp.com/send?phone=233<?php echo $wha_number?>" target="_blank" class="btn btn-success btn-sm">Whatsapp</a>
                            <a href="customer_history?r=<?php echo $number?>" type="button" class="btn btn-primary btn-sm view-details">History</a>
                        </td>
                        </tr>
                        <?php }?>
                        <thead>
                            <tr>
                            <th>id</th>
                            <th>name</th>
                            <th>number</th>
                            <th>First Purchase</th>
                            <th>Last Purchase</th>
                            <th>Total order</th>
                            <th>Total Purchase</th>
                            <th>Action</th>
                            </tr>
                            </thead>
                    </tbody>
                    </table>
    

                </div>

        


       
<!-- Small modal -->
<div id="dataModal"  class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div id="employee_detail" class="modal-content text-dark">
     
    
    
    </div>
  </div>
</div>
         
                <!--Order end-->
            </div>
            <!--Main body end-->

            <!--Customer massaging section
            <div class="col-sm-3 cus-massage">
            <h5 class="text-center ">Costomer Feedback</h5>
            <?php

      

$sql="select * from cfeedback order by id desc";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
 $data=$row['id'];
   $fname=$row['fname'];
   $sname=$row['sname'];
   $number=$row['number'];
  
   

 $link="delete/del_blog.php?id=".urlencode(base64_encode($data));
 $edit_user="edit/edit_user.php?id=".urlencode(base64_encode($data));
 $activate="edit/user_status.php?id=".urlencode(base64_encode($data));
 $dat=$data;






?>
  
                <div class="costumer-feedback massage-feedback">
                    
                    <div class="row p-4">
                        <div class="col-12 bg-success text-center text-white"><b>Seen</b></div>
                        <div class="col-4"> <p class="customer-name"><b>Kofi Samu</b></p></div>
                        <div class="col-4"> <p class="customer-name"><b>0540948579</b></p></div>
                        <div class="col-4"> <p class="customer-name"><b>1/20/2024</b></p></div>
                        <div class="col-12 text-center"> <p class="customer-name"><b>#333</b></p></div>
                        <div class="col-12 text-center"> <p class="customer-name">Massage</p></div>
                        <div class="col-12 border"> <p class="customer-name m-2">Your food was to salty</p></div>
                        <button class="btn btn-success m-2">Mark us Seen</button>
    
                    </div>
                </div>
                <?php } ?>
                   </div>
                </div>
            </div>

              

                -->

          



      
       

       <!--  isotope plugin cdn  -->
       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
     <!-- jQuery js-->
 
     <!-- Bootstrap js -->
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
     <!-- jQuery Datatable js -->
     <script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
     <!-- Bootstrap Datatable js -->    
     <script src="https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
     <script>
       $(document).ready( function () {
           $('#example_table').DataTable();
       } );

       $(document).ready(function(){  
      $('.view_massage').click(function(){  
        var employee_ids = $(this).attr("id");  
        $.ajax({  
                url:"send_customer_massage.php",  
                method:"post",  
                data:{employee_ids:employee_ids},  
                success:function(data){  
                     $('#employee_detail').html(data);  
                     $('#dataModal').modal("show");  
                }  
           });  


      });  
 });  
</script>

</body>

</html>