{% extends "base.html.twig" %}
{% block headerStyles %}
{{ parent() }}
<style>
.cabecera_filtrada{
cursor:pointer;
min-width:150px;
}
.cabecera_filtrada:after{
content: "↓";
right: 0.5em;
float:right;
bottom: 0.9em;
display: block;
opacity: .3;
}
.cabecera_filtrada:before{
right: 1em;
content: "↑";
float:right;
bottom: 0.9em;
display: block;
opacity: 1;
}
</style>
{% endblock %}
{% block content %}
<div class="page-content">
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
<div class="breadcrumb-title pe-3">Productos</div>
<form action="{{ path("productos") }}" method="GET" class="ms-auto">
<div class=" d-sm-flex align-items-center ms-auto">
<div class="form-group pe-3">
<input type="text" name="s" id="s" class="form-control" placeholder="Buscar por nombre" value="{{ s }}"/>
</div>
<div class="form-group pe-3">
<button type="submit" class="btn btn-primary">Buscar</button>
</div>
</div>
</form>
<div class="ms-auto">
<!--a href="?{{ app.request.query.all | url_encode() }}" class="btn btn-primary mx-3">Exportar datos</a-->
<a href="{{ path('add_product' , { 'page': productos.currentPageNumber }) }}" class="btn btn-primary" ><i class="bx bx-plus"></i></a>
</div>
</div>
<div class="row">
<div class="card">
<div class="card-body">
<table class="table mb-0">
<thead>
<tr>
<th scope="col">Imagen</th>
<th scope="col" class="cabecera_filtrada" data-filter="sku">SKU</th>
<th scope="col" class="cabecera_filtrada" data-filter="name">Nombre</th>
<th scope="col">Categoría</th>
<th class="cabecera_filtrada" data-filter="price" scope="col">Precio</th>
<th scope="col">IVA</th>
<th scope="col" class="cabecera_filtrada" data-filter="globalStock">Stock</th>
<th scope="col">Web</th>
<th scope="col">Variacion principal</th>
<th scope="col">Variaciones</th>
<th scope="col">Detalles</th>
</tr>
</thead>
<tbody>
{% for prod in productos %}
<tr>
<th scope="row">{% if prod.getImage()!="" and prod.getImage() != null %}<img src="{{ asset('assets/images/products/'~prod.getImage()) }}" class="product-img-2"/>{% else %}<img src="{{ asset('assets/images/logos/logo-nubes.png') }}" class="product-img-2"/>{% endif %}</th>
<td>{{ prod.getSku() }}</td>
<td>{{ prod.getName() }}</td>
<td>{{ prod.getId() | getCatsName() }}</td>
<td>{{ prod.getPrice() }}</td>
<td>{{ prod.getIva() }}</td>
<td>{{ prod.getGlobalStock() }}</td>
<td>{% if(prod.getWpId()!="") %}Si{% else %}No{% endif %}</td>
<td>
{% set variacion = prod.getId() | getVariaciones() %}
{%for key_atr,variat in variacion %}
{{key_atr}} : {% for var_atr in variat %} | {{var_atr}} {% endfor %}<br/>
{%endfor%}
</td>
{%set variations = prod.getId() | getProductVariations() %}
<td>
{%for key,variation in variations %}
{{key}} : {% for var in variation %} | {{var}} {% endfor %}<br/>
{%endfor%}
</td>
<td>
<a href="{{ path('editProduct', { 'id': prod.getId(), 'page': productos.currentPageNumber }) }}" class="btn btn-outline-primary" ><i class="bx bx-pencil"></i></a>
<a href="{{ path('addProductVariation') }}?id={{ prod.getId() }}" class="btn btn-outline-success" ><i class="bx bx-add-to-queue"></i></a>
{%if (prod.getId() | getVariaconesNum()) > 0 %}
<a href="{{ path('viewProductVariations') }}?id={{ prod.getId() }}" class="btn btn-outline-warning" ><i class="bx bx-file-find"></i></a>
{%endif%}
<button onclick="generaEtiqueta({{prod.getId()}})" class="btn btn-outline-dark" ><i class="bx bx-label"></i></button>
<button data-bs-toggle="modal" data-bs-target="#deleteItem" onclick="jQuery('#delete_item_id').val({{prod.getId()}})" class="btn btn-outline-danger" ><i class="bx bx-trash"></i></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="mt-3 col-md-12 text-center align-content-center">
{{ knp_pagination_render(productos) }}
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block modals %}
<div class="modal fade" id="addItem" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Añadir Cliente</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" >
</div>
</div>
</div>
</div>
<div class="modal fade" id="deleteItem" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header ">
<h5 class="modal-title" id="exampleModalLabel">Eliminar Producto</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="{{ path('deleteProduct') }}" method="POST">
<div class="modal-body text-center" >
<h3>¿Estas seguro que deseas eliminar el producto?</h3>
<p class="text-muted">Esta acción no se puede revertir</p>
<input type="hidden" id="delete_item_id" name="id" value=""/>
<input type="hidden" name="page" value="{{ productos.currentPageNumber }}"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-danger">Eliminar</button>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
{% block footerScripts %}
{{ parent() }}
<script>
var orden = "{{orden}}";
$(document).ready(function(){
$(".cabecera_filtrada").click(function(){
var query = "";
if(orden == "ASC"){
orden = "DESC";
}else{
orden = "ASC";
}
var filter = $(this).data("filter");
{%set arr = app.request.query.all%}
{%set arr2 = arr | filter((v, k)=> k !="orden") %}
{%set arr3 = arr2 | filter((v, k)=> k !="filter") %}
window.location.href="{{path('productos')}}?orden="+orden+"&filter="+filter+"&{{arr3 | url_encode |raw}}";
});
});
function deleteItem(){
var id = $("#delete_item_id").val();
window.location.href="{{ path('deleteProduct' , { 'page': productos.currentPageNumber }) }}?id="+id;
}
function generaEtiqueta(id){
$.ajax({
url:'{{path("printLabel")}}',
type:'POST',
async:false,
data: {id:id },
success:function(html){
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write(html);
mywindow.document.close();
mywindow.focus();
setTimeout(mywindow.print(),2000);
//mywindow.close();
}
});
}
</script>
{% endblock %}