Completato refactoring di DialogScanOrCreateLU
This commit is contained in:
parent
ee70faefa9
commit
91f075976d
@ -37,6 +37,8 @@ import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQua
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2Module;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_art.DialogScanArtComponent;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_art.DialogScanArtModule;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUComponent;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUModule;
|
||||
|
||||
// Definition of the Application graph
|
||||
@Singleton
|
||||
@ -56,6 +58,7 @@ import it.integry.integrywmsnative.view.dialogs.scan_art.DialogScanArtModule;
|
||||
OrdiniUscitaElencoModule.class,
|
||||
DialogInputQuantityV2Module.class,
|
||||
DialogScanArtModule.class,
|
||||
DialogScanOrCreateLUModule.class,
|
||||
ProdFabbisognoLineeProdModule.class,
|
||||
VersamentoMerceModule.class,
|
||||
DialogAskMagazzinoProssimitaModule.class,
|
||||
@ -75,6 +78,7 @@ public interface MainApplicationComponent {
|
||||
OrdiniUscitaElencoComponent.Factory prodOrdineLavorazioneElencoComponent();
|
||||
DialogInputQuantityV2Component.Factory dialogInputQuantityV2Component();
|
||||
DialogScanArtComponent.Factory dialogScanArtComponent();
|
||||
DialogScanOrCreateLUComponent.Factory dialogScanOrCreateLUComponent();
|
||||
ProdFabbisognoLineeProdComponent.Factory prodFabbisognoLineeProdComponent();
|
||||
VersamentoMerceComponent.Factory versamentoMerceComponent();
|
||||
DialogAskMagazzinoProssimitaComponent.Factory dialogAskMagazzinoProssimitaComponent();
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
package it.integry.integrywmsnative.core.exception;
|
||||
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityResources;
|
||||
|
||||
public class AlreadyAttachedDocumentToLUException extends Exception {
|
||||
|
||||
public AlreadyAttachedDocumentToLUException() {
|
||||
super(UtilityResources.getString(R.string.lu_already_attache_to_doc));
|
||||
}
|
||||
|
||||
}
|
||||
@ -126,7 +126,7 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
|
||||
|
||||
}
|
||||
|
||||
public static void createColloLavorazione(int segno, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
public void createColloLavorazione(int segno, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
MtbColt mtbColtToCreate = new MtbColt()
|
||||
.setSegno(segno)
|
||||
.setGestione(GestioneEnum.LAVORAZIONE);
|
||||
@ -137,16 +137,10 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
|
||||
.setOperation(CommonModelConsts.OPERATION.INSERT);
|
||||
|
||||
|
||||
saveColloStatic(mtbColtToCreate, new ISimpleOperationCallback<MtbColt>() {
|
||||
@Override
|
||||
public void onSuccess(MtbColt value) {
|
||||
saveCollo(mtbColtToCreate, value -> {
|
||||
if (onComplete != null) onComplete.run(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
}, ex -> {
|
||||
if (onFailed != null) onFailed.run(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -291,15 +285,11 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
|
||||
}
|
||||
|
||||
|
||||
public static void createColloFromEtichettaAnonima(BarcodeScanDTO barcodeScanDTO, GestioneEnum gestione, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
createColloFromEtichettaAnonimaStatic(barcodeScanDTO.getStringValue(), gestione, onComplete, onFailed);
|
||||
public void createColloFromEtichettaAnonima(BarcodeScanDTO barcodeScanDTO, GestioneEnum gestione, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
createColloFromEtichettaAnonima(barcodeScanDTO.getStringValue(), gestione, onComplete, onFailed);
|
||||
}
|
||||
|
||||
public void createColloFromEtichettaAnonima(String barcode, GestioneEnum gestione, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
createColloFromEtichettaAnonimaStatic(barcode, gestione, onComplete, onFailed);
|
||||
}
|
||||
|
||||
public static void createColloFromEtichettaAnonimaStatic(String barcode, GestioneEnum gestione, RunnableArgs<MtbColt> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
|
||||
MtbColt mtbColtToCreate = new MtbColt()
|
||||
.setGestione(gestione);
|
||||
@ -325,39 +315,22 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
|
||||
mtbColtToCreate
|
||||
.setOperation(CommonModelConsts.OPERATION.INSERT);
|
||||
|
||||
saveColloStatic(mtbColtToCreate, new ISimpleOperationCallback<MtbColt>() {
|
||||
@Override
|
||||
public void onSuccess(MtbColt value) {
|
||||
saveCollo(mtbColtToCreate, value -> {
|
||||
if (onComplete != null) onComplete.run(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
}, ex -> {
|
||||
if (onFailed != null) onFailed.run(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteCollo(MtbColt mtbColtToDelete, Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
ColliMagazzinoRESTConsumer.deleteColloStatic(mtbColtToDelete, onComplete, onFailed);
|
||||
}
|
||||
|
||||
public static void deleteColloStatic(MtbColt mtbColtToDelete, Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
|
||||
mtbColtToDelete.setOperation(CommonModelConsts.OPERATION.DELETE);
|
||||
|
||||
saveColloStatic(mtbColtToDelete, new ISimpleOperationCallback<MtbColt>() {
|
||||
@Override
|
||||
public void onSuccess(MtbColt value) {
|
||||
saveCollo(mtbColtToDelete, value -> {
|
||||
if (onComplete != null) onComplete.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
}, ex -> {
|
||||
if (onFailed != null) onFailed.run(ex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void distribuisciCollo(MtbColt mtbColtToDistribute, DistribuzioneColloDTO.CriterioDistribuzione criterioDistribuzione, RunnableArgs<List<MtbColt>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
@ -582,29 +555,6 @@ public class ColliMagazzinoRESTConsumer extends _BaseRESTConsumer {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void updateRiga(MtbColr mtbColrToUpdate, Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
updateRigaStatic(mtbColrToUpdate, onComplete, onFailed);
|
||||
}
|
||||
|
||||
public static void updateRigaStatic(MtbColr mtbColrToUpdate, Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
MtbColt mtbColt = new MtbColt()
|
||||
.setGestione(mtbColrToUpdate.getGestioneEnum())
|
||||
.setNumCollo(mtbColrToUpdate.getNumCollo())
|
||||
.setSerCollo(mtbColrToUpdate.getSerCollo())
|
||||
.setDataCollo(mtbColrToUpdate.getDataColloS());
|
||||
|
||||
mtbColt.getMtbColr().add(mtbColrToUpdate);
|
||||
|
||||
mtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP);
|
||||
mtbColrToUpdate.setOperation(CommonModelConsts.OPERATION.UPDATE);
|
||||
|
||||
EntityRESTConsumer.processEntity(mtbColt, value -> {
|
||||
if (onComplete != null) onComplete.run();
|
||||
}, onFailed, MtbColt.class);
|
||||
|
||||
}
|
||||
|
||||
public void updateDataFine(MtbColt mtbColt, Runnable onComplete, RunnableArgs<Exception> onFailed) {
|
||||
ColliMagazzinoRESTConsumer.updateDataFineStatic(mtbColt, onComplete, onFailed);
|
||||
}
|
||||
|
||||
@ -68,11 +68,8 @@ public class PosizioniRESTConsumer extends _BaseRESTConsumer{
|
||||
});
|
||||
}
|
||||
|
||||
public void getBancaliInPosizione(MtbDepoPosizione mtbDepoPosizione, RunnableArgs<List<MtbColt>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
getBancaliInPosizioneStatic(mtbDepoPosizione, onComplete, onFailed);
|
||||
}
|
||||
|
||||
public static void getBancaliInPosizioneStatic(MtbDepoPosizione mtbDepoPosizione, RunnableArgs<List<MtbColt>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
public void getBancaliInPosizione(MtbDepoPosizione mtbDepoPosizione, RunnableArgs<List<MtbColt>> onComplete, RunnableArgs<Exception> onFailed) {
|
||||
String sql = "SELECT * FROM mtb_colt WHERE segno > 0 AND cod_mdep = " + UtilityDB.valueToString(mtbDepoPosizione.getCodMdep()) + " AND posizione = " + UtilityDB.valueToString(mtbDepoPosizione.getPosizione());
|
||||
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ import it.integry.integrywmsnative.view.dialogs.DialogCommon;
|
||||
import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2DTO;
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2View;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUView;
|
||||
|
||||
public class ProdRecuperoMaterialeViewModel {
|
||||
|
||||
@ -369,7 +369,8 @@ public class ProdRecuperoMaterialeViewModel {
|
||||
};
|
||||
|
||||
if (sourceMtbColt != null) saveRunnable.run(sourceMtbColt, false);
|
||||
else DialogScanOrCreateLU.make(mContext, true, false, saveRunnable).show();
|
||||
else DialogScanOrCreateLUView.newInstance(true, false, saveRunnable)
|
||||
.show(mContext.getSupportFragmentManager(), "tag");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package it.integry.integrywmsnative.gest.prod_versamento_materiale.viewmodel;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.view.View;
|
||||
@ -10,6 +8,7 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.ObservableField;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -46,13 +45,13 @@ 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.DialogSimpleMessageView;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUView;
|
||||
|
||||
|
||||
public class ProdVersamentoMaterialViewModel {
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private FragmentActivity mContext;
|
||||
|
||||
private FragmentProdVersamentoMaterialeBinding mBinding;
|
||||
private ProdVersamentoMaterialHelper mHelper;
|
||||
@ -63,7 +62,7 @@ public class ProdVersamentoMaterialViewModel {
|
||||
public MtbColr mMtbColr;
|
||||
|
||||
|
||||
public void init(Activity context, FragmentProdVersamentoMaterialeBinding binding, ProdVersamentoMaterialHelper helper, Runnable onVersamentoCompleted) {
|
||||
public void init(FragmentActivity context, FragmentProdVersamentoMaterialeBinding binding, ProdVersamentoMaterialHelper helper, Runnable onVersamentoCompleted) {
|
||||
mContext = context;
|
||||
mBinding = binding;
|
||||
mHelper = helper;
|
||||
@ -91,7 +90,7 @@ public class ProdVersamentoMaterialViewModel {
|
||||
}
|
||||
|
||||
public void openLU() {
|
||||
DialogScanOrCreateLU.make(mContext, false, false, true, false, (mtbColt, created) -> {
|
||||
DialogScanOrCreateLUView.newInstance(false, false, true, false, (mtbColt, created) -> {
|
||||
if (mtbColt == null) {
|
||||
((IPoppableActivity) mContext).pop();
|
||||
} else if ((mtbColt.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColt.getGestioneEnum() == GestioneEnum.LAVORAZIONE || mtbColt.getGestioneEnum() == GestioneEnum.VENDITA) && mtbColt.getSegno().equals(+1)) {
|
||||
@ -100,7 +99,7 @@ public class ProdVersamentoMaterialViewModel {
|
||||
DialogSimpleMessageView.makeWarningDialog(
|
||||
new SpannableString(Html.fromHtml("E' stata scansionata una UL già vuota")),
|
||||
null, this::openLU)
|
||||
.show(((AppCompatActivity) mContext).getSupportFragmentManager(), "tag");
|
||||
.show((mContext).getSupportFragmentManager(), "tag");
|
||||
|
||||
} else {
|
||||
setMtbColt(mtbColt);
|
||||
@ -110,9 +109,9 @@ public class ProdVersamentoMaterialViewModel {
|
||||
DialogSimpleMessageView
|
||||
.makeWarningDialog(new SpannableString(Html.fromHtml("Sono accettate solamente UL di <b>Acquisto</b> o <b>Lavorazione</b> di <b>CARICO</b>")),
|
||||
null, this::openLU)
|
||||
.show(((AppCompatActivity) mContext).getSupportFragmentManager(), "tag");
|
||||
.show((mContext).getSupportFragmentManager(), "tag");
|
||||
}
|
||||
}).show();
|
||||
}).show(mContext.getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
private void choosePosition() {
|
||||
|
||||
@ -64,7 +64,7 @@ import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;
|
||||
import it.integry.integrywmsnative.view.dialogs.choose_art_from_lista_arts.DialogChooseArtFromListaArts;
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2View;
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2DTO;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUView;
|
||||
import it.integry.integrywmsnative.view.dialogs.yes_no.DialogYesNo;
|
||||
|
||||
public class RettificaGiacenzeFragment extends Fragment implements ITitledFragment, ILifecycleFragment, RettificaGiacenzeViewModel.Listener, BottomSheetMtbColrEditView.Listener {
|
||||
@ -329,13 +329,13 @@ public class RettificaGiacenzeFragment extends Fragment implements ITitledFragme
|
||||
|
||||
@Override
|
||||
public void onLUOpenRequest(RunnableArgss<MtbColt, Boolean> onComplete) {
|
||||
DialogScanOrCreateLU.make(getActivity(), true, false, (mtbColt, created) -> {
|
||||
DialogScanOrCreateLUView.newInstance(true, false, (mtbColt, created) -> {
|
||||
if (mtbColt == null) {
|
||||
((IPoppableActivity) getActivity()).pop();
|
||||
} else {
|
||||
onComplete.run(mtbColt, created);
|
||||
}
|
||||
}).show();
|
||||
}).show(getActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -40,7 +40,7 @@ import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;
|
||||
import it.integry.integrywmsnative.view.dialogs.choose_arts_from_lista_arts.DialogChooseArtsFromListaArts;
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2DTO;
|
||||
import it.integry.integrywmsnative.view.dialogs.input_quantity_v2.DialogInputQuantityV2View;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
|
||||
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUView;
|
||||
|
||||
public class VersamentoMerceFragment extends BaseFragment implements ITitledFragment, VersamentoMerceViewModel.Listener {
|
||||
|
||||
@ -103,7 +103,7 @@ public class VersamentoMerceFragment extends BaseFragment implements ITitledFrag
|
||||
|
||||
|
||||
public void openLU() {
|
||||
DialogScanOrCreateLU.make(getActivity(), true, false, true, false, (mtbColt, created) -> {
|
||||
DialogScanOrCreateLUView.newInstance(true, false, true, false, (mtbColt, created) -> {
|
||||
if (mtbColt == null) {
|
||||
((IPoppableActivity) getActivity()).pop();
|
||||
} else if ((mtbColt.getGestioneEnum() == GestioneEnum.ACQUISTO || mtbColt.getGestioneEnum() == GestioneEnum.LAVORAZIONE) && mtbColt.getSegno().equals(+1)) {
|
||||
@ -114,9 +114,9 @@ public class VersamentoMerceFragment extends BaseFragment implements ITitledFrag
|
||||
DialogSimpleMessageView
|
||||
.makeWarningDialog(new SpannableString(Html.fromHtml("Sono accettate solamente UL di <b>Acquisto</b> o <b>Lavorazione</b> di <b>CARICO</b>")),
|
||||
null, this::openLU)
|
||||
.show(getActivity().getSupportFragmentManager(), "tag");;
|
||||
.show(getActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
}).show();
|
||||
}).show(getActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.scan_art;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
@ -38,8 +37,6 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA
|
||||
@Inject
|
||||
DialogScanArtViewModel mViewModel;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private DialogScanArtBinding mBindings;
|
||||
|
||||
private int mBarcodeScannerIstanceID;
|
||||
@ -59,10 +56,10 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
this.mContext = getActivity();
|
||||
this.initBarcode();
|
||||
|
||||
mBindings = DataBindingUtil.inflate(inflater, R.layout.dialog_scan_art, container, false);
|
||||
mBindings.setLifecycleOwner(this);
|
||||
|
||||
MainApplication.appComponent
|
||||
.dialogScanArtComponent()
|
||||
@ -96,7 +93,7 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA
|
||||
private void initBarcode() {
|
||||
mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO()
|
||||
.setOnScanSuccessfull(onScanSuccessfull)
|
||||
.setOnScanFailed(ex -> UtilityExceptions.defaultException(this.mContext, ex, false)));
|
||||
.setOnScanFailed(this::onError));
|
||||
|
||||
setBarcodeListener(true);
|
||||
}
|
||||
@ -108,7 +105,7 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA
|
||||
|
||||
this.mViewModel.processBarcodeDTO(data, (status, mtbAart, ean128Model, mtbColrList) -> {
|
||||
if(mtbColrList != null && mtbColrList.size() > 0) {
|
||||
DialogChooseArtFromListaMtbColrView.make(mContext, mtbColrList, mtbColrChose -> {
|
||||
DialogChooseArtFromListaMtbColrView.make(getActivity(), mtbColrList, mtbColrChose -> {
|
||||
mOnItemChoosed.run(status, mtbAart, ean128Model, mtbColrChose);
|
||||
}).show();
|
||||
} else {
|
||||
@ -126,7 +123,7 @@ public class DialogScanArtView extends BaseDialogFragment implements DialogScanA
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
this.closeProgress();
|
||||
UtilityExceptions.defaultException(mContext, ex);
|
||||
UtilityExceptions.defaultException(getActivity(), ex);
|
||||
BarcodeManager.enable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,302 +0,0 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.scan_or_create_lu;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.text.SpannableString;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.barcode_reader.BarcodeCallbackDTO;
|
||||
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgss;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
import it.integry.integrywmsnative.core.model.MtbDepoPosizione;
|
||||
import it.integry.integrywmsnative.core.model.secondary.GestioneEnum;
|
||||
import it.integry.integrywmsnative.core.rest.consumers.BarcodeRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.rest.consumers.ColliMagazzinoRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.rest.consumers.PosizioniRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityBarcode;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityProgress;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
import it.integry.integrywmsnative.databinding.DialogScanOrCreateLuBinding;
|
||||
import it.integry.integrywmsnative.view.dialogs.DialogCommon;
|
||||
import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;
|
||||
import it.integry.integrywmsnative.view.dialogs.basket_lu.DialogBasketLU;
|
||||
|
||||
public class DialogScanOrCreateLU {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private Dialog mDialog;
|
||||
|
||||
private DialogScanOrCreateLuBinding mBinding;
|
||||
|
||||
private RunnableArgss<MtbColt, Boolean> mOnDialogDismiss;
|
||||
|
||||
private MtbColt currentMtbColt;
|
||||
|
||||
|
||||
private boolean mShouldCheckResiduo = false;
|
||||
private boolean mShouldCheckIfExistDoc = true;
|
||||
|
||||
|
||||
public static Dialog make(final Context context, RunnableArgss<MtbColt, Boolean> onDialogDismiss) {
|
||||
return new DialogScanOrCreateLU(context, false, true, true, true, onDialogDismiss).mDialog;
|
||||
}
|
||||
|
||||
public static Dialog make(final Context context, boolean enableCreation, boolean shouldCheckIfExistDoc, RunnableArgss<MtbColt, Boolean> onDialogDismiss) {
|
||||
return new DialogScanOrCreateLU(context, false, enableCreation, true, shouldCheckIfExistDoc, onDialogDismiss).mDialog;
|
||||
}
|
||||
|
||||
public static Dialog make(final Context context, boolean enableBasket, boolean enableCreation, boolean checkResiduo, boolean shouldCheckIfExistDoc, RunnableArgss<MtbColt, Boolean> onDialogDismiss) {
|
||||
return new DialogScanOrCreateLU(context, enableBasket, enableCreation, checkResiduo, shouldCheckIfExistDoc, onDialogDismiss).mDialog;
|
||||
}
|
||||
|
||||
private DialogScanOrCreateLU(Context context, boolean enableBasket, boolean enableCreation, boolean checkResiduo, boolean shouldCheckIfExistDoc, RunnableArgss<MtbColt, Boolean> onDialogDismiss) {
|
||||
mOnDialogDismiss = null;
|
||||
currentMtbColt = null;
|
||||
mShouldCheckResiduo = checkResiduo;
|
||||
mShouldCheckIfExistDoc = shouldCheckIfExistDoc;
|
||||
|
||||
mContext = context;
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||
|
||||
mBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_scan_or_create_lu, null, false);
|
||||
|
||||
mBinding.dialogScanOrCreateLuCreationLayout.setVisibility(enableCreation ? View.VISIBLE : View.GONE);
|
||||
mBinding.dialogScanOrCreateLuBasketLayout.setVisibility(enableBasket ? View.VISIBLE : View.GONE);
|
||||
|
||||
mDialog = new Dialog(context);
|
||||
mDialog.setContentView(mBinding.getRoot());
|
||||
mDialog.setCanceledOnTouchOutside(false);
|
||||
// mDialog.setCancelable(false);
|
||||
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
|
||||
init(onDialogDismiss);
|
||||
initBarcode(context);
|
||||
}
|
||||
|
||||
|
||||
private void init(RunnableArgss<MtbColt, Boolean> onDialogDismiss) {
|
||||
mOnDialogDismiss = onDialogDismiss;
|
||||
|
||||
mBinding.createNewLuButton.setOnClickListener(v -> {
|
||||
final Dialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext);
|
||||
|
||||
ColliMagazzinoRESTConsumer.createColloLavorazione(+1, createdMtbColt -> {
|
||||
sendMtbColt(createdMtbColt, progressDialog, true);
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
});
|
||||
});
|
||||
|
||||
mBinding.viewBasket.setOnClickListener(v -> {
|
||||
DialogBasketLU.make(mContext, mtbColt -> {
|
||||
sendMtbColt(mtbColt, null, false);
|
||||
}).show();
|
||||
});
|
||||
}
|
||||
|
||||
private void initBarcode(Context context) {
|
||||
|
||||
int barcodeIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO()
|
||||
.setOnScanSuccessfull(onScanSuccessfull)
|
||||
.setOnScanFailed(ex -> UtilityExceptions.defaultException(context, ex, false)));
|
||||
|
||||
mDialog.setOnDismissListener(dialog -> {
|
||||
BarcodeManager.removeCallback(barcodeIstanceID);
|
||||
BarcodeManager.enable();
|
||||
if(currentMtbColt == null) {
|
||||
mOnDialogDismiss.run(null, false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private final RunnableArgs<BarcodeScanDTO> onScanSuccessfull = data -> {
|
||||
BarcodeManager.disable();
|
||||
|
||||
final Dialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext);
|
||||
|
||||
if(UtilityBarcode.isEtichettaPosizione(data)){
|
||||
this.executeEtichettaPosizione(data, progressDialog);
|
||||
} else if(UtilityBarcode.isEtichettaAnonima(data)) {
|
||||
this.executeEtichettaAnonima(data, progressDialog);
|
||||
} else if(UtilityBarcode.isEtichetta128(data)) {
|
||||
this.executeEAN128(data, progressDialog);
|
||||
} else {
|
||||
progressDialog.dismiss();
|
||||
BarcodeManager.enable();
|
||||
DialogCommon.showNoULFound(mContext, null);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO, Dialog progressDialog) {
|
||||
|
||||
MtbDepoPosizione foundPosizione = Stream.of(SettingsManager.iDB().getAvailablePosizioni())
|
||||
.filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue()))
|
||||
.single();
|
||||
|
||||
PosizioniRESTConsumer.getBancaliInPosizioneStatic(foundPosizione, mtbColtList -> {
|
||||
|
||||
if(mtbColtList == null || mtbColtList.size() == 0){
|
||||
progressDialog.dismiss();
|
||||
BarcodeManager.enable();
|
||||
DialogCommon.showNoULFound(mContext, null);
|
||||
} else if (mtbColtList.size() == 1) {
|
||||
ColliMagazzinoRESTConsumer.getByTestataStatic(mtbColtList.get(0), mShouldCheckResiduo, false, mtbColt -> {
|
||||
sendMtbColt(mtbColt, progressDialog, false);
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
BarcodeManager.enable();
|
||||
});
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
progressDialog.dismiss();
|
||||
BarcodeManager.enable();
|
||||
showTooMuchULFound();
|
||||
}
|
||||
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
BarcodeManager.enable();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void executeEtichettaAnonima(BarcodeScanDTO barcodeScanDTO, Dialog progressDialog) {
|
||||
ColliMagazzinoRESTConsumer.getBySSCCStatic(barcodeScanDTO.getStringValue(), mShouldCheckResiduo, false, mtbColt -> {
|
||||
|
||||
if(mtbColt == null) {
|
||||
|
||||
ColliMagazzinoRESTConsumer.createColloFromEtichettaAnonima(barcodeScanDTO, GestioneEnum.LAVORAZIONE, createdMtbColt -> {
|
||||
BarcodeManager.enable();
|
||||
createdMtbColt.setDisablePrint(true);
|
||||
sendMtbColt(createdMtbColt, progressDialog, true);
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
BarcodeManager.enable();
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
if(mtbColt.getCodDtip() != null && mShouldCheckIfExistDoc) {
|
||||
DialogSimpleMessageView.makeWarningDialog(
|
||||
new SpannableString(mContext.getResources().getText(R.string.lu_already_attache_to_doc)),
|
||||
null, () -> {
|
||||
BarcodeManager.enable();
|
||||
progressDialog.dismiss();
|
||||
})
|
||||
.show(((AppCompatActivity) mContext).getSupportFragmentManager(), "tag");
|
||||
} else {
|
||||
BarcodeManager.enable();
|
||||
|
||||
mtbColt.setDisablePrint(true);
|
||||
sendMtbColt(mtbColt, progressDialog, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
BarcodeManager.enable();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void executeEAN128(BarcodeScanDTO barcodeScanDTO, Dialog progressDialog) {
|
||||
BarcodeRESTConsumer.decodeEan128Static(barcodeScanDTO, ean128Model -> {
|
||||
|
||||
if(ean128Model != null && !UtilityString.isNullOrEmpty(ean128Model.Sscc)) {
|
||||
|
||||
ColliMagazzinoRESTConsumer.getBySSCCStatic(ean128Model.Sscc, mShouldCheckResiduo, false, mtbColt -> {
|
||||
|
||||
if(mtbColt != null) {
|
||||
|
||||
if(mtbColt.getCodDtip() != null && mShouldCheckIfExistDoc) {
|
||||
DialogSimpleMessageView.makeWarningDialog(new SpannableString(mContext.getResources().getText(R.string.lu_already_attache_to_doc)),
|
||||
null, () -> {
|
||||
BarcodeManager.enable();
|
||||
progressDialog.dismiss();
|
||||
})
|
||||
.show(((AppCompatActivity) mContext).getSupportFragmentManager(), "tag");
|
||||
} else {
|
||||
if(mtbColt.getGestioneEnum() == GestioneEnum.VENDITA && mtbColt.getSegno() == -1) {
|
||||
DialogSimpleMessageView.makeWarningDialog(new SpannableString(mContext.getResources().getText(R.string.lu_gest_v_loading_alert)),
|
||||
null, () -> {
|
||||
BarcodeManager.enable();
|
||||
sendMtbColt(mtbColt, progressDialog, false);
|
||||
}, () -> {
|
||||
BarcodeManager.enable();
|
||||
progressDialog.dismiss();
|
||||
})
|
||||
.show(((AppCompatActivity) mContext).getSupportFragmentManager(), "tag");
|
||||
} else {
|
||||
|
||||
BarcodeManager.enable();
|
||||
sendMtbColt(mtbColt, progressDialog, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
BarcodeManager.enable();
|
||||
progressDialog.dismiss();
|
||||
DialogCommon.showNoULFound(mContext, null);
|
||||
}
|
||||
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
BarcodeManager.enable();
|
||||
});
|
||||
|
||||
} else {
|
||||
BarcodeManager.enable();
|
||||
progressDialog.dismiss();
|
||||
|
||||
DialogCommon.showNoULFound(mContext, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}, ex -> {
|
||||
UtilityExceptions.defaultException(mContext, ex, progressDialog);
|
||||
BarcodeManager.enable();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void showTooMuchULFound() {
|
||||
DialogSimpleMessageView.makeWarningDialog(
|
||||
new SpannableString(mContext.getResources().getText(R.string.too_much_lu_found_message_in_mono_lu)),
|
||||
null, null)
|
||||
.show(((AppCompatActivity) mContext).getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
private void sendMtbColt(MtbColt mtbColtToSend, Dialog progressDialog, boolean created) {
|
||||
currentMtbColt = mtbColtToSend;
|
||||
if(progressDialog != null) progressDialog.dismiss();
|
||||
mDialog.dismiss();
|
||||
mOnDialogDismiss.run(mtbColtToSend, created);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.scan_or_create_lu;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Subcomponent
|
||||
public interface DialogScanOrCreateLUComponent {
|
||||
|
||||
@Subcomponent.Factory
|
||||
interface Factory {
|
||||
DialogScanOrCreateLUComponent create();
|
||||
}
|
||||
|
||||
void inject(DialogScanOrCreateLUView dialogScanOrCreateLUView);
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.scan_or_create_lu;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
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.PosizioniRESTConsumer;
|
||||
|
||||
@Module(subcomponents = DialogScanOrCreateLUComponent.class)
|
||||
public class DialogScanOrCreateLUModule {
|
||||
|
||||
@Provides
|
||||
DialogScanOrCreateLUViewModel providesDialogScanOrCreateLUViewModel(PosizioniRESTConsumer posizioniRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer) {
|
||||
return new DialogScanOrCreateLUViewModel(posizioniRESTConsumer, barcodeRESTConsumer, colliMagazzinoRESTConsumer, articoloRESTConsumer);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,187 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.scan_or_create_lu;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
|
||||
import it.integry.integrywmsnative.MainApplication;
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.barcode_reader.BarcodeCallbackDTO;
|
||||
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
|
||||
import it.integry.integrywmsnative.core.di.BindableBoolean;
|
||||
import it.integry.integrywmsnative.core.expansion.BaseDialogFragment;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgss;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
||||
import it.integry.integrywmsnative.databinding.DialogScanOrCreateLuBinding;
|
||||
import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;
|
||||
import it.integry.integrywmsnative.view.dialogs.basket_lu.DialogBasketLU;
|
||||
|
||||
public class DialogScanOrCreateLUView extends BaseDialogFragment implements DialogScanOrCreateLUViewModel.Listener {
|
||||
|
||||
@Inject
|
||||
DialogScanOrCreateLUViewModel mViewModel;
|
||||
|
||||
private DialogScanOrCreateLuBinding mBindings;
|
||||
private int mBarcodeScannerIstanceID;
|
||||
|
||||
private RunnableArgss<MtbColt, Boolean> mOnComplete;
|
||||
private MtbColt openedMtbColt;
|
||||
|
||||
private boolean mShouldCheckResiduo;
|
||||
private boolean mShouldCheckIfExistDoc;
|
||||
|
||||
private final BindableBoolean basketEnabled = new BindableBoolean();
|
||||
private final BindableBoolean creationEnabled = new BindableBoolean();
|
||||
|
||||
|
||||
public static DialogScanOrCreateLUView newInstance(@NotNull RunnableArgss<MtbColt, Boolean> onComplete) {
|
||||
return new DialogScanOrCreateLUView(false, true, true, true, onComplete);
|
||||
}
|
||||
|
||||
public static DialogScanOrCreateLUView newInstance(boolean enableCreation, boolean shouldCheckIfExistDoc, @NotNull RunnableArgss<MtbColt, Boolean> onComplete) {
|
||||
return new DialogScanOrCreateLUView(false, enableCreation, true, shouldCheckIfExistDoc, onComplete);
|
||||
}
|
||||
|
||||
public static DialogScanOrCreateLUView newInstance(boolean enableBasket, boolean enableCreation, boolean checkResiduo, boolean shouldCheckIfExistDoc, @NotNull RunnableArgss<MtbColt, Boolean> onComplete) {
|
||||
return new DialogScanOrCreateLUView(enableBasket, enableCreation, checkResiduo, shouldCheckIfExistDoc, onComplete);
|
||||
}
|
||||
|
||||
private DialogScanOrCreateLUView(boolean enableBasket, boolean enableCreation, boolean checkResiduo, boolean shouldCheckIfExistDoc, @NotNull RunnableArgss<MtbColt, Boolean> onComplete) {
|
||||
super();
|
||||
mShouldCheckResiduo = checkResiduo;
|
||||
mShouldCheckIfExistDoc = shouldCheckIfExistDoc;
|
||||
|
||||
this.basketEnabled.set(enableBasket);
|
||||
this.creationEnabled.set(enableCreation);
|
||||
|
||||
mOnComplete = onComplete;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
this.initBarcode();
|
||||
|
||||
mBindings = DataBindingUtil.inflate(inflater, R.layout.dialog_scan_or_create_lu, container, false);
|
||||
mBindings.setLifecycleOwner(this);
|
||||
mBindings.setView(this);
|
||||
|
||||
MainApplication.appComponent
|
||||
.dialogScanOrCreateLUComponent()
|
||||
.create()
|
||||
.inject(this);
|
||||
|
||||
this.mViewModel
|
||||
.setListener(this);
|
||||
|
||||
getDialog().setCanceledOnTouchOutside(false);
|
||||
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
|
||||
this.mViewModel.init(mShouldCheckResiduo, mShouldCheckIfExistDoc);
|
||||
|
||||
mBindings.createNewLuButton.setOnClickListener(v -> {
|
||||
this.mViewModel.createNewLU();
|
||||
});
|
||||
|
||||
mBindings.viewBasket.setOnClickListener(v -> {
|
||||
DialogBasketLU.make(getActivity(), mtbColt -> {
|
||||
onLUOpened(mtbColt, false);
|
||||
}).show();
|
||||
});
|
||||
|
||||
return mBindings.getRoot();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDismiss(@NonNull DialogInterface dialog) {
|
||||
BarcodeManager.removeCallback(mBarcodeScannerIstanceID);
|
||||
BarcodeManager.enable();
|
||||
if(openedMtbColt == null) {
|
||||
mOnComplete.run(null, false);
|
||||
}
|
||||
super.onDismiss(dialog);
|
||||
}
|
||||
|
||||
|
||||
private void initBarcode() {
|
||||
mBarcodeScannerIstanceID = BarcodeManager.addCallback(new BarcodeCallbackDTO()
|
||||
.setOnScanSuccessfull(onScanSuccessfull)
|
||||
.setOnScanFailed(this::onError));
|
||||
|
||||
setBarcodeListener(true);
|
||||
}
|
||||
|
||||
private final RunnableArgs<BarcodeScanDTO> onScanSuccessfull = data -> {
|
||||
BarcodeManager.disable();
|
||||
this.openProgress();
|
||||
|
||||
this.mViewModel.processBarcodeDTO(data, () -> {
|
||||
BarcodeManager.enable();
|
||||
this.closeProgress();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
public BindableBoolean getBasketEnabled() {
|
||||
return basketEnabled;
|
||||
}
|
||||
|
||||
public BindableBoolean getCreationEnabled() {
|
||||
return creationEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLUVenditaConfirmRequired(RunnableArgs<Boolean> onConfirm) {
|
||||
DialogSimpleMessageView.makeWarningDialog(new SpannableString(getString(R.string.lu_gest_v_loading_alert)),
|
||||
null, () -> {
|
||||
onConfirm.run(true);
|
||||
}, () -> {
|
||||
onConfirm.run(false);
|
||||
})
|
||||
.show(((AppCompatActivity) getActivity()).getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLUOpened(MtbColt mtbColt, boolean created) {
|
||||
this.openedMtbColt = mtbColt;
|
||||
mOnComplete.run(mtbColt, created);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
this.closeProgress();
|
||||
UtilityExceptions.defaultException(getActivity(), ex);
|
||||
BarcodeManager.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingStarted() {
|
||||
this.openProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingEnded() {
|
||||
this.closeProgress();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
package it.integry.integrywmsnative.view.dialogs.scan_or_create_lu;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import it.integry.barcode_base_android_library.model.BarcodeScanDTO;
|
||||
import it.integry.integrywmsnative.core.exception.AlreadyAttachedDocumentToLUException;
|
||||
import it.integry.integrywmsnative.core.exception.NoLUFoundException;
|
||||
import it.integry.integrywmsnative.core.exception.TooManyLUFoundInMonoLUPositionException;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.interfaces.viewmodel_listeners.ILoadingListener;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
import it.integry.integrywmsnative.core.model.MtbDepoPosizione;
|
||||
import it.integry.integrywmsnative.core.model.secondary.GestioneEnum;
|
||||
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.PosizioniRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityBarcode;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
|
||||
public class DialogScanOrCreateLUViewModel {
|
||||
|
||||
|
||||
private final PosizioniRESTConsumer mPosizioniRESTConsumer;
|
||||
private final BarcodeRESTConsumer mBarcodeRESTConsumer;
|
||||
private final ColliMagazzinoRESTConsumer mColliMagazzinoRESTConsumer;
|
||||
private final ArticoloRESTConsumer mArticoloRESTConsumer;
|
||||
|
||||
private boolean mShouldCheckResiduo = false;
|
||||
private boolean mShouldCheckIfExistDoc = true;
|
||||
|
||||
private Listener mListener;
|
||||
|
||||
public DialogScanOrCreateLUViewModel(PosizioniRESTConsumer mPosizioniRESTConsumer, BarcodeRESTConsumer barcodeRESTConsumer, ColliMagazzinoRESTConsumer colliMagazzinoRESTConsumer, ArticoloRESTConsumer articoloRESTConsumer) {
|
||||
this.mPosizioniRESTConsumer = mPosizioniRESTConsumer;
|
||||
this.mBarcodeRESTConsumer = barcodeRESTConsumer;
|
||||
this.mColliMagazzinoRESTConsumer = colliMagazzinoRESTConsumer;
|
||||
this.mArticoloRESTConsumer = articoloRESTConsumer;
|
||||
}
|
||||
|
||||
|
||||
public void init(boolean checkResiduo, boolean shouldCheckIfExistDoc) {
|
||||
this.mShouldCheckResiduo = checkResiduo;
|
||||
this.mShouldCheckIfExistDoc = shouldCheckIfExistDoc;
|
||||
}
|
||||
|
||||
public void createNewLU() {
|
||||
this.sendOnLoadingStarted();
|
||||
this.mColliMagazzinoRESTConsumer.createColloLavorazione(+1, createdMtbColt -> {
|
||||
this.sendOnLoadingEnded();
|
||||
this.sendOnLUOpened(createdMtbColt, true);
|
||||
}, this::sendError);
|
||||
}
|
||||
|
||||
public void processBarcodeDTO(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
|
||||
if (UtilityBarcode.isEtichettaPosizione(barcodeScanDTO)) {
|
||||
this.executeEtichettaPosizione(barcodeScanDTO, onComplete);
|
||||
} else if (UtilityBarcode.isEtichettaAnonima(barcodeScanDTO)) {
|
||||
this.executeEtichettaAnonima(barcodeScanDTO, onComplete);
|
||||
} else if (UtilityBarcode.isEtichetta128(barcodeScanDTO)) {
|
||||
this.executeEAN128(barcodeScanDTO, onComplete);
|
||||
} else {
|
||||
onComplete.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void executeEtichettaPosizione(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
|
||||
|
||||
MtbDepoPosizione foundPosizione = Stream.of(SettingsManager.iDB().getAvailablePosizioni())
|
||||
.filter(x -> x.getPosizione().equalsIgnoreCase(barcodeScanDTO.getStringValue()))
|
||||
.single();
|
||||
|
||||
this.mPosizioniRESTConsumer.getBancaliInPosizione(foundPosizione, mtbColtList -> {
|
||||
|
||||
if (mtbColtList == null || mtbColtList.size() == 0) {
|
||||
this.sendError(new NoLUFoundException());
|
||||
} else if (mtbColtList.size() == 1) {
|
||||
this.mColliMagazzinoRESTConsumer.getByTestata(mtbColtList.get(0), mShouldCheckResiduo, false, mtbColt -> {
|
||||
onComplete.run();
|
||||
this.sendOnLUOpened(mtbColt, false);
|
||||
}, this::sendError);
|
||||
} else {
|
||||
this.sendError(new TooManyLUFoundInMonoLUPositionException());
|
||||
}
|
||||
|
||||
}, this::sendError);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void executeEtichettaAnonima(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
|
||||
this.mColliMagazzinoRESTConsumer.getBySSCC(barcodeScanDTO.getStringValue(), mShouldCheckResiduo, false, mtbColt -> {
|
||||
|
||||
if (mtbColt == null) {
|
||||
this.mColliMagazzinoRESTConsumer.createColloFromEtichettaAnonima(barcodeScanDTO, GestioneEnum.LAVORAZIONE, createdMtbColt -> {
|
||||
onComplete.run();
|
||||
this.sendOnLUOpened(createdMtbColt, true);
|
||||
}, this::sendError);
|
||||
|
||||
} else {
|
||||
if (mtbColt.getCodDtip() != null && mShouldCheckIfExistDoc) {
|
||||
this.sendError(new AlreadyAttachedDocumentToLUException());
|
||||
} else {
|
||||
mtbColt.setDisablePrint(true);
|
||||
onComplete.run();
|
||||
this.sendOnLUOpened(mtbColt, false);
|
||||
}
|
||||
}
|
||||
|
||||
}, this::sendError);
|
||||
}
|
||||
|
||||
|
||||
private void executeEAN128(BarcodeScanDTO barcodeScanDTO, Runnable onComplete) {
|
||||
this.mBarcodeRESTConsumer.decodeEan128(barcodeScanDTO, ean128Model -> {
|
||||
|
||||
if (ean128Model != null && !UtilityString.isNullOrEmpty(ean128Model.Sscc)) {
|
||||
|
||||
this.mColliMagazzinoRESTConsumer.getBySSCC(ean128Model.Sscc, mShouldCheckResiduo, false, mtbColt -> {
|
||||
|
||||
if (mtbColt != null) {
|
||||
|
||||
if (mtbColt.getCodDtip() != null && mShouldCheckIfExistDoc) {
|
||||
this.sendError(new AlreadyAttachedDocumentToLUException());
|
||||
} else {
|
||||
if (mtbColt.getGestioneEnum() == GestioneEnum.VENDITA && mtbColt.getSegno() == -1) {
|
||||
this.sendOnLUVenditaConfirmRequired(confirmed -> {
|
||||
if (confirmed) {
|
||||
onComplete.run();
|
||||
this.sendOnLUOpened(mtbColt, false);
|
||||
} else {
|
||||
onComplete.run();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
onComplete.run();
|
||||
this.sendOnLUOpened(mtbColt, false);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
this.sendError(new NoLUFoundException());
|
||||
}
|
||||
|
||||
}, this::sendError);
|
||||
|
||||
} else {
|
||||
this.sendError(new NoLUFoundException());
|
||||
}
|
||||
|
||||
}, this::sendError);
|
||||
}
|
||||
|
||||
private void sendOnLUVenditaConfirmRequired(RunnableArgs<Boolean> onConfirm) {
|
||||
if (this.mListener != null) mListener.onLUVenditaConfirmRequired(onConfirm);
|
||||
}
|
||||
|
||||
private void sendOnLUOpened(MtbColt mtbColt, boolean created) {
|
||||
if (this.mListener != null) mListener.onLUOpened(mtbColt, created);
|
||||
}
|
||||
|
||||
private void sendOnLoadingStarted() {
|
||||
if (this.mListener != null) mListener.onLoadingStarted();
|
||||
}
|
||||
|
||||
private void sendOnLoadingEnded() {
|
||||
if (this.mListener != null) mListener.onLoadingEnded();
|
||||
}
|
||||
|
||||
private void sendError(Exception ex) {
|
||||
if (this.mListener != null) mListener.onError(ex);
|
||||
}
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
interface Listener extends ILoadingListener {
|
||||
|
||||
void onLUVenditaConfirmRequired(RunnableArgs<Boolean> onConfirm);
|
||||
|
||||
void onLUOpened(MtbColt mtbColt, boolean created);
|
||||
|
||||
void onError(Exception ex);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,6 +2,12 @@
|
||||
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="view"
|
||||
type="it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLUView" />
|
||||
</data>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/base_root"
|
||||
@ -95,7 +101,8 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/dialog_scan_or_create_lu__creation_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
app:visibility="@{view.creationEnabled}">
|
||||
|
||||
|
||||
|
||||
@ -138,7 +145,8 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/dialog_scan_or_create_lu__basket_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
app:visibility="@{view.basketEnabled}">
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user