<?php $meta['styles']['local']['morris']                    = 'morris/morris.css';
    $meta['scripts']['local']['morris']                   = 'plugins/morris/morris.min.js';
    $meta['scripts']['remote']['raphael']                 = '//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js';
    /*$meta['styles']['local']['jvectormap']                = 'jvectormap/jquery-jvectormap-1.2.2.css';
    $meta['styles']['local']['datepicker3']               = 'datepicker/datepicker3.css';
    $meta['styles']['local']['daterangepicker']           = 'daterangepicker/daterangepicker-bs3.css';
    $meta['styles']['local']['wysihtml5']                 = 'bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css';

    //$meta['scripts']['remote']['jquery_ui']               = '//code.jquery.com/ui/1.11.1/jquery-ui.min.js';
    $meta['scripts']['local']['sparkline']                = 'plugins/sparkline/jquery.sparkline.min.js';
    $meta['scripts']['local']['jvectormap']               = 'plugins/jvectormap/jquery-jvectormap-1.2.2.min.js';
    $meta['scripts']['local']['jvectormap_world_mill_en'] = 'plugins/jvectormap/jquery-jvectormap-world-mill-en.js';
    $meta['scripts']['local']['knob']                     = 'plugins/jqueryKnob/jquery.knob.js';
    $meta['scripts']['local']['daterangepicker']          = 'plugins/daterangepicker/daterangepicker.js';
    $meta['scripts']['local']['datepicker']               = 'plugins/datepicker/bootstrap-datepicker.js';
    $meta['scripts']['local']['wysihtml5']                = 'plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js';
    $meta['scripts']['local']['icheck']                   = 'plugins/iCheck/icheck.min.js';*/
    //$meta['scripts']['local']['dashboard']                = 'AdminLTE/dashboard.js';

    $meta['scripts']['local']['moment']       = 'moment.js';

    $meta['scripts']['local']['datetimepicker'] = 'bootstrap-datetimepicker.min.js';
    $meta['styles']['local']['datetimepicker']  = 'bootstrap-datetimepicker.min.css';
    array_unshift($meta['scripts']['raw'], '
        $(".date").datetimepicker();
    '); ?>
<?php $meta['scripts']['raw']['chart'] = "
$(document).ready(function() {
    /*var chartStatus = new Morris.Donut({
        element: 'chart-status',
        resize: true,
        colors: ['gray', '#3c8dbc', '#00a65a', '#f56954'],
        data: [
            {label: 'Carregando', value: null },
        ],
        hideHover: 'auto'
    });*/

    var chartLocacoes = new Morris.Area({
        element: 'chart-locacoes',
        resize: true,
        data: [],
        xkey: 'date',
        ykeys: ['R', 'A', 'F', 'C'],
        labels: ['Reservas', 'Abertos', 'Faturados', 'Cancelados'],
        lineColors: ['gray', '#3c8dbc', '#00a65a', '#f56954'],
        hideHover: 'auto',
        xLabels: 'week',
        dateFormat: function(x) { x = new Date(x); return x.getDate()+'/'+(x.getMonth()+1)+'/'+x.getFullYear(); },
        xLabelFormat: function(x) { return x.getDate()+'/'+(x.getMonth()+1)+'/'+x.getFullYear(); },
        yLabelFormat: function(y){ return y != Math.round(y) ? '' : y }
    });
    
    var chartLocacoesVeiculos = new Morris.Bar({
        element: 'chart-locacoes-veiculos',
        resize: true,
        data: [],
        xkey: 'y',
        ykeys: ['R', 'A', 'F', 'C'],
        labels: ['Reservas', 'Abertos', 'Faturados', 'Cancelados'],
        barColors: ['gray', '#3c8dbc', '#00a65a', '#f56954'],
        hideHover: 'auto',
        stacked: true,
        horizontal: true,
        yLabelFormat: function(y){ return y != Math.round(y) ? '' : y }
    });

    var chartFaturamento = new Morris.Line({
        element: 'chart-faturamento',
        resize: true,
        data: [],
        xkey: 'data',
        ykeys: ['receita', 'despesa'],
        labels: ['Receita', 'Despesas'],
        lineColors: ['#00a65a', '#f56954'],
        hideHover: 'auto',
        xLabels: 'week',
        dateFormat: function(x) { x = new Date(x); return x.getDate()+'/'+(x.getMonth()+1)+'/'+x.getFullYear(); },
        xLabelFormat: function(x) { return x.getDate()+'/'+(x.getMonth()+1)+'/'+x.getFullYear(); },
        yLabelFormat: function(y){ return 'R$ ' + parseFloat(y).toFixed(2).replace('.', ',') }
    });
    
    var chartFaturamentoVeiculos = new Morris.Bar({
        element: 'chart-faturamento-veiculos',
        resize: true,
        data: [],
        xkey: 'veiculo',
        ykeys: ['receita', 'despesa'],
        labels: ['Receita', 'Despesa'],
        barColors: ['#00a65a', '#f56954'],
        hideHover: 'auto',
        stacked: false,
        horizontal: true,
        yLabelFormat: function(y){ return 'R$ ' + parseFloat(y).toFixed(2).replace('.', ',') }
    });

    function _refreshChart() {
        $.getJSON(
            '".$BASE.\Base::instance()->alias('softsat_locacao_admin_api_chart')."', 
            {de: $('#chart_de').val(), ate: $('#chart_ate').val()}, 
            function(resp) {
                if(!resp.data)
                    return;

                for(var key in resp.data.status)
                    $('#chart-status-' + key).text(resp.data.status[key]);

                //chartStatus.setData(resp.data.status.length ? resp.data.status : [{label: 'Sem dados'}]);
                chartLocacoes.setData(resp.data.locacoes.length ? resp.data.locacoes : [{date: null}]);
                chartLocacoesVeiculos.setData(resp.data.locacoes_veiculos.length ? resp.data.locacoes_veiculos : [{y: ''}]);
                chartFaturamento.setData(resp.data.faturamento.length ? resp.data.faturamento : [{data: null}]);
                chartFaturamentoVeiculos.setData(resp.data.faturamento_veiculos.length ? resp.data.faturamento_veiculos : [{data: null}]);
            }
        );
    }

    $('.date').on('dp.change', _refreshChart);
    $('.date input').keydown(function(evt) {
        if(evt.keyCode == 13)
        _refreshChart();
    });
    _refreshChart();
});"; ?>

<?php echo $this->render('hwapx/admin/admin/header.html',NULL,get_defined_vars(),0); ?>

<?php if (\Hwapx\Core\Library\ModuleManager::instance()->hasRole('softsat.locacao.grafico')): ?>
<div class="row">
<?php if(\Base::instance()->exists('__place.dashboard')) echo implode(PHP_EOL, \Base::instance()->get('__place.dashboard')) ?>
</div>
<?php endif; ?>


<?php echo $this->render('hwapx/admin/admin/footer.html',NULL,get_defined_vars(),0); ?>