<?php
setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');


$manutencoesRealizadas = $this->data['manutencoesRealizadas'];
$servicosMaisRealizados = $this->data['servicosMaisRealizados'];

?>
<form action="<?php echo base_url(); ?>gestaoResultados/graficoMensal" method="post" name="formGraficoMensal"
      id="formAddPreventiva"
      class="floating-labels m-t-40">
    <div class="form-group col-lg-4">
        <select name="mesConsutal" id="mesConsutal" class="form-control" required>
            <option value=""></option>
            <option value="01">JANEIRO</option>
            <option value="02">FEVEREIRO</option>
            <option value="03">MARÇO</option>
            <option value="04">ABRIL</option>
            <option value="05">MAIO</option>
            <option value="06">JUNHO</option>
            <option value="07">JULHO</option>
            <option value="08">AGOSTO</option>
            <option value="09">SETEMBRO</option>
            <option value="10">OUTUBRO</option>
            <option value="11">NOVEMBRO</option>
            <option value="12">DEZEMBRO</option>
        </select>
        <!--    <span class="bar"></span>-->
        <label for="input1">Mês a ser Consultado <span style="color: red">*</span></label>
        <button type="submit" id="btnCadastarPedido" class="btn btn-success"><i class="fa fa-search"></i>
            consultar
        </button>
    </div>

</form>

<div class="row">
    <div class="col-lg-12 ">
        <div class="portlet ui-sortable">
            <div class="portlet-heading bg-info">
                <h3 class="portlet-title">
                    <span class="icon"><i class="fa fa-signal"></i></span> Vendas
                </h3>
                <div class="portlet-widgets">
                    <a data-toggle="collapse" data-target="#bg-primary1" aria-expanded="true"
                       aria-controls="#bg-primary1" class="">
                        <i class="fa fa-minus"></i>
                    </a>
                    <a href="#" data-toggle="remove"><i class="fa fa-close"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="bg-primary1" class="panel-collapse collapse show" aria-expanded="true" style="">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-block">
                            <div id="manutencoesPorPeriodo"
                                 style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="col-lg-12 ">
        <div class="portlet ui-sortable">
            <div class="portlet-heading bg-info">
                <h3 class="portlet-title">
                    <span class="icon"><i class="fa fa-signal"></i></span> Vendas por Vendedor(a)
                </h3>
                <div class="portlet-widgets">
                    <a data-toggle="collapse" data-target="#bg-primary1" aria-expanded="true"
                       aria-controls="#bg-primary1" class="">
                        <i class="fa fa-minus"></i>
                    </a>
                    <a href="#" data-toggle="remove"><i class="fa fa-close"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="bg-primary1" class="panel-collapse collapse show" aria-expanded="true" style="">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-block">
                            <div id="manutencoesRealizadas"
                                 style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="col-lg-12 ">
        <div class="portlet ui-sortable">
            <div class="portlet-heading bg-info">
                <h3 class="portlet-title">
                    <span class="icon"><i class="fa fa-signal"></i></span> Vendas
                </h3>
                <div class="portlet-widgets">
                    <a data-toggle="collapse" data-target="#bg-primary1" aria-expanded="true"
                       aria-controls="#bg-primary1" class="">
                        <i class="fa fa-minus"></i>
                    </a>
                    <a href="#" data-toggle="remove"><i class="fa fa-close"></i></a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="bg-primary1" class="panel-collapse collapse show" aria-expanded="true" style="">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-block">
                            <div id="servicosMaisRealizados"
                                 style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>




</div>


<script>
    var dadosCategoria = [<?php

        foreach ($manutencoesRealizadas as $a) {
            $tipo = $a->NM_VENDEDOR;
            echo '{
                name: "' . $tipo . '",
                y: ' . number_format($a->qtdeTipo, 2, '.', '') . '
            },';
        }
        ?>];
    Highcharts.chart('manutencoesRealizadas', {
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        title: {
            text: 'Vendas por Vendedor, <?php echo $mesConsultado.' de '.date('Y') ?>'
        },
        tooltip: {
//                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.y} - {point.percentage:.1f}%',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Brands',
            colorByPoint: true,
            data: dadosCategoria
        }]
    });
    //    })

</script>

<script>

    $(function () {

        var dadosCategoria = [<?php

            foreach ($servicosMaisRealizados as $a) {
                echo '{
                name: "' . $a->NM_PRODUTO . '",
                y: ' . $a->qtdeTipo . '
            },';
            }
            ?>];

        // Create the chart
        Highcharts.chart('servicosMaisRealizados', {
            chart: {
                type: 'column'
            },
            title: {
                text: 'Produtos + Vendidos'
            },
            subtitle: {
//                text: 'Click the columns to view versions. Source: <a href="http://netmarketshare.com">netmarketshare.com</a>.'
            },
            xAxis: {
                type: 'category'
            },
            yAxis: {
                title: {
//                    text: 'Total percent market share'
                }

            },
            credits: {
                enabled: false
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                series: {
                    borderWidth: 0,
                    dataLabels: {
                        enabled: true,
//                        format: '{point.y:.1f}%'
                    }
                }
            },
            series: [{
                name: 'Notificação',
                colorByPoint: true,
                data: dadosCategoria
            }]

        });

    });

</script>


<script>
    $(function () {
        var dadosCategoria = [<?php
            foreach ($vendasDiariasPorMes as $a) {
                echo "'" . date('d', strtotime($a->Periodo))  . "',";
            }
            ?>];
        var dadosPreventivas = [<?php
            foreach ($vendasDiariasPorMes as $a) {
                echo number_format($a->totalPreventiva, 2, '.', '') . ",";
            }
            ?>];

        var dadosCorretivas = [<?php
            foreach ($vendasDiariasPorMes as $a) {
                echo number_format($a->totalCorretiva, 2, '.', '') . ",";
            }
            ?>];


        Highcharts.chart('manutencoesPorPeriodo', {
            chart: {
                type: 'line'
            },
            title: {
                text: 'Vendas Diarias do Mês: <?php echo $mesConsultado.' de '.date('Y') ?>'
            },
            subtitle: {},
            xAxis: {
                categories: dadosCategoria
            },
            yAxis: {
                title: {
                    text: 'Vendas'
                }
            },
            plotOptions: {
                line: {
                    dataLabels: {
                        enabled: true
                    },
                    enableMouseTracking: false
                }
            },
            credits: {
                enabled: false
            },
            series: [{
                name: 'Valor Vendas',
                data: dadosPreventivas
            }, {
                name: 'Qtde Pedidos',
                data: dadosCorretivas
            }]
        });
    });
</script>

