{% extends 'navbar.html.twig' %}
{% block title %}Articulos{% endblock %}
{% block content_user %}
<h5>Articulos</h5>
<style>
select.form-select {
}
</style>
{% set selectAplicaciones %}
<select class="form-control form-control-sm form-select change-aplication">
<option value=""></option>
{% for aplicacion in aplicaciones %}
<option value="{{ aplicacion.id }}">{{ aplicacion.nombre }}</option>
{% endfor %}
</select>
{% endset %}
<table id="example" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Activo</th>
<th>Codigo</th>
<th>Descripcion</th>
<th>Categoria</th>
<th>Unidad Medida</th>
<th>Aplicacion</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{% for articulo in articulos %}
<tr>
<td>
<div class="custom-control custom-switch">
<input data-id="{{ articulo.id }}" {{ articulo.activo ? "checked" : "" }} type="checkbox" class="status custom-control-input" id="chk{{ articulo.id }}"/>
<label class="custom-control-label pt-1" for="chk{{ articulo.id }}"></label>
</div>
</td>
<td>{{ articulo.codigo }}</td>
<td>{{ articulo.descripcion }}</td>
<td>{{ articulo.categoria }}</td>
<td>{{ articulo.unidaMedida }}</td>
<td id="art{{articulo.id}}" data-art="{{ articulo.id }}">{{ articulo.listaAplicaciones }}</td>
<td>{{ selectAplicaciones }}</td>
<td>
<a href="{{ path('app_almacen_articulo_edit', {'id': articulo.id}) }}" class="btn btn-success btn-sm">Modificar</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="5">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_almacen_articulo_new') }}" class="btn btn-default">Nuevo Articulo</a>
{% endblock %}
{% block javascripts_footer %}
{{ parent() }}
<script type="text/javascript">
const path = "{{ path('app_almacen_articulo_change_status', { id : '__ID__' }) }}";
$('.change-aplication').change(function(){
let select = $(this);
let idArticulo = select.closest('tr').find('td[data-art]').data('art');
let idAplicacion = select.val();
$.post("{{ path('app_almacen_articulo_add_aplicacion', { id : '__ID__' }) }}".replace('__ID__', idArticulo),
{ aplicacion: idAplicacion },
function(data){
if (data.ok) {
select.css('border-color', 'green');
$('#art' + idArticulo).html(data.aplicacion);
} else {
select.css('border-color', 'red');
}
});
});
$('.status').change(function(){
let btn = $(this);
let id = btn.data('id');
$.post(path.replace('__ID__', id),
function(data){
console.log(data);
});
});
$('#example').DataTable({
fixedHeader: true,
paging: true,
responsive: true,
language: {
url: '{{ asset('i18n/spanish.json') }}'
}
});
</script>
{% endblock %}