mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
trabajando en la vista de peiddos
This commit is contained in:
3882
logs/erp.log
3882
logs/erp.log
File diff suppressed because it is too large
Load Diff
@ -298,7 +298,7 @@ public class CartService {
|
||||
}
|
||||
|
||||
double totalBeforeDiscount = base + iva4 + iva21 + shipment;
|
||||
int fidelizacion = pedidoService.getDescuentoFidelizacion();
|
||||
int fidelizacion = pedidoService.getDescuentoFidelizacion(cart.getUserId());
|
||||
double descuento = totalBeforeDiscount * fidelizacion / 100.0;
|
||||
double total = totalBeforeDiscount - descuento;
|
||||
|
||||
|
||||
@ -1,9 +1,23 @@
|
||||
package com.imprimelibros.erp.pedidos;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PedidoRepository extends JpaRepository<Pedido, Long>, JpaSpecificationExecutor<Pedido> {
|
||||
|
||||
// Suma de "total" para un "createdBy" desde una fecha dada
|
||||
@Query("""
|
||||
SELECT COALESCE(SUM(p.total), 0)
|
||||
FROM Pedido p
|
||||
WHERE p.createdBy.id = :userId
|
||||
AND p.createdAt >= :afterDate
|
||||
""")
|
||||
Double sumTotalByCreatedByAndCreatedAtAfter(@Param("userId") Long userId,
|
||||
@Param("afterDate") LocalDateTime afterDate);
|
||||
}
|
||||
|
||||
@ -9,11 +9,14 @@ import java.util.Map;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.imprimelibros.erp.common.Utils;
|
||||
import com.imprimelibros.erp.direcciones.Direccion;
|
||||
import com.imprimelibros.erp.presupuesto.PresupuestoRepository;
|
||||
import com.imprimelibros.erp.presupuesto.dto.Presupuesto;
|
||||
import com.imprimelibros.erp.presupuesto.service.PresupuestoService;
|
||||
import com.imprimelibros.erp.users.UserService;
|
||||
import com.imprimelibros.erp.direcciones.DireccionService;
|
||||
import com.imprimelibros.erp.pedidos.PedidoLinea.Estado;
|
||||
|
||||
@Service
|
||||
public class PedidoService {
|
||||
@ -24,22 +27,25 @@ public class PedidoService {
|
||||
private final PedidoDireccionRepository pedidoDireccionRepository;
|
||||
private final DireccionService direccionService;
|
||||
private final UserService userService;
|
||||
private final PresupuestoService presupuestoService;
|
||||
|
||||
public PedidoService(PedidoRepository pedidoRepository, PedidoLineaRepository pedidoLineaRepository,
|
||||
PresupuestoRepository presupuestoRepository, PedidoDireccionRepository pedidoDireccionRepository,
|
||||
DireccionService direccionService, UserService userService) {
|
||||
DireccionService direccionService, UserService userService, PresupuestoService presupuestoService) {
|
||||
this.pedidoRepository = pedidoRepository;
|
||||
this.pedidoLineaRepository = pedidoLineaRepository;
|
||||
this.presupuestoRepository = presupuestoRepository;
|
||||
this.pedidoDireccionRepository = pedidoDireccionRepository;
|
||||
this.direccionService = direccionService;
|
||||
this.userService = userService;
|
||||
this.presupuestoService = presupuestoService;
|
||||
}
|
||||
|
||||
public int getDescuentoFidelizacion() {
|
||||
public int getDescuentoFidelizacion(Long userId) {
|
||||
// descuento entre el 1% y el 6% para clientes fidelidad (mas de 1500€ en el
|
||||
// ultimo año)
|
||||
double totalGastado = 1600.0; // Ejemplo, deberías obtenerlo del historial del cliente
|
||||
LocalDateTime haceUnAno = LocalDateTime.now().minusYears(1);
|
||||
double totalGastado = pedidoRepository.sumTotalByCreatedByAndCreatedAtAfter(userId, haceUnAno);
|
||||
if (totalGastado < 1200) {
|
||||
return 0;
|
||||
} else if (totalGastado >= 1200 && totalGastado < 1999) {
|
||||
@ -106,7 +112,7 @@ public class PedidoService {
|
||||
linea.setPresupuesto(presupuesto);
|
||||
linea.setCreatedBy(userId);
|
||||
linea.setCreatedAt(LocalDateTime.now());
|
||||
linea.setEstado(PedidoLinea.Estado.aprobado);
|
||||
linea.setEstado(getEstadoInicial(presupuesto));
|
||||
linea.setEstadoManual(false);
|
||||
pedidoLineaRepository.save(linea);
|
||||
|
||||
@ -226,4 +232,13 @@ public class PedidoService {
|
||||
|
||||
}
|
||||
|
||||
private Estado getEstadoInicial(Presupuesto p){
|
||||
|
||||
if(presupuestoService.hasMaquetacion(p)){
|
||||
return Estado.maquetacion;
|
||||
} else {
|
||||
return Estado.haciendo_ferro;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -65,7 +65,6 @@ public class PedidosController {
|
||||
|
||||
List<String> searchable = List.of(
|
||||
"id"
|
||||
// "client" no, porque lo calculas a posteriori
|
||||
);
|
||||
|
||||
// Campos ordenables
|
||||
@ -78,7 +77,7 @@ public class PedidosController {
|
||||
|
||||
Specification<Pedido> base = (root, query, cb) -> cb.conjunction();
|
||||
if (!isAdmin) {
|
||||
base = base.and((root, query, cb) -> cb.equal(root.get("userId"), currentUserId));
|
||||
base = base.and((root, query, cb) -> cb.equal(root.get("createdBy").get("id"), currentUserId));
|
||||
}
|
||||
String clientSearch = dt.getColumnSearch("cliente");
|
||||
String estadoSearch = dt.getColumnSearch("estado");
|
||||
|
||||
@ -388,7 +388,7 @@ public class Presupuesto extends AbstractAuditedEntity implements Cloneable {
|
||||
private Long proveedorRef2;
|
||||
|
||||
@Column(name = "is_reimpresion", nullable = false)
|
||||
private Boolean isReimpresion;
|
||||
private Boolean isReimpresion = false;
|
||||
|
||||
// ====== MÉTODOS AUX ======
|
||||
|
||||
|
||||
@ -1143,6 +1143,7 @@ public class PresupuestoService {
|
||||
if(presupuesto.getSelectedTirada() != null && presupuesto.getSelectedTirada().equals(tirada))
|
||||
presupuesto.setServiciosJson(new ObjectMapper().writeValueAsString(servicios));
|
||||
} catch (Exception ignore) {
|
||||
System.out.println("Error guardando servicios JSON: " + ignore.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1310,6 +1311,15 @@ public class PresupuestoService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Boolean hasMaquetacion(Presupuesto presupuesto) {
|
||||
if (presupuesto.getServiciosJson() != null && !presupuesto.getServiciosJson().isEmpty()) {
|
||||
if(presupuesto.getServiciosJson().contains("maquetacion")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// Métodos privados
|
||||
|
||||
@ -27,6 +27,7 @@ pdf.datos-maquetacion=Datos de maquetación:
|
||||
pdf.datos-marcapaginas=Datos de marcapáginas:
|
||||
|
||||
pdf.incluye-envio=El presupuesto incluye el envío a una dirección de la península.
|
||||
pdf.presupuesto-validez=Validez del presupuesto: 30 días desde la fecha de emisión.
|
||||
|
||||
pdf.politica-privacidad=Política de privacidad
|
||||
pdf.politica-privacidad.responsable=Responsable: Impresión Imprime Libros - CIF: B04998886 - Teléfono de contacto: 910052574
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
import { normalizeNumericFilter } from '../utils.js';
|
||||
|
||||
$(() => {
|
||||
|
||||
const csrfToken = document.querySelector('meta[name="_csrf"]')?.getAttribute('content');
|
||||
const csrfHeader = document.querySelector('meta[name="_csrf_header"]')?.getAttribute('content');
|
||||
if (window.$ && csrfToken && csrfHeader) {
|
||||
$.ajaxSetup({
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader(csrfHeader, csrfToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const language = document.documentElement.lang || 'es-ES';
|
||||
|
||||
const tablePedidos = $('#pedidos-datatable').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
orderCellsTop: true,
|
||||
pageLength: 50,
|
||||
lengthMenu: [10, 25, 50, 100, 500],
|
||||
order: [[5, 'desc']], // Ordena por fecha por defecto
|
||||
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
|
||||
responsive: true,
|
||||
dom: 'lBrtip',
|
||||
buttons: {
|
||||
dom: {
|
||||
button: {
|
||||
className: 'btn btn-sm btn-outline-primary me-1'
|
||||
},
|
||||
buttons: [
|
||||
{ extend: 'copy' },
|
||||
{ extend: 'csv' },
|
||||
{ extend: 'excel' },
|
||||
{ extend: 'pdf' },
|
||||
{ extend: 'print' },
|
||||
{ extend: 'colvis' }
|
||||
],
|
||||
}
|
||||
},
|
||||
ajax: {
|
||||
url: '/pedidos/datatable',
|
||||
method: 'GET',
|
||||
},
|
||||
order: [[0, 'desc']],
|
||||
columns: [
|
||||
{ data: 'id', name: 'id', orderable: true },
|
||||
{ data: 'cliente', name: 'createdBy.fullName', orderable: true },
|
||||
{ data: 'created_at', name: 'createdAt', orderable: true },
|
||||
{ data: 'total', name: 'total', orderable: true },
|
||||
{ data: 'estado', name: 'estado', orderable: true },
|
||||
{ data: 'actions', name: 'actions', orderable: false, searchable: false }
|
||||
|
||||
],
|
||||
});
|
||||
|
||||
tablePedidos.on("keyup change", ".input-filter", function () {
|
||||
const colName = $(this).data("col");
|
||||
const colIndex = tablePedidos.settings()[0].aoColumns.findIndex(c => c.name === colName);
|
||||
|
||||
if (colIndex >= 0) {
|
||||
tablePedidos
|
||||
.column(colIndex)
|
||||
.search(normalizeNumericFilter(this.value))
|
||||
.draw();
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
@ -0,0 +1,4 @@
|
||||
$(()=>{
|
||||
$(document,'.btn-view').on('click', function () {
|
||||
});
|
||||
})
|
||||
@ -46,7 +46,6 @@ $(() => {
|
||||
order: [[0, 'desc']],
|
||||
columns: [
|
||||
{ data: 'id', name: 'id', orderable: true },
|
||||
{ data: 'cliente', name: 'createdBy.fullName', orderable: true },
|
||||
{ data: 'created_at', name: 'createdAt', orderable: true },
|
||||
{ data: 'total', name: 'total', orderable: true },
|
||||
{ data: 'estado', name: 'estado', orderable: true },
|
||||
@ -66,8 +65,4 @@ $(() => {
|
||||
.draw();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('.btn-view').on('click', function () {
|
||||
});
|
||||
})
|
||||
@ -1683,7 +1683,7 @@ export default class PresupuestoWizard {
|
||||
|
||||
const body = {
|
||||
presupuesto: this.#getPresupuestoData(),
|
||||
save: !this.opts.canSave,
|
||||
save: this.opts.canSave,
|
||||
mode: this.opts.mode,
|
||||
servicios: servicios,
|
||||
datosMaquetacion: this.formData.servicios.datosMaquetacion,
|
||||
|
||||
@ -139,6 +139,7 @@
|
||||
<div class="footer">
|
||||
<div class="fw-bold fs-6 mb-1" th:text="#{pdf.incluye-envio}">El presupuesto incluye el envío a una dirección de la
|
||||
península.</div>
|
||||
<div class="fw-bold fs-6 mb-1" th:text="#{pdf.presupuesto-validez}">Validez del presupuesto: 30 días desde la fecha de emisión.</div>
|
||||
<div class="privacy">
|
||||
<div class="pv-title" th:text="#{pdf.politica-privacidad}">Política de privacidad</div>
|
||||
<div class="pv-text" th:text="#{pdf.politica-privacidad.responsable}">Responsable: Impresión Imprime Libros -
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<div th:fragment="pedido-linea (linea)">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<strong th:text="${linea.libro.titulo}">Título del libro</strong>
|
||||
<span class="text-muted" th:text="' - ' + #{pedido.linea.cantidad} + ': ' + ${linea.cantidad}"> - Cantidad: 1</span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<p>
|
||||
<strong th:text="#{pedido.linea.precio-unitario} + ': '"></strong>
|
||||
<span th:text="${#numbers.formatDecimal(linea.precioUnitario, 1, 'COMMA', 2, 'POINT')} + ' €'">10,00 €</span>
|
||||
</p>
|
||||
<p>
|
||||
<strong th:text="#{pedido.linea.precio-total} + ': '"></strong>
|
||||
<span th:text="${#numbers.formatDecimal(linea.precioTotal, 1, 'COMMA', 2, 'POINT')} + ' €'">10,00 €</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-4 text-end">
|
||||
<img th:if="${linea.libro.imagenPortadaUrl != null}" th:src="${linea.libro.imagenPortadaUrl}" alt="Portada del libro" class="img-fluid" style="max-height: 150px;" />
|
||||
<div th:if="${linea.libro.imagenPortadaUrl == null}" class="text-muted" style="height: 150px; display: flex; align-items: center; justify-content: center; border: 1px dashed #ccc;">
|
||||
<span th:text="#{pedido.linea.sin-imagen}">Sin imagen</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -32,30 +32,28 @@
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<table id="pagos-redsys-datatable" class="table table-striped table-nowrap responsive w-100">
|
||||
<table id="pedidos-datatable" class="table table-striped table-nowrap responsive w-100">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" th:text="#{pedido.table.id}">Num. Pedido</th>
|
||||
<th scope="col" th:text="#{pedido.table.cliente}">Cliente</th>
|
||||
<th scope="col" th:text="#{pedido.table.fecha}">Fecha</th>
|
||||
<th scope="col" th:text="#{pedido.table.importe}">Importe</th>
|
||||
<th scope="col" th:text="#{pedido.table.estado}">Estado</th>
|
||||
<th scope="col" th:text="#{pedido.table.acciones}">Acciones</th>
|
||||
<th class="text-start" scope="col" th:text="#{pedido.table.id}">Num. Pedido</th>
|
||||
<th class="text-start" scope="col" th:text="#{pedido.table.fecha}">Fecha</th>
|
||||
<th class="text-start" scope="col" th:text="#{pedido.table.importe}">Importe</th>
|
||||
<th class="text-start" scope="col" th:text="#{pedido.table.estado}">Estado</th>
|
||||
<th class="text-start" scope="col" th:text="#{pedido.table.acciones}">Acciones</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><input type="text" class="form-control form-control-sm input-filter" /></th>
|
||||
<th><input type="text" class="form-control form-control-sm input-filter" /></th>
|
||||
<th><input type="text" class="form-control form-control-sm input-filter" data-col="id" /></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th>
|
||||
<select class="form-control form-control-sm select-filter">
|
||||
<option value="" ></option>
|
||||
<option value="aprobado" th:text="#{pedido.estado.aprobado}">Aprobado</option>
|
||||
<option value="maquetacion" th:text="#{pedido.estado.maquetacion}">Maquetación</option>
|
||||
<option value="haciendo_ferro" th:text="#{pedido.estado.haciendo_ferro}">Haciendo ferro</option>
|
||||
<option value="produccion" th:text="#{pedido.estado.produccion}">Producción</option>
|
||||
<option value="terminado" th:text="#{pedido.estado.terminado}">Terminado</option>
|
||||
<option value="cancelado" th:text="#{pedido.estado.cancelado}">Cancelado</option>
|
||||
<select class="form-select form-select-sm input-filter" data-col="estado">
|
||||
<option value=""></option>
|
||||
<option th:text="#{pedido.estado.aprobado}" value="aprobado"></option>
|
||||
<option th:text="#{pedido.estado.maquetacion}" value="maquetacion"></option>
|
||||
<option th:text="#{pedido.estado.haciendo_ferro}" value="haciendo_ferro"></option>
|
||||
<option th:text="#{pedido.estado.produccion}" value="produccion"></option>
|
||||
<option th:text="#{pedido.estado.terminado}" value="terminado"></option>
|
||||
<option th:text="#{pedido.estado.cancelado}" value="cancelado"></option>
|
||||
</select>
|
||||
</th>
|
||||
<th></th> <!-- Acciones (sin filtro) -->
|
||||
@ -87,7 +85,7 @@
|
||||
<script th:src="@{/assets/libs/datatables/buttons.print.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/datatables/buttons.colVis.min.js}"></script>
|
||||
|
||||
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos-common.js}"></script>
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos.js}"></script>
|
||||
</th:block>
|
||||
</body>
|
||||
|
||||
@ -87,8 +87,8 @@
|
||||
<script th:src="@{/assets/libs/datatables/buttons.print.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/datatables/buttons.colVis.min.js}"></script>
|
||||
|
||||
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos.js}"></script>
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos-common.js}"></script>
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos-admin.js}"></script>
|
||||
</th:block>
|
||||
</body>
|
||||
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{imprimelibros/layout}">
|
||||
|
||||
<head>
|
||||
<th:block layout:fragment="pagetitle" />
|
||||
<th:block th:replace="~{imprimelibros/partials/head-css :: head-css}" />
|
||||
<th:block layout:fragment="pagecss">
|
||||
<link th:href="@{/assets/libs/datatables/dataTables.bootstrap5.min.css}" rel="stylesheet" />
|
||||
</th:block>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div th:replace="~{imprimelibros/partials/topbar :: topbar}" />
|
||||
<div th:replace="~{imprimelibros/partials/sidebar :: sidebar}"
|
||||
sec:authorize="isAuthenticated() and hasAnyRole('SUPERADMIN','ADMIN')">
|
||||
|
||||
<th:block layout:fragment="content">
|
||||
<div th:if="${#authorization.expression('isAuthenticated()')}">
|
||||
|
||||
<div class="container-fluid">
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="/"><i class="ri-home-5-fill"></i></a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page" th:text="#{pedido.module-title}">
|
||||
Pedidos</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="container-fluid">
|
||||
<th:block th:each="linea: ${pedidoLinea}">
|
||||
<div th:insert="~{imprimelibros/pedidos/pedidos-linea :: pedido-linea (linea=${linea})}"></div>
|
||||
</th:block>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</th:block>
|
||||
|
||||
<th:block th:replace="~{theme/partials/vendor-scripts :: scripts}" />
|
||||
<th:block layout:fragment="pagejs">
|
||||
<script th:inline="javascript">
|
||||
window.languageBundle = /*[[${languageBundle}]]*/ {};
|
||||
</script>
|
||||
|
||||
<script th:src="@{/assets/libs/datatables/datatables.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/datatables/dataTables.bootstrap5.min.js}"></script>
|
||||
|
||||
<!-- JS de Buttons y dependencias -->
|
||||
<script th:src="@{/assets/libs/datatables/dataTables.buttons.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/jszip/jszip.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/pdfmake/pdfmake.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/pdfmake/vfs_fonts.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/datatables/buttons.html5.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/datatables/buttons.print.min.js}"></script>
|
||||
<script th:src="@{/assets/libs/datatables/buttons.colVis.min.js}"></script>
|
||||
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos-common.js}"></script>
|
||||
<script type="module" th:src="@{/assets/js/pages/imprimelibros/pedidos/pedidos-admin.js}"></script>
|
||||
</th:block>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user