<?php 
ob_start();
error_reporting(0);
session_start();
include("connect.php");
$user_id=$_SESSION['user_id'];
$ver=$_SESSION['distributor_id'];

date_default_timezone_set('Asia/Calcutta');
$time = date("h:i:s");
$date  = date("Y-m-d");
$dateTime =$date." ".$time;

$ndate=date("Y-m");
$startdate=$ndate.'-01 00:00:00';
$enddate=$ndate.'-31 00:00:00';
 
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>TarkashCorp| Admin Dashboard</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta content="A fully featured admin theme which can be used to build CRM, CMS, etc." name="description" />
    <meta content="Coderthemes" name="author" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <!-- App favicon -->
    <link rel="shortcut icon" href="images/favicon.png">

    <!-- App css -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/metismenu.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/style.css" rel="stylesheet" type="text/css" />
    
    <script src="assets/charts/amcharts.js"></script>
    <script src="assets/charts/serial.js"></script>
    <script src="assets/charts/pie.js"></script>
    <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
    <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
    <script src="https://www.amcharts.com/lib/3/themes/none.js"></script>

    <script src="assets/js/modernizr.min.js"></script>
    <script type="text/javascript">
    function graph_data1(str)
    { 
      if(str=='TOTAL')
      {
         document.getElementById('chartContainer1').style.display = 'block';
         document.getElementById('chartContainer2').style.display = 'none';
         document.getElementById('chartContainer3').style.display = 'none';
         document.getElementById('chartContainer5').style.display = 'none';
      }
      else if (str=='REG')
      {
         document.getElementById('chartContainer1').style.display = 'none';
         document.getElementById('chartContainer2').style.display = 'block';
        document.getElementById('chartContainer3').style.display = 'none';
        document.getElementById('chartContainer5').style.display = 'none';          
      }
      else
      {
         document.getElementById('chartContainer1').style.display = 'none';
         document.getElementById('chartContainer2').style.display = 'none';
         document.getElementById('chartContainer3').style.display = 'block';
        document.getElementById('chartContainer5').style.display = 'none';          
      }
    }
    
    function graph_data2()
    { 
         document.getElementById('chartContainer1').style.display = 'none';
        document.getElementById('chartContainer2').style.display = 'none';
         document.getElementById('chartContainer3').style.display = 'none';
        document.getElementById('chartContainer5').style.display = 'block';         
    }
   </script>
    
    <style>

    .amcharts-export-menu-top-right {
      top: 10px;
      right: 0; 
    }
    </style>
    
</head>
<?php if(!isset($_REQUEST['ZONE'])){?><body onl oad="menu2(); graph_data1('TRAN');"><?php } else { ?> <body onl oad="menu2(); graph_data2();"> <?php } ?>
<!-- Begin page --> 
 <div id="wrapper">

    <!-- Top Bar Start --> 
        <?php include('header.php');?>
    <!-- Top Bar End -->

    <!-- ========== Left Sidebar Start ========== -->
    <div class="left side-menu">
        <div class="slimscroll-menu" id="remove-scroll">

             <?php include('menu.php');?>
                
            <div class="clearfix"></div>

        </div>

    </div>
    <!-- Left Sidebar End -->

    <!-- ============================================================== -->
    <!-- Start right Content here -->
    <!-- ============================================================== -->
    <div class="content-page">
        <!-- Start content -->
        <div class="content">
            <div class="container-fluid">

                <div class="row">
                    <div class="col-12">
                        <div class="page-title-box">
                            <h4 class="page-title float-left">Graphical Representation</h4>

                            <ol class="breadcrumb float-right">
                                <li class="breadcrumb-item"><a href="dashboard.php">BTHawk</a></li>
                                <li class="breadcrumb-item active">Graphs</li>
                            </ol>

                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
                <!-- end row -->
               
                <div class="row">
                  <div class="col-md-12 card-box" style="padding-top:5; margin-top:0;">  
                    <div class="row">
                        <div class="col-md-10">
                            <h4 class="m-t-0 header-title">Select TYPE</h4> 
                            <select class="custom-select" name="totat_dist" onChange="graph_data1(this.value);">
                                <option value="TOTAL">TOTAL DISTRIBUTORS</option>  
                                <option value="REG">DISTRIBUTORS REG. THIS MONTH</option>
                                <option value="TRAN" Selected>TRANSACTING/NON-TRANSACTING</option> 
                            </select>
                        </div> 

                        <div class="col-md-2">
                            <h4 class="header-title">SELECTZONE</h4> 
                            <form method="GET">
                             <select class="custom-select" name="ZONE" oncha nge="this.form.submit()">
                        
                               <?php if(!isset($_GET['ZONE'])) { ?><option value="">SELECT ZONE</option><?php } 
                                $select_Total_Zones=mysqli_query($con,$select_zone_qry);
                                while($data_zone=mysqli_fetch_array($select_Total_Zones))
                                {  extract($data_zone);
                                ?>
                                  <option value="<?=$Zone?>" <?php if(isset($_GET['ZONE'])){ if($Zone==$_GET['ZONE']){ ?> SELECTED <?php } }?> ><?=$Zone;?></option>
                                <?php } ?> 
                               
                             </select>
                           </form>                             
                        </div>  
    
                         <div class="col-md-12" id="chartContainer1" style="height:370px;">
                          <script>
                              var chart = AmCharts.makeChart("chartContainer1", {
                              "type": "serial",
                              "theme": "light",
                              "marginRight": 80,
                              "dataProvider": [
                              
                              <?php
                              $i=1;
                              $select_Total_Zones=mysqli_query($con,$select_zone_qry);
                             $check_point=mysqli_num_rows($select_Total_Zones);                              
                              while($data_zone=mysqli_fetch_array($select_Total_Zones))
                              {  extract($data_zone);
                              ?>
                              {
                                "country": "<?=$Zone?>",
                                "visits": "<?php
                                             $select_total_dist=mysqli_query($con,"SEL ECT * FROM tbl_channel_partner,tbl_distributor,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WHERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND tbl_distributor_master.Zone='$Zone' group by tbl_distributor.distributor_name, tbl_distributor.TM_Name order by tbl_distributor.TM_Name");
                                             echo $count_total_dist=mysqli_num_rows($select_total_dist);
                                            ?>
                                          ",
                                "color": <?php if($i%2==0){?>"#FF0F00"<?php } else { ?> "#FF6600" <?php } ?>
                              }
                              <?php if($i<$check_point){ echo ","; } $i++; } ?>
                             
                              ],"depth3D": 13,"angle": 30,
                              "valueAxes": [{
                                "axisAlpha": 0,
                                "position": "left",
                                "title": "Total Distributors"
                              }],
                              "startDuration": 4,
                              "graphs": [{
                                "balloonText": "<b>[[category]]: [[value]]</b>",
                                "fillColorsField": "color",
                                "fillAlphas": 1,
                                "lineAlpha": 0.2,
                                "type": "column",
                                "valueField": "visits"
                              }],
                              "chartCursor": {
                                "categoryBalloonEnabled": true,
                                "cursorAlpha": 0,
                                "zoomable": true
                              },
                              "categoryField": "country",
                              "categoryAxis": {
                                "gridPosition": "start",
                                "labelRotation":0
                              },
                              "export": {
                                "enabled": true
                              }

                            });
                         </script>
                         </div>
                         
                         
                         <div class="col-md-12" id="chartContainer2" style="height:370px;">
                          <script>
                              var chart = AmCharts.makeChart("chartContainer2", {
                              "type": "serial",
                              "theme": "light",
                              "marginRight": 80,
                              "dataProvider": [
                              
                              <?php
                              $i=1;
                              $select_Total_Zones=mysqli_query($con,$select_zone_qry);
                             $check_point=mysqli_num_rows($select_Total_Zones);                              
                              while($data_zone=mysqli_fetch_array($select_Total_Zones))
                              {  extract($data_zone);
                              ?>
                              {
                                "country": "<?=$Zone?>",
                                "visits": "<?php
                                             $select_total_dist=mysqli_query($con,"SEL ECT * FR OM tbl_channel_partner,tbl_distributor,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WHERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND tbl_distributor_master.Zone='$Zone' AND (tbl_distributor.registration_datetime BETWEEN '$startdate' AND '$enddate') group by tbl_distributor.distributor_name, tbl_distributor.TM_Name order by tbl_distributor.TM_Name");
                                             echo $count_total_dist=mysqli_num_rows($select_total_dist);
                                            ?>
                                            ",
                                "color": <?php if($i%2==0){?>"#FF0F00"<?php } else { ?> "#FF6600" <?php } ?>
                              }
                              <?php if($i<$check_point){ echo ","; } $i++; } ?>
                              
                              ],"depth3D": 13,"angle": 30,
                              "valueAxes": [{
                                "axisAlpha": 0,
                                "position": "left",
                                "title": "Distributors Registed In This Month"
                              }],
                              "startDuration": 1,
                              "graphs": [{
                                "balloonText": "<b>[[category]]: [[value]]</b>",
                                "fillColorsField": "color",
                                "fillAlphas": 0.9,
                                "lineAlpha": 0.2,
                                "type": "column",
                                "valueField": "visits"
                              }],
                              "chartCursor": {
                                "categoryBalloonEnabled": true,
                                "cursorAlpha": 0,
                                "zoomable": true
                              },
                              "categoryField": "country",
                              "categoryAxis": {
                                "gridPosition": "start",
                                "labelRotation":0
                              },
                              "export": {
                                "enabled": true
                              }

                            });
                         </script>
                         </div>
                         
                         <?php
                         if(isset($_REQUEST['ZONE']))
                         {    
                         ?>
                         
                         <div class="col-md-12" id="chartContainer5" style="height:370px;">
                          <script>
                            var chart = AmCharts.makeChart( "chartContainer5", {
                              "type": "pie",
                              "theme": "light",
                              "dataProvider": [ {
                                "country": "NON-TRANSACTING",
                                "value": <?php 
                                          $Zone=$_REQUEST['ZONE'];
                                          $select_total_transacting_non=mysqli_query($con,"SELECT * FR OM tbl_distributor,tbl_channel_partner,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WHERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND ( NOT EXISTS (SEL ECT * FR OM tbl_party_transaction,tbl_user WHERE tbl_party_transaction.transaction_from=tbl_user.user_id AND tbl_distributor.distributor_id=tbl_user.distributor_id AND tbl_party_transaction.transaction_date='$date' )) AND tbl_channel_partner.partner_id='$user_id' AND tbl_distributor_master.Zone='$Zone' group by tbl_distributor_master.distributor_name, tbl_distributor_master.TM_Name order by tbl_distributor_master.TM_Name");
                                          echo $count_total_transacting_non=mysqli_num_rows($select_total_transacting_non);
                                         ?>
                              }, {
                                "country": "TRANSACTING",
                                "value": <?php 
                                          $Zone=$_REQUEST['ZONE']; 
                                          $select_total_transacting=mysqli_query($con,"select * fr om tbl_distributor, tbl_user, tbl_party_transaction,tbl_channel_partner,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WHERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_party_transaction.transaction_from=tbl_user.user_id AND tbl_user.distributor_id=tbl_distributor.distributor_id AND tbl_party_transaction.transaction_date='$date' AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND tbl_channel_partner.partner_id='$user_id' AND tbl_distributor_master.Zone='$Zone' group by tbl_distributor_master.distributor_name, tbl_distributor_master.TM_Name order by tbl_distributor_master.TM_Name"); 
                                          echo $count_total_transacting=mysqli_num_rows($select_total_transacting);
                                         ?>
                              } ],
                              "valueAxes": [{
                                "axisAlpha": 0,
                                "position": "left",
                                "title": "TRANSACTING/NON-TRANSACTING DISTRIBUTORS"
                              }],
                              "valueField": "value",
                              "titleField": "country",
                              "outlineAlpha": 0.4,
                              "depth3D": 15,
                              "balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
                              "angle": 30,
                              "export": {
                                "enabled": true
                              }
                            } );
                         </script>
                         </div>
                         
                         <?php } ?>
                         
                         <div class="col-md-12" id="chartContainer3" style="height:370px;">
                          <script>
                            var chart1= AmCharts.makeChart("chartContainer3", {
                              "type": "serial",
                              "theme": "light",
                              "marginTop": 50,
                              "marginBottom": 30,
                              "marginLeft": 30,
                              "marginRight": 30,
                              "autoMargins": false,
                              "color": "#6ab7f3",
                              "dataProvider": [
                              
                              <?php
                              $i=1;
                              $select_Total_Zones=mysqli_query($con,$select_zone_qry);
                             $check_point=mysqli_num_rows($select_Total_Zones);                              
                              while($data_zone=mysqli_fetch_array($select_Total_Zones))
                              {  extract($data_zone);
                              ?>
                              {
                                "category": "<?=$Zone?>",
                                "value1": "<?php
                                           $select_transacting=mysqli_query($con,"select * fr om tbl_distributor, tbl_user, tbl_party_transaction,tbl_channel_partner,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WHERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_party_transaction.transaction_date='$date' AND tbl_party_transaction.transaction_from=tbl_user.user_id AND tbl_user.distributor_id=tbl_distributor.distributor_id AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND tbl_channel_partner.partner_id='$user_id' AND tbl_distributor_master.Zone='$Zone' group by tbl_distributor.distributor_name, tbl_distributor.TM_Name order by tbl_distributor.TM_Name");
                                           echo $count_transacting=mysqli_num_rows($select_transacting);    
                                            ?>",
                                "value2": "<?php
                                           $select_transacting_non=mysqli_query($con,"SELECT * FR OM tbl_distributor,tbl_channel_partner,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WH ERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND ( NOT EXISTS (SELECT * FR OM tbl_party_transaction,tbl_user WH ERE tbl_party_transaction.transaction_from=tbl_user.user_id AND tbl_distributor.distributor_id=tbl_user.distributor_id AND tbl_party_transaction.transaction_date='$date')) AND tbl_channel_partner.partner_id='$user_id' AND tbl_distributor_master.Zone='$Zone' group by tbl_distributor.distributor_name, tbl_distributor.TM_Name order by tbl_distributor.TM_Name");
                                           echo $count_transacting_non=mysqli_num_rows($select_transacting_non);    
                                            ?>"
                              }
                              <?php if($i<$check_point){ echo ","; } $i++; } ?>
                              
                              ],
                              "graphs": [{
                                "lineColor": "#6ab7f3",
                                "title": "TRANSACTING",
                                "fillAlphas": 1,
                                "lineAlpha": 1,
                                "type": "column",
                                "valueField": "value1",
                                "balloonText": "[[title]]<br /><span style='font-size: 14px;'>[[value]] Distributor</span>"
                              }, {
                                "lineColor": "#736dba",
                                "title": "NON-TRANSACTING",
                                "fillAlphas": 1,
                                "lineAlpha": 1,
                                "type": "column",
                                "valueField": "value2",
                                "balloonText": "[[title]]<br /><span style='font-size: 14px;'>[[value]] Distributor</span>"
                              }],
                              "categoryField": "category",
                              "categoryAxis": {
                                "position": "top",
                                "gridAlpha": 0,
                                "axisAlpha": 0,
                                "color": "#aaa",
                                "tickLength": 0,
                                "guides": [
                                
                                <?php
                                  $i=1;
                                  $select_Total_Zones=mysqli_query($con,$select_zone_qry);
                                  $check_point=mysqli_num_rows($select_Total_Zones);                              
                                  while($data_zone=mysqli_fetch_array($select_Total_Zones))
                                  {  extract($data_zone);
                                ?>
                                {
                                  "label": "<?php
                                            $select_total_dist=mysqli_query($con,"SELECT * FR OM tbl_channel_partner,tbl_distributor,tbl_cp_dist_mapping,tbl_circle_master,tbl_distributor_master WH ERE tbl_channel_partner.partner_id=tbl_cp_dist_mapping.channel_partner_id AND tbl_cp_dist_mapping.distributor_id=tbl_distributor.distributor_id AND tbl_distributor.oid=tbl_distributor_master.oid AND tbl_distributor_master.circle_id=tbl_circle_master.circle_id AND tbl_distributor_master.Zone='$Zone' group by tbl_distributor.distributor_name, tbl_distributor.TM_Name order by tbl_distributor.TM_Name");
                                            echo $count_total_dist=mysqli_num_rows($select_total_dist);?>",
                                  "category": "<?=$Zone?>",
                                  "inside": true,
                                  "fontSize": 25,
                                  "color": "#6ab7f3"
                                }
                                <?php if($i<$check_point){ echo ","; } $i++; } ?>
                                
                                
                                ]
                              },
                              "valueAxes": [{
                                "stackType": "regular",
                                "axisAlpha": 0,
                                "gridAlpha": 0,
                                "labelsEnabled": false,
                                "maximum": 300
                              }],
                              "chartCursor": {
                                "fullWidth": true,
                                "cursorAlpha": 0.1,
                                "lineAlpha": 0.1,
                                "cursorColor": "#736dba",
                                "categoryBalloonColor": "#736dba"
                              },
                              "balloon": {
                                "adjustBorderColor": false,
                                "borderAlpha": 1,
                                "shadowAlpha": 0,
                                "borderThickness": 1,
                                "fillAlpha": 1,
                                "color": "#fff"
                              }
                            });
                          </script>
                         </div>
                         
                         
                    </div>
                  </div>                    
                </div>

            </div> <!-- content -->

            <footer class="footer text-right">
               2018 - 2019 © BTHawk - <a href="https://bthawk.belltechnology.in">bthawk.belltechnology.in</a>
            </footer>

        </div>
    </div>

        <!-- ============================================================== -->
        <!-- End Right content here -->
        <!-- ============================================================== -->
    </div>
<!-- END wrapper -->

<!-- jQuery  -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/metisMenu.min.js"></script>
<script src="assets/js/waves.js"></script>
<script src="assets/js/jquery.slimscroll.js"></script>

<!-- init dashboard -->
<script src="assets/pages/jquery.dashboard.init.js"></script>

<!-- Appjs -->
<script src="assets/js/jquery.core.js"></script>
<script src="assets/js/jquery.app.js"></script>

</body>
</html>