<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

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

    oTable = $('#SLData').dataTable({

        "aaSorting": [[1, "desc"]],
        "aLengthMenu": [[10, 25, 50, 100, -1],
                        [10, 25, 50, 100, "<?=lang('all')?>"]],
        "iDisplayLength": <?=$Settings->rows_per_page?>,

        'bProcessing': true,
        'bServerSide': true,

        // ====== NUEVO SOURCE ======
        'sAjaxSource': '<?= admin_url('fel/getFelInvoices'); ?>',

        'fnServerData': function (sSource, aoData, fnCallback) {

            aoData.push({
                "name": "<?=$this->security->get_csrf_token_name()?>",
                "value": "<?=$this->security->get_csrf_hash()?>"
            });

            $.ajax({
                'dataType': 'json',
                'type': 'POST',
                'url': sSource,
                'data': aoData,
                'success': fnCallback
            });
        },

        'fnRowCallback': function (nRow, aData) {
            nRow.id = aData[0];
            return nRow;
        },

        "aoColumns": [

    {
        "bSortable": false,
        "mRender": function (data, type, row) {
            return '<input type="checkbox" class="checkbox" name="val[]" value="' + row[0] + '">';
        }
    },

    null, // fecha
    null, // ticket
    null, // NIT
    null, // cliente
    null, // serie
    null, // numero
    null, // anulada
    null, // nota de credito
    {"mRender": currencyFormat}, // total

    {"bSortable": false} // acciones
]


    })
});

// =====================================
// ABRIR NOTA DE CREDITO EN MODAL
// =====================================
$(document).on('click', '.btn-ncre', function(e){

    e.preventDefault();

    var id = $(this).data('id');

    var url = "<?= admin_url('fel/view_ncre/') ?>" + id;

    $('#myModal .modal-body').html(
        '<div class="text-center"><i class="fa fa-spinner fa-spin"></i> Cargando...</div>'
    );

    $('#myModal').modal('show');

    $('#myModal .modal-body').load(url);

});

// =====================================
// ABRIR FACTURA (TICKET) EN MODAL
// =====================================
$(document).on('click', '.btn-view', function(e){

    e.preventDefault();

    var id = $(this).data('id');

    var url = "<?= admin_url('fel/view/') ?>" + id;

    $('#myModal .modal-title').html('Factura');

    $('#myModal .modal-dialog').css('max-width','480px');

    $('#myModal .modal-body').html(
        '<div class="text-center"><i class="fa fa-spinner fa-spin"></i> Cargando factura...</div>'
    );

    $('#myModal').modal('show');

    $('#myModal .modal-body').load(url);

});

</script>


<?php if ($Owner || $GP['bulk_actions']) {
    echo admin_form_open('fel/actions', 'id="action-form"');
} ?>


<div class="box">

<div class="box-header">
    <h2 class="blue">
        <i class="fa-fw fa fa-file-text"></i>
        Facturas FEL
    </h2>
</div>


<div class="box-content">
<div class="row">
<div class="col-lg-12">

<p class="introtext">Listado de facturas certificadas</p>

<div class="table-responsive">

<table id="SLData"
       class="table table-bordered table-hover table-striped">

<thead>
<tr>

<th style="width:30px;text-align:center">
<input class="checkbox checkft" type="checkbox"/>
</th>

<th>Fecha</th>
<th>Ticket</th>
<th>NIT</th>
<th>Cliente</th>
<th>Serie</th>
<th>Numero</th>
<th>Anulada </th>
<th>NCRE </th>
<th>Total</th>
<th style="width:80px;text-align:center">Acciones</th>

</tr>
</thead>

<tbody>
<tr>
<td colspan="10" class="dataTables_empty">
<?= lang('loading_data'); ?>
</td>
</tr>
</tbody>


<tfoot class="dtFilter">
<tr class="active">

<th style="width:30px;text-align:center">
<input class="checkbox checkft" type="checkbox"/>
</th>

<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>


</tr>
</tfoot>

</table>

</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">

      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Nota de crédito</h4>
      </div>

      <div class="modal-body"></div>

    </div>
  </div>
</div>

<?php if ($Owner || $GP['bulk_actions']) { ?>

<div style="display:none;">
<input type="hidden" name="form_action" id="form_action"/>
<?= form_submit('performAction','performAction','id="action-form-submit"') ?>
</div>

<?= form_close() ?>

<?php } ?>

