Importazione scadenze DocFinance
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
|
||||||
|
public class Migration_20240925163122 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "ATTIVO", "N",
|
||||||
|
"Inserire S/N per attivare/disattivare il tipo di importazione", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "EMAIL_FOR_LOG", null,
|
||||||
|
"Inserire il file l'indirizzo email per inviare il log dell'importazione", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "FILE_FILTER", null,
|
||||||
|
"Inserire il criterio di filtro dei file o il nome del file specifio (seguire la sintassi di java)", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "GG_CANC_FILE", null,
|
||||||
|
"Giorni per la cancellazione dei file dalla cartella di appoggio", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "IMPORT_REST", "S",
|
||||||
|
"Inserire S/N per attivare/disattivare il salvataggio con i servizi REST", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "LISTENING", "N",
|
||||||
|
"Se LISTENIG = 'N' la procedura di importazione non si potrà mai mettere in ascolto sulla directory perchè nella procedura vengono prese in considerazione più file.", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "PATH_FILE", null,
|
||||||
|
"Directory contente i file da importare.", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
createSetup("IMPORT_SCADENZE", "DOCFINANCE", "PATH_FILE_IMPORTED", null,
|
||||||
|
"Directory dove vengono spostati i file dopo l'importazione.", false, null, false, false,
|
||||||
|
false, false, false, null, false, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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_20240926115459 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
executeStatement("ALTER TABLE ctb_scad ADD intercode VARCHAR(40)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -100,6 +100,9 @@ public class CtbScad extends EntityBase {
|
|||||||
@SqlField(value = "num_ord")
|
@SqlField(value = "num_ord")
|
||||||
private Integer numOrd;
|
private Integer numOrd;
|
||||||
|
|
||||||
|
@SqlField(value = "intercode", maxLength = 40)
|
||||||
|
private String intercode;
|
||||||
|
|
||||||
@MapToTable(value = "tipo_partita")
|
@MapToTable(value = "tipo_partita")
|
||||||
private Integer tipoPartita;
|
private Integer tipoPartita;
|
||||||
|
|
||||||
@@ -398,6 +401,15 @@ public class CtbScad extends EntityBase {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIntercode() {
|
||||||
|
return intercode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CtbScad setIntercode(String intercode) {
|
||||||
|
this.intercode = intercode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void insertChilds() throws Exception {
|
protected void insertChilds() throws Exception {
|
||||||
if (getCrlScadParr() != null) {
|
if (getCrlScadParr() != null) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package it.integry.ems.contabil.Import;
|
|||||||
import it.integry.ems.Import.base.BaseEntityImporter;
|
import it.integry.ems.Import.base.BaseEntityImporter;
|
||||||
import it.integry.ems.Import.base.IEntityImporter;
|
import it.integry.ems.Import.base.IEntityImporter;
|
||||||
import it.integry.ems.contabil.Import.service.ContabilImportService;
|
import it.integry.ems.contabil.Import.service.ContabilImportService;
|
||||||
|
import it.integry.ems.contabil.Import.service.ScadenzeImportService;
|
||||||
import it.integry.ems_model.base.EntityBase;
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -13,16 +14,15 @@ public class ScadenzeImporter extends BaseEntityImporter<List<EntityBase>> imple
|
|||||||
@Override
|
@Override
|
||||||
public List<EntityBase> doImport() throws Exception {
|
public List<EntityBase> doImport() throws Exception {
|
||||||
Format enumFormat = Format.fromString(super.format);
|
Format enumFormat = Format.fromString(super.format);
|
||||||
|
|
||||||
List<EntityBase> entities = Collections.emptyList();
|
List<EntityBase> entities = Collections.emptyList();
|
||||||
|
|
||||||
|
ScadenzeImportService scadenzeImportService = getContextBean(ScadenzeImportService.class);
|
||||||
|
|
||||||
if (enumFormat != null) {
|
if (enumFormat != null) {
|
||||||
switch (enumFormat) {
|
switch (enumFormat) {
|
||||||
case DOCFINANCE:
|
case DOCFINANCE:
|
||||||
|
entities = scadenzeImportService.importDocFinance(type, format, requestDto, anomalie);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Exception("Tipo " + format + " non supportato");
|
throw new Exception("Tipo " + format + " non supportato");
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ public class ScadenzeImporter extends BaseEntityImporter<List<EntityBase>> imple
|
|||||||
|
|
||||||
|
|
||||||
public enum Format {
|
public enum Format {
|
||||||
DOCFINANCE("DOC_FINANCE");
|
DOCFINANCE("DOCFINANCE");
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package it.integry.ems.contabil.Import.service;
|
||||||
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
|
import it.integry.common.var.CommonConstants;
|
||||||
|
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||||
|
import it.integry.ems.Import.dto.ImportRequestDTO;
|
||||||
|
import it.integry.ems.product.export.services.ProdottiLaranciaService;
|
||||||
|
import it.integry.ems.service.EntityProcessor;
|
||||||
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
|
import it.integry.ems_model.base.EntityBase;
|
||||||
|
import it.integry.ems_model.entity.CtbPart;
|
||||||
|
import it.integry.ems_model.entity.CtbScad;
|
||||||
|
import it.integry.ems_model.service.SetupGest;
|
||||||
|
import it.integry.ems_model.types.OperationType;
|
||||||
|
import it.integry.ems_model.utility.*;
|
||||||
|
import org.codehaus.stax2.ri.typed.StringBase64Decoder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Scope("request")
|
||||||
|
public class ScadenzeImportService {
|
||||||
|
@Autowired
|
||||||
|
private EntityProcessor entityProcessor;
|
||||||
|
@Autowired
|
||||||
|
private MultiDBTransactionManager multiDBTransactionManager;
|
||||||
|
@Autowired
|
||||||
|
private SetupGest setupGest;
|
||||||
|
@Autowired
|
||||||
|
private ProdottiLaranciaService prodottiLaranciaService;
|
||||||
|
|
||||||
|
public List<EntityBase> importDocFinance(String type, String format, ImportRequestDTO requestDTO, List<AnomalieDTO> listAnomalie) throws Exception {
|
||||||
|
List<EntityBase> entityList = new ArrayList<>();
|
||||||
|
Connection conn = multiDBTransactionManager.getPrimaryConnection();
|
||||||
|
|
||||||
|
if (requestDTO == null || requestDTO.getRawContent() == null)
|
||||||
|
throw new Exception("Nessun file da importare");
|
||||||
|
|
||||||
|
List<CtbPart> ctbParts = new ArrayList<>();
|
||||||
|
List<String> lines = UtilityString.splitStringToMultipleLine(requestDTO.getRawContent());
|
||||||
|
if (!lines.isEmpty()) {
|
||||||
|
for (String line : lines) {
|
||||||
|
String codPaga = line.substring(0, 2).trim();
|
||||||
|
|
||||||
|
BigDecimal impDare = null;
|
||||||
|
BigDecimal impAvere = null;
|
||||||
|
BigDecimal importo = UtilityString.stringToBigDecimal(line.substring(3, 18));
|
||||||
|
String segno = line.substring(2, 3);
|
||||||
|
int tipoPartita = 0;
|
||||||
|
|
||||||
|
if (segno.equalsIgnoreCase("+")) {
|
||||||
|
impDare = importo;
|
||||||
|
tipoPartita = 1;
|
||||||
|
} else {
|
||||||
|
impAvere = importo;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date dataScad = UtilityDate.StringToDate(line.substring(57, 65), "ddMMyyyy");
|
||||||
|
Date dataDoc = UtilityDate.StringToDate(line.substring(267, 275), "ddMMyyyy");
|
||||||
|
String diacod = line.substring(92, 108).trim();
|
||||||
|
Integer numDoc = UtilityString.isIntNumber(line.substring(185, 197).trim()) ? UtilityInteger.stringToInteger(line.substring(185, 197).trim()) : null;
|
||||||
|
String intercode = line.substring(197, 223);
|
||||||
|
|
||||||
|
String sql = Query.format(
|
||||||
|
"SELECT CAST(COUNT(*) AS BIT) AS exist FROM gtb_paga WHERE cod_paga = %s",
|
||||||
|
codPaga
|
||||||
|
);
|
||||||
|
codPaga = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql) ? codPaga : null;
|
||||||
|
|
||||||
|
sql = Query.format(
|
||||||
|
"SELECT cod_anag FROM gtb_anag WHERE diacod = %s",
|
||||||
|
diacod
|
||||||
|
);
|
||||||
|
String codAnag = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||||
|
|
||||||
|
String annoString = intercode.substring(0, 2).trim();
|
||||||
|
Integer anno = UtilityString.isIntNumber(annoString) ? Integer.parseInt("20" + annoString) : null;
|
||||||
|
String intercodeSubstring = intercode.substring(2).substring(0, 6).trim();
|
||||||
|
Integer numFromIntercode = UtilityString.isIntNumber(intercodeSubstring) ? UtilityInteger.stringToInteger(intercodeSubstring) : null;
|
||||||
|
|
||||||
|
CtbPart ctbPart = Stream.of(ctbParts)
|
||||||
|
.filter(x ->
|
||||||
|
(x.getNumDoc().equals(numDoc) || x.getNumDoc().equals(numFromIntercode)) &&
|
||||||
|
x.getCodAnag().equals(codAnag) &&
|
||||||
|
x.getDataDoc().equals(dataDoc)
|
||||||
|
)
|
||||||
|
.findFirstOrElse(null);
|
||||||
|
|
||||||
|
if(ctbPart != null) {
|
||||||
|
ctbParts.remove(ctbPart);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctbPart == null && numFromIntercode != null) {
|
||||||
|
sql = Query.format(
|
||||||
|
"SELECT *\n" +
|
||||||
|
"FROM ctb_part\n" +
|
||||||
|
"WHERE cod_anag = %s\n" +
|
||||||
|
" AND anno_part = %s\n" +
|
||||||
|
" AND num_doc = %s\n" +
|
||||||
|
" AND ((tipo_partita = %s\n"+
|
||||||
|
" AND dare_part - avere_part <> 0) OR (tipo_partita <> %s AND dare_part - avere_part = %s))"
|
||||||
|
, codAnag, anno, numFromIntercode, tipoPartita, tipoPartita, segno + importo
|
||||||
|
);
|
||||||
|
List<CtbPart> ctbPartList = UtilityDB.executeSimpleQueryDTO(conn, sql, CtbPart.class);
|
||||||
|
|
||||||
|
if (ctbPartList != null) {
|
||||||
|
if (ctbPartList.size() > 1) {
|
||||||
|
listAnomalie.add(AnomalieDTO.warning(String.format("Più partite trovate.\nCodAnag: %s (%s)\nIntercode scadenza: %s", codAnag, diacod, intercode.trim())));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctbPart = ctbPartList.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctbPart == null && (anno != null && anno < 2021 || dataDoc.before(UtilityDate.StringToDate("2021/07/01", "yyyy/MM/dd")))) {
|
||||||
|
sql = Query.format(
|
||||||
|
"SELECT *\n" +
|
||||||
|
"FROM ctb_part\n" +
|
||||||
|
"WHERE anno_part = '2021'\n" +
|
||||||
|
" AND num_doc = '0'\n" +
|
||||||
|
" AND cod_anag = %s",
|
||||||
|
codAnag
|
||||||
|
);
|
||||||
|
ctbPart = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(conn, sql, CtbPart.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctbPart == null) {
|
||||||
|
listAnomalie.add(
|
||||||
|
AnomalieDTO.warning(
|
||||||
|
String.format(
|
||||||
|
"Scadenza non trovata.\nCodAnag: %s (%s)\nIntercode scadenza: %s\nImporto: %s",
|
||||||
|
codAnag, diacod, intercode.trim(), segno + importo
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CtbScad ctbScad = new CtbScad();
|
||||||
|
ctbScad.setDataScad(dataScad)
|
||||||
|
.setImpAvere(impAvere)
|
||||||
|
.setImpDare(impDare)
|
||||||
|
.setCodPaga(codPaga)
|
||||||
|
.setIntercode(intercode)
|
||||||
|
.setOperation(OperationType.INSERT);
|
||||||
|
|
||||||
|
ctbPart.getCtbScad().add(ctbScad);
|
||||||
|
ctbPart.setOperation(OperationType.NO_OP);
|
||||||
|
ctbParts.add(ctbPart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//entityList = entityProcessor.processEntityList(ctbParts, false);
|
||||||
|
|
||||||
|
return entityList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,9 +3,7 @@ package it.integry.ems.contabil.context;
|
|||||||
import it.integry.annotations.PostContextConstruct;
|
import it.integry.annotations.PostContextConstruct;
|
||||||
import it.integry.ems.Import.base.EntityImporterUtility;
|
import it.integry.ems.Import.base.EntityImporterUtility;
|
||||||
import it.integry.ems.Import.enums.EntityImportType;
|
import it.integry.ems.Import.enums.EntityImportType;
|
||||||
import it.integry.ems.contabil.Import.ContabilImporter;
|
|
||||||
import it.integry.ems.contabil.Import.ScadenzeImporter;
|
import it.integry.ems.contabil.Import.ScadenzeImporter;
|
||||||
import it.integry.ems.contabil.export.ContabilExporter;
|
|
||||||
import it.integry.ems.contabil.export.ScadenzeExporter;
|
import it.integry.ems.contabil.export.ScadenzeExporter;
|
||||||
import it.integry.ems.export.base.EntityExporterUtility;
|
import it.integry.ems.export.base.EntityExporterUtility;
|
||||||
import it.integry.ems.export.enums.EntityExportType;
|
import it.integry.ems.export.enums.EntityExportType;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import it.integry.ems.contabil.export.services.MovimentiContabiliExporterService
|
|||||||
import it.integry.ems.contabil.fatture.base.enums.InvoiceType;
|
import it.integry.ems.contabil.fatture.base.enums.InvoiceType;
|
||||||
import it.integry.ems.contabil.fatture.rest.ExportFattureRequest;
|
import it.integry.ems.contabil.fatture.rest.ExportFattureRequest;
|
||||||
import it.integry.ems.contabil.fatture.services.InvoiceService;
|
import it.integry.ems.contabil.fatture.services.InvoiceService;
|
||||||
|
import it.integry.ems.document.fatture.services.PassiveInvoiceService;
|
||||||
import it.integry.ems.export.base.BaseEntityExporter;
|
import it.integry.ems.export.base.BaseEntityExporter;
|
||||||
import it.integry.ems.export.base.EntityExportResponse;
|
import it.integry.ems.export.base.EntityExportResponse;
|
||||||
import it.integry.ems.export.base.IEntityExporter;
|
import it.integry.ems.export.base.IEntityExporter;
|
||||||
@@ -17,6 +18,7 @@ public class ScadenzeExporter extends BaseEntityExporter implements IEntityExpor
|
|||||||
public EntityExportResponse doExport() throws Exception {
|
public EntityExportResponse doExport() throws Exception {
|
||||||
ScadenzeExporterFormat format = ScadenzeExporterFormat.fromString(super.format);
|
ScadenzeExporterFormat format = ScadenzeExporterFormat.fromString(super.format);
|
||||||
EntityExportResponse entityExportResponse = null;
|
EntityExportResponse entityExportResponse = null;
|
||||||
|
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case DOCFINANCE:
|
case DOCFINANCE:
|
||||||
@@ -33,7 +35,7 @@ public class ScadenzeExporter extends BaseEntityExporter implements IEntityExpor
|
|||||||
|
|
||||||
public enum ScadenzeExporterFormat {
|
public enum ScadenzeExporterFormat {
|
||||||
|
|
||||||
DOCFINANCE("DOC_FINANCE");
|
DOCFINANCE("DOCFINANCE");
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user