In importazione gelorent aggiunti riferimenti dell'ordine
This commit is contained in:
@@ -53,25 +53,25 @@ public class DocumentiImportService {
|
||||
"um.unt_mis, " +
|
||||
"um.rap_conv, " +
|
||||
"um.flag_unita_kg " +
|
||||
"FROM mtb_aart_ass cross apply dbo.getUntMisArticolo(mtb_aart_ass.cod_mart_generico, null) UM "+
|
||||
"INNER JOIN mtb_aart on mtb_aart_ass.cod_mart_generico = mtb_aart.cod_mart AND mtb_aart_ass.cod_mgrp = mtb_aart.cod_mgrp ";
|
||||
"FROM mtb_aart_ass cross apply dbo.getUntMisArticolo(mtb_aart_ass.cod_mart_generico, null) UM " +
|
||||
"INNER JOIN mtb_aart on mtb_aart_ass.cod_mart_generico = mtb_aart.cod_mart AND mtb_aart_ass.cod_mgrp = mtb_aart.cod_mgrp ";
|
||||
|
||||
List<HashMap<String, Object>> associazioneArticoli = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
sql =
|
||||
"SELECT dtb_doct_scarico.cod_anag, " +
|
||||
"dtb_doct_scarico.cod_dtip_scarico, " +
|
||||
"dtb_doct_scarico.data_doc, " +
|
||||
"dtb_doct_scarico.ser_doc, " +
|
||||
"dtb_doct_scarico.num_doc, " +
|
||||
"dtb_doct_scarico.cod_mdep, " +
|
||||
"dtb_doct_scarico.cod_mgrp, " +
|
||||
"dtb_doct_scarico.cod_dtip_carico " +
|
||||
" FROM lvw_doc_preparati dtb_doct_scarico ";
|
||||
"SELECT dtb_doct_scarico.cod_anag, " +
|
||||
"dtb_doct_scarico.cod_dtip_scarico, " +
|
||||
"dtb_doct_scarico.data_doc, " +
|
||||
"dtb_doct_scarico.ser_doc, " +
|
||||
"dtb_doct_scarico.num_doc, " +
|
||||
"dtb_doct_scarico.cod_mdep, " +
|
||||
"dtb_doct_scarico.cod_mgrp, " +
|
||||
"dtb_doct_scarico.cod_dtip_carico " +
|
||||
" FROM lvw_doc_preparati dtb_doct_scarico ";
|
||||
|
||||
List<HashMap<String, Object>> docScarico = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
for ( HashMap<String, Object> doc: docScarico) {
|
||||
for (HashMap<String, Object> doc : docScarico) {
|
||||
String codMgrp = (String) doc.get("cod_mgrp");
|
||||
String sqlRighe =
|
||||
"SELECT DISTINCT dtb_docr.cod_mart, dtb_docr.unt_doc," +
|
||||
@@ -80,7 +80,7 @@ public class DocumentiImportService {
|
||||
"dtb_docr.val_unt, " +
|
||||
"case when um.flag_unita_kg = 'S' THEN dtb_docr.val_unt ELSE Round(dtb_docr.val_unt / case when mtb_aart.peso_kg = 0 then 1 ELSE mtb_aart.peso_kg END , 5) END as costo_kg, " +
|
||||
"Cast(case when um.flag_unita_kg <> 'S' and mtb_aart.peso_kg = 0 THEN 1 ELSE 0 END as bit) as peso_zero " +
|
||||
" FROM dtb_docr " +
|
||||
" FROM dtb_docr " +
|
||||
"inner join mtb_aart on dtb_docr.cod_mart = mtb_aart.cod_mart " +
|
||||
"cross apply dbo.getUntMisArticolo(dtb_docr.cod_mart, dtb_docr.unt_doc) um " +
|
||||
"WHERE dtb_docr.cod_anag = " + UtilityDB.valueToString(UtilityHashMap.getValueIfExists(doc, "cod_anag")) + " AND " +
|
||||
@@ -90,13 +90,13 @@ public class DocumentiImportService {
|
||||
"dtb_docr.num_doc = " + UtilityDB.valueToString(UtilityHashMap.getValueIfExists(doc, "num_doc"));
|
||||
List<HashMap<String, Object>> row = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sqlRighe);
|
||||
|
||||
List<String> artPesoZero = Stream.of(row).filter(x->(boolean) UtilityHashMap.getValueIfExists(x, "peso_zero")).map(x-> (String) UtilityHashMap.getValueIfExists(x, "cod_mart")).toList();
|
||||
List<String> artPesoZero = Stream.of(row).filter(x -> (boolean) UtilityHashMap.getValueIfExists(x, "peso_zero")).map(x -> (String) UtilityHashMap.getValueIfExists(x, "cod_mart")).toList();
|
||||
|
||||
if (artPesoZero != null && artPesoZero.size() > 0 ){
|
||||
if (artPesoZero != null && artPesoZero.size() > 0) {
|
||||
String message = String.format("Nel documento %s del %s n. %s sono presenti articoli con peso = 0." + CommonConstants.A_CAPO + "Articoli: %s",
|
||||
UtilityHashMap.getValueIfExists(doc, "cod_dtip"),
|
||||
new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(UtilityHashMap.getValueIfExists(doc, "data_doc")),
|
||||
UtilityHashMap.getValueIfExists(doc, "ser_doc") + "/" +UtilityHashMap.getValueIfExists(doc, "num_doc"),
|
||||
UtilityHashMap.getValueIfExists(doc, "ser_doc") + "/" + UtilityHashMap.getValueIfExists(doc, "num_doc"),
|
||||
StringUtils.join(artPesoZero, ", "));
|
||||
AnomalieDTO anomalia = AnomalieDTO.info(message);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class DocumentiImportService {
|
||||
Boolean importDoc = true;
|
||||
List<DtbDocr> righeDoc = new ArrayList<>();
|
||||
String reparto = null;
|
||||
for(HashMap<String, Object> dati: row) {
|
||||
for (HashMap<String, Object> dati : row) {
|
||||
String codMart = (String) dati.get("cod_mart");
|
||||
String untDoc = (String) dati.get("unt_doc");
|
||||
|
||||
@@ -123,10 +123,11 @@ public class DocumentiImportService {
|
||||
String untDocCarico = null;
|
||||
String codMartCarico = null;
|
||||
if (umKG.isPresent()) {
|
||||
qtaDocCarico = (BigDecimal) dati.get("peso_netto");;
|
||||
qtaDocCarico = (BigDecimal) dati.get("peso_netto");
|
||||
;
|
||||
untDocCarico = UtilityHashMap.getValueIfExists(umKG.get(), "unt_mis");
|
||||
codMartCarico = UtilityHashMap.getValueIfExists(umKG.get(), "cod_mart_generico");
|
||||
if(reparto==null) reparto = UtilityHashMap.getValueIfExists(umKG.get(), "cod_mgpr");
|
||||
if (reparto == null) reparto = UtilityHashMap.getValueIfExists(umKG.get(), "cod_mgpr");
|
||||
costoKG = (BigDecimal) dati.get("costo_kg");
|
||||
} else {
|
||||
Optional<HashMap<String, Object>> umDoc = Stream.of(associazioneArticoli)
|
||||
@@ -137,17 +138,17 @@ public class DocumentiImportService {
|
||||
qtaDocCarico = (BigDecimal) dati.get("qta_doc");
|
||||
untDocCarico = UtilityHashMap.getValueIfExists(umDoc.get(), "unt_mis");
|
||||
codMartCarico = UtilityHashMap.getValueIfExists(umDoc.get(), "cod_mart_generico");
|
||||
if(reparto==null) reparto = UtilityHashMap.getValueIfExists(umDoc.get(), "cod_mgrp");
|
||||
if (reparto == null) reparto = UtilityHashMap.getValueIfExists(umDoc.get(), "cod_mgrp");
|
||||
costoKG = (BigDecimal) dati.get("val_unt");
|
||||
}
|
||||
}
|
||||
|
||||
if (codMartCarico == null || untDocCarico == null ) {
|
||||
if (codMartCarico == null || untDocCarico == null) {
|
||||
AnomalieDTO anomalia = AnomalieDTO.info("Nessuna associazione trovata o unità di misura non corrispondente ( " + untDoc + ") " +
|
||||
"per l'articolo " + codMart + "presente nel documemto " +
|
||||
UtilityHashMap.getValueIfExists(doc, "cod_dtip") +
|
||||
UtilityHashMap.getValueIfExists(doc, "cod_dtip") +
|
||||
" del " + new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(UtilityHashMap.getValueIfExists(doc, "data_doc")) +
|
||||
"n. " + UtilityHashMap.getValueIfExists(doc, "ser_doc") + "/" +UtilityHashMap.getValueIfExists(doc, "num_doc"));
|
||||
"n. " + UtilityHashMap.getValueIfExists(doc, "ser_doc") + "/" + UtilityHashMap.getValueIfExists(doc, "num_doc"));
|
||||
|
||||
anomalie.add(anomalia);
|
||||
importDoc = false;
|
||||
@@ -159,7 +160,7 @@ public class DocumentiImportService {
|
||||
}
|
||||
|
||||
|
||||
if (importDoc ) {
|
||||
if (importDoc) {
|
||||
DtbDoct dtbDoct = new DtbDoct();
|
||||
dtbDoct.setCodAnag(UtilityHashMap.getValueIfExists(doc, "cod_anag"))
|
||||
.setCodDtip(UtilityHashMap.getValueIfExists(doc, "cod_dtip_carico"))
|
||||
@@ -194,7 +195,7 @@ public class DocumentiImportService {
|
||||
|
||||
if (entityErr.size() > 0) {
|
||||
List<AnomalieDTO> anomaliaEntity = Stream.of(entityErr).map(
|
||||
x ->{
|
||||
x -> {
|
||||
AnomalieDTO anomalia = AnomalieDTO.error(x.getException());
|
||||
return anomalia;
|
||||
}
|
||||
@@ -206,7 +207,7 @@ public class DocumentiImportService {
|
||||
return entityReturn;
|
||||
}
|
||||
|
||||
public List<EntityBase> importDocumentiVenditaGelorent(String type, String format, String rawContentInput, List<AnomalieDTO> anomalie) throws Exception{
|
||||
public List<EntityBase> importDocumentiVenditaGelorent(String type, String format, String rawContentInput, List<AnomalieDTO> anomalie) throws Exception {
|
||||
Map<String, String> setup = setupGest.getImportSetupSection(multiDBTransactionManager.getPrimaryConnection(), type, format);
|
||||
|
||||
List<String> lines = UtilityString.splitStringToMultipleLine(rawContentInput);
|
||||
@@ -242,10 +243,12 @@ public class DocumentiImportService {
|
||||
char lastLine = columns[5].charAt(0);
|
||||
String dest = String.valueOf(Integer.parseInt(columns[6]));
|
||||
String codMart = String.valueOf(Integer.parseInt(columns[7]));
|
||||
if ( isCodMart ) codMart = "0" + codMart;
|
||||
if (isCodMart) codMart = "0" + codMart;
|
||||
Integer rifNumOrd = UtilityString.isNullOrEmpty(columns[10].trim()) ? null : Integer.parseInt(columns[10].trim());
|
||||
Date rifDataOrd = columns.length >= 13 ? UtilityDate.StringToDate(columns[12].trim(), "yyyyMMdd") : null;
|
||||
|
||||
//TESTATA
|
||||
if (typeBolla == 1){
|
||||
if (typeBolla == 1) {
|
||||
dtbDoct = new DtbDoct();
|
||||
listDtbDocr = new ArrayList<>();
|
||||
dtbDoct.setDataDoc(date);
|
||||
@@ -256,24 +259,24 @@ public class DocumentiImportService {
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT vtb_dest.cod_anag, vtb_dest.cod_vdes\n" +
|
||||
"FROM vtb_clie\n" +
|
||||
" INNER JOIN vtb_dest ON vtb_clie.cod_anag = vtb_dest.cod_anag\n" +
|
||||
" LEFT OUTER JOIN vtb_dest_intercode ON vtb_dest.cod_anag = vtb_dest_intercode.cod_anag AND\n" +
|
||||
" vtb_dest.cod_vdes = vtb_dest_intercode.cod_vdes AND\n" +
|
||||
" vtb_dest_intercode.cod_forn = %s\n" +
|
||||
"WHERE vtb_clie.flag_stato = 'A'\n" +
|
||||
" AND vtb_dest.flag_attivo = 'S'\n" +
|
||||
" AND (vtb_dest_intercode.intercode = %s OR vtb_dest.cod_affiliazione = %s)",
|
||||
codForn, dest, dest);
|
||||
"SELECT vtb_dest.cod_anag, vtb_dest.cod_vdes\n" +
|
||||
"FROM vtb_clie\n" +
|
||||
" INNER JOIN vtb_dest ON vtb_clie.cod_anag = vtb_dest.cod_anag\n" +
|
||||
" LEFT OUTER JOIN vtb_dest_intercode ON vtb_dest.cod_anag = vtb_dest_intercode.cod_anag AND\n" +
|
||||
" vtb_dest.cod_vdes = vtb_dest_intercode.cod_vdes AND\n" +
|
||||
" vtb_dest_intercode.cod_forn = %s\n" +
|
||||
"WHERE vtb_clie.flag_stato = 'A'\n" +
|
||||
" AND vtb_dest.flag_attivo = 'S'\n" +
|
||||
" AND (vtb_dest_intercode.intercode = %s OR vtb_dest.cod_affiliazione = %s)",
|
||||
codForn, dest, dest);
|
||||
|
||||
HashMap<String, Object> result = UtilityDB.executeSimpleQueryOnlyFirstRow(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (result != null){
|
||||
if (result != null) {
|
||||
dtbDoct.setCodAnag(UtilityHashMap.getValueIfExists(result, "cod_anag"));
|
||||
dtbDoct.setCodVdes(UtilityHashMap.getValueIfExists(result, "cod_vdes"));
|
||||
error = false;
|
||||
}else{
|
||||
} else {
|
||||
anomalie.add(new AnomalieDTO().setTipo(AnomalieDTO.Type.ERROR).setMessage("CodAnag e CodVdes non trovati! Codice affiliazione: " + dest));
|
||||
error = true;
|
||||
continue;
|
||||
@@ -287,50 +290,53 @@ public class DocumentiImportService {
|
||||
|
||||
boolean isVal = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (isVal){
|
||||
if (isVal) {
|
||||
anomalie.add(new AnomalieDTO().setTipo(AnomalieDTO.Type.WARNING).setMessage("Documento già esistente " + dtbDoct.getCodDtip() + " " + dtbDoct.getDataDoc() + " N. " + dtbDoct.getNumDoc()));
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
sql = "select dtb_ordt.data_ord, dtb_ordt.num_ord, dtb_ordr.riga_ord,\n" +
|
||||
"dtb_ordr.cod_mart as cod_mart\n" +
|
||||
"from dtb_ordt inner join dtb_ordr on dtb_ordt.gestione = dtb_ordr.gestione and \n" +
|
||||
"dtb_ordt.data_ord = dtb_ordr.data_ord and \n" +
|
||||
"dtb_ordt.num_ord = dtb_ordr.num_ord\n" +
|
||||
"where dtb_ordt.gestione = 'V' AND \n" +
|
||||
"dtb_ordt.cod_anag = " + UtilityDB.valueToString(dtbDoct.getCodAnag()) + " AND \n" +
|
||||
"dtb_ordt.cod_vdes = " + UtilityDB.valueToString(dtbDoct.getCodVdes()) + " AND \n" +
|
||||
"dtb_ordt.flag_sospeso = 'N' AND \n" +
|
||||
"dtb_ordt.flag_annulla = 'N' ANd\n" +
|
||||
"dtb_ordr.flag_evaso = 'I' AND \n" +
|
||||
"dtb_ordr.cod_mart is not null AND \n" +
|
||||
"dtb_ordr.qta_ord - dtb_ordr.qta_evasa > 0 AND \n" +
|
||||
"dtb_ordr.data_cons = " + UtilityDB.valueToString(dtbDoct.getDataCons());
|
||||
sql = " SELECT dtb_ordt.data_ord,\n" +
|
||||
" dtb_ordt.num_ord,\n" +
|
||||
" dtb_ordr.riga_ord,\n" +
|
||||
" dtb_ordr.cod_mart AS cod_mart\n" +
|
||||
"FROM dtb_ordt\n" +
|
||||
" INNER JOIN dtb_ordr ON dtb_ordt.gestione = dtb_ordr.gestione AND\n" +
|
||||
" dtb_ordt.data_ord = dtb_ordr.data_ord AND\n" +
|
||||
" dtb_ordt.num_ord = dtb_ordr.num_ord\n" +
|
||||
"WHERE dtb_ordt.gestione = 'V'\n" +
|
||||
" AND dtb_ordt.cod_anag = " + UtilityDB.valueToString(dtbDoct.getCodAnag()) + "\n" +
|
||||
" AND dtb_ordt.cod_vdes = " + UtilityDB.valueToString(dtbDoct.getCodVdes()) + "\n" +
|
||||
" AND dtb_ordt.flag_sospeso = 'N'\n" +
|
||||
" AND dtb_ordt.flag_annulla = 'N'\n" +
|
||||
" AND dtb_ordr.flag_evaso = 'I'\n" +
|
||||
" AND dtb_ordr.cod_mart IS NOT NULL\n" +
|
||||
" AND dtb_ordt.rif_num_ord = " + UtilityDB.valueToString(rifNumOrd) + "\n" +
|
||||
" AND dtb_ordt.rif_data_ord = " + UtilityDB.valueToString(rifDataOrd);
|
||||
|
||||
data = UtilityDB.executeSimpleQuery(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
}
|
||||
|
||||
//RIGHA
|
||||
if (typeBolla == 2 && !error){
|
||||
if (typeBolla == 2 && !error) {
|
||||
BigDecimal numCnf = UtilityString.stringToBigDecimal(columns[8]);
|
||||
DtbDocr dtbDocr = new DtbDocr();
|
||||
|
||||
if (!isCodMart) {
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT cod_mart \n" +
|
||||
" FROM dbo.getListinoAcquisto(null, null, %s, null, 'N', null) lisa \n" +
|
||||
" WHERE tipo_variazione <> 'D' AND \n" +
|
||||
"cod_mart is not null AND\n" +
|
||||
"EXISTS (SELECT * FROM dtb_ordr WHERE gestione = 'A' AND cod_mdep = %s AND data_ord >= DateAdd(year, -1, %s) and dtb_ordr.cod_mart = lisa.cod_mart)",
|
||||
codMart, codMdep, dtbDoct.getDataCons());
|
||||
"SELECT cod_mart \n" +
|
||||
" FROM dbo.getListinoAcquisto(null, null, %s, null, 'N', null) lisa \n" +
|
||||
" WHERE tipo_variazione <> 'D' AND \n" +
|
||||
"cod_mart is not null AND\n" +
|
||||
"EXISTS (SELECT * FROM dtb_ordr WHERE gestione = 'A' AND cod_mdep = %s AND data_ord >= DateAdd(year, -1, %s) and dtb_ordr.cod_mart = lisa.cod_mart)",
|
||||
codMart, codMdep, dtbDoct.getDataCons());
|
||||
|
||||
codMart = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
}
|
||||
|
||||
for (HashMap<String, Object> r : data){
|
||||
if (r.get("cod_mart").toString().equals(codMart)){
|
||||
for (HashMap<String, Object> r : data) {
|
||||
if (r.get("cod_mart").toString().equals(codMart)) {
|
||||
dtbDocr.setDataOrd(UtilityHashMap.getValueIfExists(r, "data_ord"));
|
||||
dtbDocr.setNumOrd(UtilityHashMap.getValueIfExists(r, "num_ord"));
|
||||
dtbDocr.setRigaOrd(UtilityHashMap.getValueIfExists(r, "riga_ord"));
|
||||
@@ -342,7 +348,7 @@ public class DocumentiImportService {
|
||||
dtbDocr.setOperation(OperationType.INSERT);
|
||||
listDtbDocr.add(dtbDocr);
|
||||
|
||||
if (lastLine == 'E'){
|
||||
if (lastLine == 'E') {
|
||||
Optional<DtbDocr> firstRowOrd = Stream.of(listDtbDocr).filter(x -> x.getDataOrd() != null && x.getNumOrd() != null && x.getRigaOrd() != null).findFirst();
|
||||
if (firstRowOrd.isPresent()) {
|
||||
dtbDoct
|
||||
@@ -386,7 +392,7 @@ public class DocumentiImportService {
|
||||
String whereCond = "";
|
||||
|
||||
for (EntityBase entity : r.getValue()) {
|
||||
if (!whereCond.equals("")){
|
||||
if (!whereCond.isEmpty()) {
|
||||
whereCond += " OR ";
|
||||
}
|
||||
whereCond += "(dtb_doct.cod_anag = " + UtilityDB.valueToString(((DtbDoct) entity).getCodAnag()) + " AND " +
|
||||
@@ -407,7 +413,7 @@ public class DocumentiImportService {
|
||||
return entityReturn;
|
||||
}
|
||||
|
||||
private Date checkDataCons(Date date, List<JtbRicorrenze> ricorrenze) throws Exception{
|
||||
private Date checkDataCons(Date date, List<JtbRicorrenze> ricorrenze) throws Exception {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user