mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-19 07:10:21 +00:00
trabajando en resumen
This commit is contained in:
@ -8,15 +8,21 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Locale;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.imprimelibros.erp.configurationERP.VariableService;
|
||||
import com.imprimelibros.erp.presupuesto.Presupuesto.TipoCubierta;
|
||||
import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestadorItems;
|
||||
import com.imprimelibros.erp.externalApi.skApiClient;
|
||||
|
||||
@Service
|
||||
public class PresupuestoService {
|
||||
@ -27,6 +33,9 @@ public class PresupuestoService {
|
||||
@Autowired
|
||||
protected MessageSource messageSource;
|
||||
|
||||
@Autowired
|
||||
protected skApiClient skApiClient;
|
||||
|
||||
private final PresupuestadorItems presupuestadorItems;
|
||||
|
||||
public PresupuestoService(PresupuestadorItems presupuestadorItems) {
|
||||
@ -228,7 +237,7 @@ public class PresupuestoService {
|
||||
|
||||
List<String> gramajes = new ArrayList<>();
|
||||
|
||||
final int CARTULINA_GRAFICA_ID = 3;
|
||||
final int CARTULINA_GRAFICA_ID = 5;
|
||||
final int ESTUCADO_MATE_ID = 2;
|
||||
|
||||
if (presupuesto.getPapelCubiertaId() != null && presupuesto.getPapelCubiertaId() == CARTULINA_GRAFICA_ID) {
|
||||
@ -269,17 +278,11 @@ public class PresupuestoService {
|
||||
"gramajeCubierta", presupuesto.getGramajeCubierta(),
|
||||
"carasImpresion", presupuesto.getCubiertaCaras(),
|
||||
"solapas", presupuesto.getSolapasCubierta() ? presupuesto.getTamanioSolapasCubierta() : 0,
|
||||
"acabado", 0, //// Añadir acabados
|
||||
"acabado", presupuesto.getAcabado(),
|
||||
"cabezada", presupuesto.getCabezada(),
|
||||
"lomoRedondo", presupuesto.getTipoCubierta() == TipoCubierta.tapaDuraLomoRedondo ? 1 : 0);
|
||||
|
||||
/*
|
||||
* Map<String, Object> sobrecubierta = new HashMap<>();
|
||||
* sobrecubierta.put("papel", "2");
|
||||
* sobrecubierta.put("gramaje", 170);
|
||||
* sobrecubierta.put("solapas", 80);
|
||||
* sobrecubierta.put("acabado", null);
|
||||
*
|
||||
* Map<String, Object> servicios = Map.of(
|
||||
* "retractilado", 0,
|
||||
* "retractilado5", 0,
|
||||
@ -303,9 +306,25 @@ public class PresupuestoService {
|
||||
body.put("paginasCuadernillo", SK_PAGINAS_CUADERNILLO);
|
||||
body.put("interior", interior);
|
||||
body.put("cubierta", cubierta);
|
||||
// body.put("sobrecubierta", sobrecubierta);
|
||||
body.put("guardas", null);
|
||||
body.put("faja", false);
|
||||
if (presupuesto.getSobrecubierta()) {
|
||||
Map<String, Object> sobrecubierta = new HashMap<>();
|
||||
sobrecubierta.put("papel", presupuesto.getPapelSobrecubiertaId());
|
||||
sobrecubierta.put("gramaje", presupuesto.getGramajeSobrecubierta());
|
||||
sobrecubierta.put("solapas", presupuesto.getTamanioSolapasSobrecubierta());
|
||||
sobrecubierta.put("acabado", presupuesto.getAcabadoSobrecubierta());
|
||||
body.put("sobrecubierta", sobrecubierta);
|
||||
}
|
||||
|
||||
if (presupuesto.getFaja()) {
|
||||
Map<String, Object> faja = new HashMap<>();
|
||||
faja.put("papel", presupuesto.getPapelFajaId());
|
||||
faja.put("gramaje", presupuesto.getGramajeFaja());
|
||||
faja.put("solapas", presupuesto.getTamanioSolapasFaja());
|
||||
faja.put("acabado", presupuesto.getAcabadoFaja());
|
||||
faja.put("alto", presupuesto.getAltoFaja());
|
||||
body.put("faja", faja);
|
||||
}
|
||||
// body.put("servicios", servicios);
|
||||
|
||||
return body;
|
||||
@ -372,7 +391,8 @@ public class PresupuestoService {
|
||||
});
|
||||
opciones.add(new HashMap<>() {
|
||||
{
|
||||
put("name", messageSource.getMessage("presupuesto.acabado-plastificado-mate-1c-antirrayado", null, locale));
|
||||
put("name",
|
||||
messageSource.getMessage("presupuesto.acabado-plastificado-mate-1c-antirrayado", null, locale));
|
||||
put("sk-id", 8);
|
||||
}
|
||||
});
|
||||
@ -405,4 +425,157 @@ public class PresupuestoService {
|
||||
return resultado;
|
||||
}
|
||||
|
||||
public Map<String, Object> aplicarMargenTiradas(Map<String, Object> data) {
|
||||
|
||||
// implementar margenes
|
||||
return (Map<String, Object>) data;
|
||||
}
|
||||
|
||||
public String obtenerPrecioRetractilado(Presupuesto presupuesto, Locale locale) {
|
||||
Integer[] tiradas = presupuesto.getTiradas();
|
||||
Integer tirada_min = Arrays.stream(tiradas)
|
||||
.filter(Objects::nonNull)
|
||||
.min(Integer::compareTo)
|
||||
.orElse(0);
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("tirada",
|
||||
presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : tirada_min);
|
||||
Double precio_retractilado = skApiClient.getRetractilado(requestBody);
|
||||
return precio_retractilado != null
|
||||
? NumberFormat.getNumberInstance(locale)
|
||||
.format(Math.round(precio_retractilado * 100.0) / 100.0)
|
||||
: "0,00";
|
||||
}
|
||||
|
||||
public Map<String, Object> obtenerServiciosExtras(Presupuesto presupuesto, Locale locale, skApiClient apiClient) {
|
||||
|
||||
List<Object> opciones = new ArrayList<>();
|
||||
|
||||
Double price_prototipo = this.obtenerPrototipo(presupuesto, apiClient);
|
||||
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "retractilado");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-retractilado", null, locale));
|
||||
put("description", "");
|
||||
put("price", obtenerPrecioRetractilado(presupuesto, locale));
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "service-isbn");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-isbn", null, locale));
|
||||
put("description", "");
|
||||
put("price", "30");
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "deposito-legal");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-deposito-legal", null, locale));
|
||||
put("description",
|
||||
messageSource.getMessage("presupuesto.extras-deposito-legal-descripcion", null, locale));
|
||||
put("price", "30");
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "revision-archivos");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-revision-archivos", null, locale));
|
||||
put("description", "");
|
||||
put("price", "50");
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "maquetacion-cubierta");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-maquetacion-cubierta", null, locale));
|
||||
put("description", "");
|
||||
put("price", "50");
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "ferro-digital");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-ferro-digital", null, locale));
|
||||
put("description", "");
|
||||
put("price", "0");
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
put("checked", "true");
|
||||
put("allowChange", "false");
|
||||
put("ribbonText", messageSource.getMessage("presupuesto.extras-ferro-digital-ribbon", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "ejemplar-prueba");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-ejemplar-prueba", null, locale));
|
||||
put("description", "");
|
||||
if(price_prototipo == 0.0) {
|
||||
put("price", messageSource.getMessage("presupuesto.consultar-soporte", null, locale));
|
||||
put("priceUnit", "");
|
||||
} else {
|
||||
put("price", NumberFormat.getNumberInstance(locale)
|
||||
.format(Math.round(price_prototipo * 100.0) / 100.0));
|
||||
put("priceUnit", messageSource.getMessage("app.currency-symbol", null, locale));
|
||||
}
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "marcapaginas");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-marcapaginas", null, locale));
|
||||
put("description", "");
|
||||
put("price", messageSource.getMessage("presupuesto.extras-calcular", null, locale));
|
||||
}
|
||||
});
|
||||
opciones.add(new HashMap<String, String>() {
|
||||
{
|
||||
put("id", "maquetacion");
|
||||
put("title", messageSource.getMessage("presupuesto.extras-maquetacion", null, locale));
|
||||
put("description", "");
|
||||
put("price", messageSource.getMessage("presupuesto.extras-calcular", null, locale));
|
||||
}
|
||||
});
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("servicios_extra", opciones);
|
||||
return response;
|
||||
}
|
||||
|
||||
private Double obtenerPrototipo(Presupuesto presupuesto, skApiClient apiClient) {
|
||||
|
||||
// Obtenemos el precio de 1 unidad para el ejemplar de prueba
|
||||
HashMap<String, Object> price = new HashMap<>();
|
||||
// make a copy of "presupuesto" to avoid modifying the original object
|
||||
Presupuesto presupuestoTemp = presupuesto.clone();
|
||||
presupuestoTemp.setTirada1(1);
|
||||
presupuestoTemp.setTirada2(null);
|
||||
presupuestoTemp.setTirada3(null);
|
||||
presupuestoTemp.setTirada4(null);
|
||||
if (presupuestoTemp.getTipoImpresion() == Presupuesto.TipoImpresion.color) {
|
||||
presupuestoTemp.setTipoImpresion(Presupuesto.TipoImpresion.colorhq);
|
||||
} else if (presupuestoTemp.getTipoImpresion() == Presupuesto.TipoImpresion.negro) {
|
||||
presupuestoTemp.setTipoImpresion(Presupuesto.TipoImpresion.negrohq);
|
||||
}
|
||||
String priceStr = apiClient.getPrice(this.toSkApiRequest(presupuestoTemp));
|
||||
Double price_prototipo = 0.0;
|
||||
try {
|
||||
price = new ObjectMapper().readValue(priceStr, new TypeReference<>() {
|
||||
});
|
||||
price_prototipo = ((List<Double>) ((Map<String, Object>) price.get("data")).get("precios")).get(0);
|
||||
if (price_prototipo < 25) {
|
||||
price_prototipo = 25.0;
|
||||
}
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
} catch (Exception exception) {
|
||||
}
|
||||
return price_prototipo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user