gestioen fatturazione pedane
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:
@@ -17,7 +17,7 @@ public class Migration_20241211132016 extends BaseMigration implements Migration
|
||||
false, false, false, null, false, "SELECT ACTIVITY_TYPE_ID FROM STB_ACTIVITY_TYPE WHERE FLAG_TIPOLOGIA = 'A' AND FLAG_ATTIVA = 'S'");
|
||||
|
||||
if ( isCustomer(IntegryCustomer.RossoGargano)) {
|
||||
executeStatement("INSERT INTO stb_activity_type (activity_type_id, flag_tipologia) VALUES ('FATTURA_PEDANE', 'A')");
|
||||
executeStatement("INSERT INTO stb_activity_type (activity_type_id, flag_tipologia, flag_attiva) VALUES ('FATTURA_PEDANE', 'A', 'S')");
|
||||
updateSetupValue("DTB_DOCT", "FATTURA_PEDANE", "TIPO_ATTIVITA", "FATTURA_PEDANE");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241220111416 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("UPDATE stb_menu set descrizione = 'Documenti di Vendita' WHERE cod_opz = 'VG106' AND tipo_azienda = 'PRODUZIONE ALIMENTARE'",
|
||||
"UPDATE stb_menu set descrizione = 'Documenti di Vendita ( OLD )' WHERE cod_opz = 'VG011' AND tipo_azienda = 'PRODUZIONE ALIMENTARE'"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20241220155630 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
deleteSetup("DTB_DOCT", "FATTURA_PEDANE", "TIPO_DOC");
|
||||
createSetupQuery("COD_DTIP_V", "COD_DTIP_V", "SELECT COD_DTIP + '|' + COD_DTIP + ' - ' + DESCRIZIONE FROM DTB_TIPI WHERE GESTIONE = 'V' AND TIPO_EMISSIONE = 'DIRETTA' ORDER BY 1");
|
||||
createSetup("DTB_DOCT", "FATTURA_PEDANE", "TIPO_DOC_RESI", null,
|
||||
"Tipo documento da utilizzare fatturare le pedane rientrate dal cliente o vettore", false, "COD_DTIP_V", false, false,
|
||||
false, false, false, null, false, "SELECT COD_DTIP + '|' + COD_DTIP + ' - ' + DESCRIZIONE FROM DTB_TIPI WHERE GESTIONE = 'V' AND TIPO_EMISSIONE = 'DIRETTA' ORDER BY 1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -439,7 +439,6 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
}
|
||||
|
||||
public static void calcTotali(Connection conn, DtbDocOrdT testata) throws Exception {
|
||||
String flagIvaInclusa = "N";
|
||||
List<BigDecimal> sconti = new ArrayList<>();
|
||||
List<? extends DtbDocOrdR> righe = null;
|
||||
List<MtbColt> colliFromDB = new ArrayList<>();
|
||||
@@ -463,7 +462,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
|
||||
String gestione = testata.getGestione();
|
||||
String codDivi = testata.getCodDivi();
|
||||
String flagPrezziScontati = testata.getFlagPrzScontati();
|
||||
boolean flagPrezziScontati = testata.getFlagPrzScontati().equalsIgnoreCase("S");
|
||||
BigDecimal sconto1 = testata.getSconto1();
|
||||
BigDecimal sconto2 = testata.getSconto2();
|
||||
BigDecimal sconto3 = testata.getSconto3();
|
||||
@@ -478,17 +477,14 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
boolean flagSpeseArt = false, isOrdine = false;
|
||||
if (testata instanceof DtbOrdt) {
|
||||
righe = ((DtbOrdt) testata).getDtbOrdr();
|
||||
flagIvaInclusa = ((DtbOrdt) testata).getFlagPrzIva();
|
||||
isOrdine = true;
|
||||
} else if (testata instanceof WdtbOrdt) {
|
||||
righe = ((WdtbOrdt) testata).getWdtbOrdr();
|
||||
flagIvaInclusa = ((WdtbOrdt) testata).getFlagPrzIva();
|
||||
isOrdine = true;
|
||||
} else if (testata instanceof WdtbDoct) {
|
||||
righe = ((WdtbDoct) testata).getWdtbDocr();
|
||||
} else if (testata instanceof DtbDoct) {
|
||||
righe = ((DtbDoct) testata).getDtbDocr();
|
||||
flagIvaInclusa = ((DtbDoct) testata).getFlagPrzIva();
|
||||
if ("S".equals(((DtbDoct) testata).getGeneraMovCont())) {
|
||||
insMovCont = true;
|
||||
}
|
||||
@@ -501,8 +497,9 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
flagSpeseArt = ((DtbDoct) testata).getVtbClie().getFlagSpeseArt().equalsIgnoreCase("S");
|
||||
}
|
||||
}
|
||||
boolean flagIvaInclusa = testata.getFlagPrzIva().equalsIgnoreCase("S");
|
||||
|
||||
if ("N".equals(flagPrezziScontati)) {
|
||||
if (flagPrezziScontati) {
|
||||
if (sconto1.compareTo(BigDecimal.ZERO) > 0) {
|
||||
sconti.add(sconto1);
|
||||
}
|
||||
@@ -757,7 +754,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
CALCOLO SPESE DIPENDENTI DAL TOTALE DOCUMNETO
|
||||
*/
|
||||
if (testata instanceof DtbDoct && calcScpese) {
|
||||
List<DtbDocs> speseDoc = addSpese(conn, ((DtbDoct) testata), castelletto, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazione);
|
||||
List<DtbDocs> speseDoc = addSpese(conn, ((DtbDoct) testata), castelletto, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazione, flagIvaInclusa);
|
||||
((DtbDoct) testata).getDtbDocs().addAll(speseDoc);
|
||||
BigDecimal totSpeseCalc = calcTotSpese(conn, castelletto, speseDoc, false, flagIvaInclusa, ventilazione);
|
||||
totSpese = totSpese.add(totSpeseCalc);
|
||||
@@ -807,7 +804,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
List<CtbMovi> castelletto,
|
||||
List<? extends EntityBase> spese,
|
||||
boolean addCastelletto,
|
||||
String flagIvaInclusa,
|
||||
boolean flagIvaInclusa,
|
||||
boolean ventilazione) throws Exception {
|
||||
BigDecimal importoRiga;
|
||||
BigDecimal totSpese = BigDecimal.ZERO;
|
||||
@@ -816,7 +813,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
for (EntityBase row : spese) {
|
||||
if (row.getOperation() != OperationType.DELETE) {
|
||||
codAliq = (String) DroolsUtil.getEntityFieldValue(row, "cod_aliq");
|
||||
if ("S".equalsIgnoreCase(flagIvaInclusa)) {
|
||||
if (flagIvaInclusa) {
|
||||
importoRiga = (BigDecimal) DroolsUtil.getEntityFieldValue(row, "importoIva");
|
||||
if (UtilityBigDecimal.isNullOrZero(importoRiga)) {
|
||||
importoRiga = (BigDecimal) DroolsUtil.getEntityFieldValue(row, "importo");
|
||||
@@ -834,7 +831,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
return totSpese;
|
||||
}
|
||||
|
||||
private static void calcTotImponib(DtbDocOrdT testata, Connection conn, String flagIvaInclusa,
|
||||
private static void calcTotImponib(DtbDocOrdT testata, Connection conn, boolean flagIvaInclusa,
|
||||
List<CtbMovi> castellettoIva, Integer cifreDec) throws Exception {
|
||||
BigDecimal totImponib = BigDecimal.ZERO;
|
||||
BigDecimal totImposta = BigDecimal.ZERO;
|
||||
@@ -859,7 +856,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
BigDecimal percAliq = (BigDecimal) dati.get("perc_aliq");
|
||||
boolean flagIvaAcqMerci = UtilityHashMap.<String>getValueIfExists(dati, "flag_iva_acq_merci").equalsIgnoreCase("S");
|
||||
|
||||
if ("S".equals(flagIvaInclusa)) {
|
||||
if (flagIvaInclusa) {
|
||||
BigDecimal totImpScorporo = IntegerUtility.round(CommonRules.scorporoIva(conn, totImponibAliq, codAliq), 2);
|
||||
totImpostaAliq = totImponibAliq.subtract(totImpScorporo);
|
||||
totImponibAliq = totImponibAliq.subtract(totImpostaAliq);
|
||||
@@ -1275,7 +1272,8 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
|
||||
private static List<DtbDocs> addSpese(Connection connection, DtbDoct testata, List<CtbMovi> castelletto,
|
||||
Integer maxRigaSpesa,
|
||||
String whereCondExcSpese, Integer cifreDec, Boolean ventilazione) throws Exception {
|
||||
String whereCondExcSpese, Integer cifreDec, Boolean ventilazione,
|
||||
boolean flagPrzIva) throws Exception {
|
||||
List<DtbDocs> speseCalc = new ArrayList<>();
|
||||
|
||||
String flagSpese = "", costoEsenzione = "", flagAddBollo = "";
|
||||
@@ -1291,8 +1289,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, castelletto, speseCalc, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazione);
|
||||
calcTotImponib(testata, connection, testata.getFlagPrzIva(), castelletto, cifreDec);
|
||||
maxRigaSpesa = addAltreSpese(connection, testata, castelletto, speseCalc, maxRigaSpesa, whereCondExcSpese, cifreDec, ventilazione, flagPrzIva);
|
||||
calcTotImponib(testata, connection, flagPrzIva, castelletto, cifreDec);
|
||||
}
|
||||
|
||||
//Imposta di bollo
|
||||
@@ -1310,7 +1308,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
}
|
||||
if (totDoc.compareTo(BigDecimal.ZERO) != 0) {
|
||||
addImpostaBollo(connection, testata, castelletto, speseCalc, maxRigaSpesa, whereCondExcSpese, totDoc, ventilazione);
|
||||
calcTotImponib(testata, connection, testata.getFlagPrzIva(), castelletto, cifreDec);
|
||||
calcTotImponib(testata, connection, flagPrzIva, castelletto, cifreDec);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1421,7 +1419,8 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
private static Integer addAltreSpese(Connection connection, DtbDoct testata, List<CtbMovi> castelletto,
|
||||
List<DtbDocs> speseCalc,
|
||||
Integer maxRigaSpesa, String whereCondExcSpese,
|
||||
Integer cifreDec, Boolean ventilazione) throws Exception {
|
||||
Integer cifreDec, Boolean ventilazione,
|
||||
boolean flagPrzIva) throws Exception {
|
||||
String costoEsenzione = null;
|
||||
if (testata.getVtbClie() != null) {
|
||||
costoEsenzione = testata.getVtbClie().getCostoEsenzione();
|
||||
@@ -1503,7 +1502,7 @@ public class DocOrdCalTotaliRules extends QueryRules {
|
||||
maxRigaSpesa = setDtbDocs(testata, castelletto, spesa, BigDecimal.ZERO, importo, speseCalc, maxRigaSpesa, ventilazione);
|
||||
}
|
||||
}
|
||||
calcTotImponib(testata, connection, testata.getFlagPrzIva(), castelletto, cifreDec);
|
||||
calcTotImponib(testata, connection, flagPrzIva, castelletto, cifreDec);
|
||||
}
|
||||
/*
|
||||
calcolo spese sul totale del documento
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@PropertyReactive()
|
||||
@Table(value = DtbDocImb.ENTITY)
|
||||
@@ -159,4 +160,17 @@ public class DtbDocImb extends EntityBase {
|
||||
this.tipoReso = tipoReso;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DtbDocImb)) return false;
|
||||
DtbDocImb docImb = (DtbDocImb) o;
|
||||
return Objects.equals(getId(), docImb.getId()) && Objects.equals(getCodAnag(), docImb.getCodAnag()) && Objects.equals(getCodDtip(), docImb.getCodDtip()) && Objects.equals(getDataDoc(), docImb.getDataDoc()) && Objects.equals(getSerDoc(), docImb.getSerDoc()) && Objects.equals(getNumDoc(), docImb.getNumDoc()) && Objects.equals(getCodTcol(), docImb.getCodTcol()) && Objects.equals(getNumImbCons(), docImb.getNumImbCons()) && Objects.equals(getNumImbResi(), docImb.getNumImbResi()) && Objects.equals(getTipoReso(), docImb.getTipoReso());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getId(), getCodAnag(), getCodDtip(), getDataDoc(), getSerDoc(), getNumDoc(), getCodTcol(), getNumImbCons(), getNumImbResi(), getTipoReso());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import it.integry.ems_model.entity.common.DtbDocOrdR;
|
||||
import it.integry.ems_model.rules.completing.DocumentExtEntityRules;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityHashMap;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -1292,10 +1293,12 @@ public class DtbDoct extends DtbBaseDocT implements EquatableEntityInterface<Dtb
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlagPrzIva() {
|
||||
return flagPrzIva;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DtbDoct setFlagPrzIva(String flagPrzIva) {
|
||||
this.flagPrzIva = flagPrzIva;
|
||||
return this;
|
||||
@@ -1727,15 +1730,21 @@ public class DtbDoct extends DtbBaseDocT implements EquatableEntityInterface<Dtb
|
||||
numDocOld = numDoc;
|
||||
HashMap<String, Object> oldPk = getOldPk();
|
||||
if (oldPk != null && oldPk.size() > 0) {
|
||||
|
||||
if (oldPk.containsKey("codAnag"))
|
||||
codAnagOld = (String) oldPk.get("codAnag");
|
||||
if (oldPk.containsKey("codDtip"))
|
||||
else if (oldPk.containsKey("codDtip"))
|
||||
codDtipOld = (String) oldPk.get("codDtip");
|
||||
if (oldPk.containsKey("dataDoc"))
|
||||
dataDocOld = UtilityString.parseDate((String) oldPk.get("dataDoc"));
|
||||
if (oldPk.containsKey("serDoc"))
|
||||
else if (oldPk.containsKey("dataDoc")) {
|
||||
Object value = oldPk.get("dataDoc");
|
||||
if (value instanceof String )
|
||||
dataDocOld = UtilityString.parseDate((String) oldPk.get("dataDoc"));
|
||||
else
|
||||
dataDocOld = (Date) value;
|
||||
}
|
||||
else if (oldPk.containsKey("serDoc"))
|
||||
serDocOld = (String) oldPk.get("serDoc");
|
||||
if (oldPk.containsKey("numDoc"))
|
||||
else if (oldPk.containsKey("numDoc"))
|
||||
numDocOld = (Integer) oldPk.get("numDoc");
|
||||
}
|
||||
if ("DIRETTA".equals(tipoEmissione)) {
|
||||
|
||||
@@ -1376,10 +1376,12 @@ public class DtbOrdt extends DtbDocOrdT implements EquatableEntityInterface<DtbO
|
||||
setDtbOrdr((List<DtbOrdr>) rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlagPrzIva() {
|
||||
return flagPrzIva;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DtbOrdt setFlagPrzIva(String flagPrzIva) {
|
||||
this.flagPrzIva = flagPrzIva;
|
||||
return this;
|
||||
|
||||
@@ -960,6 +960,18 @@ public class WdtbDoct extends DtbBaseDocT {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlagPrzIva() {
|
||||
return "N";
|
||||
}
|
||||
|
||||
@Override
|
||||
public DtbDocOrdT setFlagPrzIva(String flagPrzIva) {
|
||||
/*In ordini e documenti web i kit non vengono esplosi*/
|
||||
this.setFlagPrzIva("N");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WdtbDocr> getRows() {
|
||||
return getWdtbDocr();
|
||||
|
||||
@@ -984,10 +984,12 @@ public class WdtbOrdt extends DtbDocOrdT {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlagPrzIva() {
|
||||
return flagPrzIva;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WdtbOrdt setFlagPrzIva(String flagPrzIva) {
|
||||
this.flagPrzIva = flagPrzIva;
|
||||
return this;
|
||||
|
||||
@@ -117,6 +117,8 @@ public abstract class DtbDocOrdT extends EntityBase {
|
||||
public abstract DtbDocOrdT setUntMisProd( String untMisprod);
|
||||
public abstract String getExplodeKit();
|
||||
public abstract DtbDocOrdT setExplodeKit(String explodeKit);
|
||||
public abstract String getFlagPrzIva();
|
||||
public abstract DtbDocOrdT setFlagPrzIva(String flagPrzIva);
|
||||
|
||||
public abstract List<? extends DtbDocOrdR> getRows();
|
||||
public abstract void setRows(List<? extends DtbDocOrdR> rows);
|
||||
|
||||
@@ -493,21 +493,6 @@ then
|
||||
|
||||
end
|
||||
|
||||
//DATI BOLLA
|
||||
rule "completeDatiBolla"
|
||||
no-loop
|
||||
when
|
||||
eval(completeRulesEnabled)
|
||||
$docR : DtbDocr( tipoEmissione == "DIFFERITA" && codDtipBolla != null && dataDocBolla != null && serDocBolla != null && numDocBolla != null && idRigaBolla != null )
|
||||
then
|
||||
|
||||
DtbDocr rigaBolla = DocumentRules.completeDatiBolla(conn, $docR);
|
||||
modify($docR){
|
||||
setDtbDocrBolla(rigaBolla)
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
//TIPI DOCUMENTO
|
||||
rule "completeGiornaleMagDtbTipi"
|
||||
when
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DocumentiDirettiController {
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestBody DtbDoct dtbDoct) throws Exception{
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(documentiDirettiService.save(dtbDoct));
|
||||
return ServiceRestResponse.createPositiveResponse(documentiDirettiService.save(dtbDoct, true));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "update", method = RequestMethod.POST)
|
||||
@@ -33,7 +33,7 @@ public class DocumentiDirettiController {
|
||||
@RequestParam(CommonConstants.PROFILE_DB) String configuration,
|
||||
@RequestBody DtbDoct dtbDoct) throws Exception{
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(documentiDirettiService.save(dtbDoct));
|
||||
return ServiceRestResponse.createPositiveResponse(documentiDirettiService.save(dtbDoct, false));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "delete", method = RequestMethod.POST)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package it.integry.ems.document.service;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.menu.dto.StbMenuDTO;
|
||||
import it.integry.ems.rules.businessLogic.enums.TipoEmissione;
|
||||
import it.integry.ems.rules.completing.ConfigActivityRules;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
@@ -19,6 +21,7 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -36,7 +39,7 @@ public class DocumentiDirettiService {
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
|
||||
public List<EntityBase> save(DtbDoct dtbDoct) throws Exception {
|
||||
public List<EntityBase> save(DtbDoct dtbDoct, boolean isInsert) throws Exception {
|
||||
List<EntityBase> entityList = new ArrayList<>();
|
||||
entityList.add(dtbDoct);
|
||||
|
||||
@@ -53,139 +56,7 @@ public class DocumentiDirettiService {
|
||||
if (UtilityHashMap.<String>getValueIfExists(datiTipoDoc, "gestione").equalsIgnoreCase("V") &&
|
||||
TipoEmissione.valueOf(UtilityHashMap.getValueIfExists(datiTipoDoc, "tipo_emissione")) == TipoEmissione.DIRETTA &&
|
||||
!dtbDoct.getDtbDocImb().isEmpty() && dtbDoct.getDtbDocImb().stream().anyMatch(x->x.getTipoReso()!= 2)) {
|
||||
|
||||
String codAnag = dtbDoct.getCodAnag();
|
||||
String codDtip = dtbDoct.getCodDtip();
|
||||
Date dataDoc = dtbDoct.getDataDoc();
|
||||
String serDoc = dtbDoct.getSerDoc();
|
||||
Integer numDoc = dtbDoct.getNumDoc();
|
||||
Map<String, Object> oldPk = dtbDoct.getOldPk();
|
||||
if (oldPk != null && oldPk.size() > 0) {
|
||||
if (oldPk.containsKey("codAnag")) codAnag = (String) oldPk.get("codAnag");
|
||||
if (oldPk.containsKey("codDtip")) codDtip = (String) oldPk.get("codDtip");
|
||||
if (oldPk.containsKey("dataDoc")) dataDoc = UtilityString.parseDate((String) oldPk.get("dataDoc"));
|
||||
if (oldPk.containsKey("serDoc")) serDoc = (String) oldPk.get("serDoc");
|
||||
if (oldPk.containsKey("numDoc")) numDoc = (Integer) oldPk.get("numDoc");
|
||||
}
|
||||
|
||||
final String gestName = "DTB_DOCT";
|
||||
final String section = "FATTURA_PEDANE";
|
||||
final String keySectionTipoDoc = "TIPO_DOC";
|
||||
HashMap<String, String> setupSection = setupGest.getSetupSection(multiDBTransactionManager.getPrimaryConnection(), gestName, section);
|
||||
String codDtipPed = setupSection.get(keySectionTipoDoc);
|
||||
if (UtilityString.isNullOrEmpty(codDtipPed))
|
||||
throw new Exception(String.format("Tipo Documento per la creazione della fattura delle pedane non configurato %s -> %s -> %s", gestName, section, keySectionTipoDoc));
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT fattura_pedane_separate FROM vtb_clie WHERE cod_anag = %s",
|
||||
dtbDoct.getCodAnag());
|
||||
|
||||
boolean fatturaPedane = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT flag_fattura_vettore FROM gtb_porto WHERE porto = %s",
|
||||
dtbDoct.getIncoterms());
|
||||
boolean fatturaVettore = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (fatturaPedane || fatturaVettore) {
|
||||
sql = Query.format("SELECT activity_id FROM dtb_doct WHERE cod_anag = %s AND cod_dtip = %s AND data_doc = %s AND ser_doc = %s AND num_doc = %s",
|
||||
codAnag,
|
||||
codDtip,
|
||||
dataDoc,
|
||||
serDoc,
|
||||
numDoc);
|
||||
|
||||
String idAttivita = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
if (UtilityString.isNullOrEmpty(idAttivita)) {
|
||||
final String keySectionTipoAttivita = "TIPO_ATTIVITA";
|
||||
String activityTypeId = setupSection.get(keySectionTipoAttivita);
|
||||
if (UtilityString.isNullOrEmpty(activityTypeId))
|
||||
throw new Exception(String.format("Tipo attività non configurato %s -> %s -> %s", gestName, section, keySectionTipoAttivita));
|
||||
|
||||
StbActivity stbActivity = createStbAcvitity(activityTypeId);
|
||||
entityList.add(0, stbActivity);
|
||||
idAttivita = stbActivity.getActivityId();
|
||||
dtbDoct.setActivityId(idAttivita);
|
||||
}
|
||||
|
||||
String codAnagPed;
|
||||
if (fatturaVettore) {
|
||||
if (UtilityString.isNullOrEmpty(dtbDoct.getCodVvet()))
|
||||
throw new Exception("Codice vettore non presente sul documento");
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT cod_anag FROM vtb_vett WHERE cod_vvet = %s",
|
||||
dtbDoct.getCodVvet());
|
||||
|
||||
codAnagPed = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (UtilityString.isNullOrEmpty(codAnag))
|
||||
throw new Exception(String.format("Codice fornitore non trovato sul vettore %s", dtbDoct.getCodVvet()));
|
||||
} else {
|
||||
codAnagPed = dtbDoct.getCodAnag();
|
||||
}
|
||||
|
||||
DtbDoct dtbDoctPedOld = null;
|
||||
if (!UtilityString.isNullOrEmpty(idAttivita)){
|
||||
sql = Query.format("SELECT cod_anag, cod_dtip, data_doc, ser_doc, num_doc FROM dtb_doct WHERE activity_id = %s AND NOT(cod_anag = %s AND cod_dtip = %s AND data_doc = %s AND ser_doc = %s AND num_doc = %s)",
|
||||
idAttivita,
|
||||
codAnag,
|
||||
codDtip,
|
||||
dataDoc,
|
||||
serDoc,
|
||||
numDoc);
|
||||
|
||||
dtbDoctPedOld = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbDoct.class);
|
||||
}
|
||||
|
||||
Integer numDocPed = null;
|
||||
Date dataDocPed = null;
|
||||
String serDocPed = null;
|
||||
if (dtbDoctPedOld != null){
|
||||
dataDocPed = dtbDoctPedOld.getDataDoc();
|
||||
numDocPed = dtbDoctPedOld.getNumDoc();
|
||||
serDocPed = dtbDoctPedOld.getSerDoc();
|
||||
dtbDoctPedOld.setOperation(OperationType.DELETE);
|
||||
entityList.add(dtbDoctPedOld);
|
||||
}
|
||||
|
||||
DtbDoct dtbDoctPed =
|
||||
new DtbDoct()
|
||||
.setCodDtip(codDtipPed)
|
||||
.setCodAnag(codAnagPed)
|
||||
.setDataDoc(dataDocPed==null?dtbDoct.getDataDoc():dataDocPed)
|
||||
.setSerDoc(serDocPed)
|
||||
.setNumDoc(numDocPed)
|
||||
.setActivityId(idAttivita);
|
||||
dtbDoctPed.setOperation(OperationType.DELETE_THEN_INSERT);
|
||||
entityList.add(dtbDoctPed);
|
||||
|
||||
List<DtbDocImb> imballi = dtbDoct.getDtbDocImb().stream().filter(x->x.getTipoReso()!=2).collect(Collectors.toList());
|
||||
for (DtbDocImb docImb: imballi){
|
||||
String codTcol = docImb.getCodTcol();
|
||||
Integer qta = docImb.getNumImbCons() - docImb.getTipoReso();
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT cod_mart FROM mtb_tcol WHERE cod_tcol = %s",
|
||||
codTcol);
|
||||
|
||||
String codMart = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (UtilityString.isNullOrEmpty(codMart))
|
||||
throw new Exception(String.format("Codice articolo non trovato sul tipo collo %s",codTcol));
|
||||
|
||||
DtbDocr dtbDocr = new DtbDocr()
|
||||
.setCodMart(codMart)
|
||||
.setQtaDoc(new BigDecimal(qta));
|
||||
dtbDocr.setOperation(OperationType.INSERT);
|
||||
dtbDoctPed.getDtbDocr().add(dtbDocr);
|
||||
|
||||
}
|
||||
}
|
||||
saveDocImballi(dtbDoct, entityList, isInsert);
|
||||
}
|
||||
|
||||
List<EntityBase> entityRet = entityProcessor.processEntityList(entityList, true);
|
||||
@@ -195,6 +66,199 @@ public class DocumentiDirettiService {
|
||||
return entityRet;
|
||||
|
||||
}
|
||||
|
||||
private void saveDocImballi(DtbDoct dtbDoct, List<EntityBase> entityList, boolean isInsert) throws Exception {
|
||||
String sql;
|
||||
String codAnag = dtbDoct.getCodAnag();
|
||||
String codDtip = dtbDoct.getCodDtip();
|
||||
Date dataDoc = dtbDoct.getDataDoc();
|
||||
String serDoc = dtbDoct.getSerDoc();
|
||||
Integer numDoc = dtbDoct.getNumDoc();
|
||||
Map<String, Object> oldPk = dtbDoct.getOldPk();
|
||||
if (oldPk != null && oldPk.size() > 0) {
|
||||
if (oldPk.containsKey("codAnag")) codAnag = (String) oldPk.get("codAnag");
|
||||
if (oldPk.containsKey("codDtip")) codDtip = (String) oldPk.get("codDtip");
|
||||
if (oldPk.containsKey("dataDoc")) dataDoc = UtilityString.parseDate((String) oldPk.get("dataDoc"));
|
||||
if (oldPk.containsKey("serDoc")) serDoc = (String) oldPk.get("serDoc");
|
||||
if (oldPk.containsKey("numDoc")) numDoc = (Integer) oldPk.get("numDoc");
|
||||
}
|
||||
|
||||
String idAttivita = null;
|
||||
DtbDoct dtbDoctPedOld = null;
|
||||
if (!isInsert){
|
||||
sql = Query.format("SELECT activity_id FROM dtb_doct WHERE cod_anag = %s AND cod_dtip = %s AND data_doc = %s AND ser_doc = %s AND num_doc = %s",
|
||||
codAnag,
|
||||
codDtip,
|
||||
dataDoc,
|
||||
serDoc,
|
||||
numDoc);
|
||||
|
||||
idAttivita = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(idAttivita)){
|
||||
sql = Query.format("SELECT cod_anag, cod_dtip, data_doc, ser_doc, num_doc FROM dtb_doct WHERE activity_id = %s AND NOT(cod_anag = %s AND cod_dtip = %s AND data_doc = %s AND ser_doc = %s AND num_doc = %s)",
|
||||
idAttivita,
|
||||
codAnag,
|
||||
codDtip,
|
||||
dataDoc,
|
||||
serDoc,
|
||||
numDoc);
|
||||
|
||||
dtbDoctPedOld = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbDoct.class);
|
||||
}
|
||||
}
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT fattura_pedane_separate FROM vtb_clie WHERE cod_anag = %s",
|
||||
dtbDoct.getCodAnag());
|
||||
|
||||
boolean fatturaPedaneCliente = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT flag_fattura_vettore FROM gtb_porto WHERE porto = %s",
|
||||
dtbDoct.getIncoterms());
|
||||
boolean fatturaVettore = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (fatturaPedaneCliente || fatturaVettore) {
|
||||
final String gestName = "DTB_DOCT";
|
||||
final String section = "FATTURA_PEDANE";
|
||||
final String keySectionTipoDoc = "TIPO_DOC_RESI";
|
||||
|
||||
HashMap<String, String> setupSection = setupGest.getSetupSection(multiDBTransactionManager.getPrimaryConnection(), gestName, section);
|
||||
String codDtipPed = setupSection.get(keySectionTipoDoc);
|
||||
if (UtilityString.isNullOrEmpty(codDtipPed))
|
||||
throw new Exception(String.format("Tipo Documento per la creazione della fattura delle pedane non configurato %s -> %s -> %s", gestName, section, keySectionTipoDoc));
|
||||
|
||||
|
||||
if (UtilityString.isNullOrEmpty(idAttivita)) {
|
||||
final String keySectionTipoAttivita = "TIPO_ATTIVITA";
|
||||
String activityTypeId = setupSection.get(keySectionTipoAttivita);
|
||||
if (UtilityString.isNullOrEmpty(activityTypeId))
|
||||
throw new Exception(String.format("Tipo attività non configurato %s -> %s -> %s", gestName, section, keySectionTipoAttivita));
|
||||
|
||||
StbActivity stbActivity = createStbAcvitity(activityTypeId);
|
||||
entityList.add(0, stbActivity);
|
||||
idAttivita = stbActivity.getActivityId();
|
||||
dtbDoct.setActivityId(idAttivita);
|
||||
}
|
||||
|
||||
String codAnagPed;
|
||||
if (fatturaVettore) {
|
||||
if (UtilityString.isNullOrEmpty(dtbDoct.getCodFornTrasp()))
|
||||
throw new Exception("Codice fornitore del trasporto non presente sul documento");
|
||||
codAnagPed = dtbDoct.getCodFornTrasp();
|
||||
} else {
|
||||
codAnagPed = dtbDoct.getCodAnag();
|
||||
}
|
||||
|
||||
HashMap<String, Object> oldPkDoc = new HashMap<>();
|
||||
Integer numDocPed = null;
|
||||
Date dataDocPed = null;
|
||||
String serDocPed = null;
|
||||
if (dtbDoctPedOld != null){
|
||||
dataDocPed = dtbDoctPedOld.getDataDoc();
|
||||
numDocPed = dtbDoctPedOld.getNumDoc();
|
||||
|
||||
oldPkDoc = new HashMap<>();
|
||||
oldPkDoc.put("codDtip", dtbDoctPedOld.getCodDtip());
|
||||
oldPkDoc.put("codAnag", dtbDoctPedOld.getCodAnag());
|
||||
oldPkDoc.put("dataDoc", dtbDoctPedOld.getDataDoc());
|
||||
oldPkDoc.put("serDoc", dtbDoctPedOld.getSerDoc());
|
||||
oldPkDoc.put("numDoc", dtbDoctPedOld.getNumDoc());
|
||||
}
|
||||
|
||||
List<DtbDocImb> imballi = dtbDoct.getDtbDocImb().stream().filter(x->x.getTipoReso()!=2).collect(Collectors.toList());
|
||||
Map<Boolean, List<DtbDocImb>> gruppoImballi = imballi.stream().collect(Collectors.groupingBy(x -> x.getNumImbCons() > x.getNumImbResi()));
|
||||
for (Map.Entry<Boolean, List<DtbDocImb>> item : gruppoImballi.entrySet()) {
|
||||
if (item.getKey())
|
||||
codDtipPed = dtbDoct.getCodDtip();
|
||||
|
||||
if (dtbDoctPedOld !=null && codDtipPed.equalsIgnoreCase(dtbDoctPedOld.getCodDtip()))
|
||||
serDocPed = dtbDoctPedOld.getSerDoc();
|
||||
else
|
||||
serDocPed = null;
|
||||
|
||||
DtbDoct dtbDoctPed =
|
||||
new DtbDoct()
|
||||
.setCodDtip(codDtipPed)
|
||||
.setCodAnag(codAnagPed)
|
||||
.setDataDoc(dataDocPed==null? dtbDoct.getDataDoc():dataDocPed)
|
||||
.setSerDoc(serDocPed)
|
||||
.setNumDoc(numDocPed)
|
||||
.setCodMdep(dtbDoct.getCodMdep())
|
||||
.setActivityId(idAttivita)
|
||||
.setListino(dtbDoct.getListino());
|
||||
if ( !oldPkDoc.isEmpty()) {
|
||||
dtbDoctPed.setOldPk(oldPkDoc);
|
||||
}
|
||||
dtbDoctPed.setOperation(OperationType.DELETE_THEN_INSERT);
|
||||
entityList.add(dtbDoctPed);
|
||||
|
||||
|
||||
for (DtbDocImb docImb : item.getValue()) {
|
||||
String codTcol = docImb.getCodTcol();
|
||||
int qta = docImb.getNumImbCons() - docImb.getTipoReso();
|
||||
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT mtb_tcol.cod_mart, " +
|
||||
"mtb_aart.descrizione " +
|
||||
"FROM mtb_tcol INNER JOIN mtb_aart ON mtb_tcol.cod_mart = mtb_aart.cod_mart " +
|
||||
"WHERE cod_tcol = %s",
|
||||
codTcol);
|
||||
|
||||
HashMap<String, Object> datiTipoCollo = UtilityDB.executeSimpleQueryOnlyFirstRow(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
String codMart = UtilityHashMap.getValueIfExists(datiTipoCollo, "cod_mart");
|
||||
String descrizioneTipoCollo = UtilityHashMap.getValueIfExists(datiTipoCollo, "descrizione");
|
||||
if (UtilityString.isNullOrEmpty(codMart))
|
||||
throw new Exception(String.format("Codice articolo non trovato sul tipo collo %s", codTcol));
|
||||
|
||||
DtbDocr dtbDocr = new DtbDocr()
|
||||
.setCodMart(codMart)
|
||||
.setQtaDoc(new BigDecimal(qta).abs());
|
||||
dtbDocr.setOperation(OperationType.INSERT);
|
||||
dtbDoctPed.getDtbDocr().add(dtbDocr);
|
||||
|
||||
String descrizione = descrizioneTipoCollo + ": ";
|
||||
if (docImb.getNumImbCons() > 0) {
|
||||
descrizione +=
|
||||
String.format("CARICATE/I %s", docImb.getNumImbCons());
|
||||
}
|
||||
if (docImb.getNumImbResi() > 0) {
|
||||
if (descrizione != null && descrizione.length() > 0)
|
||||
descrizione += ", ";
|
||||
descrizione +=
|
||||
String.format("RESE/I %s", docImb.getNumImbResi());
|
||||
}
|
||||
dtbDocr = new DtbDocr()
|
||||
.setDescrizione(UtilityString.left(descrizione,40))
|
||||
.setDescrizioneEstesa(descrizione);
|
||||
dtbDocr.setOperation(OperationType.INSERT);
|
||||
dtbDoctPed.getDtbDocr().add(dtbDocr);
|
||||
}
|
||||
if (!imballi.isEmpty()) {
|
||||
String descrizione =
|
||||
String.format("NS. RIF. %S DEL %S N. %S/%S",
|
||||
dtbDoct.getCodDtip(),
|
||||
new SimpleDateFormat(CommonConstants.DATE_FORMAT_DMY).format(dtbDoct.getDataDoc()),
|
||||
dtbDoct.getSerDoc(),
|
||||
dtbDoct.getNumDoc());
|
||||
DtbDocr dtbDocr = new DtbDocr()
|
||||
.setDescrizione(UtilityString.left(descrizione, 40))
|
||||
.setDescrizioneEstesa(descrizione);
|
||||
dtbDocr.setOperation(OperationType.INSERT);
|
||||
dtbDoctPed.getDtbDocr().add(dtbDocr);
|
||||
}
|
||||
}
|
||||
} else if ( dtbDoctPedOld != null ){
|
||||
dtbDoctPedOld.setOperation(OperationType.DELETE);
|
||||
entityList.add(dtbDoctPedOld);
|
||||
}
|
||||
}
|
||||
|
||||
private StbActivity createStbAcvitity(String activityTypeId) throws Exception {
|
||||
String idAttivita = ConfigActivityRules.completeActivityId(multiDBTransactionManager.getPrimaryConnection());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user