mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
añadido seeder para series de facturacion
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package com.imprimelibros.erp.configurationERP;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/configuracion/variables-sistema")
|
||||
@PreAuthorize("hasRole('SUPERADMIN')")
|
||||
public class VariablesController {
|
||||
|
||||
@GetMapping()
|
||||
public String list(Model model, Locale locale) {
|
||||
return new String();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.imprimelibros.erp.facturacion.service;
|
||||
|
||||
import com.imprimelibros.erp.common.Utils;
|
||||
import com.imprimelibros.erp.configurationERP.VariableService;
|
||||
import com.imprimelibros.erp.facturacion.*;
|
||||
import com.imprimelibros.erp.facturacion.dto.FacturaGuardarDto;
|
||||
import com.imprimelibros.erp.facturacion.dto.FacturaLineaUpsertDto;
|
||||
@ -46,6 +47,7 @@ public class FacturacionService {
|
||||
private final Utils utils;
|
||||
private final MessageSource messageSource;
|
||||
private final PedidoService pedidoService;
|
||||
private final VariableService variableService;
|
||||
|
||||
public FacturacionService(
|
||||
FacturaRepository facturaRepo,
|
||||
@ -56,7 +58,8 @@ public class FacturacionService {
|
||||
UserService userService,
|
||||
Utils utils,
|
||||
MessageSource messageSource,
|
||||
PedidoService pedidoService) {
|
||||
PedidoService pedidoService,
|
||||
VariableService variableService) {
|
||||
this.facturaRepo = facturaRepo;
|
||||
this.lineaFacturaRepository = lineaFacturaRepository;
|
||||
this.serieRepo = serieRepo;
|
||||
@ -66,16 +69,17 @@ public class FacturacionService {
|
||||
this.utils = utils;
|
||||
this.messageSource = messageSource;
|
||||
this.pedidoService = pedidoService;
|
||||
this.variableService = variableService;
|
||||
}
|
||||
|
||||
public SerieFactura getDefaultSerieFactura() {
|
||||
List<SerieFactura> series = serieRepo.findAll();
|
||||
if (series.isEmpty()) {
|
||||
|
||||
Long defaultSerieId = variableService.getValorEntero("serie_facturacion_default").longValue();
|
||||
SerieFactura serie = serieRepo.findById(defaultSerieId).orElse(null);
|
||||
if (serie == null) {
|
||||
throw new IllegalStateException("No hay ninguna serie de facturación configurada.");
|
||||
}
|
||||
// Aquí simplemente devolvemos la primera. Puedes implementar lógica más
|
||||
// compleja si es necesario.
|
||||
return series.get(0);
|
||||
return serie;
|
||||
}
|
||||
|
||||
public Factura getFactura(Long facturaId) {
|
||||
@ -128,6 +132,21 @@ public class FacturacionService {
|
||||
lineaFactura.setFactura(factura);
|
||||
lineasFactura.add(lineaFactura);
|
||||
}
|
||||
if(pedido.getEnvio() > 0){
|
||||
FacturaLinea lineaEnvio = new FacturaLinea();
|
||||
lineaEnvio.setDescripcion(messageSource.getMessage("facturas.lineas.gastos-envio", null, "Gastos de envío", locale));
|
||||
lineaEnvio.setCantidad(1);
|
||||
BigDecimal baseEnvio = BigDecimal.valueOf(pedido.getEnvio()).setScale(2, RoundingMode.HALF_UP);
|
||||
lineaEnvio.setBaseLinea(baseEnvio);
|
||||
BigDecimal iva21Envio = baseEnvio.multiply(BigDecimal.valueOf(0.21)).setScale(2, RoundingMode.HALF_UP);
|
||||
lineaEnvio.setIva21Linea(iva21Envio);
|
||||
lineaEnvio.setIva4Linea(BigDecimal.ZERO);
|
||||
lineaEnvio.setTotalLinea(baseEnvio.add(iva21Envio));
|
||||
lineaEnvio.setCreatedBy(pedido.getCreatedBy());
|
||||
lineaEnvio.setCreatedAt(Instant.now());
|
||||
lineaEnvio.setFactura(factura);
|
||||
lineasFactura.add(lineaEnvio);
|
||||
}
|
||||
factura.setLineas(lineasFactura);
|
||||
|
||||
factura = facturaRepo.save(factura);
|
||||
@ -264,7 +283,7 @@ public class FacturacionService {
|
||||
|
||||
private String buildNumeroFactura(String prefijo, long numero) {
|
||||
String pref = (prefijo == null) ? "" : prefijo.trim();
|
||||
String num = String.format("%07d", numero);
|
||||
String num = String.format("%05d", numero);
|
||||
return pref.isBlank() ? num : (pref + " " + num + "/" + LocalDate.now().getYear());
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,8 @@ public class PedidoLinea {
|
||||
ferro_cliente("pedido.estado.ferro_cliente", 8),
|
||||
produccion("pedido.estado.produccion", 9),
|
||||
terminado("pedido.estado.terminado", 10),
|
||||
cancelado("pedido.estado.cancelado", 11);
|
||||
enviado("pedido.estado.enviado", 11),
|
||||
cancelado("pedido.estado.cancelado", 12);
|
||||
|
||||
private final String messageKey;
|
||||
private final int priority;
|
||||
|
||||
@ -306,7 +306,7 @@ public class PedidoService {
|
||||
}
|
||||
|
||||
if (pedidoLinea.getEstado().getPriority() >= PedidoLinea.Estado.haciendo_ferro.getPriority() &&
|
||||
pedidoLinea.getEstado().getPriority() < PedidoLinea.Estado.terminado.getPriority()) {
|
||||
pedidoLinea.getEstado().getPriority() < PedidoLinea.Estado.enviado.getPriority()) {
|
||||
PedidoLinea.Estado estadoOld = pedidoLinea.getEstado();
|
||||
Map<String, Object> result = skApiClient.checkPedidoEstado(
|
||||
Long.valueOf(pedidoLinea.getPresupuesto().getProveedorRef2().toString()), locale);
|
||||
@ -406,7 +406,7 @@ public class PedidoService {
|
||||
}
|
||||
List<PedidoLinea> lineas = pedidoLineaRepository.findByPedidoId(pedidoId);
|
||||
for (PedidoLinea linea : lineas) {
|
||||
if (linea.getEstado() != PedidoLinea.Estado.terminado) {
|
||||
if (linea.getEstado() != PedidoLinea.Estado.terminado && linea.getEstado() != PedidoLinea.Estado.enviado) {
|
||||
linea.setEstado(PedidoLinea.Estado.cancelado);
|
||||
pedidoLineaRepository.save(linea);
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ public class PedidosController {
|
||||
linea.put("buttons", buttons);
|
||||
}
|
||||
|
||||
if(pedidoLinea.getEstado() != PedidoLinea.Estado.cancelado && pedidoLinea.getEstado() != PedidoLinea.Estado.terminado) {
|
||||
if(pedidoLinea.getEstado() != PedidoLinea.Estado.cancelado && pedidoLinea.getEstado() != PedidoLinea.Estado.terminado && pedidoLinea.getEstado() != PedidoLinea.Estado.enviado) {
|
||||
showCancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 0024-series-facturacion-seeder
|
||||
author: jjo
|
||||
context: demo
|
||||
changes:
|
||||
|
||||
# --- SERIES ---
|
||||
- sql:
|
||||
splitStatements: true
|
||||
stripComments: true
|
||||
sql: |
|
||||
INSERT INTO series_facturas
|
||||
(nombre_serie, prefijo, tipo, numero_actual, created_at, updated_at, created_by, updated_by)
|
||||
SELECT
|
||||
'IMPRESIÓN DIGITAL', 'IMPR', 'facturacion', 1, NOW(), NOW(), 1, 1
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM series_facturas WHERE prefijo = 'IMPR'
|
||||
);
|
||||
|
||||
INSERT INTO series_facturas
|
||||
(nombre_serie, prefijo, tipo, numero_actual, created_at, updated_at, created_by, updated_by)
|
||||
SELECT
|
||||
'RECT. IMPRESIÓN DIGITAL', 'REC IL', 'facturacion', 1, NOW(), NOW(), 1, 1
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM series_facturas WHERE prefijo = 'REC IL'
|
||||
);
|
||||
|
||||
# --- VARIABLES (con el id real de la serie) ---
|
||||
# serie_facturacion_default -> id de la serie con prefijo IMPR
|
||||
- sql:
|
||||
splitStatements: true
|
||||
stripComments: true
|
||||
sql: |
|
||||
INSERT INTO variables (clave, valor)
|
||||
SELECT
|
||||
'serie_facturacion_default',
|
||||
CAST(sf.id AS CHAR)
|
||||
FROM series_facturas sf
|
||||
WHERE sf.prefijo = 'IMPR'
|
||||
LIMIT 1
|
||||
ON DUPLICATE KEY UPDATE valor = VALUES(valor);
|
||||
|
||||
# sere_facturacion_rect_default -> id de la serie con prefijo REC IL
|
||||
- sql:
|
||||
splitStatements: true
|
||||
stripComments: true
|
||||
sql: |
|
||||
INSERT INTO variables (clave, valor)
|
||||
SELECT
|
||||
'sere_facturacion_rect_default',
|
||||
CAST(sf.id AS CHAR)
|
||||
FROM series_facturas sf
|
||||
WHERE sf.prefijo = 'REC IL'
|
||||
LIMIT 1
|
||||
ON DUPLICATE KEY UPDATE valor = VALUES(valor);
|
||||
|
||||
rollback:
|
||||
- sql:
|
||||
splitStatements: true
|
||||
stripComments: true
|
||||
sql: |
|
||||
DELETE FROM variables
|
||||
WHERE clave IN ('serie_facturacion_default', 'sere_facturacion_rect_default');
|
||||
|
||||
DELETE FROM series_facturas
|
||||
WHERE prefijo IN ('IMPR', 'REC IL');
|
||||
@ -44,4 +44,6 @@ databaseChangeLog:
|
||||
- include:
|
||||
file: db/changelog/changesets/0022-add-estados-pago-to-pedidos-lineas-3.yml
|
||||
- include:
|
||||
file: db/changelog/changesets/0023-facturacion.yml
|
||||
file: db/changelog/changesets/0023-facturacion.yml
|
||||
- include:
|
||||
file: db/changelog/changesets/0024-series-facturacion-seeder.yml
|
||||
@ -45,6 +45,8 @@ facturas.lineas.delete.title=¿Eliminar línea de factura?
|
||||
facturas.lineas.delete.text=Esta acción no se puede deshacer.
|
||||
facturas.lineas.error.base=La base imponible no es válida.
|
||||
|
||||
facturas.lineas.gastos-envio=Gastos de envío
|
||||
|
||||
facturas.direccion.titulo=Dirección de Facturación
|
||||
facturas.direccion.razon-social=Razón Social
|
||||
facturas.direccion.identificacion-fiscal=Identificación Fiscal
|
||||
|
||||
@ -28,6 +28,7 @@ pedido.estado.esperando_aceptacion_ferro=Esperando aceptación de ferro
|
||||
pedido.estado.ferro_cliente=Esperando aprobación de ferro
|
||||
pedido.estado.produccion=Producción
|
||||
pedido.estado.terminado=Terminado
|
||||
pedido.estado.enviado=Enviado
|
||||
pedido.estado.cancelado=Cancelado
|
||||
|
||||
pedido.module-title=Pedidos
|
||||
|
||||
@ -42,7 +42,7 @@ $(() => {
|
||||
if (estadoSpan.length) {
|
||||
estadoSpan.text(response.state);
|
||||
}
|
||||
if (response.stateKey === 'terminado' || response.stateKey === 'cancelado') {
|
||||
if (response.stateKey === 'enviado' || response.stateKey === 'cancelado') {
|
||||
$(`.update-estado-button[data-linea-id='${lineaId}']`)
|
||||
.closest('.update-estado-button')
|
||||
.addClass('d-none');
|
||||
|
||||
Reference in New Issue
Block a user