<?php

  $branch = $conn->query(" select count(*) from branches     ")->fetchColumn();
  $groups = $conn->query(" select count(*) from groups     ")->fetchColumn();
  $products = $conn->query(" select count(*) from products     ")->fetchColumn();
  $clients = $conn->query(" select count(*) from clients     ")->fetchColumn();
  $orders = $conn->query(" select count(*) from orders WHERE  uid='$uid'    ")->fetchColumn();

  $categories = $conn->query(" select count(*) from categories     ")->fetchColumn();
  $users      = $conn->query(" select count(*) from sys_user     ")->fetchColumn();
  

  $ordersnew       = $conn->query(" select count(*) from orders WHERE STATUS=1 and uid='$uid'  ")->fetchColumn();
  
 
  $ordersapproved  = $conn->query(" select count(*) from orders WHERE STATUS=2 AND uid='$uid'  ")->fetchColumn();
  

  $ordersrejected  = $conn->query(" select count(*) from orders WHERE STATUS=3 AND uid='$uid'  ")->fetchColumn();
  

  $ordersclosed  = $conn->query(" select count(*) from orders WHERE STATUS=4 AND uid='$uid'  ")->fetchColumn();
 


  $neworders = $conn->prepare( "  SELECT a.id,a.client_id,a.branch_id,a.group_id,a.total_price,a.status,
                                         b.name bname,c.name cname,d.name dname,e.name ename 
                                   FROM orders a
                                   LEFT JOIN branches e ON a.branch_id = e.id
                                   LEFT JOIN groups b ON a.group_id = b.id
                                   LEFT JOIN clients c ON a.client_id = c.id
                                   LEFT JOIN orderstatus d ON a.status=d.id
                                   WHERE a.uid='$uid' 
                                   ORDER BY a.id DESC LIMIT  4    ");
  $neworders->execute();
  $norders = $neworders->fetchAll();
  

?>
 
     <!-- First Row -->
      <div class="row">  
        <div class="col-md-12">
       
            <!-- Start -->
              <div class="box box-success" style="border:solid;border-color:purple;border-width:thin; padding-top:0px; padding-bottom:0px;">
                <div class="box-body without-border" style="border-bottom:solid; border-width:thin;border-color:green;">
           
                  <div class="col-lg-3 col-md-6 col-xs-12">
                      <div class="small-box bg-green"   >
                          <div class="inner">
                          <h4 style="font-size:18px;  font-weight:800px; font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;" > New Orders </h4>

                          <p style="font-size:15px;"> <?php echo number_format( $ordersnew, 0); ?> </p>
                              <div class="icon">
                                        <i class="ion-android-contacts"></i>
                              </div>
                          </div>
                      </div>
                  </div>
                  
                  <div class="col-lg-3 col-md-6 col-xs-12">
                      <div class="small-box bg-purple" >
                          <div class="inner">
                          <h4 style="font-size:18px; font-weight:800px; font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;" > Approved Orders </h4>

                          <p style="font-size:15px;"> <?php echo number_format( $ordersapproved, 0); ?>  </p>
                              <div class="icon">
                                        <i class="ion-ios-people-outline"></i>
                              </div>
                          </div>
                          <!-- <a href="#" class="small-box-footer"> <i class="fa fa-arrow-LOCK"></i></a> -->
                      </div>
                  </div>
                  <div class="col-lg-3 col-md-6 col-xs-12">
                      <div class="small-box bg-purple" >
                          <div class="inner">
                          <h4 style="font-size:18px; font-weight:800px; font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;" > Delivered Orders </h4>
                          <p style="font-size:15px;"> <?php echo number_format( $ordersclosed, 0); ?> </p>
                          </div>
                      
                      </div>
                  </div>

                  <div class="col-lg-3 col-md-6 col-xs-12">
                      <div class="small-box bg-maroon" >
                          <div class="inner">
                          <h4 style="font-size:18px; font-weight:800px; font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;" > All Orders  </h4>
                          <p style="font-size:15px;"> <?php echo number_format( $orders, 0); ?> </p>
                          </div>
                      
                      </div>
                  </div>

                </div>

                 
                 <!-- /.row -->
                       
              </div>
              <!-- End --->
         
          <!-- /.box -->

        </div>
   
            <!-- <div class="col-md-4 ">
              <div class="box box-default"  >
                <div class="box-body without-border">
                    <div class="">
                            <a href="admin/allgroup" class="btn bg-purple btn-flat btn-md  btn-block" style="border-radius:30px;"  > <i class="fa fa-users"></i> ADD GROUP </a>
                      <a href="admin/allclient" class="btn bg-purple btn-flat btn-md  btn-block" style="border-radius:30px;" > <i class="fa fa-user-plus"></i> ADD CLIENT </a>
                      <a href="admin/allorder" class="btn bg-olive btn-flat btn-md  btn-block"  style="border-radius:30px;"> <i class="fa fa-plus"></i> ADD ORDER</a>
                      
                      

                      
                    </div>
                </div>  

                

              </div>
            </div>   -->
      </div>
     <!-- First Row -->

     <!-- second roow-->
      <div class="row">  
        <div class="col-md-4">
            <div class="box box-info" style="border:solid;border-width:thin;border-color:purple;">
              <div class="box-header with-border bg-white">
                <h3 class="box-title"> <i class="fa fa-bar-chart"></i> Quick Links   </h3>
              </div>
              <!-- /.box-header -->
            <div class="box-body">

                  <!-- /.progress-group -->
                  <a href="crm/group" class=" btn btn-success btn-md btn-block"> <i class="fa fa-users"></i> ADD GROUP </a>
                  <a href="crm/client" class=" btn btn-success btn-md btn-block"> <i class="fa fa-user"></i> ADD CLIENT </a>
                  <a href="sale/order" class=" btn btn-success btn-md btn-block"> <i class="fa fa-shopping-cart"></i> CREATE ORDER </a>

                  <!-- /.progress-group -->
                  

                  


                  <!-- /.progress-group -->
                  
                  <!-- /.progress-group -->
                   
                <!-- </div> -->
                <!-- /.col -->              
              <!-- /.table-responsive -->
            </div>
            <!-- /.box-body -->
            <!-- <div class="box-footer clearfix">
              <a href="javascript:void(0)" class="btn btn-sm btn-info btn-flat pull-left">Place New Order</a>
              <a href="javascript:void(0)" class="btn btn-sm btn-default btn-flat pull-right">View All Orders</a>
            </div> -->
            <!-- /.box-footer -->
          </div>    

         </div>

         <div class="col-md-8">
          <div class="box box-info" style="border:solid;border-width:thin;border-color:purple;">
            <div class="box-header with-border bg-white">
              <h3 class="box-title"> <i class="fa fa-calendar"></i> My Recent Orders</h3>

              <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <div class="table-responsive">
                <table class="table no-margin">
                  <thead>
                  <tr>
                    <th>#ID</th>
                    <th>BRANCH</th>
                    <th>GROUP</th>
                    <th>CLIENT_NAME</th>
                    <th>AMOUNT(KES)</th>
                    <th>STATUS</th>
                    <!-- <th>Popularity</th> -->
                  </tr>
                  </thead>
                  <tbody>                 
                    <?php foreach($norders as $neworder)
                     { ?>
                
                  <tr>
                    <td><?php echo $neworder["id"]; ?> </td>
                    <td><?php echo $neworder["ename"]; ?> </td>
                    <td><?php echo $neworder["bname"]; ?> </td>
                    <td><?php echo $neworder["cname"]; ?> </td>
                    <td><?php echo $neworder["total_price"]; ?> </td>
                    <td><span class="label label-success"> <?php echo $neworder["dname"]; ?> </span></td>
                    <!-- <td>
                      <div class="sparkbar" data-color="#00a65a" data-height="20">90,80,90,-70,61,-83,63</div>
                    </td> -->
                  </tr>
                    <?php } ?>

                  </tbody>
                </table>
              </div>
              <!-- /.table-responsive -->
            </div>
            <!-- /.box-body -->
            <!-- <div class="box-footer clearfix">
              <a href="javascript:void(0)" class="btn btn-sm btn-info btn-flat pull-left">Place New Order</a>
              <a href="javascript:void(0)" class="btn btn-sm btn-default btn-flat pull-right">View All Orders</a>
            </div> -->
            <!-- /.box-footer -->
          </div>
         </div>                  
         
      </div>
     <!-- end second roow-->

     <!-- Third Row -->
    
     <!-- end second roow-->









  


  

</script>