mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 08:58:48 +00:00
modificado los margenes por precio en lugar de por tirada y tipos
This commit is contained in:
@ -8,6 +8,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -15,11 +17,17 @@ import org.springframework.stereotype.Component;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.imprimelibros.erp.datatables.DataTablesRequest;
|
||||
import com.imprimelibros.erp.presupuesto.classes.PresupuestoFormatter;
|
||||
import com.imprimelibros.erp.presupuesto.dto.Presupuesto;
|
||||
import com.imprimelibros.erp.presupuesto.maquetacion.MaquetacionMatrices;
|
||||
import com.imprimelibros.erp.presupuesto.marcapaginas.Marcapaginas;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.Path;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Component
|
||||
public class Utils {
|
||||
|
||||
@ -42,6 +50,55 @@ public class Utils {
|
||||
return currencyFormatter.format(amount);
|
||||
}
|
||||
|
||||
public static String formatNumber(BigDecimal amount, Locale locale) {
|
||||
NumberFormat numberFormatter = NumberFormat.getNumberInstance(locale);
|
||||
return numberFormatter.format(amount);
|
||||
}
|
||||
|
||||
public static String formatNumber(Double amount, Locale locale) {
|
||||
NumberFormat numberFormatter = NumberFormat.getNumberInstance(locale);
|
||||
return numberFormatter.format(amount);
|
||||
}
|
||||
|
||||
public static Optional<BiFunction<Path<BigDecimal>, CriteriaBuilder, Predicate>> parseNumericFilter(
|
||||
DataTablesRequest dt, String colName, Locale locale) {
|
||||
String raw = dt.getColumnSearch(colName); // usa el "name" del DataTable (snake_case)
|
||||
if (raw == null || raw.isBlank())
|
||||
return Optional.empty();
|
||||
|
||||
String s = raw.trim();
|
||||
// normaliza número con coma o punto
|
||||
Function<String, BigDecimal> toBig = x -> {
|
||||
String t = x.replace(".", "").replace(",", "."); // 1.234,56 -> 1234.56
|
||||
return new BigDecimal(t);
|
||||
};
|
||||
|
||||
try {
|
||||
if (s.matches("(?i)^>=?\\s*[-\\d.,]+$")) {
|
||||
BigDecimal v = toBig.apply(s.replace(">=", "").replace(">", "").trim());
|
||||
return Optional.of((path, cb) -> cb.greaterThanOrEqualTo(path, v));
|
||||
}
|
||||
if (s.matches("(?i)^<=?\\s*[-\\d.,]+$")) {
|
||||
BigDecimal v = toBig.apply(s.replace("<=", "").replace("<", "").trim());
|
||||
return Optional.of((path, cb) -> cb.lessThanOrEqualTo(path, v));
|
||||
}
|
||||
if (s.contains("-")) { // rango "a-b"
|
||||
String[] p = s.split("-");
|
||||
if (p.length == 2) {
|
||||
BigDecimal a = toBig.apply(p[0].trim());
|
||||
BigDecimal b = toBig.apply(p[1].trim());
|
||||
BigDecimal min = a.min(b), max = a.max(b);
|
||||
return Optional.of((path, cb) -> cb.between(path, min, max));
|
||||
}
|
||||
}
|
||||
// exacto/like numérico
|
||||
BigDecimal v = toBig.apply(s);
|
||||
return Optional.of((path, cb) -> cb.equal(path, v));
|
||||
} catch (Exception ignore) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> getTextoPresupuesto(Presupuesto presupuesto, Locale locale) {
|
||||
|
||||
Map<String, Object> resumen = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user