<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("loadGraphdetail", '
    $(document).ready(function() {
     var data_plot="";
        var table_id ="#tbl_graph_lead_details"; 
        var fromdate  = $("#start_date_6").val();
        var todate  = $("#end_date_6").val();
        var table = $(table_id).DataTable({
            //scrollY         : "380px",
           // scrollX         : "true",
           // scrollCollapse  : true,
            //pageLength      : 50,
            paging:   false,
            ordering: false,
            info:     false,
            processing: true,
            ajax: {
                url: "' . Yii::app()->createUrl('dashboard/GetQuotesSalesGroupDetail') . '",
                type: "POST",
                data : {fromdate:fromdate,todate:todate},
                cache : false,
                complete:function(response){
                    data_plot=JSON.parse(response.responseText).plot;                
               }                            
            },
            columns: [
                {className: ""},
                {className: ""},
                {className: ""},
                {className: "text-right"},
                {className: ""},
                {className: ""},
            ],
            "columnDefs": [            
            {
                "targets": [ 4 ],
                "visible": false
            },
            {
                "targets": [ 5 ],
                "visible": false
            }
            ],
            
            serverSide:     true,
            bFilter: false,
            fixedColumns:   true,
			processing: true,
            fixedHeader: {
                headerOffset: $("header.main").outerHeight()
            },
//            rowCallback: function ( row, data){          
//                $("td", row).css("background-color",""+data[3]+"");
//              
//            },        
        });
        
        $("#tbl_graph_lead_details tbody").on("click", "tr", function () {
            var data = table.row( this ).data();
            var group_id  = data[5];
            //$("#loader").show();
            //alert(country_id);
            jQuery.ajax({
              "type"  : "post",
              "data"  : "group_id="+group_id+"&fromdate="+fromdate+"&todate="+todate,
              "url"  : $("#liveSite").val()+"index.php?r=dashboard/QuoteGraphSalesGroupDetails",
              "cache": false,
              "success":function(data){
                    $("#loader").hide();
                    $("#lead_info").html(data);
                    $("#lead_month_info").html("");
                    $("#quotes_month_owner_info").html("");
               }
            });
        } );
                       
        $(".dataTables_scrollFoot").hide(); 
    });', CClientScript::POS_HEAD);
//$cs->registerScript("loadgraph", "function loadgraph(data_plot){
//    alert(data_plot);
//    setTimeout(function() {
//                    $('#lead_container_1').html('<canvas id=\"lead_ownr_1\" width=\"400\" height=\"400\"></canvas>');
//                        var canvas1 =document.getElementById('lead_ownr_1');
//                    Chart.defaults.global.responsive = true;
//                    var ctx = canvas1.getContext('2d');
//                    var pieChart = new Chart(ctx).Pie(data_plot);
//                        alert(pieChart);
//                      }, 300);  
//};", CClientScript::POS_HEAD); */
$cs->registerScript("loadgraph", "    
    $(document).ready(function() {
    setTimeout(function() {
            var canvas1 =document.getElementById('lead_country_1');
        Chart.defaults.global.responsive = true;
        var ctx = canvas1.getContext('2d');
        var pieChart = new Chart(ctx).Pie(".$plot.");
          }, 300);  
});", CClientScript::POS_HEAD); 

//print_r($plot);
?>
<div class="clearfix"></div>
<br>
<div class="clearfix">
    <div class="col-lg-4" data-initial-class="col-lg-4" id="pieChartParent">
        <section class="panel">
<!--            <header class="panel-heading">
                  Lead- Lead Owner
            </header>-->
            <div class="panel-body text-center">
                <div class="clearfix canvas-holder" id="lead_container_1">
                    <canvas id="lead_country_1" width="400" height="400"></canvas>
                </div>
            </div>
        </section>
    </div>
    <div class="col-lg-8">
         <input type="hidden" id="start_date_6" value="<?php echo $from_date; ?>">
        <input type="hidden" id="end_date_6" value="<?php echo $end_date; ?>">
        <table class="table table-hover table-bordered personal-task" id="tbl_graph_lead_details">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Sales Group Name</th>
                    <th>Quotes Count</th>
                    <th>Amount</th>
                    <th></th><th></th>
                </tr>
            </thead>
            
        </table>
    </div>
    <div class="col-lg-12" id="lead_info"></div>
    <div class="col-lg-12" id="lead_month_info"></div>
    <div class="col-lg-12" id="quotes_month_owner_info"></div>
<?php

$cs->registerScript("getquoteSalesMonthDetails",  "function getquoteSalesMonthDetails(month,year,group_id){
    
        $('#loader').show();
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'month='+month+'&year='+year+'&group_id='+group_id,
              'url'  : $('#liveSite').val()+'index.php?r=dashboard/QuoteSalesMonthDetails',
              'cache': false,
              'success':function(data){
                $('#loader').hide();
                $('#lead_month_info').html(data);
                $('#quotes_month_owner_info').html('');
               }
            });
        

   
};", CClientScript::POS_HEAD); 
$cs->registerScript("getQuotesOwnerMonthDetails",  "function getQuotesOwnerMonthDetails(quotesid){
    
         $('#loader').show();
         //alert(month+' = '+year+' = '+quotesid);
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'quotesid='+quotesid,
              'url'  : $('#liveSite').val()+'index.php?r=dashboard/Quotation_items',
              'cache': false,
              'success':function(data){
                $('#loader').hide();
                $('#quotes_month_owner_info').html(data);
               }
            });
        

   
};", CClientScript::POS_HEAD);
?>
