<?php $__env->startSection('content'); ?>
    
    <style>
        #total_final2 {
            background-color: #d3d3d3;
            font-weight: 700;
        }

        #total_final {
            background-color: #d3d3d3;
        }
    </style>
    <div id="contenedor_interno" class="container-fluid">
        <div class="row ">
            <div class="col-md-12">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="<?php echo e(route('contabilidad.dashboard_facturas')); ?>">Cuenta
                                Corriente</a></li>
                        <li class="breadcrumb-item active" aria-current="page">Ver</li>
                    </ol>
                </nav>
            </div>
            <hr>
        </div>
    </div>
    <div id="contenedor-dashboard" class="container-fluid">
        <div class="row ">
            <div class="col-md-12">
                <h2>Cuenta Corriente</h2>
            </div>
        </div>
        <div class="col-md-12">
            <br>
            <table id="example2" class="display" style="width:100%">
                <thead>
                    <tr>
                        <th scope="col">ID</th>
                        <th scope="col">Nombre</th>
                        <th scope="col">Total</th>
                        <th scope="col">Vigente</th>
                        <th scope="col">+30 días</th>
                        <th scope="col">+60 días</th>
                        <th scope="col">+90 días</th>
                        <th scope="col">Ejecutivo</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $clientes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cliente): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($cliente?->id); ?></td>
                            <td><a href="<?php echo e(route('contabilidad.ver_cuenta_corriente_info', $cliente->id ?? 1)); ?>"
                                    target="_blank"><?php echo e($cliente->nombre ?? 'No Disponible'); ?></a></td>
                            <td>
                                <?php echo e(number_format($total_cliente[$cliente?->id] ?? 0, 2, '.', ',')); ?>

                            </td>
                            <td>
                                
                                <?php
                                    $total_vigente = 0;
                                    if (isset($vigente_clientes[$cliente?->id])) {
                                        foreach ($vigente_clientes[$cliente->id] as $factura) {
                                            $total_vigente += $factura->total - $factura->abono;
                                        }
                                    }
                                ?>
                                <?php echo e(number_format($total_vigente, 2, '.', ',')); ?>

                            </td>
                            <td>
                                <?php echo e(number_format($total_cliente_dias[$cliente?->id][30] ?? 0, 2, '.', ',')); ?>

                            </td>
                            <td>
                                <?php echo e(number_format($total_cliente_dias[$cliente?->id][60] ?? 0, 2, '.', ',')); ?>

                            </td>
                            <td>
                                <?php echo e(number_format(($total_cliente_dias[$cliente?->id][90] ?? 0) + ($total_cliente_dias[$cliente?->id][100] ?? 0), 2, '.', ',')); ?>

                            </td>
                            <td>
                                <?php echo e($cliente?->info_ejecutivo->name ?? 'No Disponible1'); ?>

                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                    <?php $__currentLoopData = $clientes_saldo; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cliente): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($cliente?->id); ?></td>
                            <td><a href="<?php echo e(route('contabilidad.ver_cuenta_corriente_info', $cliente?->id ?? 1)); ?>"
                                    target="_blank"><?php echo e($cliente?->nombre); ?></a></td>
                            <td class="text-danger">
                                -<?php echo e(number_format($cliente?->saldo_favor ?? 0, 2, '.', ',')); ?>


                            </td>
                            <td>

                            </td>
                            <td>


                            </td>
                            <td>

                            </td>
                            <td class="text-danger">
                                -<?php echo e(number_format($cliente?->saldo_favor ?? 0, 2, '.', ',')); ?>

                            </td>
                            <td>
                                <?php echo e($cliente?->info_ejecutivo->name ?? 'No Disponible'); ?>

                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
                <tfoot>
                    <tr id="total_final2">
                        <td id="total_final">.TOTAL</td>
                        <td></td>
                        <td id="data1"><?php echo e(number_format($total_total, 2, '.', ',')); ?></td>
                        <td id="data2"><?php echo e(number_format($total_vigente, 2, '.', ',')); ?></td>
                        <td id="data3"><?php echo e(number_format($total_total30, 2, '.', ',')); ?></td>
                        <td id="data4"><?php echo e(number_format($total_total60, 2, '.', ',')); ?></td>
                        <td id="data5"><?php echo e(number_format($total_total90 + $total_total100, 2, '.', ',')); ?></td>
                        <td></td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
    <script>
        jQuery.fn.dataTable.Api.register('sum()', function() {
            return this.flatten().reduce(function(a, b) {
                if (typeof a === 'string') {
                    a = a.replace(/[^\d.-]/g, '') * 1;
                }
                if (typeof b === 'string') {
                    b = b.replace(/[^\d.-]/g, '') * 1;
                }

                return a + b;
            }, 0);
        });
        $('#example2').dataTable({
            "paging": false,
            "order": [
                [0, "desc"]
            ],
            dom: 'Bfrtip',
            buttons: [
                'excel', 'print'
            ],
            drawCallback: function() {
                var api = this.api();

                let dollarUSLocale = Intl.NumberFormat('en-IN');
                $("#data1").html(
                    api.column(2, {
                        page: 'current'
                    }).data().sum().toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
                );
                $("#data2").html(
                    api.column(3, {
                        page: 'current'
                    }).data().sum().toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
                );
                $("#data3").html(
                    api.column(4, {
                        page: 'current'
                    }).data().sum().toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
                );
                $("#data4").html(
                    api.column(5, {
                        page: 'current'
                    }).data().sum().toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
                );
                $("#data5").html(
                    api.column(6, {
                        page: 'current'
                    }).data().sum().toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
                );
                $("#data6").html(
                    api.column(7, {
                        page: 'current'
                    }).data().sum().toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
                );
            }

        });

        $('.cuentas').each(function() {
            var total30 = parseFloat($(this).find('.totals30').text().replace(',', ''));
            var total60 = parseFloat($(this).find('.totals60').text().replace(',', ''));
            var total90 = parseFloat($(this).find('.totals90').text().replace(',', ''));
            var total100 = parseFloat($(this).find('.totals100').text().replace(',', ''));
            if (total30 > 0) {

            } else {
                total30 = 0;
            }
            if (total60 > 0) {

            } else {
                total60 = 0;
            }
            if (total90 > 0) {

            } else {
                total90 = 0;
            }
            if (total100 > 0) {

            } else {
                total100 = 0;
            }
            var totalf = total30 + total60 + total100 + total90;
            $(this).find('.totals').text(totalf.toFixed(2));
        })
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('contabilidad.menu', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/devpwg5/laravelrp.com/resources/views/contabilidad/cuenta_corriente.blade.php ENDPATH**/ ?>