<?php $__env->startSection('title'); ?>
Dashboard
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content-header'); ?>
Painel de instrumentos
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
    <div class="col-md-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">Relatório de Orçamentação</h3>

                <div class="box-tools pull-right">
                    <?php echo Form::select('filter-year', $yearsArr, $year, array('class' => 'form-control select2')); ?>

                </div>
            </div>

            
            <div class="box-body">
                <div class="row">
                    
                    <div class="col-md-8">
                        <p class="text-center">
                            <strong>Estatísticas mensais <?php echo $year; ?></strong>
                        </p>
                        <div class="chart">
                            <canvas id="salesChart" style="height: 180px; width: 100%;" width="100" height="180"></canvas>
                        </div>
                    </div>
                    
                    <div class="col-md-4">
                        
                        <p class="text-center">
                            <strong>Totais <?php echo $year; ?></strong>
                        </p>
                        
                        <?php foreach($statusTotals as $status): ?>
                        <div class="progress-group">
                            <span class="progress-text"><?php echo trans('dashboard.budgets.status.' . $status->status . '.text'); ?> (<?php echo money($status->price, '€'); ?>)</span>
                            <span class="progress-number"><b><?php echo $status->total; ?></b>/<?php echo $totals['budgetsCount']; ?></span>

                            <div class="progress sm">
                                <div class="progress-bar progress-bar-<?php echo trans('dashboard.budgets.status.' . $status->status . '.class'); ?>" style="width: <?php echo percent($totals['budgetsCount'], $status->total); ?>%"></div>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
            
            <div class="box-footer">
                <div class="row">
                    
                    <div class="col-sm-4 col-xs-6">
                        
                        <?php /* New Customers */ ?>
                        <div class="description-block border-right">
                             <?php if($variation['customers'] >= 0): ?>
                            <span class="description-percentage text-green" data-toggle="tooltip" title="Percentagem comparativamente ao ano anterior">
                                <i class="fa fa-caret-up"></i> <?php echo $variation['customers']; ?>%
                            </span>
                            <?php else: ?>
                            <span class="description-percentage text-red" data-toggle="tooltip" title="Percentagem comparativamente ao ano anterior">
                                <i class="fa fa-caret-down"></i> <?php echo $variation['customers'] * -1; ?>%
                            </span>
                            <?php endif; ?>
                            <h5 class="description-header"><?php echo $totals['customers']; ?></h5>
                            <span class="description-text">Clientes Novos</span>
                        </div>
                    </div>
                    
                    <?php /* Budgets Total */ ?>
                    <div class="col-sm-4 col-xs-6">
                        <div class="description-block border-right">
                           <?php if($variation['budgetsTotal'] >= 0): ?>
                            <span class="description-percentage text-green" data-toggle="tooltip" title="Percentagem comparativamente ao ano anterior">
                                <i class="fa fa-caret-up"></i> <?php echo $variation['budgetsTotal']; ?>%
                            </span>
                            <?php else: ?>
                            <span class="description-percentage text-red" data-toggle="tooltip" title="Percentagem comparativamente ao ano anterior">
                                <i class="fa fa-caret-down"></i> <?php echo $variation['budgetsTotal'] * -1; ?>%
                            </span>
                            <?php endif; ?>
                            <h5 class="description-header"><?php echo money($totals['budgetsTotal'], '€'); ?></h5>
                            <span class="description-text">Orçamentado em <?php echo $year; ?></span>
                        </div>
                    </div>
                    
                    <?php /* Budgets Count */ ?>
                    <div class="col-sm-4 col-xs-6">
                        <div class="description-block">
                            <?php if($variation['budgetsCount'] >= 0): ?>
                            <span class="description-percentage text-green" data-toggle="tooltip" title="Percentagem comparativamente ao ano anterior">
                                <i class="fa fa-caret-up"></i> <?php echo $variation['budgetsCount']; ?>%
                            </span>
                            <?php else: ?>
                            <span class="description-percentage text-red" data-toggle="tooltip" title="Percentagem comparativamente ao ano anterior">
                                <i class="fa fa-caret-down"></i> <?php echo $variation['budgetsCount'] * -1; ?>%
                            </span>
                            <?php endif; ?>
                            <h5 class="description-header"><?php echo $totals['budgetsCount']; ?></h5>
                            <span class="description-text">Orçamentos em <?php echo $year; ?></span>
                        </div>
                        <!-- /.description-block -->
                    </div>
                </div>
                <!-- /.row -->
            </div>
            <!-- /.box-footer -->
        </div>
        <!-- /.box -->
    </div>
    <!-- /.col -->
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script type="text/javascript">
    $(document).ready(function () {

        var salesChartCanvas = $("#salesChart").get(0).getContext("2d");
        
        // This will get the first returned node in the jQuery collection.
        var salesChart = new Chart(salesChartCanvas);
        var salesChartData = {
            labels: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
            datasets: [
                {
                    label: "Rejeitados",
                    fillColor: "#DD4B39",
                    strokeColor: "#DD4B39",
                    pointColor: "#DD4B39",
                    pointStrokeColor: "#fff",
                    pointHighlightFill: "#ba1705",
                    pointHighlightStroke: "#ba1705",
                    data: [<?php echo $budgetsChart['rejected']; ?>]
                },
                {
                    label: "Pendentes",
                    fillColor: "#F39C12",
                    strokeColor: "#F39C12",
                    pointColor: "#F39C12",
                    pointStrokeColor: "#fff",
                    pointHighlightFill: "#c67d0f",
                    pointHighlightStroke: "#c67d0f",
                    data: [<?php echo $budgetsChart['pending']; ?>]
                },
                {
                    label: "Aprovados",
                    fillColor: "#00A65A",
                    strokeColor: "#00A65A",
                    pointColor: "#00A65A",
                    pointStrokeColor: "#fff",
                    pointHighlightFill: "#008245",
                    pointHighlightStroke: "#008245",
                    data: [<?php echo $budgetsChart['approved']; ?>]
                },
            ]
        };
        var salesChartOptions = {
            //Boolean - If we should show the scale at all
            showScale: true,
            //Boolean - Whether grid lines are shown across the chart
            scaleShowGridLines: false,
            //String - Colour of the grid lines
            scaleGridLineColor: "rgba(0,0,0,.05)",
            //Number - Width of the grid lines
            scaleGridLineWidth: 1,
            //Boolean - Whether to show horizontal lines (except X axis)
            scaleShowHorizontalLines: true,
            //Boolean - Whether to show vertical lines (except Y axis)
            scaleShowVerticalLines: true,
            //Boolean - Whether the line is curved between points
            bezierCurve: true,
            //Number - Tension of the bezier curve between points
            bezierCurveTension: 0.3,
            //Boolean - Whether to show a dot for each point
            pointDot: true,
            //Number - Radius of each point dot in pixels
            pointDotRadius: 4,
            //Number - Pixel width of point dot stroke
            pointDotStrokeWidth: 1,
            //Number - amount extra to add to the radius to cater for hit detection outside the drawn point
            pointHitDetectionRadius: 20,
            //Boolean - Whether to show a stroke for datasets
            datasetStroke: true,
            //Number - Pixel width of dataset stroke
            datasetStrokeWidth: 2,
            //Boolean - Whether to fill the dataset with a color
            datasetFill: true,
            //String - A legend template
            legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].lineColor%>\"></span><%=datasets[i].label%></li><%}%></ul>",
            //Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
            maintainAspectRatio: true,
            //Boolean - whether to make the chart responsive to window resizing
            responsive: true
        };
        //Create the line chart
        salesChart.Line(salesChartData, salesChartOptions);
    });
    
    $(document).on('change','select[name=filter-year]', function(){
        var year = $(this).val();
        var url = updateURLParameter("<?php echo route('admin.home'); ?>", 'year', year);
        
        window.location = url
    })

</script>
<?php $__env->stopSection(); ?>