diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java index 8fc662e3..e2b3b69e 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoFragment.java @@ -4,6 +4,7 @@ package it.integry.integrywmsnative.gest.picking_libero; import android.app.Dialog; import android.content.Context; import android.os.Bundle; +import android.text.SpannableString; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -49,8 +50,10 @@ import it.integry.integrywmsnative.gest.spedizione.exceptions.InvalidPesoKGExcep import it.integry.integrywmsnative.gest.spedizione.model.PickedQuantityDTO; import it.integry.integrywmsnative.gest.spedizione.model.PickingObjectDTO; import it.integry.integrywmsnative.ui.ElevatedToolbar; +import it.integry.integrywmsnative.view.bottom_sheet__mtb_colr_edit.BottomSheetMtbColrEditView; import it.integry.integrywmsnative.view.dialogs.DialogConsts; import it.integry.integrywmsnative.view.dialogs.ask_cliente.DialogAskCliente; +import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageHelper; import it.integry.integrywmsnative.view.dialogs.choose_arts_from_lista_arts.DialogChooseArtsFromListaArts; import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2; import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2DTO; @@ -58,7 +61,7 @@ import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQua /** * A simple {@link Fragment} subclass. */ -public class PickingLiberoFragment extends Fragment implements ITitledFragment, IScrollableFragment, PickingLiberoViewModel.Listener { +public class PickingLiberoFragment extends Fragment implements ITitledFragment, IScrollableFragment, PickingLiberoViewModel.Listener, BottomSheetMtbColrEditView.Listener { private FragmentPickingLiberoBinding mBindings; @@ -129,6 +132,7 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, this.initVars(); this.initBarcodeReader(); + this.initBottomSheet(); this.initRecyclerView(); boolean flagAskCliente = SettingsManager.iDB().isFlagAskClienteInPickingLibero(); @@ -153,6 +157,11 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); } + private void initBottomSheet() { + mBindings.bottomSheetMtbColrEdit.setListener(this); + mBindings.bottomSheetMtbColrEdit.init(mBindings.bottomSheetMtbColrEdit, mBindings.bottomSheetMtbColrEditBackground); + } + private void initRecyclerView() { mBindings.pickingLiberoMainList.setNestedScrollingEnabled(false); @@ -167,6 +176,11 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, private void initAdapter() { mAdapter = new PickingLiberoListAdapter(mViewModel.getCurrentMtbColt().getMtbColr()); mBindings.pickingLiberoMainList.setAdapter(mAdapter); + + this.mAdapter.setOnItemClickListener(clickedMtbColr -> { + mBindings.bottomSheetMtbColrEdit.setMtbColr(clickedMtbColr); + mBindings.bottomSheetMtbColrEdit.expand(); + }); } private void destroyAdapter() { @@ -266,6 +280,17 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, thereIsAnOpenedUL.set(false); } + @Override + public void onMtbColrDeleteRequest(RunnableArgs onComplete) { + String text = getResources().getString(R.string.alert_delete_mtb_colr); + DialogSimpleMessageHelper.makeWarningDialog(getActivity(), + new SpannableString(text), + null, + () -> onComplete.run(true), + () -> onComplete.run(false) + ).show(); + } + @Override public void onError(Exception ex) { this.closeProgress(); @@ -306,9 +331,9 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, - BigDecimal totalQtaToBeTaken, - BigDecimal totalNumCnfToBeTaken, - BigDecimal qtaCnfToBeTaken, + BigDecimal totalQtaAvailable, + BigDecimal totalNumCnfAvailable, + BigDecimal qtaCnfAvailable, String partitaMag, Date dataScad, boolean canOverflowOrderQuantity, @@ -321,9 +346,9 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, .setInitialNumCnf(initialNumCnf) .setInitialQtaCnf(initialQtaCnf) .setInitialQtaTot(initialQtaTot) - .setTotalQtaToBeTaken(totalQtaToBeTaken) - .setTotalNumCnfToBeTaken(totalNumCnfToBeTaken) - .setQtaCnfToBeTaken(qtaCnfToBeTaken) + .setTotalQtaAvailable(totalQtaAvailable) + .setTotalNumCnfAvailable(totalNumCnfAvailable) + .setQtaCnfAvailable(qtaCnfAvailable) .setPartitaMag(partitaMag) .setDataScad(dataScad) .setCanOverflowOrderQuantity(canOverflowOrderQuantity) @@ -351,4 +376,16 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment, public void onRowSaved() { FBToast.successToast(getActivity(), getResources().getString(R.string.data_saved), FBToast.LENGTH_SHORT); } + + + + @Override + public void onMtbColrEdit(MtbColr mtbColr) { + this.mViewModel.dispatchRowEdit(mtbColr); + } + + @Override + public void onMtbColrDelete(MtbColr mtbColr) { + this.mViewModel.deleteRow(mtbColr); + } } diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java index 027ee950..bac826c6 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/PickingLiberoViewModel.java @@ -29,6 +29,7 @@ import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsume import it.integry.integrywmsnative.core.rest.consumers.PrinterRESTConsumer; import it.integry.integrywmsnative.core.rest.model.Ean128Model; import it.integry.integrywmsnative.core.rest.model.Ean13PesoModel; +import it.integry.integrywmsnative.core.settings.SettingsManager; import it.integry.integrywmsnative.core.utility.UtilityBarcode; import it.integry.integrywmsnative.core.utility.UtilityBigDecimal; import it.integry.integrywmsnative.core.utility.UtilityDate; @@ -345,13 +346,28 @@ public class PickingLiberoViewModel { mColliMagazzinoRESTConsumer.saveCollo(clonedTestata, value -> { for (int i = 0; i < mtbColrObservableField.size(); i++) { + MtbColr initialMtbColr = mtbColrObservableField.get(i); - mtbColrObservableField.get(i) + initialMtbColr .setDataCollo(value.getDataColloS()) .setNumCollo(value.getNumCollo()) .setGestione(value.getGestione()) .setSerCollo(value.getSerCollo()); + initialMtbColr.setRiga(value.getMtbColr().get(i).getRiga()); + +// for (int j = 0; j < value.getMtbColr().size(); j++) { +// MtbColr savedMtbColr = value.getMtbColr().get(j); +// if (savedMtbColr.getCodMart().equals(initialMtbColr.getCodMart()) && +// UtilityString.equalsIgnoreCase(savedMtbColr.getPartitaMag(), initialMtbColr.getPartitaMag()) && +// UtilityString.equalsIgnoreCase(savedMtbColr.getCodCol(), initialMtbColr.getCodCol()) && +// UtilityString.equalsIgnoreCase(savedMtbColr.getCodTagl(), initialMtbColr.getCodTagl()) && +// savedMtbColr.getQtaCol().equals(initialMtbColr.getQtaCol()) && +// savedMtbColr.getNumCnf().equals(initialMtbColr.getNumCnf())) { +// initialMtbColr.setRiga(savedMtbColr.getRiga()); +// } +// } + mCurrentMtbColt.getMtbColr().add(mtbColrObservableField.get(i)); } @@ -475,6 +491,176 @@ public class PickingLiberoViewModel { } + private void loadRifULFromMtbColr(MtbColr mtbColr, RunnableArgs onComplete) { + //Se ho dei riferimenti ad una UL devo leggere la QTA ancora disponibile sulla Ul + if (mtbColr != null && + !UtilityString.isNullOrEmpty(mtbColr.getGestioneRif()) && + !UtilityString.isNullOrEmpty(mtbColr.getSerColloRif()) && + !UtilityString.isNullOrEmpty(mtbColr.getDataColloRifS()) && + mtbColr.getNumColloRif() != null) { + + mColliMagazzinoRESTConsumer.getByChiaveCollo( + mtbColr.getGestioneRifEnum(), + mtbColr.getNumColloRif(), + mtbColr.getDataColloRifS(), + mtbColr.getSerColloRif(), + true, + false, + onComplete, + this::sendError); + + } else { + onComplete.run(null); + } + } + + + public void dispatchRowEdit(MtbColr mtbColrToUpdate) { + + final PickingObjectDTO pickingObjectDTO = new PickingObjectDTO() + .setMtbAart(mtbColrToUpdate.getMtbAart()); + + loadRifULFromMtbColr(mtbColrToUpdate, mtbColtRif -> { + + + + BigDecimal totalQtaAvailable = null; + BigDecimal totalNumCnfAvailable = null; + BigDecimal qtaCnfAvailable = null; + + List mtbColrRifs = mtbColtRif != null && + mtbColtRif.getMtbColr() != null ? mtbColtRif.getMtbColr() : null; + + MtbColr mtbColrRif = null; + + if (mtbColrRifs != null && mtbColrRifs.size() > 0) { + //TODO: Da capire se รจ necessario controllare anche il cod_jcom + mtbColrRif = Stream.of(mtbColrRifs) + .filter(x -> UtilityString.equalsIgnoreCase(x.getCodMart(), mtbColrToUpdate.getCodMart()) && + UtilityString.equalsIgnoreCase(x.getCodCol(), mtbColrToUpdate.getCodCol()) && + UtilityString.equalsIgnoreCase(x.getCodTagl(), mtbColrToUpdate.getCodTagl()) && + UtilityString.equalsIgnoreCase(x.getPartitaMag(), mtbColrToUpdate.getPartitaMag())) + .single(); + } + + + if (mtbColrRif != null) { + + totalQtaAvailable = mtbColrRif.getQtaCol().add(mtbColrToUpdate.getQtaCol()); + totalNumCnfAvailable = mtbColrRif.getNumCnf().add(mtbColrToUpdate.getNumCnf()); + qtaCnfAvailable = mtbColrRif.getQtaCnf(); + + } else { + + totalQtaAvailable = mtbColrToUpdate.getQtaCol(); + totalNumCnfAvailable = mtbColrToUpdate.getNumCnf(); + qtaCnfAvailable = mtbColrToUpdate.getQtaCnf(); + + } + + this.sendOnItemDispatched( + pickingObjectDTO, + pickingObjectDTO.getMtbAart(), + mtbColrToUpdate.getNumCnf(), + mtbColrToUpdate.getQtaCnf(), + mtbColrToUpdate.getQtaCol(), + totalQtaAvailable, + totalNumCnfAvailable, + qtaCnfAvailable, + mtbColrToUpdate.getPartitaMag(), + mtbColrToUpdate.getDataScadPartitaD(), + false, + false, + true, + (pickedQuantityDTO, shouldCloseLU) -> { + + this.saveEditedRow(mtbColrToUpdate, + pickedQuantityDTO.getNumCnf(), + pickedQuantityDTO.getQtaCnf(), + pickedQuantityDTO.getQtaTot(), + pickedQuantityDTO.getPartitaMag(), + pickedQuantityDTO.getDataScad(), + shouldCloseLU); + }); + + + }); + } + + + private void saveEditedRow(MtbColr mtbColrToUpdate, BigDecimal numCnf, BigDecimal qtaCnf, BigDecimal qtaTot, String partitaMag, Date dataScad, boolean shouldCloseLU) { + + this.sendOnLoadingStarted(); + + + MtbColt mtbColt = new MtbColt() + .setNumCollo(mtbColrToUpdate.getNumCollo()) + .setDataCollo(mtbColrToUpdate.getDataColloS()) + .setSerCollo(mtbColrToUpdate.getSerCollo()) + .setGestione(mtbColrToUpdate.getGestione()) + .setMtbColr(new ObservableArrayList<>()); + mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); + + final MtbColr mtbColr = (MtbColr) mtbColrToUpdate.clone(); + mtbColr.setOperation(CommonModelConsts.OPERATION.UPDATE); + mtbColr + .setNumCnf(numCnf) + .setQtaCnf(qtaCnf) + .setQtaCol(qtaTot) + .setPartitaMag(partitaMag) + .setDataScadPartita(dataScad) + .setUtente(SettingsManager.i().user.fullname) + .setCausale(MtbColr.Causale.RETTIFICA) + .setDatetimeRow(UtilityDate.getDateInstance()); + + mtbColt.getMtbColr().add(mtbColr); + + this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> { + + mtbColr.setNumCnf(numCnf) + .setQtaCnf(qtaCnf) + .setQtaCol(qtaTot); + + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToUpdate); + this.mCurrentMtbColt.getMtbColr().add(mtbColr); + + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); + + }, this::sendError); + } + + + public void deleteRow(MtbColr mtbColrToDelete) { + this.sendMtbColrDeleteRequest(shouldDelete -> { + if (shouldDelete) { + this.sendOnLoadingStarted(); + + MtbColt mtbColt = new MtbColt() + .setNumCollo(mtbColrToDelete.getNumCollo()) + .setDataCollo(mtbColrToDelete.getDataColloS()) + .setSerCollo(mtbColrToDelete.getSerCollo()) + .setGestione(mtbColrToDelete.getGestione()) + .setMtbColr(new ObservableArrayList<>()); + mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); + + MtbColr mtbColr = (MtbColr) mtbColrToDelete.clone(); + + mtbColr.setOperation(CommonModelConsts.OPERATION.DELETE); + mtbColt.getMtbColr().add(mtbColr); + + this.mColliMagazzinoRESTConsumer.saveCollo(mtbColt, (value) -> { + this.mCurrentMtbColt.getMtbColr().remove(mtbColrToDelete); + + this.sendOnRowSaved(); + this.sendOnLoadingEnded(); + + }, this::sendError); + } + }); + } + + public void closeLU() { if (mCurrentMtbColt == null) return; @@ -528,12 +714,17 @@ public class PickingLiberoViewModel { if (this.mListener != null) mListener.onLUClosed(); } + private void sendMtbColrDeleteRequest(RunnableArgs onComplete) { + if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete); + } + private void sendLUClienteRequired(RunnableArgs onComplete, Runnable onAbort) { if (this.mListener != null) mListener.onLUClienteRequired(onComplete, onAbort); } private void sendArtSelectionRequest(List mtbColrsToPick, RunnableArgs> onComplete, Runnable onAbort) { - if (this.mListener != null) mListener.onArtSelectionRequest(mtbColrsToPick, onComplete, onAbort); + if (this.mListener != null) + mListener.onArtSelectionRequest(mtbColrsToPick, onComplete, onAbort); } private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO, @@ -541,9 +732,9 @@ public class PickingLiberoViewModel { BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, - BigDecimal totalQtaToBeTaken, - BigDecimal totalNumCnfToBeTaken, - BigDecimal qtaCnfToBeTaken, + BigDecimal totalQtaAvailable, + BigDecimal totalNumCnfAvailable, + BigDecimal qtaCnfAvailable, String partitaMag, Date dataScad, boolean canOverflowOrderQuantity, @@ -555,9 +746,9 @@ public class PickingLiberoViewModel { initialNumCnf, initialQtaCnf, initialQtaTot, - totalQtaToBeTaken, - totalNumCnfToBeTaken, - qtaCnfToBeTaken, + totalQtaAvailable, + totalNumCnfAvailable, + qtaCnfAvailable, partitaMag, dataScad, canOverflowOrderQuantity, @@ -584,6 +775,8 @@ public class PickingLiberoViewModel { void onLUClosed(); + void onMtbColrDeleteRequest(RunnableArgs onComplete); + void onError(Exception ex); void onLUClienteRequired(RunnableArgs onComplete, Runnable onAbort); @@ -595,9 +788,9 @@ public class PickingLiberoViewModel { BigDecimal initialNumCnf, BigDecimal initialQtaCnf, BigDecimal initialQtaTot, - BigDecimal totalQtaToBeTaken, - BigDecimal totalNumCnfToBeTaken, - BigDecimal qtaCnfToBeTaken, + BigDecimal totalQtaAvailable, + BigDecimal totalNumCnfAvailable, + BigDecimal qtaCnfAvailable, String partitaMag, Date dataScad, boolean canOverflowOrderQuantity, diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/core/PickingLiberoListAdapter.java b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/core/PickingLiberoListAdapter.java index c32582f2..434be576 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/core/PickingLiberoListAdapter.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/picking_libero/core/PickingLiberoListAdapter.java @@ -83,7 +83,7 @@ public class PickingLiberoListAdapter extends ExtendedRecyclerView { - - private Activity mContext; - private FragmentMainRettificaGiacenzeBinding mBinding; - - private BottomSheetBehavior mBottomSheetBehavior; - - private RettificaGiacenzeHelper mHelper; - private RettificaGiacenzeMainListAdapter mAdapter; - - public ObservableField mtbColt = new ObservableField<>(); - public BindableBoolean isFabVisible = new BindableBoolean(); - public BindableBoolean isMtbColtLoaded = new BindableBoolean(); - - private boolean isCreatedLU = true; - - - public void init(Activity context, FragmentMainRettificaGiacenzeBinding binding, RettificaGiacenzeHelper helper) { - mContext = context; - mBinding = binding; - mHelper = helper; - } - - public void setMtbColt(MtbColt mtbColt, boolean isCreated) { - this.mtbColt.set(mtbColt); - this.isCreatedLU = isCreated; - - isFabVisible.set(mtbColt != null); - isMtbColtLoaded.set(mtbColt != null); - - if (this.mtbColt.get().getMtbColr() == null) - this.mtbColt.get().setMtbColr(new ObservableArrayList<>()); - else { - ObservableArrayList mtbColrList = this.mtbColt.get().getMtbColr(); - - for (int i = 0; i < mtbColrList.size(); i++) { - if (mtbColrList.get(i).getQtaCol() == null || mtbColrList.get(i).getQtaCol().floatValue() < 0) { - mtbColrList.remove(i); - i--; - } - } - - } - - - initRecyclerView(); - initBottomSheetActions(); - } - - public void resetMtbColt(boolean openNew) { - this.mtbColt.set(null); - isFabVisible.set(false); - isMtbColtLoaded.set(false); - mBinding.rettificaGiacenzeMainList.setAdapter(null); - - ((IPoppableActivity) mContext).pop(); - } - - - private void initRecyclerView() { - mBinding.rettificaGiacenzeMainList.setNestedScrollingEnabled(false); - - mBinding.rettificaGiacenzeMainList.setHasFixedSize(true); - - mBinding.rettificaGiacenzeMainList.setLayoutManager(new LinearLayoutManager(mContext)); - - DividerItemDecoration itemDecorator = new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL); - itemDecorator.setDrawable(ContextCompat.getDrawable(mContext, R.drawable.divider)); - mBinding.rettificaGiacenzeMainList.addItemDecoration(itemDecorator); - -// mAdapter = new RettificaGiacenzeMainListAdapter(mContext, mtbColt.get().getMtbColr(), this, mBinding.rettificaGiacenzeEmptyView); -// mBinding.rettificaGiacenzeMainList.setAdapter(mAdapter); - } - - private void initBottomSheetActions() { -// mBinding.bg.setOnClickListener(v -> mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED)); - -// mBottomSheetBehavior = BottomSheetBehavior.from(mBinding.bottomSheetActions); - -// mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { -// @Override -// public void onStateChanged(@NonNull View bottomSheet, int newState) { -// if (newState == BottomSheetBehavior.STATE_COLLAPSED) -// mBinding.bg.setVisibility(View.GONE); -// } -// -// @Override -// public void onSlide(@NonNull View bottomSheet, float slideOffset) { -// mBinding.bg.setVisibility(View.VISIBLE); -// mBinding.bg.setAlpha(slideOffset); -// } -// }); - } - - public RunnableArgs onScanSuccessfull = data -> { - - BarcodeManager.disable(); - - Dialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext); - - if (data.getType() == BarcodeType.EAN8 || data.getType() == BarcodeType.EAN13 || data.getType() == BarcodeType.UPCA) { - searchArtInt(data.getStringValue(), progressDialog); - } else if (UtilityBarcode.isEtichetta128(data)) { - this.executeEtichettaEan128(data, progressDialog); - } else { - BarcodeManager.enable(); - progressDialog.dismiss(); - } - - }; - - - private void executeEtichettaEan128(BarcodeScanDTO barcodeScanDTO, Dialog progressDialog) { - BarcodeRESTConsumer.decodeEan128Static(barcodeScanDTO, ean128Model -> { - - String barcodeProd = null; - - if (!UtilityString.isNullOrEmpty(ean128Model.Sscc)) barcodeProd = ean128Model.Sscc; - if (!UtilityString.isNullOrEmpty(ean128Model.Gtin)) barcodeProd = ean128Model.Gtin; - if (!UtilityString.isNullOrEmpty(ean128Model.Content)) - barcodeProd = ean128Model.Content; - - if (!UtilityString.isNullOrEmpty(barcodeProd)) { - if (barcodeProd.startsWith("0") || barcodeProd.startsWith("9")) { - barcodeProd = barcodeProd.substring(1, barcodeProd.length()); - } - this.loadBarcodeArticolo(barcodeProd, ean128Model, progressDialog); - } else { - //EAN 128 non completo o comunque mancano i riferimenti al prodotto - progressDialog.dismiss(); - BarcodeManager.enable(); - } - }, ex -> { - UtilityExceptions.defaultException(mContext, ex, progressDialog); - BarcodeManager.enable(); - }); - } - - - private void loadBarcodeArticolo(String barcodeProd, Ean128Model ean128Model, Dialog progressDialog) { - if (barcodeProd.length() == 14) { -// barcodeProd = UtilityBarcode.convertITF14toNeutral(barcodeProd); - barcodeProd = UtilityBarcode.convertITF14toEAN13(barcodeProd); - } - - ArticoloRESTConsumer.getByBarcodeProdStatic(barcodeProd, mtbAartList -> { - - if (mtbAartList != null && mtbAartList.size() > 0) { - - this.dispatchArt(mtbAartList.get(0), ean128Model); - - BarcodeManager.enable(); - progressDialog.dismiss(); - - } else { - BarcodeManager.enable(); - progressDialog.dismiss(); - - DialogSimpleMessageHelper.makeWarningDialog(mContext, - new SpannableString(mContext.getResources().getText(R.string.no_result_from_barcode)), - null, null) - .show(); - } - - }, ex -> { - BarcodeManager.enable(); - UtilityExceptions.defaultException(mContext, ex, progressDialog); - }); - } - - - public void setupSearchFornitori(ArrayList listaFornitori) { - AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(mContext, listaFornitori); - mBinding.autoCompleteFornitori.setAdapter(autoCompleteFornitoreAdapter); - mBinding.autoCompleteFornitori.setDropDownWidth(mContext.getResources().getDisplayMetrics().widthPixels); - - mBinding.inputCodArtDescrForn.setOnEditorActionListener((v, actionId, event) -> { - if (actionId == EditorInfo.IME_ACTION_DONE) { - resetAllError(); - if (UtilityString.isNullOrEmpty(mBinding.autoCompleteFornitori.getText().toString())) { - setError(mBinding.autoCompleteFornitoriLayout, mContext.getResources().getText(R.string.error).toString()); - return true; - } - - if (UtilityString.isNullOrEmpty(mBinding.inputCodArtDescrForn.getText().toString())) { - setError(mBinding.layoutCodArtDescrForn, mContext.getResources().getText(R.string.error).toString()); - return true; - } - - searchArtFor( - mBinding.autoCompleteFornitori.getText().toString(), - mBinding.inputCodArtDescrForn.getText().toString()); - return true; - } - return false; - }); - - - mBinding.inputCodArtDescrInt.setOnEditorActionListener((v, actionId, event) -> { - if (actionId == EditorInfo.IME_ACTION_DONE) { - resetAllError(); - - if (UtilityString.isNullOrEmpty(mBinding.inputCodArtDescrInt.getText().toString())) { - setError(mBinding.layoutCodArtDescrInt, mContext.getResources().getText(R.string.error).toString()); - return true; - } - - searchArtInt(mBinding.inputCodArtDescrInt.getText().toString(), UtilityProgress.createDefaultProgressDialog(mContext)); - return true; - } - return false; - }); - } - - - private void setError(TextInputLayout textInputLayout, String message) { - textInputLayout.setErrorEnabled(true); - textInputLayout.setError(message); - textInputLayout.setErrorIconDrawable(null); - } - - private void resetAllError() { - resetError(mBinding.autoCompleteFornitoriLayout); - resetError(mBinding.layoutCodArtDescrForn); - resetError(mBinding.layoutCodArtDescrInt); - } - - private void resetTexts() { - //mBinding.autoCompleteFornitori.setText(""); - mBinding.inputCodArtDescrForn.setText(""); - mBinding.inputCodArtDescrInt.setText(""); - } - - private void resetError(TextInputLayout textInputLayout) { - textInputLayout.setErrorEnabled(false); - textInputLayout.setError(null); - } - - private void searchArtFor(String codAlis, String queryText) { - final Dialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext); - //progressDialog.show(); - - mHelper.searchArtForn(codAlis, queryText, listaArts -> { - progressDialog.dismiss(); - - List mtbAarts = Stream.of(listaArts).map(x -> (MtbAart) x).toList(); - - dispatchArtsList(mtbAarts); - }, ex -> UtilityExceptions.defaultException(mContext, ex, progressDialog)); - } - - private void searchArtInt(String queryText, Dialog progressDialog) { - //progressDialog.show(); - - mHelper.searchArtInt(queryText, listaArts -> { - progressDialog.dismiss(); - BarcodeManager.enable(); - dispatchArtsList(listaArts); - }, ex -> { - UtilityExceptions.defaultException(mContext, ex, progressDialog); - BarcodeManager.enable(); - }); - } - - - private void dispatchArtsList(List articoloFornitoreDTOS) { - - if (articoloFornitoreDTOS != null) { - if (articoloFornitoreDTOS.size() == 0) { - showNoArtsFound(); - } else if (articoloFornitoreDTOS.size() == 1) { - dispatchArt(articoloFornitoreDTOS.get(0), null); - } else { - DialogChooseArtFromListaArts.make(mContext, articoloFornitoreDTOS, mtbAart -> this.dispatchArt(mtbAart, null)).show(); - } - } else { - showNoArtsFound(); - } - } - - private void showNoArtsFound() { - DialogSimpleMessageHelper.makeWarningDialog(mContext, - new SpannableString(mContext.getResources().getText(R.string.no_items_found_message)), - null, null).show(); - } - - - private void dispatchArt(MtbAart mtbAart, Ean128Model ean128Model) { - DialogInputQuantity.DTO qtaDto = new DialogInputQuantity.DTO(); - - qtaDto.setMtbAart(mtbAart); - - qtaDto.setQtaCnf(mtbAart.getQtaCnf()); - qtaDto.setNumCnf(1); - qtaDto.setQtaTot(mtbAart.getQtaCnf()); - - qtaDto.setQtaDaEvadere(new BigDecimal(-1)); - qtaDto.setQtaDisponibile(new BigDecimal(-1)); - - qtaDto.setCanPartitaMagBeChanged(true); - qtaDto.setCanDataScadBeChanged(true); - - - if (ean128Model != null) { - if (!UtilityString.isNullOrEmpty(ean128Model.BatchLot)) { - qtaDto.setBatchLot(ean128Model.BatchLot); - qtaDto.setCanPartitaMagBeChanged(false); - } - - try { - if (!UtilityString.isNullOrEmpty(ean128Model.BestBefore)) { - qtaDto.setDataScad(UtilityDate.recognizeDate(ean128Model.BestBefore)); - qtaDto.setCanDataScadBeChanged(false); - } else if (!UtilityString.isNullOrEmpty(ean128Model.Expiry)) { - qtaDto.setDataScad(UtilityDate.recognizeDate(ean128Model.Expiry)); - qtaDto.setCanDataScadBeChanged(false); - } - - } catch (Exception e) { - UtilityLogger.errorMe(e); - } - - - if (ean128Model.Count != null && ean128Model.Count > 0) { - qtaDto.setNumCnf(ean128Model.Count); - } - - if (ean128Model.NetWeightKg != null && ean128Model.NetWeightKg > 0) { - qtaDto.setQtaTot(new BigDecimal(ean128Model.NetWeightKg)); - } else { - qtaDto.setQtaTot(qtaDto.getQtaCnf().multiply(new BigDecimal(qtaDto.getNumCnf()))); - } - - - qtaDto.setShouldAskDataScad(true); - } - - - DialogInputQuantity.makeBase(mContext, qtaDto, true, (quantityDTO) -> { - onPostDispatch(mtbAart, quantityDTO); - }, null).show(); - } - - - private void onPostDispatch(MtbAart mtbAart, QuantityDTO quantityDTO) { - - final Dialog progress = UtilityProgress.createDefaultProgressDialog(mContext); - - final MtbColr mtbColr = new MtbColr() - .setCodMart(mtbAart.getCodMart()) - .setPartitaMag(quantityDTO.batchLot.get()) - .setDataScadPartita(quantityDTO.expireDate) - .setDescrizione(mtbAart.getDescrizioneEstesa()) - .setCausale(MtbColr.Causale.RETTIFICA) - .setUtente(SettingsManager.i().user.fullname); - - mtbColr.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); - - if (!isCreatedLU) { - mtbColr - .setQtaCol(BigDecimal.ZERO) - .setNumCnf(BigDecimal.ZERO) - .setDataCollo(mtbColt.get().getDataColloS()) - .setNumCollo(mtbColt.get().getNumCollo()) - .setGestione(mtbColt.get().getGestione()) - .setSerCollo(mtbColt.get().getSerCollo()); - - ColliMagazzinoRESTConsumer.creaRettificaColloStatic(mtbColr, - quantityDTO.numCnf.getBigDecimal(), - quantityDTO.qtaTot.getBigDecimal(), - () -> { - mtbColr.setUntMis(mtbAart.getUntMis()) - .setMtbAart(mtbAart); - - mtbColt.get().getMtbColr().add(mtbColr); - FBToast.successToast(mContext, mContext.getResources().getString(R.string.data_saved), FBToast.LENGTH_SHORT); - - resetTexts(); - progress.dismiss(); - }, ex -> { - UtilityExceptions.defaultException(mContext, ex, progress); - }); - } else { - mtbColr - .setQtaCol(quantityDTO.qtaTot.getBigDecimal()) - .setNumCnf(quantityDTO.numCnf.getBigDecimal()); - - MtbColt cloneMtbColt = (MtbColt) mtbColt.get().clone(); - cloneMtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); - - cloneMtbColt.setMtbColr(new ObservableArrayList<>()); - - ColliMagazzinoRESTConsumer.saveColloStatic(cloneMtbColt, new ISimpleOperationCallback() { - @Override - public void onSuccess(MtbColt value) { - - mtbColr - .setDataCollo(value.getDataColloS()) - .setNumCollo(value.getNumCollo()) - .setGestione(value.getGestione()) - .setSerCollo(value.getSerCollo()) - .setRiga(value.getMtbColr().get(0).getRiga()) - .setUntMis(mtbAart.getUntMis()) - .setMtbAart(mtbAart); - - mtbColt.get().getMtbColr().add(mtbColr); - - FBToast.successToast(mContext, mContext.getResources().getString(R.string.data_saved), FBToast.LENGTH_SHORT); - - resetTexts(); - progress.dismiss(); - } - - @Override - public void onFailed(Exception ex) { - UtilityExceptions.defaultException(mContext, ex, progress); - } - }); - } - - } - - - @Override - public void onItemClick(MtbColr item, int position) { - mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); - - MtbColr clickedItem = mtbColt.get().getMtbColr().get(position); - -// mBinding.bottomSheetActionsTitle.setText(clickedItem.getDescrizione()); -// mBinding.bottomSheetActionsSubtitle.setText(clickedItem.getCodMart()); -// -// mBinding.bottomSheetActionsEditBtn.setOnClickListener(v -> onItemEdit(item, position)); -// mBinding.bottomSheetActionsDeleteBtn.setOnClickListener(v -> onItemDelete(item)); -// -// mBinding.bottomSheetActionsQuantity.setText(UtilityNumber.decimalToString(clickedItem.getQtaCol()) + " " + clickedItem.getMtbAart().getUntMis()); - } - - public void openLU() { - DialogScanOrCreateLU.make(mContext, true, false, (mtbColt, created) -> { - if (mtbColt == null) { - ((IPoppableActivity) mContext).pop(); - } else { - setMtbColt(mtbColt, created); - } - }).show(); - } - - public boolean thereIsAnOpenedUL() { - return mtbColt.get() != null; - } - - public boolean thereIsAnyRowInUL() { - return mtbColt.get() != null && - mtbColt.get().getMtbColr() != null && - mtbColt.get().getMtbColr().size() > 0; - } - - public void closeLU(boolean openNewOne, boolean saveCausale) { - - if (thereIsAnOpenedUL()) { - - final Dialog progress = UtilityProgress.createDefaultProgressDialog(mContext); - - if (thereIsAnyRowInUL()) { - - if (!UtilityString.isNullOrEmpty(SettingsManager.iDB().getDefaultCausaleRettificaGiacenze()) && saveCausale) { - saveCausaleRettificaGiacenze(progress, () -> { - posizionaCollo(() -> postSaveOperations(openNewOne, progress), - () -> { - progress.dismiss(); - resetMtbColt(openNewOne); - }, - ex -> UtilityExceptions.defaultException(mContext, ex, progress)); - }); - - - } else { - posizionaCollo(() -> { - postSaveOperations(openNewOne, progress); - }, () -> { - progress.dismiss(); - resetMtbColt(openNewOne); - }, ex -> UtilityExceptions.defaultException(mContext, ex, progress)); - } - } else { - -// ColliMagazzinoRESTConsumer.deleteCollo(mtbColt.get(), () -> { - progress.dismiss(); - resetMtbColt(openNewOne); -// }, ex -> UtilityExceptions.defaultException(mContext, ex, progress)); - - } - } - } - - - private void postSaveOperations(boolean openNewOne, Dialog progressDialog) { - if (!mtbColt.get().getDisablePrint()) { - printCollo(progressDialog); - } else { - progressDialog.dismiss(); - resetMtbColt(openNewOne); - } - } - - private void saveCausaleRettificaGiacenze(Dialog progress, Runnable onComplete) { - - final MtbCols mtbCols = new MtbCols() - .setCausale(SettingsManager.iDB().getDefaultCausaleRettificaGiacenze()); - mtbCols.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); - - MtbColt cloneMtbColt = (MtbColt) mtbColt.get().clone(); - cloneMtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP); - cloneMtbColt.setMtbColr(new ObservableArrayList<>()); - - cloneMtbColt.setMtbCols(new ArrayList<>()); - cloneMtbColt.getMtbCols().add(mtbCols); - - ColliMagazzinoRESTConsumer.saveColloStatic(cloneMtbColt, mtbColt -> onComplete.run(), ex -> { - UtilityExceptions.defaultException(mContext, ex, progress); - DialogCommon.showRestError(mContext, ex, onComplete::run); - }); - } - - private void posizionaCollo(Runnable onComplete, Runnable onAbort, RunnableArgs onFailed) { - - DialogYesNo.make(mContext, "Posiziona UL", "Vuoi cambiare la posizione della UL corrente?", result -> { - - switch (result) { - case YES: - DialogAskPositionOfLU.makeBase(mContext, mtbColt.get(), false, (status, mtbDepoPosizione) -> { - if (status == DialogConsts.Results.ABORT) { - onAbort.run(); - } else { - if (mtbDepoPosizione != null && mtbColt.get() != null) { - Objects.requireNonNull(mtbColt.get()).setPosizione(mtbDepoPosizione.getPosizione()); - onComplete.run(); - } else { - onAbort.run(); - } - } - - - }, onFailed).show(); - break; - - case NO: - onAbort.run(); - break; - } - - }).show(); - - - } - - private void onItemEdit(MtbColr mtbColrToEdit, int index) { - mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); - - MtbColr mtbColrToEditClone = (MtbColr) mtbColrToEdit.clone(); - - DialogInputQuantity.DTO dto = new DialogInputQuantity.DTO() - .setBatchLot(mtbColrToEditClone.getPartitaMag()) - .setQtaDaEvadere(null) - .setQtaOrd(null) - .setQtaDisponibile(new BigDecimal(-1)) - .setMtbAart(mtbColrToEditClone.getMtbAart()) - .setCanPartitaMagBeChanged(false) - .setQtaTot(mtbColrToEditClone.getQtaCol()) - .setQtaCnf(mtbColrToEditClone.getQtaCnf()) - .setNumCnf(mtbColrToEditClone.getNumCnf().intValue()); - - DialogInputQuantity.makeBase(mContext, dto, true, value -> { - - BigDecimal newQtaCol = value.qtaTot.getBigDecimal(); //.subtract(mtbColrToEditClone.getQtaCol()); - BigDecimal newNumCnf = value.numCnf.getBigDecimal(); //.subtract(mtbColrToEditClone.getNumCnf()); - - if (newQtaCol.compareTo(BigDecimal.ZERO) != 0) { - if (newNumCnf.compareTo(BigDecimal.ZERO) == 0 && newQtaCol.compareTo(BigDecimal.ZERO) > 0) - newNumCnf = BigDecimal.ONE; - else if (newNumCnf.compareTo(BigDecimal.ZERO) == 0 && newQtaCol.compareTo(BigDecimal.ZERO) < 0) - newNumCnf = new BigDecimal(-1); - - Dialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext); - - mtbColrToEditClone - .setRiga(null); - - - if (!isCreatedLU) { - BigDecimal finalNewNumCnf = newNumCnf; - ColliMagazzinoRESTConsumer.creaRettificaColloStatic( - mtbColrToEditClone, - newNumCnf, - newQtaCol, - () -> { - progressDialog.dismiss(); - mtbColt.get().getMtbColr().remove(index); - - mtbColrToEditClone - .setQtaCol(newQtaCol) - .setNumCnf(finalNewNumCnf) - .setMtbAart(mtbColrToEdit.getMtbAart()) - .setOperation(CommonModelConsts.OPERATION.NO_OP); - - mtbColt.get().getMtbColr().add(index, mtbColrToEditClone); - }, ex -> UtilityExceptions.defaultException(mContext, ex, progressDialog) - ); - } else { - - mtbColrToEditClone - .setRiga(null) - .setDatetimeRow(UtilityDate.getDateInstance()) - .setQtaCol(newQtaCol) - .setNumCnf(newNumCnf) - .setUtente(SettingsManager.i().user.fullname) - .setCausale(MtbColr.Causale.RETTIFICA) - .setOperation(CommonModelConsts.OPERATION.INSERT); - - MtbColt mtbColtClone = (MtbColt) mtbColt.get().clone(); - mtbColtClone.setMtbColr(new ObservableArrayList<>()); - mtbColtClone.getMtbColr().add(mtbColrToEditClone); - mtbColtClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); - - ColliMagazzinoRESTConsumer.saveColloStatic(mtbColtClone, valueNewMtbColt -> { - progressDialog.dismiss(); - mtbColt.get().getMtbColr().remove(index); - - mtbColrToEditClone - .setQtaCol(value.qtaTot.getBigDecimal()) - .setNumCnf(value.numCnf.getBigDecimal()) - .setMtbAart(mtbColrToEdit.getMtbAart()) - .setOperation(CommonModelConsts.OPERATION.NO_OP); - - mtbColt.get().getMtbColr().add(index, mtbColrToEditClone); - }, ex -> UtilityExceptions.defaultException(mContext, ex, progressDialog)); - } - } - - }, null).show(); - - } - - private void onItemDelete(MtbColr mtbColrToDelete) { - mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); - - MtbColr mtbColrToDeleteClone = (MtbColr) mtbColrToDelete.clone(); - - mtbColrToDeleteClone - .setRiga(null) - .setDatetimeRow(UtilityDate.getDateInstance()) - .setUtente(SettingsManager.i().user.fullname) - .setCausale(MtbColr.Causale.RETTIFICA) - .setOperation(CommonModelConsts.OPERATION.INSERT); - - Dialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext); - - - if (!isCreatedLU) { - ColliMagazzinoRESTConsumer.creaRettificaColloStatic( - mtbColrToDeleteClone, - BigDecimal.ZERO, - BigDecimal.ZERO, - () -> { - progressDialog.dismiss(); - mtbColt.get().getMtbColr().remove(mtbColrToDelete); - }, ex -> UtilityExceptions.defaultException(mContext, ex, progressDialog) - ); - } else { - - mtbColrToDeleteClone - .setQtaCol(mtbColrToDeleteClone.getQtaCol().multiply(new BigDecimal(-1))); - - MtbColt mtbColtClone = (MtbColt) mtbColt.get().clone(); - mtbColtClone.setMtbColr(new ObservableArrayList<>()); - mtbColtClone.getMtbColr().add(mtbColrToDeleteClone); - mtbColtClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE); - - ColliMagazzinoRESTConsumer.saveColloStatic(mtbColtClone, value -> { - progressDialog.dismiss(); - mtbColt.get().getMtbColr().remove(mtbColrToDelete); - }, ex -> { - UtilityExceptions.defaultException(mContext, ex, progressDialog); - }); - } - } - - - private void printCollo(Dialog progress) { - - this.showAskPrint(shouldPrint -> { - - if (shouldPrint) { - PrinterRESTConsumer.getAvailablePrintersStatic(SettingsManager.i().userSession.depo.getCodMdep(), value -> { - - if (value.size() > 0) { - - try { - ReportManager.getReportNameLUFromGestione(mtbColt.get().getGestioneEnum(), reportName -> { - - PrinterRESTConsumer.printColloStatic(value.get(0), - mtbColt.get(), - 1, - reportName, - () -> { - progress.dismiss(); - resetMtbColt(true); - - Resources res = mContext.getResources(); - String errorMessage = res.getText(R.string.alert_print_completed_message).toString(); - DialogSimpleMessageHelper.makeSuccessDialog(mContext, res.getText(R.string.completed).toString(), new SpannableString(errorMessage), null, null).show(); - }, ex -> { - UtilityLogger.errorMe(ex); - progress.dismiss(); - showPrintErrorDialog(ex.getMessage()); - }); - - }, ex -> { - UtilityLogger.errorMe(ex); - progress.dismiss(); - String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex); - showPrintErrorDialog(errorMessage); - }); - } catch (Exception ex) { - progress.dismiss(); - UtilityLogger.errorMe(ex); - String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex); - showPrintErrorDialog(errorMessage); - } - - } else { - progress.dismiss(); - String errorMessage = "Nessuna stampante configurata"; - showPrintErrorDialog(errorMessage); - } - }, ex -> { - progress.dismiss(); - UtilityLogger.errorMe(ex); - String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex); - showPrintErrorDialog(errorMessage); - }); - } else { - progress.dismiss(); - resetMtbColt(true); - } - - }); - } - - - private void showAskPrint(RunnableArgs onComplete) { - DialogSimpleMessageHelper.makeInfoDialog( - mContext, - mContext.getResources().getString(R.string.action_print_ul), - new SpannableString(mContext.getResources().getString(R.string.ask_print_message)), - null, - () -> onComplete.run(true), - () -> onComplete.run(false)).show(); - } - - private void showPrintErrorDialog(String message) { - DialogSimpleMessageHelper.makeErrorDialog( - mContext, - new SpannableString(message), - null, - null, - R.string.button_ignore_print, - () -> resetMtbColt(true)).show(); - } -} diff --git a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java index 1b04a8e9..5e31ed89 100644 --- a/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java +++ b/app/src/main/java/it/integry/integrywmsnative/gest/spedizione/SpedizioneViewModel.java @@ -1024,7 +1024,6 @@ public class SpedizioneViewModel { pickedQuantityDTO.getDataScad(), shouldCloseLU); }); - }); } diff --git a/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml b/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml index f40ebcb5..d5b7f775 100644 --- a/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml +++ b/app/src/main/res/layout/fragment_main_rettifica_giacenze.xml @@ -17,7 +17,7 @@ + type="it.integry.integrywmsnative.gest.rettifica_giacenze.RettificaGiacenzeViewModel" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_picking_libero.xml b/app/src/main/res/layout/fragment_picking_libero.xml index ff42e67d..ded92645 100644 --- a/app/src/main/res/layout/fragment_picking_libero.xml +++ b/app/src/main/res/layout/fragment_picking_libero.xml @@ -135,112 +135,20 @@ fab:fab_colorRipple="#66FFFFFF"/> - + android:layout_height="match_parent" + android:background="#99000000" + android:visibility="gone" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + app:layout_behavior=".view.bottom_sheet__base.AutoCloseBottomSheetBehavior" />