<!DOCTYPE html>
<html>
<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>Listad de Pagos</title>
</head>
<body>
    <table style="width: 100%; border-collapse: collapse; font-family: 'Arial', sans-serif;">
        <thead>
            <tr>
                <th style="text-align: center" colspan="14"><?php echo e($compania->razonsocial); ?></th>
            </tr>
            <tr>
                <th style="text-align: center" colspan="14"><?php echo e($compania->tipodoc." : ".$compania->numeroi); ?></th>
            </tr>
            <tr style="font-size: 12px;">
                <th style="border: 1px solid #000">COD. CATASTRAL</th>
                <th style="border: 1px solid #000">VIGENCIA</th>
                <th style="border: 1px solid #000">PROPIETARIO</th>
                <th style="border: 1px solid #000">FACTURA</th>
                <th style="border: 1px solid #000">FECHA PAGO</th>
                <th style="border: 1px solid #000">IMPUESTO</th>
                <th style="border: 1px solid #000">INTERES</th>
                <th style="border: 1px solid #000">CAS</th>
                <th style="border: 1px solid #000">INT. CAS</th>
                <th style="border: 1px solid #000">DESCUENTO</th>
                <th style="border: 1px solid #000">PAPELERIA</th>
                <th style="border: 1px solid #000">SOB. BOMB.</th>
                <th style="border: 1px solid #000">D. COBRAR</th>
                <th style="border: 1px solid #000">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);
            if(empty($bancoI)){
                $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])
                        ->groupBy('pag.banco')
                        ->get();
            }else{
                $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();
            }
            $imp = $sob = $cor =  $int = $des = $pap = $sbm = $inc = $deb = $xxx = $xant = $xact = $impA = $sobA = $corA = $intA = $desA = $papA = 0;
            $sbmA = $incA = $debA = $impH = $sobH = $corH = $intH = $desH = $papH = $sbmH = $incH = $debH = 0;
            ?>
            <?php $__currentLoopData = $dataBancos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?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'),
                    'pago.tipopago',
                    'pago.parametrizacionanno',
                    'av.anno as vig','predio.id_unico as predio'
                )
                ->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)
                // ->where('tp.orden', '=', '001')
                ->orderBy('pago.fechapago', 'ASC')
                ->orderBy('predio.id_unico', 'ASC')
                ->orderBy('av.anno', 'ASC')
                // ->orderBy('tp.tercero', 'ASC')
                ->orderBy('pago.id_unico', 'ASC')
                ->groupBy('dtf.avaluo')
                ->groupBy('pago.id_unico')
                ->get();
                // ->where('pago.tipopago', '!=', 6)
                ?>
                <?php if(count($dataPredio) > 0): ?>
                    <tr style="font-size: 12px;">
                        <td colspan="1" style="text-align:left; font-weight: 800">BANCO:</td>
                        <td colspan="3" style="font-weight: 800"><?php echo e($value->nombrebanco); ?></td>
                        <td colspan="1" style="text-align:left; font-weight: 800">NÂ° CUENTA:</td>
                        <td colspan="6" style="font-weight: 800"><?php echo e($value->nmcta); ?></td>
                    </tr>
                    <?php $__currentLoopData = $dataPredio; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                        $x = 0;
                        if($row->tipopago == 7){
                            $descuento = $row->descuento>0?$row->descuento * -1:$row->descuento;
                        }else{
                            $descuento = $row->descuento<0?$row->descuento * -1:$row->descuento;
                        }
                        $dataProp = DB::table('gp_tercero_predio as tp')
                                    ->select( 'tr.nombres as propietario')
                                    ->leftJoin('gr_propietarios as tr', 'tp.tercero', '=', 'tr.id_unico')
                                    ->where('tp.propietario', '=', 0)
                                    ->where('tp.orden', '=', '001')
                                    ->where('tp.predio', '=', $row->predio)
                                    ->groupBy('tp.tercero')
                                    ->get();
                        $propietario= $dataProp[0]->propietario;
                        if ($propietario==null) {
                         $propietario="-";
                        }

                        ?>
                        <tr>
                            <td style="font-size: 13px; border: 1px solid #000; font-weight: 800"><?php echo e("'".$row->codigo_catastral."'"); ?></td>
                            <td style="font-size: 13px; border: 1px solid #000; font-weight: 800"><?php echo e($row->vig); ?></td>
                              <td style="font-size: 13px; border: 1px solid #000; font-weight: 800"><?php echo e($propietario); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000;font-weight: 800"><?php echo e($row->numero); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000;font-weight: 800"><?php echo e($row->anno); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->impuesto,0,'.',',')); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->interes_mora,0,'.',',')); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->corporacion_regional,0,'.',',')); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->interes_corporacion,0,'.',',')); ?></td>
                            <?php if($row->tipopago == 7): ?>
                                <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($descuento,0,'.',',')); ?></td>
                            <?php else: ?>
                                <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e($row->descuento<0? number_format($row->descuento*-1,0,'.',','):number_format($row->descuento,0,'.',',')); ?></td>
                            <?php endif; ?>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->papeleria,0,'.',',')); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->Sobretasa_Bomberil,0,'.',',')); ?></td>
                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($row->Debido_Cobrar,0,'.',',')); ?></td>
                            <?php
                                $x = $row->impuesto + $row->corporacion_regional + $row->interes_mora + $row->descuento  + $row->interes_corporacion + $row->papeleria + $row->Sobretasa_Bomberil + $row->Debido_Cobrar;
                            ?>

                            <td style="text-align: right; font-size: 13px; border: 1px solid #000"><?php echo e(number_format($x,0,'.',',')); ?></td>
                        </tr>
                        <?php
                        $ximp += $row->impuesto;
                        $xsob += $row->sobretasa;
                        $xcor += $row->corporacion_regional;
                        $xint += $row->interes_mora;
                        if($row->tipopago == 7){
                            $xdes += $descuento;
                            $des  += $descuento;
                        }else{
                            $xdes += $row->descuento<0?$row->descuento * -1:$row->descuento;
                            $des  += $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;
                        $pap += $row->papeleria;
                        $sbm += $row->Sobretasa_Bomberil;
                        $inc += $row->interes_corporacion;
                        $deb += $row->Debido_Cobrar;
                        $xxx += $x;

                       $param    = session()->get('anno');
                        if ($param==6) {
                            $aņo='2021';
                        }else if($param==10){
                            $aņo='2022';
                        }else if($param==13){
                          $aņo='2023';
                        }
                        if($row->vig == $aņo){                         
                            $xact += $x;
                            $impH += $row->impuesto;
                            $sobH += $row->sobretasa;
                            $corH += $row->corporacion_regional;
                            $intH += $row->interes_mora;
                            if($row->tipopago == 7){
                                $desH += $descuento;
                            }else{
                                $desH += $row->descuento<0?$row->descuento * -1:$row->descuento;
                            }
                            $papH += $row->papeleria;
                            $sbmH += $row->Sobretasa_Bomberil;
                            $incH += $row->interes_corporacion;
                            $debH += $row->Debido_Cobrar;
                        }else{
                            $xant += $x;
                            $impA += $row->impuesto;
                            $sobA += $row->sobretasa;
                            $corA += $row->corporacion_regional;
                            $intA += $row->interes_mora;
                            if($row->tipopago == 7){
                                $desA += $descuento;
                            }else{
                                $desA += $row->descuento<0?$row->descuento * -1:$row->descuento;
                            }
                            $papA += $row->papeleria;
                            $sbmA += $row->Sobretasa_Bomberil;
                            $incA += $row->interes_corporacion;
                            $debA += $row->Debido_Cobrar;
                        }
                        ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td colspan="5" style="font-size: 11px; border: 1px solid #000"><b>TOTAL BANCO</b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($ximp, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xint, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xcor, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xinc, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xdes, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xpap, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xsbm, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xdeb, 0, '.', ',')); ?></b></td>
                        <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xxxx, 0, '.', ',')); ?></b></td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <tfoot>
                <tr>
                    <td colspan="5" style="font-size: 11px; border: 1px solid #000"><b>TOTALES</b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($imp, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($int, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($cor, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($inc, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($des, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($pap, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($sbm, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($deb, 0, '.', ',')); ?></b></td>
                    <td style="text-align: right; font-size: 13px; border: 1px solid #000"><b><?php echo e(number_format($xxx, 0, '.', ',')); ?></b></td>
                </tr>
            </tfoot>
        </tbody>
    </table>
    <br/>
    <table style="font-family: 'Arial', sans-serif; border-collapse: collapse;">
        <thead>
            <tr>
                <th colspan="16" style="border: 1px solid #000;">RESUMEN DE VIGENCIAS</th>
            </tr>
            <tr>
                <th colspan="8" style="text-align:center; font-size: 13px; border: 1px solid #000;">VIGENCIAS ANTERIORES</th>
                <th colspan="8" style="text-align:center; font-size: 13px; border: 1px solid #000;">VIGENCIA ACTUAL</th>
            </tr>
            <tr>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">IMPUESTO</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">INTERES</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">CAS</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">INT. CAS</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">DESCUENTO</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">PAPELERIA</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">SOB. BOMB</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">DEB. COBRAR</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">IMPUESTO</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">INTERES</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">CAS</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">INT. CAS</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">DESCUENTO</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">PAPELERIA</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">SOB. BOMB</th>
                <th style="font-size: 13px; text-align: center; border: 1px solid #000;">DEB. COBRAR</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($impA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($intA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($corA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($incA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($desA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($papA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($sbmA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($debA, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($impH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($intH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($corH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($incH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($desH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($papH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($sbmH, 0, '.', ',')); ?></td>
                <td style="font-size:13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($debH, 0, '.', ',')); ?></td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="3" style="font-size: 13px; text-align: right; font-weight: 800; border: 1px solid #000;">TOTAL VIGENCIAS ANTERIORES</td>
                <td colspan="5" style="font-size: 13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($xant, 0, '.', ',')); ?></td>
                <td colspan="3" style="font-size: 13px; text-align: right; font-weight: 800; border: 1px solid #000;">TOTAL VIGENCIA ACTUAL</td>
                <td colspan="5" style="font-size: 13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($xact, 0, '.', ',')); ?></td>
            </tr>
            <tr>
                <td colspan="11" style="font-size: 13px; text-align: right; font-weight:800; border: 1px solid #000;">TOTAL VIGENCIAS</td>
                <td colspan="5" style="font-size: 13px; text-align: right; border: 1px solid #000;"><?php echo e(number_format($xant + $xact, 0, '.', ',')); ?></td>
            </tr>
        </tfoot>
    </table>
</body>
</html>