Merge branch 'develop' into feature/RefactoringGestioneColli

# Conflicts:
#	app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/ProdRecuperoMaterialeModule.java
#	app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/ProdRecuperoMaterialeViewModel.java
#	app/src/main/java/it/integry/integrywmsnative/gest/prod_recupero_materiale/rest/ProdRecuperoMaterialeRESTConsumer.java
#	app/src/main/res/layout/fragment_prod_recupero_materiale.xml
This commit is contained in:
2025-09-17 15:14:00 +02:00
5 changed files with 105 additions and 120 deletions

View File

@@ -4,9 +4,6 @@ import androidx.databinding.BaseObservable;
import java.math.BigDecimal; import java.math.BigDecimal;
import it.integry.integrywmsnative.core.CommonConst;
import it.integry.integrywmsnative.core.utility.UtilityNumber;
public class BindableFloat extends BaseObservable { public class BindableFloat extends BaseObservable {
private Float value; private Float value;
@@ -15,10 +12,6 @@ public class BindableFloat extends BaseObservable {
} }
public BigDecimal getBigDecimal() { public BigDecimal getBigDecimal() {
int numberOfDigits = UtilityNumber.countNumberOfDecimalDigits(get());
if(numberOfDigits > CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS) numberOfDigits = CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS;
return BigDecimal.valueOf(get()); return BigDecimal.valueOf(get());
} }

View File

@@ -265,7 +265,7 @@ public class Converters {
BigDecimal value = null; BigDecimal value = null;
if (!UtilityString.isNullOrEmpty(s.toString())) if (!UtilityString.isNullOrEmpty(s.toString()))
value = new BigDecimal(s.toString()); value = UtilityNumber.parseBigDecimal(s.toString(), Locale.getDefault());
observableBigDecimal.set(value); observableBigDecimal.set(value);
} }
@@ -275,7 +275,7 @@ public class Converters {
} }
BigDecimal newValue = observableBigDecimal.get(); BigDecimal newValue = observableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));
@@ -296,7 +296,7 @@ public class Converters {
String newValueString = s.toString().trim(); String newValueString = s.toString().trim();
if (!UtilityString.isNullOrEmpty(newValueString)) if (!UtilityString.isNullOrEmpty(newValueString))
value = new BigDecimal(newValueString); value = UtilityNumber.parseBigDecimal(newValueString, Locale.getDefault());
observableBigDecimal.set(value); observableBigDecimal.set(value);
} }
@@ -305,7 +305,7 @@ public class Converters {
view.addTextChangedListener(watcher); view.addTextChangedListener(watcher);
} }
BigDecimal newValue = observableBigDecimal.get(); BigDecimal newValue = observableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));
@@ -326,7 +326,7 @@ public class Converters {
String newValueString = s.toString().trim(); String newValueString = s.toString().trim();
if (!UtilityString.isNullOrEmpty(newValueString)) if (!UtilityString.isNullOrEmpty(newValueString))
value = new BigDecimal(newValueString); value = UtilityNumber.parseBigDecimal(newValueString, Locale.getDefault());
observableBigDecimal.set(value); observableBigDecimal.set(value);
} }
@@ -335,7 +335,7 @@ public class Converters {
view.addTextChangedListener(watcher); view.addTextChangedListener(watcher);
} }
BigDecimal newValue = observableBigDecimal.get(); BigDecimal newValue = observableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));
@@ -354,7 +354,8 @@ public class Converters {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
BigDecimal value = null; BigDecimal value = null;
if (!UtilityString.isNullOrEmpty(s.toString())) if (!UtilityString.isNullOrEmpty(s.toString()))
value = new BigDecimal(s.toString()); value = UtilityNumber.parseBigDecimal(s.toString(), Locale.getDefault());
bindableBigDecimal.set(value); bindableBigDecimal.set(value);
} }
}; };
@@ -362,7 +363,7 @@ public class Converters {
view.addTextChangedListener(watcher); view.addTextChangedListener(watcher);
} }
BigDecimal newValue = bindableBigDecimal.get(); BigDecimal newValue = bindableBigDecimal.get();
BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? new BigDecimal(view.getText().toString()) : null; BigDecimal viewValue = !view.getText().toString().trim().isEmpty() ? UtilityNumber.parseBigDecimal(view.getText().toString(), Locale.getDefault()) : null;
if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) { if (!UtilityBigDecimal.equalsTo(viewValue, newValue)) {
view.setText(UtilityNumber.decimalToString(newValue)); view.setText(UtilityNumber.decimalToString(newValue));

View File

@@ -1,6 +1,7 @@
package it.integry.integrywmsnative.core.utility; package it.integry.integrywmsnative.core.utility;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.Locale; import java.util.Locale;
@@ -9,7 +10,8 @@ import it.integry.integrywmsnative.core.CommonConst;
public class UtilityNumber { public class UtilityNumber {
private static DecimalFormat decimalFormatInstance; // Locale italiano per la formattazione
private static final Locale ITALIAN_LOCALE = new Locale("it", "IT");
public static String decimalToString(Float bigDecimal){ public static String decimalToString(Float bigDecimal){
if(bigDecimal == null) return "0"; if(bigDecimal == null) return "0";
@@ -23,71 +25,59 @@ public class UtilityNumber {
public static String decimalToString(BigDecimal bigDecimal, int decimal){ public static String decimalToString(BigDecimal bigDecimal, int decimal){
if(bigDecimal == null) return "0"; if(bigDecimal == null) return "0";
return decimalToString(bigDecimal.floatValue(), decimal);
// Usa stripTrailingZeros per rimuovere gli zeri finali
BigDecimal stripped = bigDecimal.stripTrailingZeros();
// Limita il numero di decimali visualizzati
int scale = Math.min(stripped.scale(), decimal);
stripped = stripped.setScale(scale, RoundingMode.DOWN);
// Configura il formato italiano con virgola come separatore decimale
DecimalFormatSymbols italianSymbols = new DecimalFormatSymbols(ITALIAN_LOCALE);
italianSymbols.setDecimalSeparator(',');
// Crea il pattern dinamico basato sul numero di decimali
StringBuilder patternBuilder = new StringBuilder("0");
if (scale > 0) {
patternBuilder.append(".");
for (int i = 0; i < scale; i++) {
patternBuilder.append("0");
}
}
DecimalFormat formatter = new DecimalFormat(patternBuilder.toString(), italianSymbols);
String result = formatter.format(stripped);
// Se il risultato termina con ',', rimuovilo (per i numeri interi)
if (result.endsWith(",")) {
result = result.substring(0, result.length() - 1);
}
return result;
} }
public static String decimalToString(float floatValue, int decimal) { public static String decimalToString(float floatValue, int decimal) {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); return decimalToString(BigDecimal.valueOf(floatValue), decimal);
otherSymbols.setDecimalSeparator('.');
otherSymbols.setGroupingSeparator(',');
final DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setMaximumFractionDigits(decimal);
decimalFormat.setDecimalFormatSymbols(otherSymbols);
decimalFormat.setGroupingUsed(false);
decimalFormat.setMinimumFractionDigits(Math.min(2, decimal));
return decimalFormat.format(floatValue);
} }
public static DecimalFormat getNumberFormatInstance() { public static BigDecimal parseBigDecimal(String value, Locale locale) {
if (value == null || value.trim().isEmpty()) return null;
if(decimalFormatInstance == null) { try {
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.getDefault()); DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
otherSymbols.setDecimalSeparator('.'); DecimalFormat format = new DecimalFormat();
otherSymbols.setGroupingSeparator(','); format.setDecimalFormatSymbols(symbols);
format.setParseBigDecimal(true);
decimalFormatInstance = new DecimalFormat(); return (BigDecimal) format.parse(value);
decimalFormatInstance.setMaximumFractionDigits(CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS); } catch (Exception e) {
decimalFormatInstance.setDecimalFormatSymbols(otherSymbols); return null;
decimalFormatInstance.setGroupingUsed(false);
} }
return decimalFormatInstance;
} }
public static int countNumberOfDecimalDigits(Float value) { /**
String text = getNumberFormatInstance().format(Math.abs(value)); * Parsa una stringa numerica italiana (con virgola come separatore decimale)
int integerPlaces = text.indexOf('.'); * e restituisce un BigDecimal
int decimalPlaces = text.length() - integerPlaces - 1; */
public static BigDecimal parseItalianBigDecimal(String value) {
return decimalPlaces; return parseBigDecimal(value, ITALIAN_LOCALE);
}
public static String normalizeStringNumber(String numberString) {
return numberString.replaceAll(",", ".");
}
public static Float decimalToFloat(BigDecimal bigDecimalValue) {
float multiplier = (float) Math.pow(10, CommonConst.Config.NUMBER_OF_DECIMAL_DIGITS);
Float floatValue = null;
if(bigDecimalValue != null) {
int intValue = (int) (bigDecimalValue.floatValue() * multiplier);
floatValue = Float.valueOf(intValue / multiplier);
}
return floatValue;
}
public static float truncateToDecimal(float v, int i) {
int delta = 10*i;
return ((int)v*delta)/delta;
} }
} }

View File

@@ -1,28 +1,10 @@
package it.integry.integrywmsnative.gest.prod_recupero_materiale; package it.integry.integrywmsnative.gest.prod_recupero_materiale;
import java.util.concurrent.ExecutorService;
import dagger.Module; import dagger.Module;
import dagger.Provides;
import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.MaterialiRESTConsumer;
import it.integry.integrywmsnative.gest.prod_recupero_materiale.rest.ProdRecuperoMaterialeRESTConsumer;
@Module(subcomponents = ProdRecuperoMaterialeComponent.class) @Module(subcomponents = ProdRecuperoMaterialeComponent.class)
public class ProdRecuperoMaterialeModule { public class ProdRecuperoMaterialeModule {
@Provides
ProdRecuperoMaterialeRESTConsumer providesProdRecuperMaterialeRESTConsumer(MaterialiRESTConsumer materialiRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer) {
return new ProdRecuperoMaterialeRESTConsumer(articoloRESTConsumer, materialiRESTConsumer);
}
@Provides
ProdRecuperoMaterialeViewModel providesProdRecuperoMaterialeViewModel(ProdRecuperoMaterialeRESTConsumer prodRecuperoMaterialeRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
MaterialiRESTConsumer materialiRESTConsumer,
ExecutorService executorService) {
return new ProdRecuperoMaterialeViewModel(prodRecuperoMaterialeRESTConsumer, colliMagazzinoRESTConsumer, materialiRESTConsumer, executorService);
}
} }

View File

@@ -5,7 +5,6 @@ import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -24,6 +23,7 @@ public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer {
private final ArticoloRESTConsumer mArticoloRESTConsumer; private final ArticoloRESTConsumer mArticoloRESTConsumer;
private final MaterialiRESTConsumer mMaterialiRESTConsumer; private final MaterialiRESTConsumer mMaterialiRESTConsumer;
@Inject
public ProdRecuperoMaterialeRESTConsumer(ArticoloRESTConsumer articoloRESTConsumer, MaterialiRESTConsumer materialiRESTConsumer) { public ProdRecuperoMaterialeRESTConsumer(ArticoloRESTConsumer articoloRESTConsumer, MaterialiRESTConsumer materialiRESTConsumer) {
this.mMaterialiRESTConsumer = materialiRESTConsumer; this.mMaterialiRESTConsumer = materialiRESTConsumer;
this.mArticoloRESTConsumer = articoloRESTConsumer; this.mArticoloRESTConsumer = articoloRESTConsumer;
@@ -55,6 +55,25 @@ public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer {
return keyMap; return keyMap;
}, Collectors.toList())); }, Collectors.toList()));
for (HashMap<String, Object> ulKey : ulListGrouped.keySet()) {
var matchingUls = ulList.stream().filter(x ->
Objects.equals(x.getGestione(), ulKey.get("gestione")) &&
Objects.equals(x.getDataCollo(), ulKey.get("data_collo")) &&
Objects.equals(x.getSerCollo(), ulKey.get("ser_collo")) &&
Objects.equals(x.getNumCollo(), ulKey.get("num_collo")) &&
Objects.equals(x.getCodMart(), ulKey.get("cod_mart")) &&
Objects.equals(x.getPartitaMag(), ulKey.get("partita_mag")) &&
Objects.equals(x.getGestioneRif(), ulKey.get("gestione_rif")) &&
Objects.equals(x.getDataColloRif(), ulKey.get("data_collo_rif")) &&
Objects.equals(x.getSerColloRif(), ulKey.get("ser_collo_rif")) &&
Objects.equals(x.getNumColloRif(), ulKey.get("num_collo_rif"))
).collect(Collectors.toUnmodifiableList());
ulKey.put("qta_col", matchingUls.stream().map(HistoryVersamentoProdULRestDTO::getQtaCol)
.reduce(BigDecimal.ZERO, BigDecimal::add));
ulKey.put("num_cnf", matchingUls.stream().map(HistoryVersamentoProdULRestDTO::getNumCnf)
.reduce(BigDecimal.ZERO, BigDecimal::add));
}
ulListGrouped.forEach((key, value) -> { ulListGrouped.forEach((key, value) -> {
@@ -75,35 +94,35 @@ public class ProdRecuperoMaterialeRESTConsumer extends _BaseRESTConsumer {
.collect(Collectors.toUnmodifiableList()); .collect(Collectors.toUnmodifiableList());
var restData = value.get(0); var restData = value.get(0);
var qtaCol = (BigDecimal) key.get("qta_col");
var numCnf = (BigDecimal) key.get("num_cnf");
newUlList.add(new HistoryVersamentoProdULDTO() newUlList.add(new HistoryVersamentoProdULDTO()
.setGestione(restData.getGestione()) .setGestione(restDTO.getGestione())
.setDataCollo(restData.getDataCollo()) .setDataCollo(restDTO.getDataCollo())
.setSerCollo(restData.getSerCollo()) .setSerCollo(restDTO.getSerCollo())
.setNumCollo(restData.getNumCollo()) .setNumCollo(restDTO.getNumCollo())
.setSegno(restData.getSegno()) .setSegno(restDTO.getSegno())
.setCodMart(restData.getCodMart()) .setCodMart(restDTO.getCodMart())
.setCodCol(restData.getCodCol()) .setCodCol(restDTO.getCodCol())
.setCodTagl(restData.getCodTagl()) .setCodTagl(restDTO.getCodTagl())
.setCodJfas(restData.getCodJfas()) .setCodJfas(restDTO.getCodJfas())
.setDescrizioneArt(restData.getDescrizioneArt()) .setDescrizioneArt(restDTO.getDescrizioneArt())
.setDescrizioneFase(restData.getDescrizioneFase()) .setDescrizioneFase(restDTO.getDescrizioneFase())
.setQtaCol(restData.getQtaCol()) .setQtaCol(qtaCol)
.setQtaCnf(restData.getQtaCnf()) .setQtaCnf(restDTO.getQtaCnf())
.setNumCnf(restData.getNumCnf()) .setNumCnf(numCnf)
.setPartitaMag(restData.getPartitaMag()) .setPartitaMag(restDTO.getPartitaMag())
.setCodJcom(restData.getCodJcom()) .setCodJcom(restDTO.getCodJcom())
.setDatetimeRow(restData.getDatetimeRow()) .setDatetimeRow(restDTO.getDatetimeRow())
.setUntMis(restData.getUntMis()) .setUntMis(restDTO.getUntMis())
.setBarcodeUlOut(restData.getBarcodeUlOut()) .setGestioneRif(restDTO.getGestioneRif())
.setCodMdepOut(restData.getCodMdepOut()) .setDataColloRif(restDTO.getDataColloRif())
.setPosizioneOut(restData.getPosizioneOut()) .setSerColloRif(restDTO.getSerColloRif())
.setBarcodeUlIn(restData.getBarcodeUlIn()) .setNumColloRif(restDTO.getNumColloRif())
.setCodMdepIn(restData.getCodMdepIn()) .setOrdini(ordineList));
.setPosizioneIn(restData.getPosizioneIn())
.setOrdini(listaOrdini));
}); });
if (!newUlList.isEmpty()) { if (!newUlList.isEmpty()) {