Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <section>
- <form id="codigobarras" class="codigo">
- <input type="text" name="codigo" id="codigo" placeholder="Escanear Codigo de Barras del DN" class="codigo"/>
- </form>
- <button class="btn btn-info " id="descargar" name="descargar">Descargar <span class="glyphicon glyphicon-save"></span></button>
- </section>
- <section class="tsect">
- <table class="grilla" id="tabla">
- <thead>
- <tr>
- <th>Id</th>
- <th>NetApp Po</th>
- <th>Customer Np</th>
- <th>Qty</th>
- <th>Rev</th>
- <th>Boxes by Po</th>
- <th>Dn</th>
- <th>Create Date asn</th>
- <th>Shipping Address</th>
- <th>Description</th>
- <th>So Number</th>
- <th>Eliminar campo</th>
- </tr>
- </thead>
- <tbody id="registros">
- </tbody>
- </table>
- <script type="text/javascript">
- /* Tras cargar el documento posicionamos el cursor en el lector de código de barras */
- document.addEventListener('DOMContentLoaded', function() {
- let codigobarras = document.getElementById('codigobarras');
- /* Ponemos el foco en el campo "codigo" */
- codigobarras.codigo.focus();
- /* Capturamos el evento de envío de formulario (pulsar ENTER o pulsar Enviar) */
- codigobarras.addEventListener("submit", function(e) {
- /* Evitamos el envío real del formulario */
- e.preventDefault();
- /* Hacemos la llamada al API (busqueda.php o el API de ejemplo) */
- $.ajax({
- url: 'php/busqueda.php',
- method: 'post',
- data: {
- codigo: codigobarras.codigo.value,
- },
- })
- .done(function(datos) {
- /* Depuramos los datos recibidos */
- console.log( datos );
- /* Si no se devolvió ningún registro (false) debería hacerse algo */
- if (datos === false) {
- /* hacer algo */
- alert('No se encontró el código de barras');
- return;
- }
- /* Agregamos una fila con los datos obtenidos */
- $('#registros').append($('<tr>')
- .append($('<td>').append(datos.id, '<input type="checkbox" name="dn[]" value="append(datos.id)" checked>'))
- .append($('<td>').append( datos.net_app_po ))
- .append($('<td>').append( datos.costumer_np ))
- .append($('<td>').append( datos.qty ))
- .append($('<td>').append( datos.rev ))
- .append($('<td>').append( datos.boxes_by_po ))
- .append($('<td>').append( datos.dn ))
- .append($('<td>').append( datos.create_date_asn ))
- .append($('<td>').append( datos.shipping_address ))
- .append($('<td>').append( datos.description ))
- .append($('<td>').append( datos.so_no ))
- .append($('<td>').append( '<input type="button" class="btn btn-danger btn-sm" id="eliminar" value="Eliminar">'))
- );
- })
- .fail(function() {
- alert( "Error" );
- })
- .always(function() {
- /* Seleccionamos el texto para que se pueda sobreescribir por la siguiente lectura */
- $("input[name='codigo']").select();
- });
- });
- }, false);
- </script>
- </section>
- /*funcion para validar */
- $('document').ready(function(){
- $('#codigobarras #codigo').val();
- if(pallet_status >= 3){
- location.href = "seriales.html";
- }else{
- alert("El codigo escaneado aun no tiene confirmacion");
- }
- });
- <?php
- $servidor = 'localhost';
- $base_datos = 'net';
- $usuario = 'root';
- $clave = '';
- /* Dos métodos de poner el juego de caracteres en utf-8 */
- $conexion = new PDO(
- "mysql:host=${servidor};dbname=${base_datos};charset=utf8",
- $usuario,
- $clave,
- [
- PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
- ]
- );
- /* No es necesario y no es recomendable hacerlo así */
- /*$conexion->exec("SET CHARACTER SET utf8");*/
- /* Preparamos la consulta SQL */
- $res = $conexion->prepare('SELECT * FROM caratulasalida WHERE dn = :codigo');
- /* Asignamos el parámetro al valor enviado por POST */
- $res->bindValue(':codigo', $_POST['codigo'], PDO::PARAM_STR);
- /* Ejecutamos la consulta */
- $res->execute();
- /* Devolvemos el registro obtenido como respuesta en JSON */
- header("Content-type: application/json; charset=utf-8");
- echo json_encode($res->fetch(PDO::FETCH_ASSOC));
- ?>
- MariaDB [net]> show create table caratulasalida;
- +----------------------------------------------------+
- | Table | Create Table |
- +----------------------------------------------------+
- | caratulasalida | CREATE TABLE `caratulasalida` (
- `net_app_po` varchar(250) COLLATE utf8_bin NOT NULL,
- `costumer_np` varchar(250) COLLATE utf8_bin NOT NULL,
- `qty` int(11) NOT NULL,
- `rev` varchar(250) COLLATE utf8_bin NOT NULL,
- `boxes_by_po` int(11) NOT NULL,
- `pallet_status` int(11) NOT NULL,
- `dn` varchar(250) COLLATE utf8_bin NOT NULL,
- `create_date_asn` varchar(250) COLLATE utf8_bin NOT NULL,
- `shipping_address` varchar(250) COLLATE utf8_bin NOT NULL,
- `description` varchar(250) COLLATE utf8_bin NOT NULL,
- `so_no` int(11) NOT NULL,
- `id` int(11) NOT NULL AUTO_INCREMENT,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=256 DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
- +----------------+------------------------------------------------------------+
- MariaDB [net]> show create table scanserial;
- +-------------------------------------------+
- | Table | Create Table |
- +-------------------------------------------+
- | scanserial | CREATE TABLE `scanserial` (
- `dn` varchar(250) NOT NULL,
- `PO` varchar(250) NOT NULL,
- `serial_number` varchar(250) NOT NULL,
- `second` int(11) NOT NULL,
- `shiping_sn` varchar(250) NOT NULL,
- `model` varchar(250) NOT NULL,
- `id` int(11) NOT NULL AUTO_INCREMENT,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=260 DEFAULT CHARSET=latin1 |
- +-------------------------------------------------------------+
Add Comment
Please, Sign In to add comment