<?php include("_config/dbconfig.php"); ?>
<?php include("_includes/head.php"); ?>
<title>Graph </title>

<style>
    .table-bordered > thead > tr > th, .table-bordered > thead > tr > td, .table-bordered  tr  td {
        border-width: 1px !important; 
        border: 1px solid #676767 !important;
    }
</style>

<?php
include("_includes/header.php");

if (isset($_SESSION['user_session'])) {
    $agent_id = $_SESSION['user_session'];
} else {    $agent_id = 0;  }


$ee = explode("/", $_SERVER["PHP_SELF"]);
$link = end($ee) . '?' . $_SERVER["QUERY_STRING"];

$StartDate = "";
$EndDate = "";
    
if(isset($_POST['search_submit'])){ 
    $StartDate = $_POST['eventStartDate'];
    $EndDate = $_POST['eventEndDate'];
    
    $events_ = $obj_events_class->getEventByDate($StartDate, $EndDate,$agent_id);
    
    
    if(count($events_)){
        $ids = implode(',', $events_);
        $AssignClients = $obj_jobs_class->getAssignClientsByEveIds($ids, $agent_id);
        $graph_title = $obj_jobs_class->change_date2($StartDate)." to ".$obj_jobs_class->change_date2($EndDate);
    }
}
        

if (isset($_SESSION['user_session'])) {
    $agent_id = $_SESSION['user_session'];
} else {    $agent_id = 0;  }

$event_all = $obj_events_class->getEvent();

if (isset($_GET['event']) && !empty($_GET['event'])) {

    $exhibition_id = base64_decode($_GET['event']);
    $event = $obj_events_class->getEvent($exhibition_id);
    $AssignClients = $obj_jobs_class->getAssignClients($exhibition_id, $agent_id);
    /*echo '<pre>';print_r($AssignClients); echo '</pre>';       */
} else {
    /*echo "<script>window.location='events.php'</script>";
    die();*/
}
    $modal = '';
?>
<div class="col-sm-12 right_form">
    <div class="title"> 
        <h1><?php  
                    if(isset($event['event_name'])){
                        echo $event['event_name']; 
                    }else {
                        echo "Graph";
                    }
                
                ?>  
            <p class="date_d">
                <?php
                if (!empty($event['start_date']))
                    echo $obj_jobs_class->change_date2($event['start_date']);
                if (!empty($event['end_date']))
                    echo ' to ' . $obj_jobs_class->change_date2($event['end_date']);
                ?> 
            </p>
        </h1>
    </div>
    <ol class="breadcrumb white">
        <li><a href="dashboard.php">Dashboard</a></li>
        <li><a href="events.php">Exhibitions</a></li>
        <li class="active">Create Graph by Exhibition Dates</li>
        
        <li class="right"><a href="event_graph.php">Create Graph by Exhibitions</a></li>
    </ol>
  
    <div class="col-sm-12 a_client"> 
        <div class="row">  
            
                <div class="col-sm-2 col-xs-2 form-group" >
                    <label>Select Exhibition By Date</label>       
                     
                </div>
            <form action="" method="POST" id="_form">    
            <div class="col-sm-2 col-xs-2 form-group">
                <input type="text" autocomplete="off" onkeydown="return false;" id="start_date1" class="form-control" required="required" name="eventStartDate" placeholder="from" value="<?= $StartDate ?>" />
            </div>
            <div class="col-sm-2 col-xs-2 form-group">
            <input type="text"  value="<?= $EndDate ?>" autocomplete="off" onkeydown="return false;" id="end_date1" class="form-control date " required="required" name="eventEndDate" placeholder="to" />
                
            </div>
                      <div class="col-sm-1 col-xs-1 form-group">
                          <input type="submit" value="submit" name="search_submit" class="btn btn-default" >
                          
                    </div>
                
                </form>
            
            
            <div class="col-sm-12">

                <div class="table-result table-responsive">   
                    <?php
                    
                    $count_comp = 0;  $count_deny = 0;  $count_pip= 0; $count_pen = 0;
                    $count_hot = 0;  $count_warm= 0;  $count_cold= 0; 

 if (isset($AssignClients) && count($AssignClients)>0) {
                    foreach($AssignClients as $a_client){
                        
                        if($a_client['status_order'] == 1){$count_comp +=1;}
                        else if($a_client['status_order'] ==  0){$count_deny +=1;}
                        else if($a_client['status_order'] ==  4){$count_pip +=1;}
                        else if($a_client['status_order'] ==  2){$count_pen +=1;}

                        if($a_client['pipeline']==80 && $a_client['status_order']==4 ){ $count_hot+=1;};
                        if($a_client['pipeline']==50 && $a_client['status_order']==4){ $count_cold+=1;}; 
                        if($a_client['pipeline']==10 && $a_client['status_order']==4) { $count_warm+=1;};
                    }
                    
    ?>
                        <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto;"></div>                    
<?php                    
 
 
 
 $msg = " Total Clients: ".count($AssignClients);
 $msg .= "<br> Pending Clients: ".$count_pen;
 $msg .= "<br> Accepted Clients: ".$count_comp;
 $msg .= "<br> Denied Clients: ".$count_deny;
 $msg .= "<br> Hot Clients: ".$count_hot;
 $msg .= "<br> Warm Clients: ".$count_warm;
 $msg .= "<br> Cold Clients: ".$count_cold;
 
?>
                        <div id="" style="position: absolute; left: 50px; top: 20px; font-weight: 600; line-height: 30px; font-size: 12px;">
                            <?php echo $msg;?>
                        </div>
 <?php } else if(isset($_POST['search_submit'])){
                        echo "No exhibition found. ";
            
 }else { echo "Select Start & End Date. "; }?>
                </div>
            </div>
        </div>
    </div>	

</div>


<?php include("_includes/footer.php"); ?>
<script type="text/javascript">
$(function () {
    
     $("#start_date1").datepicker({
            dateFormat: 'mm/dd/yy',
            numberOfMonths: 1,
            onSelect: function(selected) {
              $("#end_date1").datepicker("option","minDate", selected)
            }
        });
        $("#end_date1").datepicker({
            dateFormat: 'mm/dd/yy',
            numberOfMonths: 1,
            onSelect: function(selected) {
               // $("#start_date1").datepicker("option","maxDate", selected)
            }
        });   
    })
</script>        

<?php  if (isset($AssignClients) && count($AssignClients)>0) { ?>
<script type="text/javascript">        
$(function () {        
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        title: {
            text: '<?php echo $graph_title; ?>'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            name: 'Clients',
            colorByPoint: true,
            data: [{
                name: 'Pending',
                y: <?php echo ($count_pen/count($AssignClients)*100);?>
            }, {
                name: 'Accepted',
                y: <?php echo ($count_comp/count($AssignClients)*100);?>
            }, {
                name: 'Denied',
                y: <?php echo ($count_deny/count($AssignClients)*100);?>,
                sliced: true,
                selected: true
            }, {
                name: 'Hot',
                y: <?php echo ($count_hot/count($AssignClients)*100);?>
            }, {
                name: 'Warm',
                y: <?php echo ($count_warm/count($AssignClients)*100);?>
            }, {
                name: 'Cold',
                y: <?php echo ($count_cold/count($AssignClients)*100);?>
            }]
        }]
    });
});
		</script>
                
                
<script src="js/highcharts.js"></script>
<script src="js/exporting.js"></script>

<script>

    function goEvent(){
        vv = $("#exi_id").val();
        window.location = 'event_graph.php?event='+vv+'&1=1';        
        
    }


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


 

</script>

<?php } ?>
<script>
    $(document).ready(function () {
        $(".start_date").datepicker({
            dateFormat: 'yy-mm-dd',
            numberOfMonths: 1,
            onSelect: function (selected) {
                $(".end_date").datepicker("option", "minDate", selected)
            }
        });
        $(".end_date").datepicker({
            dateFormat: 'yy-mm-dd',
            numberOfMonths: 1,
            onSelect: function (selected) {
                //$("#start_date").datepicker("option","maxDate", selected)
            }
        });
    });
</script>