<?php echo $__env->make('forms.fbncheader', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('forms.fdatatables', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

<style type="text/css">
tfoot input {
  width: 100%;
}

</style>

<div style="background-color:rgba(127,255,212,.2);"  class="col-lg-max container-fluid">
    <?php echo Form::open(['url' => 'reglement_pointage/'.$employeur_id.'/'.$exercice, 'method' => 'PUT']); ?>


    <div style="padding-left:0px" class="col-lg-max">
         <div class="row" style="">   
            <div class="col-md-1" style="padding-left:0px;">
               <?php echo Html::image("img/entreprise_cotisations.png", 
                    "Pointage", 
                    array( 'width'=>'120px','maxwidth'=>'10%',
                        "style"=>"padding:4px" )); ?> 
            </div>
            <div class="col-md-8" style="padding-left:0px;">
                <h2 style="margin-top:2px;">Pointage des règlements</h2>
            </div>
            <div class="col-md-4" style="padding-left:0px;">
                <?php echo Form::hidden('employeur_id2', $employeur_id, ['id'  => 'employeur_id2']); ?>

                <?php echo Form::label('employeur_nom', 'Employeur :' ); ?>

                <?php echo Form::text('employeur_nom', $employeur_nom, 
                    ['placeholder' => 'Employeur', 'class' => 'form-control'
                        , 'id' => 'employeur_nom','style'=>'background:whitesmoke']); ?>

                 <!-- source: "../autocomplete_employeur", -->
                <script>
                    $(function() { 

                       $("#employeur_nom").autocomplete({
                            source: "<?php echo route('autocomplete_employeur'); ?>",
                            minLength: 1,
                            select: function(event, ui) {
                                $('#employeur_nom').val(ui.item.id+" "+(ui.item.value.trim()));
                                $('#employeur_id2').val(ui.item.id);
                                if(ui.item.value=="TOUS") $('#employeur_id2').val('TOUS');
                                location.href="<?php echo url('reglement_pointage/'); ?>/"
                                    +$('#employeur_id2').val()+"/"+$('#exercice_id').val();
                            },
                            close: function(event, ui) {
                                
                            }
                        }); 

                    });
                </script>
            </div>
            <div class="col-md-2">
                <?php echo Form::label('annes', 'Années :' ); ?>

                <?php echo Form::select('exercice',$exercices,$exercice,
                    [
                        'id' => 'exercice_id','class' => 'form-control selectpicker',
                        'data-width' => "100%",'style' => 'font-weight:bold;background:whitesmoke'
                    ]
                ); ?>

                <script>
                    $(document).ready(function() {
                        $('#exercice_id').on('change', function() {
                            location.href="<?php echo url('reglement_pointage/'); ?>/"
                                +$('#employeur_id2').val()+"/"+$('#exercice_id').val();
                        });
                    });
                </script>
            </div>

            <div class="col-md-1">
                <?php echo Form::label('montant_lettrage', 'Lettrage'); ?>

                <?php echo Form::text('montant_lettrage','', ['id'=>'montant_lettrage','readonly','class' => 'form-control']); ?>

            </div>
            <div class="col-md-1" style="padding-top:23px">
                <?php echo Form::button('Lettrer', ['id'=>'bt_lettrer','class' => 'btn btn-primary','onclick'=>'submit();']); ?> 
            </div>

            <div class="col-md-1" style="">
                <?php echo Form::label('afficher', 'Afficher'); ?>

                <?php if(!$affiche_tout): ?>
                    <?php echo Form::button('Tout', [
                        'class' => 'btn btn-warning','align'=>'right','onclick'=>'affiche(0)']); ?> 
                <?php else: ?>
                    <?php echo Form::button('Lignes non lettrées', 
                        ['class' => 'btn btn-warning','align'=>'right','onclick'=>'affiche(1)']); ?> 
                <?php endif; ?>
            </div>
        </div>
    </div>



    <div class='col-lg-max' style="padding-top:15px">
        <?php if($employeur_id): ?>
            <?php echo form::hidden('checklist','',['id'=>'checklist']); ?>

            <div class="col-lg-10">
                    <table id="_table" style="background-color:white"
                        class="table table-striped table-bordered table-hover" width="100%" >
                        <thead class="">
                            <tr>
                                <th width='1%'>N°</th>
                                <th width='10%'>Ex</th>
                                <th width='10%'>Date</th>
                                <th width='10%'>Débit</th>
                                <th width='10%'>Crédit</th>
                                <th width='1%'>Mois</th>
                                <th width='1%'>Nb&nbsp;Mois</th>
                                <th width='10%'>DatDépôt</th>
                                <th width='10%'>DatEncais</th>
                                <th width='1%'>Lettrage<br/>
                                    <span style="color:grey;">Tout&nbsp;</span>
                                    <?php echo Form::checkbox('box_all', '1',false
                                        , ['id'=>'box_all','style'=>'','onclick'=>'check_all()']); ?>

                                    
                                </th>
                                <th width='1%'>&nbsp</th>
                            </tr>
                        </thead>  

                        <tbody>
                            <?php $liste_id=''; ?>
                            <?php $__currentLoopData = $cotisations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cotisation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $class_lg=''; 
                                if($cotisation->isReglement) $class_lg='success';
                                $liste_id.=(($liste_id=='')?'':',').$cotisation->id;
                            ?>
                            <tr>

                                <td id='id_<?php echo $cotisation->id; ?>' style="color:grey"><?php echo $cotisation->id; ?></td>
                                <td align="center"><?php echo $cotisation->exercice; ?></td>
                                <td align="center"><?php echo $cotisation->date; ?></td>
                                <td align="right" id="debit_<?php echo $cotisation->id; ?>" style="font-weight:bold;color:darkred" class="" nowrap><?php echo $cotisation->debit; ?></td>
                                <td align="right" id="credit_<?php echo $cotisation->id; ?>" style="font-weight:bold;color:darkblue" class="" nowrap><?php echo $cotisation->credit; ?></td>
                                <td><?php echo $cotisation->mois; ?></td>
                                <td><?php echo $cotisation->nbmois; ?></td>
                                <td align="center"><?php echo $cotisation->date_depot; ?></td>
                                <td align="center"><?php echo $cotisation->encais_date; ?></td>
                                <td align="center">
                                    <?php if($cotisation->encais_date!=""): ?>
                                        <?php if($cotisation->lettrage2==""): ?>
                                            <?php echo Form::checkbox('box_'.$cotisation->id, '1',false
                                            , ['id'=>'box_'.$cotisation->id,'onclick'=>'check()']); ?>

                                        <?php else: ?>
                                            <?php echo $cotisation->lettrage2; ?>

                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                                <td nowrap> 
                                    <a href="<?php echo url('pointage_encaissement/'.$cotisation->id); ?>" 
                                        class="btn btn-info pull-left" style="margin-right: 3px;">Encaisser</a>
                                </td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>

                    <div class="cform-group" style='font-weight:bold;padding-top:-30px;margin-bottom:100px'>
                        <div class="col-md-2">TOTAL&nbsp;DEBIT&nbsp;:&nbsp;
                            <div class='form-control' style='color:red' align='right' id='total_DEBIT'></div>
                        </div>

                        <div class="col-md-2">TOTAL&nbsp;CREDIT&nbsp;:&nbsp;
                            <div class='form-control' style='color:blue' align='right' id='total_CREDIT'></div>
                        </div>
                    </div>
            </div>
        <?php endif; ?>
    </div>

   <?php echo Form::close(); ?> 
</div>

</body></html>



<script>
    //Complete la liste des boites cochées
    function check(check_all=0) {
        var listbox='<?php echo $liste_id ?>';
        var t_listbox=listbox.split(',');
        var listcheck="";
        var montant_credit=0;
        var montant_debit=0;
        for(i=0;i<t_listbox.length;i++) {
            if(check_all==1) $("#box_"+t_listbox[i]).prop('checked','true');
            if(check_all==2) $("#box_"+t_listbox[i]).prop('checked','');
            if($("#box_"+t_listbox[i]).prop('checked'))  {
                listcheck+=((listcheck=="")?"":",")+t_listbox[i];
                montant_credit+=parseInt($("#credit_"+t_listbox[i]).html());
                montant_debit+=parseInt($("#debit_"+t_listbox[i]).html());
            }
        }
        $("#checklist").val(listcheck);
        var total=montant_credit-montant_debit;
        $("#montant_lettrage").val(total);
        if((total!=0)||(listcheck=="")) $("#bt_lettrer").hide();
        else $("#bt_lettrer").show();
    }

    function check_all() {
        if($("#box_all").prop('checked')) check(1);
        else  check(2);
    }

    function affiche(val) {
        var url="<?php echo url('reglement_pointage/'); ?>/"
                +$('#employeur_id2').val()+"/"+$('#exercice_id').val()+"/";
        if(val==0) url+="1";
        else  url+="0";
        location.href=url;
    }

    check();


</script>

<script>
    $(document).ready(function() {
        $.fn.dataTable.moment('D/M/YYYY');
        var col_visible=[];
        var col_sortable=[7,8];
        var col_numeric=[3];
        var coldep_footer=3;

        function format(n, sep) {
            sep = sep || "."; // Default to period as decimal separator
            return n.toLocaleString().split(sep)[0]
                + sep;
        }

        // Setup - add a text input to each footer cell
        $('#_table tfoot th:lt(2)').filter(':gt(0)').each( function (i) {
            var title = $('#_table thead th').eq( $(this).index() ).text();
            $(this).html( '<input id="input_'+i+'" type="text" placeholder="'+title+'" data-index="'+i+'" />');
        } );

        var table =$('#_table').DataTable( {
                bAutoWidth: false,
                bPaginate: false,
                bInfo: true,
                bFilter: true,
                deferRender:    true,
                scrollY:        400,
                scrollX:        '100%',
                scrollCollapse: true,
                scroller:       true,

                oLanguage: {
                    "sZeroRecords": "Aucune ligne",
                    "sInfo": "Affichage de _START_ &agrave; _END_ sur _TOTAL_ lignes",
                    "sInfoEmpty": "Showing 0 to 0 of 0 records",
                    "decimal": ",",
                    "thousands": " ",
                    "sSearch":"Chercher",

                    buttons: {
                        colvis: 'Colonnes à afficher',
                        copy: 'Copier',
                        print: 'Imprimer',
                        copyTitle: 'Ajouté au presse-papiers',
                        copyKeys: 'Appuyez sur <i>ctrl</i> ou <i>\u2318</i> + <i>C</i> pour copier les données du tableau à votre presse-papiers. <br><br>Pour annuler, cliquez sur ce message ou appuyez sur Echap.',
                        copySuccess: {
                            _: '%d lignes copiées',
                            1: '1 ligne copiée'
                            }
                        }
                    },

                    "aaSorting": [
                        [1,'desc']
                    ],

                    "aoColumnDefs": [
                        { "sTypes": "numeric", "aTargets": col_numeric },
                        { "bSortable": false, "aTargets": col_sortable },
                        { "visible": false, "targets": col_visible },
                    ],


                    dom: "<'row'<'col-sm-1 text-left'><'col-sm-4'><'col-sm-6 text-right'>>" +
                    "<'row'<'col-sm-12'tr>>" +
                    "<'row'<'col-sm-12 text-right'i><'col-sm-7'p>>",

                    buttons: [ 
                        {extend: 'copy',exportOptions: {columns: ':visible'} },
                        {extend: 'excel',exportOptions: {columns: ':visible'} },
                        {extend: 'pdf',exportOptions: {columns: ':visible'} },
                        {extend: 'print',exportOptions: {columns: ':visible'} },
                        'colvis'
                    ],

            "footerCallback": function(row, data, start, end, display) {
                var api = this.api(), data;
                var intVal = function ( i ) {
                    return typeof i === 'string' ?
                        i.replace(/[\$,]/g, '')*1 :
                        typeof i === 'number' ?
                            i : 0;
                };

                

                total = api.column(coldep_footer, { page: 'current'}).data().reduce(function(a, b) {
                        return intVal(a) + intVal(b);}, 0);
                var total_debit=total;
                total=format(total, ' ');
                $('#total_DEBIT').html(total);

                total = api.column(coldep_footer+1, { page: 'current'}).data().reduce(function(a, b) {
                        return intVal(a) + intVal(b);}, 0);
                var total_credit=total;
                total=format(total, ' ');
                $('#total_CREDIT').html(total);             
            },

        } );


        // Filter event handler
        $( table.table().container() ).on( 'keyup', 'tfoot input', function () {
            table
                .column( $(this).data('index')+1 )
                .search( this.value )
                .draw();
        } );



        $('#_table').DataTable().draw();

        $(window).resize(function () {
                    $('#_table').DataTable().draw();
        });

} );


</script>


<?php /**PATH C:\xampp\htdocs\SYSINFO\cpswf\sipre\resources\views/recouvrement/cotisations/pointage.blade.php ENDPATH**/ ?>