<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("loadGraphdetail", '
    $(document).ready(function() {
     var data_plot="";
        var table_id ="#tbl_graph_lead_details"; 
        var fromdate  = $("#invoice_datefrom_1").val();
        var todate  = $("#invoice_dateto_1").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/GetInvoiceOwnerDetail') . '",
                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 user_id  = data[1];
            
            jQuery.ajax({
              "type"  : "post",
              "data"  : "user_id="+user_id+"&fromdate="+fromdate+"&todate="+todate,
              "url"  : $("#liveSite").val()+"index.php?r=dashboard/invoiceGraphOwnerDetails",
              "cache": false,
              "success":function(data){
                    $("#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_ownr_1');
        Chart.defaults.global.responsive = true;
        var ctx = canvas1.getContext('2d');
        var pieChart = new Chart(ctx).Pie(".$plot.");
          }, 300);  
});", CClientScript::POS_HEAD);



?>
<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_ownr_1" width="400" height="400"></canvas>
                </div>
            </div>
        </section>
    </div>
    <div class="col-lg-8">
        <input type="hidden" id="invoice_datefrom_1" name="invoice_datefrom_1" value="<?php echo $fromdate; ?>"/>
        <input type="hidden" id="invoice_dateto_1" name="invoice_dateto_1" value="<?php echo $todate; ?>"/>
        <table class="table table-hover table-bordered personal-task" id="tbl_graph_lead_details">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Invoice Owner</th>
                    <th>Invoice Count</th>
                    <th>Amount</th>
                    <th></th><th></th>
                </tr>
            </thead>
            <!--<tfoot>
                <tr>
                    <th>No</th>
                    <th>Lead Owner</th>
                    <th>Lead Count</th>
                    <th></th><th></th>
                </tr>
            </tfoot>--!>
        </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("getMonthDetails",  "function getMonthDetails(month,year,ownerid){
    
         $('#loader').show();
            jQuery.ajax({
              'type'  : 'post',
              'data'  : 'month='+month+'&year='+year+'&ownerid='+ownerid,
              'url'  : $('#liveSite').val()+'index.php?r=dashboard/InvoiceGetMonthDetails',
              'cache': false,
              'success':function(data){
                $('#loader').hide();
                $('#lead_month_info').html(data);
                $('#quotes_month_owner_info').html('');    
               }
            });
        

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

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