<div class="row">
  <div class="col-md-12">
		<div class="ibox">
			<div class="ibox-content">
        <div class="row">
          <div class="col-lg-12">
            <button id="nueva-entrada-guardar-csv-btn" type="button" class="btn btn-primary"><i class="fa fa-save" style=""></i> Guardar traslado</button>
          </div>
          <div class="col-lg-12 full-height-scroll" style="margin-top:15px;height:500px;overflow-x:auto;">
            <div class="col-md-12">
              <table class="table table-hover">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Tipo</th>
                    <th>Fecha</th>
                    <th>Ref</th>
                    <th>Producto</th>
                    <th>Cantidad</th>
                    <th>Precio</th>
                    <th>Bodega</th>
                    <th>Tienda</th>
                    <th></th>
                  </tr>
                </thead>
                <tbody>
                    <?php $bad = false;$i=1;foreach($entradas as $entrada):?>
                    <tr>
                        <th width="5%"><?php echo $i;?></th>
                        <th width="10%" class="text-center"><?php echo ($entrada["tipo"]==0)?"<div class='label label-info'>Entrada</div>":"<div class='label label-warning'>Salida</div>";?></th>
                        <th width="10%"><?php echo $entrada["fecha"];?></th>
                        <td width="10%"><?php echo utf8_decode($entrada["referencia"]);?></td>
                        <td width="15%"><?php echo utf8_decode($entrada["descripcion"]);?></td>
                        <td width="5%"><?php echo $entrada["cantidad"];?></td>
                        <td width="5%">$<?php echo $entrada["precio"];?></td>
                        <td width="15%"><?php echo $entrada["bodega"]." (".$entrada["total_bodega"].") ";?><i class="fa fa fa-level-<?php echo ($entrada["tipo"]==0)?"down":"up";?> text-<?php echo ($entrada["tipo"]==0)?"danger":"success";?>"></i></td>
                        <td width="15%"><?php echo $entrada["tienda"]." (".$entrada["total_tienda"].") ";?><i class="fa fa fa-level-<?php echo ($entrada["tipo"]==0)?"up":"down";?> text-<?php echo ($entrada["tipo"]==0)?"success":"danger";?>"></i></td>
                        <td width="10%"class="text-center">
                        <?php 
                            switch($entrada["estado"]):
                                case "Ok":
                                echo '<div class="label label-primary">Ok</div>';
                                break;
                                case "Referencia no encontrada":
                                //$bad = true;
                                echo '<div class="label label-danger">Referencia no encontrada</div>';
                                $bad = true;
                                break;
                                case "Referencia duplicada":
                                //$bad = true;
                                echo '<div class="label label-danger">Referencia duplicada</div>';
                                break;
                            endswitch;
                        ?>
                        </td>
                    </tr>
                    <?php $i++;endforeach;?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  var entradas = <?php echo json_encode($entradas);?>;
  <?php
    if($bad):
  ?>
  $("#nueva-entrada-guardar-csv-btn").prop("disabled",true);
  toastr.options = {
    "closeButton": true,
    "progressBar": true,
    "positionClass": "toast-top-right"
  }
  toastr.error('Hay errores en su archivo CSV, corregir o no podran cargarse al Sistema');
  <?php
    endif;
  ?>
  $("#nueva-entrada-guardar-csv-btn").on("click",function(){
    swal({
        title: "Guardar Traslado",
        text: " &iquest;Desea guardar el traslado cargada desde CSV?",
        type: "warning",
        html: true,
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Si, guardar",
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    },
    function(isConfirm){
        if (isConfirm) {
    $.post( "<?php echo base_url();?>productos/guardar_traslado", { entradas: entradas })
    .done(function( data ) {
    toastr.options = {
        "closeButton": true,
        "progressBar": true,
        "positionClass": "toast-top-right"
    }
    toastr.success('Traslado guardada exitosamente');
    $("#entradas-mode li:first a").click();
    });					
        }
    });
  });
</script>