<?php 
require_once('includes/check-login.php');
require_once('includes/header.php'); 
require_once('includes/menu.php'); 
require_once('includes/config.php'); 
$tablename="save_order";	
$addurl="service-view.php";
$date=date("Y-m-d");
if($_SESSION['role_id']==1){
$sql = "SELECT * from ".$tablename." WHERE order_date='$date' order by id desc limit 0,10";

$total_order=$con->query("SELECT id from save_order order by id desc");
$today_order=$con->query("SELECT id from save_order WHERE order_date='$date' order by id desc");
$total_customer=$con->query("SELECT u.user_id, ud.name,r.role_name AS type, ud.phone, u.active,u.created_at,u.updated_at FROM users u JOIN user_details ud ON u.user_id = ud.user_id JOIN user_roles ur ON ud.user_id = ur.user_id JOIN roles r ON r.role_id = ur.role_id WHERE ur.role_id IN(3)");
$total_vendor=$con->query("SELECT u.user_id, ud.name,r.role_name AS type, ud.phone, u.active,u.created_at,u.updated_at FROM users u JOIN user_details ud ON u.user_id = ud.user_id JOIN user_roles ur ON ud.user_id = ur.user_id JOIN roles r ON r.role_id = ur.role_id WHERE ur.role_id IN(2)");
}else{
$sql="SELECT * from ".$tablename." WHERE order_date='$date' and vendor_id='".$_SESSION['userid']."' order by id desc limit 0,10";    
$total_order=$con->query("SELECT id from save_order WHERE vendor_id='".$_SESSION['userid']."' order by id desc");
$today_order=$con->query("SELECT id from save_order WHERE order_date='$date' and vendor_id='".$_SESSION['userid']."' order by id desc");
}
$result = $con->query($sql);
?>
<style>.card-body .fa{font-size:50px;}</style>
<link href='dist/css/dashboard.css' rel='stylesheet' type='text/css' />
<!-- Datatable CSS -->
<link href='data_tables/datatables.min.css' rel='stylesheet' type='text/css' />
<!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">                                
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>                    
                        <li class="active"><a href="services.php">Dashboard</a></li>           
                    </ol>                
            </section>

            <!-- Main content -->
            <section class="content">                
                <!-- Default box -->
                <div class="box box-form">
                    <div class="box-header with-border">
                        <h3 class="box-title">Dashboard</h3><br/>
                       
                    </div>
                    <div class="box-body">  
                    <div class="row">
         <?php if($_SESSION['role_id']==1){?>                
          <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="card card-stats">
              <div class="card-body ">
                <div class="row">
                  <div class="col-5 col-md-4">
                    <div class="icon-big text-center icon-warning">
                     <i class="fa fa-line-chart" aria-hidden="true"></i>
                    </div>
                  </div>
                  <div class="col-7 col-md-8">
                    <div class="numbers">
                      <p class="card-category">Total Order</p>
                      <p class="card-title"><?php echo mysqli_num_rows($total_order);?>
                    </p></div>
                  </div>
                </div>
              </div>
              <div class="card-footer ">
                <hr>
                <div class="stats">
                  <i class="fa fa-refresh"></i> Total
                </div>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="card card-stats">
              <div class="card-body ">
                <div class="row">
                  <div class="col-5 col-md-4">
                    <div class="icon-big text-center icon-warning">
                     <i class="fa fa-cube" aria-hidden="true"></i>
                    </div>
                  </div>
                  <div class="col-7 col-md-8">
                    <div class="numbers">
                      <p class="card-category">Today</p>
                      <p class="card-title"><?php echo mysqli_num_rows($today_order);?>
                        </p><p>
                    </p></div>
                  </div>
                </div>
              </div>
              <div class="card-footer ">
                <hr>
                <div class="stats">
                  <i class="fa fa-calendar-o"></i> Today
                </div>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="card card-stats">
              <div class="card-body ">
                <div class="row">
                  <div class="col-5 col-md-4">
                    <div class="icon-big text-center icon-warning">
                     <i class="fa fa-bars" aria-hidden="true"></i>
                    </div>
                  </div>
                  <div class="col-7 col-md-8">
                    <div class="numbers">
                      <p class="card-category">Customer</p>
                      <p class="card-title"><?php echo mysqli_num_rows($total_customer);?>
                        </p><p>
                    </p></div>
                  </div>
                </div>
              </div>
              <div class="card-footer ">
                <hr>
                <div class="stats">
                  <i class="fa fa-clock-o"></i>Customer
                </div>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="card card-stats">
              <div class="card-body ">
                <div class="row">
                  <div class="col-5 col-md-4">
                    <div class="icon-big text-center icon-warning">
                      <i class="fa fa-file" aria-hidden="true"></i>
                    </div>
                  </div>
                  <div class="col-7 col-md-8">
                    <div class="numbers">
                      <p class="card-category">Vendor</p>
                      <p class="card-title"><?php echo mysqli_num_rows($total_vendor);?>
                        </p><p>
                    </p></div>
                  </div>
                </div>
              </div>
              <div class="card-footer ">
                <hr>
                <div class="stats">
                  <i class="fa fa-refresh"></i> Vendor
                </div>
              </div>
            </div>
          </div>
          <?php }else{?>
           <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="card card-stats">
              <div class="card-body ">
                <div class="row">
                  <div class="col-5 col-md-4">
                    <div class="icon-big text-center icon-warning">
                     <i class="fa fa-line-chart" aria-hidden="true"></i>
                    </div>
                  </div>
                  <div class="col-7 col-md-8">
                    <div class="numbers">
                      <p class="card-category">Total Order</p>
                      <p class="card-title"><?php echo mysqli_num_rows($total_order);?>
                    </p></div>
                  </div>
                </div>
              </div>
              <div class="card-footer ">
                <hr>
                <div class="stats">
                  <i class="fa fa-refresh"></i> Total
                </div>
              </div>
            </div>
          </div>
          <div class="col-lg-3 col-md-6 col-sm-6">
            <div class="card card-stats">
              <div class="card-body ">
                <div class="row">
                  <div class="col-5 col-md-4">
                    <div class="icon-big text-center icon-warning">
                     <i class="fa fa-cube" aria-hidden="true"></i>
                    </div>
                  </div>
                  <div class="col-7 col-md-8">
                    <div class="numbers">
                      <p class="card-category">Today</p>
                      <p class="card-title"><?php echo mysqli_num_rows($today_order);?>
                        </p><p>
                    </p></div>
                  </div>
                </div>
              </div>
              <div class="card-footer ">
                <hr>
                <div class="stats">
                  <i class="fa fa-calendar-o"></i> Today
                </div>
              </div>
            </div>
          </div>
          <?php }?>
        </div>
                       <table id='workapp' class='display dataTable table table-bordered table-hover'>
                            <thead>
                            <tr>
							    <th class="table-check">
						         S.No
						        </th>
                                <th>Order ID</th>                    
                                <th>Name</th>  
                                <th>Phone</th> 
                                <th>Email</th>
                                <th>Job Date & Time</th>
                                <th>Status</th>
                                <th>Action</th>                                 
                            </tr>
                            </thead> 
                              <tbody>
							<?php $i=1;
							if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                            $status=$row['job_status'];
                            if($status==0){
                               $stacom="Pending"; 
                            }else if($status==1){
                               $stacom="Approved";  
                            }else if($status==2){
                               $stacom="Completed";  
                            }else{
                               $stacom="Canceled";  
                            }?>
						   <tr>
						   <td class="table-check">
						   <?php echo $i;?></td>
						   <td><?php echo $row['id'];?></td>
						   <td><?php echo $row['name'];?></td>
						   <td><?php echo $row['phone'];?></td>
						   <td><?php echo $row['email'];?></td>
						   <td><?php echo $row['job_date'];?> & <?php echo $row['job_time'];?></td>
						   <td><?php echo $stacom;?></td>
						   <td><a href="<?php echo $base_url.$addurl;?>?id=<?php echo $row['id'];?>" class="tabledit-edit-button btn btn-sm btn-primary" title="View"><span class="glyphicon glyphicon-eye-open"></span></a></td>
						    </tr>								  
							 <?php $i++;}}?>
                           </tbody>							
                        </table>

                    </div>
                    
                    <!-- /.box-footer-->                    
                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->                                        
        </div>
        <!-- /.content-wrapper -->        
<script src="js/common.js"></script>  
<script src="js/datatables.js"></script>    
<?php require_once('includes/footer.php'); ?>