@include('forms.fbncheader')
@include('forms.fdatatables')


{!! Html::style('css/jquery-ui.structure.min.css') !!}
{!! Html::style('css/jquery-ui.theme.min.css') !!}



<div style="background-color:rgba(255,182,193,.2);"  
    class="col-lg-max col-lg-offset-1 container-fluid">

<div style="padding-left:0px" class="col-lg-max">
     <div class="row" style="">   
        <div class="col-xs-1" style="padding-left:0px;">
           {!! Html::image("img/entreprise_med.png", 
                "Employeurs", 
                array( 'width'=>'100%',
                    "style"=>"padding:4px" ))
            !!} 
        </div>
        <div class="col-xs-10" style="padding-left:0px;">
            <h1 style="margin-top:2px;">
                 Mises en demeure<small> - Employeurs Actifs</small>
            </h1>
        </div>


        <div class="row col-xs-2">
            {!! Form::label('annee', 'Année :' ) !!}
            {!! Form::select('exercice',$exercices,$exercice,
                [
                    'id' => 'exercice_id','class' => 'form-control selectpicker',
                    'data-width' => "100%",'style' => 'font-weight:bold;'
                ]
            ) 
            !!}
            <script>
                $(document).ready(function() {
                    $('#exercice_id').on('change', function() {
                        location.href="{!! url('/recouvrement/med_prepa/') !!}/"
                            +$('#exercice_id').val();
                    });
                });
            </script>
        </div>

    </div>
</div>

<div class='col-lg-max' style="padding-top:5px">
    <div class="table-responsive" >
        <table id="_table" style="background-color:white"  
            class="table table-condensed table-striped table-hover table-bordered">
            <thead>
                <tr>
                    <th width='1%'>N°</th>
                    <th>Nom</th>
                    <th width='10%'>Adresse</th>
                    <th width='1%'>Ile</th>
                    <th width='1%'>NbSal</th>
                    <th width='1%'>Date<br>1er Immat.</th>
                    <th width='5%'>Masse<br>Derniers Salaires</th>
                    <th width='5%'>Dernier<br/>mois</th>
                    <th width='5%'>Mois<br>Manquants</th>
                    <th width='5%'>Cotis.<br>Manquante</th>
                    <th width='5%'>Maj</th>
                    <th width='5%'>Total</th>
                    <th width='1%'>Mise en<br>demeure</th>
                    <th width='1%'></th>
                </tr>
            </thead>
 
            <tbody>
                @foreach ($employeurs as $employeur)
                <?php
                    $masse_dernier=$employeur->getMasseDerniersSalaires($exercice);

                    $masse_dernier=0;
                    $mois_manquants=0;
                    $dernier_mois="";
                    $taux_total=0;
                    $cotis=0;

                    if($exercice=="")
                    /**/
                    $mois_manquants=$employeur->getNbMoisManquantsSalaires($exercice);
                    $dernier_mois=$employeur->DateDernierSalaire;
                    $taux_total=$taux;
                    $cotis=round($masse_dernier*$taux_total/100,0);
                    $cotis=round($cotis*$mois_manquants);
                    
                    if(!is_numeric($exercice)) $exercice=0;
                    $maj=$employeur->getMajoration($exercice);//round($prc_maj*$cotis/100);

                    $numero="";

                ?>
                <tr>
                    <td>
                        {!! str_pad($employeur->id,4,'0',STR_PAD_LEFT) !!}
                    </td>
                    <td nowrap>
                        <a href="{!! url('tiers/employeurs/')."/".$employeur->id !!}" target="_blank">
                            {!! $employeur->NomReduit !!}
                        </a>
                    </td>
                    <td>{!! $employeur->adresse !!}</td>
                    <td>{!! $employeur->ile !!}</td>
                    <td>{!! $employeur->getNbEmployes($exercice) !!}</td>
                    <td align="right">{!! $employeur->date_deb !!}</td>
                    <td align="right">{!! $masse_dernier !!}</td>
                    <td align="right">{!! $dernier_mois !!}</td>
                    <td align="right">{!! $mois_manquants !!}</td>
                    <td align="right">{!! $cotis !!}</td>
                    <td align="right">{!! $maj !!}</td>
                    <td align="right">{!! $cotis+$maj !!}</td>
                    <td align="center">{!! $employeur->ListeMedHTML !!}</td>
                    <td align="right">
                        @if($cotis+$maj>0)
                        <a href="{!! url('recouvrement/med_create/')."/".$employeur->id !!}" 
                            class="btn btn-success pull-left" 
                            style="margin-right: 3px;"
                             target="_blank">
                            <span class="glyphicon glyphicon-plus">MED</span>
                        </a>
                        @endif

                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>

</div>




</body></html>

<script>
    $(document).ready(function() {

        var table =$('#_table').DataTable( {
            bAutoWidth: false,
            bPaginate: false,
            bInfo: true,
            bFilter: true,
            //deferRender:    true,
            scrollY:        "400px",
            scrollX:        true,
            scrollCollapse: 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": [
                    [0,'desc']
                ],

                "aoColumnDefs": [
                    { "sTypes": "numeric", "aTargets": [ 5,6,7 ] },
                    { bSortable: false, aTargets: [] },
                    { visible: false, targets: [] },
                ],


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

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

            } );



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


    } );
</script>



