<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("loadGraphdetail", '
    $(document).ready(function() {
     var data_plot="";
        var table_id ="#tbl_graph_invoice_details";  
        var fromdate  = $("#invoice_datefrom_14").val();
        var todate  = $("#invoice_dateto_14").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/GetInvoiceDetail') . '",
                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_invoice_details tbody").on("click", "tr", function () {
            var data = table.row( this ).data();
            var month  = data[4];
            var year  = data[5];
            jQuery.ajax({
              "type"  : "post",
              "data"  : "month="+month+"&year="+year,
              "url"  : $("#liveSite").val()+"index.php?r=dashboard/InvoiceYear",
              "cache": false,
              "success":function(data){
                    $("#loader").hide();
                    $("#lead_info").html(data);
               }
            });
        } );
                       
        $(".dataTables_scrollFoot").hide(); 
    });', CClientScript::POS_HEAD);

$cs->registerScript("loadgraph", "    
    $(document).ready(function() {
    setTimeout(function() {
            var canvas1 =document.getElementById('current_year_invoice');
        Chart.defaults.global.responsive = true;
        var ctx = canvas1.getContext('2d');
        var pieChart = new Chart(ctx).Pie(".$plot.");
          }, 300);  
});", 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); 
//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="current_year_invoice" width="400" height="400"></canvas>
                </div>
            </div>
        </section>
    </div>
    <div class="col-lg-8">
        <input type="hidden" id="invoice_datefrom_14" name="invoice_datefrom_14" value="<?php echo $fromdate; ?>"/>
        <input type="hidden" id="invoice_dateto_14" name="invoice_dateto_14" value="<?php echo $todate; ?>"/>
        <table class="table table-hover table-bordered personal-task" id="tbl_graph_invoice_details">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Month</th>
                    <th>Invoice 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="quotes_month_owner_info"></div>
   