<?php 
include "header.php"; 


if(isset($_SESSION['user'])){
    
    
    
?>
    <!-- Main content -->
    <section class="content" id="homeDAta">
      <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info" id="todayLeads">
              <div class="inner">
                 <?php 
                
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as today FROM new_invoice where dates = '$today'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['today'];?></h3>
                <p>Today Leads</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as week FROM new_invoice
                          WHERE dates >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
                          AND   dates < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo $row['week'];?></h3>

                <p>Last Week Leads</p>
              </div>
              <div class="icon">
                <i class="ion ion-stats-bars"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as lastMonth FROM new_invoice
                        WHERE YEAR(dates) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
                        AND MONTH(dates) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>
                <h3><?php echo $row['lastMonth'];?></h3>

                <p>Last Month Leads</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT count(*) as total FROM new_invoice ";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Total Leads</p>
              </div>
              <div class="icon">
                <i class="ion ion-pie-graph"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
         <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" id= "todayLeadsSell" style="background-color:#7CF944">
              <div class="inner">
                 <?php 
            
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND user_status.created_at = '$today'
                            and new_invoice.websitename != 'http://member.tvcnw.com'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $sell = $row['total'];
                 if($sell == ""){
                     $sell = "0";
                 }
                ?>
                <h3><?php echo "$" .$sell;?></h3>
                <p>Today Sell</p>
              </div>
              <div class="icon">
               <i class="fa fa-shopping-cart"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info" >
              <div class="inner">
                <?php 
               
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                             and new_invoice.websitename != 'http://member.tvcnw.com'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo "$". $row['total'];?></h3>

                <p>Total Sell</p>
              </div>
              <div class="icon">
                <i class="fa fa-money"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#E62277">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as decline FROM `user_status` WHERE status = 'Decline' or status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $total = $row['decline'];
                 
                  $query = "SELECT count(*) as Success from user_status WHERE status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $success = $row['Success'];
                
                $approved = $success/$total*100;
                 
                ?>
                <h3><?php echo round($approved)."%";?></h3>

                <p>Approved Ratio</p>
              </div>
              <div class="icon">
                <i class="fa  fa-check"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#35ACF7">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT count(*) as total FROM user_status where status = 'Success' ";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Total Customers</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
        <div class="row">
          <div class="col-lg-3 col-6" id="todayRenew" style="cursor:pointer;color:white">
            <!-- small box -->
            <div class="small-box"  style="background-color:#2D3B4E">
              <div class="inner">
                 <?php 
            
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND new_invoice.websitename = 'http://member.tvcnw.com'
                            AND user_status.created_at = '$today'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $sell = $row['total'];
                 if($sell == ""){
                     $sell = "0";
                 }
                ?>
                <h3><?php echo "$" .$sell;?></h3>
                <p>Today Renew Sell</p>
              </div>
              <div class="icon">
               <i class="fa fa-shopping-cart"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6" id="totalsellRenew" style="cursor:pointer;color:white" >
            <!-- small box -->
            <div class="small-box"  style="background-color:#0A408E">
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND new_invoice.websitename = 'http://member.tvcnw.com'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo "$". $row['total'];?></h3>

                <p>Total Renew Sell</p>
              </div>
              <div class="icon">
                <i class="fa fa-money"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6" id="requestRenew" style="cursor:pointer">
            <!-- small box -->
            <div class="small-box" style="background-color:#A9E43E">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as total from new_invoice
                            where websitename = 'http://member.tvcnw.com'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $total = $row['total'];
                 
                
                 
                ?>
                <h3><?php echo $total;?></h3>

                <p>Total Renew Requests</p>
              </div>
              <div class="icon">
                <i class="fa  fa-check"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6" id="totalRenew" style="cursor:pointer">
            <!-- small box -->
            <div class="small-box" style="background-color:#DD4E67">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT count(new_invoice.id) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND new_invoice.websitename = 'http://member.tvcnw.com'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Total Renewed Users</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
        <!-- /.row -->
        <!-- Main row -->
        <div class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-6">
           <div class="card">
              <div class="card-header no-border">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title" id="weekleads">WEEK LEADS <span id="demo" style="font-size: 18px"></span></h3>
                  <a href="javascript:void(0)" id="reporting">View Report</a>
                </div>
              </div>
              <div class="card-body">
                 <div class="position-relative mb-4">
                  <canvas id="visitors-chart3" height="200"></canvas>
                </div>

                <!-- <div id="chart-container">
        <canvas id="graphCanvas"></canvas>
                  </div> -->
                <!-- /.d-flex -->

                
            </div>
            </div>
            <!-- /.card -->

           
            <!-- /.card -->
          </div>
          <!-- /.col-md-6 -->
          <div class="col-lg-6">
            <div class="card">
              <div class="card-header no-border">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Domains Total Leads <span id="demo2" style="font-size: 18px"></span></h3>
                  <a href="javascript:void(0);" id="sellReport">View Report</a>
                </div>
              </div>
              <div class="card-body">
                 <div class="position-relative mb-4">
                  <canvas id="visitors-chart1" height="200"></canvas>
                </div>

                <!-- <div id="chart-container">
        <canvas id="graphCanvas"></canvas>
                  </div> -->
                <!-- /.d-flex -->

                
            </div>
            <!-- /.card -->

            
          </div>
          <!-- /.col-md-6 -->
        </div>
        <!-- /.row -->
      </div>
      <div class="row">
          <div class="col-lg-6">
           <div class="card">
              <div class="card-header no-border">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Daily Sell Report  <span id="demo3" style="font-size: 18px"></span></h3>
                  <a href="javascript:void(0)" id="reporting">View Report</a>
                </div>
              </div>
              <div class="card-body">
                 <div class="position-relative mb-4">
                  <canvas id="sellDaily" height="200"></canvas>
                </div>

                <!-- <div id="chart-container">
        <canvas id="graphCanvas"></canvas>
                  </div> -->
                <!-- /.d-flex -->

                
            </div>
            </div>
            <!-- /.card -->

           
            <!-- /.card -->
          </div>
          <!-- /.col-md-6 -->
          <div class="col-lg-6">
            <div class="card">
              <div class="card-header no-border">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Monthly Sell Report</h3>
                  <a href="javascript:void(0);" id="monthReport">View Report</a>
                </div>
              </div>
              <div class="card-body">
                 <div class="position-relative mb-4">
                  <canvas id="monthSell" height="200"></canvas>
                </div>

                <!-- <div id="chart-container">
        <canvas id="graphCanvas"></canvas>
                  </div> -->
                <!-- /.d-flex -->

                
            </div>
            <!-- /.card -->

            
          </div>
          <!-- /.col-md-6 -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </div>
        <!-- /.row (main row) -->
      </div><!-- /.container-fluid -->
    </section>
<section class="content" id="userDATA" style="display: none">
  <div class="row">
     
      <div class="col-lg-4 col-md-4" id="ExportDiv">
         <div id="reportrange2" style="color:blue">
        <i class="fa fa-calendar"></i>&nbsp;
        <span></span> <i class="fa fa-caret-down"></i>
       
    </div>
    <br>
    <select class="form-control" id = "type">
        <option>select Type</option>
         <option value="Decline">Decline</option>
          <option value="Success">Success</option>
    </select>
    <br>
     <select class="form-control" id = "bank">
        <option>Select Bank</option>
         <option value="HBL">HBL</option>
          <option value="ALFALAH">ALFALAH</option>
    </select>
    <br>
       <a class="btn btn-warning" id="Export">Export Excel</a>
      </div>
      
        <div class="col-lg-4 col-md-4"></div>
    </div>
    <br>
      <div class="row">
        <div class="col-12">
         

          <!-- /.card -->

          <div class="card">
            <div class="card-header">
              <h3 class="card-title" id="cardData">Data Table With Full Features 
              
                <a class="btn btn-info pull-right" style="color:white" id="advanceSearch">search</a> 
                <a class="btn btn-info pull-right" ><div id="reportrange" style="color:blue">
                  <i class="fa fa-calendar"></i>&nbsp;
                  <span></span> <i class="fa fa-caret-down"></i>
              </div>
              
              
              </a>   <div class="col-2 pull-right">
                        <select class="form-control" id="cus_date" style="color:white;background-color:#128396">
                            <option value="">Select Type</option>
                            <option value="Success">Paid</option>
                            <option value="Decline">Decline</option>
                            <option value="Padding">Pending</option>
                            <option value="Cancel">Cancel</option>
                        </select>
                    </div></h3>

            </div>
            <!-- /.card-header -->
       

             <div class="card-body"  id="mainCard">
              
               

              
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->

    
   
    </section>
   
    <!-- /.content -->
  </div>
<?php include "footer.php";

}else{
   
  header("location:login.php");
}

 ?>
