Merge branch 'feature/RefactoringGestioneColli' into master-beta
All checks were successful
WMS - Android (New)/pipeline/head This commit looks good

This commit is contained in:
2025-06-24 12:21:35 +02:00
8 changed files with 465 additions and 404 deletions

View File

@@ -180,6 +180,12 @@ public class ArticoloRESTConsumer extends _BaseRESTConsumer {
}
public MtbAart getByCodMartSynchronized(String codMartToFind) throws Exception {
var artList = getByCodMartsSynchronized(Collections.singletonList(codMartToFind));
return artList != null && !artList.isEmpty() ? artList.get(0) : null;
}
public List<MtbGrup> getArtsGroupsSynchronized(List<String> groupsToFind) throws Exception {
var whereCondMap = Stream.of(groupsToFind)
.map(x -> {

View File

@@ -497,17 +497,6 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
var value = saveColloSynchronized(cloneMtbColt);
}
public void updateDataFine(MtbColt mtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {
try {
synchronousUpdateDataFine(mtbColt);
if (onComplete != null) onComplete.run();
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
});
}
public void retrieveBasketColli(RunnableArgs<List<MtbColt>> onComplete, RunnableArgs<Exception> onFailed) {
ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
@@ -526,7 +515,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
});
}
public void creaRettificaCollo(MtbColr sourceMtbColrOriginal, BigDecimal newNumCnf, BigDecimal newQtaTot, RunnableArgs<MtbColr> onComplete, RunnableArgs<Exception> onFailed) {
public MtbColr creaRettificaColloSynchronized(MtbColr sourceMtbColrOriginal, BigDecimal newNumCnf, BigDecimal newQtaTot) throws Exception {
MtbColr sourceMtbColr = (MtbColr) sourceMtbColrOriginal.clone();
sourceMtbColr.setMtbPartitaMag(null);
sourceMtbColr.setMtbAart(null);
@@ -537,18 +526,22 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
.setNewQtaCol(newQtaTot);
ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
colliMagazzinoRESTConsumerService.creaRettificaCollo(
var response = colliMagazzinoRESTConsumerService.creaRettificaCollo(
SettingsManager.i().getUserSession().getDepo().getCodMdep(),
rettificaULDTO
).enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<MtbColr>> call, Response<ServiceRESTResponse<MtbColr>> response) {
analyzeAnswer(response, "creaRettificaCollo", onComplete, onFailed);
).execute();
var data = analyzeAnswer(response, "creaRettificaCollo");
return data;
}
@Override
public void onFailure(Call<ServiceRESTResponse<MtbColr>> call, @NonNull final Exception e) {
if (onFailed != null) onFailed.run(e);
public void creaRettificaCollo(MtbColr sourceMtbColrOriginal, BigDecimal newNumCnf, BigDecimal newQtaTot, RunnableArgs<MtbColr> onComplete, RunnableArgs<Exception> onFailed) {
executorService.execute(() -> {;
try {
var result = creaRettificaColloSynchronized(sourceMtbColrOriginal, newNumCnf, newQtaTot);
if (onComplete != null) onComplete.run(result);
} catch (Exception ex) {
if (onFailed != null) onFailed.run(ex);
}
});
}
@@ -664,25 +657,14 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
});
}
public void confirmGiacenzaUL(MtbColt sourceMtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) {
public void confirmGiacenzaULSynchronized(MtbColt sourceMtbColt) throws Exception {
MtbColt sourceMtbColtClone = (MtbColt) sourceMtbColt.clone();
sourceMtbColtClone.setMtbColr(new ObservableArrayList<>());
ColliMagazzinoRESTConsumerService colliMagazzinoRESTConsumerService = restBuilder.getService(ColliMagazzinoRESTConsumerService.class);
colliMagazzinoRESTConsumerService.confirmGiacenzaUL(sourceMtbColtClone).enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<Object>> call, Response<ServiceRESTResponse<Object>> response) {
analyzeAnswer(response, "confirmGiacenzaUL", data -> {
onComplete.run();
var response = colliMagazzinoRESTConsumerService.confirmGiacenzaUL(sourceMtbColtClone).execute();
}, onFailed);
}
@Override
public void onFailure(Call<ServiceRESTResponse<Object>> call, @NonNull final Exception e) {
if (onFailed != null) onFailed.run(e);
}
});
analyzeAnswer(response, "confirmGiacenzaUL");
}
public MtbColr makeSynchronousRetrieveShipmentUlFromProductionUlRequest(String barcodeUl) throws Exception {

View File

@@ -55,7 +55,7 @@ public interface ColliMagazzinoRESTConsumerService {
Call<ServiceRESTResponse<VersamentoAutomaticoULResponseDTO>> versamentoAutomaticoUL(@Body MtbColt mtbColt);
@POST("wms/confirmGiacenzaUL")
Call<ServiceRESTResponse<Object>> confirmGiacenzaUL(@Body MtbColt mtbColt);
Call<ServiceRESTResponse<Void>> confirmGiacenzaUL(@Body MtbColt mtbColt);
@POST("wms/generic/canULBeDeleted")

View File

@@ -242,13 +242,21 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
private final RunnableArgs<BarcodeScanDTO> onScanSuccessful = data -> {
this.onLoadingStarted();
this.mViewModel.processBarcodeDTO(data, this::onLoadingEnded);
executorService.execute(() -> {
try {
this.mViewModel.processBarcodeDTO(data);
this.onLoadingEnded();
} catch (Exception e) {
this.onError(e);
}
});
};
public void setUIToForn() {
mBinding.rettificaGiacenzeFornCheckBox.setChecked(true);
mBinding.rettificaGiacenzeFornLayout.setBackgroundTintList(ColorStateList.valueOf(getActivity().getResources().getColor(R.color.alpha_blue_500)));
mBinding.rettificaGiacenzeFornLayout.setBackgroundTintList(ColorStateList.valueOf(requireActivity().getResources().getColor(R.color.alpha_blue_500)));
mBinding.rettificaGiacenzeArtIntCheckBox.setChecked(false);
mBinding.rettificaGiacenzeArtIntLayout.setBackgroundTintList(null);
@@ -264,7 +272,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
public void setUIToIntArt() {
mBinding.rettificaGiacenzeArtIntCheckBox.setChecked(true);
mBinding.rettificaGiacenzeArtIntLayout.setBackgroundTintList(ColorStateList.valueOf(getActivity().getResources().getColor(R.color.alpha_blue_500)));
mBinding.rettificaGiacenzeArtIntLayout.setBackgroundTintList(ColorStateList.valueOf(requireActivity().getResources().getColor(R.color.alpha_blue_500)));
mBinding.rettificaGiacenzeFornCheckBox.setChecked(false);
mBinding.rettificaGiacenzeFornLayout.setBackgroundTintList(null);
@@ -274,11 +282,23 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
mBinding.inputCodArtDescrInt.requestFocusFromTouch();
}
public void closeLU(boolean saveCausale) {
executorService.execute(() -> {
this.onLoadingStarted();
try {
mViewModel.closeLU(saveCausale, true);
this.onLoadingEnded();
} catch (Exception e) {
this.onError(e);
}
});
}
@Override
public void onFornitoriLoaded(ArrayList<FornitoreDTO> fornitoriList) {
handler.post(() -> {
AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(getActivity(), fornitoriList);
AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(requireActivity(), fornitoriList);
mBinding.autoCompleteFornitori.setAdapter(autoCompleteFornitoreAdapter);
mBinding.autoCompleteFornitori.setDropDownWidth(getActivity().getResources().getDisplayMetrics().widthPixels);
@@ -296,9 +316,15 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
return true;
}
executorService.execute(() -> {
try {
mViewModel.searchArtFor(
mBinding.autoCompleteFornitori.getText().toString(),
mBinding.inputCodArtDescrForn.getText().toString());
} catch (Exception e) {
this.onError(e);
}
});
return true;
}
return false;
@@ -314,7 +340,13 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
return true;
}
mViewModel.searchArtInt(mBinding.inputCodArtDescrInt.getText().toString(), null, null);
executorService.execute(() -> {
try {
mViewModel.searchArtInt(mBinding.inputCodArtDescrInt.getText().toString(), null);
} catch (Exception e) {
this.onError(e);
}
});
return true;
}
return false;
@@ -326,7 +358,13 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
public void onRequestNewArtCreation(String description, BarcodeScanDTO barcode) {
DialogCreateNewArtView.newInstance(description, barcode, currentMtbColtObs.get().getPosizione(),
createdCodMart -> {
mViewModel.searchArtInt(createdCodMart, null, null);
executorService.execute(() -> {
try {
mViewModel.searchArtInt(createdCodMart, null);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
})
.show(requireActivity().getSupportFragmentManager(), "tag");
}
@@ -359,14 +397,14 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
}
@Override
public void onLUClosed() {
public void onLUClosed(boolean requestNewLu) {
handler.post(() -> {
destroyAdapter();
this.currentMtbColtObs.set(null);
thereIsAnOpenedUL.set(false);
this.mViewModel.requestLU();
if(requestNewLu) this.mViewModel.requestLU();
/*if (getActivity() != null) ((IPoppableActivity) getActivity()).pop();*/
});
}
@@ -416,7 +454,7 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) {
RunnableArgs<PickedQuantityDTO> onComplete) {
DialogInputQuantityV2DTO dialogInputQuantityV2DTO = new DialogInputQuantityV2DTO()
.setMtbAart(mtbAart)
@@ -444,16 +482,20 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
mDialogInputQuantityV2View
.setDialogInputQuantityV2DTO(dialogInputQuantityV2DTO)
.setOnComplete(resultDTO -> {
if (resultDTO == null || resultDTO.isAborted()) return;
if (resultDTO == null || resultDTO.isAborted()) {
onComplete.run(null);
return;
};
PickedQuantityDTO pickedQuantityDTO = new PickedQuantityDTO()
.setNumCnf(resultDTO.getNumCnf())
.setQtaCnf(resultDTO.getQtaCnf())
.setQtaTot(resultDTO.getQtaTot())
.setPartitaMag(resultDTO.getPartitaMag())
.setDataScad(resultDTO.getDataScad());
.setDataScad(resultDTO.getDataScad())
.setShouldCloseLu(resultDTO.isShouldCloseLu());
onComplete.run(pickedQuantityDTO, resultDTO.isShouldCloseLu());
onComplete.run(pickedQuantityDTO);
})
.show(requireActivity().getSupportFragmentManager(), "tag");
}, () -> {
@@ -508,7 +550,15 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
@Override
public void onMtbColrEdit(MtbColr mtbColr) {
executorService.execute(() -> {
this.onLoadingStarted();
try {
this.mViewModel.dispatchRowEdit(mtbColr);
this.onLoadingEnded();
} catch (Exception e) {
this.onError(e);
}
});
}
@Override
@@ -605,7 +655,18 @@ public class RettificaGiacenzeFragment extends BaseFragment implements ITitledFr
@Override
public void onPreDestroy(Runnable onComplete) {
if (mViewModel.getCurrentMtbColt() != null)
mViewModel.closeLU(false);
executorService.execute(() -> {
try {
this.onLoadingStarted();
mViewModel.closeLU(false, false);
this.onLoadingEnded();
onComplete.run();
} catch (Exception e) {
this.onError(e);
}
});
else {
BarcodeManager.removeCallback(mBarcodeScannerInstanceID);
onComplete.run();

View File

@@ -1,5 +1,7 @@
package it.integry.integrywmsnative.gest.rettifica_giacenze;
import android.os.Handler;
import javax.inject.Singleton;
import dagger.Module;
@@ -25,11 +27,12 @@ public class RettificaGiacenzeModule {
@Provides
@Singleton
RettificaGiacenzeViewModel providesRettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer,
RettificaGiacenzeViewModel providesRettificaGiacenzeViewModel(Handler handler,
ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
PrinterRESTConsumer printerRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer,
RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) {
return new RettificaGiacenzeViewModel(articoloRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, barcodeRESTConsumer, rettificaGiacenzeRESTConsumer);
return new RettificaGiacenzeViewModel(handler, articoloRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, barcodeRESTConsumer, rettificaGiacenzeRESTConsumer);
}
}

View File

@@ -1,19 +1,23 @@
package it.integry.integrywmsnative.gest.rettifica_giacenze;
import com.annimon.stream.Stream;
import android.os.Handler;
import android.util.Pair;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.inject.Inject;
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
import it.integry.integrywmsnative.core.exception.NoArtsFoundException;
import it.integry.integrywmsnative.core.exception.NoResultFromBarcodeException;
import it.integry.integrywmsnative.core.exception.ScannedPositionNotExistException;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.expansion.RunnableArgss;
import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILUPositionListener;
import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILUPrintListener;
import it.integry.integrywmsnative.core.model.CommonModelConsts;
@@ -35,6 +39,7 @@ import it.integry.integrywmsnative.core.utility.UtilityBigDecimal;
import it.integry.integrywmsnative.core.utility.UtilityDate;
import it.integry.integrywmsnative.core.utility.UtilityString;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.FornitoreDTO;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByCodArtFornOrDescrizioneResponseDTO;
import it.integry.integrywmsnative.gest.rettifica_giacenze.rest.RettificaGiacenzeRESTConsumer;
import it.integry.integrywmsnative.gest.spedizione.exceptions.InvalidPesoKGException;
import it.integry.integrywmsnative.gest.spedizione.model.PickedQuantityDTO;
@@ -45,6 +50,7 @@ public class RettificaGiacenzeViewModel {
public MtbColt mCurrentMtbColt = null;
private final Handler handler;
private final ArticoloRESTConsumer mArticoloRESTConsumer;
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
private final PrinterRESTConsumer mPrinterRESTConsumer;
@@ -63,11 +69,13 @@ public class RettificaGiacenzeViewModel {
private boolean mAnyEditDone = false;
@Inject
public RettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer,
public RettificaGiacenzeViewModel(Handler handler,
ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
PrinterRESTConsumer printerRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer,
RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) {
this.handler = handler;
this.mArticoloRESTConsumer = articoloRESTConsumer;
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
this.mPrinterRESTConsumer = printerRESTConsumer;
@@ -111,28 +119,28 @@ public class RettificaGiacenzeViewModel {
}
public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO) throws Exception {
if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) {
//Not implemented now
onComplete.run();
return;
} else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) {
//Cerco tramite etichetta ean 128 (che può indicarmi un articolo o una UL)
this.executeEtichettaEan128(barcodeScanDTO, onComplete);
this.executeEtichettaEan128(barcodeScanDTO);
} else if (UtilityBarcode.isEanPeso(barcodeScanDTO)) {
//Cerco tramite articolo ean peso
this.executeEtichettaEanPeso(barcodeScanDTO, onComplete);
this.executeEtichettaEanPeso(barcodeScanDTO);
} else if (UtilityBarcode.isEtichettaArt(barcodeScanDTO)) {
this.searchArtInt(null, barcodeScanDTO, onComplete);
this.searchArtInt(null, barcodeScanDTO);
} else {
onComplete.run();
}
}
private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> {
private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO) throws Exception {
var ean128Model = mBarcodeRESTConsumer.decodeEan128Synchronized(barcodeScanDTO);
String barcodeProd = null;
String codMart = null;
@@ -147,71 +155,66 @@ public class RettificaGiacenzeViewModel {
if (!UtilityString.isNullOrEmpty(barcodeProd)) {
PickDataDTO pickDataDTO = PickDataDTO.fromEan128(ean128Model);
this.loadArticolo(barcodeProd, pickDataDTO, barcodeScanDTO, onComplete);
this.loadArticolo(barcodeProd, pickDataDTO, barcodeScanDTO);
} else if (!UtilityString.isNullOrEmpty(codMart)) {
this.searchArtInt(codMart, barcodeScanDTO, onComplete);
} else {
//EAN 128 non completo o comunque mancano i riferimenti al prodotto
onComplete.run();
}
}, this::sendError);
this.searchArtInt(codMart, barcodeScanDTO);
}
private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
}
private void executeEtichettaEanPeso(BarcodeScanDTO barcodeScanDTO) {
try {
Ean13PesoModel ean13PesoModel = Ean13PesoModel.fromBarcode(barcodeScanDTO.getStringValue());
this.loadArticolo(ean13PesoModel.getPrecode(), PickDataDTO.fromEan128(ean13PesoModel.toEan128()), barcodeScanDTO, onComplete);
this.loadArticolo(ean13PesoModel.getPrecode(), PickDataDTO.fromEan128(ean13PesoModel.toEan128()), barcodeScanDTO);
} catch (Exception ex) {
this.sendError(ex);
}
}
private void loadArticolo(String barcodeProd, PickDataDTO pickData, BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
this.mArticoloRESTConsumer.searchByBarcode(barcodeProd, mtbAartList -> {
if (onComplete != null) onComplete.run();
private void loadArticolo(String barcodeProd, PickDataDTO pickData, BarcodeScanDTO barcodeScanDTO) throws Exception {
var mtbAartList = this.mArticoloRESTConsumer.searchByBarcodeSynchronized(barcodeProd);
if (mtbAartList != null && !mtbAartList.isEmpty()) {
this.dispatchArts(mtbAartList, pickData, null, barcodeScanDTO);
} else {
this.sendError(new NoResultFromBarcodeException(barcodeProd));
}
}, this::sendError);
}
public void searchArtFor(String codAlis, String queryText) {
public void searchArtFor(String codAlis, String queryText) throws Exception {
this.sendOnLoadingStarted();
mRettificaGiacenzeRESTConsumer.searchArtForn(codAlis, queryText, listaArts -> {
var listaArts = mRettificaGiacenzeRESTConsumer.searchArtFornSynchronized(codAlis, queryText);
this.sendOnLoadingEnded();
List<MtbAart> mtbAarts = null;
if (listaArts != null)
mtbAarts = Stream.of(listaArts)
.map(x -> (MtbAart) x.getMtbAart())
.toList();
mtbAarts = listaArts.stream()
.map(SearchArticoloByCodArtFornOrDescrizioneResponseDTO::getMtbAart)
.collect(Collectors.toList());
dispatchArts(mtbAarts, null, queryText, null);
}, this::sendError);
}
public void searchArtInt(String queryText, BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
public void searchArtInt(String queryText, BarcodeScanDTO barcodeScanDTO) throws Exception {
this.sendOnLoadingStarted();
String barcode = barcodeScanDTO != null ? barcodeScanDTO.getStringValue() : null;
mRettificaGiacenzeRESTConsumer.searchArtInt(UtilityString.isNull(queryText, barcode), listaArts -> {
var listaArts = mRettificaGiacenzeRESTConsumer.searchArtIntSynchronized(UtilityString.isNull(queryText, barcode));
this.sendOnLoadingEnded();
dispatchArts(listaArts, null, queryText, barcodeScanDTO);
if (onComplete != null) onComplete.run();
}, this::sendError);
}
private void dispatchArts(List<MtbAart> artsList, PickDataDTO pickData, String description, BarcodeScanDTO barcodeProd) {
private void dispatchArts(List<MtbAart> artsList, PickDataDTO pickData, String description, BarcodeScanDTO barcodeProd) throws Exception {
if (artsList == null || artsList.isEmpty()) {
if (SettingsManager.iDB().isFlagEnableArtCreation())
this.sendRequestNewArtCreation(description, barcodeProd);
@@ -220,29 +223,31 @@ public class RettificaGiacenzeViewModel {
return;
}
RunnableArgs<MtbAart> dispatchArtRunnable = mtbAart -> {
MtbAart selectedArt = null;
var matchRows = Stream.of(this.mCurrentMtbColt.getMtbColr())
.filter(x -> x.getCodMart().equalsIgnoreCase(mtbAart.getCodMart()))
.toList();
if (artsList.size() == 1) {
selectedArt = artsList.get(0);
} else {
selectedArt = this.sendOnArtListLoaded(new ArrayList<>(artsList));
}
MtbAart finalSelectedArt = selectedArt;
var matchRows = this.mCurrentMtbColt.getMtbColr().stream()
.filter(x -> x.getCodMart().equalsIgnoreCase(finalSelectedArt.getCodMart()))
.collect(Collectors.toList());
if (matchRows.size() != 1) {
dispatchArt(mtbAart, pickData);
dispatchArt(selectedArt, pickData);
} else {
dispatchRowEdit(matchRows.get(0));
}
};
if (artsList.size() == 1) {
dispatchArtRunnable.run(artsList.get(0));
} else {
this.sendOnArtListLoaded(new ArrayList<>(artsList), dispatchArtRunnable);
}
}
public void dispatchArt(MtbAart mtbAart, PickDataDTO pickDataDTO) {
public void dispatchArt(MtbAart mtbAart, PickDataDTO pickDataDTO) throws Exception {
PickingObjectDTO pickingObjectDTO = new PickingObjectDTO()
.setMtbAart(mtbAart)
.setTempPickData(pickDataDTO);
@@ -320,7 +325,7 @@ public class RettificaGiacenzeViewModel {
dataScad.plusDays(pickingObjectDTO.getMtbAart().getGgScadPartita());
}
this.sendOnItemDispatched(
var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO,
pickingObjectDTO.getMtbAart(),
initialNumCnf,
@@ -337,20 +342,25 @@ public class RettificaGiacenzeViewModel {
dataScad,
false,
canPartitaMagBeChanged,
true,
(pickedQuantityDTO, shouldCloseLU) -> {
true);
if (pickedQuantityDTO == null) {
return;
}
this.saveNewRow(pickingObjectDTO,
pickedQuantityDTO.getNumCnf(),
pickedQuantityDTO.getQtaCnf(),
pickedQuantityDTO.getQtaTot(),
pickedQuantityDTO.getPartitaMag(),
pickedQuantityDTO.getDataScad(),
shouldCloseLU);
});
pickedQuantityDTO.isShouldCloseLu());
}
public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) {
public void saveNewRow(PickingObjectDTO pickingObjectDTO, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception {
this.sendOnLoadingStarted();
final MtbColr mtbColr = new MtbColr()
@@ -375,162 +385,142 @@ public class RettificaGiacenzeViewModel {
.setPosizioneIn(mCurrentMtbColt.getPosizione())
.setCodMdepIn(mCurrentMtbColt.getCodMdep());
var savedMtbColr = mColliMagazzinoRESTConsumer.creaRettificaColloSynchronized(mtbColr, numCnf, qtaTot);
MtbAart mtbAart = mArticoloRESTConsumer.getByCodMartSynchronized(savedMtbColr.getCodMart());
mColliMagazzinoRESTConsumer.creaRettificaCollo(mtbColr,
numCnf,
qtaTot,
savedMtbColr -> {
mtbColr
.setQtaCol(savedMtbColr.getQtaCol())
.setQtaCnf(savedMtbColr.getQtaCnf())
.setNumCnf(savedMtbColr.getNumCnf())
.setUntMis(pickingObjectDTO.getMtbAart().getUntMis())
.setMtbAart(pickingObjectDTO.getMtbAart());
.setUntMis(mtbAart.getUntMis())
.setMtbAart(mtbAart);
handler.post(() -> {
mCurrentMtbColt.getMtbColr().add(mtbColr);
});
this.mAnyEditDone = true;
this.sendOnRowSaved();
if (shouldCloseLU) closeLU(true, true);
this.sendOnLoadingEnded();
if (shouldCloseLU) closeLU(true, null);
}, this::sendError);
}
public void closeLU(boolean saveCausale) {
closeLU(saveCausale, null);
}
public void closeLU(boolean saveCausale, Runnable onComplete) {
public void closeLU(boolean saveCausale, boolean requestNewLu) throws Exception {
if (mCurrentMtbColt == null) {
if (onComplete != null) onComplete.run();
return;
}
this.sendOnLoadingStarted();
var canBeDeleted = this.mColliMagazzinoRESTConsumer.canULBeDeletedSynchronized(mCurrentMtbColt);
this.mColliMagazzinoRESTConsumer.canULBeDeleted(mCurrentMtbColt, canBeDeleted -> {
if (canBeDeleted) {
deleteLU(() -> {
this.sendLUClosed();
this.sendOnLoadingEnded();
});
deleteLU();
this.sendLUClosed(requestNewLu);
} else {
Runnable saveAction = () -> {
this.mColliMagazzinoRESTConsumer.updateDataFine(
mCurrentMtbColt, () -> {
this.askPostionChange(mCurrentMtbColt, () -> {
this.createDoc(mCurrentMtbColt, () -> {
this.mAnyEditDone = false;
postSaveBehaviour(onComplete);
});
});
}, this::sendError);
};
if (saveCausale || mAnyEditDone) {
this.saveCausaleRettificaGiacenze(saveAction);
} else {
saveAction.run();
this.saveCausaleRettificaGiacenze();
}
}
this.mColliMagazzinoRESTConsumer.synchronousUpdateDataFine(mCurrentMtbColt);
}, this::sendError);
this.askPostionChange(mCurrentMtbColt);
this.createDoc(mCurrentMtbColt);
this.mAnyEditDone = false;
postSaveBehaviour(requestNewLu);
}
private void askPostionChange(MtbColt mtbColt, Runnable onComplete) {
}
private void askPostionChange(MtbColt mtbColt) throws Exception {
if (mtbColt.getGestioneEnum() == GestioneEnum.VENDITA || mtbColt.getSegno() == -1 || !SettingsManager.iDB().isFlagPositionChangeRequest()) {
onComplete.run();
return;
}
this.sendLUPositionChangeRequest((shouldChangePosition, mtbDepoPosizione) -> {
if (shouldChangePosition) {
this.savePosizione(mtbDepoPosizione, onComplete);
} else {
onComplete.run();
}
});
var response = this.sendLUPositionChangeRequest();
if (response == null || !response.first) {
return;
}
private void createDoc(MtbColt mtbColt, Runnable onComplete) {
var mtbDepoPosizione = response.second;
if (mtbDepoPosizione == null) {
//Nessuna posizione trovata con questo barcode
throw new ScannedPositionNotExistException();
}
this.savePosizione(mtbDepoPosizione);
}
private void createDoc(MtbColt mtbColt) throws Exception {
if (!(mtbColt.getGestioneEnum() == GestioneEnum.VENDITA && mtbColt.getSegno() == -1) || !generaDocIfVendita) {
onComplete.run();
return;
}
mRettificaGiacenzeRESTConsumer.saveDoc(this.mCurrentMtbColt, onComplete, this::sendError);
mRettificaGiacenzeRESTConsumer.saveDocSynchronized(this.mCurrentMtbColt);
}
private void saveCausaleRettificaGiacenze(Runnable onComplete) {
this.mColliMagazzinoRESTConsumer.confirmGiacenzaUL(mCurrentMtbColt, onComplete, this::sendError);
private void saveCausaleRettificaGiacenze() throws Exception {
this.mColliMagazzinoRESTConsumer.confirmGiacenzaULSynchronized(mCurrentMtbColt);
}
private void savePosizione(MtbDepoPosizione mtbDepoPosizione, Runnable onComplete) {
this.mColliMagazzinoRESTConsumer.updatePosizioneUL(mCurrentMtbColt.getBarcodeUl(), mtbDepoPosizione != null ? mtbDepoPosizione.getPosizione() : CommonModelConsts.ENTITY_NULL_STRING,
onComplete,
this::sendError);
private void savePosizione(MtbDepoPosizione mtbDepoPosizione) throws Exception {
this.mColliMagazzinoRESTConsumer.updatePosizioneULSynchronized(mCurrentMtbColt.getBarcodeUl(), mtbDepoPosizione != null ? mtbDepoPosizione.getPosizione() : CommonModelConsts.ENTITY_NULL_STRING);
}
private void postSaveBehaviour(Runnable onComplete) {
private void postSaveBehaviour(boolean requestNewLu) {
if (!mCurrentMtbColt.getDisablePrint()) {
printLU(() -> {
this.mCurrentMtbColt = null;
this.sendLUClosed();
this.sendOnLoadingEnded();
if (onComplete != null) onComplete.run();
});
} else {
this.mCurrentMtbColt = null;
this.sendLUClosed();
this.sendOnLoadingEnded();
if (onComplete != null) onComplete.run();
}
printLU();
}
private void deleteLU(Runnable onComplete) {
this.mCurrentMtbColt = null;
this.sendLUClosed(requestNewLu);
}
private void deleteLU() throws Exception {
DeleteULRequestDTO deleteULRequestDTO = new DeleteULRequestDTO()
.setMtbColt(mCurrentMtbColt);
mColliMagazzinoRESTConsumer.deleteUL(deleteULRequestDTO, () -> {
mColliMagazzinoRESTConsumer.deleteULSynchronized(deleteULRequestDTO);
this.mCurrentMtbColt = null;
if (onComplete != null) onComplete.run();
}, this::sendError);
}
private void printLU(Runnable onComplete) {
private void printLU() {
var shouldPrint = this.sendLUPrintRequest();
if (!shouldPrint) {
onComplete.run();
} else {
return;
}
this.mPrinterRESTConsumer.printCollo(mCurrentMtbColt, () -> {
try {
this.mPrinterRESTConsumer.synchronousPrintCollo(mCurrentMtbColt);
this.sendLUSuccessfullyPrinted();
onComplete.run();
}, ex -> this.sendLUPrintError(ex, onComplete));
} catch (Exception e) {
this.sendLUPrintError(e);
}
}
public void dispatchRowEdit(MtbColr mtbColrToUpdate) {
public void dispatchRowEdit(MtbColr mtbColrToUpdate) throws Exception {
var newMtbAartList = this.mRettificaGiacenzeRESTConsumer.searchArtIntSynchronized(mtbColrToUpdate.getMtbAart().getCodMart());
this.mRettificaGiacenzeRESTConsumer.searchArtInt(mtbColrToUpdate.getMtbAart().getCodMart(), newMtbAartList -> {
var newMtbAart = newMtbAartList.get(0);
final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO()
.setMtbAart(newMtbAart);
this.sendOnItemDispatched(
var pickedQuantityDTO = this.sendOnItemDispatched(
pickingObjectDTO,
pickingObjectDTO.getMtbAart(),
mtbColrToUpdate.getNumCnf(),
@@ -545,8 +535,12 @@ public class RettificaGiacenzeViewModel {
mtbColrToUpdate.getDataScadPartita(),
false,
false,
true,
(pickedQuantityDTO, shouldCloseLU) -> {
true);
if (pickedQuantityDTO == null) {
return;
}
this.saveEditedRow(mtbColrToUpdate,
pickedQuantityDTO.getNumCnf(),
@@ -554,36 +548,35 @@ public class RettificaGiacenzeViewModel {
pickedQuantityDTO.getQtaTot(),
pickedQuantityDTO.getPartitaMag(),
pickedQuantityDTO.getDataScad(),
shouldCloseLU);
});
}, this::sendError);
pickedQuantityDTO.isShouldCloseLu());
}
private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) {
private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, LocalDate dataScad, boolean shouldCloseLU) throws Exception {
this.sendOnLoadingStarted();
this.mColliMagazzinoRESTConsumer.creaRettificaCollo(
var savedMtbColr = this.mColliMagazzinoRESTConsumer.creaRettificaColloSynchronized(
mtbColrToUpdate,
numCnf,
qtaTot,
savedMtbColr -> {
qtaTot);
mtbColrToUpdate
.setQtaCol(qtaTot)
.setQtaCnf(qtaCnf)
.setNumCnf(numCnf)
.setOperation(CommonModelConsts.OPERATION.NO_OP);
handler.post(() -> {
this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate);
this.mCurrentMtbColt.getMtbColr().add(mtbColrToUpdate);
});
this.mAnyEditDone = true;
this.sendOnRowSaved();
if (shouldCloseLU) closeLU(true, true);
this.sendOnLoadingEnded();
},
this::sendError
);
}
public void deleteRow(MtbColr mtbColrToDelete) {
@@ -596,7 +589,9 @@ public class RettificaGiacenzeViewModel {
BigDecimal.ZERO,
BigDecimal.ZERO,
savedMtbColr -> {
handler.post(() -> {
this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete);
});
this.sendOnLoadingEnded();
this.sendOnRowSaved();
},
@@ -623,8 +618,27 @@ public class RettificaGiacenzeViewModel {
}
private void sendOnArtListLoaded(ArrayList<MtbAart> artList, RunnableArgs<MtbAart> onArtChoosed) {
if (this.mListener != null) mListener.onArtListLoaded(artList, onArtChoosed);
private MtbAart sendOnArtListLoaded(ArrayList<MtbAart> artList) {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<MtbAart> result = new AtomicReference<>();
if (this.mListener != null) mListener.onArtListLoaded(artList, mtbAart -> {
result.set(mtbAart);
countDownLatch.countDown();
});
else {
result.set(null);
countDownLatch.countDown();
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
this.sendError(e);
}
return result.get();
}
private void sendOnLUOpenRequest(boolean enableCreation, boolean checkIfDocumentExists, boolean warnOnOpeningVendita, RunnableArgs<DialogScanOrCreateLUView.Result> onComplete) {
@@ -640,15 +654,15 @@ public class RettificaGiacenzeViewModel {
if (this.mListener != null) mListener.onLUOpened(mtbColt);
}
private void sendLUClosed() {
if (this.mListener != null) mListener.onLUClosed();
private void sendLUClosed(boolean requestNewLu) {
if (this.mListener != null) mListener.onLUClosed(requestNewLu);
}
private void sendMtbColrDeleteRequest(RunnableArgs<Boolean> onComplete) {
if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete);
}
private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
private PickedQuantityDTO sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
MtbAart mtbAart,
BigDecimal initialNumCnf,
BigDecimal initialQtaCnf,
@@ -664,8 +678,11 @@ public class RettificaGiacenzeViewModel {
LocalDate dataScad,
boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete) {
boolean canLUBeClosed) {
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<PickedQuantityDTO> result = new AtomicReference<>();
if (this.mListener != null) mListener.onItemDispatched(pickingObjectDTO,
mtbAart,
initialNumCnf,
@@ -683,7 +700,23 @@ public class RettificaGiacenzeViewModel {
canOverflowOrderQuantity,
canPartitaMagBeChanged,
canLUBeClosed,
onComplete);
pickedQuantity -> {
result.set(pickedQuantity);
countDownLatch.countDown();
});
else {
result.set(null);
countDownLatch.countDown();
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
this.sendError(e);
}
return result.get();
}
private void sendOnRowSaved() {
@@ -699,12 +732,26 @@ public class RettificaGiacenzeViewModel {
return false;
}
private void sendLUPrintError(Exception ex, Runnable onComplete) {
if (this.mListener != null) mListener.onLUPrintError(ex, onComplete);
private void sendLUPrintError(Exception ex) {
if (this.mListener != null) mListener.onLUPrintError(ex, null);
}
private void sendLUPositionChangeRequest(RunnableArgss<Boolean, MtbDepoPosizione> onComplete) {
if (this.mListener != null) mListener.onLUPositionChangeRequest(onComplete);
private Pair<Boolean, MtbDepoPosizione> sendLUPositionChangeRequest() {
final CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Pair<Boolean, MtbDepoPosizione>> result = new AtomicReference<>();
mListener.onLUPositionChangeRequest((status, data) -> {
result.set(new Pair<>(status, data));
latch.countDown();
});
try {
latch.await(); // Attende che il dialog venga chiuso
return result.get();
} catch (InterruptedException e) {
this.sendError(e);
}
return null;
}
public interface Listener extends ILUPrintListener, ILUPositionListener {
@@ -722,7 +769,7 @@ public class RettificaGiacenzeViewModel {
void onLUOpened(MtbColt mtbColt);
void onLUClosed();
void onLUClosed(boolean requestNewLu);
void onMtbColrDeleteRequest(RunnableArgs<Boolean> onComplete);
@@ -745,7 +792,7 @@ public class RettificaGiacenzeViewModel {
boolean canOverflowOrderQuantity,
boolean canPartitaMagBeChanged,
boolean canLUBeClosed,
RunnableArgss<PickedQuantityDTO, Boolean> onComplete);
RunnableArgs<PickedQuantityDTO> onComplete);
void onRowSaved();
}

View File

@@ -1,8 +1,5 @@
package it.integry.integrywmsnative.gest.rettifica_giacenze.rest;
import androidx.annotation.NonNull;
import com.annimon.stream.Stream;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
@@ -18,16 +15,11 @@ import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer;
import it.integry.integrywmsnative.core.rest.handler.ManagedErrorCallback;
import it.integry.integrywmsnative.core.rest.model.SaveDocFromPickingRequestDTO;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.FornitoreDTO;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByBarcodeOrCodMartRequestDTO;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByBarcodeOrCodMartResponseDTO;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByCodArtFornOrDescrizioneRequestDTO;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.SearchArticoloByCodArtFornOrDescrizioneResponseDTO;
import retrofit2.Call;
import retrofit2.Response;
@Singleton
public class RettificaGiacenzeRESTConsumer extends _BaseRESTConsumer {
@@ -52,42 +44,29 @@ public class RettificaGiacenzeRESTConsumer extends _BaseRESTConsumer {
}
public void searchArtForn(String codAlis, String codArtForOrDescr, RunnableArgs<List<SearchArticoloByCodArtFornOrDescrizioneResponseDTO>> onComplete, RunnableArgs<Exception> onError) {
public List<SearchArticoloByCodArtFornOrDescrizioneResponseDTO> searchArtFornSynchronized(String codAlis, String codArtForOrDescr) throws Exception {
final RettificaGiacenzeRESTConsumerService service = restBuilder.getService(RettificaGiacenzeRESTConsumerService.class);
service.searchByCodArtFornOrDescrizione(new SearchArticoloByCodArtFornOrDescrizioneRequestDTO()
var response = service.searchByCodArtFornOrDescrizione(new SearchArticoloByCodArtFornOrDescrizioneRequestDTO()
.setCodAlis(codAlis)
.setCodArtFornOrDescrizione(codArtForOrDescr))
.enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<List<SearchArticoloByCodArtFornOrDescrizioneResponseDTO>>> call,
Response<ServiceRESTResponse<List<SearchArticoloByCodArtFornOrDescrizioneResponseDTO>>> response) {
analyzeAnswer(response, "searchByCodArtFornOrDescrizione", onComplete, onError);
}
@Override
public void onFailure(Call<ServiceRESTResponse<List<SearchArticoloByCodArtFornOrDescrizioneResponseDTO>>> call, @NonNull final Exception e) {
onError.run(e);
}
});
.execute();
var data = analyzeAnswer(response, "searchByCodArtFornOrDescrizione");
return data;
}
public void searchArtInt(String codMartOrBarcodeOrDescr, RunnableArgs<List<MtbAart>> onComplete, RunnableArgs<Exception> onError) {
public List<MtbAart> searchArtIntSynchronized(String codMartOrBarcodeOrDescr) throws Exception {
final RettificaGiacenzeRESTConsumerService service = restBuilder.getService(RettificaGiacenzeRESTConsumerService.class);
service.searchByCodMartOrBarcode(new SearchArticoloByBarcodeOrCodMartRequestDTO()
var response = service.searchByCodMartOrBarcode(new SearchArticoloByBarcodeOrCodMartRequestDTO()
.setCodMartOrBarcode(codMartOrBarcodeOrDescr))
.enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<List<SearchArticoloByBarcodeOrCodMartResponseDTO>>> call,
Response<ServiceRESTResponse<List<SearchArticoloByBarcodeOrCodMartResponseDTO>>> response) {
analyzeAnswer(response, "searchByCodMartOrBarcode", data -> {
.execute();
if(data == null) data = new ArrayList<>();
var data = analyzeAnswer(response, "searchByCodMartOrBarcode");
var listToReturn = Stream.of(data)
if (data == null) data = new ArrayList<>();
var listToReturn = data.stream()
.map(x -> x.getMtbAart()
.setQtaEsistente(x.getQtaEsistente())
.setQtaImpegnata(x.getQtaImpegnata())
@@ -95,36 +74,19 @@ public class RettificaGiacenzeRESTConsumer extends _BaseRESTConsumer {
.setNumCnfImpegnata(x.getNumCnfImpegnata()))
.toList();
onComplete.run(listToReturn);
}, onError);
}
@Override
public void onFailure(Call<ServiceRESTResponse<List<SearchArticoloByBarcodeOrCodMartResponseDTO>>> call, @NonNull final Exception e) {
onError.run(e);
}
});
return listToReturn;
}
public void saveDoc(MtbColt mtbColt, Runnable onComplete, RunnableArgs<Exception> onError) {
public void saveDocSynchronized(MtbColt mtbColt) throws Exception {
var request = new SaveDocFromPickingRequestDTO()
.setColliFromMtbColts(Collections.singletonList(mtbColt));
final RettificaGiacenzeRESTConsumerService service = restBuilder.getService(RettificaGiacenzeRESTConsumerService.class);
service.saveDocFromPickingPvm(request)
.enqueue(new ManagedErrorCallback<>() {
@Override
public void onResponse(Call<ServiceRESTResponse<Void>> call, Response<ServiceRESTResponse<Void>> response) {
analyzeAnswerList(response, "saveDocFromPickingPvm", data -> onComplete.run(), onError);
}
@Override
public void onFailure(Call<ServiceRESTResponse<Void>> call, @NonNull final Exception e) {
onError.run(e);
}
});
var response = service.saveDocFromPickingPvm(request)
.execute();
var data = analyzeAnswerList(response, "saveDocFromPickingPvm");
}
}

View File

@@ -293,7 +293,7 @@
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:onClick="@{() -> viewmodel.closeLU(true)}"
android:onClick="@{() -> view.closeLU(true)}"
android:tint="@android:color/white"
app:srcCompat="@drawable/ic_round_check_24"
app:visibility="@{view.thereIsAnOpenedUL}" />