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

//var_dump($gastosMensalPorManutencoes);


$manutencoesRealizadas = $this->data['manutencoesRealizadas'];
$servicosMaisRealizados = $this->data['servicosMaisRealizados'];
//$pecasMaisUsadas = $this->data['pecasMaisUsadas'];
$gastosMensalPorManutencoes = $this->data['gastosMensalPorManutencoes'] ;
$gastosMensalPorManutencoesAnoCorrente = $this->data['gastosMensalPorManutencoesAnoCorrente'] ;


//$servicosPorPeriodo = $this->data['servicosPorPeriodo'] ;
//$pecasPorPeriodo = $this->data['pecasPorPeriodo'] ;
//$lancamentosMaiorPorValor = $this->data['lancamentosMaiorPorValor'];
//
//$gastosElevadorr = $this->data['gastosElevadorr'];
//$gastosManutencao = $this->data['gastosManutencao'];
//$notificacaoMaior = $this->data['notificacaoMaior'];
//$ocorrenciasMaior = $this->data['ocorrenciasMaior'];
//
//$gastosLuzAnual = $this->data['gastosLuzAnual'];
//$gastosGasAnual = $this->data['gastosGasAnual'];
//foreach($lancamentosMaior as $p){
//    echo $p->categoria.'-'.$p->valorCategorias;
//}
?>

<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 por Vendedor
                </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="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
                </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="manutencoesPorPeriodoPeloAnoAtual"
                                 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: <? echo 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 ($pecasMaisUsadas as $a) {
                echo "'" . $a->DS_DESCRICAO_PECA . "',";
            }
            ?>];
        var dadosGrafico = [<?php
            foreach ($pecasMaisUsadas as $a) {
                echo $a->qtdeTipo . ",";
            }
            ?>];


        Highcharts.chart('pecasMaisUsadas', {


            chart: {
                type: 'bar'
            },
            title: {
                text: 'Peças + utilizadas'
            },
            subtitle: {},
            xAxis: {

                categories: dadosCategoria,
                title: {
                    text: null
                }
            },
            yAxis: {},
            legend: {
                x: -40,
                y: 80,
            },

            plotOptions: {
                bar: {
                    dataLabels: {
                        enabled: true
                    }
                }
            },

            credits: {
                enabled: false
            },
            series: [{
//            colorByPoint: true,
                data: dadosGrafico
            }]
        });
    });

</script>

<script>
    $(function () {
        var dadosCategoria = [<?php
            foreach ($gastosMensalPorManutencoes as $a) {
                echo "'" . strftime('%b/%y', strtotime($a->Periodo))  . "',";
            }
            ?>];
        var dadosPreventivas = [<?php
            foreach ($gastosMensalPorManutencoes as $a) {
                echo number_format($a->totalPreventiva, 2, '.', '') . ",";
            }
            ?>];

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


        Highcharts.chart('manutencoesPorPeriodo', {
            chart: {
                type: 'line'
            },
            title: {
                text: 'Vendas nos últimos 12 MESES por Valor e Qtde Pedidos'
            },
            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>

<script>
    $(function () {
        var dadosCategoria = [<?php
            foreach ($gastosMensalPorManutencoesAnoCorrente as $a) {
                echo "'" . strftime('%b/%y', strtotime($a->Periodo))  . "',";
            }
            ?>];
        var dadosPreventivas = [<?php
            foreach ($gastosMensalPorManutencoesAnoCorrente as $a) {
                echo number_format($a->totalPreventiva, 2, '.', '') . ",";
            }
            ?>];

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


        Highcharts.chart('manutencoesPorPeriodoPeloAnoAtual', {
            chart: {
                type: 'line'
            },
            title: {
                text: 'Vendas no ano de <? echo date('Y')?> por Valor e Qtde Pedidos'
            },
            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>

<script>
    $(function () {
        var dadosCategoria = [<?php
            foreach ($gastosMensalPorManutencoes as $a) {
                echo "'" . strftime('%b/%y', strtotime($a->Periodo))  . "',";
            }
            ?>];
        var servicosPorPeriodo = [<?php
            foreach ($servicosPorPeriodo as $a) {
                echo number_format($a->totalServicos, 2, '.', '') . ",";
            }
            ?>];


        Highcharts.chart('servicosPorPeriodo', {
            chart: {
                type: 'line'
            },
            title: {
                text: 'Valor de Vendas por Período'
            },
            subtitle: {},
            xAxis: {
                categories: dadosCategoria
            },
            yAxis: {
                title: {
                    text: 'Manutenções'
                }
            },
            plotOptions: {
                line: {
                    dataLabels: {
                        enabled: true
                    },
                    enableMouseTracking: false
                }
            },
            credits: {
                enabled: false
            },
            series: [{
                name: 'Vendas Realizados',
                data: servicosPorPeriodo
            }]
        });
    });
</script>

<script>
    $(function () {
        var dadosCategoria = [<?php
            foreach ($gastosMensalPorManutencoes as $a) {
                echo "'" . strftime('%b', strtotime($a->Periodo))  . "',";
            }
            ?>];
        var pecasPorPeriodo = [<?php
            foreach ($pecasPorPeriodo as $a) {
                echo number_format($a->totalPecas, 2, '.', '') . ",";
            }
            ?>];


        Highcharts.chart('pecasPorPeriodo', {
            chart: {
                type: 'line'
            },
            title: {
                text: 'Quantidade de Vendas por Período'
            },
            subtitle: {},
            xAxis: {
                categories: dadosCategoria
            },
            yAxis: {
                title: {
                    text: 'Vendas'
                }
            },
            plotOptions: {
                line: {
                    dataLabels: {
                        enabled: true
                    },
                    enableMouseTracking: false
                }
            },
            credits: {
                enabled: false
            },
            series: [{
                name: 'Vendas',
                data: pecasPorPeriodo
            }]
        });
    });
</script>