[ROSSOGARGANO]
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
- corretta gestione trasferimenti in docmenti di vendita
This commit is contained in:
@@ -78,16 +78,16 @@ public class DocumentiDirettiService {
|
||||
entityList.addAll(mtbLisaCostoDataDelete);
|
||||
}
|
||||
List<MtbLisaCostoData> mtbLisaCostoData = documentService.popolaTabellaCosti(dtbDoct.getCodAnag(),
|
||||
dtbDoct.getCodDtip(),
|
||||
dtbDoct.getDataDoc(),
|
||||
dtbDoct.getSerDoc(),
|
||||
dtbDoct.getNumDoc(), false, false);
|
||||
dtbDoct.getCodDtip(),
|
||||
dtbDoct.getDataDoc(),
|
||||
dtbDoct.getSerDoc(),
|
||||
dtbDoct.getNumDoc(), false, false);
|
||||
if (mtbLisaCostoData != null)
|
||||
entityList.addAll(mtbLisaCostoData);
|
||||
}
|
||||
|
||||
List<EntityBase> entityRet = new ArrayList<>();
|
||||
for ( EntityBase e: entityList) {
|
||||
for (EntityBase e : entityList) {
|
||||
entityProcessor.processEntity(e, true, multiDBTransactionManager);
|
||||
entityRet.add(e);
|
||||
}
|
||||
@@ -98,10 +98,10 @@ public class DocumentiDirettiService {
|
||||
dtbDoct.getDataDoc(),
|
||||
dtbDoct.getSerDoc(),
|
||||
dtbDoct.getNumDoc(), false, false);
|
||||
if (mtbLisaCostoData != null){
|
||||
if (mtbLisaCostoData != null) {
|
||||
entityList.addAll(mtbLisaCostoData);
|
||||
|
||||
for ( EntityBase e: mtbLisaCostoData) {
|
||||
for (EntityBase e : mtbLisaCostoData) {
|
||||
entityProcessor.processEntity(e, true, multiDBTransactionManager);
|
||||
entityRet.add(e);
|
||||
}
|
||||
@@ -116,49 +116,48 @@ public class DocumentiDirettiService {
|
||||
}
|
||||
|
||||
private DtbDoct checkUDSForTransfer(DtbDoct dtbDoct, List<EntityBase> entityList, boolean isNewDoc) throws Exception {
|
||||
if (dtbDoct.getMtbColt().isEmpty())
|
||||
if (dtbDoct.getMtbColt().isEmpty() && isNewDoc)
|
||||
return null;
|
||||
String codDtipTrasf = setupGest.getSetupDepo(multiDBTransactionManager.getPrimaryConnection(), "PICKING", "LOGISTICA", "COD_DTIP_DOC_TRASF_INTERNI", dtbDoct.getCodMdep());
|
||||
if (!UtilityString.isNullOrEmpty(codDtipTrasf))
|
||||
return null;
|
||||
//<editor-fold desc="Prendo tutti i colli, con le quantità associate che devono essere trasferite">
|
||||
String whereCondColli =
|
||||
StringUtils.join(dtbDoct.getMtbColt().stream().map(ul -> {
|
||||
try {
|
||||
return String.format("(%s)", ul.getPkWhereCond());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).collect(Collectors.toList()), " OR ");
|
||||
List<UlVenditaDTO> artsToTransfer = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), Query.format("WITH uds AS (SELECT *\n" +
|
||||
" FROM mtb_colt\n" +
|
||||
" WHERE cod_mdep <> {}\n" +
|
||||
" AND (" + whereCondColli + "))\n" +
|
||||
"\n" +
|
||||
"SELECT mtb_colt.data_collo,\n" +
|
||||
" mtb_colt.ser_collo,\n" +
|
||||
" mtb_colt.gestione,\n" +
|
||||
" mtb_colt.num_collo,\n" +
|
||||
" cod_mdep,\n" +
|
||||
" cod_mart,\n" +
|
||||
" partita_mag,\n" +
|
||||
" mtb_colt.cod_tcol,\n" +
|
||||
" SUM(qta_col) AS qta_col,\n" +
|
||||
" SUM(num_cnf) AS num_cnf\n" +
|
||||
"FROM uds mtb_colt\n" +
|
||||
" INNER JOIN mtb_colr ON mtb_colt.gestione = mtb_colr.gestione AND mtb_colt.data_collo = mtb_colr.data_collo AND\n" +
|
||||
" mtb_colt.ser_collo = mtb_colr.ser_collo AND mtb_colt.num_collo = mtb_colr.num_collo\n" +
|
||||
"GROUP BY mtb_colt.data_collo, mtb_colt.ser_collo, mtb_colt.gestione, mtb_colt.num_collo, cod_mdep, partita_mag,cod_mart, mtb_colt.cod_tcol\n", dtbDoct.getCodMdep(), whereCondColli)
|
||||
, UlVenditaDTO.class);
|
||||
|
||||
|
||||
//controllo che ci sia qualcosa da trasferire
|
||||
if (UtilityList.isNullOrEmpty(artsToTransfer)) {
|
||||
return null;
|
||||
String whereCondColli = StringUtils.join(dtbDoct.getMtbColt().stream().filter(x -> !x.getOperation().equals(OperationType.DELETE)).map(ul -> {
|
||||
try {
|
||||
return String.format("(%s)", ul.getPkWhereCond());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).collect(Collectors.toList()), " OR ");
|
||||
List<UlVenditaDTO> artsToTransfer;
|
||||
if (UtilityString.isNullOrEmpty(whereCondColli)) {
|
||||
artsToTransfer = new ArrayList<>();
|
||||
} else {
|
||||
artsToTransfer = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), Query.format("WITH uds AS (SELECT *\n" +
|
||||
" FROM mtb_colt\n" +
|
||||
" WHERE cod_mdep <> {}\n" +
|
||||
" AND (" + whereCondColli + "))\n" +
|
||||
"\n" +
|
||||
"SELECT mtb_colt.data_collo,\n" +
|
||||
" mtb_colt.ser_collo,\n" +
|
||||
" mtb_colt.gestione,\n" +
|
||||
" mtb_colt.num_collo,\n" +
|
||||
" cod_mdep,\n" +
|
||||
" cod_mart,\n" +
|
||||
" partita_mag,\n" +
|
||||
" mtb_colt.cod_tcol,\n" +
|
||||
" SUM(qta_col) AS qta_col,\n" +
|
||||
" SUM(num_cnf) AS num_cnf\n" +
|
||||
"FROM uds mtb_colt\n" +
|
||||
" INNER JOIN mtb_colr ON mtb_colt.gestione = mtb_colr.gestione AND mtb_colt.data_collo = mtb_colr.data_collo AND\n" +
|
||||
" mtb_colt.ser_collo = mtb_colr.ser_collo AND mtb_colt.num_collo = mtb_colr.num_collo\n" +
|
||||
"GROUP BY mtb_colt.data_collo, mtb_colt.ser_collo, mtb_colt.gestione, mtb_colt.num_collo, cod_mdep, partita_mag,cod_mart, mtb_colt.cod_tcol\n", dtbDoct.getCodMdep(), whereCondColli)
|
||||
, UlVenditaDTO.class);
|
||||
if (artsToTransfer == null) artsToTransfer = new ArrayList<>();
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="raccolgo le info basi del nuovo documento">
|
||||
String codDtipTrasf = setupGest.getSetupDepo(multiDBTransactionManager.getPrimaryConnection(), "PICKING", "LOGISTICA", "COD_DTIP_DOC_TRASF_INTERNI", dtbDoct.getCodMdep());
|
||||
if (UtilityString.isNullOrEmpty(codDtipTrasf)) {
|
||||
throw new Exception("Le UL incluse nel documento richiedono un trasferimento di deposito, ma nessun tipo documento è stato configurato per il deposito di arrivo.");
|
||||
}
|
||||
MtbDepo mtbDepo = new MtbDepo();
|
||||
mtbDepo.setCodMdep(dtbDoct.getCodMdep())
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
@@ -191,14 +190,18 @@ public class DocumentiDirettiService {
|
||||
dtbDoct.setActivityId(activityId);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
List<DtbDoct> docTrasfList = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(),Query.format("SELECT cod_anag,data_doc,ser_doc,num_doc,cod_dtip from dtb_doct where activity_id = {} and cod_dtip = {} ", activityId, codDtipTrasf), DtbDoct.class);
|
||||
if (docTrasfList == null) docTrasfList = new ArrayList<>();
|
||||
docTrasfList =docTrasfList.stream().peek(x->x.setOperation(OperationType.DELETE)).collect(Collectors.toList());
|
||||
|
||||
List<String> depositiPartenza = artsToTransfer.stream().map(UlVenditaDTO::getCodMdep).distinct().collect(Collectors.toList());
|
||||
for (String codMdep : depositiPartenza) {
|
||||
//<editor-fold desc="Controllo se esiste già un documento di trasferimento">
|
||||
DtbDoct docTrasf = null;
|
||||
|
||||
if (!isNewDoc) {
|
||||
String sql = Query.format("SELECT cod_anag,data_doc,ser_doc,num_doc,cod_dtip from dtb_doct where activity_id = {} and cod_dtip = {} and cod_mdep = {}", activityId, codDtipTrasf, codMdep);
|
||||
docTrasf = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbDoct.class);
|
||||
docTrasf = docTrasfList.stream().filter(x->x.getCodMdep().equals(codMdep)).findFirst().orElse(null);
|
||||
if (docTrasf != null) {
|
||||
docTrasf.setOperation(OperationType.UPDATE);
|
||||
List<DtbDocr> oldDocRows = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), "SELECT * from dtb_docr where " + docTrasf.getPkWhereCond(), DtbDocr.class);
|
||||
@@ -217,6 +220,7 @@ public class DocumentiDirettiService {
|
||||
.setCodDtip(codDtipTrasf)
|
||||
.setActivityId(activityId);
|
||||
docTrasf.setOperation(OperationType.INSERT);
|
||||
docTrasfList.add(docTrasf);
|
||||
}
|
||||
//</editor-fold>
|
||||
//<editor-fold desc="Raggruppo le quantità da trasferire per deposito/articolo/partita">
|
||||
@@ -274,8 +278,8 @@ public class DocumentiDirettiService {
|
||||
docTrasf.setOperation(OperationType.DELETE);
|
||||
//</editor-fold>
|
||||
|
||||
entityList.add(docTrasf);
|
||||
}
|
||||
entityList.addAll(docTrasfList);
|
||||
|
||||
|
||||
return dtbDoct;
|
||||
|
||||
Reference in New Issue
Block a user