<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<section class="content-header">
    <h1><i class="fa fa-bar-chart"></i> Relatório BPO Financeiro</h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo site_url('admin/financeiro/bpo')?>"><i class="fa fa-university"></i> BPO</a></li>
        <li class="active">Relatório Gerencial</li>
    </ol>
</section>
<section class="content">

<div class="box box-default">
    <div class="box-body">
        <form method="get" class="form-inline">
            <div class="form-group" style="margin-right:10px">
                <label>De</label>
                <input type="date" name="data_ini" class="form-control" value="<?php echo $data_ini?>">
            </div>
            <div class="form-group" style="margin-right:10px">
                <label>Até</label>
                <input type="date" name="data_fim" class="form-control" value="<?php echo $data_fim?>">
            </div>
            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> Gerar</button>
        </form>
    </div>
</div>

<div class="box">
    <div class="box-header with-border" style="background:#1a659e;color:#fff">
        <h3 class="box-title" style="color:#fff">
            <i class="fa fa-table"></i> Período: <?php echo date('d/m/Y',strtotime($data_ini))?> a <?php echo date('d/m/Y',strtotime($data_fim))?>
        </h3>
    </div>
    <div class="box-body no-padding">
        <table class="table table-bordered table-striped table-hover" id="tbl-rel">
            <thead>
                <tr style="background:#f4f4f4">
                    <th>Cliente</th>
                    <th class="text-center">Processos</th>
                    <th class="text-right">Honorários Total</th>
                    <th class="text-right text-success">Recebidos</th>
                    <th class="text-right text-warning">Pendentes</th>
                    <th class="text-right text-danger">Vencidos</th>
                    <th class="text-center">Situação</th>
                </tr>
            </thead>
            <tbody>
            <?php
            $g_total=$g_rec=$g_pend=$g_venc=$g_proc=0;
            foreach($relatorio as $r):
                $g_total+=(float)$r->honorarios_total;
                $g_rec+=(float)$r->honorarios_recebidos;
                $g_pend+=(float)$r->honorarios_pendentes;
                $g_venc+=(float)$r->honorarios_vencidos;
                $g_proc+=(int)$r->total_processos;
                $sit = (float)$r->honorarios_vencidos>0?'danger':((float)$r->honorarios_pendentes>0?'warning':'success');
                $sit_text = (float)$r->honorarios_vencidos>0?'Vencido':((float)$r->honorarios_pendentes>0?'Pendente':'Em dia');
            ?>
            <tr>
                <td><strong><?php echo htmlspecialchars($r->cliente)?></strong></td>
                <td class="text-center"><?php echo (int)$r->total_processos?></td>
                <td class="text-right">R$ <?php echo number_format($r->honorarios_total,2,',','.')?></td>
                <td class="text-right text-success">R$ <?php echo number_format($r->honorarios_recebidos,2,',','.')?></td>
                <td class="text-right text-warning">R$ <?php echo number_format($r->honorarios_pendentes,2,',','.')?></td>
                <td class="text-right <?php echo (float)$r->honorarios_vencidos>0?'text-danger':''?>">
                    <strong>R$ <?php echo number_format($r->honorarios_vencidos,2,',','.')?></strong>
                </td>
                <td class="text-center">
                    <span class="label label-<?php echo $sit?>"><?php echo $sit_text?></span>
                </td>
            </tr>
            <?php endforeach; ?>
            </tbody>
            <tfoot>
                <tr style="background:#f4f4f4;font-weight:bold">
                    <td>TOTAIS</td>
                    <td class="text-center"><?php echo $g_proc?></td>
                    <td class="text-right">R$ <?php echo number_format($g_total,2,',','.')?></td>
                    <td class="text-right text-success">R$ <?php echo number_format($g_rec,2,',','.')?></td>
                    <td class="text-right text-warning">R$ <?php echo number_format($g_pend,2,',','.')?></td>
                    <td class="text-right text-danger">R$ <?php echo number_format($g_venc,2,',','.')?></td>
                    <td></td>
                </tr>
            </tfoot>
        </table>
    </div>
</div>
</section>
<link href="<?php echo base_url('assets/css/datatables/dataTables.bootstrap.css')?>" rel="stylesheet">
<script src="<?php echo base_url('assets/js/plugins/datatables/jquery.dataTables.js')?>"></script>
<script src="<?php echo base_url('assets/js/plugins/datatables/dataTables.bootstrap.js')?>"></script>
<script>$(function(){$('#tbl-rel').dataTable({"order":[[5,'desc']],"pageLength":50,"language":{"url":"//cdn.datatables.net/plug-ins/1.10.21/i18n/Portuguese-Brasil.json"}});});</script>
