<?php 
include "header.php";
include "sidebar.php";

$sqlpac=mysql_query("select * from tbl_package where amount<1 and status='Enable'");
$respac=mysql_fetch_assoc($sqlpac);

?>
  <!-- Plugin -->
  <link rel="stylesheet" href="assets/vendor/morris-js/morris.css">

  <!-- Page -->
  <div class="page">
    
    <div class="page-content container-fluid">
      <div class="row" data-plugin="matchHeight" data-by-row="true">
        <div class="col-xlg-3 col-md-12">
          <div class="row height-full">
            <div class="col-xlg-12 col-md-3">
              <!-- Panel Overall Sales -->
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-blue-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>Registered Users</div>
                     
                    </div>
                    <div class="counter-number-group margin-bottom-15">
                      <span class="counter-number-related"></span>
                      
                      <span class="counter-number"><?php $u=mysql_query("select * from tbl_users");
					  echo mysql_num_rows($u);?></span>
                    </div>
                    
                  </div>
                </div>
              </div>
              <!-- End Panel Overall Sales -->
            </div>

            <div class="col-xlg-12 col-md-3">
              <!-- Panel Today's Sales -->
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-red-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>Total Orders</div>
                     
                    </div>
                    <div class="counter-number-group margin-bottom-10">
                      
                      <span class="counter-number"><?php $u=mysql_query("select * from tbl_queries where status='accepted'");
					  echo mysql_num_rows($u);?></span>
                    </div>
                    
                  </div>
                </div>
              </div>
              <!-- End Panel Today's Sales -->
            </div>
            <div class="col-xlg-12 col-md-3">
              <!-- Panel Overall Sales -->
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-grey-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>Total Ads</div>
                     
                    </div>
                    <div class="counter-number-group margin-bottom-10">
                      
                      <span class="counter-number"><?php $u=mysql_query("select * from tbl_ads where admin_status='Approved'");
					  echo mysql_num_rows($u);?></span>
                    </div>
                    
                  </div>
                </div>
              </div>
              <!-- End Panel Today's Sales -->
            </div>
            
            <div class="col-xlg-12 col-md-3">
              <!-- Panel Overall Sales -->
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-green-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>Total Paid Ads</div>
                     
                    </div>
                    <div class="counter-number-group margin-bottom-10">
                      
                      <span class="counter-number"><?php $u1=mysql_query("select * from tbl_ads where package!='".$respac['pid']."' and admin_status='Approved'");
					  echo mysql_num_rows($u1);?></span>
                    </div>
                    
                  </div>
                </div>
              </div>
              <!-- End Panel Today's Sales -->
            </div>
          </div>
        </div>

        <div class="col-xlg-3 col-md-12">
          <div class="row height-full">
            

            <div class="col-xlg-12 col-md-4">
              <!-- Panel Today's Sales -->
              <div class="widget widget-shadow">
               
              </div>
              <!-- End Panel Today's Sales -->
            </div>
            
            <div style="" class="col-xlg-3 col-md-12">
          <div class="row height-full">
            <div class="col-xlg-12 col-md-6" style="height:50%;">
              <!-- Panel Overall Sales -->
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-blue-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>OVERALL AVERAGE EARNING FROM EACH USER</div>
                      
                    </div>
                    <div class="counter-number-group margin-bottom-15">
                      <span class="counter-number-related">Rs.</span>
                      <span class="counter-number">
                      	<?php $sqlusd=mysql_query("select * from tbl_users");
						$mysqn=mysql_num_rows($sqlusd);
						
						
						$for_adid="";
						$income="0";
						$sqlq=mysql_query("select * from tbl_queries where status='accepted'");
						
						while($resq=mysql_fetch_assoc($sqlq))
						{
							$for_adid=$resq['for_adid'];
							
							$sqla=mysql_query("select package from tbl_ads where ads_id='$for_adid'");
							
							$resa=mysql_fetch_assoc($sqla);
							
							$package=$resa['package'];
							
							$sqlps=mysql_query("select * from tbl_package where pid='$package'");
							$resps=mysql_fetch_assoc($sqlps);
							
							
							$income=$income+$resps['amount'];
							
							
							
						}
						$am=$income/$mysqn;
						 echo round($am);?>
                      
                      </span>
                    </div>
                    <div class="counter-label">
                      <!--<div class="progress progress-xs margin-bottom-10 bg-blue-800">
                        <div class="progress-bar progress-bar-info bg-white" style="width: 42%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="42" role="progressbar">
                          <span class="sr-only">42%</span>
                        </div>
                      </div>-->
                      <div class="counter counter-sm text-left">
                        <!--<div class="counter-number-group">
                          <span class="counter-number font-size-14">42%</span>
                          <span class="counter-number-related font-size-14">HIGHER THAN LAST MONTH</span>
                        </div>-->
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!-- End Panel Overall Sales -->
            </div>

            <div class="col-xlg-12 col-md-6" style="height:50%;">
              <!-- Panel Today's Sales -->
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-red-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>CURRENT MONTH AVERAGE EARNING FROM EACH USER</div>
                     
                    </div>
                    <div class="counter-number-group margin-bottom-10">
                      <span class="counter-number-related">Rs.</span>
                      <span class="counter-number">
                      	<?php 
						
						
						$for_adid1="";
						$income1="0";
						
						$for_adid2="";
						$income2="0";
						
						$sqlq1=mysql_query("select * from tbl_queries where status='accepted' and MONTH(datetime)='".date('m')."' and Year(datetime)='".date('Y')."'");
						
						$m=date('m');
						
						$m=$m-1;
					
						$sqlq2=mysql_query("select * from tbl_queries where status='accepted' and MONTH(datetime)='".$m."' and Year(datetime)='".date('Y')."'");
						while($resq2=mysql_fetch_assoc($sqlq2))
						{
							$for_adid2=$resq2['for_adid'];
							
							$sqla2=mysql_query("select package from tbl_ads where ads_id='$for_adid2'");
							
							$resa2=mysql_fetch_assoc($sqla2);
							
							$package2=$resa2['package'];
							
							$sqlps2=mysql_query("select * from tbl_package where pid='$package2'");
							$resps2=mysql_fetch_assoc($sqlps2);
							
							$income2=$income2+$resps2['amount'];
						}
						
						$am2=$income2/$mysqn;
						
											
						while($resq1=mysql_fetch_assoc($sqlq1))
						{
							$for_adid1=$resq1['for_adid'];
							
							$sqla1=mysql_query("select package from tbl_ads where ads_id='$for_adid1'");
							
							$resa1=mysql_fetch_assoc($sqla1);
							
							$package1=$resa1['package'];
							
							$sqlps1=mysql_query("select * from tbl_package where pid='$package1'");
							$resps1=mysql_fetch_assoc($sqlps1);
							
							$income1=$income1+$resps1['amount'];
							
						}
						$am1=$income1/$mysqn;
						
						echo round($am1);
						
						//
						?>
                      </span>
                    </div>
                    <div class="counter-label">
                      <div class="progress progress-xs margin-bottom-10 bg-red-800">
                        <div class="progress-bar progress-bar-info bg-white" style="width: <?php 
						if($am2>0)
						{
							
							echo $pr=(round($am1)/round($am2)*100);
						
							
						}
						else
						{
							echo "100";
						}
						  ?>%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="70" role="progressbar">
                          <span class="sr-only"><?php 
						if($am2>0)
						{
							echo $pr=(round($am1)/round($am2)*100);
						}
						else
						{
							echo "100";
						}
						  ?>%</span>
                        </div>
                      </div>
                      <div class="counter counter-sm text-left">
                        <div class="counter-number-group">
                          <span class="counter-number font-size-14"><?php 
						if($am2>0)
						{
							echo $pr=(round($am1)/round($am2)*100);
						}
						else
						{
							echo "100";
						}
						  ?>%</span>
                          <span class="counter-number-related font-size-14">
                          <?php 
						  if($am1>$am2)
						  {
						  ?> 
                          HIGHER THAN LAST MONTH
                          <?php }
						  else
						  {
							 ?> LESS THAN LAST MONTH
                             <?php
						  }
						   ?>
                          </span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!-- End Panel Today's Sales -->
            </div>
          </div>
        </div>
            <!--<div class="col-xlg-12 col-md-4">
             
              <div class="widget widget-shadow">
                <div class="widget-content widget-radius padding-30 bg-red-600 white">
                  <div class="counter counter-lg counter-inverse text-left">
                    <div class="counter-label margin-bottom-20">
                      <div>Per User Earning</div>
                     
                    </div>
                    <div class="counter-number-group margin-bottom-10">
                      
                      <span class="counter-number">
						</span>
                    </div>
                    
                  </div>
                </div>
              </div>
             
            </div>-->
            
            <div class="col-xlg-12 col-md-4">
              <!-- Panel Today's Sales -->
              <div class="widget widget-shadow">
               
              </div>
              <!-- End Panel Today's Sales -->
            </div>
            
            
            
          </div>
        </div>
        

	

        <div class="col-xlg-12 col-lg-12 col-md-12" >
          <!-- Panel Services -->
          <div class="widget widget-shadow" id="widgetBar">
            <div class="widget-content widget-radius  bg-white padding-30">
              <div class="row padding-bottom-20" style="height:calc(100% - 230px);">
                <div class="col-xs-6">
                  <div class="blue-grey-700">Monthly Chart Of Current Year</div>
                </div>
              </div>
               <div class="example">
                  <div id="exampleMorrisBar1"></div>
                </div>
            </div>
          </div>
          
          <div class="widget widget-shadow" id="widgetBar">
            <div class="widget-content widget-radius  bg-white padding-30">
              <div class="row padding-bottom-20" style="height:calc(100% - 230px);">
                <div class="col-xs-6">
                  <div class="blue-grey-700">ORDERS</div>
                </div>
              </div>
               <div class="example">
                  <div id="exampleMorrisBar"></div>
                </div>
            </div>
          </div>
          <!-- End Panel Services -->
          <!-- Panel Services -->
          <div class="widget widget-shadow" id="widgetBar">
            <div class="widget-content widget-radius  bg-white padding-30">
              <div class="row padding-bottom-20" style="height:calc(100% - 230px);">
                <div class="col-xs-6">
                  <div class="blue-grey-700">STATISTICS</div>
                </div>
              </div>
              
               <div class="example">
               		<div class="col-md-6">
              		
                  		<div id="exampleMorrisDonut"></div>
                    </div>
                    <div class="col-md-6">
                    <div id="exampleMorrisDonut1"></div>
                    </div>    
                </div>
            </div>
          </div>
          
          
          <div class="widget widget-shadow" id="widgetBar">
            <div class="widget-content widget-radius  bg-white padding-30">
              <div class="row padding-bottom-20" style="height:calc(100% - 230px);">
                <div class="col-xs-6">
                  <div class="blue-grey-700">Earning Chart</div>
                </div>
              </div>
              
               <div class="example">
               		<div id="exampleMorrisDonut2"></div>
               </div>
            </div>
          </div>
          <!-- End Panel Services -->          
        </div>

        

        

        
      </div>
    </div>
  </div>
  <!-- End Page -->



  <!-- Footer -->




  <!-- Footer -->
  

  <!-- Core  -->

  
 <?php include("footer.php");?>
  <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>-->
  
 
<script>
    (function(document, window, $) {
      'use strict';

      var Site = window.Site;

      $(document).ready(function($) {
        Site.run();
      });

      // Example Morris Bar
      // ------------------
	  
	  
	  (function() {
        Morris.Bar({
          element: 'exampleMorrisBar1',
          data: [
<?php
$earning="0";

    
	$sql11 = mysql_query("select *, MONTH(datetime) AS monthname from tbl_queries where status='accepted' and year(datetime)='".date('Y')."' GROUP BY MONTHNAME(datetime) ORDER BY datetime ASC");
	while($row11 = mysql_fetch_array($sql11))
	{
		
	//echo"select *, MONTH(datetime) AS monthname from tbl_queries where status='accepted' and month(datetime)='".$row11['monthname']."' and year(datetime)='".date('Y')."' ORDER BY datetime ASC";
	
	$sql12 = mysql_query("select *, MONTH(datetime) AS monthname from tbl_queries where status='accepted' and month(datetime)='".$row11['monthname']."' and year(datetime)='".date('Y')."'  ORDER BY datetime ASC");
	
	
	$num1 = mysql_num_rows($sql12);
	 
	 
	 	$sql1 = mysql_query("select *, MONTH(datetime) AS monthname from tbl_queries where status='accepted' and month(datetime)='".$row11['monthname']."' and year(datetime)='".date('Y')."' GROUP BY MONTH(datetime)  ORDER BY datetime ASC");
	 while($row1 = mysql_fetch_array($sql1))
	 {
		
		
		$sqlads8=mysql_query("select * from tbl_ads where ads_id='".$row1['for_adid']."'");
		$resads8=mysql_fetch_assoc($sqlads8);
		
		$packd2=mysql_query("select * from tbl_package where pid='".$resads8['package']."'");
		
		$respackd2=mysql_fetch_assoc($packd2);
		
		
		$earning=$respackd2['amount']*$num1;
?>			  
             { y: '<?php echo date("F", mktime(0, 0, 0, $row1['monthname'], 10));?>', a: <?php echo $earning;?>},
<?php 
	 }
} ?>
          ],
          xkey: 'y',
          ykeys: ['a'],
          labels: ['Rupees'],
          barGap: 6,
          barSizeRatio: 0.35,
          smooth: true,
          gridTextColor: '#474e54',
          gridLineColor: '#eef0f2',
          goalLineColors: '#e3e6ea',
          gridTextFamily: $.configs.get('site', 'fontFamily'),
          gridTextWeight: '300',
          numLines: 5,
          gridtextSize: 14,
          resize: true,
          barColors: [$.colors("green", 500)]
        });
      })();
	  
	  
	  
	  
	  
      (function() {
        Morris.Bar({
          element: 'exampleMorrisBar',
          data: [
<?php
	
	$sql = mysql_query("SELECT *, MONTHNAME(datetime) AS monthname FROM tbl_queries where status='accepted' GROUP BY MONTHNAME(datetime)  ORDER BY  datetime ASC");
	$num = mysql_num_rows($sql);
	while($row = mysql_fetch_array($sql))
	{
?>			  
             { y: '<?php echo $row['monthname'];?>', a: <?php echo $num;?>},
<?php } ?>
          ],
          xkey: 'y',
          ykeys: ['a'],
          labels: ['Orders'],
          barGap: 6,
          barSizeRatio: 0.35,
          smooth: true,
          gridTextColor: '#474e54',
          gridLineColor: '#eef0f2',
          goalLineColors: '#e3e6ea',
          gridTextFamily: $.configs.get('site', 'fontFamily'),
          gridTextWeight: '300',
          numLines: 5,
          gridtextSize: 14,
          resize: true,
          barColors: [$.colors("blue", 500)]
        });
      })();
	  
	  <?php
	$sql1 = mysql_query("SELECT * FROM tbl_users where date='".date('Y-m-d')."'");
	$totalorder = mysql_num_rows($sql1);
	
	$sql2 = mysql_query("SELECT * FROM tbl_ads where postdate='".date('Y-m-d')."'");
	$totalsupport = mysql_num_rows($sql2);
	
	$sql3 = mysql_query("SELECT * FROM tbl_queries where date(datetime)='".date('Y-m-d')."' and status='accepted'");
	$totaluser = mysql_num_rows($sql3);
	
	
	
?>	  
      // Example Morris Donut
      // --------------------
      (function() {
        Morris.Donut({
          element: 'exampleMorrisDonut',
          data: [{
            label: "Today Registered Users",
            value: <?php echo $totalorder;?>
          }, {
            label: "Today Listed Ads",
            value: <?php echo $totalsupport;?>
          }, {
            label: "Today Orders",
            value: <?php echo $totaluser;?>
          }, ],
          // barSizeRatio: 0.35,
          resize: true,
          colors: [$.colors("red", 500), $.colors("primary", 500), $.colors(
            "blue-grey", 300)]
        });
      })();	
	  
	  
<?php
	

	$sqlads1=mysql_query("select * from tbl_ads where package!='".$respac['pid']."' and admin_status!='Achieved' and postdate='".date('Y-m-d')."'");
	$resads1=mysql_num_rows($sqlads1);
	
	
	
	$sqlads2=mysql_query("select * from tbl_ads where package!='".$respac['pid']."' and admin_status!='Achieved' and month(postdate)='".date('m')."'");
	$resads2=mysql_num_rows($sqlads2);
	

?>	
	 (function() {
        Morris.Donut({
          element: 'exampleMorrisDonut1',
          data: [{
            label: "Today Paid Ads",
            value: <?php echo $resads1;?>
          }, {
            label: "Monthly Paid Ads",
            value: <?php echo $resads2;?>
          }, ],
          // barSizeRatio: 0.35,
          resize: true,
          colors: [$.colors("red", 500), $.colors("green", 500)]
        });
      })();
	  
       	 <?php
	$monthearning="0";
	$sqlads3=mysql_query("select * from tbl_queries where status='accepted' and month(datetime)='".date('m')."' and year(datetime)='".date('Y')."'");
	
	
	while($resads3=mysql_fetch_assoc($sqlads3))
	{
	
	
	
	$sqlads4=mysql_query("select * from tbl_ads where ads_id='".$resads3['for_adid']."'");
	$resads4=mysql_fetch_assoc($sqlads4);
	
	$packd=mysql_query("select * from tbl_package where pid='".$resads4['package']."'");
	
	$respackd=mysql_fetch_assoc($packd);
	
	
	$monthearning=$respackd['amount']+$monthearning;
	
	
	}
	
	
	
	$todayearning="0";
	$sqlads5=mysql_query("select * from tbl_queries where status='accepted' and date(datetime)='".date('Y-m-d')."'");
	
	
	while($resads5=mysql_fetch_assoc($sqlads5))
	{
	
	
	
	$sqlads6=mysql_query("select * from tbl_ads where ads_id='".$resads5['for_adid']."'");
	$resads6=mysql_fetch_assoc($sqlads6);
	
	$packd1=mysql_query("select * from tbl_package where pid='".$resads6['package']."'");
	
	$respackd1=mysql_fetch_assoc($packd1);
	
	
	$todayearning=$respackd1['amount']+$todayearning;
	
	
	}
	

?>	  
	  
	    (function() {
        Morris.Donut({
          element: 'exampleMorrisDonut2',
          data: [{
            label: "Today Total Earning",
            value: <?php echo $todayearning;?>
          }, {
            label: "Monthly Total Earning",
            value: <?php echo $monthearning;?>
          }, ],
          // barSizeRatio: 0.35,
          resize: true,
          colors: [$.colors("blue-grey", 500), $.colors("red", 500)]
        });
      })();	  		
	  
    })(document, window, jQuery);
  </script>
  <!-- Core  -->

 