mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-28 06:38:51 +00:00
trabajando en modificar para obtener los servicios
This commit is contained in:
@ -21,9 +21,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.imprimelibros.erp.externalApi.skApiClient;
|
import com.imprimelibros.erp.externalApi.skApiClient;
|
||||||
import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
import com.imprimelibros.erp.presupuesto.classes.ImagenPresupuesto;
|
||||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestoMaquetacion;
|
import com.imprimelibros.erp.presupuesto.classes.PresupuestoMaquetacion;
|
||||||
@ -116,21 +113,14 @@ public class PresupuestoController {
|
|||||||
|
|
||||||
if (calcular) {
|
if (calcular) {
|
||||||
|
|
||||||
HashMap<String, Object> price = new HashMap<>();
|
HashMap<String, Object> price = presupuestoService.calcularPresupuesto(presupuesto, locale);
|
||||||
String priceStr = apiClient.getPrice(presupuestoService.toSkApiRequest(presupuesto));
|
|
||||||
|
|
||||||
try {
|
|
||||||
price = new ObjectMapper().readValue(priceStr, new TypeReference<>() {
|
|
||||||
});
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
price = new HashMap<>();
|
|
||||||
price.put("error", messageSource.getMessage("presupuesto.error-obtener-precio", null, locale));
|
|
||||||
}
|
|
||||||
if (!price.containsKey("data")) {
|
if (!price.containsKey("data")) {
|
||||||
return ResponseEntity.badRequest()
|
return ResponseEntity.badRequest()
|
||||||
.body(messageSource.getMessage("presupuesto.error-obtener-precio", null, locale));
|
.body(messageSource.getMessage("presupuesto.error-obtener-precio", null, locale));
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(price.get("data"));
|
return ResponseEntity.ok(price.get("data"));
|
||||||
|
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
@ -154,7 +144,7 @@ public class PresupuestoController {
|
|||||||
|
|
||||||
Map<String, Object> resultado = new HashMap<>();
|
Map<String, Object> resultado = new HashMap<>();
|
||||||
// servicios extra
|
// servicios extra
|
||||||
resultado.putAll(presupuestoService.obtenerServiciosExtras(presupuesto, locale, apiClient));
|
resultado.putAll(presupuestoService.obtenerServiciosExtras(presupuesto, locale));
|
||||||
Map<String, String> language = new HashMap<>();
|
Map<String, String> language = new HashMap<>();
|
||||||
language.put("calcular", messageSource.getMessage("presupuesto.calcular", null, locale));
|
language.put("calcular", messageSource.getMessage("presupuesto.calcular", null, locale));
|
||||||
resultado.put("language", language);
|
resultado.put("language", language);
|
||||||
|
|||||||
@ -44,9 +44,6 @@ public class PresupuestoService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected MessageSource messageSource;
|
protected MessageSource messageSource;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
protected skApiClient skApiClient;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected MaquetacionPreciosRepository maquetacionPreciosRepository;
|
protected MaquetacionPreciosRepository maquetacionPreciosRepository;
|
||||||
|
|
||||||
@ -58,10 +55,12 @@ public class PresupuestoService {
|
|||||||
|
|
||||||
private final PresupuestadorItems presupuestadorItems;
|
private final PresupuestadorItems presupuestadorItems;
|
||||||
private final PresupuestoFormatter presupuestoFormatter;
|
private final PresupuestoFormatter presupuestoFormatter;
|
||||||
|
private final skApiClient apiClient;
|
||||||
|
|
||||||
public PresupuestoService(PresupuestadorItems presupuestadorItems, PresupuestoFormatter presupuestoFormatter) {
|
public PresupuestoService(PresupuestadorItems presupuestadorItems, PresupuestoFormatter presupuestoFormatter, skApiClient apiClient) {
|
||||||
this.presupuestadorItems = presupuestadorItems;
|
this.presupuestadorItems = presupuestadorItems;
|
||||||
this.presupuestoFormatter = presupuestoFormatter;
|
this.presupuestoFormatter = presupuestoFormatter;
|
||||||
|
this.apiClient = apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateDatosGenerales(int[] tiradas) {
|
public boolean validateDatosGenerales(int[] tiradas) {
|
||||||
@ -453,18 +452,18 @@ public class PresupuestoService {
|
|||||||
Map<String, Object> requestBody = new HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
requestBody.put("tirada",
|
requestBody.put("tirada",
|
||||||
presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : tirada_min);
|
presupuesto.getSelectedTirada() != null ? presupuesto.getSelectedTirada() : tirada_min);
|
||||||
Double precio_retractilado = skApiClient.getRetractilado(requestBody);
|
Double precio_retractilado = apiClient.getRetractilado(requestBody);
|
||||||
return precio_retractilado != null
|
return precio_retractilado != null
|
||||||
? NumberFormat.getNumberInstance(locale)
|
? NumberFormat.getNumberInstance(locale)
|
||||||
.format(Math.round(precio_retractilado * 100.0) / 100.0)
|
.format(Math.round(precio_retractilado * 100.0) / 100.0)
|
||||||
: "0,00";
|
: "0,00";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> obtenerServiciosExtras(Presupuesto presupuesto, Locale locale, skApiClient apiClient) {
|
public Map<String, Object> obtenerServiciosExtras(Presupuesto presupuesto, Locale locale) {
|
||||||
|
|
||||||
List<Object> opciones = new ArrayList<>();
|
List<Object> opciones = new ArrayList<>();
|
||||||
|
|
||||||
Double price_prototipo = this.obtenerPrototipo(presupuesto, apiClient);
|
Double price_prototipo = this.obtenerPrototipo(presupuesto);
|
||||||
|
|
||||||
opciones.add(new HashMap<String, String>() {
|
opciones.add(new HashMap<String, String>() {
|
||||||
{
|
{
|
||||||
@ -561,7 +560,7 @@ public class PresupuestoService {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Double obtenerPrototipo(Presupuesto presupuesto, skApiClient apiClient) {
|
private Double obtenerPrototipo(Presupuesto presupuesto) {
|
||||||
|
|
||||||
// Obtenemos el precio de 1 unidad para el ejemplar de prueba
|
// Obtenemos el precio de 1 unidad para el ejemplar de prueba
|
||||||
HashMap<String, Object> price = new HashMap<>();
|
HashMap<String, Object> price = new HashMap<>();
|
||||||
@ -775,13 +774,30 @@ public class PresupuestoService {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Object> getResumen(Presupuesto presupuesto, String[] servicios, Locale locale) {
|
public Map<String, Object> getResumen(Presupuesto presupuesto, String[] servicios, Locale locale) {
|
||||||
Map<String, Object> resumen = new HashMap<>();
|
Map<String, Object> resumen = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
resumen.put("titulo", presupuesto.getTitulo());
|
resumen.put("titulo", presupuesto.getTitulo());
|
||||||
resumen.put("texto", presupuestoFormatter.resumen(presupuesto, servicios, locale));
|
resumen.put("texto", presupuestoFormatter.resumen(presupuesto, servicios, locale));
|
||||||
|
|
||||||
return resumen;
|
return resumen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> calcularPresupuesto(Presupuesto presupuesto, Locale locale) {
|
||||||
|
|
||||||
|
HashMap<String, Object> price = new HashMap<>();
|
||||||
|
String priceStr = apiClient.getPrice(this.toSkApiRequest(presupuesto));
|
||||||
|
|
||||||
|
try {
|
||||||
|
price = new ObjectMapper().readValue(priceStr, new TypeReference<>() {
|
||||||
|
});
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
price = new HashMap<>();
|
||||||
|
price.put("error", messageSource.getMessage("presupuesto.error-obtener-precio", null, locale));
|
||||||
|
}
|
||||||
|
|
||||||
|
return price;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -170,7 +170,7 @@ presupuesto.resumen-texto-guardas-cabezada= <li>Guardas {0} en {1} {2}. Color de
|
|||||||
presupuesto.resumen-texto-acabado-cubierta= <li>Acabado {0}. </li>
|
presupuesto.resumen-texto-acabado-cubierta= <li>Acabado {0}. </li>
|
||||||
presupuesto.resumen-texto-end=</ul>
|
presupuesto.resumen-texto-end=</ul>
|
||||||
presupuesto.resumen-texto-sobrecubierta=<li>Sobrecubierta impresa en {0} {1} gr. <ul><li>Acabado {2}</li><li>Solapas: {3} mm.</li></ul></li>
|
presupuesto.resumen-texto-sobrecubierta=<li>Sobrecubierta impresa en {0} {1} gr. <ul><li>Acabado {2}</li><li>Solapas: {3} mm.</li></ul></li>
|
||||||
presupuesto.resumen-texto-faja=<li>Faja impresa en {0} {1} gr. con un alto de {2} mm. <ul><li>Acabado {3}</li><li>Solapas:{4} mm.</li></ul></li>
|
presupuesto.resumen-texto-faja=<li>Faja impresa en {0} {1} gr. con un alto de {2} mm. <ul><li>Acabado {3}</li><li>Solapas: {4} mm.</li></ul></li>
|
||||||
presupuesto.volver-extras=Volver a extras
|
presupuesto.volver-extras=Volver a extras
|
||||||
|
|
||||||
# Resumen del presupuesto
|
# Resumen del presupuesto
|
||||||
|
|||||||
@ -1390,9 +1390,18 @@ class PresupuestoCliente {
|
|||||||
this.summaryTableExtras.addClass('d-none');
|
this.summaryTableExtras.addClass('d-none');
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
const servicios = [];
|
||||||
|
$('.service-checkbox:checked').each(function () {
|
||||||
|
const $servicio = $(this);
|
||||||
|
servicios.push({
|
||||||
|
id: $(`label[for="${$servicio.attr('id')}"] .service-title`).text().trim() || $servicio.attr('id'),
|
||||||
|
price: $(`label[for="${$servicio.attr('id')}"] .service-price`).text().trim() || $servicio.attr('price')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
presupuesto: this.#getPresupuestoData(), // objeto JS con campos que coincidan con la entidad
|
presupuesto: this.#getPresupuestoData(), // objeto JS con campos que coincidan con la entidad
|
||||||
servicios: this.formData.servicios.servicios // array de strings
|
servicios: servicios
|
||||||
};
|
};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|||||||
Reference in New Issue
Block a user