

<?php
$totalMoradores = $totalMoradores = $this->db->query("SELECT COUNT(*)as a FROM morador")->row()->a;
$moradoresAtualizados = $this->db->query("SELECT COUNT(*)as a FROM morador WHERE cpfMorador IS NOT NULL")->row()->a;
$moradoresAtualizadosT = ($moradoresAtualizados * 100) / $totalMoradores;

$notificacoesMesAtual = $this->db->query("SELECT COUNT(*)as a FROM multanotificacao WHERE month(data) = month('" . strftime('%Y-%m-%d') . "') AND year(data) = year('" . strftime('%Y-%m-%d') . "')")->row()->a;
$ocorrenciaMesAnterior = $this->db->query("SELECT COUNT(*)as a FROM multanotificacao WHERE month(data) = month('" . strftime('%Y-%m-%d', strtotime('-1 Month')) . "') AND year(data) = year('" . strftime('%Y-%m-%d', strtotime('-1 Month')) . "')")->row()->a;
$diferenca = $notificacoesMesAtual - $ocorrenciaMesAnterior;
$valor = $ocorrenciaMesAnterior == 0 ? 0 : ($diferenca / $ocorrenciaMesAnterior) * 100;
$curva = ($diferenca >= 0) ? "up" : "down";

$ocorrenciaMesAtual = $this->db->query("SELECT COUNT(*)as a FROM livro_ocorrencia WHERE month(dataOcorrencia) = month('" . strftime('%Y-%m-%d') . "') AND year(dataOcorrencia) = year('" . strftime('%Y-%m-%d') . "')")->row()->a;
$ocorrenciaMesAtualSolucionadas = $this->db->query("SELECT COUNT(*)as a FROM livro_ocorrencia WHERE situacaoOcorrencia = 'Solucionado' AND  month(dataOcorrencia) = month('" . strftime('%Y-%m-%d') . "') AND year(dataOcorrencia) = year('" . strftime('%Y-%m-%d') . "')")->row()->a;

if($ocorrenciaMesAtual > 0){
$resolvidas = ($ocorrenciaMesAtualSolucionadas / $ocorrenciaMesAtual) * 100;
}else{
$resolvidas = 0;
}


$gastosMesAtual = $this->db->query("SELECT SUM(valor)as a FROM lancamentos WHERE month(data_vencimento) = month('" . strftime('%Y-%m-%d') . "') AND year(data_vencimento) = year('" . strftime('%Y-%m-%d') . "')")->row()->a;
$gastosMesAnterior = $this->db->query("SELECT SUM(valor)as a FROM lancamentos WHERE month(data_vencimento) = month('" . strftime('%Y-%m-%d', strtotime('-1 Month')) . "') AND year(data_vencimento) = year('" . strftime('%Y-%m-%d', strtotime('-1 Month')) . "')")->row()->a;
$diferencaGastos = $gastosMesAtual - $gastosMesAnterior;
$valorFinanceiro = $gastosMesAnterior == 0 ? 0 : ($diferencaGastos / $gastosMesAnterior) * 100;
$curvaGastos = ($diferencaGastos >= 0) ? "up" : "down";


?>

<div class="col-lg-12">
    <div class="portlet">
        <div class="portlet-heading bg-primary">
            <h3 class="portlet-title">
                <span class="icon"><i class="fa fa-signal"></i></span> Dados Informativos
            </h3>
            <div class="portlet-widgets">
                <a href="javascript:;" data-toggle="reload"><i class="zmdi zmdi-refresh"></i></a>
                <a data-toggle="collapse" data-parent="#accordion1" href="#bg-primaryDados"><i class="zmdi zmdi-minus"></i></a>
                <a href="#" data-toggle="remove"><i class="zmdi zmdi-close"></i></a>
            </div>
            <div class="clearfix"></div>
        </div>
        <div id="bg-primaryDados" class="panel-collapse collapse in">
            <div class="widget-content">

                <div class="container">

                    <div class="row">

                        <div class="col-lg-3 col-md-4">
                            <div class="card-box">
                                <h4 class="header-title m-t-0 m-b-30">%Moradores Atualizados</h4>
                                <p style="margin-top: -12%"><?php echo $moradoresAtualizados ?> - Moradores Atualizados</p>

                                <div class="widget-chart-1">
                                    <div class="widget-chart-box-1">
                                        <div style="display:inline;width:80px;height:80px;">
                                            <input data-plugin="knob" data-width="80" data-height="80" data-fgcolor="#f05050 "
                                                   data-bgcolor="#F9B9B9"
                                                   value="<?php echo number_format($moradoresAtualizadosT, 2, ",", ".") ?> "
                                                   data-skin="tron" data-angleoffset="180"
                                                   data-readonly="true" data-thickness=".15" readonly="readonly"
                                                   style="width: 44px; height: 26px; position: absolute; vertical-align: middle; margin-top: 26px; margin-left: -62px; border: 0px; background: none; font-style: normal; font-variant: normal; font-weight: bold; font-stretch: normal; font-size: 16px; line-height: normal; font-family: Arial; text-align: center; color: rgb(240, 80, 80); padding: 0px; -webkit-appearance: none;">
                                        </div>
                                    </div>


                                    <div class="widget-detail-1">

                                        <h2 class="p-t-10 m-b-0"> <?php echo $totalMoradores ?> </h2>
                                        <p class="text-muted">Moradores Cadastrados</p>
                                    </div>

                                </div>
                            </div>
                        </div><!-- end col -->

                        <div class="col-lg-3 col-md-5">
                            <div class="card-box">


                                <h4 class="header-title m-t-0 m-b-30">Advertências/Multas</h4>
                                <p style="margin-top: -12%"><?php echo strftime('Em %m/%Y', strtotime('-1 Month')) . ' : <strong>' . $ocorrenciaMesAnterior . ' </strong>' ?> </p>
                                <div class="widget-box-2">
                                    <div class="widget-detail-2">
                        <span style="font-size: larger"
                              class="badge badge-success pull-left m-t-20"><?php echo number_format($valor, 2, ",", ".") ?>
                            <i
                                class="zmdi zmdi-trending-<?php echo $curva ?>"></i> </span>
                                        <h2 class="m-b-0"> <?php echo $notificacoesMesAtual ?> </h2>
                                        <p class="text-muted m-b-25"><?php echo strftime('Em %m/%Y') ?></p>
                                    </div>
                                    <div class="progress progress-bar-success-alt progress-sm m-b-0">
                                        <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="77"
                                             aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $valor ?>%;">
                                            <span class="sr-only">90% Complete</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-lg-3 col-md-5">
                            <div class="card-box">

                                <h4 class="header-title m-t-0 m-b-30">Ocorrências Solucionadas</h4>
                                <p style="margin-top: -12%"><?php echo $ocorrenciaMesAtualSolucionadas ?> - Solucionadas</p>
                                <div class="widget-chart-1">
                                    <div class="widget-chart-box-1">
                                        <div style="display:inline;width:80px;height:80px;">
                                            <input data-plugin="knob" data-width="80" data-height="80" data-fgcolor="#ffbd4a"
                                                   data-bgcolor="#FFE6BA" value="<?php echo $resolvidas ?>" data-skin="tron"
                                                   data-angleoffset="180"
                                                   data-readonly="true" data-thickness=".15" readonly="readonly"
                                                   style="width: 44px; height: 26px; position: absolute; vertical-align: middle; margin-top: 26px; margin-left: -62px; border: 0px; background: none; font-style: normal; font-variant: normal; font-weight: bold; font-stretch: normal; font-size: 16px; line-height: normal; font-family: Arial; text-align: center; color: rgb(255, 189, 74); padding: 0px; -webkit-appearance: none;">
                                        </div>
                                    </div>
                                    <div class="widget-detail-1">
                                        <h2 class="p-t-10 m-b-0"> <?php echo $ocorrenciaMesAtual ?> </h2>
                                        <p class="text-muted"><?php echo strftime('%m/%Y') ?></p>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="col-lg-3 col-md-5">

                            <div class="card-box">

                                <h4 class="header-title m-t-0 m-b-30">Financeiro</h4>
                                <p style="margin-top: -12%"><?php echo strftime('Gastos em %m/%Y', strtotime('-1 Month')) ?> :
                                    <strong> R$ <?php echo  number_format($gastosMesAnterior, 2, ',', '.') ?> </strong>  </p>

                                <div class="widget-box-2">
                                    <div class="widget-detail-2">
                        <span style="font-size: larger"
                              class="badge badge-pink pull-left m-t-20"><?php echo number_format($valorFinanceiro, 2, ',', '.') ?>% <i
                                class="zmdi zmdi-trending-<?php echo $curvaGastos ?>"></i> </span>
                                        <h2 class="m-b-0"> <?php echo number_format($gastosMesAtual, 2, ',', '.') ?> </h2>
                                        <p class="text-muted m-b-25"><?php echo strftime('Gastos em %m/%Y') ?></p>
                                    </div>
                                    <div class="progress progress-bar-pink-alt progress-sm m-b-0">
                                        <div class="progress-bar progress-bar-pink" role="progressbar" aria-valuenow="77"
                                             aria-valuemin="0" aria-valuemax="100" style="width: 77%;">
                                            <span class="sr-only">77% Complete</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                    </div>


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


