Implementata la possibilità di modificare / eliminare righe in PickingLibero

This commit is contained in:
Giuseppe Scorrano 2020-09-04 19:18:38 +02:00
parent ec2395145d
commit b2a93c0a18
10 changed files with 273 additions and 1110 deletions

View File

@ -4,6 +4,7 @@ package it.integry.integrywmsnative.gest.picking_libero;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.SpannableString;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.PickedQuantityDTO;
import it.integry.integrywmsnative.gest.spedizione.model.PickingObjectDTO; import it.integry.integrywmsnative.gest.spedizione.model.PickingObjectDTO;
import it.integry.integrywmsnative.ui.ElevatedToolbar; 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.DialogConsts;
import it.integry.integrywmsnative.view.dialogs.ask_cliente.DialogAskCliente; 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.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.DialogInputQuantityV2;
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2DTO; 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. * 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; private FragmentPickingLiberoBinding mBindings;
@ -129,6 +132,7 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
this.initVars(); this.initVars();
this.initBarcodeReader(); this.initBarcodeReader();
this.initBottomSheet();
this.initRecyclerView(); this.initRecyclerView();
boolean flagAskCliente = SettingsManager.iDB().isFlagAskClienteInPickingLibero(); boolean flagAskCliente = SettingsManager.iDB().isFlagAskClienteInPickingLibero();
@ -153,6 +157,11 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
.setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false))); .setOnScanFailed(ex -> UtilityExceptions.defaultException(getActivity(), ex, false)));
} }
private void initBottomSheet() {
mBindings.bottomSheetMtbColrEdit.setListener(this);
mBindings.bottomSheetMtbColrEdit.init(mBindings.bottomSheetMtbColrEdit, mBindings.bottomSheetMtbColrEditBackground);
}
private void initRecyclerView() { private void initRecyclerView() {
mBindings.pickingLiberoMainList.setNestedScrollingEnabled(false); mBindings.pickingLiberoMainList.setNestedScrollingEnabled(false);
@ -167,6 +176,11 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
private void initAdapter() { private void initAdapter() {
mAdapter = new PickingLiberoListAdapter(mViewModel.getCurrentMtbColt().getMtbColr()); mAdapter = new PickingLiberoListAdapter(mViewModel.getCurrentMtbColt().getMtbColr());
mBindings.pickingLiberoMainList.setAdapter(mAdapter); mBindings.pickingLiberoMainList.setAdapter(mAdapter);
this.mAdapter.setOnItemClickListener(clickedMtbColr -> {
mBindings.bottomSheetMtbColrEdit.setMtbColr(clickedMtbColr);
mBindings.bottomSheetMtbColrEdit.expand();
});
} }
private void destroyAdapter() { private void destroyAdapter() {
@ -266,6 +280,17 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
thereIsAnOpenedUL.set(false); thereIsAnOpenedUL.set(false);
} }
@Override
public void onMtbColrDeleteRequest(RunnableArgs<Boolean> 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 @Override
public void onError(Exception ex) { public void onError(Exception ex) {
this.closeProgress(); this.closeProgress();
@ -306,9 +331,9 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
BigDecimal initialNumCnf, BigDecimal initialNumCnf,
BigDecimal initialQtaCnf, BigDecimal initialQtaCnf,
BigDecimal initialQtaTot, BigDecimal initialQtaTot,
BigDecimal totalQtaToBeTaken, BigDecimal totalQtaAvailable,
BigDecimal totalNumCnfToBeTaken, BigDecimal totalNumCnfAvailable,
BigDecimal qtaCnfToBeTaken, BigDecimal qtaCnfAvailable,
String partitaMag, String partitaMag,
Date dataScad, Date dataScad,
boolean canOverflowOrderQuantity, boolean canOverflowOrderQuantity,
@ -321,9 +346,9 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
.setInitialNumCnf(initialNumCnf) .setInitialNumCnf(initialNumCnf)
.setInitialQtaCnf(initialQtaCnf) .setInitialQtaCnf(initialQtaCnf)
.setInitialQtaTot(initialQtaTot) .setInitialQtaTot(initialQtaTot)
.setTotalQtaToBeTaken(totalQtaToBeTaken) .setTotalQtaAvailable(totalQtaAvailable)
.setTotalNumCnfToBeTaken(totalNumCnfToBeTaken) .setTotalNumCnfAvailable(totalNumCnfAvailable)
.setQtaCnfToBeTaken(qtaCnfToBeTaken) .setQtaCnfAvailable(qtaCnfAvailable)
.setPartitaMag(partitaMag) .setPartitaMag(partitaMag)
.setDataScad(dataScad) .setDataScad(dataScad)
.setCanOverflowOrderQuantity(canOverflowOrderQuantity) .setCanOverflowOrderQuantity(canOverflowOrderQuantity)
@ -351,4 +376,16 @@ public class PickingLiberoFragment extends Fragment implements ITitledFragment,
public void onRowSaved() { public void onRowSaved() {
FBToast.successToast(getActivity(), getResources().getString(R.string.data_saved), FBToast.LENGTH_SHORT); 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);
}
} }

View File

@ -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.consumers.PrinterRESTConsumer;
import it.integry.integrywmsnative.core.rest.model.Ean128Model; import it.integry.integrywmsnative.core.rest.model.Ean128Model;
import it.integry.integrywmsnative.core.rest.model.Ean13PesoModel; 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.UtilityBarcode;
import it.integry.integrywmsnative.core.utility.UtilityBigDecimal; import it.integry.integrywmsnative.core.utility.UtilityBigDecimal;
import it.integry.integrywmsnative.core.utility.UtilityDate; import it.integry.integrywmsnative.core.utility.UtilityDate;
@ -345,13 +346,28 @@ public class PickingLiberoViewModel {
mColliMagazzinoRESTConsumer.saveCollo(clonedTestata, value -> { mColliMagazzinoRESTConsumer.saveCollo(clonedTestata, value -> {
for (int i = 0; i < mtbColrObservableField.size(); i++) { for (int i = 0; i < mtbColrObservableField.size(); i++) {
MtbColr initialMtbColr = mtbColrObservableField.get(i);
mtbColrObservableField.get(i) initialMtbColr
.setDataCollo(value.getDataColloS()) .setDataCollo(value.getDataColloS())
.setNumCollo(value.getNumCollo()) .setNumCollo(value.getNumCollo())
.setGestione(value.getGestione()) .setGestione(value.getGestione())
.setSerCollo(value.getSerCollo()); .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)); mCurrentMtbColt.getMtbColr().add(mtbColrObservableField.get(i));
} }
@ -475,6 +491,176 @@ public class PickingLiberoViewModel {
} }
private void loadRifULFromMtbColr(MtbColr mtbColr, RunnableArgs<MtbColt> 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<MtbColr> 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() { public void closeLU() {
if (mCurrentMtbColt == null) return; if (mCurrentMtbColt == null) return;
@ -528,12 +714,17 @@ public class PickingLiberoViewModel {
if (this.mListener != null) mListener.onLUClosed(); if (this.mListener != null) mListener.onLUClosed();
} }
private void sendMtbColrDeleteRequest(RunnableArgs<Boolean> onComplete) {
if (this.mListener != null) mListener.onMtbColrDeleteRequest(onComplete);
}
private void sendLUClienteRequired(RunnableArgs<VtbDest> onComplete, Runnable onAbort) { private void sendLUClienteRequired(RunnableArgs<VtbDest> onComplete, Runnable onAbort) {
if (this.mListener != null) mListener.onLUClienteRequired(onComplete, onAbort); if (this.mListener != null) mListener.onLUClienteRequired(onComplete, onAbort);
} }
private void sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, RunnableArgs<List<MtbColr>> onComplete, Runnable onAbort) { private void sendArtSelectionRequest(List<MtbColr> mtbColrsToPick, RunnableArgs<List<MtbColr>> 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, private void sendOnItemDispatched(PickingObjectDTO pickingObjectDTO,
@ -541,9 +732,9 @@ public class PickingLiberoViewModel {
BigDecimal initialNumCnf, BigDecimal initialNumCnf,
BigDecimal initialQtaCnf, BigDecimal initialQtaCnf,
BigDecimal initialQtaTot, BigDecimal initialQtaTot,
BigDecimal totalQtaToBeTaken, BigDecimal totalQtaAvailable,
BigDecimal totalNumCnfToBeTaken, BigDecimal totalNumCnfAvailable,
BigDecimal qtaCnfToBeTaken, BigDecimal qtaCnfAvailable,
String partitaMag, String partitaMag,
Date dataScad, Date dataScad,
boolean canOverflowOrderQuantity, boolean canOverflowOrderQuantity,
@ -555,9 +746,9 @@ public class PickingLiberoViewModel {
initialNumCnf, initialNumCnf,
initialQtaCnf, initialQtaCnf,
initialQtaTot, initialQtaTot,
totalQtaToBeTaken, totalQtaAvailable,
totalNumCnfToBeTaken, totalNumCnfAvailable,
qtaCnfToBeTaken, qtaCnfAvailable,
partitaMag, partitaMag,
dataScad, dataScad,
canOverflowOrderQuantity, canOverflowOrderQuantity,
@ -584,6 +775,8 @@ public class PickingLiberoViewModel {
void onLUClosed(); void onLUClosed();
void onMtbColrDeleteRequest(RunnableArgs<Boolean> onComplete);
void onError(Exception ex); void onError(Exception ex);
void onLUClienteRequired(RunnableArgs<VtbDest> onComplete, Runnable onAbort); void onLUClienteRequired(RunnableArgs<VtbDest> onComplete, Runnable onAbort);
@ -595,9 +788,9 @@ public class PickingLiberoViewModel {
BigDecimal initialNumCnf, BigDecimal initialNumCnf,
BigDecimal initialQtaCnf, BigDecimal initialQtaCnf,
BigDecimal initialQtaTot, BigDecimal initialQtaTot,
BigDecimal totalQtaToBeTaken, BigDecimal totalQtaAvailable,
BigDecimal totalNumCnfToBeTaken, BigDecimal totalNumCnfAvailable,
BigDecimal qtaCnfToBeTaken, BigDecimal qtaCnfAvailable,
String partitaMag, String partitaMag,
Date dataScad, Date dataScad,
boolean canOverflowOrderQuantity, boolean canOverflowOrderQuantity,

View File

@ -83,7 +83,7 @@ public class PickingLiberoListAdapter extends ExtendedRecyclerView<MtbColr, Pick
return this; return this;
} }
interface OnItemClickListener { public interface OnItemClickListener {
void onItemClick(MtbColr item); void onItemClick(MtbColr item);
} }

View File

@ -64,12 +64,12 @@ import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQua
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU; import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
import it.integry.integrywmsnative.view.dialogs.yes_no.DialogYesNo; import it.integry.integrywmsnative.view.dialogs.yes_no.DialogYesNo;
public class RettificaGiacenzeFragment extends Fragment implements ITitledFragment, RettificaGiacenzeViewModelNEW.Listener, BottomSheetMtbColrEditView.Listener { public class RettificaGiacenzeFragment extends Fragment implements ITitledFragment, RettificaGiacenzeViewModel.Listener, BottomSheetMtbColrEditView.Listener {
private FragmentMainRettificaGiacenzeBinding mBinding = null; private FragmentMainRettificaGiacenzeBinding mBinding = null;
@Inject @Inject
RettificaGiacenzeViewModelNEW mViewModel; RettificaGiacenzeViewModel mViewModel;
public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false); public BindableBoolean thereIsAnOpenedUL = new BindableBoolean(false);
public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(false); public BindableBoolean thereIsntAnOpenedUL = new BindableBoolean(false);

View File

@ -10,7 +10,6 @@ import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.PrinterRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.PrinterRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer; import it.integry.integrywmsnative.core.rest.consumers.SystemRESTConsumer;
import it.integry.integrywmsnative.gest.picking_libero.PickingLiberoViewModel;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.RettificaGiacenzeRESTConsumer; import it.integry.integrywmsnative.gest.rettifica_giacenze.core.RettificaGiacenzeRESTConsumer;
@Module(includes = {MainApplicationModule.class}) @Module(includes = {MainApplicationModule.class})
@ -26,11 +25,11 @@ public class RettificaGiacenzeModule {
@Provides @Provides
@Singleton @Singleton
RettificaGiacenzeViewModelNEW providesRettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer, RettificaGiacenzeViewModel providesRettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
PrinterRESTConsumer printerRESTConsumer, PrinterRESTConsumer printerRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer,
RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) { RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) {
return new RettificaGiacenzeViewModelNEW(articoloRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, barcodeRESTConsumer, rettificaGiacenzeRESTConsumer); return new RettificaGiacenzeViewModel(articoloRESTConsumer, colliMagazzinoRESTConsumer, printerRESTConsumer, barcodeRESTConsumer, rettificaGiacenzeRESTConsumer);
} }
} }

View File

@ -43,7 +43,7 @@ import it.integry.integrywmsnative.gest.spedizione.model.PickDataDTO;
import it.integry.integrywmsnative.gest.spedizione.model.PickedQuantityDTO; import it.integry.integrywmsnative.gest.spedizione.model.PickedQuantityDTO;
import it.integry.integrywmsnative.gest.spedizione.model.PickingObjectDTO; import it.integry.integrywmsnative.gest.spedizione.model.PickingObjectDTO;
public class RettificaGiacenzeViewModelNEW { public class RettificaGiacenzeViewModel {
public MtbColt mCurrentMtbColt = null; public MtbColt mCurrentMtbColt = null;
@ -53,7 +53,7 @@ public class RettificaGiacenzeViewModelNEW {
private final BarcodeRESTConsumer mBarcodeRESTConsumer; private final BarcodeRESTConsumer mBarcodeRESTConsumer;
private final RettificaGiacenzeRESTConsumer mRettificaGiacenzeRESTConsumer; private final RettificaGiacenzeRESTConsumer mRettificaGiacenzeRESTConsumer;
private RettificaGiacenzeViewModelNEW.Listener mListener; private RettificaGiacenzeViewModel.Listener mListener;
private String mCurrentUser; private String mCurrentUser;
private String mDefaultCausale; private String mDefaultCausale;
@ -61,11 +61,11 @@ public class RettificaGiacenzeViewModelNEW {
private boolean mIsCreatedLU; private boolean mIsCreatedLU;
@Inject @Inject
public RettificaGiacenzeViewModelNEW(ArticoloRESTConsumer articoloRESTConsumer, public RettificaGiacenzeViewModel(ArticoloRESTConsumer articoloRESTConsumer,
ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer,
PrinterRESTConsumer printerRESTConsumer, PrinterRESTConsumer printerRESTConsumer,
BarcodeRESTConsumer barcodeRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer,
RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) { RettificaGiacenzeRESTConsumer rettificaGiacenzeRESTConsumer) {
this.mArticoloRESTConsumer = articoloRESTConsumer; this.mArticoloRESTConsumer = articoloRESTConsumer;
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer; this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
this.mPrinterRESTConsumer = printerRESTConsumer; this.mPrinterRESTConsumer = printerRESTConsumer;
@ -101,7 +101,7 @@ public class RettificaGiacenzeViewModelNEW {
} }
public RettificaGiacenzeViewModelNEW setListener(RettificaGiacenzeViewModelNEW.Listener listener) { public RettificaGiacenzeViewModel setListener(RettificaGiacenzeViewModel.Listener listener) {
this.mListener = listener; this.mListener = listener;
return this; return this;
} }

View File

@ -1,838 +0,0 @@
package it.integry.integrywmsnative.gest.rettifica_giacenze.viewmodel;
import android.app.Activity;
import android.app.Dialog;
import android.content.res.Resources;
import android.text.SpannableString;
import android.view.inputmethod.EditorInfo;
import androidx.core.content.ContextCompat;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.annimon.stream.Stream;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.textfield.TextInputLayout;
import com.tfb.fbtoast.FBToast;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
import it.integry.barcode_base_android_library.model.BarcodeType;
import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
import it.integry.integrywmsnative.core.di.BindableBoolean;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.interfaces.IPoppableActivity;
import it.integry.integrywmsnative.core.interfaces.IRecyclerItemClicked;
import it.integry.integrywmsnative.core.model.CommonModelConsts;
import it.integry.integrywmsnative.core.model.MtbAart;
import it.integry.integrywmsnative.core.model.MtbColr;
import it.integry.integrywmsnative.core.model.MtbCols;
import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.report.ReportManager;
import it.integry.integrywmsnative.core.rest.CommonRESTException;
import it.integry.integrywmsnative.core.rest.consumers.ArticoloRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.rest.consumers.ISimpleOperationCallback;
import it.integry.integrywmsnative.core.rest.consumers.PrinterRESTConsumer;
import it.integry.integrywmsnative.core.rest.model.Ean128Model;
import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.utility.UtilityBarcode;
import it.integry.integrywmsnative.core.utility.UtilityDate;
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
import it.integry.integrywmsnative.core.utility.UtilityLogger;
import it.integry.integrywmsnative.core.utility.UtilityProgress;
import it.integry.integrywmsnative.core.utility.UtilityString;
import it.integry.integrywmsnative.databinding.FragmentMainRettificaGiacenzeBinding;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.RettificaGiacenzeHelper;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.adapter.AutoCompleteFornitoreAdapter;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.adapter.RettificaGiacenzeMainListAdapter;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.FornitoreDTO;
import it.integry.integrywmsnative.view.dialogs.DialogCommon;
import it.integry.integrywmsnative.view.dialogs.DialogConsts;
import it.integry.integrywmsnative.view.dialogs.ask_position_of_lu.DialogAskPositionOfLU;
import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageHelper;
import it.integry.integrywmsnative.view.dialogs.choose_art_from_lista_arts.DialogChooseArtFromListaArts;
import it.integry.integrywmsnative.view.dialogs.input_quantity.DialogInputQuantity;
import it.integry.integrywmsnative.view.dialogs.input_quantity.QuantityDTO;
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
import it.integry.integrywmsnative.view.dialogs.yes_no.DialogYesNo;
public class RettificaGiacenzeViewModel implements IRecyclerItemClicked<MtbColr> {
private Activity mContext;
private FragmentMainRettificaGiacenzeBinding mBinding;
private BottomSheetBehavior mBottomSheetBehavior;
private RettificaGiacenzeHelper mHelper;
private RettificaGiacenzeMainListAdapter mAdapter;
public ObservableField<MtbColt> 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<MtbColr> 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<BarcodeScanDTO> 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<FornitoreDTO> 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<MtbAart> 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<MtbAart> 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<MtbColt>() {
@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<Exception> 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<Boolean> 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();
}
}

View File

@ -1024,7 +1024,6 @@ public class SpedizioneViewModel {
pickedQuantityDTO.getDataScad(), pickedQuantityDTO.getDataScad(),
shouldCloseLU); shouldCloseLU);
}); });
}); });
} }

View File

@ -17,7 +17,7 @@
<variable <variable
name="viewmodel" name="viewmodel"
type="it.integry.integrywmsnative.gest.rettifica_giacenze.RettificaGiacenzeViewModelNEW" /> type="it.integry.integrywmsnative.gest.rettifica_giacenze.RettificaGiacenzeViewModel" />
</data> </data>
<FrameLayout <FrameLayout
@ -341,141 +341,6 @@
app:behavior_peekHeight="0dp" app:behavior_peekHeight="0dp"
app:layout_behavior=".view.bottom_sheet__base.AutoCloseBottomSheetBehavior" /> app:layout_behavior=".view.bottom_sheet__base.AutoCloseBottomSheetBehavior" />
<!-- <LinearLayout-->
<!-- android:id="@+id/bottom_sheet_actions"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="bottom"-->
<!-- android:background="#fff"-->
<!-- android:orientation="vertical"-->
<!-- android:padding="16dp"-->
<!-- app:behavior_hideable="true"-->
<!-- app:behavior_peekHeight="0dp"-->
<!-- app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">-->
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:orientation="horizontal">-->
<!-- <LinearLayout-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginBottom="8dp"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_constraintEnd_toStartOf="@id/bottom_sheet_actions_quantity"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- android:id="@+id/bottom_sheet_actions_title"-->
<!-- style="@style/AppTheme.NewMaterial.Text.Medium"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:paddingStart="0dp"-->
<!-- android:paddingEnd="8dp"-->
<!-- android:textColor="#444"-->
<!-- android:textStyle="bold"-->
<!-- tools:text="Descrizione articolo" />-->
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- android:id="@+id/bottom_sheet_actions_subtitle"-->
<!-- style="@style/AppTheme.NewMaterial.Text.Small"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- tools:text="ABF52IL" />-->
<!-- </LinearLayout>-->
<!-- <TextView-->
<!-- android:id="@+id/bottom_sheet_actions_quantity"-->
<!-- style="@style/AppTheme.NewMaterial.Text.Small"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:gravity="end"-->
<!-- android:textStyle="bold"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- tools:text="250 PZ" />-->
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal">-->
<!-- <androidx.constraintlayout.widget.Guideline-->
<!-- android:id="@+id/guideline_action"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_constraintGuide_percent="0.50" />-->
<!-- <LinearLayout-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:gravity="center"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_constraintEnd_toStartOf="@id/guideline_action"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<!-- <androidx.appcompat.widget.AppCompatImageButton-->
<!-- android:id="@+id/bottom_sheet_actions_edit_btn"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="@android:color/white"-->
<!-- android:padding="16dp"-->
<!-- android:scaleX="1.5"-->
<!-- android:scaleY="1.5"-->
<!-- android:src="@drawable/ic_edit_24dp"-->
<!-- android:tint="@color/green_600" />-->
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- style="@style/AppTheme.NewMaterial.Text.Small"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/edit" />-->
<!-- </LinearLayout>-->
<!-- <LinearLayout-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:gravity="center"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="@id/guideline_action"-->
<!-- app:layout_constraintTop_toTopOf="parent">-->
<!-- <androidx.appcompat.widget.AppCompatImageButton-->
<!-- android:id="@+id/bottom_sheet_actions_delete_btn"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="@android:color/white"-->
<!-- android:padding="16dp"-->
<!-- android:scaleX="1.5"-->
<!-- android:scaleY="1.5"-->
<!-- android:src="@drawable/ic_delete_24dp"-->
<!-- android:tint="@color/red_600" />-->
<!-- <androidx.appcompat.widget.AppCompatTextView-->
<!-- style="@style/AppTheme.NewMaterial.Text.Small"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/delete" />-->
<!-- </LinearLayout>-->
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
<!-- </LinearLayout>-->
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -135,112 +135,20 @@
fab:fab_colorRipple="#66FFFFFF"/> fab:fab_colorRipple="#66FFFFFF"/>
<View <View
android:visibility="gone" android:id="@+id/bottom_sheet__mtb_colr_edit__background"
android:id="@+id/bg"
android:background="#99000000"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"
android:background="#99000000"
android:visibility="gone" />
<LinearLayout <it.integry.integrywmsnative.view.bottom_sheet__mtb_colr_edit.BottomSheetMtbColrEditView
android:id="@+id/bottom_sheet_actions" android:id="@+id/bottom_sheet__mtb_colr_edit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:padding="16dp"
android:layout_gravity="bottom"
app:behavior_hideable="true" app:behavior_hideable="true"
app:behavior_peekHeight="0dp" app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> app:layout_behavior=".view.bottom_sheet__base.AutoCloseBottomSheetBehavior" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/bottom_sheet_actions_quantity"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/bottom_sheet_actions_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Descrizione articolo"
android:textColor="#444"
android:textSize="18sp"
android:maxLines="1"
android:ellipsize="end"
android:paddingEnd="8dp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/bottom_sheet_actions_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="ABF52IL"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/bottom_sheet_actions_quantity"
android:layout_width="wrap_content"
android:gravity="end"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="15sp"
tools:text="250 PZ"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/bottom_sheet_actions_delete_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="@android:color/white"
android:scaleX="1.5"
android:scaleY="1.5"
android:src="@drawable/ic_delete_24dp"
android:tint="@color/red_600" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/delete"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>