modifiche per ventilazione iva
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -416,30 +416,6 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
return rowsToSave;
|
||||
}
|
||||
|
||||
// public static void explodeKit(Connection conn, DtbDocOrdT testata) throws Exception {
|
||||
// List<? extends DtbDocOrdR> righe = testata.getRows();
|
||||
// List<? extends DtbDocOrdR> righeComp = new ArrayList<>();
|
||||
// String explodeKit = testata.getExplodeKit();
|
||||
//
|
||||
// if (explodeKit.equalsIgnoreCase("S")) {
|
||||
// List<? extends DtbDocOrdR> 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<? extends DtbDocOrdR> 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<? extends DtbDocOrdR> 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<BigDecimal> sconti = new ArrayList<>();
|
||||
List<? extends DtbDocOrdR> righe = null;
|
||||
@@ -485,7 +460,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
testata.setOperation(OperationType.UPDATE);
|
||||
}
|
||||
|
||||
HashMap<String, BigDecimal> lhm_castelletto = new HashMap<>();
|
||||
List<CtbMovi> 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<? extends EntityBase> 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<DtbDocs> speseDoc = addSpese(conn, ((DtbDoct) testata), lhm_castelletto, castellettoIva, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazioneIva);
|
||||
List<DtbDocs> 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<String, BigDecimal> lhm_castelletto,
|
||||
List<? extends EntityBase> spese, boolean addCastelletto, String flagIvaInclusa,
|
||||
Integer cifreDec) throws Exception {
|
||||
List<CtbMovi> lhm_castelletto,
|
||||
List<? extends EntityBase> 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<String, BigDecimal> lhm_castelletto,
|
||||
List<CtbMovi> castellettoIva, Integer cifreDec, boolean ventilazioneIva) throws Exception {
|
||||
private static void calcTotImponib(DtbDocOrdT testata, Connection conn, String flagIvaInclusa,
|
||||
List<CtbMovi> lhm_castelletto,
|
||||
List<CtbMovi> 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<String, BigDecimal> 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<String, Object> 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<String, BigDecimal> 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<CtbMovi> lhm_castelletto) {
|
||||
java.util.Optional<CtbMovi> 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<String, BigDecimal> lhm_castelletto, List<DtbDocs> speseArt,
|
||||
List<DtbDocs> 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<DtbDocs> addSpese(Connection connection, DtbDoct testata, HashMap<String, BigDecimal> lhm_castelletto,
|
||||
private static List<DtbDocs> addSpese(Connection connection, DtbDoct testata, List<CtbMovi> lhm_castelletto,
|
||||
List<CtbMovi> castellettoIva, Integer maxRigaSpesa,
|
||||
String whereCondExcSpese, Integer cifreDec, boolean ventilazioneIva) throws Exception {
|
||||
String whereCondExcSpese, Integer cifreDec, Boolean ventilazione) throws Exception {
|
||||
List<DtbDocs> 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<String, BigDecimal> lhm_castelletto, GtbSpes gtbSpes, BigDecimal qta, BigDecimal importo,
|
||||
List<DtbDocs> speseCalc, Integer maxRigaSpesa) throws Exception {
|
||||
private static Integer setDtbDocs(DtbDoct testata, List<CtbMovi> lhm_castelletto,
|
||||
GtbSpes gtbSpes, BigDecimal qta, BigDecimal importo,
|
||||
List<DtbDocs> 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<String, BigDecimal> lhm_castelletto, List<DtbDocs> speseCalc,
|
||||
Integer maxRigaSpesa, String whereCondExcSpese, BigDecimal totDoc) throws Exception {
|
||||
private static Integer addImpostaBollo(Connection connection, DtbDoct testata, List<CtbMovi> lhm_castelletto, List<DtbDocs> 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<String, BigDecimal> lhm_castelletto,
|
||||
private static Integer addAltreSpese(Connection connection, DtbDoct testata, List<CtbMovi> lhm_castelletto,
|
||||
List<CtbMovi> castellettoIva, List<DtbDocs> 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<String, BigDecimal> 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;
|
||||
|
||||
@@ -286,9 +286,11 @@ public class DocumentRules extends QueryRules {
|
||||
return codCcon;
|
||||
}
|
||||
|
||||
public static boolean chkDocAP(Connection conn, DtbDocr dtbDocr) throws Exception {
|
||||
public static HashMap<String, Boolean> 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<String, Boolean> dati = new HashMap<>();
|
||||
dati.put("doc_ap", isDocAp);
|
||||
dati.put("ventilazione", ventilazione);
|
||||
|
||||
return dati;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -367,6 +367,7 @@ public class DtbDocr extends DtbBaseDocR implements EquatableEntityInterface<Dtb
|
||||
private Integer idRigaBolla;
|
||||
|
||||
private Boolean docAp;
|
||||
private Boolean ventilazione;
|
||||
|
||||
@MapToTable(value = "data_ins_testata")
|
||||
private Date dataInsTestata;
|
||||
@@ -1398,6 +1399,15 @@ public class DtbDocr extends DtbBaseDocR implements EquatableEntityInterface<Dtb
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getVentilazione() {
|
||||
return ventilazione;
|
||||
}
|
||||
|
||||
public DtbDocr setVentilazione(Boolean ventilazione) {
|
||||
this.ventilazione = ventilazione;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataInsTestata() {
|
||||
return dataInsTestata;
|
||||
}
|
||||
|
||||
@@ -114,160 +114,180 @@ public class GtbSpes extends EntityBase {
|
||||
return codSpes;
|
||||
}
|
||||
|
||||
public void setCodSpes(String codSpes) {
|
||||
public GtbSpes setCodSpes(String codSpes) {
|
||||
this.codSpes = codSpes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return descrizione;
|
||||
}
|
||||
|
||||
public void setDescrizione(String descrizione) {
|
||||
public GtbSpes setDescrizione(String descrizione) {
|
||||
this.descrizione = descrizione;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodAliq() {
|
||||
return codAliq;
|
||||
}
|
||||
|
||||
public void setCodAliq(String codAliq) {
|
||||
public GtbSpes setCodAliq(String codAliq) {
|
||||
this.codAliq = codAliq;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTipoCalcolo() {
|
||||
return tipoCalcolo;
|
||||
}
|
||||
|
||||
public void setTipoCalcolo(String tipoCalcolo) {
|
||||
public GtbSpes setTipoCalcolo(String tipoCalcolo) {
|
||||
this.tipoCalcolo = tipoCalcolo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getImporto() {
|
||||
return importo;
|
||||
}
|
||||
|
||||
public void setImporto(BigDecimal importo) {
|
||||
public GtbSpes setImporto(BigDecimal importo) {
|
||||
this.importo = importo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getArrotonda() {
|
||||
return arrotonda;
|
||||
}
|
||||
|
||||
public void setArrotonda(BigDecimal arrotonda) {
|
||||
public GtbSpes setArrotonda(BigDecimal arrotonda) {
|
||||
this.arrotonda = arrotonda;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodCconCos() {
|
||||
return codCconCos;
|
||||
}
|
||||
|
||||
public void setCodCconCos(String codCconCos) {
|
||||
public GtbSpes setCodCconCos(String codCconCos) {
|
||||
this.codCconCos = codCconCos;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodCconRic() {
|
||||
return codCconRic;
|
||||
}
|
||||
|
||||
public void setCodCconRic(String codCconRic) {
|
||||
public GtbSpes setCodCconRic(String codCconRic) {
|
||||
this.codCconRic = codCconRic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getValUnt() {
|
||||
return valUnt;
|
||||
}
|
||||
|
||||
public void setValUnt(BigDecimal valUnt) {
|
||||
public GtbSpes setValUnt(BigDecimal valUnt) {
|
||||
this.valUnt = valUnt;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUntMis() {
|
||||
return untMis;
|
||||
}
|
||||
|
||||
public void setUntMis(String untMis) {
|
||||
public GtbSpes setUntMis(String untMis) {
|
||||
this.untMis = untMis;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodDiviCont() {
|
||||
return codDiviCont;
|
||||
}
|
||||
|
||||
public void setCodDiviCont(String codDiviCont) {
|
||||
public GtbSpes setCodDiviCont(String codDiviCont) {
|
||||
this.codDiviCont = codDiviCont;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getCambioDiviCont() {
|
||||
return cambioDiviCont;
|
||||
}
|
||||
|
||||
public void setCambioDiviCont(BigDecimal cambioDiviCont) {
|
||||
public GtbSpes setCambioDiviCont(BigDecimal cambioDiviCont) {
|
||||
this.cambioDiviCont = cambioDiviCont;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFlagSpesIntra() {
|
||||
return flagSpesIntra;
|
||||
}
|
||||
|
||||
public void setFlagSpesIntra(String flagSpesIntra) {
|
||||
public GtbSpes setFlagSpesIntra(String flagSpesIntra) {
|
||||
this.flagSpesIntra = flagSpesIntra;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFlagRipartisci() {
|
||||
return flagRipartisci;
|
||||
}
|
||||
|
||||
public void setFlagRipartisci(String flagRipartisci) {
|
||||
public GtbSpes setFlagRipartisci(String flagRipartisci) {
|
||||
this.flagRipartisci = flagRipartisci;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getNumRate() {
|
||||
return numRate;
|
||||
}
|
||||
|
||||
public void setNumRate(Integer numRate) {
|
||||
public GtbSpes setNumRate(Integer numRate) {
|
||||
this.numRate = numRate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getSpesaSuPagamento() {
|
||||
return spesaSuPagamento;
|
||||
}
|
||||
|
||||
public void setSpesaSuPagamento(Boolean spesaSuPagamento) {
|
||||
public GtbSpes setSpesaSuPagamento(Boolean spesaSuPagamento) {
|
||||
this.spesaSuPagamento = spesaSuPagamento;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTipoUm() {
|
||||
return tipoUm;
|
||||
}
|
||||
|
||||
public void setTipoUm(String tipoUm) {
|
||||
public GtbSpes setTipoUm(String tipoUm) {
|
||||
this.tipoUm = tipoUm;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFlagUnitaKg() {
|
||||
return flagUnitaKg;
|
||||
}
|
||||
|
||||
public void setFlagUnitaKg(String flagUnitaKg) {
|
||||
public GtbSpes setFlagUnitaKg(String flagUnitaKg) {
|
||||
this.flagUnitaKg = flagUnitaKg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getPesoKg() {
|
||||
return pesoKg;
|
||||
}
|
||||
|
||||
public void setPesoKg(BigDecimal pesoKg) {
|
||||
public GtbSpes setPesoKg(BigDecimal pesoKg) {
|
||||
this.pesoKg = pesoKg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getQtaSpes() {
|
||||
return qtaSpes;
|
||||
}
|
||||
|
||||
public void setQtaSpes(BigDecimal qtaSpes) {
|
||||
public GtbSpes setQtaSpes(BigDecimal qtaSpes) {
|
||||
this.qtaSpes = qtaSpes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodConaiEsente() {
|
||||
@@ -328,7 +348,8 @@ public class GtbSpes extends EntityBase {
|
||||
return flagRipartisciIntra;
|
||||
}
|
||||
|
||||
public void setFlagRipartisciIntra(Boolean flagRipartisciIntra) {
|
||||
public GtbSpes setFlagRipartisciIntra(Boolean flagRipartisciIntra) {
|
||||
this.flagRipartisciIntra = flagRipartisciIntra;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,6 +610,17 @@ then
|
||||
modify ( $testata ) { setCambioDiviCont(cambio) }
|
||||
end
|
||||
|
||||
|
||||
rule "completeVentilazioneCtbMovi"
|
||||
no-loop
|
||||
when
|
||||
eval(completeRulesEnabled)
|
||||
$ctbMovi : CtbMovi(ventilazione == null)
|
||||
then
|
||||
Boolean ventilazione = AccountingRules.completeVentilazione(conn, $ctbMovi);
|
||||
modify ( $ctbMovi ) { setVentilazione(ventilazione) }
|
||||
end
|
||||
|
||||
rule "completeDatiReverseCharge"
|
||||
no-loop
|
||||
when
|
||||
|
||||
@@ -483,11 +483,12 @@ end
|
||||
rule "completeCostoAP"
|
||||
when
|
||||
eval(completeRulesEnabled)
|
||||
$docR : DtbDocr( docAp == null && tipoEmissione != null)
|
||||
$docR : DtbDocr( ( docAp == null || ventilazione == null ) && tipoEmissione != null)
|
||||
then
|
||||
Boolean docAp = DocumentRules.chkDocAP(conn, $docR);
|
||||
HashMap<String, Boolean> dati = DocumentRules.checkDatiContab(conn, $docR);
|
||||
modify($docR){
|
||||
setDocAp(docAp)
|
||||
setDocAp(dati.get("doc_ap")),
|
||||
setVentilazione(dati.get("ventilazione"))
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user