Generate Bar Code

0

How about friends this time I have a problem, I am storing products in an inventory, but I need to integrate the option of barcode to give input and output to the products, I am using the library JSBarcodes but I would like you to generate the barcode from the code stored on my BD.

<table id="example1" class="table table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Cod. Barras</th>
                                    <th>Imagen</th>
                                    <th>Nombre</th>
                                    <th>Marca</th>
                                    <th>Presentacion</th>

                                    <th>Precio</th>
                                    <th>Precio de Compra</th>
                                    <th>Stock Min.</th>
                                    <th>Stock</th>

                                    <th>Categoria</th>
                                    <th>Opciones</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(!empty($productos)):?>
                                    <?php foreach($productos as $producto):?>
                                        <tr>
                                            <td><?php echo $producto->id;?></td>
                                             <!--echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); -->
                                             <td><svg id="barcode"><?php echo $producto->codigo_barras;?></svg></td>
                                            <td><img src="<?php echo base_url().'assets/imagenes_productos/'.$producto->imagen?>" alt="<?php echo $producto->nombre?>" style="width: 100px; " class="img-responsive"></td>           
                                            <td><?php echo $producto->nombre;?></td>
                                            <td><?php echo $producto->marca;?></td>
                                            <td><?php echo $producto->presentacion;?></td>

                                            <td><?php echo $producto->precio;?></td>
                                            <td><?php echo $producto->precio_compra;?></td>
                                            <?php if($producto->condicion == "1"):?>
                                                <td><?php echo $producto->stock_minimo;?></td>
                                                <?php if ($producto->stock <= $producto->stock_minimo): ?>
                                                    <td style="color: red;"><b><?php echo $producto->stock;?></b></td>
                                                <?php else:?>
                                                    <td style="color: green;"><b><?php echo $producto->stock;?></b></td>
                                                <?php endif ?>

                                            <?php else: ?>
                                                <td>N/A</td>
                                                <td>N/A</td>
                                            <?php endif;?>
                                            <td><?php echo $producto->categoria;?></td>
                                            <td>
                                                <div class="btn-group">
                                                    <button type="button" class="btn btn-info btn-view-producto" data-toggle="modal" data-target="#modal-default" value="<?php echo $producto->id;?>">
                                                        <span class="fa fa-search"></span>
                                                    </button>
                                                    <?php if($permisos->update == 1):?>
                                                    <a href="<?php echo base_url()?>mantenimiento/productos/edit/<?php echo $producto->id;?>" class="btn btn-warning"><span class="fa fa-pencil"></span></a>
                                                    <?php endif;?>
                                                    <?php if($permisos->delete == 1):?>
                                                    <a href="<?php echo base_url();?>mantenimiento/productos/delete/<?php echo $producto->id;?>" class="btn btn-danger btn-remove"><span class="fa fa-remove"></span></a>
                                                    <?php endif;?>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php endforeach;?>
                                <?php endif;?>
                            </tbody>
                        </table>

I have a script where I send the id:

  $('#barcode').JsBarcode("Codigo",{displayValue:true,fontSize:20});

This is the view of the Datatable:

I would like to see below the code that I have assigned to that product with its respective bar code. If I generate a barcode but I put the name, in the jQuery, instead of code that there could go the number for example 63278994643

This is the Datatable with the code that is in my BD and that I show it for an echo.

Now if you already generate it but it appears twice:

    
asked by WilsonicX 15.10.2018 в 23:42
source

1 answer

0

You can place the code within <td> like this:

<td><?php echo $producto->codigo_barras;?><svg id="barcode"></svg></td>

Then you capture it in jQuery and assign it like this:

var codigo = $("#barcode").parent().text();
var svg = $("#barcode").html();
$('#barcode').parent().html(svg);
$('#barcode').JsBarcode(codigo,{displayValue:true,fontSize:20});
    
answered by 15.10.2018 в 23:53