<div class="container col d-flex justify-content-center">
   <div class="row">
      <div class="col-lg-12">
         <div class="card shadow-lg p-3 mb-5 bg-white ">
            <div class="card-header">
               <h3> Apertura de Turno </h3>
            </div>
            <div class="card-body">
               <!-- COMIENZO DEL FORMULARIO -->
               <form id="turnoopen01" action="/links/edit-turno" method="POST" class="needs-validation" novalidate>
                  <div class="form-row">
                     <!-- LABELS E INPUTS DEL LA PRIMERA FILA  -->

                     <!-- LABELS E INPUTS DE  LA FECHA -->

                     <div class="col-md-3 mb-3">
                        <label class="font-weight-bold" for="fecha">Fecha</label>
                        <input name="fecha" type="date" class="form-control" id="id-fecha" placeholder=""
                           value="{{lista.3.newParam.la_fecha}}" required>
                        <div class="valid-feedback"></div>
                        <div class="invalid-feedback">Complete el campo.</div>
                     </div>

                     <div class="col-md-2 mb-3">
                        <label class="font-weight-bold" for="turno">Turno</label>
                        <select name="turno" class="custom-select" required>
                           <option value="{{lista.3.newParam.turno}}" selected="selected">{{lista.3.newParam.horarios}}</option>
                           {{#each lista}}
                           {{#each lista_turnos}}
                           <option value={{id_turnos}}>{{horarios}}</option>
                           {{/each}}

                           {{/each}}

                        </select>
                     </div>
                     <div class="col-md-3 mb-3">
                        <label class="font-weight-bold"        for="area">Area</label>
                        <input class="form-control" type="text"  id="area"   value = "{{lista.3.newParam.nombdpto}}"   name="area" readonly>                     
                     </div>
<!--  Reversar en caso de que sea necesario -->
                  <!--   <div class="col-md-3 mb-3">
                        <label class="font-weight-bold"        for="area">Area</label>
                        <select name="area" class="custom-select"   onchange="cambioarea('0')"  required>
                           <option value="{{lista.3.newParam.dpto}}" selected="selected">{{lista.3.newParam.nombdpto}}</option>
                           {{#each lista}}
                           {{#each lista_areas}}
                           <option value={{id_dpto}}>{{nombre}}</option>
                           {{/each}}
                           {{/each}}
                        </select>
                     </div>   -->
<!--  Reversar en caso de que sea necesario -->

                     <div class="col-md-3 mb-3">
                        <label class="font-weight-bold"        for="area">grupo</label>
                        <select name="grupo" class="custom-select"   onchange="cambiogrupo('0')"  required>
                           <option value="{{lista.3.newParam.id_grupo}}" selected="selected">{{lista.3.newParam.nombre_grupo}}</option>
                           {{#each lista}}
                           {{#each lista_grupos}}                          
                           <option value="{{id_grupo}}" >{{descripcion}}</option>
                           {{/each}}
                           {{/each}}
                           <option value="999"   >Todos</option>
                        </select>
                     </div>


                    <div class="col-md-3 mb-3">
                      <label class="font-weight-bold" for="desformula">Supervisor</label> 
                      <div class="input-group">
                        <input class="form-control" type="text" placeholder="" id="desformula"   name="supervisorname" readonly  value = "{{user.fullname}}" >                     
                      </div>
                    </div>

                      
                      <div class="input-group">
                         <input type="hidden"  name="idregistro" value= "{{lista.3.newParam.idreg}}" >
                        <input type="hidden"  class="form-control"  name="indextable" >                         
                        <input type="hidden"  class="form-control"  name="tipo_de_submit"  value=0 >
                        <input type="hidden"   class="form-control"  name="tablamaquinas"  value=0 >
                        <input type="hidden"   class="form-control"  name="inputtabladetalle" > 
                        <input type="hidden"  class="form-control"    name="Id_registro"  value = "{{lista.3.newParam.idreg}}" > 
                        <input type="hidden"  class="form-control"   name="tabladeeliminados"  value = "" > 
                        <input type="hidden"  class="form-control"   name="id_dpto"  value = "{{lista.3.newParam.dpto}}" > 
                        
                      </div>


                  </div> <!-- FIN DE LABELS E INPUTS DEL LA PRIMERA FILA  -->

                  <div class="form-row">
                            <div class="col-md-2 mb-3">
                            <label class="font-weight-bold" for="cliente">Maquina</label>
                            <div class="input-group">
                                <input type="text" class="form-control"  name="idmaquina-1974" id = "Idmaquinact1978"    onkeypress="return false;">
                                <div class="input-group-append">
                                <button href="#" class="btn btn-secondary"  id = "btn-maquinact"  data-toggle="modal" data-target="#myModal9"  type="button"><i class="fa fa-search"></i> 
                                </button>
                                </div>  
                            </div>
                            </div>

                            <div class="col-md-6 mb-3">
                            <label class="font-weight-bold" for="descliente">Descripcion</label> 
                            <div class="input-group">
                                <input class="form-control" type="text"   readonly id="desmaquinaid-88" name="des-maquina88" >                     

                                <button type="button" id="btnCrear" class="btn btn-outline-primary   mt-8"    onclick="Add_new_Maquina()"><i class='fas fa-plus-circle'  ></i> </button> 
                            </div>
                            </div>


                  </div>  <!-- FIN DE LABELS E INPUTS DEL LA segunda FILA  -->


                 <div class="form-row">
                    <div style="height: 400px;overflow: scroll;"> 
                      <div class="col">
                         <table id="tabla123" class="table table-hover"   class="table table-responsive" class="table table-fit" >
                            
                              <thead>
                                 <tr >
                                    <th  style="display:none">Rowid</th>
                                    <th  style="display:none">ID</th>
                                    <th  style="display:none" >ID unico</th>
                                    <th   width="10%">Descripcion</th>
                                    <th   width="15%" >#Orden</th>
                                    <th   width="45%" >Producto</th>
                                    <th   width="15%" >Operador</th>
                                    <td colspan="2"  class="text-center  font-weight-bold" >Ayudantes</td>
                                    <th   class="text-center" >Acciones</th>
                                 </tr>
                              </thead>
                              <tbody>
                                    {{#each lista}}
                                    {{#each lista_detalle}}
                                    <tr>
                                       <td style="display:none"  > {{RowId}} </td> 
                                       <td style="display:none">{{id_maquina}} </td>
                                       <td style="display:none">{{id_unico}} </td>
                                       <td>{{maquina}} </td>
                                       <td> <div class="input-group"> <input type="text" class="form-control"  name="numorden"  value= {{orden}}  > <div class="input-group-append"> <button href="#" class="btn btn-secondary"  data-toggle="modal" data-target="#modalPlanes" type="button"> <i class="fa fa-search"></i> </button> </div> </div> </td>
                                       
                                       <td> <input class="form-control" type="text"  id="des-orden"  name="des-orden" readonly  value =  {{descripcion_articulo}}  > </td>

                                       <td>  <select id="oper01" name="operador"  class="custom-select"  > <option value= selected="selected"></option>  <option value=></option>  </select>   </td> 

                                       <td> <select  id="ayudan01" name="ayudante1" class="custom-select" > <option value=" " selected="selected"></option>   <option value=></option>  </option>  </select>   </td> 
                                       <td>  <select id="ayudan02" name="ayudante2" class="custom-select" > <option value=" " selected="selected"></option>   <option value=></option> </option>  </select> </td> 
                                       <td class="text-center"> <a class="delete" title="Delete" data-toggle="tooltip"><i class="fas fa-trash"></i></a> </td>  </td>
                                    </tr>
                                    {{/each}}
                                    {{/each}}
                              </tbody>
                        </table>


                      </div>
                    </div>

                 </div>

                  <div class="form-row">
                        <div style="display:none" >
                        <table id="tabledeleted" >
                              <thead>
                                 <tr>
                                    <th>ID maquina</th>
                                    <th >ID unico</th>
                                 </tr>
                              </thead>   
                              <tbody>

                              </tbody>    
                        </table>
                        </div>                     
                  </div>

                  <!-- FIN DE la TERCERA linea ROW-->

                  
                  <div class="form-row">
                     <!-- COMIENZO DE la CUARTA linea ROW-->
                            <div class="col-md-8 mb-3">
                              <div class="input-group">                               

                              </div>
                            </div>
                            <div class="col-md-2 mb-3">
                              <div class="input-group">                               
                               <input type="button" id="btn-grabar" value="Save" name="register" class="btn btn-success accept"/>
                              </div>
                            </div>
                            <div class="col-md-2 mb-3">
                              <div class="input-group">                               
                                <button id="btnCerrar" class="btn btn-danger" onclick= "cambiarstatus(1)"  >Cancelar</button>                              
                              </div>
                            </div>
                  </div>


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

<script src="/jquery/dist/jquery.js"></script>


<script>
function mostrarcatalogoMaquinas() {
     var id_dpto = document.getElementsByName('id_dpto')[0].value;
     var url1 = "/links/listar-maquinasctl9/" + id_dpto ;
     var table9 = $('#tablamaquinas').DataTable();
         table9.clear()
         table9.draw();
         $.ajax({
                type: "GET",
                url: url1,
                datatype: "json",
                traditional: true
          })
            .done(function (data) {
                  var groupColumn = 0;        
                  var table = $('#tablamaquinas').DataTable({
                      data:  data,
                      destroy: true,
                  "columns":[                      
                  { "data": "id_maquina", "title": "ID" },
                  { "data": "codigo", "title": "Codigo" },
                  { "data": "descripcion", "title": "Descripcion" },
                  { "defaultContent": "<div class='text-center'> <div class='btn-group'> <button class='btn btn-info btn-sm btnAceptar-ctlmaquina'>Seleccionar</button> </div> </div>" }
                  ],
                  pageLength : 10,
                  lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']],
                  "scrollY": 400,
                  "scrollX": true,
                  "order": [[ groupColumn, 'asc' ]],
                  "displayLength": 25
                  }); // fin de datatable declaracion     
                  $('#myModal9').on('shown.bs.modal', function (e) {
                        $('#tablamaquinas').DataTable().draw(true);
                  })  
              });
}

</script>


<script>

$(document).ready(function() { 
    $('form #btn-grabar').click(function(e) {
        cambiarstatus(0); 
        var ord_sinop = validarordenoperador();
        if ( ord_sinop <=0) {
               // realizo el submit para grabar 
               anexartabla();
              // toastr.success('Registro Grabado exitosamente', 'Producción Indesplast', {timeOut: 2000})     
        } else {
          toastr.error('Falta asignar operador a la maquina', 'Producción Indesplast', {timeOut: 2000})
        }
    });

//****
    var rows = document.getElementById('tabla123').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
    for (i = 0; i < rows.length; i++) {
        rows[i].onclick = function() {
          // document.getElementsByName('indextable')[0].value = (this.rowIndex - 1 );
          // alert(document.getElementsByName('indextable')[0].value  + '  en el evento 22 2')
        }
    }
///***************

$('form #btn-maquinact').click(function(e) {
    mostrarcatalogoMaquinas();    
 });

//*********
});
//***************
$(document).on("click", ".delete", function(){
      var fila = $(this).closest("tr");
      var id_maquina = parseInt(fila.find('td:eq(1)').text());
      var id_unico = fila.find('td:eq(2)').text();
      //alert(id_unico + "gdfgsdfgfsdg")
      addeliminados(id_maquina,id_unico) ;
      $(this).parents("tr").remove();
		$(".add-new").removeAttr("disabled");

//*****

});

//*******************
  function validarordenoperador(){
         var table2 = document.getElementById('tabla123');
         var numero_de_ordenes_sin_operador = 0;
         for(var r = 0; r < (table2.rows.length -1); r++) {
            var orden = document.getElementsByName('numorden')[r].value ;          
            //var orden = 0 ;
            orden = orden.trim();
            var operador =  parseInt('0' + validarslect (document.getElementsByName('operador')[r].value));
             
            if (orden.length > 0)       {
                 if (operador <= 0) {
                     numero_de_ordenes_sin_operador = numero_de_ordenes_sin_operador + 1;
                 }
            }
         } // fin del for

//***
        function validarslect(dataselec) {
           
           if (dataselec == 'selected="selected"') {
                    return '0'
           } {
                    return  dataselec
           }
        }

//***


         return numero_de_ordenes_sin_operador;
  }
//*******************
</script>


<script>

   function cambiarstatus(valor) {
      document.getElementsByName('tipo_de_submit')[0].value = valor;
   }

//*****************************************

function addeliminados( id_maquina, id_unico) {
   var  id_maq, unico , trHTML;
   id_maq = id_maquina; 
   unico = id_unico;
   //alert(unico)
   trHTML = '<tr><td>' + id_maq  + '</td><td>' + unico + '</td></tr>';
   $('#tabledeleted').append(trHTML);
}


</script>



<script>

   (function () {
      'use strict';
      window.addEventListener('load', function () {
         // Fetch all the forms we want to apply custom Bootstrap validation styles to
         cargarvalorestabla(0);
         
         var forms = document.getElementsByClassName('needs-validation');
         // Loop over them and prevent submission
         var validation = Array.prototype.filter.call(forms, function (form) {
            form.addEventListener('submit', function (event) {
               if (form.checkValidity() === false) {
                  if (parseInt(document.getElementsByName('tipo_de_submit')[0].value) <= 0) {
                      event.preventDefault();
                      event.stopPropagation();
                  }
                  
               }
               form.classList.add('was-validated');
            }, false);
         });
      }, false);
   })();


</script>


<script>
//********
function Add_new_Maquina() {
        var trHTML = '';
        var id_maquina = document.getElementsByName('idmaquina-1974')[0].value;
        var descripcion = document.getElementsByName('des-maquina88')[0].value;
        var unico = '99'
        trHTML += '<tr> <td style="display:none">' + 0 + '</td>' + '<td style="display:none">' + id_maquina + '</td><td style="display:none">' + unico +  '</td><td>' + descripcion + '<td><div class="input-group"> <input type="text" class="form-control" placeholder="" name="numorden"  value=  ""  > <div class="input-group-append"> <button href="#" class="btn btn-secondary"  data-toggle="modal" data-target="#modalPlanes" type="button"> <i class="fa fa-search"></i> </button> </div> </div></td>' + '<td><input class="form-control" type="text" placeholder="" id="des-orden" name="des-orden" readonly></td>' + '<td><select name="operador" class="custom-select" > <option value="" ></option>  <option value=></option>  </select> </td>' + '<td><select name="ayudante1" class="custom-select" > <option value="" ></option> <option value=></option>  </select> </td>' + '<td><select name="ayudante2" class="custom-select" > <option value="" ></option> <option value="" ></option>  </select> </td><td class="text-center"> <a class="delete" title="Delete" data-toggle="tooltip"><i class="fas fa-trash"></i></a> </td>  </td></tr>';
        $('#tabla123').append(trHTML);
        cambiogrupo(0);
    var rows = document.getElementById('tabla123').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
    for (i = 0; i < rows.length; i++) {
        rows[i].onclick = function() {
           document.getElementsByName('indextable')[0].value = (this.rowIndex - 1 ); 
        }
    }
    document.getElementsByName('idmaquina-1974')[0].value = '';
    document.getElementsByName('des-maquina88')[0].value = ''; 


}
//*******
function cambioarea(value) {

var id_dpto = parseInt('0' + document.getElementsByName('area')[0].value);
var url1 = "/links/areas/" + id_dpto;

var table = document.getElementById("tabla123");


for(var i = table.rows.length - 1; i > 0; i--)
{
    table.deleteRow(i);
}

$.ajax({
    url: url1,
    type: "GET",
    dataType: "json",
    success: function (data) {
        //console.log(data);
        var trHTML = '';
        var unico = '99'
        $.each(data, function (i, item) {
           trHTML += '<tr> <td style="display:none">' + i + '</td><td style="display:none">' + item.id_maquina + '</td><td style="display:none">' + unico +  '</td><td>' + item.descripcion + '<td><div class="input-group"> <input type="text" class="form-control" placeholder="" name="numorden"  value=  ""  > <div class="input-group-append"> <button href="#" class="btn btn-secondary"  data-toggle="modal" data-target="#modalPlanes" type="button"> <i class="fa fa-search"></i> </button> </div> </div></td>' + '<td><input class="form-control" type="text" placeholder="" id="des-orden" name="des-orden" readonly></td>' + '<td><select name="operador" class="custom-select" > <option value="" ></option>  <option value=></option>  </select> </td>' + '<td><select name="ayudante1" class="custom-select" > <option value="" ></option> <option value=></option>  </select> </td>' + '<td><select name="ayudante2" class="custom-select" > <option value="" ></option> <option value="" ></option>  </select> </td><td class="text-center"> <a class="delete" title="Delete" data-toggle="tooltip"><i class="fas fa-trash"></i></a> </td>  </td></tr>';
        });
        cambiogrupo(0);
///**
    var rows = document.getElementById('tabla123').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
    for (i = 0; i < rows.length; i++) {
        rows[i].onclick = function() {
           document.getElementsByName('indextable')[0].value = (this.rowIndex - 1 );
        }
    }
//***


    },
    error: function (error) {
        console.log(`Error ${error}`);
    }
   
});

}

//************************
function cargarvalorestabla(value) {
     var id_reg = parseInt('0' + document.getElementsByName('Id_registro')[0].value);
     var url1 = "/links/detalleopenturno/" + id_reg;
         $.ajax({
            url: url1,
            type: "GET",
            dataType: "json",
            success: function (data) {
               var trHTML = '';
               $.each(data, function (i, item) {
                     document.getElementsByName('numorden')[i].value = item.orden;
                     document.getElementsByName('des-orden')[i].value = item.descripcion_articulo;
                     if ( parseInt(item.operador) > 0) {
                          var selectInnerHTML ='<option value="'+ item.operador + '" selected="selected" >' + item.nombre_operador + '</option>';
                          document.getElementsByName('operador')[i].innerHTML = selectInnerHTML ;

                          document.getElementsByName('operador')[i].innerHTML = selectInnerHTML +  '<select id="oper01"  name="operador" class="custom-select" > <option value={{lista.6.newParam.operador}} selected="selected">{{lista.6.newParam.nomboperador}}</option> {{#each lista}} {{#each operadores}} <option value={{id_trabajador}}>{{persona}}</option> {{/each}} {{/each}} </select> ';
                     } else {
                           document.getElementsByName('operador')[i].innerHTML = '<select id="oper01"  name="operador" class="custom-select" > <option value={{lista.6.newParam.operador}} selected="selected">{{lista.6.newParam.nomboperador}}</option> {{#each lista}} {{#each operadores}} <option value={{id_trabajador}}>{{persona}}</option> {{/each}} {{/each}} </select> ';
                     }
                     
                     if (parseInt(item.ayudante1) > 0 ) {
                          var selectInnerHTML_ayudante1 ='<option value="'+ item.ayudante1 + '" selected="selected" >' + item.nombre_ayudante1 + '</option>';
                          document.getElementsByName('ayudante1')[i].innerHTML = selectInnerHTML_ayudante1 ;
                          document.getElementsByName('ayudante1')[i].innerHTML = selectInnerHTML_ayudante1 +  '<select id="ayudan01" name="ayudante1" class="custom-select" > <option value={{lista.6.newParam.ayudante1}} selected="selected">{{lista.6.newParam.nombayudante1}}</option> {{#each lista}}  {{#each lista_trabajadores}} <option value={{id_trabajador}}>{{persona}}</option> {{/each}} {{/each}} </select>';
                     } else {
                          document.getElementsByName('ayudante1')[i].innerHTML = '<select id="ayudan01" name="ayudante1" class="custom-select" > <option value={{lista.6.newParam.ayudante1}} selected="selected">{{lista.6.newParam.nombayudante1}}</option> {{#each lista}}  {{#each lista_trabajadores}} <option value={{id_trabajador}}>{{persona}}</option> {{/each}} {{/each}} </select>';
                     }

                     if (parseInt(item.ayudante2) > 0 ) {
                          var selectInnerHTML_ayudante2 ='<option value="'+ item.ayudante2 + '" selected="selected" >' + item.nombre_ayudante2 + '</option>';
                          document.getElementsByName('ayudante2')[i].innerHTML = selectInnerHTML_ayudante2 ;
                          document.getElementsByName('ayudante2')[i].innerHTML = selectInnerHTML_ayudante2 + '<select id="ayudan02" name="ayudante2" class="custom-select" > <option value={{lista.6.newParam.ayudante1}} selected="selected">{{lista.6.newParam.nombayudante1}}</option> {{#each lista}}  {{#each lista_trabajadores}} <option value={{id_trabajador}}>{{persona}}</option> {{/each}} {{/each}} </select>' ;
                     } else {
                          document.getElementsByName('ayudante2')[i].innerHTML = '<select id="ayudan02" name="ayudante2" class="custom-select" > <option value={{lista.6.newParam.ayudante1}} selected="selected">{{lista.6.newParam.nombayudante1}}</option> {{#each lista}}  {{#each lista_trabajadores}} <option value={{id_trabajador}}>{{persona}}</option> {{/each}} {{/each}} </select>' ;
                     }
                     
                      var x = document.getElementById("tabla123").rows[i +1].cells;
                      x[0].innerHTML =   i ;

               });

///**
    var rows = document.getElementById('tabla123').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
    for (i = 0; i < rows.length; i++) {
        rows[i].onclick = function() {
           document.getElementsByName('indextable')[0].value = (this.rowIndex - 1 );
        }
    }
//***


            },
            error: function (error) {
               console.log(`Error ${error}`);
            }


            
         });


}


//*****************************

</script>

<script>

function cambiogrupo(value)   {
     var id_grupo = parseInt('0' + document.getElementsByName('grupo')[0].value);
     var url1 = "/links/trabadoresxgrupo/" + id_grupo;
         $.ajax({
            url: url1,
            type: "GET",
            dataType: "json",
            success: function (data) {
               var trHTMLayudante1 = '<select  name="ayudante1" class="custom-select" > <option value="" ></option>';
               var trHTMLayudante2 = '<select  name="ayudante2" class="custom-select" > <option value="" ></option>';
               var selectInnerHTML= '<select id="oper01"  name="operador" class="custom-select" >  <option value="" selected="selected"></option>' ;
               $.each(data, function (i, item) {
                     if (item.rol.trim() == 'Operador') {
                          selectInnerHTML += '<option value="' + item.id_trabajador + '">' + item.persona + '</option>';                                                   
                     } else {
                        trHTMLayudante1 += '<option value="' + item.id_trabajador + '">' + item.persona + '</option>';
                        trHTMLayudante2 +=  '<option value="' + item.id_trabajador + '">' + item.persona + '</option>';
                     }     
               });
               selectInnerHTML +=  '</select>';
               trHTMLayudante1 += '</select>';
               trHTMLayudante2 += '</select>';
               asignarvaloresselect(selectInnerHTML,trHTMLayudante1,trHTMLayudante2)

            },
            error: function (error) {
               console.log(`Error ${error}`);
            }


            
         });

}// fin de la funcion
//**************************//
function asignarvaloresselect(v_operador,v_ayudante1, v_ayudante2) {
   var table3 = document.getElementById('tabla123');
   for(var i = 0; i < table3.rows.length; i++) {
        document.getElementsByName('operador')[i].innerHTML = v_operador ;
        document.getElementsByName('ayudante1')[i].innerHTML = v_ayudante1 ;
        document.getElementsByName('ayudante2')[i].innerHTML = v_ayudante2 ;
   }
}

//*************************//
</script>

<script>

function anexartabla() {
      var TableData;
          TableData = storeTblValues()
          TableData = JSON.stringify(TableData);
      var json =  TableData;
      document.getElementsByName('tablamaquinas')[0].value = json;
      anexartablaEliminados();
      $("#turnoopen01").submit();
};

   // Handle form submission event
   $('#turnoopen01').on('submit', function(e){
      var form = this;
      
      var TableData;
          TableData = storeTblValues()
         TableData = JSON.stringify(TableData);
         var json =  TableData;
         document.getElementsByName('tablamaquinas')[0].value = json;
         anexartablaEliminados();
   });


function storeTblValues()
{
    var TableData = new Array();
    var IdsMaq = new Array();
    var desmaquina = new Array();
    var ids_unicos = new Array();
         var table2 = document.getElementById('tabla123');
         $("#tabla123 tbody tr").each(function (index) {
            var campo1 = "";
            var campo2 = "";
            var campos3 = "";
               $(this).children("td").each(function (index2) {
                  switch (index2) {
                     case 1:
                        campo1 = $(this).text().trim();
                        IdsMaq.push(campo1)
                        break;
                     case 2:
                        campo3 = $(this).text().trim();
                        ids_unicos.push(campo3)
                        break;

                     case 3:
                        campo2 = $(this).text().trim();
                        desmaquina.push(campo2)
                        break;
                           
                  }

               });

         });

         for(var r = 0; r < table2.rows.length; r++) {
          if (r < (table2.rows.length) - 1) {
             var orden = document.getElementsByName('numorden')[r].value ;
             TableData.push({
              "Id_maquina" : IdsMaq[r]
            , "Id_unidco" : ids_unicos[r]
            , "orden" : orden
            , "filtro": IdsMaq[r] + '-' +  desmaquina[r]
            , "Operador" : validarslect (document.getElementsByName('operador')[r].value)
            , "Ayudante1" : validarslect (document.getElementsByName('ayudante1')[r].value)
            , "Ayudante2" : validarslect(document.getElementsByName('ayudante2')[r].value)
                })                
          }          
        }

        function validarslect(dataselec) {
           
           if (dataselec == 'selected="selected"') {
                    return '0'
           } {
                    return  dataselec
           }
        }
    return TableData;
}

//**************************************************************************

function anexartablaEliminados() {
      var TableData;
          TableData = storeTblValuesEliminados()
          TableData = JSON.stringify(TableData);
      var json =  TableData;
      document.getElementsByName('tabladeeliminados')[0].value = json;
};

//**************************************************************************

function storeTblValuesEliminados()
{
    var TableData = new Array();
    var IdsMaqui = new Array();
    var Idsunicos = new Array();
         var table2 = document.getElementById('tabledeleted');
         $("#tabledeleted tbody tr").each(function (index) {
            var campo1 = "";
            var campo2 = "";
               $(this).children("td").each(function (index2) {
                  switch (index2) {
                     case 0:
                        campo1 = $(this).text().trim();
                        IdsMaqui.push(campo1)
                        break;
                     case 1:
                        campo2 = $(this).text().trim();
                        Idsunicos.push(campo2)
                        break;

                  }

               });

         });

        for(var r = 0; r < table2.rows.length; r++) {
          if (r < (table2.rows.length) - 1) {
            TableData.push({
              "Id_maquinaD" : IdsMaqui[r]
              ,"Id_unicoD" : Idsunicos[r]
               })      
          }          
        }
    return TableData;
}

//******************************************

</script>

{{>catalagodeplanes2 }}

{{>catalogomaquinas2 }}