<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <meta name="description" content="Sistema Integrado">
    <meta name="description" content="Sistema Contable">
    <title>Recaudo Diario</title>
    <style type="text/css" media="screen">
        html, body{
            font-family: "Arial", sans-serif;
        }
    </style>
</head>
<body>
    <div>
        <div>
            <table style="width: 100%;" border="0">
                <thead>
                    <tr>
                        <th style="width: 10%; text-align:left" rowspan="3">
                            @if(!empty($compania->logo))
                                <img src="{{ $compania->logo }}" style="width:55px;"/>
                            @endif
                        </th>
                        <th style="text-align: center">
                            <span style="font-family: sans-serif; font-size: 14px; text-align:center; box-align: center"><b>{{ $compania->razonsocial }}</b></span>
                        </th>
                    </tr>
                    <tr>
                        <th style="text-align: center">
                            <span style="font-size: 14px; margin-bottom: 0px; text-align:center"><b>{{ $compania->tipodoc }}:</b></span>
                            <span style="font-size: 14px; margin-bottom: 0px; text-align:center"><b>{{ $compania->numeroi }}</b></span>
                        </th>
                    </tr>
                    <tr>
                        <td style="text-align: center">
                            <span style="font-size: 14px; margim-bottom: 0px; text-align:center">Relación de Recaudos de Impuesto Predial Entre  {{$fIN}} y  {{$fFF}} </span>
                        </td>
                    </tr>
                </thead>
            </table>
        </div>
        <div>
            <table style="width: 100%;" border="1" style="font-size: 7px">
                <thead>
                    <tr>
                        <th style="font-size: 13px">Código Catastral</th>
                        <th style="font-size: 13px">Propietario</th>
                        <th style="font-size: 13px">Factura</th>
                        <th style="font-size: 13px">Fecha P</th>
                        @foreach ( $nomCon as $con )
                            <th style="font-size: 13px">{{ ucwords(mb_strtolower($con->cnom)) }}</th>
                        @endforeach
                        <th style="font-size: 13px">Total</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    list($imp, $sob ,$cor, $int, $des, $pap, $sbm, $inc, $deb, $xxx) = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    $dataBancos = DB::table('gr_detalle_pago_predial as dtp')
                            ->select(
                                DB::raw('(if(
                                    concat_ws(" ", ter.nombreuno, ter.nombredos, ter.apellidouno, ter.apellidodos) = " ",
                                    ter.razonsocial,
                                    concat_ws(" ", ter.nombreuno, ter.nombredos, ter.apellidouno, ter.apellidodos)
                                )) as nombrebanco'),
                                'cta.numerocuenta as nmcta',
                                'pag.banco as banco'
                            )
                            ->leftJoin('gr_pago_predial as pag', 'dtp.pago', '=', 'pag.id_unico')
                            ->leftJoin('gf_cuenta_bancaria as cta', 'pag.banco', '=', 'cta.id_unico')
                            ->leftJoin('gf_tercero as ter', 'cta.banco', '=', 'ter.id_unico')
                            ->whereBetween('pag.fechapago', [$fechaI, $fechaF])
                            ->whereBetween('cta.id_unico', [$bancoI, $bancoF])
                            ->groupBy('pag.banco')
                            ->get();
                    ?>
                    @foreach ($dataBancos as $value) {
                        <tr>
                            <td colspan="4" style="text-align:left; font-weight: 800">BANCO:</td>
                            <td colspan="4" style="font-weight: 800">{{ $value->nombrebanco }}</td>
                            <td colspan="2" style="text-align:left; font-weight: 800">N° CUENTA:</td>
                            <td colspan="4" style="font-weight: 800">{{ $value->nmcta }}</td>
                        </tr>
                        <?php
                            list($ximp, $xsob ,$xcor, $xint, $xdes, $xpap, $xsbm, $xinc, $xdeb, $xxxx) = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                            $dataPredio = DB::table('gr_detalle_pago_predial as dtp')
                            ->select(
                                'predio.codigo_catastral',
                                'tr.nombres as propietario',
                                'fp.numero',
                                DB::raw("DATE_FORMAT(pago.fechapago, '%d/%m/%Y') as anno"),
                                DB::raw('sum(if(cp.id_concepto = 1, dtp.valor, 0)) as impuesto'),
                                DB::raw('sum(if(cp.id_concepto = 3, dtp.valor, 0)) as corporacion_regional'),
                                DB::raw('sum(if(cp.id_concepto = 2, dtp.valor, 0)) as sobretasa'),
                                DB::raw('sum(if(cp.id_concepto = 5, dtp.valor, 0)) as descuento'),
                                DB::raw('sum(if(cp.id_concepto = 4, dtp.valor, 0)) as interes_mora'),
                                DB::raw('sum(if(cp.id_concepto = 8, dtp.valor, 0)) as interes_corporacion'),
                                DB::raw('sum(if(cp.id_concepto = 7, dtp.valor, 0)) as Sobretasa_Bomberil'),
                                DB::raw('sum(if(cp.id_concepto = 9, dtp.valor, 0)) as Debido_Cobrar'),
                                DB::raw('sum(if(cp.id_concepto = 6, dtp.valor, 0)) as papeleria')
                            )
                            ->leftJoin('gr_pago_predial as pago', 'dtp.pago', '=', 'pago.id_unico')
                            ->leftJoin('gr_detalle_factura_predial as dtf', 'dtp.detallefactura', '=', 'dtf.id_unico')
                            ->leftJoin('gr_factura_predial as fp', 'dtf.factura', '=', 'fp.id_unico')
                            ->leftJoin('gp_predio1 as predio', 'fp.predio', '=', 'predio.id_unico')
                            ->leftJoin('gp_tercero_predio as tp', 'tp.predio', '=', 'predio.id_unico')
                            ->leftJoin('gr_propietarios as tr', 'tp.tercero', '=', 'tr.id_unico')
                            ->leftJoin('gr_avaluo as av', 'dtf.avaluo', '=', 'av.id_unico')
                            ->leftJoin('gr_concepto_predial as cp', 'dtf.concepto', '=', 'cp.id_unico')
                            ->whereBetween('pago.fechapago', [$fechaI, $fechaF])
                            ->where('pago.banco', '=', $value->banco)
                            ->where('tp.propietario', '=', 0)
                            ->groupBy('pago.id_unico')
                            ->get();

                        ?>
                        @foreach ($dataPredio as $row)
                            <?php
                            $x = 0;
                            ?>
                            <tr>
                                <td style="font-size: 13px">{{$row->codigo_catastral}}</td>
                                <td style="font-size: 13px">{{$row->codigo_catastral}}</td>
                                <td style="text-align: right; font-size: 13px">{{$row->numero}}</td>
                                <td style="text-align: right; font-size: 13px">{{$row->anno}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->impuesto,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->sobretasa,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->corporacion_regional,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->interes_mora,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{$row->descuento<0? number_format($row->descuento*-1,0,'.',','):number_format($row->descuento,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->papeleria,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->Sobretasa_Bomberil,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->interes_corporacion,0,'.',',')}}</td>
                                <td style="text-align: right; font-size: 13px">{{number_format($row->Debido_Cobrar,0,'.',',')}}</td>
                                <?php
                                    $x = $row->impuesto + $row->sobretasa + $row->corporacion_regional + $row->interes_mora + $row->descuento + $row->papeleria + $row->Sobretasa_Bomberil + $row->interes_corporacion + $row->Debido_Cobrar;
                                ?>

                                <td style="text-align: right; font-size: 13px">{{number_format($x,0,'.',',')}}</td>
                            </tr>
                            <?php
                            $ximp += $row->impuesto; $xsob += $row->sobretasa; $xcor += $row->corporacion_regional; $xint += $row->interes_mora;
                            $xdes += $row->descuento<0?$row->descuento*-1:$row->descuento; $xpap += $row->papeleria; $xsbm += $row->Sobretasa_Bomberil;
                            $xinc += $row->interes_corporacion; $xdeb += $row->Debido_Cobrar;
                            $xxxx += $x;

                            $imp += $row->impuesto; $sob += $row->sobretasa; $cor += $row->corporacion_regional; $int += $row->interes_mora;
                            $des += $row->descuento<0?$row->descuento*-1:$row->descuento; $pap += $row->papeleria; $sbm += $row->Sobretasa_Bomberil;
                            $inc += $row->interes_corporacion; $deb += $row->Debido_Cobrar;
                            $xxx += $x;
                            ?>
                        @endforeach
                        <tr>
                            <td colspan="4" style="font-size: 11px"><b>TOTAL BANCO</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($ximp, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xsob, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xcor, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xint, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xdes, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xpap, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xsbm, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xinc, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xdeb, 0, '.', ',') }}</b></td>
                            <td style="text-align: right; font-size: 13px"><b>{{ number_format($xxxx, 0, '.', ',') }}</b></td>
                        </tr>
                    @endforeach
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="4" style="font-size: 11px"><b>TOTALES</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($imp, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($sob, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($cor, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($int, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($des, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($pap, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($sbm, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($inc, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($deb, 0, '.', ',') }}</b></td>
                        <td style="text-align: right; font-size: 13px"><b>{{ number_format($xxx, 0, '.', ',') }}</b></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</body>
</html>