diff --git a/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20241219111120.java b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20241219111120.java new file mode 100644 index 0000000000..67ac96edce --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20241219111120.java @@ -0,0 +1,22 @@ +package it.integry.ems.migration.model; + +import it.integry.ems.migration._base.BaseMigration; +import it.integry.ems.migration._base.MigrationModelInterface; + +public class Migration_20241219111120 extends BaseMigration implements MigrationModelInterface { + + @Override + public void up() throws Exception { + if (isHistoryDB()) + return; + + executeStatement( + "update stb_menu set descrizione = 'Porto - Incoterms' where cod_opz = 'TG012'", + "update stb_menu_opz set descrizione = 'Porto - Incoterms' where cod_opz = 'TG012'" + ); + } + + @Override + public void down() throws Exception { + } +} \ No newline at end of file diff --git a/ems-core/src/main/java/it/integry/ems/rules/completing/AccountingRules.java b/ems-core/src/main/java/it/integry/ems/rules/completing/AccountingRules.java index bc76f794f8..6e86d09701 100644 --- a/ems-core/src/main/java/it/integry/ems/rules/completing/AccountingRules.java +++ b/ems-core/src/main/java/it/integry/ems/rules/completing/AccountingRules.java @@ -1020,4 +1020,24 @@ public class AccountingRules extends QueryRules { } + public static Boolean completeVentilazione(Connection connection, CtbMovi ctbMovi) throws SQLException { + boolean ventilazione; + if ( ctbMovi.getParent() instanceof CtbMovt) { + String sql = + Query.format( + "SELECT CAST(IIF((SELECT segno_liquid FROM ctb_ireg WHERE cod_ireg = %s) = -1 AND flag_iva_acq_merci = 'S', 1, 0) AS BIT)\n" + + "FROM gtb_aliq\n" + + "WHERE cod_aliq = %s", + ((CtbMovt) ctbMovi.getParent()).getCodIreg(), + ctbMovi.getCodAliq()); + + ventilazione = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, sql); + + + } else { + ventilazione = ctbMovi.getVentilazione()==null?false:ctbMovi.getVentilazione(); + } + return ventilazione; + } + } diff --git a/ems-core/src/main/java/it/integry/ems/rules/completing/DocOrdCalTotaliRules.java b/ems-core/src/main/java/it/integry/ems/rules/completing/DocOrdCalTotaliRules.java index 4e01a8ccda..ed21824c57 100644 --- a/ems-core/src/main/java/it/integry/ems/rules/completing/DocOrdCalTotaliRules.java +++ b/ems-core/src/main/java/it/integry/ems/rules/completing/DocOrdCalTotaliRules.java @@ -416,30 +416,6 @@ public class DocOrdCalTotaliRules extends QueryRules { return rowsToSave; } -// public static void explodeKit(Connection conn, DtbDocOrdT testata) throws Exception { -// List righe = testata.getRows(); -// List righeComp = new ArrayList<>(); -// String explodeKit = testata.getExplodeKit(); -// -// if (explodeKit.equalsIgnoreCase("S")) { -// List righeKit = findKit(testata); -// if (righeKit != null) { -// String gestione = testata.getGestione(); -// for (int i = 0; i < righeKit.size(); i++) { -// final DtbDocOrdR row = righeKit.get(i); -// List dtbDocOrdRS = explodeKitRow(conn, row, i); -// righeComp.addAll(dtbDocOrdRS); -// } -// } -// -// if (righeComp.size() > 0) { -// righe.addAll(righeComp); -// Stream.of(righe).sortBy(x->x.getRigaKit()); -// testata.setRows(righe); -// } -// } -// } - public static List explodeKitRow(Connection conn, DtbDocOrdR row) throws Exception { DtbDocOrdT testata = (DtbDocOrdT) row.getParent(); if (testata.getExplodeKit().equalsIgnoreCase("S")) { @@ -463,7 +439,6 @@ public class DocOrdCalTotaliRules extends QueryRules { } public static void calcTotali(Connection conn, DtbDocOrdT testata) throws Exception { - Boolean insMovCont = false; String flagIvaInclusa = "N"; List sconti = new ArrayList<>(); List righe = null; @@ -485,7 +460,7 @@ public class DocOrdCalTotaliRules extends QueryRules { testata.setOperation(OperationType.UPDATE); } - HashMap lhm_castelletto = new HashMap<>(); + List lhm_castelletto = new ArrayList<>(); String gestione = testata.getGestione(); String codDivi = testata.getCodDivi(); @@ -500,7 +475,8 @@ public class DocOrdCalTotaliRules extends QueryRules { Integer maxRigaSpesa = 0; String whereCondExcSpese = null; boolean calcScpese = false; - boolean flagSpeseArt = false, isOrdine = false, ventilazioneIva = false; + Boolean insMovCont = false; + boolean flagSpeseArt = false, isOrdine = false; if (testata instanceof DtbOrdt) { righe = ((DtbOrdt) testata).getDtbOrdr(); flagIvaInclusa = ((DtbOrdt) testata).getFlagPrzIva(); @@ -525,18 +501,6 @@ public class DocOrdCalTotaliRules extends QueryRules { if (((DtbDoct) testata).getVtbClie() != null) { flagSpeseArt = ((DtbDoct) testata).getVtbClie().getFlagSpeseArt().equalsIgnoreCase("S"); } - if (insMovCont){ - String sql = - Query.format( - "SELECT CAST(COUNT(*) AS BIT)\n" + - "FROM mtb_depo\n" + - "WHERE %s BETWEEN ISNULL(data_iniz_vent, %s) AND ISNULL(data_fine_vent, CAST(GETDATE() AS DATE))\n" + - " AND mtb_depo.cod_mdep = %s\n", - ((DtbDoct) testata).getDataReg(), - ((DtbDoct) testata).getDataReg(), - testata.getCodMdep()); - ventilazioneIva = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql); - } } if ("N".equals(flagPrezziScontati)) { @@ -617,17 +581,7 @@ public class DocOrdCalTotaliRules extends QueryRules { } } - //RosannaR 23/05/2018 - //(problema riscontrato a Mafrat per i documenti di ContoVendita con sconto in testata) - //lasciando i 5 decimali anche il calcolo dell'imponibile e del totale documento - // venivano calcolati con i 5 decimali e comunque il calcolo differiva da quello di P.W. - - // if ("S".equals(flagIvaInclusa)) { importoRiga = CommonRules.roundValue(importoRiga, cifreDec); - // } else { - // importoRiga = IntegerUtility.round(importoRiga, 5); - // } - nettoMerce = nettoMerce.add(importoRiga.setScale(2, RoundingMode.HALF_UP)); } @@ -659,16 +613,10 @@ public class DocOrdCalTotaliRules extends QueryRules { } } - if ("S".equals(flagIvaInclusa)) { - if (qta.compareTo(BigDecimal.ZERO) != 0) { - //if(impRigaIva.compareTo(BigDecimal.ZERO)!= 0) { - addCastellettoIva(impRigaIva, codAliq, lhm_castelletto); - } - } else { - if (qta.compareTo(BigDecimal.ZERO) != 0) { - //if(importoRiga.compareTo(BigDecimal.ZERO)!= 0) { - addCastellettoIva(importoRiga, codAliq, lhm_castelletto); - } + if (qta.compareTo(BigDecimal.ZERO) != 0) { + boolean ventilazione = false; + if ( row instanceof DtbDocr) ventilazione = ((DtbDocr) row).getVentilazione(); + addCastellettoIva("S".equals(flagIvaInclusa)?impRigaIva:importoRiga, codAliq, ventilazione, lhm_castelletto); } /************************** @@ -698,7 +646,7 @@ public class DocOrdCalTotaliRules extends QueryRules { !(((DtbDoct) testata).getGestione().equalsIgnoreCase("A") && ((DtbDoct) testata).getDtbTipi().getSegnoQtaCar() + ((DtbDoct) testata).getDtbTipi().getSegnoQtaScar() == 0 && ((DtbDoct) testata).getDtbTipi().getSegnoValCar() + ((DtbDoct) testata).getDtbTipi().getSegnoValScar() != 0)) { - maxRigaSpesa = addSpeseArt(conn, (DtbDoct) testata, dtbDocr, lhm_castelletto, speseArt, maxRigaSpesa, whereCondExcSpese, cifreDec); + maxRigaSpesa = addSpeseArt(conn, (DtbDoct) testata, dtbDocr, speseArt, maxRigaSpesa, whereCondExcSpese, cifreDec, ((DtbDocr) row).getVentilazione()); } //Assegna dati bolla su righe nuove @@ -759,7 +707,7 @@ public class DocOrdCalTotaliRules extends QueryRules { /* CALCOLO DELLE SPESE */ - BigDecimal totSpese = BigDecimal.ZERO; + BigDecimal totSpese; List spese = null; if (testata instanceof DtbOrdt) { spese = ((DtbOrdt) testata).getDtbOrds(); @@ -772,7 +720,18 @@ public class DocOrdCalTotaliRules extends QueryRules { spese = ((DtbDoct) testata).getDtbDocs(); } - totSpese = calcTotSpese(conn, lhm_castelletto, spese, true, flagIvaInclusa, cifreDec); + Boolean ventilazione = false; + if ( testata instanceof DtbDoct) { + String sql = + Query.format( + "SELECT CAST(COUNT(*) AS BIT)\n" + + "FROM mtb_depo\n" + + "WHERE %s BETWEEN ISNULL(data_iniz_vent, %s) AND ISNULL(data_fine_vent, CAST(GETDATE() AS DATE))\n" + + " AND mtb_depo.cod_mdep = %s\n", + ((DtbDoct) testata).getDataReg(), ((DtbDoct) testata).getDataReg(), testata.getCodMdep()); + ventilazione = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql); + } + totSpese = calcTotSpese(conn, lhm_castelletto, spese, true, flagIvaInclusa, ventilazione); /****************************************** ASSEGNAZIONE NUM_COLLI e PESO A DOCUMENTO @@ -780,7 +739,7 @@ public class DocOrdCalTotaliRules extends QueryRules { setNumColliPeso(testata, calcColli, datiTrasp, colli, colliFromDB); //CALCOLO TOTALI E CASTELLETTO IVA - calcTotImponib(testata, conn, flagIvaInclusa, lhm_castelletto, castellettoIva, cifreDec, ventilazioneIva); + calcTotImponib(testata, conn, flagIvaInclusa, lhm_castelletto, castellettoIva, cifreDec); //Prima di calcolare l'acconto estrerre l'elenco delle bolle agganciate alla fatture differita if (testata instanceof DtbDoct && ((DtbDoct) testata).getDtbTipi().getTipoEmissioneEnum() == TipoEmissione.DIFFERITA) { @@ -801,9 +760,9 @@ public class DocOrdCalTotaliRules extends QueryRules { CALCOLO SPESE DIPENDENTI DAL TOTALE DOCUMNETO */ if (testata instanceof DtbDoct && calcScpese) { - List speseDoc = addSpese(conn, ((DtbDoct) testata), lhm_castelletto, castellettoIva, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazioneIva); + List speseDoc = addSpese(conn, ((DtbDoct) testata), lhm_castelletto, castellettoIva, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazione); ((DtbDoct) testata).getDtbDocs().addAll(speseDoc); - BigDecimal totSpeseCalc = calcTotSpese(conn, lhm_castelletto, speseDoc, false, flagIvaInclusa, cifreDec); + BigDecimal totSpeseCalc = calcTotSpese(conn, lhm_castelletto, speseDoc, false, flagIvaInclusa, ventilazione); totSpese = totSpese.add(totSpeseCalc); } @@ -848,9 +807,11 @@ public class DocOrdCalTotaliRules extends QueryRules { } private static BigDecimal calcTotSpese(Connection conn, - HashMap lhm_castelletto, - List spese, boolean addCastelletto, String flagIvaInclusa, - Integer cifreDec) throws Exception { + List lhm_castelletto, + List spese, + boolean addCastelletto, + String flagIvaInclusa, + boolean ventilazione) throws Exception { BigDecimal importoRiga; BigDecimal totSpese = BigDecimal.ZERO; String codAliq; @@ -868,7 +829,7 @@ public class DocOrdCalTotaliRules extends QueryRules { } totSpese = totSpese.add(importoRiga); if (addCastelletto) { - addCastellettoIva(importoRiga, codAliq, lhm_castelletto); + addCastellettoIva(importoRiga, codAliq, ventilazione, lhm_castelletto); } } } @@ -876,8 +837,9 @@ public class DocOrdCalTotaliRules extends QueryRules { return totSpese; } - private static void calcTotImponib(DtbDocOrdT testata, Connection conn, String flagIvaInclusa, HashMap lhm_castelletto, - List castellettoIva, Integer cifreDec, boolean ventilazioneIva) throws Exception { + private static void calcTotImponib(DtbDocOrdT testata, Connection conn, String flagIvaInclusa, + List lhm_castelletto, + List castellettoIva, Integer cifreDec) throws Exception { BigDecimal totImponib = BigDecimal.ZERO; BigDecimal totImposta = BigDecimal.ZERO; castellettoIva.clear(); @@ -888,10 +850,11 @@ public class DocOrdCalTotaliRules extends QueryRules { castellettoIva.add(iva); } } else { - for (Entry entry : lhm_castelletto.entrySet()) { - String codAliq = entry.getKey(); - BigDecimal totImponibAliq = entry.getValue(); - BigDecimal totImpostaAliq = BigDecimal.ZERO; + for (CtbMovi entry : lhm_castelletto) { + String codAliq = entry.getCodAliq(); + BigDecimal totImponibAliq = entry.getImponibile(); + Boolean ventilazioneIva = entry.getVentilazione(); + BigDecimal totImpostaAliq; if (!UtilityString.isNullOrEmpty(codAliq)) { String sql = "SELECT tipo_iva, flag_marca_da_bollo, perc_aliq, flag_iva_acq_merci FROM gtb_aliq WHERE cod_aliq = " + UtilityDB.valueToString(codAliq); HashMap dati = UtilityDB.executeSimpleQueryOnlyFirstRow(conn, sql); @@ -933,15 +896,20 @@ public class DocOrdCalTotaliRules extends QueryRules { testata.setTotImponib(totImponib).setTotIva(totImposta); } - private static void addCastellettoIva(BigDecimal importoRiga, String codAliq, HashMap lhm_castelletto) { - BigDecimal totImponib; - if (lhm_castelletto.containsKey(codAliq)) { - totImponib = lhm_castelletto.get(codAliq); - totImponib = totImponib.add(importoRiga); + private static void addCastellettoIva(BigDecimal importoRiga, String codAliq, Boolean ventilazione, List lhm_castelletto) { + java.util.Optional first = lhm_castelletto.stream().filter(x -> x.getCodAliq().equalsIgnoreCase(codAliq) && x.getVentilazione() == ventilazione).findFirst(); + CtbMovi ctbMovi; + if (first.isPresent()) { + ctbMovi = first.get(); + lhm_castelletto.remove(ctbMovi); + ctbMovi.setImponibile(ctbMovi.getImponibile().add(importoRiga)); } else { - totImponib = importoRiga; + ctbMovi = new CtbMovi() + .setCodAliq(codAliq) + .setVentilazione(ventilazione) + .setImponibile(importoRiga); } - lhm_castelletto.put(codAliq, totImponib); + lhm_castelletto.add(ctbMovi); } public static BigDecimal calcImposta(Connection conn, BigDecimal totImponib, BigDecimal percAliq, String tipoIva, Integer cifreDec) @@ -1196,12 +1164,11 @@ public class DocOrdCalTotaliRules extends QueryRules { } private static Integer addSpeseArt(Connection conn, DtbDoct testata, DtbDocr row, - HashMap lhm_castelletto, List speseArt, + List speseArt, Integer maxRigaSpesa, String whereCondExcSpese, - Integer cifreDec) throws Exception { + Integer cifreDec, Boolean ventilazione) throws Exception { - BigDecimal costoKg = BigDecimal.ZERO, percEsenzione = BigDecimal.ZERO; - String codConaiEsenzione = null, descrizioneEsenzione = null; + BigDecimal costoKg; if (((testata.getVtbClie() != null && testata.getVtbClie().getFlagSpeseArt().equalsIgnoreCase("S")) || !testata.getGestione().equalsIgnoreCase("V")) && @@ -1303,15 +1270,15 @@ public class DocOrdCalTotaliRules extends QueryRules { importo = importo.add(importoOld); qtaSpesa = qtaSpesa.add(qtaSpesaOld); - maxRigaSpesa = setDtbDocs(testata, null, spesa, qtaSpesa, importo, speseArt, maxRigaSpesa); + maxRigaSpesa = setDtbDocs(testata, null, spesa, qtaSpesa, importo, speseArt, maxRigaSpesa, ventilazione); } } return maxRigaSpesa; } - private static List addSpese(Connection connection, DtbDoct testata, HashMap lhm_castelletto, + private static List addSpese(Connection connection, DtbDoct testata, List lhm_castelletto, List castellettoIva, Integer maxRigaSpesa, - String whereCondExcSpese, Integer cifreDec, boolean ventilazioneIva) throws Exception { + String whereCondExcSpese, Integer cifreDec, Boolean ventilazione) throws Exception { List speseCalc = new ArrayList<>(); String flagSpese = "", costoEsenzione = "", flagAddBollo = ""; @@ -1327,8 +1294,8 @@ public class DocOrdCalTotaliRules extends QueryRules { !UtilityBigDecimal.isNullOrZero(testata.getTotImponib().add(testata.getTotIva()).subtract(testata.getAcconto())) && (!UtilityString.isNullOrEmpty(testata.getCodPaga()) || !UtilityString.isNullOrEmpty(costoEsenzione) || !UtilityString.isNullOrEmpty(testata.getCodVvet()))) { - maxRigaSpesa = addAltreSpese(connection, testata, lhm_castelletto, castellettoIva, speseCalc, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazioneIva); - calcTotImponib(testata, connection, testata.getFlagPrzIva(), lhm_castelletto, castellettoIva, cifreDec, ventilazioneIva); + maxRigaSpesa = addAltreSpese(connection, testata, lhm_castelletto, castellettoIva, speseCalc, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazione); + calcTotImponib(testata, connection, testata.getFlagPrzIva(), lhm_castelletto, castellettoIva, cifreDec); } //Imposta di bollo @@ -1345,8 +1312,8 @@ public class DocOrdCalTotaliRules extends QueryRules { totDoc = totDoc.add(iva.getImponibile().add(iva.getImposta())); } if (totDoc.compareTo(BigDecimal.ZERO) != 0) { - addImpostaBollo(connection, testata, lhm_castelletto, speseCalc, maxRigaSpesa, whereCondExcSpese, totDoc); - calcTotImponib(testata, connection, testata.getFlagPrzIva(), lhm_castelletto, castellettoIva, cifreDec, ventilazioneIva); + addImpostaBollo(connection, testata, lhm_castelletto, speseCalc, maxRigaSpesa, whereCondExcSpese, totDoc, ventilazione); + calcTotImponib(testata, connection, testata.getFlagPrzIva(), lhm_castelletto, castellettoIva, cifreDec); } } } @@ -1371,8 +1338,10 @@ public class DocOrdCalTotaliRules extends QueryRules { return calcScpese; } - private static Integer setDtbDocs(DtbDoct testata, HashMap lhm_castelletto, GtbSpes gtbSpes, BigDecimal qta, BigDecimal importo, - List speseCalc, Integer maxRigaSpesa) throws Exception { + private static Integer setDtbDocs(DtbDoct testata, List lhm_castelletto, + GtbSpes gtbSpes, BigDecimal qta, BigDecimal importo, + List speseCalc, Integer maxRigaSpesa, + Boolean ventilazione) throws Exception { maxRigaSpesa++; DtbDocs dtbDocs = new DtbDocs(); dtbDocs.setEntityHolder(testata.getEntityHolder()); @@ -1399,7 +1368,7 @@ public class DocOrdCalTotaliRules extends QueryRules { dtbDocs.setRiga(maxRigaSpesa); dtbDocs.setOperation(OperationType.INSERT); if (lhm_castelletto != null) { - addCastellettoIva(dtbDocs.getImporto(), dtbDocs.getCodAliq(), lhm_castelletto); + addCastellettoIva(dtbDocs.getImporto(), dtbDocs.getCodAliq(), ventilazione, lhm_castelletto); } speseCalc.add(dtbDocs); @@ -1409,23 +1378,23 @@ public class DocOrdCalTotaliRules extends QueryRules { if (spesaDoc != null) { speseCalc.remove(spesaDoc); } - GtbSpes gtbSpesEzenConai = new GtbSpes(); - gtbSpesEzenConai.setCodSpes(gtbSpes.getCodConaiEsente()); - gtbSpesEzenConai.setDescrizione(UtilityString.left(UtilityString.BigDecimalToString(gtbSpes.getPercEsenzione(), "##0.00") + "% " + gtbSpes.getDescrizioneEsenzione(), 40)); - gtbSpesEzenConai.setUntMis(gtbSpes.getUntMis()); - gtbSpesEzenConai.setCodAliq(gtbSpes.getCodAliqEsenzione()); - gtbSpesEzenConai.setTipoCalcolo("CONAI"); + GtbSpes gtbSpesEzenConai = new GtbSpes() + .setCodSpes(gtbSpes.getCodConaiEsente()) + .setDescrizione(UtilityString.left(UtilityString.BigDecimalToString(gtbSpes.getPercEsenzione(), "##0.00") + "% " + gtbSpes.getDescrizioneEsenzione(), 40)) + .setUntMis(gtbSpes.getUntMis()) + .setCodAliq(gtbSpes.getCodAliqEsenzione()) + .setTipoCalcolo("CONAI"); BigDecimal qtaEzenConai = qta.multiply(gtbSpes.getPercEsenzione().divide(new BigDecimal(100))).multiply(new BigDecimal(-1)).setScale(EmsRestConstants.cifreDecMax, RoundingMode.HALF_UP); BigDecimal importoEsenConai = importo.multiply(gtbSpes.getPercEsenzione().divide(new BigDecimal(100))).multiply(new BigDecimal(-1)).setScale(EmsRestConstants.cifreDecMax, RoundingMode.HALF_UP); gtbSpesEzenConai.setImporto(importoEsenConai.divide(qtaEzenConai, EmsRestConstants.cifreDecMax, RoundingMode.HALF_UP)); - maxRigaSpesa = setDtbDocs(testata, null, gtbSpesEzenConai, qtaEzenConai, importoEsenConai, speseCalc, maxRigaSpesa); + maxRigaSpesa = setDtbDocs(testata, null, gtbSpesEzenConai, qtaEzenConai, importoEsenConai, speseCalc, maxRigaSpesa, ventilazione); } return maxRigaSpesa; } - private static Integer addImpostaBollo(Connection connection, DtbDoct testata, HashMap lhm_castelletto, List speseCalc, - Integer maxRigaSpesa, String whereCondExcSpese, BigDecimal totDoc) throws Exception { + private static Integer addImpostaBollo(Connection connection, DtbDoct testata, List lhm_castelletto, List speseCalc, + Integer maxRigaSpesa, String whereCondExcSpese, BigDecimal totDoc, Boolean ventilazione) throws Exception { final String tipoCalcolo = "BOLLO"; String impMinDoc = setupGest.getSetup(connection, "EXPORT_DOCUMENTI VENDITA", "FATTURE_FPR", "DATI_BOLLO_IMP_MIN"); @@ -1443,7 +1412,8 @@ public class DocOrdCalTotaliRules extends QueryRules { GtbSpes gtbSpes = new ResultSetMapper().mapQueryToObject(connection, sql, GtbSpes.class, OperationType.INSERT); if (gtbSpes != null) { - maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, gtbSpes, BigDecimal.ZERO, gtbSpes.getImporto(), speseCalc, maxRigaSpesa); + maxRigaSpesa = setDtbDocs(testata, + lhm_castelletto, gtbSpes, BigDecimal.ZERO, gtbSpes.getImporto(), speseCalc, maxRigaSpesa, ventilazione); } } @@ -1451,10 +1421,10 @@ public class DocOrdCalTotaliRules extends QueryRules { return maxRigaSpesa; } - private static Integer addAltreSpese(Connection connection, DtbDoct testata, HashMap lhm_castelletto, + private static Integer addAltreSpese(Connection connection, DtbDoct testata, List lhm_castelletto, List castellettoIva, List speseCalc, Integer maxRigaSpesa, String whereCondExcSpese, - Integer cifreDec, boolean ventilazioneIva) throws Exception { + Integer cifreDec, Boolean ventilazione) throws Exception { String costoEsenzione = null; if (testata.getVtbClie() != null) { costoEsenzione = testata.getVtbClie().getCostoEsenzione(); @@ -1513,12 +1483,13 @@ public class DocOrdCalTotaliRules extends QueryRules { importo = importo.multiply(numRate).setScale(EmsRestConstants.cifreDecMax); } - if (testata.getGestione().equalsIgnoreCase("V") && spesa.getFlagRipartisci().equalsIgnoreCase("S")) { + if (testata.getGestione().equalsIgnoreCase("V") && + spesa.getFlagRipartisci().equalsIgnoreCase("S")) { BigDecimal totSpese = BigDecimal.ZERO; BigDecimal importoTot = spesa.getImporto(); Integer i = 1; - for (Entry entry : lhm_castelletto.entrySet()) { - BigDecimal imponib = entry.getValue(); + for (CtbMovi entry : lhm_castelletto) { + BigDecimal imponib = entry.getImponibile(); if (i == lhm_castelletto.size()) { importo = importoTot.subtract(totSpese); @@ -1528,14 +1499,14 @@ public class DocOrdCalTotaliRules extends QueryRules { } totSpese = totSpese.add(importo); i++; - spesa.setCodAliq(entry.getKey()); - maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa); + spesa.setCodAliq(entry.getCodAliq()); + maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa, ventilazione); } } else { - maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa); + maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa, ventilazione); } } - calcTotImponib(testata, connection, testata.getFlagPrzIva(), lhm_castelletto, castellettoIva, cifreDec, ventilazioneIva); + calcTotImponib(testata, connection, testata.getFlagPrzIva(), lhm_castelletto, castellettoIva, cifreDec); } /* calcolo spese sul totale del documento @@ -1563,7 +1534,7 @@ public class DocOrdCalTotaliRules extends QueryRules { importo = importo.setScale(0, RoundingMode.CEILING); importo = importo.multiply(arrotonda); importo = importo.multiply(numRate); - maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa); + maxRigaSpesa = setDtbDocs(testata, lhm_castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa, ventilazione); } return maxRigaSpesa; diff --git a/ems-core/src/main/java/it/integry/ems/rules/completing/DocumentRules.java b/ems-core/src/main/java/it/integry/ems/rules/completing/DocumentRules.java index cc2161f628..6c98995913 100644 --- a/ems-core/src/main/java/it/integry/ems/rules/completing/DocumentRules.java +++ b/ems-core/src/main/java/it/integry/ems/rules/completing/DocumentRules.java @@ -286,9 +286,11 @@ public class DocumentRules extends QueryRules { return codCcon; } - public static boolean chkDocAP(Connection conn, DtbDocr dtbDocr) throws Exception { + public static HashMap checkDatiContab(Connection conn, DtbDocr dtbDocr) throws Exception { + boolean isDocAp = false; Date dataReg = dtbDocr.getDataDoc(); + String codMdep = UtilityString.isNull(dtbDocr.getCodMdep(), ((DtbDoct) dtbDocr.getParent()).getCodMdep()); if (dtbDocr.getTipoEmissione().equalsIgnoreCase(String.valueOf(TipoEmissione.DIFFERITA)) && dtbDocr.getDataDocBolla() != null && dtbDocr.getCodDtipBolla() != null && @@ -319,7 +321,20 @@ public class DocumentRules extends QueryRules { isDocAp = true; } - return isDocAp; + sql = + Query.format( + "SELECT CAST(COUNT(*) AS BIT)\n" + + "FROM mtb_depo\n" + + "WHERE %s BETWEEN ISNULL(data_iniz_vent, %s) AND ISNULL(data_fine_vent, CAST(GETDATE() AS DATE))\n" + + " AND mtb_depo.cod_mdep = %s\n", + dataReg,dataReg, codMdep); + Boolean ventilazione = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql); + + HashMap dati = new HashMap<>(); + dati.put("doc_ap", isDocAp); + dati.put("ventilazione", ventilazione); + + return dati; } diff --git a/ems-core/src/main/java/it/integry/ems_model/entity/DtbDocr.java b/ems-core/src/main/java/it/integry/ems_model/entity/DtbDocr.java index 9eba4f2db5..6ede932ec3 100644 --- a/ems-core/src/main/java/it/integry/ems_model/entity/DtbDocr.java +++ b/ems-core/src/main/java/it/integry/ems_model/entity/DtbDocr.java @@ -367,6 +367,7 @@ public class DtbDocr extends DtbBaseDocR implements EquatableEntityInterface dati = DocumentRules.checkDatiContab(conn, $docR); modify($docR){ - setDocAp(docAp) + setDocAp(dati.get("doc_ap")), + setVentilazione(dati.get("ventilazione")) } end