<?php
 
  
    $query = 'SELECT G.brand AS brand, G.stock_value AS stock_value FROM (SELECT
            B.product_class AS brand,
            SUM(SL.quantity) * S.rate AS stock_value
            FROM {{stock_ledger}} SL LEFT JOIN {{store}} S ON S.id = SL.product_id
            LEFT JOIN {{product_class}} B ON S.brand_class_id = B.id GROUP BY S.id ) AS G GROUP BY G.brand';
    $graphdata4 = Yii::app()->db->createCommand($query)->queryAll();
    
        $plot = '[';
        foreach($graphdata4 as $eachdata ){
            $color = substr(md5(rand()), 0, 6);
            $plot .= '{label:"'.$eachdata['brand'].'", value:'.$eachdata['stock_value'].', color: "#'.$color.'"},';
        }
        $plot .= ']';
     
?>
<div class="clearfix"></div>
<br>
<div class="clearfix">
    
        <div class="col-lg-4" data-initial-class="col-lg-3" id="pieChartParent">
        <section class="panel">
            <header class="panel-heading">
               Current stock
            </header>
            <div class="panel-body text-center">
                <div class="clearfix canvas-holder">
                    <canvas id="current_stk" width="400" height="400" onclick="loadPopupModal('dashboard/current_stock_details','Current Stock','lg');"></canvas>
                </div>
            </div>
        </section>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        var order_data5=<?php echo $plot;?>;
        var canvas1 =document.getElementById("current_stk");
        Chart.defaults.global.responsive = true;
        var ctx = canvas1.getContext("2d");
        var pieChart = new Chart(ctx).Pie(order_data5);
    });

    
</script>






