Guest User

Untitled

a guest
Jun 19th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. <section>
  2. <form id="codigobarras" class="codigo">
  3. <input type="text" name="codigo" id="codigo" placeholder="Escanear Codigo de Barras del DN" class="codigo"/>
  4. </form>
  5. <button class="btn btn-info " id="descargar" name="descargar">Descargar <span class="glyphicon glyphicon-save"></span></button>
  6. </section>
  7.  
  8. <section class="tsect">
  9. <table class="grilla" id="tabla">
  10. <thead>
  11. <tr>
  12. <th>Id</th>
  13. <th>NetApp Po</th>
  14. <th>Customer Np</th>
  15. <th>Qty</th>
  16. <th>Rev</th>
  17. <th>Boxes by Po</th>
  18. <th>Dn</th>
  19. <th>Create Date asn</th>
  20. <th>Shipping Address</th>
  21. <th>Description</th>
  22. <th>So Number</th>
  23. <th>Eliminar campo</th>
  24. </tr>
  25. </thead>
  26. <tbody id="registros">
  27.  
  28. </tbody>
  29. </table>
  30.  
  31. <script type="text/javascript">
  32. /* Tras cargar el documento posicionamos el cursor en el lector de código de barras */
  33. document.addEventListener('DOMContentLoaded', function() {
  34. let codigobarras = document.getElementById('codigobarras');
  35. /* Ponemos el foco en el campo "codigo" */
  36. codigobarras.codigo.focus();
  37. /* Capturamos el evento de envío de formulario (pulsar ENTER o pulsar Enviar) */
  38. codigobarras.addEventListener("submit", function(e) {
  39. /* Evitamos el envío real del formulario */
  40. e.preventDefault();
  41. /* Hacemos la llamada al API (busqueda.php o el API de ejemplo) */
  42. $.ajax({
  43. url: 'php/busqueda.php',
  44. method: 'post',
  45. data: {
  46. codigo: codigobarras.codigo.value,
  47. },
  48. })
  49. .done(function(datos) {
  50. /* Depuramos los datos recibidos */
  51. console.log( datos );
  52. /* Si no se devolvió ningún registro (false) debería hacerse algo */
  53. if (datos === false) {
  54. /* hacer algo */
  55. alert('No se encontró el código de barras');
  56. return;
  57. }
  58. /* Agregamos una fila con los datos obtenidos */
  59. $('#registros').append($('<tr>')
  60. .append($('<td>').append(datos.id, '<input type="checkbox" name="dn[]" value="append(datos.id)" checked>'))
  61. .append($('<td>').append( datos.net_app_po ))
  62. .append($('<td>').append( datos.costumer_np ))
  63. .append($('<td>').append( datos.qty ))
  64. .append($('<td>').append( datos.rev ))
  65. .append($('<td>').append( datos.boxes_by_po ))
  66. .append($('<td>').append( datos.dn ))
  67. .append($('<td>').append( datos.create_date_asn ))
  68. .append($('<td>').append( datos.shipping_address ))
  69. .append($('<td>').append( datos.description ))
  70. .append($('<td>').append( datos.so_no ))
  71. .append($('<td>').append( '<input type="button" class="btn btn-danger btn-sm" id="eliminar" value="Eliminar">'))
  72. );
  73. })
  74. .fail(function() {
  75. alert( "Error" );
  76. })
  77. .always(function() {
  78. /* Seleccionamos el texto para que se pueda sobreescribir por la siguiente lectura */
  79. $("input[name='codigo']").select();
  80. });
  81. });
  82. }, false);
  83.  
  84. </script>
  85. </section>
  86.  
  87. /*funcion para validar */
  88. $('document').ready(function(){
  89. $('#codigobarras #codigo').val();
  90. if(pallet_status >= 3){
  91. location.href = "seriales.html";
  92. }else{
  93. alert("El codigo escaneado aun no tiene confirmacion");
  94. }
  95. });
  96.  
  97. <?php
  98. $servidor = 'localhost';
  99. $base_datos = 'net';
  100. $usuario = 'root';
  101. $clave = '';
  102. /* Dos métodos de poner el juego de caracteres en utf-8 */
  103. $conexion = new PDO(
  104. "mysql:host=${servidor};dbname=${base_datos};charset=utf8",
  105. $usuario,
  106. $clave,
  107. [
  108. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
  109. ]
  110. );
  111. /* No es necesario y no es recomendable hacerlo así */
  112. /*$conexion->exec("SET CHARACTER SET utf8");*/
  113. /* Preparamos la consulta SQL */
  114. $res = $conexion->prepare('SELECT * FROM caratulasalida WHERE dn = :codigo');
  115. /* Asignamos el parámetro al valor enviado por POST */
  116. $res->bindValue(':codigo', $_POST['codigo'], PDO::PARAM_STR);
  117. /* Ejecutamos la consulta */
  118. $res->execute();
  119. /* Devolvemos el registro obtenido como respuesta en JSON */
  120. header("Content-type: application/json; charset=utf-8");
  121. echo json_encode($res->fetch(PDO::FETCH_ASSOC));
  122.  
  123.  
  124.  
  125. ?>
  126.  
  127. MariaDB [net]> show create table caratulasalida;
  128. +----------------------------------------------------+
  129. | Table | Create Table |
  130. +----------------------------------------------------+
  131. | caratulasalida | CREATE TABLE `caratulasalida` (
  132. `net_app_po` varchar(250) COLLATE utf8_bin NOT NULL,
  133. `costumer_np` varchar(250) COLLATE utf8_bin NOT NULL,
  134. `qty` int(11) NOT NULL,
  135. `rev` varchar(250) COLLATE utf8_bin NOT NULL,
  136. `boxes_by_po` int(11) NOT NULL,
  137. `pallet_status` int(11) NOT NULL,
  138. `dn` varchar(250) COLLATE utf8_bin NOT NULL,
  139. `create_date_asn` varchar(250) COLLATE utf8_bin NOT NULL,
  140. `shipping_address` varchar(250) COLLATE utf8_bin NOT NULL,
  141. `description` varchar(250) COLLATE utf8_bin NOT NULL,
  142. `so_no` int(11) NOT NULL,
  143. `id` int(11) NOT NULL AUTO_INCREMENT,
  144. PRIMARY KEY (`id`)
  145. ) ENGINE=InnoDB AUTO_INCREMENT=256 DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
  146. +----------------+------------------------------------------------------------+
  147.  
  148. MariaDB [net]> show create table scanserial;
  149. +-------------------------------------------+
  150. | Table | Create Table |
  151. +-------------------------------------------+
  152. | scanserial | CREATE TABLE `scanserial` (
  153. `dn` varchar(250) NOT NULL,
  154. `PO` varchar(250) NOT NULL,
  155. `serial_number` varchar(250) NOT NULL,
  156. `second` int(11) NOT NULL,
  157. `shiping_sn` varchar(250) NOT NULL,
  158. `model` varchar(250) NOT NULL,
  159. `id` int(11) NOT NULL AUTO_INCREMENT,
  160. PRIMARY KEY (`id`)
  161. ) ENGINE=InnoDB AUTO_INCREMENT=260 DEFAULT CHARSET=latin1 |
  162. +-------------------------------------------------------------+
Add Comment
Please, Sign In to add comment