  <?php
  session_start();
  ?>
  <script>

    $(function () {
//ready
$('.select2').select2();
$("#monto").maskMoney({allowNegative: true, thousands:'.', decimal:',', affixesStay: false});

const Toast = Swal.mixin({
  toast: true,
  position: 'top-end',
  showConfirmButton: false,
  timer: 3000
});
$(document).ready(function(e) {
  $('#filtercam').hide();
  $('#list_bank_transactions_filter').append('<button class="btn btn-primary" id="addfilter"><i class="fas fa-filter"></i></button>');
});
var wp_filter = $("#filter").DataTable({
 searching: false,
 paging: false,
 ordering:  false,
 responsive: {
  details: {
    type: 'column'
  }
},
columnDefs: [ {
  className: 'control',
  orderable: false,
  targets:   0
} ],
autoWidth: true,
bProcessing: false,
bServerSide: false,
bInfo: false,
});
var wp_table = $("#list_bank_transactions").DataTable({
  responsive: {
    details: {
      type: 'column'
    }
  },
  columnDefs: [ {
    className: 'control',
    orderable: false,
    targets:   0
  } ],
  order: [ 1, 'asc' ],
  autoWidth: true,
  bProcessing: false,
  bServerSide: false,
  bInfo: false,
  columns: [
  { data: 'id' , render: function(data, type, row){
    return cel(data, row.id);
  }},
  { data: 'fecha' ,className: "tdcentrado"},
  { data: 'banco' ,className: "tdcentrado"},
  { data: 'titular' ,className: "tdcentrado"},
  { data: 'num_cuenta'  ,className: "tdcentrado"},
  { data: 'tipo_t'  ,className: "tdcentrado"},
  { data: 'transaccion'  ,className: "tdcentrado"},
  { data: 'numero_o'  ,className: "tdcentrado"},
  { data: 'monto'  ,className: "tdcentrado"},
  { data: 'motivo'  ,className: "tdcentrado"},
  { data: 'usuario'  ,className: "tdcentrado"},
  ],
});
//Funcion para consultar datos de usarios y llenar tabla//
function dataTable_init() {
  data = {'option':'<?php echo $decryp->encryptroute('view/bank_transactions/query_bank_transactions_delete')?>'};
  $.post('<?php echo $url_admin;?>core/process.php', data)
  .done(function(resp){
   wp_table = $("#list_bank_transactions").DataTable();
   wp_table.clear();
   $.each(resp.datos, function (k, v) {
    wp_table.row.add(v);
  });
   wp_table.draw();
   wp_table.columns.adjust().responsive.recalc();
 }).fail( function(jqXHR, textStatus, errorThrown) {
   var resp=jqXHR.responseJSON;
   var status=jqXHR.status;
   if(status == 401){
    toastr.error(resp.msg);
    logout();
  }else{
   toastr.error(resp.msg);
 }
});
}
//Funcion status//
function status(wpid, wpactive) {
  var status='<span class="badge badge-'+wpactive+'">'+wpid+'</span>'; 
  actions_cell = status;
  return actions_cell;
}

//Funcion para botones de accion//
function actions(wpid,img,pdf) {
  actions_cell = '<button class="btn btn-danger delete" data-data1="' + wpid + '" ><i class="fa fa fa-trash"></i></button>';
  return actions_cell;
}
//Campo vacio para responsive//
function cel(wpid, wpactive) {
  actions_cell = '';
  return actions_cell;
}

//Funcion para buscar datos por columnas//
function filterColumn (i) {
 wp_table
 .columns( i )
 .search($('#col'+i+'_filter').val(), true, false)
 .draw();
}
$('input.column_filter').on( 'keyup', function () {
  var data=$(this).data('column');
  filterColumn($(this).data('column'));
} );

$('#col1_filter').on( 'change', function () {
  filterColumn($(this).data('column'));
} );
//Funcion abrir seccion filtros //
$(document).on('click', '#addfilter', function(e){
  $('#filtercam').show();
  $("#addfilter").remove();
  $('#list_bank_transactions_filter').append(' <button class="btn btn-danger" id="closefilter"><i class="fas fa-window-close"></i></button>');
});
//Funcion cerrar seccion filtros//
$(document).on('click', '#closefilter', function(e){
  $('#filtercam').hide();
  $("#closefilter").remove();
  $('#list_bank_transactions_filter').append(' <button class="btn btn-primary" id="addfilter"><i class="fas fa-filter"></i></button>');
});


dataTable_init();


//END//
});
</script>