Merge branch 'develop' into feature/RefactoringGestioneColli
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
# Conflicts: # ems-engine/src/main/java/it/integry/ems/production/service/MesProductionServiceV2.java # ems-engine/src/main/java/it/integry/ems/retail/pvmRetail/service/PvmService.java # ems-engine/src/main/java/it/integry/ems/retail/wms/generic/service/WMSGenericService.java
This commit is contained in:
@@ -8,6 +8,7 @@ import it.integry.ems.properties.EmsProperties;
|
||||
import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.FileItem;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
@@ -192,67 +193,66 @@ public class EmailWatcherListener extends TimerTask {
|
||||
private void notifyErrorToEmail(String emailListen, String mittente, String messageObj, Date messageDate,
|
||||
String emailDbg, String errorMessage) throws Exception {
|
||||
if (!UtilityString.isNullOrEmpty(emailDbg)) {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(emailListenerInfo.getDatabase());
|
||||
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager(emailListenerInfo.getDatabase())) {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
|
||||
String nomeAzienda = "";
|
||||
PreparedStatement ps = ds.getConnection().prepareStatement("select nome_ditta from azienda");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
nomeAzienda = rs.getString("nome_ditta");
|
||||
String nomeAzienda = "";
|
||||
PreparedStatement ps = mdb.prepareStatement("select nome_ditta from azienda");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
nomeAzienda = rs.getString("nome_ditta");
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
String htmlMailBody = "Gentile Amministratore,<br> si e' verificato il seguente errore <br><b>" + errorMessage + "</b><br> del servizio " + emailListenerInfo.getServiceRest() +
|
||||
"<br> in ascolto sulla mail " + emailListen + " provocato dal messaggio (mittente " + mittente + ") con oggetto " + messageObj + " in data " + sdf.format(messageDate);
|
||||
|
||||
String mailSubject = nomeAzienda + " - ERRORE SU " + InetAddress.getLocalHost().getHostName() +
|
||||
" Servizio " + emailListenerInfo.getServiceRest() + ";Database " + emailListenerInfo.getDatabase();
|
||||
|
||||
// AttachmentDTO dto = new AttachmentDTO();
|
||||
// dto.setFileByte(files);
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
//jsonObjectMapper.writeValue(writer, dto);
|
||||
|
||||
String jsonBody = writer.toString();
|
||||
|
||||
String database = emailListenerInfo.getDatabase();
|
||||
|
||||
String auth = RestUtil.generateAuth(database, database, "POST", jsonBody,
|
||||
"application/json", prop.getRootApi() + EmsRestConstants.PATH_SEND_MAIL);
|
||||
|
||||
final Client client = ClientBuilder.newClient();
|
||||
WebTarget resource = client.target(prop.getEndPointWS()).path(
|
||||
prop.getRootApi() + EmsRestConstants.PATH_SEND_MAIL)
|
||||
.resolveTemplate("mode", "async");
|
||||
resource = resource.queryParam(CommonConstants.PROFILE_DB, database)
|
||||
.queryParam("from", "").queryParam("to", emailDbg)
|
||||
.queryParam("subject", mailSubject).queryParam("msgText", htmlMailBody)
|
||||
.queryParam("isHtml", true);
|
||||
|
||||
resource.request().header("Authorization", database + ":" + auth)
|
||||
.async()
|
||||
.post(Entity.json(jsonBody), new InvocationCallback<Response>() {
|
||||
@Override
|
||||
public void completed(Response response) {
|
||||
String value = response.readEntity(String.class);
|
||||
logger.info(response.getStatus() + " - " + value);
|
||||
response.close();
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
logger.error(throwable);
|
||||
client.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
ds.forceClose();
|
||||
|
||||
String htmlMailBody = "Gentile Amministratore,<br> si e' verificato il seguente errore <br><b>" + errorMessage + "</b><br> del servizio " + emailListenerInfo.getServiceRest() +
|
||||
"<br> in ascolto sulla mail " + emailListen + " provocato dal messaggio (mittente " + mittente + ") con oggetto " + messageObj + " in data " + sdf.format(messageDate);
|
||||
|
||||
String mailSubject = nomeAzienda + " - ERRORE SU " + InetAddress.getLocalHost().getHostName() +
|
||||
" Servizio " + emailListenerInfo.getServiceRest() + ";Database " + emailListenerInfo.getDatabase();
|
||||
|
||||
// AttachmentDTO dto = new AttachmentDTO();
|
||||
// dto.setFileByte(files);
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
//jsonObjectMapper.writeValue(writer, dto);
|
||||
|
||||
String jsonBody = writer.toString();
|
||||
|
||||
String database = emailListenerInfo.getDatabase();
|
||||
|
||||
String auth = RestUtil.generateAuth(database, database, "POST", jsonBody,
|
||||
"application/json", prop.getRootApi() + EmsRestConstants.PATH_SEND_MAIL);
|
||||
|
||||
final Client client = ClientBuilder.newClient();
|
||||
WebTarget resource = client.target(prop.getEndPointWS()).path(
|
||||
prop.getRootApi() + EmsRestConstants.PATH_SEND_MAIL)
|
||||
.resolveTemplate("mode", "async");
|
||||
resource = resource.queryParam(CommonConstants.PROFILE_DB, database)
|
||||
.queryParam("from", "").queryParam("to", emailDbg)
|
||||
.queryParam("subject", mailSubject).queryParam("msgText", htmlMailBody)
|
||||
.queryParam("isHtml", true);
|
||||
|
||||
resource.request().header("Authorization", database + ":" + auth)
|
||||
.async()
|
||||
.post(Entity.json(jsonBody), new InvocationCallback<Response>() {
|
||||
@Override
|
||||
public void completed(Response response) {
|
||||
String value = response.readEntity(String.class);
|
||||
logger.info(response.getStatus() + " - " + value);
|
||||
response.close();
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
logger.error(throwable);
|
||||
client.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package it.integry.ems.entity_logger.db_schema_manager.dto;
|
||||
|
||||
public enum DatabaseVersionEnum {
|
||||
|
||||
SQLServer2000((short) 80),
|
||||
SQLServer2005((short) 90),
|
||||
SQLServer2008((short) 100),
|
||||
SQLServer2008R2((short) 105),
|
||||
SQLServer2012((short) 110),
|
||||
SQLServer2014((short) 120),
|
||||
SQLServer2016((short) 130),
|
||||
SQLServer2017((short) 140),
|
||||
SQLServer2019((short) 150),
|
||||
SQLServer2022((short) 160);
|
||||
|
||||
private short code;
|
||||
|
||||
private DatabaseVersionEnum(short code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static DatabaseVersionEnum fromCode(short code) {
|
||||
for (DatabaseVersionEnum b : DatabaseVersionEnum.values()) {
|
||||
if (b.code == code) return b;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.integry.ems.migration._base;
|
||||
|
||||
import it.integry.ems._context.ApplicationContextProvider;
|
||||
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseVersionEnum;
|
||||
import it.integry.ems.migration.dto.SqlObjectTypeEnum;
|
||||
import it.integry.ems.schedule.new_cron_job.dto.operations.base_classes.BaseScheduledOperationDTO;
|
||||
import it.integry.ems.schedule.new_cron_job.service.AutomatedOperationHandlerComponent;
|
||||
@@ -561,4 +562,39 @@ public abstract class BaseMigration implements MigrationModelInterface {
|
||||
gestSync.manageWithParentConnection(advancedDataSource.getConnection());
|
||||
|
||||
}
|
||||
|
||||
private DatabaseVersionEnum getSqlCompatibilityLevel() throws Exception {
|
||||
short compatibilityLevel =
|
||||
UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(advancedDataSource.getConnection(),
|
||||
Query.format("SELECT compatibility_level FROM sys.databases WHERE name = %s", advancedDataSource.getDataSource().getDbName()));
|
||||
|
||||
|
||||
return DatabaseVersionEnum.fromCode(compatibilityLevel);
|
||||
}
|
||||
|
||||
protected boolean isSqlVersionEqualsOrGreatherThan(DatabaseVersionEnum version) throws Exception {
|
||||
DatabaseVersionEnum dbVersion = getSqlCompatibilityLevel();
|
||||
|
||||
return dbVersion.getCode() >= version.getCode();
|
||||
}
|
||||
|
||||
protected boolean isSqlServer2008() throws Exception {
|
||||
return getSqlCompatibilityLevel() == DatabaseVersionEnum.SQLServer2008;
|
||||
}
|
||||
|
||||
protected boolean isSqlServer2012() throws Exception {
|
||||
return getSqlCompatibilityLevel() == DatabaseVersionEnum.SQLServer2012;
|
||||
}
|
||||
|
||||
protected boolean isSqlServer2014() throws Exception {
|
||||
return getSqlCompatibilityLevel() == DatabaseVersionEnum.SQLServer2014;
|
||||
}
|
||||
|
||||
protected boolean isSqlServer2019() throws Exception {
|
||||
return getSqlCompatibilityLevel() == DatabaseVersionEnum.SQLServer2019;
|
||||
}
|
||||
|
||||
protected boolean isSqlServer2022() throws Exception {
|
||||
return getSqlCompatibilityLevel() == DatabaseVersionEnum.SQLServer2022;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
import it.integry.ems_model.entity.WtbGestSetupUser;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Migration_20250404180134 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
String sql =
|
||||
"SELECT value\n" +
|
||||
"FROM stb_gest_setup\n" +
|
||||
"WHERE key_section = 'ENABLE_MODIFICA_LOTTO_SUGGERITO'";
|
||||
|
||||
String value = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(this.advancedDataSource.getConnection(), sql);
|
||||
|
||||
if (UtilityString.isNullOrEmpty(value)) {
|
||||
value = "N";
|
||||
}
|
||||
|
||||
createSetup("PVM", "MONITORAGGIO_LINEE_V2", "ENABLE_MODIFICA_SCADENZA_LOTTO", value,
|
||||
"Se abilitato permette la modifica della data di scadenza del lotto proposto in fase di assegnazione all'ordine.",
|
||||
false, "SI_NO", false, false,
|
||||
true, false, false, null, false, "SELECT 'S' UNION ALL SELECT 'N'");
|
||||
|
||||
// Sposto setup esistente a nuova
|
||||
sql =
|
||||
"SELECT user_name, gest_name, section, key_section, value\n" +
|
||||
"FROM wtb_gest_setup_user\n" +
|
||||
"WHERE key_section = 'ENABLE_MODIFICA_LOTTO_SUGGERITO'";
|
||||
|
||||
List<WtbGestSetupUser> userSetupConfig = UtilityDB.executeSimpleQueryDTO(advancedDataSource.getConnection(), sql, WtbGestSetupUser.class);
|
||||
|
||||
if (userSetupConfig != null && !userSetupConfig.isEmpty()) {
|
||||
for (WtbGestSetupUser userSetup : userSetupConfig) {
|
||||
userSetup
|
||||
.setKeySection("ENABLE_MODIFICA_SCADENZA_LOTTO");
|
||||
|
||||
userSetup.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
userSetup.manageWithParentConnection(advancedDataSource.getConnection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomerDB;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250410130507 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createSetup("MES", "SETUP", "CONTROLLO_SCADENZA_MULTIPLA", null,
|
||||
"Se true sulle linee scelte attiva la logica di generazione dei lotti con scadenza multipla.",
|
||||
false, "SI_NO", false, false,
|
||||
false, false, false, "jtb_fasi", false, "SELECT 'S' UNION ALL SELECT 'N'");
|
||||
|
||||
if (isCustomerDb(IntegryCustomerDB.RossoGargano_RossoGargano)) {
|
||||
executeStatement(
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'A1', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'A2', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'A3', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B1', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B2', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B3', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B4', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B5', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B6', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'B7', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'C1', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'C2', N'S');\n" +
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'MES', N'SETUP', N'CONTROLLO_SCADENZA_MULTIPLA', N'jtb_fasi', N'C3', N'S');"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250411101647 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("alter table ctb_beni alter column descrizione varchar(1024) not null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250411105328 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateFunction("f_suggestCodeCodBene", "CREATE FUNCTION f_suggestCodeCodBene\n" +
|
||||
"(\n" +
|
||||
" -- Add the parameters for the function here\n" +
|
||||
" @partitalCode varchar(5)\n" +
|
||||
")\n" +
|
||||
"RETURNS varchar(10)\n" +
|
||||
"AS\n" +
|
||||
"BEGIN\n" +
|
||||
" declare @max int, @codBene varchar(10), @len int;\n" +
|
||||
" \n" +
|
||||
" \n" +
|
||||
" -- Return the result of the function\n" +
|
||||
" RETURN @codBene\n" +
|
||||
"\n" +
|
||||
"END");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,605 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250411123155 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createOrUpdateFunction("MES_GetWorkOrders",
|
||||
"CREATE FUNCTION [dbo].[MES_GetWorkOrders](@codJfas VARCHAR(50), @dateStart DATE, @dateEnd DATE, @flagEvaso VARCHAR(1),\n" +
|
||||
" @codAnag VARCHAR(5))\n" +
|
||||
" RETURNS TABLE\n" +
|
||||
" AS RETURN\n" +
|
||||
" -- DECLARE @codJfas VARCHAR(5) = 'L1'\n" +
|
||||
" -- DECLARE @dateStart DATE = DATEADD(MONTH, -1, GETDATE())\n" +
|
||||
" -- DECLARE @dateEnd DATE = DATEADD(MONTH, 1, GETDATE())\n" +
|
||||
" -- DECLARE @flagEvaso VARCHAR(1) = 'I'\n" +
|
||||
" -- DECLARE @codAnag VARCHAR(5) = null;\n" +
|
||||
"\n" +
|
||||
"--Funzione per calcolare la sequenza di ordini su una linea e il RunTimeEND\n" +
|
||||
" WITH setup AS (SELECT ISNULL(@dateStart, DATEADD(DAY, -14, GETDATE())) AS date_start,\n" +
|
||||
" ISNULL(@dateEnd, GETDATE()) AS date_end,\n" +
|
||||
" ISNULL(@flagEvaso, 'I') AS flag_evaso,\n" +
|
||||
" @codJfas AS cod_jfas,\n" +
|
||||
" @codAnag AS cod_anag),\n" +
|
||||
"\n" +
|
||||
" setup_depo AS (SELECT cod_mdep, value AS flag_carico_scarico_immediato\n" +
|
||||
" FROM stb_gest_setup_depo\n" +
|
||||
" WHERE gest_name = 'CARICO_SCARICO_PF'\n" +
|
||||
" AND section = 'SETUP'\n" +
|
||||
" AND key_section = 'GENERA_CARICO_SCARICO_IMMEDIATO'),\n" +
|
||||
"\n" +
|
||||
" setup_run_time AS (SELECT value AS flag_restart\n" +
|
||||
" FROM stb_gest_setup\n" +
|
||||
" WHERE gest_name = 'PVM'\n" +
|
||||
" AND section = 'MONITORAGGIO_LINEE_V2'\n" +
|
||||
" AND key_section = 'RESTART_RUN_TIME_END'),\n" +
|
||||
"\n" +
|
||||
" mtb_colr_sum_filtered_rows AS (SELECT gestione,\n" +
|
||||
" data_collo,\n" +
|
||||
" num_collo,\n" +
|
||||
" ser_collo,\n" +
|
||||
" cod_mart,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" qta_col,\n" +
|
||||
" num_cnf\n" +
|
||||
" FROM mtb_colr\n" +
|
||||
" WHERE gestione_rif IS NULL\n" +
|
||||
" AND data_collo_rif IS NULL\n" +
|
||||
" AND ser_collo_rif IS NULL\n" +
|
||||
" AND num_collo_rif IS NULL),\n" +
|
||||
"\n" +
|
||||
" mtb_colr_sum_valid_colli AS (SELECT DISTINCT gestione,\n" +
|
||||
" data_collo,\n" +
|
||||
" ser_collo,\n" +
|
||||
" num_collo\n" +
|
||||
" FROM mtb_colt\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE segno = 1\n" +
|
||||
" AND data_ord BETWEEN setup.date_start AND setup.date_end),\n" +
|
||||
"\n" +
|
||||
" mtb_colr_sum AS (SELECT colr.gestione,\n" +
|
||||
" colr.data_collo,\n" +
|
||||
" colr.num_collo,\n" +
|
||||
" colr.ser_collo,\n" +
|
||||
" colr.cod_mart,\n" +
|
||||
" colr.data_ord,\n" +
|
||||
" colr.num_ord,\n" +
|
||||
" SUM(colr.qta_col) AS qta_col,\n" +
|
||||
" SUM(colr.num_cnf) AS num_cnf\n" +
|
||||
" FROM mtb_colr_sum_valid_colli colt\n" +
|
||||
" INNER JOIN mtb_colr_sum_filtered_rows colr\n" +
|
||||
" ON colr.gestione = colt.gestione\n" +
|
||||
" AND colr.data_collo = colt.data_collo\n" +
|
||||
" AND colr.num_collo = colt.num_collo\n" +
|
||||
" AND colr.ser_collo = colt.ser_collo\n" +
|
||||
" GROUP BY colr.gestione,\n" +
|
||||
" colr.data_collo,\n" +
|
||||
" colr.num_collo,\n" +
|
||||
" colr.ser_collo,\n" +
|
||||
" colr.cod_mart,\n" +
|
||||
" colr.data_ord,\n" +
|
||||
" colr.num_ord),\n" +
|
||||
"\n" +
|
||||
" machine_last_event AS (SELECT gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" cod_cmac,\n" +
|
||||
" MAX(data_mov) AS max_data_mov\n" +
|
||||
" FROM dtb_ord_macc\n" +
|
||||
" GROUP BY gestione, data_ord, num_ord, cod_cmac),\n" +
|
||||
"\n" +
|
||||
" machine_event_values AS (SELECT evento,\n" +
|
||||
" IIF(tipologia = 'ENTRATA', 1, -1) AS value\n" +
|
||||
" FROM dtb_ord_macc_eventi),\n" +
|
||||
"\n" +
|
||||
" in_production_machines AS (SELECT dtb.gestione,\n" +
|
||||
" dtb.data_ord,\n" +
|
||||
" dtb.num_ord,\n" +
|
||||
" LAST_VALUE(dtb.data_mov) OVER (ORDER BY dtb.gestione,\n" +
|
||||
" dtb.data_ord,\n" +
|
||||
" dtb.num_ord) AS max_data_mov,\n" +
|
||||
" LAST_VALUE(ev.value) OVER (ORDER BY dtb.gestione,\n" +
|
||||
" dtb.data_ord,\n" +
|
||||
" dtb.num_ord) AS final_value\n" +
|
||||
" FROM dtb_ord_macc dtb\n" +
|
||||
" INNER JOIN machine_last_event le\n" +
|
||||
" ON dtb.data_ord = le.data_ord\n" +
|
||||
" AND dtb.num_ord = le.num_ord\n" +
|
||||
" AND dtb.gestione = le.gestione\n" +
|
||||
" AND dtb.cod_cmac = le.cod_cmac\n" +
|
||||
" AND dtb.data_mov = le.max_data_mov\n" +
|
||||
" INNER JOIN machine_event_values ev\n" +
|
||||
" ON dtb.evento = ev.evento\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE dtb.data_ord BETWEEN setup.date_start AND setup.date_end),\n" +
|
||||
"\n" +
|
||||
" dtb_ord_with_max_step AS (SELECT gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" id_step AS id_step,\n" +
|
||||
" MAX(id_step) OVER (PARTITION BY gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ord_steps.num_fase) AS max_id_step,\n" +
|
||||
" num_fase,\n" +
|
||||
" MAX(num_fase) OVER (PARTITION BY gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord) AS max_fase,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ord_steps.flag_step_attivo,\n" +
|
||||
" dtb_ord_steps.data_iniz,\n" +
|
||||
" dtb_ord_steps.data_fine,\n" +
|
||||
" dtb_ord_steps.qta_lav,\n" +
|
||||
" dtb_ord_steps.qta_prod,\n" +
|
||||
" dtb_ord_steps.hr_num,\n" +
|
||||
" dtb_ord_steps.descrizione_attivita,\n" +
|
||||
" SUM(CAST(DATEDIFF(S, data_iniz, ISNULL(data_fine, GETDATE())) AS BIGINT))\n" +
|
||||
" OVER (PARTITION BY gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" num_fase,\n" +
|
||||
" dtb_ord_steps.cod_jfas) AS elapsed_time\n" +
|
||||
" FROM dtb_ord_steps\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE data_ord BETWEEN setup.date_start AND setup.date_end\n" +
|
||||
" AND gestione = 'L'),\n" +
|
||||
"\n" +
|
||||
" dtb_ord_max_step AS (SELECT DISTINCT IIF(in_production_machines.max_data_mov IS NOT NULL AND\n" +
|
||||
" (dtb_ord_with_max_step.id_step = 0 OR\n" +
|
||||
" (dtb_ord_with_max_step.id_step > 0 AND\n" +
|
||||
" dtb_ord_with_max_step.data_fine IS NOT NULL AND\n" +
|
||||
" DATEDIFF(MINUTE,\n" +
|
||||
" dtb_ord_with_max_step.data_fine,\n" +
|
||||
" in_production_machines.max_data_mov) >\n" +
|
||||
" 5)), 1, 0) AS starting_machines,\n" +
|
||||
" dtb_ord_with_max_step.*\n" +
|
||||
" FROM dtb_ord_with_max_step\n" +
|
||||
" LEFT OUTER JOIN in_production_machines\n" +
|
||||
" ON dtb_ord_with_max_step.data_ord =\n" +
|
||||
" in_production_machines.data_ord\n" +
|
||||
" AND\n" +
|
||||
" dtb_ord_with_max_step.num_ord =\n" +
|
||||
" in_production_machines.num_ord\n" +
|
||||
" AND\n" +
|
||||
" dtb_ord_with_max_step.gestione =\n" +
|
||||
" in_production_machines.gestione\n" +
|
||||
" AND in_production_machines.final_value = 1\n" +
|
||||
"\n" +
|
||||
" WHERE max_id_step = id_step),\n" +
|
||||
"\n" +
|
||||
" riga_ord_prod_w_materia_prima AS (SELECT dtb_ordr.data_ord AS data_ord_prod,\n" +
|
||||
" dtb_ordr.num_ord AS num_ord_prod,\n" +
|
||||
" dtb_ordr.riga_ord AS riga_ord_prod,\n" +
|
||||
" dtb_ordr.gestione AS gestione_ord_prod,\n" +
|
||||
" IIF(CONVERT(DATE, dtb_ordr.data_ord) >= CONVERT(DATE, GETDATE()),\n" +
|
||||
" 'S',\n" +
|
||||
" 'N') AS flag_avviabile,\n" +
|
||||
" mtb_aart_prod.flag_tracciabilita,\n" +
|
||||
" dtb_ordr.unt_ord,\n" +
|
||||
" dtb_ordr.rap_conv,\n" +
|
||||
" dtb_ordr.unt_ord2,\n" +
|
||||
" CAST(ROUND(dtb_ordr.qta_ord2 /\n" +
|
||||
" ISNULL(NULLIF(dtb_ordr.qta_ord, 0), 1),\n" +
|
||||
" 5) AS NUMERIC(20, 5)) AS rap_conv2,\n" +
|
||||
" dtb_ordr.unt_ord3,\n" +
|
||||
" CAST(ROUND(dtb_ordr.qta_ord3 /\n" +
|
||||
" ISNULL(NULLIF(dtb_ordr.qta_ord, 0), 1),\n" +
|
||||
" 5) AS NUMERIC(20, 5)) AS rap_conv3,\n" +
|
||||
" dtb_ordr.qta_ord,\n" +
|
||||
" dtb_ordr.qta_ord2,\n" +
|
||||
" dtb_ordr.qta_ord3,\n" +
|
||||
" dtb_ordr.num_cnf,\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis IN ('PZ', 'NR'), mtb_aart_prod.qta_cnf,\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis2 IN ('PZ', 'NR'),\n" +
|
||||
" mtb_aart_prod.qta_cnf /\n" +
|
||||
" ISNULL(NULLIF(mtb_aart_prod.rap_conv2, 0), 1),\n" +
|
||||
" mtb_aart_prod.qta_cnf)) AS cal_qta_cnf,\n" +
|
||||
" IIF(dtb_ordr.colli_pedana = 0 OR dtb_ordr.colli_pedana = 1,\n" +
|
||||
" IIF(mtb_aart_prod.colli_pedana = 0, 1, mtb_aart_prod.colli_pedana),\n" +
|
||||
" dtb_ordr.colli_pedana)\n" +
|
||||
" AS colli_pedana,\n" +
|
||||
" dtb_ordr.pos_riga,\n" +
|
||||
" dtb_ordr.cod_mdep,\n" +
|
||||
"\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis IN ('PZ', 'NR'), 1,\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis2 IN ('PZ', 'NR') AND\n" +
|
||||
" NULLIF(mtb_aart_prod.rap_conv2, 0) IS NOT NULL,\n" +
|
||||
" mtb_aart_prod.rap_conv2,\n" +
|
||||
" 1)) AS calc_rap_conv,\n" +
|
||||
" mtb_aart_prod.gg_scad_partita,\n" +
|
||||
" mtb_aart_prod.qta_cnf\n" +
|
||||
" FROM dtb_ordr\n" +
|
||||
" INNER JOIN mtb_aart mtb_aart_prod ON mtb_aart_prod.cod_mart = dtb_ordr.cod_mart\n" +
|
||||
" WHERE dtb_ordr.gestione = 'A'),\n" +
|
||||
"\n" +
|
||||
" ord_lav AS (SELECT dtb_ordt.cod_jcom,\n" +
|
||||
" riga_ord_prod_w_materia_prima.data_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.riga_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_avviabile,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_tracciabilita,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_partita_mag.partita_mag IS NULL THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv\n" +
|
||||
" ELSE CASE\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord = mtb_aart.unt_mis THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord = mtb_aart.unt_mis2 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv2 IS NULL OR mtb_partita_mag.rap_conv2 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2, mtb_partita_mag.rap_conv2)\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord = mtb_aart.unt_mis3 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv3 IS NULL OR mtb_partita_mag.rap_conv3 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3, mtb_partita_mag.rap_conv3)\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
" AS rap_conv,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord2,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_partita_mag.partita_mag IS NULL THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2\n" +
|
||||
" ELSE CASE\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord2 = mtb_aart.unt_mis THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord2 = mtb_aart.unt_mis2 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv2 IS NULL OR mtb_partita_mag.rap_conv2 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2, mtb_partita_mag.rap_conv2)\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord2 = mtb_aart.unt_mis3 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv3 IS NULL OR mtb_partita_mag.rap_conv3 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3, mtb_partita_mag.rap_conv3)\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
" AS rap_conv2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord3,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_partita_mag.partita_mag IS NULL THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3\n" +
|
||||
" ELSE CASE\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord3 = mtb_aart.unt_mis THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord3 = mtb_aart.unt_mis2 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv2 IS NULL OR mtb_partita_mag.rap_conv2 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2, mtb_partita_mag.rap_conv2)\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord3 = mtb_aart.unt_mis3 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv3 IS NULL OR mtb_partita_mag.rap_conv3 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3, mtb_partita_mag.rap_conv3)\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
" AS rap_conv3,\n" +
|
||||
" ISNULL(dtb_ordt.descr_estesa_prod, dtb_ordt.descrizione_prod) AS descrizione_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf *\n" +
|
||||
" riga_ord_prod_w_materia_prima.cal_qta_cnf AS num_pezzi,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.gg_scad_partita,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf /\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana AS num_pedane,\n" +
|
||||
" riga_ord_prod_w_materia_prima.pos_riga,\n" +
|
||||
" dtb_ordt.flag_evaso_prod,\n" +
|
||||
" dtb_ordt.flag_evaso_forzato,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN (dtb_ordt.flag_evaso_prod = 'I' OR\n" +
|
||||
" (setupCaricoImmediato.flag_carico_scarico_immediato = 'S' AND\n" +
|
||||
" flag_evaso_prod = 'E'))\n" +
|
||||
" AND dtb_ordt.flag_evaso_forzato = 'N'\n" +
|
||||
" THEN 'I'\n" +
|
||||
" WHEN flag_evaso_prod <> 'I' AND dtb_ordt.flag_evaso_forzato = 'S'\n" +
|
||||
" THEN flag_evaso_prod\n" +
|
||||
" END AS flag_ordine_evaso,\n" +
|
||||
" dtb_ordt.gestione,\n" +
|
||||
" dtb_ordt.data_ord,\n" +
|
||||
" dtb_ordt.cod_tcol_UL,\n" +
|
||||
" mtb_tcol.descrizione AS descrizione_tcol,\n" +
|
||||
" dtb_ordt.cod_anag,\n" +
|
||||
" gtb_anag.rag_soc AS rag_soc_anag,\n" +
|
||||
" gtb_anag.part_iva,\n" +
|
||||
" dtb_ordt.rif_ord,\n" +
|
||||
" dtb_ordt.cod_vdes,\n" +
|
||||
" dtb_ordt.cod_mdep,\n" +
|
||||
" ISNULL(riga_ord_prod_w_materia_prima.cod_mdep, dtb_ordt.cod_mdep) AS cod_mdep_prod,\n" +
|
||||
" dtb_ordt.num_ord,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ordt.cod_jfas AS cod_jfas_lav,\n" +
|
||||
" mtb_partita_mag.partita_mag,\n" +
|
||||
" ISNULL(mtb_partita_mag.partita_mag_prod,\n" +
|
||||
" mtb_partita_mag.partita_mag) AS partita_mag_prod,\n" +
|
||||
" dtb_ordt.note AS note_lav,\n" +
|
||||
" mtb_partita_mag.data_scad,\n" +
|
||||
" dtb_ordt.cod_prod,\n" +
|
||||
" jtb_comt.descrizione AS descrizione_commessa,\n" +
|
||||
" dtb_ordt.data_iniz_prod,\n" +
|
||||
" dtb_ord_steps.id_step,\n" +
|
||||
" dtb_ord_steps.max_fase,\n" +
|
||||
" dtb_ord_steps.num_fase,\n" +
|
||||
" IIF(mtb_aart.flag_qta_cnf_fissa = 'S' AND\n" +
|
||||
" (mtb_aart.qta_cnf > 1 OR riga_ord_prod_w_materia_prima.colli_pedana > 1), 'Colli',\n" +
|
||||
" jtb_cicl.unt_mis_prod)\n" +
|
||||
" AS unt_mis_prod,\n" +
|
||||
" IIF(mtb_aart.flag_qta_cnf_fissa = 'S' AND\n" +
|
||||
" (mtb_aart.qta_cnf > 1 OR riga_ord_prod_w_materia_prima.colli_pedana > 1),\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana, jtb_cicl.qta_prod)\n" +
|
||||
" AS qta_batch_prod,\n" +
|
||||
" IIF(mtb_aart.qta_cnf > 1 OR riga_ord_prod_w_materia_prima.colli_pedana > 1,\n" +
|
||||
" mtb_aart.qta_cnf,\n" +
|
||||
" jtb_cicl.rap_conv_prod) AS rap_conv_prod,\n" +
|
||||
" dtb_ord_steps.data_iniz,\n" +
|
||||
" dtb_ord_steps.data_fine,\n" +
|
||||
" dtb_ord_steps.qta_lav AS qta_lav,\n" +
|
||||
" IIF(dtb_ord_steps.qta_prod <> 0, dtb_ord_steps.qta_prod,\n" +
|
||||
" dtb_ordt.qta_prod) AS qta_prod,\n" +
|
||||
" dtb_ord_steps.hr_num,\n" +
|
||||
" dtb_ord_steps.descrizione_attivita,\n" +
|
||||
" 3600 / (ISNULL(NULLIF(jtb_dist_clav_dir.duration, 0), 1) /\n" +
|
||||
" ISNULL(NULLIF(jtb_cicl.rap_conv_prod, 0), 1)) AS prod_std,\n" +
|
||||
" dtb_ord_steps.elapsed_time,\n" +
|
||||
" SUM(ISNULL(mtb_colr_carico.qta_col, 0)) AS qta_trasferite,\n" +
|
||||
" COUNT(mtb_colr_carico.num_collo) AS udc_trasferiti,\n" +
|
||||
" COUNT(colli_lotto.num_collo) AS uds_scaricati,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN dtb_ord_steps.id_step = 0\n" +
|
||||
" THEN IIF(dtb_ord_steps.starting_machines = 1, 'IN AVVIO', 'PROGRAMMATO')\n" +
|
||||
" WHEN dtb_ord_steps.data_fine IS NULL\n" +
|
||||
" THEN 'IN CORSO'\n" +
|
||||
" ELSE 'IN PAUSA'\n" +
|
||||
" END AS stato,\n" +
|
||||
" CONVERT(INT, SUM(ISNULL(\n" +
|
||||
" mtb_colr_carico.qta_col / riga_ord_prod_w_materia_prima.calc_rap_conv,\n" +
|
||||
" 0))) AS pz_trasferiti,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN (jtb_dist_clav_dir.duration / ISNULL(NULLIF(jtb_cicl.rap_conv_prod, 0), 1)) *\n" +
|
||||
" (dtb_ordt.qta_prod * dtb_ordt.rap_conv_prod -\n" +
|
||||
" SUM(ISNULL(mtb_colr_carico.qta_col, 0))) > 0\n" +
|
||||
" THEN\n" +
|
||||
" (jtb_dist_clav_dir.duration /\n" +
|
||||
" ISNULL(NULLIF(jtb_cicl.rap_conv_prod, 0), 1)) *\n" +
|
||||
" (dtb_ordt.qta_prod * dtb_ordt.rap_conv_prod -\n" +
|
||||
" SUM(ISNULL(mtb_colr_carico.qta_col, 0)))\n" +
|
||||
" ELSE 0 END AS run_time_sec,\n" +
|
||||
" jl.id_lotto,\n" +
|
||||
" jlt.data_lotto,\n" +
|
||||
" mtb_aart.peso_kg,\n" +
|
||||
" dtb_ordt.data_cons_prod_max\n" +
|
||||
" FROM dtb_ord_max_step dtb_ord_steps\n" +
|
||||
" INNER JOIN dtb_ordt ON dtb_ord_steps.data_ord = dtb_ordt.data_ord\n" +
|
||||
" AND dtb_ord_steps.num_ord = dtb_ordt.num_ord\n" +
|
||||
" AND dtb_ord_steps.gestione = dtb_ordt.gestione\n" +
|
||||
" LEFT OUTER JOIN setup_depo setupCaricoImmediato\n" +
|
||||
" ON dtb_ordt.cod_mdep = setupCaricoImmediato.cod_mdep\n" +
|
||||
" LEFT OUTER JOIN jtb_dist_clav_dir\n" +
|
||||
" ON dtb_ordt.cod_prod = jtb_dist_clav_dir.cod_prod AND\n" +
|
||||
" dtb_ordt.cod_jfas = jtb_dist_clav_dir.cod_jfas\n" +
|
||||
" LEFT OUTER JOIN mtb_partita_mag\n" +
|
||||
" ON dtb_ordt.partita_mag = mtb_partita_mag.partita_mag AND\n" +
|
||||
" dtb_ordt.cod_prod = mtb_partita_mag.cod_mart AND\n" +
|
||||
" mtb_partita_mag.flag_stato = 'A'\n" +
|
||||
" LEFT OUTER JOIN mtb_colr_sum mtb_colr_carico\n" +
|
||||
" ON dtb_ordt.data_ord = mtb_colr_carico.data_ord AND\n" +
|
||||
" dtb_ordt.gestione = mtb_colr_carico.gestione AND\n" +
|
||||
" dtb_ordt.num_ord = mtb_colr_carico.num_ord AND\n" +
|
||||
" dtb_ordt.cod_prod = mtb_colr_carico.cod_mart\n" +
|
||||
" LEFT OUTER JOIN jtb_comt ON dtb_ordt.cod_jcom = jtb_comt.cod_jcom\n" +
|
||||
" LEFT OUTER JOIN riga_ord_prod_w_materia_prima\n" +
|
||||
" ON riga_ord_prod_w_materia_prima.gestione_ord_prod =\n" +
|
||||
" dtb_ordt.gestione_rif AND\n" +
|
||||
" riga_ord_prod_w_materia_prima.data_ord_prod =\n" +
|
||||
" dtb_ordt.data_ord_rif AND\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_ord_prod =\n" +
|
||||
" dtb_ordt.num_ord_rif AND\n" +
|
||||
" riga_ord_prod_w_materia_prima.riga_ord_prod = dtb_ordt.riga_ord_rif\n" +
|
||||
" LEFT OUTER JOIN jtb_cicl ON jtb_cicl.cod_prod = dtb_ordt.cod_prod\n" +
|
||||
" LEFT OUTER JOIN mtb_aart ON mtb_aart.cod_mart = dtb_ordt.cod_prod\n" +
|
||||
" LEFT OUTER JOIN gtb_anag ON dtb_ordt.cod_anag = gtb_anag.cod_anag\n" +
|
||||
" LEFT OUTER JOIN mtb_tcol ON dtb_ordt.cod_tcol_UL = mtb_tcol.cod_tcol\n" +
|
||||
" LEFT OUTER JOIN jtb_lotr jl\n" +
|
||||
" ON dtb_ord_steps.cod_jfas = jl.cod_jfas AND\n" +
|
||||
" dtb_ordt.gestione = jl.gestione AND\n" +
|
||||
" dtb_ordt.data_ord = jl.data_ord AND\n" +
|
||||
" dtb_ordt.num_ord = jl.num_ord\n" +
|
||||
" LEFT OUTER JOIN jtb_lott jlt\n" +
|
||||
" ON jl.cod_jfas = jlt.cod_jfas AND jl.id_lotto = jlt.id_lotto\n" +
|
||||
" LEFT OUTER JOIN mtb_colt colli_lotto ON jlt.id_lotto = colli_lotto.id_lotto\n" +
|
||||
"\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE dtb_ordt.flag_annulla = 'N'\n" +
|
||||
" AND dtb_ord_steps.data_ord BETWEEN setup.date_start AND setup.date_end\n" +
|
||||
" AND (setup.flag_evaso IS NULL\n" +
|
||||
" OR (\n" +
|
||||
" (setup.flag_evaso = 'I'\n" +
|
||||
" AND\n" +
|
||||
" dtb_ord_steps.flag_step_attivo = 'S'\n" +
|
||||
" AND (flag_evaso_prod = 'I'\n" +
|
||||
" OR\n" +
|
||||
" (setupCaricoImmediato.flag_carico_scarico_immediato = 'S'\n" +
|
||||
" AND\n" +
|
||||
" flag_evaso_prod = 'E'))\n" +
|
||||
" AND dtb_ordt.flag_evaso_forzato = 'N'\n" +
|
||||
" )\n" +
|
||||
" OR (setup.flag_evaso = 'E '\n" +
|
||||
" AND (flag_evaso_prod = 'E' OR jlt.data_chiusura IS NOT NULL))\n" +
|
||||
" )\n" +
|
||||
" )\n" +
|
||||
" AND (setup.cod_jfas IS NULL\n" +
|
||||
" OR dtb_ordt.cod_jfas = setup.cod_jfas)\n" +
|
||||
" AND (setup.cod_anag IS NULL\n" +
|
||||
" OR dtb_ordt.cod_anag = setup.cod_anag)\n" +
|
||||
" GROUP BY riga_ord_prod_w_materia_prima.data_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.riga_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_avviabile,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_tracciabilita,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord,\n" +
|
||||
" mtb_partita_mag.rap_conv2,\n" +
|
||||
" mtb_partita_mag.rap_conv3,\n" +
|
||||
" dtb_ordt.note,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv,\n" +
|
||||
" dtb_ordt.descrizione_prod,\n" +
|
||||
" dtb_ordt.descr_estesa_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf,\n" +
|
||||
" mtb_aart.qta_cnf,\n" +
|
||||
" mtb_aart.gg_scad_partita,\n" +
|
||||
" mtb_aart.flag_qta_cnf_fissa,\n" +
|
||||
" riga_ord_prod_w_materia_prima.pos_riga,\n" +
|
||||
" dtb_ordt.flag_evaso_prod,\n" +
|
||||
" dtb_ordt.flag_evaso_forzato,\n" +
|
||||
" dtb_ordt.gestione,\n" +
|
||||
" dtb_ordt.data_ord,\n" +
|
||||
" dtb_ordt.num_ord,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ordt.cod_jfas,\n" +
|
||||
" dtb_ordt.cod_jcom,\n" +
|
||||
" mtb_partita_mag.partita_mag,\n" +
|
||||
" mtb_partita_mag.partita_mag_prod,\n" +
|
||||
" mtb_partita_mag.data_scad,\n" +
|
||||
" dtb_ordt.cod_prod,\n" +
|
||||
" dtb_ordt.data_iniz_prod,\n" +
|
||||
" dtb_ord_steps.id_step,\n" +
|
||||
" dtb_ord_steps.data_iniz,\n" +
|
||||
" dtb_ord_steps.data_fine,\n" +
|
||||
" dtb_ordt.cod_tcol_UL,\n" +
|
||||
" dtb_ordt.cod_anag,\n" +
|
||||
" gtb_anag.rag_soc,\n" +
|
||||
" gtb_anag.part_iva,\n" +
|
||||
" dtb_ordt.rif_ord,\n" +
|
||||
" dtb_ordt.cod_vdes,\n" +
|
||||
" dtb_ordt.cod_mdep,\n" +
|
||||
" riga_ord_prod_w_materia_prima.cod_mdep,\n" +
|
||||
" mtb_aart.colli_pedana,\n" +
|
||||
" dtb_ord_steps.qta_prod,\n" +
|
||||
" dtb_ordt.qta_prod,\n" +
|
||||
" jtb_dist_clav_dir.duration,\n" +
|
||||
" jtb_comt.descrizione,\n" +
|
||||
" dtb_ord_steps.elapsed_time,\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana,\n" +
|
||||
" dtb_ord_steps.hr_num,\n" +
|
||||
" mtb_aart.unt_mis,\n" +
|
||||
" mtb_aart.unt_mis2,\n" +
|
||||
" mtb_aart.rap_conv2,\n" +
|
||||
" mtb_aart.unt_mis3,\n" +
|
||||
" mtb_aart.rap_conv3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_ord,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_ord2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_ord3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.cal_qta_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.gg_scad_partita,\n" +
|
||||
" jtb_cicl.qta_prod,\n" +
|
||||
" jtb_cicl.rap_conv_prod,\n" +
|
||||
" dtb_ord_steps.descrizione_attivita,\n" +
|
||||
" jtb_cicl.unt_mis_prod,\n" +
|
||||
" mtb_tcol.descrizione,\n" +
|
||||
" dtb_ordt.qta_prod,\n" +
|
||||
" dtb_ordt.rap_conv_prod,\n" +
|
||||
" setupCaricoImmediato.flag_carico_scarico_immediato,\n" +
|
||||
" dtb_ord_steps.num_fase, dtb_ord_steps.qta_lav,\n" +
|
||||
" jl.id_lotto, jlt.data_lotto, mtb_aart.peso_kg, dtb_ordt.data_cons_prod_max,\n" +
|
||||
" dtb_ord_steps.id_step,\n" +
|
||||
" dtb_ord_steps.max_fase,\n" +
|
||||
" dtb_ord_steps.starting_machines)\n" +
|
||||
" SELECT ROW_NUMBER() OVER (ORDER BY data_ord, num_ord_prod, pos_riga, num_ord) AS sort,\n" +
|
||||
" cod_jcom,\n" +
|
||||
" data_ord_prod,\n" +
|
||||
" num_ord_prod,\n" +
|
||||
" riga_ord_prod,\n" +
|
||||
" flag_avviabile,\n" +
|
||||
" flag_tracciabilita,\n" +
|
||||
" unt_ord,\n" +
|
||||
" rap_conv,\n" +
|
||||
" unt_ord2,\n" +
|
||||
" rap_conv2,\n" +
|
||||
" unt_ord3,\n" +
|
||||
" rap_conv3,\n" +
|
||||
" descrizione_prod,\n" +
|
||||
" num_pezzi,\n" +
|
||||
" num_cnf,\n" +
|
||||
" gg_scad_partita,\n" +
|
||||
" qta_cnf,\n" +
|
||||
" colli_pedana,\n" +
|
||||
" num_pedane,\n" +
|
||||
" pos_riga,\n" +
|
||||
" flag_evaso_prod,\n" +
|
||||
" flag_evaso_forzato,\n" +
|
||||
" flag_ordine_evaso,\n" +
|
||||
" gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" cod_tcol_UL,\n" +
|
||||
" descrizione_tcol,\n" +
|
||||
" cod_anag,\n" +
|
||||
" rag_soc_anag,\n" +
|
||||
" part_iva,\n" +
|
||||
" rif_ord,\n" +
|
||||
" cod_vdes,\n" +
|
||||
" cod_mdep,\n" +
|
||||
" cod_mdep_prod,\n" +
|
||||
" num_ord,\n" +
|
||||
" cod_jfas,\n" +
|
||||
" cod_jfas_lav,\n" +
|
||||
" partita_mag,\n" +
|
||||
" partita_mag_prod,\n" +
|
||||
" note_lav,\n" +
|
||||
" data_scad,\n" +
|
||||
" cod_prod,\n" +
|
||||
" descrizione_commessa,\n" +
|
||||
" data_iniz_prod,\n" +
|
||||
" id_step,\n" +
|
||||
" unt_mis_prod,\n" +
|
||||
" qta_batch_prod,\n" +
|
||||
" rap_conv_prod,\n" +
|
||||
" data_iniz,\n" +
|
||||
" data_fine,\n" +
|
||||
" qta_prod,\n" +
|
||||
" qta_lav,\n" +
|
||||
" max_fase,\n" +
|
||||
" num_fase,\n" +
|
||||
" hr_num,\n" +
|
||||
" descrizione_attivita,\n" +
|
||||
" prod_std,\n" +
|
||||
" elapsed_time,\n" +
|
||||
" qta_trasferite,\n" +
|
||||
" udc_trasferiti,\n" +
|
||||
" uds_scaricati,\n" +
|
||||
" stato,\n" +
|
||||
" pz_trasferiti,\n" +
|
||||
" run_time_sec,\n" +
|
||||
" SUM(run_time_sec) OVER (PARTITION BY cod_jfas, data_ord_prod) AS cumulative_run_time_sec,\n" +
|
||||
" CONVERT(INT, run_time_sec / 3600) AS run_time_hour,\n" +
|
||||
" ROUND((run_time_sec / 3600 - CONVERT(INT, run_time_sec / 3600)) * 60, 0) AS run_time_min,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN setup_run_time.flag_restart = 'S' THEN\n" +
|
||||
" DATEADD(SECOND, SUM(run_time_sec)\n" +
|
||||
" OVER (PARTITION BY cod_jfas, data_ord_prod ORDER BY stato, cod_jfas, data_ord_prod, pos_riga ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),\n" +
|
||||
" CASE\n" +
|
||||
" WHEN (data_ord_prod > GETDATE() AND (data_iniz IS NULL OR data_fine IS NOT NULL))\n" +
|
||||
" THEN DATEADD(HH, 7, data_ord_prod)\n" +
|
||||
" ELSE GETDATE() END)\n" +
|
||||
" ELSE\n" +
|
||||
" DATEADD(SECOND, SUM(run_time_sec)\n" +
|
||||
" OVER (PARTITION BY cod_jfas ORDER BY stato, cod_jfas, data_ord_prod, num_ord_prod, pos_riga ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),\n" +
|
||||
" GETDATE())\n" +
|
||||
" END AS run_time_end,\n" +
|
||||
" id_lotto,\n" +
|
||||
" data_lotto,\n" +
|
||||
" peso_kg,\n" +
|
||||
" data_cons_prod_max\n" +
|
||||
" FROM ord_lav\n" +
|
||||
" CROSS APPLY setup_run_time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250414113736 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createOrUpdateFunction("relativeWorkDateConsLav", "CREATE FUNCTION [dbo].[relativeWorkDateConsLav] (@StartDate DATE, @DaysToAdd INT)\n" +
|
||||
"RETURNS DATETIME\n" +
|
||||
"AS\n" +
|
||||
"BEGIN\n" +
|
||||
" DECLARE @CurrentDate DATE = @StartDate;\n" +
|
||||
" DECLARE @Counter INT = 0;\n" +
|
||||
" DECLARE @gg INT = 0;\n" +
|
||||
"\n" +
|
||||
" IF @StartDate is null \n" +
|
||||
" BEGIN\n" +
|
||||
" RETURN @startdate\n" +
|
||||
" END\n" +
|
||||
" IF @DaysToAdd < 0 \n" +
|
||||
" BEGIN\n" +
|
||||
" SELECT @gg = -1 -- Per sottrarre giorni\n" +
|
||||
" SELECT @DaysToAdd = ABS(@DaysToAdd) -- Rendi il numero di giorni positivo\n" +
|
||||
" END\n" +
|
||||
" ELSE\n" +
|
||||
" SELECT @gg = 1 -- Per aggiungere giorni\n" +
|
||||
"\n" +
|
||||
" -- Inizia a contare i giorni lavorativi, considerando weekend e festività\n" +
|
||||
" WHILE @Counter < @DaysToAdd\n" +
|
||||
" BEGIN\n" +
|
||||
" SET @CurrentDate = DATEADD(DAY, @gg, @CurrentDate); -- Aggiungi o sottrai un giorno\n" +
|
||||
"\n" +
|
||||
" -- Verifica se la data corrente è un sabato, una domenica o una festività\n" +
|
||||
" IF (DATEPART(WEEKDAY, @CurrentDate) NOT IN (SELECT dayweek.rowId \n" +
|
||||
" FROM getTableRowByNumber(1, 7) dayweek \n" +
|
||||
" LEFT OUTER JOIN (SELECT CONVERT(INTEGER, value_string) AS rowid\n" +
|
||||
" FROM ParseStringIntoArray((SELECT dbo.getGestSetup('DATI_AZIENDA','DOCU_ORD','GG_CONSEGNA')), '|') \n" +
|
||||
" WHERE LEN(value_string) <> 0) dayLav \n" +
|
||||
" ON dayweek.rowid = dayLav.rowid\n" +
|
||||
" WHERE dayLav.rowid IS NULL) OR (SELECT COUNT(*)\n" +
|
||||
" FROM ParseStringIntoArray((SELECT dbo.getGestSetup('DATI_AZIENDA','DOCU_ORD','GG_CONSEGNA')), '|') \n" +
|
||||
" WHERE LEN(value_string) <> 0\n" +
|
||||
" ) = 0)\n" +
|
||||
" AND @CurrentDate NOT IN (SELECT data FROM jtb_ricorrenze WHERE DATEPART(YEAR, @CurrentDate) = anno) -- Verifica che non sia una festività\n" +
|
||||
" BEGIN\n" +
|
||||
" SET @Counter = @Counter + 1; -- Incrementa il contatore se è un giorno lavorativo\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
"\n" +
|
||||
" RETURN @CurrentDate; -- Restituisce la data finale\n" +
|
||||
"END");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.entity_logger.db_schema_manager.dto.DatabaseVersionEnum;
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250414140322 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
if (!isSqlVersionEqualsOrGreatherThan(DatabaseVersionEnum.SQLServer2016))
|
||||
return;
|
||||
|
||||
createOrUpdateFunction("parseStringIntoArray", "CREATE FUNCTION [dbo].[ParseStringIntoArray](@stringToSplit varchar(max), @sep varchar(5))\n" +
|
||||
"RETURNS @returnList TABLE (value_string varchar(4096)) AS \n" +
|
||||
"BEGIN \n" +
|
||||
" if len(@sep ) = 1\n" +
|
||||
" begin\n" +
|
||||
" insert into @returnList\n" +
|
||||
" SELECT value as value_string FROM STRING_SPLIT(@stringToSplit, @sep)\n" +
|
||||
" end\n" +
|
||||
" else\n" +
|
||||
" begin\n" +
|
||||
" IF @stringToSplit IS NULL begin RETURN END\n" +
|
||||
"\n" +
|
||||
" DECLARE @name NVARCHAR(255)\n" +
|
||||
" DECLARE @pos INT, @len int\n" +
|
||||
"\n" +
|
||||
" WHILE CHARINDEX(@sep, @stringToSplit) > 0\n" +
|
||||
" BEGIN\n" +
|
||||
" /*SELECT @len = len(@sep)*/\n" +
|
||||
" SELECT @len = DATALENGTH(@sep)\n" +
|
||||
" SELECT @pos = CHARINDEX(@sep, @stringToSplit) \n" +
|
||||
" SELECT @name = SUBSTRING(@stringToSplit, @len, @pos-@len)\n" +
|
||||
"\n" +
|
||||
" INSERT INTO @returnList \n" +
|
||||
" SELECT @name\n" +
|
||||
" \n" +
|
||||
" SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+@len, LEN(@stringToSplit)-@pos)\n" +
|
||||
" END\n" +
|
||||
"\n" +
|
||||
" INSERT INTO @returnList\n" +
|
||||
" SELECT @stringToSplit\n" +
|
||||
" end\n" +
|
||||
" RETURN \n" +
|
||||
"end");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,605 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250414155711 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createOrUpdateFunction("MES_GetWorkOrders",
|
||||
"CREATE FUNCTION [dbo].[MES_GetWorkOrders](@codJfas VARCHAR(50), @dateStart DATE, @dateEnd DATE, @flagEvaso VARCHAR(1),\n" +
|
||||
" @codAnag VARCHAR(5))\n" +
|
||||
" RETURNS TABLE\n" +
|
||||
" AS RETURN\n" +
|
||||
" -- DECLARE @codJfas VARCHAR(5) = 'L1'\n" +
|
||||
" -- DECLARE @dateStart DATE = DATEADD(MONTH, -1, GETDATE())\n" +
|
||||
" -- DECLARE @dateEnd DATE = DATEADD(MONTH, 1, GETDATE())\n" +
|
||||
" -- DECLARE @flagEvaso VARCHAR(1) = 'I'\n" +
|
||||
" -- DECLARE @codAnag VARCHAR(5) = null;\n" +
|
||||
"\n" +
|
||||
"--Funzione per calcolare la sequenza di ordini su una linea e il RunTimeEND\n" +
|
||||
" WITH setup AS (SELECT ISNULL(@dateStart, DATEADD(DAY, -14, GETDATE())) AS date_start,\n" +
|
||||
" ISNULL(@dateEnd, GETDATE()) AS date_end,\n" +
|
||||
" ISNULL(@flagEvaso, 'I') AS flag_evaso,\n" +
|
||||
" @codJfas AS cod_jfas,\n" +
|
||||
" @codAnag AS cod_anag),\n" +
|
||||
"\n" +
|
||||
" setup_depo AS (SELECT cod_mdep, value AS flag_carico_scarico_immediato\n" +
|
||||
" FROM stb_gest_setup_depo\n" +
|
||||
" WHERE gest_name = 'CARICO_SCARICO_PF'\n" +
|
||||
" AND section = 'SETUP'\n" +
|
||||
" AND key_section = 'GENERA_CARICO_SCARICO_IMMEDIATO'),\n" +
|
||||
"\n" +
|
||||
" setup_run_time AS (SELECT value AS flag_restart\n" +
|
||||
" FROM stb_gest_setup\n" +
|
||||
" WHERE gest_name = 'PVM'\n" +
|
||||
" AND section = 'MONITORAGGIO_LINEE_V2'\n" +
|
||||
" AND key_section = 'RESTART_RUN_TIME_END'),\n" +
|
||||
"\n" +
|
||||
" mtb_colr_sum_filtered_rows AS (SELECT gestione,\n" +
|
||||
" data_collo,\n" +
|
||||
" num_collo,\n" +
|
||||
" ser_collo,\n" +
|
||||
" cod_mart,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" qta_col,\n" +
|
||||
" num_cnf\n" +
|
||||
" FROM mtb_colr\n" +
|
||||
" WHERE gestione_rif IS NULL\n" +
|
||||
" AND data_collo_rif IS NULL\n" +
|
||||
" AND ser_collo_rif IS NULL\n" +
|
||||
" AND num_collo_rif IS NULL),\n" +
|
||||
"\n" +
|
||||
" mtb_colr_sum_valid_colli AS (SELECT DISTINCT gestione,\n" +
|
||||
" data_collo,\n" +
|
||||
" ser_collo,\n" +
|
||||
" num_collo\n" +
|
||||
" FROM mtb_colt\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE segno = 1\n" +
|
||||
" AND data_ord BETWEEN setup.date_start AND setup.date_end),\n" +
|
||||
"\n" +
|
||||
" mtb_colr_sum AS (SELECT colr.gestione,\n" +
|
||||
" colr.data_collo,\n" +
|
||||
" colr.num_collo,\n" +
|
||||
" colr.ser_collo,\n" +
|
||||
" colr.cod_mart,\n" +
|
||||
" colr.data_ord,\n" +
|
||||
" colr.num_ord,\n" +
|
||||
" SUM(colr.qta_col) AS qta_col,\n" +
|
||||
" SUM(colr.num_cnf) AS num_cnf\n" +
|
||||
" FROM mtb_colr_sum_valid_colli colt\n" +
|
||||
" INNER JOIN mtb_colr_sum_filtered_rows colr\n" +
|
||||
" ON colr.gestione = colt.gestione\n" +
|
||||
" AND colr.data_collo = colt.data_collo\n" +
|
||||
" AND colr.num_collo = colt.num_collo\n" +
|
||||
" AND colr.ser_collo = colt.ser_collo\n" +
|
||||
" GROUP BY colr.gestione,\n" +
|
||||
" colr.data_collo,\n" +
|
||||
" colr.num_collo,\n" +
|
||||
" colr.ser_collo,\n" +
|
||||
" colr.cod_mart,\n" +
|
||||
" colr.data_ord,\n" +
|
||||
" colr.num_ord),\n" +
|
||||
"\n" +
|
||||
" machine_last_event AS (SELECT gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" cod_cmac,\n" +
|
||||
" MAX(data_mov) AS max_data_mov\n" +
|
||||
" FROM dtb_ord_macc\n" +
|
||||
" GROUP BY gestione, data_ord, num_ord, cod_cmac),\n" +
|
||||
"\n" +
|
||||
" machine_event_values AS (SELECT evento,\n" +
|
||||
" IIF(tipologia = 'ENTRATA', 1, -1) AS value\n" +
|
||||
" FROM dtb_ord_macc_eventi),\n" +
|
||||
"\n" +
|
||||
" in_production_machines AS (SELECT dtb.gestione,\n" +
|
||||
" dtb.data_ord,\n" +
|
||||
" dtb.num_ord,\n" +
|
||||
" LAST_VALUE(dtb.data_mov) OVER (ORDER BY dtb.gestione,\n" +
|
||||
" dtb.data_ord,\n" +
|
||||
" dtb.num_ord) AS max_data_mov,\n" +
|
||||
" LAST_VALUE(ev.value) OVER (ORDER BY dtb.gestione,\n" +
|
||||
" dtb.data_ord,\n" +
|
||||
" dtb.num_ord) AS final_value\n" +
|
||||
" FROM dtb_ord_macc dtb\n" +
|
||||
" INNER JOIN machine_last_event le\n" +
|
||||
" ON dtb.data_ord = le.data_ord\n" +
|
||||
" AND dtb.num_ord = le.num_ord\n" +
|
||||
" AND dtb.gestione = le.gestione\n" +
|
||||
" AND dtb.cod_cmac = le.cod_cmac\n" +
|
||||
" AND dtb.data_mov = le.max_data_mov\n" +
|
||||
" INNER JOIN machine_event_values ev\n" +
|
||||
" ON dtb.evento = ev.evento\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE dtb.data_ord BETWEEN setup.date_start AND setup.date_end),\n" +
|
||||
"\n" +
|
||||
" dtb_ord_with_max_step AS (SELECT gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" id_step AS id_step,\n" +
|
||||
" MAX(id_step) OVER (PARTITION BY gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ord_steps.num_fase) AS max_id_step,\n" +
|
||||
" num_fase,\n" +
|
||||
" MAX(num_fase) OVER (PARTITION BY gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord) AS max_fase,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ord_steps.flag_step_attivo,\n" +
|
||||
" dtb_ord_steps.data_iniz,\n" +
|
||||
" dtb_ord_steps.data_fine,\n" +
|
||||
" dtb_ord_steps.qta_lav,\n" +
|
||||
" dtb_ord_steps.qta_prod,\n" +
|
||||
" dtb_ord_steps.hr_num,\n" +
|
||||
" dtb_ord_steps.descrizione_attivita,\n" +
|
||||
" SUM(CAST(DATEDIFF(S, data_iniz, ISNULL(data_fine, GETDATE())) AS BIGINT))\n" +
|
||||
" OVER (PARTITION BY gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" num_ord,\n" +
|
||||
" num_fase,\n" +
|
||||
" dtb_ord_steps.cod_jfas) AS elapsed_time\n" +
|
||||
" FROM dtb_ord_steps\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE data_ord BETWEEN setup.date_start AND setup.date_end\n" +
|
||||
" AND gestione = 'L'),\n" +
|
||||
"\n" +
|
||||
" dtb_ord_max_step AS (SELECT DISTINCT IIF(in_production_machines.max_data_mov IS NOT NULL AND\n" +
|
||||
" (dtb_ord_with_max_step.id_step = 0 OR\n" +
|
||||
" (dtb_ord_with_max_step.id_step > 0 AND\n" +
|
||||
" dtb_ord_with_max_step.data_fine IS NOT NULL AND\n" +
|
||||
" DATEDIFF(MINUTE,\n" +
|
||||
" dtb_ord_with_max_step.data_fine,\n" +
|
||||
" in_production_machines.max_data_mov) >\n" +
|
||||
" 5)), 1, 0) AS starting_machines,\n" +
|
||||
" dtb_ord_with_max_step.*\n" +
|
||||
" FROM dtb_ord_with_max_step\n" +
|
||||
" LEFT OUTER JOIN in_production_machines\n" +
|
||||
" ON dtb_ord_with_max_step.data_ord =\n" +
|
||||
" in_production_machines.data_ord\n" +
|
||||
" AND\n" +
|
||||
" dtb_ord_with_max_step.num_ord =\n" +
|
||||
" in_production_machines.num_ord\n" +
|
||||
" AND\n" +
|
||||
" dtb_ord_with_max_step.gestione =\n" +
|
||||
" in_production_machines.gestione\n" +
|
||||
" AND in_production_machines.final_value = 1\n" +
|
||||
"\n" +
|
||||
" WHERE max_id_step = id_step),\n" +
|
||||
"\n" +
|
||||
" riga_ord_prod_w_materia_prima AS (SELECT dtb_ordr.data_ord AS data_ord_prod,\n" +
|
||||
" dtb_ordr.num_ord AS num_ord_prod,\n" +
|
||||
" dtb_ordr.riga_ord AS riga_ord_prod,\n" +
|
||||
" dtb_ordr.gestione AS gestione_ord_prod,\n" +
|
||||
" IIF(CONVERT(DATE, dtb_ordr.data_ord) >= CONVERT(DATE, GETDATE()),\n" +
|
||||
" 'S',\n" +
|
||||
" 'N') AS flag_avviabile,\n" +
|
||||
" mtb_aart_prod.flag_tracciabilita,\n" +
|
||||
" dtb_ordr.unt_ord,\n" +
|
||||
" dtb_ordr.rap_conv,\n" +
|
||||
" dtb_ordr.unt_ord2,\n" +
|
||||
" CAST(ROUND(dtb_ordr.qta_ord2 /\n" +
|
||||
" ISNULL(NULLIF(dtb_ordr.qta_ord, 0), 1),\n" +
|
||||
" 5) AS NUMERIC(20, 5)) AS rap_conv2,\n" +
|
||||
" dtb_ordr.unt_ord3,\n" +
|
||||
" CAST(ROUND(dtb_ordr.qta_ord3 /\n" +
|
||||
" ISNULL(NULLIF(dtb_ordr.qta_ord, 0), 1),\n" +
|
||||
" 5) AS NUMERIC(20, 5)) AS rap_conv3,\n" +
|
||||
" dtb_ordr.qta_ord,\n" +
|
||||
" dtb_ordr.qta_ord2,\n" +
|
||||
" dtb_ordr.qta_ord3,\n" +
|
||||
" dtb_ordr.num_cnf,\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis IN ('PZ', 'NR'), mtb_aart_prod.qta_cnf,\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis2 IN ('PZ', 'NR'),\n" +
|
||||
" mtb_aart_prod.qta_cnf /\n" +
|
||||
" ISNULL(NULLIF(mtb_aart_prod.rap_conv2, 0), 1),\n" +
|
||||
" mtb_aart_prod.qta_cnf)) AS cal_qta_cnf,\n" +
|
||||
" IIF(dtb_ordr.colli_pedana = 0 OR dtb_ordr.colli_pedana = 1,\n" +
|
||||
" IIF(mtb_aart_prod.colli_pedana = 0, 1, mtb_aart_prod.colli_pedana),\n" +
|
||||
" dtb_ordr.colli_pedana)\n" +
|
||||
" AS colli_pedana,\n" +
|
||||
" dtb_ordr.pos_riga,\n" +
|
||||
" dtb_ordr.cod_mdep,\n" +
|
||||
"\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis IN ('PZ', 'NR'), 1,\n" +
|
||||
" IIF(mtb_aart_prod.unt_mis2 IN ('PZ', 'NR') AND\n" +
|
||||
" NULLIF(mtb_aart_prod.rap_conv2, 0) IS NOT NULL,\n" +
|
||||
" mtb_aart_prod.rap_conv2,\n" +
|
||||
" 1)) AS calc_rap_conv,\n" +
|
||||
" mtb_aart_prod.gg_scad_partita,\n" +
|
||||
" mtb_aart_prod.qta_cnf\n" +
|
||||
" FROM dtb_ordr\n" +
|
||||
" INNER JOIN mtb_aart mtb_aart_prod ON mtb_aart_prod.cod_mart = dtb_ordr.cod_mart\n" +
|
||||
" WHERE dtb_ordr.gestione = 'A'),\n" +
|
||||
"\n" +
|
||||
" ord_lav AS (SELECT dtb_ordt.cod_jcom,\n" +
|
||||
" riga_ord_prod_w_materia_prima.data_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.riga_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_avviabile,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_tracciabilita,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_partita_mag.partita_mag IS NULL THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv\n" +
|
||||
" ELSE CASE\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord = mtb_aart.unt_mis THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord = mtb_aart.unt_mis2 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv2 IS NULL OR mtb_partita_mag.rap_conv2 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2, mtb_partita_mag.rap_conv2)\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord = mtb_aart.unt_mis3 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv3 IS NULL OR mtb_partita_mag.rap_conv3 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3, mtb_partita_mag.rap_conv3)\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
" AS rap_conv,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord2,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_partita_mag.partita_mag IS NULL THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2\n" +
|
||||
" ELSE CASE\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord2 = mtb_aart.unt_mis THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord2 = mtb_aart.unt_mis2 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv2 IS NULL OR mtb_partita_mag.rap_conv2 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2, mtb_partita_mag.rap_conv2)\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord2 = mtb_aart.unt_mis3 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv3 IS NULL OR mtb_partita_mag.rap_conv3 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3, mtb_partita_mag.rap_conv3)\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
" AS rap_conv2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord3,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN mtb_partita_mag.partita_mag IS NULL THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3\n" +
|
||||
" ELSE CASE\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord3 = mtb_aart.unt_mis THEN\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord3 = mtb_aart.unt_mis2 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv2 IS NULL OR mtb_partita_mag.rap_conv2 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2, mtb_partita_mag.rap_conv2)\n" +
|
||||
" WHEN riga_ord_prod_w_materia_prima.unt_ord3 = mtb_aart.unt_mis3 THEN\n" +
|
||||
" IIF(mtb_partita_mag.rap_conv3 IS NULL OR mtb_partita_mag.rap_conv3 = 0,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3, mtb_partita_mag.rap_conv3)\n" +
|
||||
" END\n" +
|
||||
" END\n" +
|
||||
" AS rap_conv3,\n" +
|
||||
" ISNULL(dtb_ordt.descr_estesa_prod, dtb_ordt.descrizione_prod) AS descrizione_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf *\n" +
|
||||
" riga_ord_prod_w_materia_prima.cal_qta_cnf AS num_pezzi,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.gg_scad_partita,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf /\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana AS num_pedane,\n" +
|
||||
" riga_ord_prod_w_materia_prima.pos_riga,\n" +
|
||||
" dtb_ordt.flag_evaso_prod,\n" +
|
||||
" dtb_ordt.flag_evaso_forzato,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN (dtb_ordt.flag_evaso_prod = 'I' OR\n" +
|
||||
" (setupCaricoImmediato.flag_carico_scarico_immediato = 'S' AND\n" +
|
||||
" flag_evaso_prod = 'E'))\n" +
|
||||
" AND dtb_ordt.flag_evaso_forzato = 'N'\n" +
|
||||
" THEN 'I'\n" +
|
||||
" WHEN flag_evaso_prod <> 'I' AND dtb_ordt.flag_evaso_forzato = 'S'\n" +
|
||||
" THEN flag_evaso_prod\n" +
|
||||
" END AS flag_ordine_evaso,\n" +
|
||||
" dtb_ordt.gestione,\n" +
|
||||
" dtb_ordt.data_ord,\n" +
|
||||
" dtb_ordt.cod_tcol_UL,\n" +
|
||||
" mtb_tcol.descrizione AS descrizione_tcol,\n" +
|
||||
" dtb_ordt.cod_anag,\n" +
|
||||
" gtb_anag.rag_soc AS rag_soc_anag,\n" +
|
||||
" gtb_anag.part_iva,\n" +
|
||||
" dtb_ordt.rif_ord,\n" +
|
||||
" dtb_ordt.cod_vdes,\n" +
|
||||
" dtb_ordt.cod_mdep,\n" +
|
||||
" ISNULL(riga_ord_prod_w_materia_prima.cod_mdep, dtb_ordt.cod_mdep) AS cod_mdep_prod,\n" +
|
||||
" dtb_ordt.num_ord,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ordt.cod_jfas AS cod_jfas_lav,\n" +
|
||||
" mtb_partita_mag.partita_mag,\n" +
|
||||
" ISNULL(mtb_partita_mag.partita_mag_prod,\n" +
|
||||
" mtb_partita_mag.partita_mag) AS partita_mag_prod,\n" +
|
||||
" dtb_ordt.note AS note_lav,\n" +
|
||||
" mtb_partita_mag.data_scad,\n" +
|
||||
" dtb_ordt.cod_prod,\n" +
|
||||
" jtb_comt.descrizione AS descrizione_commessa,\n" +
|
||||
" dtb_ordt.data_iniz_prod,\n" +
|
||||
" dtb_ord_steps.id_step,\n" +
|
||||
" dtb_ord_steps.max_fase,\n" +
|
||||
" dtb_ord_steps.num_fase,\n" +
|
||||
" IIF(mtb_aart.flag_qta_cnf_fissa = 'S' AND\n" +
|
||||
" (mtb_aart.qta_cnf > 1 OR riga_ord_prod_w_materia_prima.colli_pedana > 1), 'Colli',\n" +
|
||||
" jtb_cicl.unt_mis_prod)\n" +
|
||||
" AS unt_mis_prod,\n" +
|
||||
" IIF(mtb_aart.flag_qta_cnf_fissa = 'S' AND\n" +
|
||||
" (mtb_aart.qta_cnf > 1 OR riga_ord_prod_w_materia_prima.colli_pedana > 1),\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana, jtb_cicl.qta_prod)\n" +
|
||||
" AS qta_batch_prod,\n" +
|
||||
" IIF(mtb_aart.qta_cnf > 1 OR riga_ord_prod_w_materia_prima.colli_pedana > 1,\n" +
|
||||
" mtb_aart.qta_cnf,\n" +
|
||||
" jtb_cicl.rap_conv_prod) AS rap_conv_prod,\n" +
|
||||
" dtb_ord_steps.data_iniz,\n" +
|
||||
" dtb_ord_steps.data_fine,\n" +
|
||||
" dtb_ord_steps.qta_lav AS qta_lav,\n" +
|
||||
" IIF(dtb_ord_steps.qta_prod <> 0, dtb_ord_steps.qta_prod,\n" +
|
||||
" dtb_ordt.qta_prod) AS qta_prod,\n" +
|
||||
" dtb_ord_steps.hr_num,\n" +
|
||||
" dtb_ord_steps.descrizione_attivita,\n" +
|
||||
" 3600 / (ISNULL(NULLIF(jtb_dist_clav_dir.duration, 0), 1) /\n" +
|
||||
" ISNULL(NULLIF(jtb_cicl.rap_conv_prod, 0), 1)) AS prod_std,\n" +
|
||||
" dtb_ord_steps.elapsed_time,\n" +
|
||||
" SUM(ISNULL(mtb_colr_carico.qta_col, 0)) AS qta_trasferite,\n" +
|
||||
" COUNT(mtb_colr_carico.num_collo) AS udc_trasferiti,\n" +
|
||||
" COUNT(colli_lotto.num_collo) AS uds_scaricati,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN dtb_ord_steps.id_step = 0\n" +
|
||||
" THEN IIF(dtb_ord_steps.starting_machines = 1, 'IN AVVIO', 'PROGRAMMATO')\n" +
|
||||
" WHEN dtb_ord_steps.data_fine IS NULL\n" +
|
||||
" THEN 'IN CORSO'\n" +
|
||||
" ELSE 'IN PAUSA'\n" +
|
||||
" END AS stato,\n" +
|
||||
" CONVERT(INT, SUM(ISNULL(\n" +
|
||||
" mtb_colr_carico.qta_col / riga_ord_prod_w_materia_prima.calc_rap_conv,\n" +
|
||||
" 0))) AS pz_trasferiti,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN (jtb_dist_clav_dir.duration / ISNULL(NULLIF(jtb_cicl.rap_conv_prod, 0), 1)) *\n" +
|
||||
" (dtb_ordt.qta_prod * dtb_ordt.rap_conv_prod -\n" +
|
||||
" SUM(ISNULL(mtb_colr_carico.qta_col, 0))) > 0\n" +
|
||||
" THEN\n" +
|
||||
" (jtb_dist_clav_dir.duration /\n" +
|
||||
" ISNULL(NULLIF(jtb_cicl.rap_conv_prod, 0), 1)) *\n" +
|
||||
" (dtb_ordt.qta_prod * dtb_ordt.rap_conv_prod -\n" +
|
||||
" SUM(ISNULL(mtb_colr_carico.qta_col, 0)))\n" +
|
||||
" ELSE 0 END AS run_time_sec,\n" +
|
||||
" jl.id_lotto,\n" +
|
||||
" jlt.data_lotto,\n" +
|
||||
" mtb_aart.peso_kg,\n" +
|
||||
" dtb_ordt.data_cons_prod_max\n" +
|
||||
" FROM dtb_ord_max_step dtb_ord_steps\n" +
|
||||
" INNER JOIN dtb_ordt ON dtb_ord_steps.data_ord = dtb_ordt.data_ord\n" +
|
||||
" AND dtb_ord_steps.num_ord = dtb_ordt.num_ord\n" +
|
||||
" AND dtb_ord_steps.gestione = dtb_ordt.gestione\n" +
|
||||
" LEFT OUTER JOIN setup_depo setupCaricoImmediato\n" +
|
||||
" ON dtb_ordt.cod_mdep = setupCaricoImmediato.cod_mdep\n" +
|
||||
" LEFT OUTER JOIN jtb_dist_clav_dir\n" +
|
||||
" ON dtb_ordt.cod_prod = jtb_dist_clav_dir.cod_prod AND\n" +
|
||||
" dtb_ordt.cod_jfas = jtb_dist_clav_dir.cod_jfas\n" +
|
||||
" LEFT OUTER JOIN mtb_partita_mag\n" +
|
||||
" ON dtb_ordt.partita_mag = mtb_partita_mag.partita_mag AND\n" +
|
||||
" dtb_ordt.cod_prod = mtb_partita_mag.cod_mart AND\n" +
|
||||
" mtb_partita_mag.flag_stato = 'A'\n" +
|
||||
" LEFT OUTER JOIN mtb_colr_sum mtb_colr_carico\n" +
|
||||
" ON dtb_ordt.data_ord = mtb_colr_carico.data_ord AND\n" +
|
||||
" dtb_ordt.gestione = mtb_colr_carico.gestione AND\n" +
|
||||
" dtb_ordt.num_ord = mtb_colr_carico.num_ord AND\n" +
|
||||
" dtb_ordt.cod_prod = mtb_colr_carico.cod_mart\n" +
|
||||
" LEFT OUTER JOIN jtb_comt ON dtb_ordt.cod_jcom = jtb_comt.cod_jcom\n" +
|
||||
" LEFT OUTER JOIN riga_ord_prod_w_materia_prima\n" +
|
||||
" ON riga_ord_prod_w_materia_prima.gestione_ord_prod =\n" +
|
||||
" dtb_ordt.gestione_rif AND\n" +
|
||||
" riga_ord_prod_w_materia_prima.data_ord_prod =\n" +
|
||||
" dtb_ordt.data_ord_rif AND\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_ord_prod =\n" +
|
||||
" dtb_ordt.num_ord_rif AND\n" +
|
||||
" riga_ord_prod_w_materia_prima.riga_ord_prod = dtb_ordt.riga_ord_rif\n" +
|
||||
" LEFT OUTER JOIN jtb_cicl ON jtb_cicl.cod_prod = dtb_ordt.cod_prod\n" +
|
||||
" LEFT OUTER JOIN mtb_aart ON mtb_aart.cod_mart = dtb_ordt.cod_prod\n" +
|
||||
" LEFT OUTER JOIN gtb_anag ON dtb_ordt.cod_anag = gtb_anag.cod_anag\n" +
|
||||
" LEFT OUTER JOIN mtb_tcol ON dtb_ordt.cod_tcol_UL = mtb_tcol.cod_tcol\n" +
|
||||
" LEFT OUTER JOIN jtb_lotr jl\n" +
|
||||
" ON dtb_ord_steps.cod_jfas = jl.cod_jfas AND\n" +
|
||||
" dtb_ordt.gestione = jl.gestione AND\n" +
|
||||
" dtb_ordt.data_ord = jl.data_ord AND\n" +
|
||||
" dtb_ordt.num_ord = jl.num_ord\n" +
|
||||
" LEFT OUTER JOIN jtb_lott jlt\n" +
|
||||
" ON jl.cod_jfas = jlt.cod_jfas AND jl.id_lotto = jlt.id_lotto\n" +
|
||||
" LEFT OUTER JOIN mtb_colt colli_lotto ON jlt.id_lotto = colli_lotto.id_lotto\n" +
|
||||
"\n" +
|
||||
" CROSS APPLY setup\n" +
|
||||
" WHERE dtb_ordt.flag_annulla = 'N'\n" +
|
||||
" AND dtb_ord_steps.data_ord BETWEEN setup.date_start AND setup.date_end\n" +
|
||||
" AND (setup.flag_evaso IS NULL\n" +
|
||||
" OR (\n" +
|
||||
" (setup.flag_evaso = 'I'\n" +
|
||||
" AND\n" +
|
||||
" dtb_ord_steps.flag_step_attivo = 'S'\n" +
|
||||
" AND (flag_evaso_prod = 'I'\n" +
|
||||
" OR\n" +
|
||||
" (setupCaricoImmediato.flag_carico_scarico_immediato = 'S'\n" +
|
||||
" AND\n" +
|
||||
" flag_evaso_prod = 'E'))\n" +
|
||||
" AND dtb_ordt.flag_evaso_forzato = 'N'\n" +
|
||||
" )\n" +
|
||||
" OR (setup.flag_evaso = 'E '\n" +
|
||||
" AND (flag_evaso_prod = 'E' OR jlt.data_chiusura IS NOT NULL))\n" +
|
||||
" )\n" +
|
||||
" )\n" +
|
||||
" AND (setup.cod_jfas IS NULL\n" +
|
||||
" OR dtb_ord_steps.cod_jfas = setup.cod_jfas)\n" +
|
||||
" AND (setup.cod_anag IS NULL\n" +
|
||||
" OR dtb_ordt.cod_anag = setup.cod_anag)\n" +
|
||||
" GROUP BY riga_ord_prod_w_materia_prima.data_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.riga_ord_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_avviabile,\n" +
|
||||
" riga_ord_prod_w_materia_prima.flag_tracciabilita,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord,\n" +
|
||||
" mtb_partita_mag.rap_conv2,\n" +
|
||||
" mtb_partita_mag.rap_conv3,\n" +
|
||||
" dtb_ordt.note,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv,\n" +
|
||||
" dtb_ordt.descrizione_prod,\n" +
|
||||
" dtb_ordt.descr_estesa_prod,\n" +
|
||||
" riga_ord_prod_w_materia_prima.num_cnf,\n" +
|
||||
" mtb_aart.qta_cnf,\n" +
|
||||
" mtb_aart.gg_scad_partita,\n" +
|
||||
" mtb_aart.flag_qta_cnf_fissa,\n" +
|
||||
" riga_ord_prod_w_materia_prima.pos_riga,\n" +
|
||||
" dtb_ordt.flag_evaso_prod,\n" +
|
||||
" dtb_ordt.flag_evaso_forzato,\n" +
|
||||
" dtb_ordt.gestione,\n" +
|
||||
" dtb_ordt.data_ord,\n" +
|
||||
" dtb_ordt.num_ord,\n" +
|
||||
" dtb_ord_steps.cod_jfas,\n" +
|
||||
" dtb_ordt.cod_jfas,\n" +
|
||||
" dtb_ordt.cod_jcom,\n" +
|
||||
" mtb_partita_mag.partita_mag,\n" +
|
||||
" mtb_partita_mag.partita_mag_prod,\n" +
|
||||
" mtb_partita_mag.data_scad,\n" +
|
||||
" dtb_ordt.cod_prod,\n" +
|
||||
" dtb_ordt.data_iniz_prod,\n" +
|
||||
" dtb_ord_steps.id_step,\n" +
|
||||
" dtb_ord_steps.data_iniz,\n" +
|
||||
" dtb_ord_steps.data_fine,\n" +
|
||||
" dtb_ordt.cod_tcol_UL,\n" +
|
||||
" dtb_ordt.cod_anag,\n" +
|
||||
" gtb_anag.rag_soc,\n" +
|
||||
" gtb_anag.part_iva,\n" +
|
||||
" dtb_ordt.rif_ord,\n" +
|
||||
" dtb_ordt.cod_vdes,\n" +
|
||||
" dtb_ordt.cod_mdep,\n" +
|
||||
" riga_ord_prod_w_materia_prima.cod_mdep,\n" +
|
||||
" mtb_aart.colli_pedana,\n" +
|
||||
" dtb_ord_steps.qta_prod,\n" +
|
||||
" dtb_ordt.qta_prod,\n" +
|
||||
" jtb_dist_clav_dir.duration,\n" +
|
||||
" jtb_comt.descrizione,\n" +
|
||||
" dtb_ord_steps.elapsed_time,\n" +
|
||||
" riga_ord_prod_w_materia_prima.colli_pedana,\n" +
|
||||
" dtb_ord_steps.hr_num,\n" +
|
||||
" mtb_aart.unt_mis,\n" +
|
||||
" mtb_aart.unt_mis2,\n" +
|
||||
" mtb_aart.rap_conv2,\n" +
|
||||
" mtb_aart.unt_mis3,\n" +
|
||||
" mtb_aart.rap_conv3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.unt_ord3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_ord,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_ord2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_ord3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv2,\n" +
|
||||
" riga_ord_prod_w_materia_prima.rap_conv3,\n" +
|
||||
" riga_ord_prod_w_materia_prima.qta_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.cal_qta_cnf,\n" +
|
||||
" riga_ord_prod_w_materia_prima.gg_scad_partita,\n" +
|
||||
" jtb_cicl.qta_prod,\n" +
|
||||
" jtb_cicl.rap_conv_prod,\n" +
|
||||
" dtb_ord_steps.descrizione_attivita,\n" +
|
||||
" jtb_cicl.unt_mis_prod,\n" +
|
||||
" mtb_tcol.descrizione,\n" +
|
||||
" dtb_ordt.qta_prod,\n" +
|
||||
" dtb_ordt.rap_conv_prod,\n" +
|
||||
" setupCaricoImmediato.flag_carico_scarico_immediato,\n" +
|
||||
" dtb_ord_steps.num_fase, dtb_ord_steps.qta_lav,\n" +
|
||||
" jl.id_lotto, jlt.data_lotto, mtb_aart.peso_kg, dtb_ordt.data_cons_prod_max,\n" +
|
||||
" dtb_ord_steps.id_step,\n" +
|
||||
" dtb_ord_steps.max_fase,\n" +
|
||||
" dtb_ord_steps.starting_machines)\n" +
|
||||
" SELECT ROW_NUMBER() OVER (ORDER BY data_ord, num_ord_prod, pos_riga, num_ord) AS sort,\n" +
|
||||
" cod_jcom,\n" +
|
||||
" data_ord_prod,\n" +
|
||||
" num_ord_prod,\n" +
|
||||
" riga_ord_prod,\n" +
|
||||
" flag_avviabile,\n" +
|
||||
" flag_tracciabilita,\n" +
|
||||
" unt_ord,\n" +
|
||||
" rap_conv,\n" +
|
||||
" unt_ord2,\n" +
|
||||
" rap_conv2,\n" +
|
||||
" unt_ord3,\n" +
|
||||
" rap_conv3,\n" +
|
||||
" descrizione_prod,\n" +
|
||||
" num_pezzi,\n" +
|
||||
" num_cnf,\n" +
|
||||
" gg_scad_partita,\n" +
|
||||
" qta_cnf,\n" +
|
||||
" colli_pedana,\n" +
|
||||
" num_pedane,\n" +
|
||||
" pos_riga,\n" +
|
||||
" flag_evaso_prod,\n" +
|
||||
" flag_evaso_forzato,\n" +
|
||||
" flag_ordine_evaso,\n" +
|
||||
" gestione,\n" +
|
||||
" data_ord,\n" +
|
||||
" cod_tcol_UL,\n" +
|
||||
" descrizione_tcol,\n" +
|
||||
" cod_anag,\n" +
|
||||
" rag_soc_anag,\n" +
|
||||
" part_iva,\n" +
|
||||
" rif_ord,\n" +
|
||||
" cod_vdes,\n" +
|
||||
" cod_mdep,\n" +
|
||||
" cod_mdep_prod,\n" +
|
||||
" num_ord,\n" +
|
||||
" cod_jfas,\n" +
|
||||
" cod_jfas_lav,\n" +
|
||||
" partita_mag,\n" +
|
||||
" partita_mag_prod,\n" +
|
||||
" note_lav,\n" +
|
||||
" data_scad,\n" +
|
||||
" cod_prod,\n" +
|
||||
" descrizione_commessa,\n" +
|
||||
" data_iniz_prod,\n" +
|
||||
" id_step,\n" +
|
||||
" unt_mis_prod,\n" +
|
||||
" qta_batch_prod,\n" +
|
||||
" rap_conv_prod,\n" +
|
||||
" data_iniz,\n" +
|
||||
" data_fine,\n" +
|
||||
" qta_prod,\n" +
|
||||
" qta_lav,\n" +
|
||||
" max_fase,\n" +
|
||||
" num_fase,\n" +
|
||||
" hr_num,\n" +
|
||||
" descrizione_attivita,\n" +
|
||||
" prod_std,\n" +
|
||||
" elapsed_time,\n" +
|
||||
" qta_trasferite,\n" +
|
||||
" udc_trasferiti,\n" +
|
||||
" uds_scaricati,\n" +
|
||||
" stato,\n" +
|
||||
" pz_trasferiti,\n" +
|
||||
" run_time_sec,\n" +
|
||||
" SUM(run_time_sec) OVER (PARTITION BY cod_jfas, data_ord_prod) AS cumulative_run_time_sec,\n" +
|
||||
" CONVERT(INT, run_time_sec / 3600) AS run_time_hour,\n" +
|
||||
" ROUND((run_time_sec / 3600 - CONVERT(INT, run_time_sec / 3600)) * 60, 0) AS run_time_min,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN setup_run_time.flag_restart = 'S' THEN\n" +
|
||||
" DATEADD(SECOND, SUM(run_time_sec)\n" +
|
||||
" OVER (PARTITION BY cod_jfas, data_ord_prod ORDER BY stato, cod_jfas, data_ord_prod, pos_riga ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),\n" +
|
||||
" CASE\n" +
|
||||
" WHEN (data_ord_prod > GETDATE() AND (data_iniz IS NULL OR data_fine IS NOT NULL))\n" +
|
||||
" THEN DATEADD(HH, 7, data_ord_prod)\n" +
|
||||
" ELSE GETDATE() END)\n" +
|
||||
" ELSE\n" +
|
||||
" DATEADD(SECOND, SUM(run_time_sec)\n" +
|
||||
" OVER (PARTITION BY cod_jfas ORDER BY stato, cod_jfas, data_ord_prod, num_ord_prod, pos_riga ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW),\n" +
|
||||
" GETDATE())\n" +
|
||||
" END AS run_time_end,\n" +
|
||||
" id_lotto,\n" +
|
||||
" data_lotto,\n" +
|
||||
" peso_kg,\n" +
|
||||
" data_cons_prod_max\n" +
|
||||
" FROM ord_lav\n" +
|
||||
" CROSS APPLY setup_run_time");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250415120106 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("INSERT INTO dtb_mod_stampa(mod_stampa, descrizione, flag_attivo) VALUES('PACKC','Packing List di carico', 'S')");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.IntegryCustomer;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250416105511 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("UPDATE stb_gest_setup SET tipo_setup = 'mtb_sgrp' where gest_name = 'PVM' and section = 'PIAN_ACC_ROSSG' and key_section = 'REPORT_NAME_SCHEDA_SCAR';");
|
||||
|
||||
if (isCustomer(IntegryCustomer.RossoGargano)) {
|
||||
updateSetupValue("PVM", "PIAN_ACC_ROSSG", "REPORT_NAME_SCHEDA_SCAR",null);
|
||||
executeStatement(
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'PVM', N'PIAN_ACC_ROSSG', N'REPORT_NAME_SCHEDA_SCAR', N'mtb_sgrp', N'MG~02', N'ReportCQCarciofi');",
|
||||
"INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value) VALUES (N'PVM', N'PIAN_ACC_ROSSG', N'REPORT_NAME_SCHEDA_SCAR', N'mtb_sgrp', N'MG~01', N'SchedaGestioneScaricoProdotto');"
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250416155709 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
createSetup("w_ddocu_ord_rc", "SETUP", "DISATTIVA_ASS_COMM_TESTATA_ORD_PROD", "N",
|
||||
"Valido solo per le aziende tessili: se impostata a S allora nel caricare un ordine di produzione non valorizza automaticamente il codice commessa di testata (Anno stag) quando si carica il primo articolo nell'ordine", false, null, false, false,
|
||||
false, false, false, null, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,28 @@ import java.util.*;
|
||||
|
||||
public class AccountingRules extends QueryRules {
|
||||
|
||||
public static String completeCodBene(Connection conn, CtbBeni ctbBeni) throws SQLException {
|
||||
String sql =
|
||||
Query.format(
|
||||
"SELECT dbo.f_suggestCodeCodBene(%s)", ctbBeni.getCodCatbene());
|
||||
|
||||
String codBene = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
|
||||
if (UtilityString.isNullOrEmpty(codBene)) {
|
||||
Integer len = 4;
|
||||
String partialCode = ctbBeni.getCodCatbene() + "%";
|
||||
sql =
|
||||
Query.format(
|
||||
"SELECT ISNULL( max(cast(right(cod_bene, [LUNGHEZZA] ) as int)) ,0)\n" +
|
||||
" FROM ctb_beni\n" +
|
||||
" WHERE cod_bene like %S AND ISNUMERIC(right(cod_bene, [LUNGHEZZA])) = 1", partialCode);
|
||||
sql = sql.replace("[LUNGHEZZA]", UtilityDB.valueToString(len));
|
||||
Integer maxCode = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
codBene = ctbBeni.getCodCatbene() + String.format("%0" + len + "d", maxCode + 1);
|
||||
}
|
||||
|
||||
return codBene;
|
||||
}
|
||||
|
||||
public static Integer completeNumIreg(Connection connection, String codIreg) throws Exception {
|
||||
String sql =
|
||||
|
||||
@@ -99,6 +99,8 @@ public class AnagRules extends QueryRules {
|
||||
if (UtilityString.isNullOrEmpty(gtbAnag.getSesso())) gtbAnag.setSesso(sesso);
|
||||
if (UtilityString.isNullOrEmpty(gtbAnag.getDataNascita())) gtbAnag.setDataNascita(dataNascita);
|
||||
|
||||
gtbAnag.setFlagPersonaFg("F");
|
||||
|
||||
String comune = codFiscale.substring(11, 15);
|
||||
ComuniService comuniService = ContextLoader.getCurrentWebApplicationContext().getBean(ComuniService.class);
|
||||
Optional<Comune> comuneOpt =
|
||||
|
||||
@@ -166,7 +166,7 @@ public class CommonRules extends QueryRules {
|
||||
}
|
||||
|
||||
public static String getUserNameFromFullName(Connection connection, String fullName) throws Exception {
|
||||
if ( !UtilityString.isNullOrEmpty(fullName)) {
|
||||
if (!UtilityString.isNullOrEmpty(fullName)) {
|
||||
String sql = Query.format("SELECT user_name FROM stb_user WHERE full_name = %s",
|
||||
fullName);
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, sql);
|
||||
@@ -1257,13 +1257,40 @@ public class CommonRules extends QueryRules {
|
||||
" FROM " + MtbColt.ENTITY +
|
||||
" WHERE data_ord = {} AND " +
|
||||
" num_ord = {} AND " +
|
||||
" gestione = {} AND "+
|
||||
" gestione = {} AND " +
|
||||
" segno = {}", dataOrd, numOrd, gestione, segno);
|
||||
|
||||
int maxProgressivoUl = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
return maxProgressivoUl + 1;
|
||||
}
|
||||
|
||||
public static int retrieveNextProgressivoUlRG(Connection conn, String gestione, LocalDate dataOrd, int numOrd, int segno) throws SQLException {
|
||||
String sql = Query.format(
|
||||
"WITH partite AS (SELECT dot.cod_prod AS cod_mart, mpm.partita_mag_prod, dot.cod_jfas\n" +
|
||||
" FROM dtb_ordt dot\n" +
|
||||
" INNER JOIN mtb_partita_mag mpm\n" +
|
||||
" ON dot.cod_prod = mpm.cod_mart AND dot.partita_mag = mpm.partita_mag\n" +
|
||||
" WHERE dot.data_ord = %s\n" +
|
||||
" AND dot.num_ord = %s\n" +
|
||||
" AND dot.gestione = [gestione])\n" +
|
||||
"SELECT ISNULL(MAX(progressivo_ul), 0) AS progressivo_ul\n" +
|
||||
"FROM mtb_colt\n" +
|
||||
" INNER JOIN mtb_colr mcr ON mtb_colt.gestione = mcr.gestione AND mtb_colt.data_collo = mcr.data_collo AND\n" +
|
||||
" mtb_colt.ser_collo = mcr.ser_collo AND mtb_colt.num_collo = mcr.num_collo\n" +
|
||||
" INNER JOIN mtb_partita_mag mpm ON mcr.cod_mart = mpm.cod_mart AND mcr.partita_mag = mpm.partita_mag\n" +
|
||||
" INNER JOIN partite ON mcr.cod_mart = partite.cod_mart AND mpm.partita_mag_prod = partite.partita_mag_prod\n" +
|
||||
" AND mtb_colt.cod_jfas = partite.cod_jfas\n" +
|
||||
"WHERE mtb_colt.gestione = [gestione]\n" +
|
||||
" AND segno = %s",
|
||||
dataOrd,
|
||||
numOrd,
|
||||
segno
|
||||
).replace("[gestione]", UtilityDB.valueToString(gestione));
|
||||
|
||||
int maxProgressivoUl = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
return maxProgressivoUl + 1;
|
||||
}
|
||||
|
||||
public static void updateDatiInv(Connection conn, DtbDoct entity) throws Exception {
|
||||
String codAnagOld = null, serDocOld = null, codDtipOld = null;
|
||||
Integer numDocOld = null;
|
||||
@@ -1272,23 +1299,28 @@ public class CommonRules extends QueryRules {
|
||||
HashMap<String, Object> oldPk = entity.getOldPk();
|
||||
if (oldPk != null && !oldPk.isEmpty()) {
|
||||
|
||||
if (oldPk.containsKey("codAnag")) codAnagOld = (String) oldPk.get("codAnag"); else codAnagOld = entity.getCodAnag();
|
||||
if (oldPk.containsKey("codDtip")) codDtipOld = (String) oldPk.get("codDtip"); else codDtipOld = entity.getCodDtip();
|
||||
if (oldPk.containsKey("dataDoc")) dataDocOld = UtilityString.parseDate((String) oldPk.get("dataDoc")); else dataDocOld = entity.getDataDoc();
|
||||
if (oldPk.containsKey("serDoc")) serDocOld = (String) oldPk.get("serDoc"); else serDocOld = entity.getSerDoc();
|
||||
if (oldPk.containsKey("numDoc")) numDocOld = (Integer) oldPk.get("numDoc"); else numDocOld = entity.getNumDoc();
|
||||
if (oldPk.containsKey("codAnag")) codAnagOld = (String) oldPk.get("codAnag");
|
||||
else codAnagOld = entity.getCodAnag();
|
||||
if (oldPk.containsKey("codDtip")) codDtipOld = (String) oldPk.get("codDtip");
|
||||
else codDtipOld = entity.getCodDtip();
|
||||
if (oldPk.containsKey("dataDoc")) dataDocOld = UtilityString.parseDate((String) oldPk.get("dataDoc"));
|
||||
else dataDocOld = entity.getDataDoc();
|
||||
if (oldPk.containsKey("serDoc")) serDocOld = (String) oldPk.get("serDoc");
|
||||
else serDocOld = entity.getSerDoc();
|
||||
if (oldPk.containsKey("numDoc")) numDocOld = (Integer) oldPk.get("numDoc");
|
||||
else numDocOld = entity.getNumDoc();
|
||||
|
||||
if (!entity.getCodDtip().equals(codDtipOld) ||
|
||||
!entity.getCodAnag().equals(codAnagOld) ||
|
||||
!entity.getDataDoc().equals(dataDocOld) ||
|
||||
entity.getSerDoc().equals(serDocOld) ||
|
||||
!entity.getNumDoc().equals(numDocOld)){
|
||||
!entity.getNumDoc().equals(numDocOld)) {
|
||||
String sql =
|
||||
"UPDATE mtb_invent " +
|
||||
"SET cod_anag = " + UtilityDB.valueToString(entity.getCodAnag())+ ", " +
|
||||
"cod_dtip = " + UtilityDB.valueToString(entity.getCodDtip())+ ", " +
|
||||
"SET cod_anag = " + UtilityDB.valueToString(entity.getCodAnag()) + ", " +
|
||||
"cod_dtip = " + UtilityDB.valueToString(entity.getCodDtip()) + ", " +
|
||||
"data_doc = " + UtilityDB.valueDateToString(entity.getDataDoc(), CommonConstants.DATE_FORMAT_YMD) + ", " +
|
||||
"ser_doc = " + UtilityDB.valueToString(entity.getSerDoc())+ ", " +
|
||||
"ser_doc = " + UtilityDB.valueToString(entity.getSerDoc()) + ", " +
|
||||
"num_doc = " + UtilityDB.valueToString(entity.getNumDoc());
|
||||
sql = UtilityDB.addwhereCond(sql, entity.getWhereCondOldPk(null), false);
|
||||
conn.createStatement().executeUpdate(sql);
|
||||
|
||||
@@ -16,10 +16,7 @@ import it.integry.ems_model.exception.DataConverterNotFoundException;
|
||||
import it.integry.ems_model.rules.util.DroolsUtil;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityBigDecimal;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import it.integry.ems_model.utility.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -967,7 +964,12 @@ public class DocOrdRules extends QueryRules {
|
||||
.setNumOrd(dtbOrdt.getNumOrdRif())
|
||||
.setGeneraOrdLavDaProd(false);
|
||||
dtbOrdtProd.setOperation(OperationType.NO_OP);
|
||||
BigDecimal valUnt = dtbOrdt.getTotImponib().divide(dtbOrdt.getQtaProd(), 5, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
/*
|
||||
BigDecimal valUnt = new BigDecimal(0);
|
||||
if (dtbOrdt.getQtaProd().compareTo(BigDecimal.ZERO) > 0) {
|
||||
valUnt = dtbOrdt.getTotImponib().divide(dtbOrdt.getQtaProd(), 5, BigDecimal.ROUND_HALF_UP);
|
||||
}*/
|
||||
|
||||
DtbOrdr dtbOrdrProd =
|
||||
new DtbOrdr().setRigaOrd(dtbOrdt.getRigaOrdRif());
|
||||
@@ -984,7 +986,7 @@ public class DocOrdRules extends QueryRules {
|
||||
.setRapConv(dtbOrdt.getRapConvProd())
|
||||
.setQtaOrd(dtbOrdt.getQtaProd())
|
||||
.setQtaEvasa(dtbOrdt.getQtaEvasaProd())
|
||||
.setValUnt(valUnt)
|
||||
/*.setValUnt(valUnt)*/
|
||||
.setSconto5(dtbOrdt.getSconto1())
|
||||
.setSconto6(dtbOrdt.getSconto2())
|
||||
.setSconto7(dtbOrdt.getSconto3())
|
||||
@@ -1005,4 +1007,21 @@ public class DocOrdRules extends QueryRules {
|
||||
|
||||
return dtbOrdtProd;
|
||||
}
|
||||
|
||||
public static Integer completeNumOrdProd(Connection connection, DtbOrdt dtbOrdt) throws SQLException {
|
||||
String sql = Query.format(
|
||||
"SELECT num_ord\n" +
|
||||
"FROM dtb_ordt\n" +
|
||||
"WHERE gestione = 'A'\n" +
|
||||
" AND gestione_rif = 'A'\n" +
|
||||
" AND data_ord = %s\n" +
|
||||
" AND cod_anag = %s\n" +
|
||||
" AND cod_jfas = %s",
|
||||
dtbOrdt.getDataOrd(),
|
||||
dtbOrdt.getCodAnag(),
|
||||
dtbOrdt.getCodJfas()
|
||||
);
|
||||
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.service.dto.AttachmentDTO;
|
||||
import it.integry.ems.service.dto.EntityFieldDTO;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.settings.SettingsController;
|
||||
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
||||
@@ -830,26 +829,7 @@ public class EmsServices {
|
||||
if (UtilityDebug.isDebugExecution() || UtilityDebug.isIntegryServer())
|
||||
throw new Exception("Cannot export server info in DEBUG mode");
|
||||
|
||||
|
||||
List<AvailableConnectionsModel> availableConnectionList =
|
||||
settingsModel.getAvailableConnectionsWithoutDuplicatedProfiles(true, settingsController.getHistoryProfileDb());
|
||||
|
||||
for (AvailableConnectionsModel model : availableConnectionList) {
|
||||
try {
|
||||
if (model.getInternalDb() && !model.getProfileName().equalsIgnoreCase(settingsModel.getDefaultProfile())) {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(model.getProfileName());
|
||||
|
||||
String sql = "SELECT db_distributore FROM azienda";
|
||||
String dbDistributore = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(ds.getConnection(), sql);
|
||||
|
||||
multiDBTransactionManager.addConnection(model.getProfileName(), ds, model.getDbName().equalsIgnoreCase(dbDistributore));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
logger.error(String.format("La connessione al DB \"%s\" non è valida. %s", model.getProfileName(), ex.getMessage()), ex);
|
||||
}
|
||||
}
|
||||
multiDBTransactionManager.setPrimaryDs(settingsModel.getDefaultProfile());
|
||||
|
||||
HashMap<String, Object> arguments = new HashMap<>();
|
||||
|
||||
@@ -911,7 +891,7 @@ public class EmsServices {
|
||||
int requestStatusCode = HttpRestWrapper.callGeneric(url, null, null, jsonBody, ContentType.APPLICATION_JSON, srb, null);
|
||||
}
|
||||
|
||||
private DatabaseEngineInfoDTO getDatabaseEngineInfo(MultiDBTransactionManager data) {
|
||||
private DatabaseEngineInfoDTO getDatabaseEngineInfo(MultiDBTransactionManager mdb) {
|
||||
DatabaseEngineInfoDTO databaseEngineInfoDTO = null;
|
||||
try {
|
||||
String dbEngineVersionSql = "SELECT product_version " +
|
||||
@@ -947,7 +927,7 @@ public class EmsServices {
|
||||
" , CAST(SERVERPROPERTY('productlevel') AS nvarchar) as product_level " +
|
||||
" , CAST(SERVERPROPERTY('edition') AS nvarchar) as edition) info";
|
||||
|
||||
HashMap<String, Object> result = UtilityDB.executeSimpleQueryOnlyFirstRow(data.getPrimaryConnection(), dbEngineVersionSql);
|
||||
HashMap<String, Object> result = UtilityDB.executeSimpleQueryOnlyFirstRow(mdb.getPrimaryConnection(), dbEngineVersionSql);
|
||||
|
||||
databaseEngineInfoDTO = new DatabaseEngineInfoDTO()
|
||||
.setProductEdition(UtilityHashMap.<String>getValueIfExists(result, "edition"))
|
||||
@@ -957,7 +937,7 @@ public class EmsServices {
|
||||
.setDatabaseInfoList(new ArrayList<>());
|
||||
|
||||
|
||||
for (AdvancedDataSource dataSource : data.getActiveConnections()) {
|
||||
for (AdvancedDataSource dataSource : mdb.getActiveConnections()) {
|
||||
String databaseInfoSql = "SELECT DB_NAME(database_id) AS database_name, Name AS logical_name," +
|
||||
" (size*8)/1024 AS size_mb, " +
|
||||
" case when max_size > 200000000 then -1 " +
|
||||
@@ -987,7 +967,7 @@ public class EmsServices {
|
||||
}
|
||||
|
||||
|
||||
private List<ApplicationInfoDTO> getApplicatinInfo(MultiDBTransactionManager data) throws Exception {
|
||||
private List<ApplicationInfoDTO> getApplicatinInfo(MultiDBTransactionManager mdb) throws Exception {
|
||||
List<ApplicationInfoDTO> applicationInfoDTOList = new ArrayList<>();
|
||||
|
||||
String sql =
|
||||
@@ -999,13 +979,8 @@ public class EmsServices {
|
||||
" FROM azienda";
|
||||
|
||||
|
||||
List<AdvancedDataSource> db =
|
||||
data.getActiveConnections().stream()
|
||||
.filter(x -> UtilityString.equalsIgnoreCase(x.getDataSource().getProfile(), x.getDataSource().getDbName()) &&
|
||||
x.isInternalDb())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (AdvancedDataSource dataSource : db) {
|
||||
for (AdvancedDataSource dataSource : mdb.getActiveConnections()) {
|
||||
HashMap<String, Object> resultDbInfo = UtilityDB.executeSimpleQueryOnlyFirstRow(dataSource.getConnection(), sql);
|
||||
|
||||
final HashMap<String, String> setupSection = setupGest.getSetupSection(multiDBTransactionManager.getPrimaryConnection(), "DATI_AZIENDA", "SETUP");
|
||||
|
||||
@@ -559,7 +559,7 @@ public class ReportProcessor {
|
||||
" AND ((:codAnag is null and cod_anag is null) OR (:codAnag is not null and ISNULL(cod_anag,:codAnag) = :codAnag)) " +
|
||||
" AND ((:codMdep is null and cod_mdep is null) OR (:codMdep is not null and ISNULL(cod_mdep,:codMdep) = :codMdep)) " +
|
||||
" AND ((:codDtip is null and cod_dtip is null) OR (:codDtip is not null and ISNULL(cod_dtip,:codDtip) = :codDtip)) " +
|
||||
"order by cod_anag desc, cod_mdep desc";
|
||||
"order by cod_anag desc, cod_mdep desc, cod_dtip desc";
|
||||
sql = sql
|
||||
.replace(":codAnag", UtilityDB.valueToString(reportTypeDTO.getCodAnag()))
|
||||
.replace(":codDtip", UtilityDB.valueToString(reportTypeDTO.getCodDtip()))
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package it.integry.ems.service.dto.production;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class InsertPartitaMagRequestDTO {
|
||||
private String codMart;
|
||||
|
||||
private String partitaMag;
|
||||
|
||||
private String partitaMagProd;
|
||||
|
||||
private Date dataScad;
|
||||
|
||||
private String codJfas;
|
||||
|
||||
private String note;
|
||||
|
||||
private String gestione;
|
||||
|
||||
private Date dataOrd;
|
||||
|
||||
private Integer numOrd;
|
||||
|
||||
public String getCodMart() {
|
||||
return codMart;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setCodMart(String codMart) {
|
||||
this.codMart = codMart;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPartitaMag() {
|
||||
return partitaMag;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setPartitaMag(String partitaMag) {
|
||||
this.partitaMag = partitaMag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPartitaMagProd() {
|
||||
return partitaMagProd;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setPartitaMagProd(String partitaMagProd) {
|
||||
this.partitaMagProd = partitaMagProd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataScad() {
|
||||
return dataScad;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setDataScad(Date dataScad) {
|
||||
this.dataScad = dataScad;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodJfas() {
|
||||
return codJfas;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setCodJfas(String codJfas) {
|
||||
this.codJfas = codJfas;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setNote(String note) {
|
||||
this.note = note;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getGestione() {
|
||||
return gestione;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setGestione(String gestione) {
|
||||
this.gestione = gestione;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataOrd() {
|
||||
return dataOrd;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setDataOrd(Date dataOrd) {
|
||||
this.dataOrd = dataOrd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getNumOrd() {
|
||||
return numOrd;
|
||||
}
|
||||
|
||||
public InsertPartitaMagRequestDTO setNumOrd(Integer numOrd) {
|
||||
this.numOrd = numOrd;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -152,6 +152,11 @@ public class OrdineLavorazioneDTO {
|
||||
@JsonSerialize
|
||||
private String partitaMag;
|
||||
|
||||
@SqlField(value = "partita_mag_prod")
|
||||
@JsonProperty("partitaMagProd")
|
||||
@JsonSerialize
|
||||
private String partitaMagProd;
|
||||
|
||||
@SqlField(value = "data_scad")
|
||||
@JsonProperty("dataScad")
|
||||
@JsonSerialize(using = JsonDateAdapterSerializer.class)
|
||||
@@ -639,6 +644,15 @@ public class OrdineLavorazioneDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPartitaMagProd() {
|
||||
return partitaMagProd;
|
||||
}
|
||||
|
||||
public OrdineLavorazioneDTO setPartitaMagProd(String partitaMagProd) {
|
||||
this.partitaMagProd = partitaMagProd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataScad() {
|
||||
return dataScad;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws Exception {
|
||||
|
||||
if (requestData.getRequestURI().contains("system/ok")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String profileDb = settingsModel.getDefaultProfile();
|
||||
if (requestData != null && requestData.isValidProfileDB()) {
|
||||
|
||||
@@ -93,9 +93,7 @@ public class UserCacheService {
|
||||
.filter(x -> x.getUsername().equalsIgnoreCase(user.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if (existentUser.isPresent()) {
|
||||
users.remove(existentUser.get());
|
||||
}
|
||||
existentUser.ifPresent(users::remove);
|
||||
|
||||
users.add(user);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class CtbBeni extends EntityBase {
|
||||
@SqlField(value = "cod_bene", maxLength = 10, nullable = false)
|
||||
private String codBene;
|
||||
|
||||
@SqlField(value = "descrizione", maxLength = 1024)
|
||||
@SqlField(value = "descrizione", maxLength = 1024, nullable = false)
|
||||
private String descrizione;
|
||||
|
||||
@SqlField(value = "data_doc_acq", nullable = false)
|
||||
|
||||
@@ -1605,13 +1605,6 @@ public class DtbDoct extends DtbBaseDocT implements EquatableEntityInterface<Dtb
|
||||
for (DtbDocCarat dtbDocCarat : getDtbDocCarat()) {
|
||||
dtbDocCarat.manageWithParentConnection(connection, dtbDocCarat.getOperation(), dataCompleting, entityHolder);
|
||||
}
|
||||
for (MtbColt mtbColt : getMtbColt()) {
|
||||
if (mtbColt.getOperation() == OperationType.DELETE) {
|
||||
deleteRifDocdaCollo(mtbColt);
|
||||
} else {
|
||||
mtbColt.manageWithParentConnection(connection, mtbColt.getOperation(), dataCompleting, entityHolder);
|
||||
}
|
||||
}
|
||||
for (DrlDocAttached drlDocAttached : getDrlDocAttached()) {
|
||||
drlDocAttached.manageWithParentConnection(connection, drlDocAttached.getOperation(), dataCompleting, entityHolder);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems_model.annotation.*;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
@@ -12,12 +13,13 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@Table(JtbCicl.ENTITY)
|
||||
@JsonTypeName(JtbCicl.ENTITY)
|
||||
public class JtbCicl extends EntityBase {
|
||||
public class JtbCicl extends EntityBase implements EquatableEntityInterface<JtbCicl> {
|
||||
|
||||
private final static Logger logger = LogManager.getLogger();
|
||||
|
||||
@@ -586,4 +588,32 @@ public class JtbCicl extends EntityBase {
|
||||
JtbCiclCq jtbCiclCq = new JtbCiclCq();
|
||||
jtbCiclCq.deleteAllEntities(connection, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCodeKey() {
|
||||
return Objects.hash(getCodProd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsKey(JtbCicl other) {
|
||||
if (this == other)
|
||||
return true;
|
||||
|
||||
if (hashCodeKey() != other.hashCodeKey())
|
||||
return false;
|
||||
|
||||
return Objects.equals(getCodProd(), other.getCodProd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof JtbCicl)) return false;
|
||||
JtbCicl jtbCicl = (JtbCicl) o;
|
||||
return Objects.equals(getCodProd(), jtbCicl.getCodProd()) && Objects.equals(getCodJfas(), jtbCicl.getCodJfas()) && Objects.equals(getQtaProd(), jtbCicl.getQtaProd()) && Objects.equals(getgIniz(), jtbCicl.getgIniz()) && Objects.equals(getGgTot(), jtbCicl.getGgTot()) && Objects.equals(getDescrizione(), jtbCicl.getDescrizione()) && Objects.equals(getDataUltVar(), jtbCicl.getDataUltVar()) && Objects.equals(getDescrizioneProd(), jtbCicl.getDescrizioneProd()) && Objects.equals(getUntMisProd(), jtbCicl.getUntMisProd()) && Objects.equals(getCaratteristica1(), jtbCicl.getCaratteristica1()) && Objects.equals(getDescrizioneCar1(), jtbCicl.getDescrizioneCar1()) && Objects.equals(getCaratteristica2(), jtbCicl.getCaratteristica2()) && Objects.equals(getDescrizioneCar2(), jtbCicl.getDescrizioneCar2()) && Objects.equals(getPesoSpec(), jtbCicl.getPesoSpec()) && Objects.equals(getDescrizioneEstesa(), jtbCicl.getDescrizioneEstesa()) && Objects.equals(getPercCostGen(), jtbCicl.getPercCostGen()) && Objects.equals(getPercRicLb(), jtbCicl.getPercRicLb()) && Objects.equals(getCodMart(), jtbCicl.getCodMart()) && Objects.equals(getFlagAttiva(), jtbCicl.getFlagAttiva()) && Objects.equals(getImgFile(), jtbCicl.getImgFile()) && Objects.equals(getRapConvProd(), jtbCicl.getRapConvProd()) && Objects.equals(getCodDiviCont(), jtbCicl.getCodDiviCont()) && Objects.equals(getCambioDiviCont(), jtbCicl.getCambioDiviCont()) && Objects.equals(getLunghezza(), jtbCicl.getLunghezza()) && Objects.equals(getLarghezza(), jtbCicl.getLarghezza()) && Objects.equals(getAltezza(), jtbCicl.getAltezza()) && Objects.equals(getLottoMinOrd(), jtbCicl.getLottoMinOrd()) && Objects.equals(getFlagQtaMultipla(), jtbCicl.getFlagQtaMultipla()) && Objects.equals(getQtaAllocazione(), jtbCicl.getQtaAllocazione()) && Objects.equals(getActivityTypeId(), jtbCicl.getActivityTypeId()) && Objects.equals(getFlagTipologia(), jtbCicl.getFlagTipologia()) && Objects.equals(getFlagTipoProd(), jtbCicl.getFlagTipoProd()) && Objects.equals(getSupplyDefault(), jtbCicl.getSupplyDefault()) && Objects.equals(getFlagScomposizione(), jtbCicl.getFlagScomposizione()) && Objects.equals(getCodCq(), jtbCicl.getCodCq()) && Objects.equals(getDataIns(), jtbCicl.getDataIns()) && Objects.equals(getPrezzoBase(), jtbCicl.getPrezzoBase()) && Objects.equals(getCostoProduzione(), jtbCicl.getCostoProduzione()) && Objects.equals(getCostoComplessivo(), jtbCicl.getCostoComplessivo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getCodProd(), getCodJfas(), getQtaProd(), getgIniz(), getGgTot(), getDescrizione(), getDataUltVar(), getDescrizioneProd(), getUntMisProd(), getCaratteristica1(), getDescrizioneCar1(), getCaratteristica2(), getDescrizioneCar2(), getPesoSpec(), getDescrizioneEstesa(), getPercCostGen(), getPercRicLb(), getCodMart(), getFlagAttiva(), getImgFile(), getRapConvProd(), getCodDiviCont(), getCambioDiviCont(), getLunghezza(), getLarghezza(), getAltezza(), getLottoMinOrd(), getFlagQtaMultipla(), getQtaAllocazione(), getActivityTypeId(), getFlagTipologia(), getFlagTipoProd(), getSupplyDefault(), getFlagScomposizione(), getCodCq(), getDataIns(), getPrezzoBase(), getCostoProduzione(), getCostoComplessivo());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,19 @@ import it.integry.ems_model.annotation.SqlDetailId;
|
||||
import it.integry.ems_model.annotation.SqlField;
|
||||
import it.integry.ems_model.annotation.Table;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@PropertyReactive
|
||||
@Table(JtbDistMate.ENTITY)
|
||||
@JsonTypeName(JtbDistMate.ENTITY)
|
||||
public class JtbDistMate extends EntityBase {
|
||||
public class JtbDistMate extends EntityBase implements EquatableEntityInterface<JtbDistMate> {
|
||||
|
||||
private final static Logger logger = LogManager.getLogger();
|
||||
|
||||
@@ -88,128 +90,144 @@ public class JtbDistMate extends EntityBase {
|
||||
return codProd;
|
||||
}
|
||||
|
||||
public void setCodProd(String codProd) {
|
||||
public JtbDistMate setCodProd(String codProd) {
|
||||
this.codProd = codProd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getIdRiga() {
|
||||
return idRiga;
|
||||
}
|
||||
|
||||
public void setIdRiga(Integer idRiga) {
|
||||
public JtbDistMate setIdRiga(Integer idRiga) {
|
||||
this.idRiga = idRiga;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodMart() {
|
||||
return codMart;
|
||||
}
|
||||
|
||||
public void setCodMart(String codMart) {
|
||||
public JtbDistMate setCodMart(String codMart) {
|
||||
this.codMart = codMart;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getQtaStd() {
|
||||
return qtaStd;
|
||||
}
|
||||
|
||||
public void setQtaStd(BigDecimal qtaStd) {
|
||||
public JtbDistMate setQtaStd(BigDecimal qtaStd) {
|
||||
this.qtaStd = qtaStd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescrizione() {
|
||||
return descrizione;
|
||||
}
|
||||
|
||||
public void setDescrizione(String descrizione) {
|
||||
public JtbDistMate setDescrizione(String descrizione) {
|
||||
this.descrizione = descrizione;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRifProgetto() {
|
||||
return rifProgetto;
|
||||
}
|
||||
|
||||
public void setRifProgetto(String rifProgetto) {
|
||||
public JtbDistMate setRifProgetto(String rifProgetto) {
|
||||
this.rifProgetto = rifProgetto;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
public JtbDistMate setNote(String note) {
|
||||
this.note = note;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getPercSfrido() {
|
||||
return percSfrido;
|
||||
}
|
||||
|
||||
public void setPercSfrido(BigDecimal percSfrido) {
|
||||
public JtbDistMate setPercSfrido(BigDecimal percSfrido) {
|
||||
this.percSfrido = percSfrido;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescrizioneEstesa() {
|
||||
return descrizioneEstesa;
|
||||
}
|
||||
|
||||
public void setDescrizioneEstesa(String descrizioneEstesa) {
|
||||
public JtbDistMate setDescrizioneEstesa(String descrizioneEstesa) {
|
||||
this.descrizioneEstesa = descrizioneEstesa;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUntMisDist() {
|
||||
return untMisDist;
|
||||
}
|
||||
|
||||
public void setUntMisDist(String untMisDist) {
|
||||
public JtbDistMate setUntMisDist(String untMisDist) {
|
||||
this.untMisDist = untMisDist;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getRapConvDist() {
|
||||
return rapConvDist;
|
||||
}
|
||||
|
||||
public void setRapConvDist(BigDecimal rapConvDist) {
|
||||
public JtbDistMate setRapConvDist(BigDecimal rapConvDist) {
|
||||
this.rapConvDist = rapConvDist;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFlagPri() {
|
||||
return flagPri;
|
||||
}
|
||||
|
||||
public void setFlagPri(String flagPri) {
|
||||
public JtbDistMate setFlagPri(String flagPri) {
|
||||
this.flagPri = flagPri;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getCostoUnt() {
|
||||
return costoUnt;
|
||||
}
|
||||
|
||||
public void setCostoUnt(BigDecimal costoUnt) {
|
||||
public JtbDistMate setCostoUnt(BigDecimal costoUnt) {
|
||||
this.costoUnt = costoUnt;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getNumFase() {
|
||||
return numFase;
|
||||
}
|
||||
|
||||
public void setNumFase(Integer numFase) {
|
||||
public JtbDistMate setNumFase(Integer numFase) {
|
||||
this.numFase = numFase;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getDataUltMod() {
|
||||
return dataUltMod;
|
||||
}
|
||||
|
||||
public void setDataUltMod(Date dataUltMod) {
|
||||
public JtbDistMate setDataUltMod(Date dataUltMod) {
|
||||
this.dataUltMod = dataUltMod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModificatoDa() {
|
||||
return modificatoDa;
|
||||
}
|
||||
|
||||
public void setModificatoDa(String modificatoDa) {
|
||||
public JtbDistMate setModificatoDa(String modificatoDa) {
|
||||
this.modificatoDa = modificatoDa;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCodProdPri() {
|
||||
@@ -220,4 +238,32 @@ public class JtbDistMate extends EntityBase {
|
||||
this.codProdPri = codProdPri;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCodeKey() {
|
||||
return Objects.hash(getCodProd(), getIdRiga());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsKey(JtbDistMate other) {
|
||||
if (this == other)
|
||||
return true;
|
||||
|
||||
if (hashCodeKey() != other.hashCodeKey())
|
||||
return false;
|
||||
|
||||
return Objects.equals(getCodProd(), other.getCodProd()) && Objects.equals(getIdRiga(), other.getIdRiga());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof JtbDistMate)) return false;
|
||||
JtbDistMate that = (JtbDistMate) o;
|
||||
return Objects.equals(getCodProd(), that.getCodProd()) && Objects.equals(getIdRiga(), that.getIdRiga()) && Objects.equals(getCodMart(), that.getCodMart()) && Objects.equals(getQtaStd(), that.getQtaStd()) && Objects.equals(getDescrizione(), that.getDescrizione()) && Objects.equals(getRifProgetto(), that.getRifProgetto()) && Objects.equals(getNote(), that.getNote()) && Objects.equals(getPercSfrido(), that.getPercSfrido()) && Objects.equals(getDescrizioneEstesa(), that.getDescrizioneEstesa()) && Objects.equals(getUntMisDist(), that.getUntMisDist()) && Objects.equals(getRapConvDist(), that.getRapConvDist()) && Objects.equals(getFlagPri(), that.getFlagPri()) && Objects.equals(getCostoUnt(), that.getCostoUnt()) && Objects.equals(getNumFase(), that.getNumFase()) && Objects.equals(getDataUltMod(), that.getDataUltMod()) && Objects.equals(getModificatoDa(), that.getModificatoDa()) && Objects.equals(getCodProdPri(), that.getCodProdPri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getCodProd(), getIdRiga(), getCodMart(), getQtaStd(), getDescrizione(), getRifProgetto(), getNote(), getPercSfrido(), getDescrizioneEstesa(), getUntMisDist(), getRapConvDist(), getFlagPri(), getCostoUnt(), getNumFase(), getDataUltMod(), getModificatoDa(), getCodProdPri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.entity.StbGestSetupDet;
|
||||
import it.integry.ems_model.utility.Query;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.json.JSONArray;
|
||||
@@ -303,6 +305,27 @@ public class SetupGest {
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, query);
|
||||
}
|
||||
|
||||
public List<StbGestSetupDet> getSetupDetList(String gestName, String section, String keySection) throws Exception {
|
||||
MultiDBTransactionManager multiDBTransactionManager = ContextLoader.getCurrentWebApplicationContext().getBean(MultiDBTransactionManager.class);
|
||||
|
||||
return getSetupDetList(multiDBTransactionManager.getPrimaryConnection(), gestName, section, keySection);
|
||||
}
|
||||
|
||||
public List<StbGestSetupDet> getSetupDetList(Connection connection, String gestName, String section, String keySection) throws Exception {
|
||||
String sql = Query.format(
|
||||
"SELECT val_col_rif, CONVERT(TEXT, value) AS value\n" +
|
||||
"FROM stb_gest_setup_det\n" +
|
||||
"WHERE gest_name = %s\n" +
|
||||
" AND section = %s\n" +
|
||||
" AND key_section = %s",
|
||||
gestName,
|
||||
section,
|
||||
keySection
|
||||
);
|
||||
|
||||
return UtilityDB.executeSimpleQueryDTO(connection, sql, StbGestSetupDet.class);
|
||||
}
|
||||
|
||||
//UTENTE WEB
|
||||
public boolean getSetupUserBoolean(Connection conn, String gestName, String section, String keySection, String username) throws Exception {
|
||||
return "S".equalsIgnoreCase(getSetupUser(conn, gestName, section, keySection, username));
|
||||
|
||||
@@ -56,3 +56,17 @@ then
|
||||
modify ( $ordR ) { setDataInizProd(dataInizProd) }
|
||||
end
|
||||
|
||||
rule "completeNumOrdProd"
|
||||
no-loop
|
||||
salience 10
|
||||
when
|
||||
eval(completeRulesEnabled)
|
||||
$entity : DtbOrdt(gestione == "A" && gestioneRif == "A" && dataOrd != null && codAnag != null && codJfas != null
|
||||
&& numOrd == null && dataOrdRif == null && numOrdRif == null
|
||||
&& (operation == OperationType.INSERT || operation == OperationType.INSERT_OR_UPDATE))
|
||||
then
|
||||
Integer numOrd = DocOrdRules.completeNumOrdProd(conn, $entity);
|
||||
modify($entity) {
|
||||
setNumOrd(numOrd)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -21,4 +21,15 @@ global Boolean completeRulesEnabled
|
||||
global IntegryCustomerDB customerDb
|
||||
global IntegryCustomer customer
|
||||
|
||||
rule "completeMtbColtProgressivoUlRG"
|
||||
no-loop
|
||||
when
|
||||
eval(postRulesEnabled)
|
||||
$mtbColt: MtbColt(operation != OperationType.DELETE && progressivoUl == null && gestione != null && gestione == 'L' && dataOrd != null && numOrd != null)
|
||||
then
|
||||
int progressivoToSave = CommonRules.retrieveNextProgressivoUlRG(conn, $mtbColt.getGestione(), $mtbColt.getDataOrd(), $mtbColt.getNumOrd(), $mtbColt.getSegno());
|
||||
|
||||
modify($mtbColt){
|
||||
setProgressivoUl(progressivoToSave);
|
||||
}
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ import it.integry.ems.utility.UtilityLogger
|
||||
import it.integry.ems.utility.UtilityEntity
|
||||
import it.integry.ems_model.utility.UtilityHashMap
|
||||
import it.integry.ems_model.utility.UtilityDate
|
||||
import it.integry.ems_model.utility.UtilityDB
|
||||
|
||||
global Connection conn
|
||||
global String username
|
||||
@@ -735,3 +736,15 @@ then
|
||||
setFlagCont($entity.getNumCmov()==null?"N":"S")
|
||||
}
|
||||
end
|
||||
|
||||
rule "completeCodBene"
|
||||
no-loop
|
||||
when
|
||||
eval(completeRulesEnabled)
|
||||
$entity : CtbBeni(codCatbene != null && codBene == null && operation != OperationType.DELETE)
|
||||
then
|
||||
String codBene = AccountingRules.completeCodBene(conn, $entity);
|
||||
modify ( $entity ) {
|
||||
setCodBene(codBene)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -870,7 +870,7 @@ public class SteUPService {
|
||||
(chkRotturaStock?"mvw_barcode.cod_barre":"griglia.bar_code") + " as barcode, \n" +
|
||||
"cod_msgr\n " +
|
||||
" from steup_getGrigliaVendita(" + UtilityDB.valueToString(codMdep) + "," + UtilityDB.valueToString(codJfas) + ") griglia " +
|
||||
(chkRotturaStock?" INNER JOIN mvw_barcode on griglia.cod_mart = mvw_barcode.cod_mart ":"") +
|
||||
(chkRotturaStock?" INNER JOIN mvw_barcode on griglia.cod_mart_kit = mvw_barcode.cod_mart ":"") +
|
||||
"order by descrizione";
|
||||
} else if (chkRotturaStock && barcode != null & !barcode.isEmpty()) {
|
||||
sql = "SELECT cod_mart,descrizione,bar_code as barcode,cod_msgr\n" +
|
||||
|
||||
@@ -449,38 +449,37 @@ public class AutofatturaService {
|
||||
}
|
||||
|
||||
for (AvailableConnectionsModel model : availableConnections) {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(model.getProfileName());
|
||||
Connection conn = ds.getConnection();
|
||||
String sql = "select e_mail from stb_email where flag_default_contabilita = 'S'";
|
||||
List<String> email = UtilityDB.executeSimpleQueryOnlyFirstColumn(conn, sql);
|
||||
Azienda azienda = Azienda.getDefaultAzienda(conn);
|
||||
if (email == null || email.isEmpty()) {
|
||||
mailService.sendSystemErrorLog("[" + model.getProfileName() + " - " + azienda.getNomeDitta() + "][" + UtilityServer.getHostName() + "] Verifica autofatture ",
|
||||
"Verifica autofatture",
|
||||
"Sull'azienda " + azienda.getNomeDitta() + " non è presente nessuna email con flag default contabilità, non sarà possibile inviare la mail di verifica.",
|
||||
(String) null, new Date());
|
||||
} else {
|
||||
sql =
|
||||
"select Cast(ctb_movt.num_cmov as varchar) as num_cmov " +
|
||||
"from ctb_movt " +
|
||||
"inner join ctb_movi on ctb_movt.num_cmov = ctb_movi.num_cmov " +
|
||||
"inner join gtb_aliq on ctb_movi.cod_aliq = gtb_aliq.cod_aliq AND gtb_aliq.flag_autofattura = 'S' " +
|
||||
"inner join ctb_ireg on ctb_movt.cod_ireg = ctb_ireg.cod_ireg AND ctb_ireg.segno_liquid = -1 " +
|
||||
"WHERE ctb_movt.data_cmov BETWEEN DateAdd(day, -15, Cast(getDate() as date)) AND DateAdd(day, -1, Cast(getDate() as date)) AND " +
|
||||
"not exists (SELECT num_cmov FROM crl_movt_rif_cmov WHERE ctb_movt.num_cmov = crl_movt_rif_cmov.num_cmov OR ctb_movt.num_cmov = crl_movt_rif_cmov.num_cmov_rif)";
|
||||
List<String> listMov = UtilityDB.executeSimpleQueryOnlyFirstColumn(conn, sql);
|
||||
if (listMov != null && !listMov.isEmpty()) {
|
||||
String elencoMovimenti = String.join(CommonConstants.A_CAPO, listMov);
|
||||
String elencoEmail = String.join(",", email);
|
||||
String message =
|
||||
"Attenzione i seguenti movimenti contabili non hanno la fattura di integrazione agganciata: " + CommonConstants.A_CAPO + elencoMovimenti;
|
||||
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager(model)) {
|
||||
|
||||
mailService.sendMail(elencoEmail, null, "[" + model.getProfileName() + " - " + azienda.getNomeDitta() + "] Verifica autofatture ", message);
|
||||
Connection conn = mdb.getPrimaryConnection();
|
||||
String sql = "select e_mail from stb_email where flag_default_contabilita = 'S'";
|
||||
List<String> email = UtilityDB.executeSimpleQueryOnlyFirstColumn(conn, sql);
|
||||
Azienda azienda = Azienda.getDefaultAzienda(conn);
|
||||
if (email == null || email.isEmpty()) {
|
||||
mailService.sendSystemErrorLog("[" + model.getProfileName() + " - " + azienda.getNomeDitta() + "][" + UtilityServer.getHostName() + "] Verifica autofatture ",
|
||||
"Verifica autofatture",
|
||||
"Sull'azienda " + azienda.getNomeDitta() + " non è presente nessuna email con flag default contabilità, non sarà possibile inviare la mail di verifica.",
|
||||
(String) null, new Date());
|
||||
} else {
|
||||
sql =
|
||||
"select Cast(ctb_movt.num_cmov as varchar) as num_cmov " +
|
||||
"from ctb_movt " +
|
||||
"inner join ctb_movi on ctb_movt.num_cmov = ctb_movi.num_cmov " +
|
||||
"inner join gtb_aliq on ctb_movi.cod_aliq = gtb_aliq.cod_aliq AND gtb_aliq.flag_autofattura = 'S' " +
|
||||
"inner join ctb_ireg on ctb_movt.cod_ireg = ctb_ireg.cod_ireg AND ctb_ireg.segno_liquid = -1 " +
|
||||
"WHERE ctb_movt.data_cmov BETWEEN DateAdd(day, -15, Cast(getDate() as date)) AND DateAdd(day, -1, Cast(getDate() as date)) AND " +
|
||||
"not exists (SELECT num_cmov FROM crl_movt_rif_cmov WHERE ctb_movt.num_cmov = crl_movt_rif_cmov.num_cmov OR ctb_movt.num_cmov = crl_movt_rif_cmov.num_cmov_rif)";
|
||||
List<String> listMov = UtilityDB.executeSimpleQueryOnlyFirstColumn(conn, sql);
|
||||
if (listMov != null && !listMov.isEmpty()) {
|
||||
String elencoMovimenti = String.join(CommonConstants.A_CAPO, listMov);
|
||||
String elencoEmail = String.join(",", email);
|
||||
String message =
|
||||
"Attenzione i seguenti movimenti contabili non hanno la fattura di integrazione agganciata: " + CommonConstants.A_CAPO + elencoMovimenti;
|
||||
|
||||
mailService.sendMail(elencoEmail, null, "[" + model.getProfileName() + " - " + azienda.getNomeDitta() + "] Verifica autofatture ", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ds.forceClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package it.integry.ems.contabil.service;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.contabil.dto.AutofatturaDTO;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
@@ -33,18 +32,17 @@ public class DulciarSincronizzazione {
|
||||
|
||||
@Autowired
|
||||
EntityProcessor entityProcessor;
|
||||
|
||||
@Autowired
|
||||
AutofatturaService autofatturaService;
|
||||
|
||||
public void sync() throws Exception {
|
||||
DataSource dulciarSource = new DataSource();
|
||||
dulciarSource.initialize("DULCIAR");
|
||||
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager("DULCIAR")) {
|
||||
Date dataIniz = UtilityDate.dateFromPart(2022, 07, 01);
|
||||
|
||||
Date dataIniz = UtilityDate.dateFromPart(2022, 07, 01);
|
||||
|
||||
syncDoc(dulciarSource.getConnection(), dataIniz);
|
||||
|
||||
syncMovCont(dulciarSource.getConnection(), dataIniz);
|
||||
syncDoc(mdb.getPrimaryConnection(), dataIniz);
|
||||
syncMovCont(mdb.getPrimaryConnection(), dataIniz);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncDoc(Connection connection, Date dataIniz) throws Exception {
|
||||
|
||||
@@ -3,11 +3,11 @@ package it.integry.ems.contabil.service;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.contabil.dto.AutofatturaDTO;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
import it.integry.ems.rules.businessLogic.enums.TipoPartita;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
@@ -25,9 +25,6 @@ import org.springframework.stereotype.Service;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
@@ -57,30 +54,29 @@ public class RossoGarganoSyncService {
|
||||
private List<String> fornitori = new ArrayList<>();
|
||||
|
||||
public void sync() throws Exception {
|
||||
Date startDate = new Date();
|
||||
DataSource rgExchange = new DataSource();
|
||||
rgExchange.initialize("ROSSOGARGANOEXCHANGE");
|
||||
try {
|
||||
saveCtbCaus(rgExchange.getConnection());
|
||||
logger.info("Importazione causali: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
int timingId = UtilityTiming.startNewTiming("Sync RossoGargano");
|
||||
|
||||
saveGtbPaga(rgExchange.getConnection());
|
||||
logger.info("Importazione codici pagamento: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager("ROSSOGARGANOEXCHANGE")) {
|
||||
saveCtbCaus(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione causali");
|
||||
|
||||
saveGtbAliq(rgExchange.getConnection());
|
||||
logger.info("Importazione codici aliquota: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveGtbPaga(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione codici pagamento");
|
||||
|
||||
saveVtbAgen(rgExchange.getConnection());
|
||||
logger.info("Importazione agenti: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveGtbAliq(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione codici aliquota");
|
||||
|
||||
savePdc(rgExchange.getConnection());
|
||||
logger.info("Importazione Conti del piano dei conti: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveVtbAgen(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione agenti");
|
||||
|
||||
saveFornitori(rgExchange.getConnection());
|
||||
logger.info("Importazione Fornitori dei conti: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
savePdc(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione Conti del piano dei conti");
|
||||
|
||||
deleteCtbMovt(rgExchange.getConnection());
|
||||
logger.info("Cancellazione movimenti contabili: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveFornitori(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione Fornitori dei conti");
|
||||
|
||||
deleteCtbMovt(mdb.getPrimaryConnection());
|
||||
UtilityTiming.intervalTiming(timingId, "Cancellazione movimenti contabili");
|
||||
|
||||
String sql =
|
||||
"SELECT CAST(FORMAT(DATEPART(YEAR, data_iniz), '0000') +\n" +
|
||||
@@ -100,14 +96,16 @@ public class RossoGarganoSyncService {
|
||||
|
||||
BigDecimal dataFine = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
saveCtbMovt(rgExchange.getConnection(), "(PNOTA.PN_DATA_COMPETENZA = 20210701 AND PN_CAUSALE_MOVIMENTO = '998')", dataIniz, dataFine, false);
|
||||
logger.info("Importazione apertura conti: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveCtbMovt(mdb.getPrimaryConnection(), "(PNOTA.PN_DATA_COMPETENZA = 20210701 AND PN_CAUSALE_MOVIMENTO = '998')", dataIniz, dataFine, false);
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione apertura conti");
|
||||
|
||||
saveCtbMovt(rgExchange.getConnection(), "(PNOTA.PN_SEZIONALE_IVA <> '' AND PN_CAUSALE_MOVIMENTO <> '998')", dataIniz, dataFine, false);
|
||||
logger.info("Importazione fatture attive e passive: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveCtbMovt(mdb.getPrimaryConnection(), "(PNOTA.PN_SEZIONALE_IVA <> '' AND PN_CAUSALE_MOVIMENTO <> '998')", dataIniz, dataFine, false);
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione fatture attive e passive");
|
||||
|
||||
saveCtbMovt(rgExchange.getConnection(), "(PN_CAUSALE_MOVIMENTO <> '998')", dataIniz, dataFine, true);
|
||||
logger.info("Importazione altri movimenti contabili: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
saveCtbMovt(mdb.getPrimaryConnection(), "(PN_CAUSALE_MOVIMENTO <> '998')", dataIniz, dataFine, true);
|
||||
UtilityTiming.intervalTiming(timingId, "Importazione altri movimenti contabili");
|
||||
|
||||
UtilityTiming.endTiming(timingId, true);
|
||||
} catch (Exception e) {
|
||||
if (!UtilityDebug.isDebugExecution()) {
|
||||
mailService.sendSystemErrorLog("Importazione movimenti contabili " + multiDBTransactionManager.getPrimaryDatasource().getDbName(),
|
||||
@@ -116,8 +114,6 @@ public class RossoGarganoSyncService {
|
||||
e, new Date());
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
rgExchange.forceClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public class CaricoProdFinLavDTO {
|
||||
private String activityID;
|
||||
private Integer idLotto;
|
||||
private boolean escludiArticoliGestitiDaWmsInScarico;
|
||||
private boolean fermaCreaDocs;
|
||||
|
||||
public String getCodJfas() {
|
||||
return codJfas;
|
||||
@@ -401,4 +402,13 @@ public class CaricoProdFinLavDTO {
|
||||
this.numDoc = numDoc;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isFermaCreaDocs() {
|
||||
return fermaCreaDocs;
|
||||
}
|
||||
|
||||
public CaricoProdFinLavDTO setFermaCreaDocs(boolean fermaCreaDocs) {
|
||||
this.fermaCreaDocs = fermaCreaDocs;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class DocumentiExporter extends BaseEntityExporter implements IEntityExpo
|
||||
break;
|
||||
case INTESA:
|
||||
DocumentiIntesaExportService intesaExportService = context.getBean(DocumentiIntesaExportService.class);
|
||||
entityExportResponse = intesaExportService.export(username, type, format);
|
||||
entityExportResponse = intesaExportService.export(whereCond, type, format, anomalie);
|
||||
break;
|
||||
case EXCEL:
|
||||
case CSV:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package it.integry.ems.document.export.service;
|
||||
|
||||
import com.mysql.cj.xdevapi.Warning;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.export.base.EntityExportResponse;
|
||||
import it.integry.ems.response.FileItem;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
@@ -20,6 +22,7 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Scope("request")
|
||||
@@ -37,22 +40,29 @@ public class DocumentiIntesaExportService {
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
public EntityExportResponse<List<FileItem>> export(String userName, String type, String format) throws Exception {
|
||||
EntityExportResponse<List<FileItem>> entityExportResponse = new EntityExportResponse<>();
|
||||
public EntityExportResponse<List<FileItem>> export(String whereCond, String type, String format, List<AnomalieDTO> anomalie) throws Exception {
|
||||
Connection conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
|
||||
Date dataDoc = UtilityDate.StringToDate("27/02/2025", CommonConstants.DATE_FORMAT_DMY);
|
||||
EntityExportResponse<List<FileItem>> entityExportResponse = new EntityExportResponse<>();
|
||||
entityExportResponse.setAnomalie(anomalie);
|
||||
|
||||
char charSeparator = ';';
|
||||
String fileName = "index";
|
||||
String ext = "csv";
|
||||
|
||||
String sql = UtilityDB.addwhereCond("SELECT * FROM dtb_doct ", whereCond, false);
|
||||
List<DtbDoct> dtbDocts = UtilityDB.executeSimpleQueryDTO(conn, sql, DtbDoct.class);
|
||||
if (dtbDocts == null || dtbDocts.isEmpty()) throw new Exception("Nessun documento trovato");
|
||||
|
||||
List<Date> dateDocumenti = dtbDocts.stream().map(DtbDoct::getDataDoc).collect(Collectors.toList());
|
||||
|
||||
Map<String, String> setup = setupGest.getExportSetupSection(conn, type, format);
|
||||
String piattaforma = setup.get("PIATTAFORMA");
|
||||
String comunita = setup.get("COMUNITA");
|
||||
String azienda = setup.get("AZIENDA");
|
||||
String tipoDoc = setup.get("TIPO_DOC");
|
||||
|
||||
String sql = Query.format(
|
||||
sql = Query.format(
|
||||
"WITH RankedPDF AS (SELECT pdf.*,\n" +
|
||||
" ROW_NUMBER() OVER (\n" +
|
||||
" PARTITION BY pdf.data_doc, pdf.num_doc, pdf.ser_doc, pdf.cod_anag, pdf.cod_dtip\n" +
|
||||
@@ -87,11 +97,11 @@ public class DocumentiIntesaExportService {
|
||||
" ON doc.data_doc = pdf.data_doc AND doc.num_doc = pdf.num_doc AND doc.ser_doc = pdf.ser_doc\n" +
|
||||
" AND doc.cod_anag = pdf.cod_anag AND doc.cod_dtip = pdf.cod_dtip\n" +
|
||||
" CROSS APPLY azienda\n" +
|
||||
"WHERE doc.data_doc = %s\n" +
|
||||
"WHERE doc.data_doc IN (" + UtilityDB.listValueToString(dateDocumenti) + ")\n" +
|
||||
" AND doc.gestione = 'V'\n" +
|
||||
" AND dtb_tipi.tipo_emissione = 'DIRETTA'\n" +
|
||||
" AND pdf.rn = 1",
|
||||
SIGNED_PREFIX, piattaforma, comunita, azienda, dataDoc
|
||||
SIGNED_PREFIX, piattaforma, comunita, azienda
|
||||
);
|
||||
|
||||
byte[] csvContent = UtilityQuery.mapQueryToCSV(conn, sql, charSeparator, false, false).getBytes();
|
||||
@@ -115,11 +125,11 @@ public class DocumentiIntesaExportService {
|
||||
" INNER JOIN RankedPDF pdf\n" +
|
||||
" ON doc.data_doc = pdf.data_doc AND doc.num_doc = pdf.num_doc AND doc.ser_doc = pdf.ser_doc\n" +
|
||||
" AND doc.cod_anag = pdf.cod_anag AND doc.cod_dtip = pdf.cod_dtip\n" +
|
||||
"WHERE doc.data_doc = %s\n" +
|
||||
"WHERE doc.data_doc = " + UtilityDB.listValueToString(dateDocumenti) + "\n" +
|
||||
" AND doc.gestione = 'V'\n" +
|
||||
" AND dtb_tipi.tipo_emissione = 'DIRETTA'\n" +
|
||||
" AND pdf.rn = 1",
|
||||
SIGNED_PREFIX, dataDoc
|
||||
SIGNED_PREFIX
|
||||
);
|
||||
List<HashMap<String, Object>> resultQuery = UtilityDB.executeSimpleQuery(conn, sql);
|
||||
List<DtbDocPdf> dtbDocPdfList = new ArrayList<>();
|
||||
@@ -156,9 +166,11 @@ public class DocumentiIntesaExportService {
|
||||
|
||||
entityProcessor.processEntityList(dtbDocPdfList, true);
|
||||
|
||||
if (dtbDocPdfList.isEmpty()) {
|
||||
logger.info("[Esportazione Intesa del {}] nessun file inviato", new Date());
|
||||
return null;
|
||||
if (logger.isInfoEnabled() && dtbDocPdfList.isEmpty()) {
|
||||
String anomalia = "Nessun file firmato inviato";
|
||||
logger.error(anomalia);
|
||||
anomalie.add(AnomalieDTO.warning(anomalia));
|
||||
return entityExportResponse;
|
||||
}
|
||||
|
||||
List<FileItem> listFileToZip = new ArrayList<>();
|
||||
|
||||
@@ -651,9 +651,7 @@ public class DocumentProdService {
|
||||
boolean fermaCreaDocsEnabled = setupGest.getSetupBoolean(multiDBTransactionManager.getPrimaryConnection(), "CARICO_SCARICO_PF", "SETUP", "FERMA_CREA_DOCS");
|
||||
|
||||
if (fermaCreaDocsEnabled) {
|
||||
boolean fermaCreaDocs = setupGest.getSetupUserBoolean(multiDBTransactionManager.getPrimaryConnection(), "CARICO_SCARICO_PF", "SETUP", "FERMA_CREA_DOCS", requestDataDTO.getUsername());
|
||||
|
||||
if (fermaCreaDocs) {
|
||||
if (carico.isFermaCreaDocs() || setupGest.getSetupUserBoolean(multiDBTransactionManager.getPrimaryConnection(), "CARICO_SCARICO_PF", "SETUP", "FERMA_CREA_DOCS", requestDataDTO.getUsername())) {
|
||||
DtbOrdt dtbOrdt = new DtbOrdt();
|
||||
|
||||
dtbOrdt
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package it.integry.ems.logistic.Import.service;
|
||||
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.entity.MtbColr;
|
||||
@@ -68,272 +66,272 @@ public class BiolexchImportService {
|
||||
throw new Exception("CONFIGURARE PROFILEDB BIOLEXCH IN STB_GEST_SETUP.");
|
||||
}
|
||||
|
||||
// Connessione al database di interscambio
|
||||
DataSource dsBiolexch = new DataSource();
|
||||
dsBiolexch.initialize(profileSource);
|
||||
Connection connBiolexch = dsBiolexch.getConnection();
|
||||
try (MultiDBTransactionManager exchangeMultiDb = new MultiDBTransactionManager(profileSource)) {
|
||||
|
||||
// Acquisizione colli da importare
|
||||
sql = "select colli.SSCC " +
|
||||
" ,colli.riga " +
|
||||
" ,colli.data_collo " +
|
||||
" ,colli.OrdRow " +
|
||||
" ,colli.cod_mart " +
|
||||
" ,colli.partita_mag " +
|
||||
" ,colli.data_scad " +
|
||||
" ,colli.UM " +
|
||||
" ,colli.qta_col " +
|
||||
" ,colli.num_cnf " +
|
||||
" ,colli.datetime_row " +
|
||||
" ,ordini.gestione " +
|
||||
" ,ordini.data_ord " +
|
||||
" ,ordini.num_ord " +
|
||||
" ,ordini.cod_anag " +
|
||||
" ,ordini.cod_vdes " +
|
||||
" ,ordini.cod_mdep " +
|
||||
" ,ordini.listino " +
|
||||
" ,ordini.anno " +
|
||||
" ,ordini.num_ord_provv " +
|
||||
" ,ordini.serie " +
|
||||
" ,colli.UDCOrigine " +
|
||||
" from (select SSCC " +
|
||||
",ROW_NUMBER() over (partition by SSCC order by SSCC) as riga " +
|
||||
",movdate as data_collo " +
|
||||
",OrdRow " +
|
||||
",ItemID as cod_mart " +
|
||||
",BatchNum as partita_mag " +
|
||||
",ExpirationDate as data_scad " +
|
||||
",UM " +
|
||||
",Qty as qta_col" +
|
||||
",NumPack as num_cnf" +
|
||||
",MovDate as datetime_row" +
|
||||
",flagERPRead " +
|
||||
",ordNum" +
|
||||
",ShippingList.UDCOrigine " +
|
||||
" from BiolevanteExch.dbo.ShippingList where len(SSCC) <> 0 AND SSCC IS NOT NULL) colli inner join " +
|
||||
" (select CONVERT(varchar(4), DATEPART(year, dtb_ordt.data_ord)) + 'I' + SPACE(2) + FORMAT(case when dbo.getGestSetup('IMPORT_COLLI', 'BIOLEXCH', 'ORDINI_DA_PLURIMA') = 'S' then dtb_ordt.num_ord_provv else dtb_ordt.num_ord end, '000000') as ordNumBiolexch, " +
|
||||
" dtb_ordt.gestione, " +
|
||||
" dtb_ordt.data_ord, " +
|
||||
" dtb_ordt.num_ord, " +
|
||||
" dtb_ordt.cod_anag, " +
|
||||
" dtb_ordt.cod_vdes, " +
|
||||
" dtb_ordt.cod_mdep, " +
|
||||
" dtb_ordt.listino, " +
|
||||
" dtb_ordr.riga_ord, " +
|
||||
" DATEPART(year, dtb_ordt.data_ord) as anno, " +
|
||||
" dtb_ordt.num_ord_provv, " +
|
||||
" dtb_ordt.serie " +
|
||||
" from dtb_ordt, " +
|
||||
" dtb_ordr " +
|
||||
" where dtb_ordt.data_ord = dtb_ordr.data_ord and " +
|
||||
" dtb_ordt.gestione = dtb_ordr.gestione and " +
|
||||
" dtb_ordt.num_ord = dtb_ordr.num_ord and" +
|
||||
" dtb_ordt.gestione = 'V' and " +
|
||||
" ISNULL(dtb_ordt.serie,'') = case when dbo.getGestSetup('IMPORT_COLLI', 'BIOLEXCH', 'ORDINI_DA_PLURIMA') = 'S' then 'O' else '' end and " +
|
||||
" dtb_ordt.data_ord > DATEADD(year, -1, getDate()) )ordini on colli.OrdNum = ordini.ordNumBiolexch and " +
|
||||
" colli.OrdRow = ordini.riga_ord " +
|
||||
" where flagERPRead = 0 " +
|
||||
"order by SSCC, riga";
|
||||
// Acquisizione colli da importare
|
||||
sql = "select colli.SSCC " +
|
||||
" ,colli.riga " +
|
||||
" ,colli.data_collo " +
|
||||
" ,colli.OrdRow " +
|
||||
" ,colli.cod_mart " +
|
||||
" ,colli.partita_mag " +
|
||||
" ,colli.data_scad " +
|
||||
" ,colli.UM " +
|
||||
" ,colli.qta_col " +
|
||||
" ,colli.num_cnf " +
|
||||
" ,colli.datetime_row " +
|
||||
" ,ordini.gestione " +
|
||||
" ,ordini.data_ord " +
|
||||
" ,ordini.num_ord " +
|
||||
" ,ordini.cod_anag " +
|
||||
" ,ordini.cod_vdes " +
|
||||
" ,ordini.cod_mdep " +
|
||||
" ,ordini.listino " +
|
||||
" ,ordini.anno " +
|
||||
" ,ordini.num_ord_provv " +
|
||||
" ,ordini.serie " +
|
||||
" ,colli.UDCOrigine " +
|
||||
" from (select SSCC " +
|
||||
",ROW_NUMBER() over (partition by SSCC order by SSCC) as riga " +
|
||||
",movdate as data_collo " +
|
||||
",OrdRow " +
|
||||
",ItemID as cod_mart " +
|
||||
",BatchNum as partita_mag " +
|
||||
",ExpirationDate as data_scad " +
|
||||
",UM " +
|
||||
",Qty as qta_col" +
|
||||
",NumPack as num_cnf" +
|
||||
",MovDate as datetime_row" +
|
||||
",flagERPRead " +
|
||||
",ordNum" +
|
||||
",ShippingList.UDCOrigine " +
|
||||
" from BiolevanteExch.dbo.ShippingList where len(SSCC) <> 0 AND SSCC IS NOT NULL) colli inner join " +
|
||||
" (select CONVERT(varchar(4), DATEPART(year, dtb_ordt.data_ord)) + 'I' + SPACE(2) + FORMAT(case when dbo.getGestSetup('IMPORT_COLLI', 'BIOLEXCH', 'ORDINI_DA_PLURIMA') = 'S' then dtb_ordt.num_ord_provv else dtb_ordt.num_ord end, '000000') as ordNumBiolexch, " +
|
||||
" dtb_ordt.gestione, " +
|
||||
" dtb_ordt.data_ord, " +
|
||||
" dtb_ordt.num_ord, " +
|
||||
" dtb_ordt.cod_anag, " +
|
||||
" dtb_ordt.cod_vdes, " +
|
||||
" dtb_ordt.cod_mdep, " +
|
||||
" dtb_ordt.listino, " +
|
||||
" dtb_ordr.riga_ord, " +
|
||||
" DATEPART(year, dtb_ordt.data_ord) as anno, " +
|
||||
" dtb_ordt.num_ord_provv, " +
|
||||
" dtb_ordt.serie " +
|
||||
" from dtb_ordt, " +
|
||||
" dtb_ordr " +
|
||||
" where dtb_ordt.data_ord = dtb_ordr.data_ord and " +
|
||||
" dtb_ordt.gestione = dtb_ordr.gestione and " +
|
||||
" dtb_ordt.num_ord = dtb_ordr.num_ord and" +
|
||||
" dtb_ordt.gestione = 'V' and " +
|
||||
" ISNULL(dtb_ordt.serie,'') = case when dbo.getGestSetup('IMPORT_COLLI', 'BIOLEXCH', 'ORDINI_DA_PLURIMA') = 'S' then 'O' else '' end and " +
|
||||
" dtb_ordt.data_ord > DATEADD(year, -1, getDate()) )ordini on colli.OrdNum = ordini.ordNumBiolexch and " +
|
||||
" colli.OrdRow = ordini.riga_ord " +
|
||||
" where flagERPRead = 0 " +
|
||||
"order by SSCC, riga";
|
||||
|
||||
sql = UtilityDB.addwhereCond(sql, whereCond, true);
|
||||
PreparedStatement ps = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
int rows = UtilityDB.countRow(rs);
|
||||
int i = 0;
|
||||
sql = UtilityDB.addwhereCond(sql, whereCond, true);
|
||||
PreparedStatement ps = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
int rows = UtilityDB.countRow(rs);
|
||||
int i = 0;
|
||||
|
||||
while (rs.next()) {
|
||||
String SSCC = rs.getString(1);
|
||||
int SSCCRow = rs.getInt(2);
|
||||
LocalDate SSCCDate = UtilityLocalDate.localDateFromDate(rs.getDate(3));
|
||||
Integer ordRigaBio = rs.getInt(4);
|
||||
String codMart = rs.getString(5);
|
||||
String partitaMag = rs.getString(6);
|
||||
Date dataScadPartitaMag = rs.getDate(7);
|
||||
String untMis = rs.getString(8);
|
||||
BigDecimal qtaCol = rs.getBigDecimal(9);
|
||||
BigDecimal numCnf = rs.getBigDecimal(10);
|
||||
LocalDateTime SSCCDataOraRiga = rs.getTimestamp(11).toLocalDateTime();
|
||||
String gestione = rs.getString(12);
|
||||
Date dataOrd = rs.getDate(13);
|
||||
Integer numOrd = rs.getInt(14);
|
||||
String codAnag = rs.getString(15);
|
||||
String codVdes = rs.getString(16);
|
||||
String codMdep = rs.getString(17);
|
||||
String codVlis = rs.getString(18);
|
||||
String UDCOrigine = rs.getString(22);
|
||||
i++;
|
||||
while (rs.next()) {
|
||||
String SSCC = rs.getString(1);
|
||||
int SSCCRow = rs.getInt(2);
|
||||
LocalDate SSCCDate = UtilityLocalDate.localDateFromDate(rs.getDate(3));
|
||||
Integer ordRigaBio = rs.getInt(4);
|
||||
String codMart = rs.getString(5);
|
||||
String partitaMag = rs.getString(6);
|
||||
Date dataScadPartitaMag = rs.getDate(7);
|
||||
String untMis = rs.getString(8);
|
||||
BigDecimal qtaCol = rs.getBigDecimal(9);
|
||||
BigDecimal numCnf = rs.getBigDecimal(10);
|
||||
LocalDateTime SSCCDataOraRiga = rs.getTimestamp(11).toLocalDateTime();
|
||||
String gestione = rs.getString(12);
|
||||
Date dataOrd = rs.getDate(13);
|
||||
Integer numOrd = rs.getInt(14);
|
||||
String codAnag = rs.getString(15);
|
||||
String codVdes = rs.getString(16);
|
||||
String codMdep = rs.getString(17);
|
||||
String codVlis = rs.getString(18);
|
||||
String UDCOrigine = rs.getString(22);
|
||||
i++;
|
||||
|
||||
// Acquisizione collo orgine riferimento
|
||||
Boolean existColloRif = false;
|
||||
if (UDCOrigine != null && UDCOrigine.length() == 18) {
|
||||
String gestioneOrigine = SSCC.substring(9, 10);
|
||||
if (gestioneOrigine.compareTo("1") == 0) {
|
||||
gestioneColloRif = "A";
|
||||
} else if (gestioneOrigine.compareTo("2") == 0) {
|
||||
gestioneColloRif = "L";
|
||||
} else {
|
||||
gestioneColloRif = "V";
|
||||
// Acquisizione collo orgine riferimento
|
||||
Boolean existColloRif = false;
|
||||
if (UDCOrigine != null && UDCOrigine.length() == 18) {
|
||||
String gestioneOrigine = SSCC.substring(9, 10);
|
||||
if (gestioneOrigine.compareTo("1") == 0) {
|
||||
gestioneColloRif = "A";
|
||||
} else if (gestioneOrigine.compareTo("2") == 0) {
|
||||
gestioneColloRif = "L";
|
||||
} else {
|
||||
gestioneColloRif = "V";
|
||||
}
|
||||
annoColloRif = new Integer("20" + SSCC.substring(10, 12));
|
||||
numColloRif = new Integer(SSCC.substring(12, 17));
|
||||
|
||||
sql = "SELECT data_collo, ser_collo " +
|
||||
" FROM mtb_colt " +
|
||||
" WHERE gestione = " + UtilityDB.valueToString(gestioneColloRif) + " AND " +
|
||||
" DATEPART(year, data_collo) = " + UtilityDB.valueToString(annoColloRif) + " AND " +
|
||||
" num_collo = " + UtilityDB.valueToString(numColloRif);
|
||||
|
||||
PreparedStatement info = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql);
|
||||
ResultSet res = info.executeQuery();
|
||||
if (res.next()) {
|
||||
existColloRif = true;
|
||||
dataColloRif = UtilityLocalDate.localDateFromDate(res.getDate(1));
|
||||
serColloRif = res.getString(2);
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
}
|
||||
annoColloRif = new Integer("20" + SSCC.substring(10, 12));
|
||||
numColloRif = new Integer(SSCC.substring(12, 17));
|
||||
|
||||
sql = "SELECT data_collo, ser_collo " +
|
||||
" FROM mtb_colt " +
|
||||
" WHERE gestione = " + UtilityDB.valueToString(gestioneColloRif) + " AND " +
|
||||
" DATEPART(year, data_collo) = " + UtilityDB.valueToString(annoColloRif) + " AND " +
|
||||
" num_collo = " + UtilityDB.valueToString(numColloRif);
|
||||
|
||||
// Verifica esistenza articolo/lotto
|
||||
int count = 0;
|
||||
sql = "SELECT count(*) " +
|
||||
" FROM mtb_partita_mag " +
|
||||
" WHERE cod_mart = " + UtilityDB.valueToString(codMart) + " AND " +
|
||||
" partita_mag = " + UtilityDB.valueToString(partitaMag);
|
||||
|
||||
PreparedStatement info = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql);
|
||||
ResultSet res = info.executeQuery();
|
||||
if (res.next()) {
|
||||
existColloRif = true;
|
||||
dataColloRif = UtilityLocalDate.localDateFromDate(res.getDate(1));
|
||||
serColloRif = res.getString(2);
|
||||
count = res.getInt(1);
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
}
|
||||
|
||||
// Verifica esistenza articolo/lotto
|
||||
int count = 0;
|
||||
sql = "SELECT count(*) " +
|
||||
" FROM mtb_partita_mag " +
|
||||
" WHERE cod_mart = " + UtilityDB.valueToString(codMart) + " AND " +
|
||||
" partita_mag = " + UtilityDB.valueToString(partitaMag);
|
||||
|
||||
PreparedStatement info = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql);
|
||||
ResultSet res = info.executeQuery();
|
||||
if (res.next()) {
|
||||
count = res.getInt(1);
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
if (count == 0) {
|
||||
int index = 0;
|
||||
MtbPartitaMag partMag = new MtbPartitaMag();
|
||||
partMag.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
partMag.setCodMart(codMart);
|
||||
partMag.setPartitaMag(partitaMag);
|
||||
partMag.setDataScad(dataScadPartitaMag);
|
||||
if (!entities.isEmpty()) {
|
||||
index = entities.size() - 1;
|
||||
} else {
|
||||
index = entities.size();
|
||||
}
|
||||
entities.add(index, partMag);
|
||||
}
|
||||
|
||||
// Verifica unità di misura: se non è UM Magazzino allora la quantità viene ricalcolata in funzione del'UM di magazzino
|
||||
BigDecimal rapConv = null;
|
||||
String untMisMagaz = null;
|
||||
sql = "SELECT CASE " + UtilityDB.valueToString(untMis) + " WHEN unt_mis THEN 1 WHEN unt_mis2 THEN rap_conv2 " + " WHEN unt_mis3 THEN rap_conv3 " + " ELSE 1 END as rap_conv " +
|
||||
" FROM mtb_aart " +
|
||||
" WHERE cod_mart = " + UtilityDB.valueToString(codMart);
|
||||
|
||||
info = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql);
|
||||
res = info.executeQuery();
|
||||
if (res.next()) {
|
||||
rapConv = res.getBigDecimal(1);
|
||||
if (rapConv.compareTo(BigDecimal.ONE) != 0) {
|
||||
qtaCol = qtaCol.multiply(rapConv).setScale(5, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
// Inserimento testata collo
|
||||
if (SSCCRow == 1) {
|
||||
if (SSCC.length() == 18) {
|
||||
numCollo = new Integer(SSCC.substring(11, 17));
|
||||
serCollo = "V"; /*E' stata creata una pedana mista*/
|
||||
} else if (SSCC.substring(0, 1).compareTo("U") == 0) {
|
||||
numCollo = new Integer(SSCC.substring(3));
|
||||
serCollo = "UL"; /*E' stata sparata l'intera pedana*/
|
||||
} else {
|
||||
numCollo = 0;
|
||||
serCollo = "/";
|
||||
}
|
||||
|
||||
colT = new MtbColt();
|
||||
colT.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
colT.setGestione(gestione);
|
||||
colT.setDataCollo(SSCCDate);
|
||||
colT.setSerCollo(serCollo);
|
||||
colT.setNumCollo(numCollo);
|
||||
colT.setSegno(-1);
|
||||
colT.setDataOrd(UtilityLocalDate.localDateFromDate(dataOrd));
|
||||
colT.setNumOrd(numOrd);
|
||||
colT.setCodAnag(codAnag);
|
||||
colT.setCodVdes(codVdes);
|
||||
colT.setCodMdep(codMdep);
|
||||
colT.setCodVlis(codVlis);
|
||||
colT.setAnnotazioni(SSCC);
|
||||
entities.add(colT);
|
||||
}
|
||||
|
||||
// Inserimento righe collo
|
||||
MtbColr colR = new MtbColr();
|
||||
colR.setOperation(OperationType.INSERT);
|
||||
colR.setRiga(SSCCRow);
|
||||
colR.setCodMart(codMart);
|
||||
colR.setPartitaMag(partitaMag);
|
||||
colR.setDataOrd(UtilityLocalDate.localDateFromDate(dataOrd));
|
||||
colR.setNumOrd(numOrd);
|
||||
colR.setRigaOrd(ordRigaBio);
|
||||
colR.setQtaCol(qtaCol);
|
||||
colR.setNumCnf(numCnf);
|
||||
colR.setDataScadPartita(dataScadPartitaMag);
|
||||
colR.setDatetimeRow(SSCCDataOraRiga);
|
||||
if (existColloRif) {
|
||||
colR.setGestioneRif(gestioneColloRif);
|
||||
colR.setDataColloRif(dataColloRif);
|
||||
colR.setSerColloRif(serColloRif);
|
||||
colR.setNumColloRif(numColloRif);
|
||||
}
|
||||
colT.getMtbColr().add(colR);
|
||||
|
||||
if (i < rows) {
|
||||
rs.next();
|
||||
SSCCNew = rs.getString(1);
|
||||
rs.previous();
|
||||
}
|
||||
|
||||
// Registrazione colli
|
||||
if (i == rows || SSCC.compareTo(SSCCNew) != 0) {
|
||||
try {
|
||||
for (int a = 0; a < entities.size(); a++) {
|
||||
colTCheck = new MtbColt();
|
||||
if (entities.get(a) instanceof MtbColt) {
|
||||
colTCheck = (MtbColt) entities.get(a);
|
||||
}
|
||||
entityProcessor.processEntity(entities.get(a), true, true, multiDBTransactionManager.getPrimaryDatasource().getProfile(), multiDBTransactionManager);
|
||||
if (entities.get(a) instanceof MtbColt) {
|
||||
entitiesReturn.add(entities.get(a));
|
||||
|
||||
// Blocco collo registrato
|
||||
sql = "UPDATE ShippingList SET flagERPRead = 1 " +
|
||||
"WHERE SSCC = " + UtilityDB.valueToString(((MtbColt) entities.get(a)).getAnnotazioni());
|
||||
ps = connBiolexch.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
if (count == 0) {
|
||||
int index = 0;
|
||||
MtbPartitaMag partMag = new MtbPartitaMag();
|
||||
partMag.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
partMag.setCodMart(codMart);
|
||||
partMag.setPartitaMag(partitaMag);
|
||||
partMag.setDataScad(dataScadPartitaMag);
|
||||
if (!entities.isEmpty()) {
|
||||
index = entities.size() - 1;
|
||||
} else {
|
||||
index = entities.size();
|
||||
}
|
||||
multiDBTransactionManager.commitAll();
|
||||
connBiolexch.commit();
|
||||
entities = new ArrayList<>();
|
||||
} catch (Exception e) {
|
||||
if (colTCheck != null) {
|
||||
anomalies.add(AnomalieDTO.warning(colTCheck.getAnnotazioni() + "\r\n" + e.getMessage()));
|
||||
entities.add(index, partMag);
|
||||
}
|
||||
|
||||
// Verifica unità di misura: se non è UM Magazzino allora la quantità viene ricalcolata in funzione del'UM di magazzino
|
||||
BigDecimal rapConv = null;
|
||||
String untMisMagaz = null;
|
||||
sql = "SELECT CASE " + UtilityDB.valueToString(untMis) + " WHEN unt_mis THEN 1 WHEN unt_mis2 THEN rap_conv2 " + " WHEN unt_mis3 THEN rap_conv3 " + " ELSE 1 END as rap_conv " +
|
||||
" FROM mtb_aart " +
|
||||
" WHERE cod_mart = " + UtilityDB.valueToString(codMart);
|
||||
|
||||
info = multiDBTransactionManager.getPrimaryDatasource().getConnection().prepareStatement(sql);
|
||||
res = info.executeQuery();
|
||||
if (res.next()) {
|
||||
rapConv = res.getBigDecimal(1);
|
||||
if (rapConv.compareTo(BigDecimal.ONE) != 0) {
|
||||
qtaCol = qtaCol.multiply(rapConv).setScale(5, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
// Inserimento testata collo
|
||||
if (SSCCRow == 1) {
|
||||
if (SSCC.length() == 18) {
|
||||
numCollo = new Integer(SSCC.substring(11, 17));
|
||||
serCollo = "V"; /*E' stata creata una pedana mista*/
|
||||
} else if (SSCC.substring(0, 1).compareTo("U") == 0) {
|
||||
numCollo = new Integer(SSCC.substring(3));
|
||||
serCollo = "UL"; /*E' stata sparata l'intera pedana*/
|
||||
} else {
|
||||
numCollo = 0;
|
||||
serCollo = "/";
|
||||
}
|
||||
|
||||
colT = new MtbColt();
|
||||
colT.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
colT.setGestione(gestione);
|
||||
colT.setDataCollo(SSCCDate);
|
||||
colT.setSerCollo(serCollo);
|
||||
colT.setNumCollo(numCollo);
|
||||
colT.setSegno(-1);
|
||||
colT.setDataOrd(UtilityLocalDate.localDateFromDate(dataOrd));
|
||||
colT.setNumOrd(numOrd);
|
||||
colT.setCodAnag(codAnag);
|
||||
colT.setCodVdes(codVdes);
|
||||
colT.setCodMdep(codMdep);
|
||||
colT.setCodVlis(codVlis);
|
||||
colT.setAnnotazioni(SSCC);
|
||||
entities.add(colT);
|
||||
}
|
||||
|
||||
// Inserimento righe collo
|
||||
MtbColr colR = new MtbColr();
|
||||
colR.setOperation(OperationType.INSERT);
|
||||
colR.setRiga(SSCCRow);
|
||||
colR.setCodMart(codMart);
|
||||
colR.setPartitaMag(partitaMag);
|
||||
colR.setDataOrd(UtilityLocalDate.localDateFromDate(dataOrd));
|
||||
colR.setNumOrd(numOrd);
|
||||
colR.setRigaOrd(ordRigaBio);
|
||||
colR.setQtaCol(qtaCol);
|
||||
colR.setNumCnf(numCnf);
|
||||
colR.setDataScadPartita(dataScadPartitaMag);
|
||||
colR.setDatetimeRow(SSCCDataOraRiga);
|
||||
if (existColloRif) {
|
||||
colR.setGestioneRif(gestioneColloRif);
|
||||
colR.setDataColloRif(dataColloRif);
|
||||
colR.setSerColloRif(serColloRif);
|
||||
colR.setNumColloRif(numColloRif);
|
||||
}
|
||||
colT.getMtbColr().add(colR);
|
||||
|
||||
if (i < rows) {
|
||||
rs.next();
|
||||
SSCCNew = rs.getString(1);
|
||||
rs.previous();
|
||||
}
|
||||
|
||||
// Registrazione colli
|
||||
if (i == rows || SSCC.compareTo(SSCCNew) != 0) {
|
||||
try {
|
||||
for (int a = 0; a < entities.size(); a++) {
|
||||
colTCheck = new MtbColt();
|
||||
if (entities.get(a) instanceof MtbColt) {
|
||||
colTCheck = (MtbColt) entities.get(a);
|
||||
}
|
||||
entityProcessor.processEntity(entities.get(a), true, true, multiDBTransactionManager.getPrimaryDatasource().getProfile(), multiDBTransactionManager);
|
||||
if (entities.get(a) instanceof MtbColt) {
|
||||
entitiesReturn.add(entities.get(a));
|
||||
|
||||
// Blocco collo registrato
|
||||
sql = "UPDATE ShippingList SET flagERPRead = 1 " +
|
||||
"WHERE SSCC = " + UtilityDB.valueToString(((MtbColt) entities.get(a)).getAnnotazioni());
|
||||
ps = exchangeMultiDb.prepareStatement(sql);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
}
|
||||
multiDBTransactionManager.commitAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
entities = new ArrayList<>();
|
||||
} catch (Exception e) {
|
||||
if (colTCheck != null) {
|
||||
anomalies.add(AnomalieDTO.warning(colTCheck.getAnnotazioni() + "\r\n" + e.getMessage()));
|
||||
}
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
exchangeMultiDb.rollbackAll();
|
||||
entities = new ArrayList<>();
|
||||
}
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
connBiolexch.rollback();
|
||||
entities = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
if (entitiesReturn.isEmpty()) {
|
||||
entitiesReturn.add(new MtbColt());
|
||||
}
|
||||
|
||||
@@ -524,35 +524,6 @@ public class OrdiniAcquistoExportServices {
|
||||
|
||||
}
|
||||
|
||||
public EntityExportResponse exportOrdiniVendita(String type, String format) throws Exception {
|
||||
Connection connection = multiDBTransactionManager.getPrimaryConnection();
|
||||
|
||||
DataSource dsSlim2k = new DataSource();
|
||||
Map<String, String> setup = setupGest.getImportSetupSection(connection, type, format);
|
||||
EntityExportResponse<List<File>> entityExportResponse = new EntityExportResponse<List<File>>();
|
||||
String profileSlim2k = setup.get("PROFILE");
|
||||
|
||||
if (UtilityString.isNullOrEmpty(profileSlim2k)) {
|
||||
throw new Exception("Profile non configurato per la procedura di importazione liste di scarico SLIM2K");
|
||||
}
|
||||
|
||||
try {
|
||||
dsSlim2k.initialize(profileSlim2k);
|
||||
String listaSingoloOrdine = setup.get("LISTA_SINGOLO_ORDINE");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (!dsSlim2k.isClosed()) {
|
||||
dsSlim2k.forceClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return entityExportResponse;
|
||||
}
|
||||
|
||||
public EntityExportResponse exportOrdiniSlim2K(String type, String format) throws Exception {
|
||||
EntityExportResponse<List<File>> entityExportResponse = new EntityExportResponse<List<File>>();
|
||||
|
||||
|
||||
@@ -92,94 +92,91 @@ public class ProductServices {
|
||||
|
||||
public List<MtbAart> exportArtDialogo(String whereCond) throws Exception {
|
||||
//PROCEDURA DI IMPORTAZIONE ARTICOLI FORMAT - CARELLI
|
||||
String query;
|
||||
FileItem fileItem;
|
||||
DataSource dsArticoli = new DataSource();
|
||||
|
||||
HashMap<String, String> setup = setupGest.getSetupSection(multiDBTransactionManager.getPrimaryConnection(), "w_marti_rc", "DIALOGO");
|
||||
|
||||
String profileDbArt = setup.get("PROFILE_DB");
|
||||
|
||||
dsArticoli.initialize(profileDbArt);
|
||||
try(MultiDBTransactionManager mdb = new MultiDBTransactionManager(profileDbArt)) {
|
||||
|
||||
String queryArticoli =
|
||||
"SELECT mtb_aart.cod_mart " +
|
||||
" FROM mtb_aart LEFT OUTER JOIN mtb_lisa ON mtb_aart.cod_mart = mtb_lisa.cod_mart " +
|
||||
"LEFT OUTER JOIN mvw_barcode ON mtb_aart.cod_mart = mvw_barcode.cod_mart " +
|
||||
" WHERE mtb_aart.cod_mart NOT IN (SELECT cod_mart FROM " + multiDBTransactionManager.getPrimaryDatasource().getDbName() + ".dbo.mtb_aart)";
|
||||
queryArticoli = UtilityDB.addwhereCond(queryArticoli, whereCond, true);
|
||||
String queryArticoli =
|
||||
"SELECT mtb_aart.cod_mart " +
|
||||
" FROM mtb_aart LEFT OUTER JOIN mtb_lisa ON mtb_aart.cod_mart = mtb_lisa.cod_mart " +
|
||||
"LEFT OUTER JOIN mvw_barcode ON mtb_aart.cod_mart = mvw_barcode.cod_mart " +
|
||||
" WHERE mtb_aart.cod_mart NOT IN (SELECT cod_mart FROM " + multiDBTransactionManager.getPrimaryDatasource().getDbName() + ".dbo.mtb_aart)";
|
||||
queryArticoli = UtilityDB.addwhereCond(queryArticoli, whereCond, true);
|
||||
|
||||
String sql = setup.get("QUERY");
|
||||
sql = UtilityDB.addwhereCond(sql, "mtb_aart.cod_mart IN (" + queryArticoli + ") ", false);
|
||||
String sql = setup.get("QUERY");
|
||||
sql = UtilityDB.addwhereCond(sql, "mtb_aart.cod_mart IN (" + queryArticoli + ") ", false);
|
||||
|
||||
ResultSetMapper rsArt = new ResultSetMapper();
|
||||
List<MtbAart> articoli = rsArt.mapQuerySetToList(dsArticoli.getConnection(), sql, MtbAart.class, OperationType.SELECT_OBJECT);
|
||||
ResultSetMapper rsArt = new ResultSetMapper();
|
||||
List<MtbAart> articoli = rsArt.mapQuerySetToList(mdb.getPrimaryConnection(), sql, MtbAart.class, OperationType.SELECT_OBJECT);
|
||||
|
||||
if (articoli == null || articoli.isEmpty()) {
|
||||
throw new Exception("Nessun articolo trovato");
|
||||
}
|
||||
|
||||
sql =
|
||||
"SELECT mtb_aart_bar_code.cod_mart, " +
|
||||
" cod_barre, " +
|
||||
" qta_cnf " +
|
||||
" FROM mtb_aart_bar_code " +
|
||||
"WHERE mtb_aart_bar_code.cod_mart IN (" + queryArticoli + ") ";
|
||||
|
||||
ResultSetMapper rsBarcode = new ResultSetMapper();
|
||||
List<MtbAartBarCode> barcode = rsBarcode.mapQuerySetToList(dsArticoli.getConnection(), sql, MtbAartBarCode.class, OperationType.SELECT_OBJECT);
|
||||
|
||||
sql =
|
||||
"SELECT mtb_lisa.cod_mart, " +
|
||||
" cod_alis, " +
|
||||
" cod_art_for, " +
|
||||
" unt_mis_acq, " +
|
||||
" flag_attivo " +
|
||||
" FROM mtb_lisa " +
|
||||
" WHERE mtb_lisa.cod_mart IN (" + queryArticoli + ") ";
|
||||
|
||||
|
||||
List<MtbLisa> listini = rsBarcode.mapQuerySetToList(dsArticoli.getConnection(), sql, MtbLisa.class, OperationType.SELECT_OBJECT);
|
||||
|
||||
sql = "SELECT where_cond_sql FROM stb_subscription WHERE user_name = " + UtilityDB.valueToString(multiDBTransactionManager.getPrimaryDatasource().getDbName());
|
||||
|
||||
String whereCondSync = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(dsArticoli.getConnection(), sql);
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(whereCondSync) && !listini.isEmpty()) {
|
||||
List<MtbLisa> myObjs = new ArrayList<>();
|
||||
myObjs.addAll(listini);
|
||||
|
||||
String selectSql = "SELECT * FROM " + listini.get(0).getClass().getCanonicalName() + " WHERE " + whereCondSync;
|
||||
|
||||
// Create a new Query.
|
||||
Query q = new Query();
|
||||
q.parse(selectSql);
|
||||
|
||||
QueryResults qr = q.execute(myObjs);
|
||||
List<?> res = qr.getResults();
|
||||
|
||||
if (res != null && res.size() >= 0) {
|
||||
listini = (List<MtbLisa>) res;
|
||||
if (articoli == null || articoli.isEmpty()) {
|
||||
throw new Exception("Nessun articolo trovato");
|
||||
}
|
||||
}
|
||||
|
||||
for (MtbAart art : articoli) {
|
||||
art.setOnlyPkMaster(false);
|
||||
sql =
|
||||
"SELECT mtb_aart_bar_code.cod_mart, " +
|
||||
" cod_barre, " +
|
||||
" qta_cnf " +
|
||||
" FROM mtb_aart_bar_code " +
|
||||
"WHERE mtb_aart_bar_code.cod_mart IN (" + queryArticoli + ") ";
|
||||
|
||||
List<MtbAartBarCode> mtbAartBarCode = Stream.of(barcode).filter(x -> x.getCodMart().equalsIgnoreCase(art.getCodMart())).toList();
|
||||
if (mtbAartBarCode != null) {
|
||||
art.setMtbAartBarCode(mtbAartBarCode);
|
||||
}
|
||||
if (!listini.isEmpty()) {
|
||||
List<MtbLisa> mtbLisa = Stream.of(listini).filter(x -> x.getCodMart().equalsIgnoreCase(art.getCodMart())).toList();
|
||||
if (mtbLisa != null) {
|
||||
art.setMtbLisa(mtbLisa);
|
||||
ResultSetMapper rsBarcode = new ResultSetMapper();
|
||||
List<MtbAartBarCode> barcode = rsBarcode.mapQuerySetToList(mdb.getPrimaryConnection(), sql, MtbAartBarCode.class, OperationType.SELECT_OBJECT);
|
||||
|
||||
sql =
|
||||
"SELECT mtb_lisa.cod_mart, " +
|
||||
" cod_alis, " +
|
||||
" cod_art_for, " +
|
||||
" unt_mis_acq, " +
|
||||
" flag_attivo " +
|
||||
" FROM mtb_lisa " +
|
||||
" WHERE mtb_lisa.cod_mart IN (" + queryArticoli + ") ";
|
||||
|
||||
|
||||
List<MtbLisa> listini = rsBarcode.mapQuerySetToList(mdb.getPrimaryConnection(), sql, MtbLisa.class, OperationType.SELECT_OBJECT);
|
||||
|
||||
sql = "SELECT where_cond_sql FROM stb_subscription WHERE user_name = " + UtilityDB.valueToString(multiDBTransactionManager.getPrimaryDatasource().getDbName());
|
||||
|
||||
String whereCondSync = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(mdb.getPrimaryConnection(), sql);
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(whereCondSync) && !listini.isEmpty()) {
|
||||
List<MtbLisa> myObjs = new ArrayList<>();
|
||||
myObjs.addAll(listini);
|
||||
|
||||
String selectSql = "SELECT * FROM " + listini.get(0).getClass().getCanonicalName() + " WHERE " + whereCondSync;
|
||||
|
||||
// Create a new Query.
|
||||
Query q = new Query();
|
||||
q.parse(selectSql);
|
||||
|
||||
QueryResults qr = q.execute(myObjs);
|
||||
List<?> res = qr.getResults();
|
||||
|
||||
if (res != null && res.size() >= 0) {
|
||||
listini = (List<MtbLisa>) res;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for (MtbAart art : articoli) {
|
||||
art.setOnlyPkMaster(false);
|
||||
|
||||
return articoli;
|
||||
List<MtbAartBarCode> mtbAartBarCode = Stream.of(barcode).filter(x -> x.getCodMart().equalsIgnoreCase(art.getCodMart())).toList();
|
||||
if (mtbAartBarCode != null) {
|
||||
art.setMtbAartBarCode(mtbAartBarCode);
|
||||
}
|
||||
if (!listini.isEmpty()) {
|
||||
List<MtbLisa> mtbLisa = Stream.of(listini).filter(x -> x.getCodMart().equalsIgnoreCase(art.getCodMart())).toList();
|
||||
if (mtbLisa != null) {
|
||||
art.setMtbLisa(mtbLisa);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return articoli;
|
||||
}
|
||||
}
|
||||
|
||||
private String exportArtDialogoExclude(String[] elencoCampi, String nomeCampo) {
|
||||
@@ -784,17 +781,17 @@ public class ProductServices {
|
||||
|
||||
public void popolaTabellaRiassegnazione() throws Exception {
|
||||
String profileDB = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "w_mriassegna_costo_dlg", "TABELLA COSTI", "PROFILE_DB");
|
||||
Connection conn = null;
|
||||
if (!UtilityString.isNullOrEmpty(profileDB) && !profileDB.equalsIgnoreCase(multiDBTransactionManager.getPrimaryDatasource().getProfile())) {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(profileDB);
|
||||
conn = ds.getConnection();
|
||||
} else {
|
||||
conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
try(MultiDBTransactionManager mdb = new MultiDBTransactionManager(profileDB)) {
|
||||
Connection conn = null;
|
||||
if (!UtilityString.isNullOrEmpty(profileDB) && !profileDB.equalsIgnoreCase(multiDBTransactionManager.getPrimaryDatasource().getProfile())) {
|
||||
conn = mdb.getPrimaryConnection();
|
||||
} else {
|
||||
conn = multiDBTransactionManager.getPrimaryConnection();
|
||||
}
|
||||
CallableStatement cs = conn.prepareCall("{call popolaTabelleCosti}");
|
||||
cs.execute();
|
||||
cs.close();
|
||||
}
|
||||
CallableStatement cs = conn.prepareCall("{call popolaTabelleCosti}");
|
||||
cs.execute();
|
||||
cs.close();
|
||||
}
|
||||
|
||||
public void aggCostiDaTabella(Date dataIniz, Date dataFine, String whereCond) throws Exception {
|
||||
|
||||
@@ -100,13 +100,9 @@ public class AgribookFieldService {
|
||||
.setDescrizione(dto.getDestinatario())
|
||||
.setNote(dto.getNote())
|
||||
.setQtaAttesa(dto.getQtaAttesa())
|
||||
.setPartitaMagProd(dto.getPartitaMagProd())
|
||||
.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(dto.getPartitaMagProd())) {
|
||||
partitaMag.setPartitaMagProd(dto.getPartitaMagProd());
|
||||
partitaMag.setDataProd(UtilityLocalDate.localDateToDate(dto.getDataInizProd()));
|
||||
}
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(dto.getVarieta())) {
|
||||
MtbPartitaMagCarat carat = this.getVarieta(connection, dto.getCodMart(), dto.getPartitaMag());
|
||||
if (carat == null) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package it.integry.ems.production.controller;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.document.dto.ChiusuraLavorazioneDTO;
|
||||
import it.integry.ems.document.service.DocumentProdService;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.production.dto.*;
|
||||
import it.integry.ems.production.service.MesProductionServiceV2;
|
||||
@@ -41,13 +40,13 @@ public class MesProductionControllerV2 {
|
||||
|
||||
@Autowired
|
||||
private MesProductionServiceV2 mesProductionService;
|
||||
|
||||
@Autowired
|
||||
private ProductionLineService productionLineService;
|
||||
|
||||
@Autowired
|
||||
private ProductionOrderDataHandlerService productionOrderDataHandlerService;
|
||||
@Autowired
|
||||
private DocumentProdService documentProdService;
|
||||
|
||||
@Autowired
|
||||
private RequestDataDTO requestDataDTO;
|
||||
|
||||
@@ -426,14 +425,21 @@ public class MesProductionControllerV2 {
|
||||
@RequestMapping(value = "checkMaterialeInBarcode", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse checkMaterialeBarcodeInOrdine(@RequestParam(CommonConstants.PROFILE_DB) String profileDB,
|
||||
@RequestBody CheckMaterialeBarcodeInOrdineDTO dto) throws Exception {
|
||||
@RequestBody CheckMaterialeBarcodeInOrdineDTO dto) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(mesProductionService.checkMaterialeBarcodeInOrdine(dto));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "versaMaterialeSuOrdine", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ServiceRestResponse versaMaterialeSuOrdine(@RequestParam(CommonConstants.PROFILE_DB) String profileDB,
|
||||
@RequestBody VersamentoMaterialeSuOrdineDTO dto) throws Exception {
|
||||
@RequestBody VersamentoMaterialeSuOrdineDTO dto) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(mesProductionService.versaMaterialeSuOrdine(dto));
|
||||
}
|
||||
|
||||
@PostMapping(value = "duplicaOrdiniGiornoDopo")
|
||||
public @ResponseBody
|
||||
ServiceRestResponse duplicaOrdiniGiornoDopo(@RequestParam String codJfas) throws Exception {
|
||||
mesProductionService.duplicaOrdiniGiornoDopo(codJfas);
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import it.integry.ems.production.service.ProductionService;
|
||||
import it.integry.ems.response.EsitoType;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.rules.businessLogic.dto.LoadColliDTO;
|
||||
import it.integry.ems.service.dto.production.InsertPartitaMagRequestDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
import it.integry.ems_model.entity.DtbOrdt;
|
||||
@@ -156,11 +157,18 @@ public class ProductionController {
|
||||
try {
|
||||
Date dataOrd = UtilityString.isNullOrEmpty(dataOrdS) ? null : UtilityDate.RecognizeDate(dataOrdS);
|
||||
|
||||
return ServiceRestResponse.createPositiveResponse(productionService.getDettaglioCostiProd(codProd, partitaMag, codJcom,dataOrd,numOrd));
|
||||
return ServiceRestResponse.createPositiveResponse(productionService.getDettaglioCostiProd(codProd, partitaMag, codJcom, dataOrd, numOrd));
|
||||
} catch (Exception e) {
|
||||
logger.error(request.getRequestURI(), e);
|
||||
return new ServiceRestResponse(EsitoType.KO, profileDB, e);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value = "insertPartitaMag")
|
||||
public @ResponseBody
|
||||
ServiceRestResponse insertPartitaMag(
|
||||
@RequestParam(required = false, defaultValue = "true") boolean saveEntity,
|
||||
@RequestBody InsertPartitaMagRequestDTO dto) throws Exception {
|
||||
return ServiceRestResponse.createPositiveResponse(productionService.insertPartitaMag(dto, saveEntity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.document.dto.CaricoLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.ChiusuraLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.RientroLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.ScaricoLavorazioneDTO;
|
||||
import it.integry.ems.document.dto.*;
|
||||
import it.integry.ems.document.service.DocumentProdService;
|
||||
import it.integry.ems.exception.MissingDataException;
|
||||
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
|
||||
@@ -26,12 +23,16 @@ import it.integry.ems.retail.wms.generic.service.WMSGenericService;
|
||||
import it.integry.ems.retail.wms.generic.service.WMSGiacenzaULService;
|
||||
import it.integry.ems.retail.wms.lavorazione.service.WMSLavorazioneService;
|
||||
import it.integry.ems.rules.completing.DocumentRules;
|
||||
import it.integry.ems.rules.completing.PartitaMagRules;
|
||||
import it.integry.ems.rules.completing.dto.DatiPartitaMagDTO;
|
||||
import it.integry.ems.service.*;
|
||||
import it.integry.ems.service.dto.GenericComunicationMailTemplateDataDTO;
|
||||
import it.integry.ems.service.dto.production.InsertPartitaMagRequestDTO;
|
||||
import it.integry.ems.service.dto.production.OrdineLavorazioneDTO;
|
||||
import it.integry.ems.service.exception.EmptyReportException;
|
||||
import it.integry.ems.service.production.ProductionOrderDataHandlerService;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.config.EmsRestConstants;
|
||||
@@ -44,6 +45,7 @@ import it.integry.ems_model.utility.BarcodeEan128.Ean128Model;
|
||||
import it.integry.ems_model.utility.BarcodeEan128.UtilityBarcodeEan128;
|
||||
import it.integry.ems_model.utility.*;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -150,6 +152,10 @@ public class MesProductionServiceV2 {
|
||||
|
||||
|
||||
public Object getCurrentMachinesStatus(String codJfas) throws Exception {
|
||||
if (UtilityDebug.isDebugExecution() || UtilityDebug.isIntegryServer()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RegisterSupervisorDTO hmiData = getSupervisorPanelData(codJfas);
|
||||
|
||||
if (hmiData != null) {
|
||||
@@ -420,6 +426,31 @@ public class MesProductionServiceV2 {
|
||||
entityProcessor.processEntity(dtbOrdtProdToUpdate, skipCommit, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
// Aggiorno la data prod sulla partita mag. se esistente e non gia' impostata
|
||||
sql = Query.format(
|
||||
"SELECT mpm.cod_mart, mpm.partita_mag\n" +
|
||||
"FROM dtb_ordt dot\n" +
|
||||
" INNER JOIN mtb_partita_mag mpm ON dot.cod_prod = mpm.cod_mart AND dot.partita_mag = mpm.partita_mag\n" +
|
||||
" AND mpm.data_prod IS NULL\n" +
|
||||
"WHERE dot.num_ord = %s\n" +
|
||||
" AND dot.data_ord = %s\n" +
|
||||
" AND dot.gestione = %s",
|
||||
numOrd,
|
||||
dataOrd,
|
||||
gestioneOrd
|
||||
);
|
||||
|
||||
MtbPartitaMag mtbPartitaMagToUpdate = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbPartitaMag.class);
|
||||
|
||||
if (mtbPartitaMagToUpdate != null
|
||||
&& !UtilityString.isNullOrEmpty(mtbPartitaMagToUpdate.getCodMart())
|
||||
&& !UtilityString.isNullOrEmpty(mtbPartitaMagToUpdate.getPartitaMag())) {
|
||||
mtbPartitaMagToUpdate.setOperation(OperationType.UPDATE);
|
||||
|
||||
mtbPartitaMagToUpdate.setDataProd(new Date());
|
||||
|
||||
entityProcessor.processEntity(mtbPartitaMagToUpdate, skipCommit, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
String syncOpenOrder = String.format("EXEC [MES_SyncAperturaOrdineLavorazione] %d, %s, %s;",
|
||||
numOrd,
|
||||
@@ -1289,7 +1320,11 @@ public class MesProductionServiceV2 {
|
||||
CheckMaterialeBarcodeInOrdineResponseDTO response = new CheckMaterialeBarcodeInOrdineResponseDTO();
|
||||
|
||||
MtbColt collo;
|
||||
collo = pvmService.getColloByBarcode(dto.getBarcode(), true);
|
||||
try{
|
||||
collo = pvmService.getColloByBarcode(dto.getBarcode(), true);
|
||||
}catch (Exception e){
|
||||
collo = null;
|
||||
}
|
||||
|
||||
if (collo == null) {
|
||||
boolean canCreateUlFromEan128 = setupGest.getSetupBoolean(multiDBTransactionManager.getPrimaryConnection(), "PVM", "MONITORAGGIO_LINEE_V2", "CAN_CREATE_UL_FROM_EAN");
|
||||
@@ -1318,6 +1353,19 @@ public class MesProductionServiceV2 {
|
||||
|
||||
|
||||
DtbOrdt ordineLav = completeDatiOrdine(dto.getOrdine());
|
||||
|
||||
MtbPartitaMag partitaMagOrdine = null;
|
||||
|
||||
if (!UtilityString.isNullOrEmpty(ordineLav.getPartitaMag())) {
|
||||
partitaMagOrdine = new MtbPartitaMag();
|
||||
|
||||
partitaMagOrdine.setCodMart(ordineLav.getCodProd())
|
||||
.setPartitaMag(ordineLav.getPartitaMag())
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
entityProcessor.processEntity(partitaMagOrdine, true, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
String codMgrpSL = setupGest.getSetup("w_lpianoprod_rc", "SETUP", "GRUPPO_SL");
|
||||
boolean matchLottoSlToOrdine = setupGest.getSetupDetBoolean("MES", "SETUP", "VINCOLA_LOTTO_ORDINE_A_SL", dto.getCodJfas());
|
||||
|
||||
@@ -1325,12 +1373,13 @@ public class MesProductionServiceV2 {
|
||||
.map(MtbColr::getCodMart)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
|
||||
if (codMarts.size() > 1)
|
||||
throw new Exception("Impossibile versare a produzione una pedana mista!");
|
||||
|
||||
MtbAart rowArt = WMSUtility.getArticoloByCodMart(codMarts.get(0), multiDBTransactionManager.getPrimaryConnection());
|
||||
|
||||
GiacenzaArtInBarcodeDTO invDto = new GiacenzaArtInBarcodeDTO();
|
||||
|
||||
invDto
|
||||
.setBarcodeUl(collo.getBarcodeUl())
|
||||
.setCodMart(rowArt.getCodMart())
|
||||
@@ -1355,11 +1404,33 @@ public class MesProductionServiceV2 {
|
||||
// continue;
|
||||
}
|
||||
|
||||
if (rowArt.getCodMgrp().equalsIgnoreCase(codMgrpSL) &&
|
||||
matchLottoSlToOrdine &&
|
||||
!UtilityString.isNullOrEmpty(ordineLav.getPartitaMag()) &&
|
||||
!ordineLav.getPartitaMag().startsWith(row.getPartitaMag())) {
|
||||
response.getAnomalie().add(AnomalieDTO.warning(String.format("La partita di semilavorato che si vuole versare (%s) non corrisponde a quella dell'ordine (%s), per concludere la procedura di versamento verrà creato un nuovo ordine di lavorazione con la partita selezionata!", row.getPartitaMag(), ordineLav.getPartitaMag())));
|
||||
MtbPartitaMag partitaMagRow = new MtbPartitaMag();
|
||||
|
||||
partitaMagRow
|
||||
.setCodMart(row.getCodMart())
|
||||
.setPartitaMag(row.getPartitaMag())
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
entityProcessor.processEntity(partitaMagRow, true, multiDBTransactionManager);
|
||||
|
||||
if (rowArt.getCodMgrp().equalsIgnoreCase(codMgrpSL)
|
||||
&& matchLottoSlToOrdine
|
||||
&& !UtilityString.isNullOrEmpty(ordineLav.getPartitaMag())
|
||||
&& (!partitaMagRow.getPartitaMagProd().equalsIgnoreCase(partitaMagOrdine.getPartitaMagProd())
|
||||
|| !DateUtils.isSameDay(partitaMagRow.getDataScad(), partitaMagOrdine.getDataScad()))) {
|
||||
if (!partitaMagRow.getPartitaMagProd().equalsIgnoreCase(partitaMagOrdine.getPartitaMagProd())) {
|
||||
response.getAnomalie().add(AnomalieDTO.warning(String.format(
|
||||
"Lotto di produzione (%s) diverso da quello in lavorazione (%s).\nVuoi creare un nuovo ordine?",
|
||||
partitaMagRow.getPartitaMag(),
|
||||
partitaMagOrdine.getPartitaMagProd())));
|
||||
} else {
|
||||
response.getAnomalie().add(AnomalieDTO.warning(String.format(
|
||||
"La data di scadenza del lotto versato (%s) è diversa da quella del lotto di lavorazione (%s).\nVuoi creare un nuovo ordine?",
|
||||
UtilityDate.formatDate(partitaMagRow.getDataScad(), CommonConstants.DATE_FORMAT_DMY),
|
||||
UtilityDate.formatDate(partitaMagOrdine.getDataScad(), CommonConstants.DATE_FORMAT_DMY)
|
||||
)));
|
||||
}
|
||||
|
||||
response.setNewOrderRequired(true);
|
||||
}
|
||||
invDto.setPartitaMag(row.getPartitaMag())
|
||||
@@ -1444,123 +1515,171 @@ public class MesProductionServiceV2 {
|
||||
ordine.setOperation(OperationType.SELECT_OBJECT);
|
||||
entityProcessor.processEntity(ordine, multiDBTransactionManager);
|
||||
|
||||
if (dto.isCloneOrdine()) {
|
||||
|
||||
String sql = Query.format("SELECT dtb_ordr.* from dtb_ordr\n" +
|
||||
" inner join dtb_ordt on dtb_ordr.data_ord = dtb_ordt.data_ord_rif and dtb_ordr.gestione = gestione_rif and dtb_ordr.num_ord = num_ord_rif\n" +
|
||||
" where dtb_ordt.gestione = {} and dtb_ordt.data_ord = {} and dtb_ordt.num_ord = {} and dtb_ordr.cod_mart = {}", ordine.getGestione(), ordine.getDataOrd(), ordine.getNumOrd(), ordine.getCodProd());
|
||||
DtbOrdr oldRow = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbOrdr.class);
|
||||
|
||||
CreaOrdineProdDTO newOrdDTO = new CreaOrdineProdDTO();
|
||||
newOrdDTO.setCodAnag(ordine.getCodAnag())
|
||||
.setDataOrd(LocalDate.now())
|
||||
.setUntOrd(oldRow.getUntOrd())
|
||||
.setCodMart(oldRow.getCodMart())
|
||||
.setCodMdep(ordine.getCodMdep())
|
||||
.setNumCnf(oldRow.getNumCnf())
|
||||
.setQtaOrd(ordine.getQtaProd())
|
||||
.setCodJfas(ordine.getCodJfas())
|
||||
.setColliPedana(oldRow.getColliPedana());
|
||||
ordine = productionService.saveOrdineProd(newOrdDTO);
|
||||
ordine.setOperation(OperationType.SELECT_OBJECT);
|
||||
entityProcessor.processEntity(ordine, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
List<CreateUDSRequestOrderDTO> ordini = new ArrayList<>();
|
||||
MaterialeVersatoSuOrdineDTO versamentoEsistente = getPreviousVersamentoBarcodeSuOrdine(dto.getOrdine(), sourceBarcodeUl);
|
||||
MtbColt uds;
|
||||
if (versamentoEsistente == null) {
|
||||
CreateUDSRequestOrderDTO orderDTO = new CreateUDSRequestOrderDTO()
|
||||
.setNumOrd(ordine.getNumOrd())
|
||||
.setDataOrd(ordine.getDataOrd().toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate())
|
||||
.setGestione(ordine.getGestione());
|
||||
ordini.add(orderDTO);
|
||||
CreateUDSRequestDTO requestDTO = new CreateUDSRequestDTO()
|
||||
.setCodMdep(ordine.getCodMdep())
|
||||
.setCausaleCollo(CreateUDSRequestDTO.Causale.SCARICO)
|
||||
.setSegno(-1)
|
||||
.setOrders(ordini);
|
||||
uds = wmsLavorazioneService.createUDS(requestDTO);
|
||||
|
||||
} else {
|
||||
try {
|
||||
if (dto.isCloneOrdine()) {
|
||||
String sql = Query.format("SELECT dtb_ordr.* from dtb_ordr\n" +
|
||||
" inner join dtb_ordt on dtb_ordr.data_ord = dtb_ordt.data_ord_rif and dtb_ordr.gestione = gestione_rif and dtb_ordr.num_ord = num_ord_rif\n" +
|
||||
" where dtb_ordt.gestione = {} and dtb_ordt.data_ord = {} and dtb_ordt.num_ord = {} and dtb_ordr.cod_mart = {}", ordine.getGestione(), ordine.getDataOrd(), ordine.getNumOrd(), ordine.getCodProd());
|
||||
DtbOrdr oldRow = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbOrdr.class);
|
||||
|
||||
CreaOrdineProdDTO newOrdDTO = new CreaOrdineProdDTO();
|
||||
newOrdDTO.setCodAnag(ordine.getCodAnag())
|
||||
.setDataOrd(LocalDate.now())
|
||||
.setUntOrd(oldRow.getUntOrd())
|
||||
.setCodMart(oldRow.getCodMart())
|
||||
.setCodMdep(ordine.getCodMdep())
|
||||
.setNumCnf(oldRow.getNumCnf())
|
||||
.setQtaOrd(ordine.getQtaProd())
|
||||
.setCodJfas(ordine.getCodJfas())
|
||||
.setColliPedana(oldRow.getColliPedana());
|
||||
|
||||
ordine = productionService.saveOrdineProd(newOrdDTO);
|
||||
|
||||
ordine.setOperation(OperationType.SELECT_OBJECT);
|
||||
entityProcessor.processEntity(ordine, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
List<CreateUDSRequestOrderDTO> ordini = new ArrayList<>();
|
||||
|
||||
MaterialeVersatoSuOrdineDTO versamentoEsistente = getPreviousVersamentoBarcodeSuOrdine(dto.getOrdine(), sourceBarcodeUl);
|
||||
if (versamentoEsistente == null) {
|
||||
CreateUDSRequestOrderDTO orderDTO = new CreateUDSRequestOrderDTO()
|
||||
.setNumOrd(ordine.getNumOrd())
|
||||
.setDataOrd(ordine.getDataOrd().toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate())
|
||||
.setGestione(ordine.getGestione());
|
||||
|
||||
ordini.add(orderDTO);
|
||||
|
||||
CreateUDSRequestDTO requestDTO = new CreateUDSRequestDTO()
|
||||
.setCodMdep(ordine.getCodMdep())
|
||||
.setCausaleCollo(CreateUDSRequestDTO.Causale.SCARICO)
|
||||
.setSegno(-1)
|
||||
.setOrders(ordini);
|
||||
|
||||
uds = wmsLavorazioneService.createUDS(requestDTO);
|
||||
} else {
|
||||
uds = new MtbColt(versamentoEsistente.getGestione(), versamentoEsistente.getDataCollo(), versamentoEsistente.getNumCollo(), versamentoEsistente.getSerCollo())
|
||||
.setBarcodeUl(versamentoEsistente.getBarcodeUlIn());
|
||||
}
|
||||
}
|
||||
|
||||
for (MvwSitArtUdcDetInventarioDTO scarico : contenuto) {
|
||||
String sql = "SELECT riga_ord\n" +
|
||||
"from dtb_ordr\n" +
|
||||
"where data_ord = " + UtilityDB.valueToString(ordine.getDataOrd()) + "\n" +
|
||||
" and num_ord = " + UtilityDB.valueToString(ordine.getNumOrd()) + "\n" +
|
||||
" and gestione = " + UtilityDB.valueToString(ordine.getGestione()) + "\n" +
|
||||
" and cod_mart = " + UtilityDB.valueToString(scarico.getCodMart());
|
||||
Integer rigaOrd = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
for (MvwSitArtUdcDetInventarioDTO scarico : contenuto) {
|
||||
String sql = "SELECT riga_ord\n" +
|
||||
"from dtb_ordr\n" +
|
||||
"where data_ord = " + UtilityDB.valueToString(ordine.getDataOrd()) + "\n" +
|
||||
" and num_ord = " + UtilityDB.valueToString(ordine.getNumOrd()) + "\n" +
|
||||
" and gestione = " + UtilityDB.valueToString(ordine.getGestione()) + "\n" +
|
||||
" and cod_mart = " + UtilityDB.valueToString(scarico.getCodMart());
|
||||
Integer rigaOrd = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
MtbColr sourceMtbColr = new MtbColr();
|
||||
|
||||
MtbColr sourceMtbColr = new MtbColr();
|
||||
sourceMtbColr
|
||||
sourceMtbColr
|
||||
.setBarcodeUlIn(scarico.getBarcodeUl())
|
||||
.setPosizioneIn(scarico.getPosizione())
|
||||
.setCodMdepIn(scarico.getCodMdep())
|
||||
.setNumCollo(scarico.getNumCollo())
|
||||
.setSerCollo(scarico.getSerCollo())
|
||||
.setDataCollo(scarico.getDataCollo())
|
||||
.setGestione(scarico.getGestione())
|
||||
.setCodMart(scarico.getCodMart())
|
||||
.setPartitaMag(scarico.getPartitaMag())
|
||||
.setPesoLordoKg(scarico.getPesoLordoKG())
|
||||
.setPesoNettoKg(scarico.getPesoNettoKG());
|
||||
.setNumCollo(scarico.getNumCollo())
|
||||
.setSerCollo(scarico.getSerCollo())
|
||||
.setDataCollo(scarico.getDataCollo())
|
||||
.setGestione(scarico.getGestione())
|
||||
.setCodMart(scarico.getCodMart())
|
||||
.setPartitaMag(scarico.getPartitaMag())
|
||||
.setPesoLordoKg(scarico.getPesoLordoKG())
|
||||
.setPesoNettoKg(scarico.getPesoNettoKG());
|
||||
|
||||
InsertUDSRowRequestDTO insertRequestDto = new InsertUDSRowRequestDTO()
|
||||
.setCodMart(scarico.getCodMart())
|
||||
.setQtaTot(UtilityBigDecimal.isNull(dto.getQtaVersamento(), scarico.getQtaCol()))
|
||||
.setPartitaMag(scarico.getPartitaMag())
|
||||
.setSourceMtbColr(sourceMtbColr)
|
||||
.setTargetMtbColt(uds)
|
||||
.setQtaCnf(scarico.getQtaCnf())
|
||||
.setDataOrd(ordine.getDataOrd())
|
||||
.setRigaOrd(rigaOrd)
|
||||
.setNumOrd(ordine.getNumOrd());
|
||||
wmsLavorazioneService.insertUDSRow(insertRequestDto);
|
||||
InsertUDSRowRequestDTO insertRequestDto = new InsertUDSRowRequestDTO()
|
||||
.setCodMart(scarico.getCodMart())
|
||||
.setQtaTot(UtilityBigDecimal.isNull(dto.getQtaVersamento(), scarico.getQtaCol()))
|
||||
.setPartitaMag(scarico.getPartitaMag())
|
||||
.setSourceMtbColr(sourceMtbColr)
|
||||
.setTargetMtbColt(uds)
|
||||
.setQtaCnf(scarico.getQtaCnf())
|
||||
.setDataOrd(ordine.getDataOrd())
|
||||
.setRigaOrd(rigaOrd)
|
||||
.setNumOrd(ordine.getNumOrd());
|
||||
wmsLavorazioneService.insertUDSRow(insertRequestDto);
|
||||
|
||||
String codMgrpSL = setupGest.getSetup("w_lpianoprod_rc", "SETUP", "GRUPPO_SL");
|
||||
boolean matchLottoSlToOrdine = setupGest.getSetupDetBoolean("MES", "SETUP", "VINCOLA_LOTTO_ORDINE_A_SL", dto.getCodJfas());
|
||||
String codMgrpSL = setupGest.getSetup("w_lpianoprod_rc", "SETUP", "GRUPPO_SL");
|
||||
boolean matchLottoSlToOrdine = setupGest.getSetupDetBoolean("MES", "SETUP", "VINCOLA_LOTTO_ORDINE_A_SL", dto.getCodJfas());
|
||||
|
||||
if (UtilityString.isNullOrEmpty(ordine.getPartitaMag()) && scarico.getCodGruppo().equalsIgnoreCase(codMgrpSL) && matchLottoSlToOrdine) {
|
||||
MtbPartitaMag partitaSL = new MtbPartitaMag();
|
||||
|
||||
partitaSL.setCodMart(scarico.getCodMart())
|
||||
.setPartitaMag(scarico.getPartitaMag())
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
entityProcessor.processEntity(partitaSL, multiDBTransactionManager);
|
||||
|
||||
entityProcessor.processEntity(partitaSL, true, multiDBTransactionManager);
|
||||
|
||||
String partitaMagPf = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), Query.format("with datiPartita as (\n" +
|
||||
" select MAX(ASCII(right(partita_mag,LEN(partita_mag) - LEN({})))) + 1 as nextProgressivo\n" +
|
||||
" from mtb_partita_mag where cod_mart = {} and partita_mag like {}\n" +
|
||||
")\n" +
|
||||
"select concat({},ISNULL(CHAR(nextProgressivo),'A'))\n" +
|
||||
"from datiPartita", partitaSL.getPartitaMag(), ordine.getCodProd(), partitaSL.getPartitaMag() + "%", partitaSL.getPartitaMag()));
|
||||
partitaMagPf = UtilityString.isNull(partitaMagPf, partitaSL.getPartitaMag());
|
||||
MtbPartitaMag partitaPf = new MtbPartitaMag();
|
||||
partitaPf.setCodMart(ordine.getCodProd())
|
||||
.setPartitaMag(partitaMagPf)
|
||||
.setDataScad(partitaSL.getDataScad())
|
||||
.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
entityProcessor.processEntity(partitaPf, true, multiDBTransactionManager);
|
||||
ordine.setPartitaMag(partitaMagPf)
|
||||
.setOperation(OperationType.UPDATE);
|
||||
MtbPartitaMag partitaOrdine = null;
|
||||
|
||||
entityProcessor.processEntity(ordine, true, multiDBTransactionManager);
|
||||
// Controllo se esiste partita con stesso lotto e scadenza
|
||||
if (!UtilityString.isNullOrEmpty(ordine.getPartitaMag())) {
|
||||
partitaOrdine = new MtbPartitaMag();
|
||||
|
||||
partitaOrdine
|
||||
.setCodMart(ordine.getCodProd())
|
||||
.setPartitaMag(ordine.getPartitaMag())
|
||||
.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
entityProcessor.processEntity(partitaOrdine, true, multiDBTransactionManager);
|
||||
}
|
||||
|
||||
// Assegna una nuova partita se l'ordine non ha nessuna partita o se il semilavorato ha diversa partitaMagProd o data scadenza
|
||||
if (matchLottoSlToOrdine
|
||||
&& scarico.getCodGruppo().equalsIgnoreCase(codMgrpSL)
|
||||
&& (UtilityString.isNullOrEmpty(ordine.getPartitaMag())
|
||||
|| !partitaOrdine.getPartitaMagProd().equalsIgnoreCase(partitaSL.getPartitaMagProd())
|
||||
|| !DateUtils.isSameDay(partitaOrdine.getDataScad(), partitaSL.getDataScad()))) {
|
||||
sql = Query.format(
|
||||
"WITH datiPartita\n" +
|
||||
" AS (SELECT MAX(ASCII(RIGHT(partita_mag, LEN(partita_mag) - LEN(%s)))) + 1 AS nextProgressivo\n" +
|
||||
" FROM mtb_partita_mag\n" +
|
||||
" WHERE cod_mart = %s\n" +
|
||||
" AND partita_mag_prod = %s)\n" +
|
||||
"SELECT CONCAT(%s, ISNULL(CHAR(nextProgressivo), 'A'))\n" +
|
||||
"FROM datiPartita",
|
||||
partitaSL.getPartitaMagProd(),
|
||||
ordine.getCodProd(),
|
||||
partitaSL.getPartitaMagProd(),
|
||||
partitaSL.getPartitaMagProd()
|
||||
);
|
||||
|
||||
String partitaMagPf = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
partitaMagPf = UtilityString.isNull(partitaMagPf, partitaSL.getPartitaMagProd());
|
||||
|
||||
MtbPartitaMag partitaPf = new MtbPartitaMag();
|
||||
|
||||
partitaPf
|
||||
.setCodMart(ordine.getCodProd())
|
||||
.setPartitaMag(partitaMagPf)
|
||||
.setPartitaMagProd(partitaSL.getPartitaMagProd())
|
||||
.setDataProd(partitaSL.getDataProd())
|
||||
.setDataScad(partitaSL.getDataScad())
|
||||
.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
entityProcessor.processEntity(partitaPf, true, multiDBTransactionManager);
|
||||
|
||||
ordine.setPartitaMag(partitaMagPf)
|
||||
.setOperation(OperationType.UPDATE);
|
||||
|
||||
entityProcessor.processEntity(ordine, true, multiDBTransactionManager);
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.isStartOrdine() || dto.isCloneOrdine()) {
|
||||
openStep(ordine.getDataOrd(), ordine.getNumOrd(), ordine.getGestione(), dto.getCodJfas(), 0, null, null, null, true);
|
||||
}
|
||||
|
||||
multiDBTransactionManager.commitAll();
|
||||
} catch (Exception e) {
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
if (dto.isStartOrdine() || dto.isCloneOrdine()) {
|
||||
openStep(ordine.getDataOrd(), ordine.getNumOrd(), ordine.getGestione(), dto.getCodJfas(), 0);
|
||||
}
|
||||
return uds;
|
||||
}
|
||||
|
||||
@@ -1977,4 +2096,168 @@ public class MesProductionServiceV2 {
|
||||
|
||||
return UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, AttachmentDTO.class);
|
||||
}
|
||||
|
||||
public void duplicaOrdiniGiornoDopo(String codJfas) throws Exception {
|
||||
String sql = Query.format(
|
||||
"WITH setup AS (SELECT *\n" +
|
||||
" FROM stb_gest_setup_det\n" +
|
||||
" WHERE gest_name = 'MES'\n" +
|
||||
" AND section = 'SETUP'\n" +
|
||||
" AND key_section = 'COD_MGRP_SCADENZA_MULTIPLA'\n" +
|
||||
" AND value = 'S')\n" +
|
||||
"SELECT ordini.*\n" +
|
||||
"FROM MES_GetWorkOrders(%s, DATEADD(DAY, -30, GETDATE()), NULL, NULL, NULL) ordini\n" +
|
||||
" INNER JOIN mtb_aart ma ON ordini.cod_prod = ma.cod_mart\n" +
|
||||
" INNER JOIN mtb_grup mg ON ma.cod_mgrp = mg.cod_mgrp\n" +
|
||||
" INNER JOIN setup ON val_col_rif = mg.cod_mgrp\n" +
|
||||
"WHERE ordini.stato = 'IN CORSO'\n" +
|
||||
"ORDER BY ordini.sort",
|
||||
codJfas
|
||||
);
|
||||
|
||||
List<OrdineLavorazioneDTO> ordini = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, OrdineLavorazioneDTO.class);
|
||||
|
||||
if (ordini == null || ordini.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
List<DtbOrdt> ordiniSalvati = new ArrayList<>();
|
||||
|
||||
for (OrdineLavorazioneDTO ordine : ordini) {
|
||||
Date dataOrd = UtilityDate.dateAdd(UtilityDate.getTodayWithoutTime(), 1);
|
||||
|
||||
// ORDINE DI PRODUZIONE
|
||||
DtbOrdt ordProd = new DtbOrdt()
|
||||
.setCodAnag(ordine.getCodAnag())
|
||||
.setDataOrd(dataOrd)
|
||||
.setCodJfas(ordine.getCodJfas())
|
||||
.setGestione("A")
|
||||
.setGestioneRif("A")
|
||||
.setCodMdep(ordine.getCodMdep());
|
||||
|
||||
ordProd.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
sql = Query.format(
|
||||
"SELECT *\n" +
|
||||
"FROM dtb_ordr\n" +
|
||||
"WHERE gestione = %s\n" +
|
||||
" AND data_ord = %s\n" +
|
||||
" AND num_ord = %s\n",
|
||||
ordine.getGestione(),
|
||||
ordine.getDataOrd(),
|
||||
ordine.getNumOrd()
|
||||
);
|
||||
|
||||
List<DtbOrdr> righeOrdineLav = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbOrdr.class);
|
||||
|
||||
if (righeOrdineLav == null || righeOrdineLav.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DtbOrdr ordLav = new DtbOrdr()
|
||||
.setCodMart(ordine.getCodProd())
|
||||
.setCodJfas(ordine.getCodJfas())
|
||||
.setQtaOrd(ordine.getQtaProd())
|
||||
.setRapConv(ordine.getRapConv())
|
||||
.setUntOrd(ordine.getUntOrd())
|
||||
.setDataCons(dataOrd)
|
||||
.setColliPedana(ordine.getColliPedana())
|
||||
.setDataInizProd(UtilityLocalDate.localDateFromDate(dataOrd))
|
||||
.setCodTcolUl(ordine.getCodTcolUl())
|
||||
.setNote(ordine.getNoteLav())
|
||||
.setDistinta(new ArrayList<>());
|
||||
|
||||
ordLav.setOperation(OperationType.INSERT);
|
||||
|
||||
ordProd.addDtbOrdr(ordLav);
|
||||
|
||||
String partitaMag = PartitaMagRules.suggestCodePartitaMag(multiDBTransactionManager.getPrimaryConnection(),
|
||||
new DatiPartitaMagDTO()
|
||||
.setCodMart(ordLav.getCodMart())
|
||||
.setDataOrd(dataOrd)
|
||||
.setGestione("L")
|
||||
.setCodJfas(ordLav.getCodJfas()));
|
||||
|
||||
List<EntityBase> listPartitaMag = productionService.insertPartitaMag(new InsertPartitaMagRequestDTO()
|
||||
.setCodMart(ordine.getCodProd())
|
||||
.setPartitaMag(partitaMag)
|
||||
.setDataScad(ordine.getDataScad())
|
||||
.setNote(ordine.getNoteLav()), false);
|
||||
|
||||
if (!listPartitaMag.isEmpty()) {
|
||||
MtbPartitaMag mtbPartitaMag = (MtbPartitaMag) listPartitaMag.get(0);
|
||||
|
||||
mtbPartitaMag.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
entityProcessor.processEntity(mtbPartitaMag, true, multiDBTransactionManager);
|
||||
|
||||
ordLav.setPartitaMag(mtbPartitaMag.getPartitaMag());
|
||||
}
|
||||
|
||||
for (DtbOrdr rigaOrdine : righeOrdineLav) {
|
||||
JtbDistMate jtbDistMate = new JtbDistMate()
|
||||
.setCodProd(ordLav.getCodMart())
|
||||
.setCodMart(rigaOrdine.getCodMart())
|
||||
.setQtaStd(rigaOrdine.getQtaOrd())
|
||||
.setNumFase(rigaOrdine.getNumFase());
|
||||
|
||||
jtbDistMate.setOperation(OperationType.INSERT);
|
||||
|
||||
ordLav
|
||||
.getDistinta()
|
||||
.add(jtbDistMate);
|
||||
}
|
||||
|
||||
entityProcessor.processEntity(ordProd, true, multiDBTransactionManager);
|
||||
|
||||
this.closeStep(ordine.getDataOrd(), ordine.getNumOrd(), ordine.getGestione(), ordine.getCodJfas(), null, null);
|
||||
|
||||
// CaricoProdFinLavDTO caricoProdFinLavDTO = new CaricoProdFinLavDTO();
|
||||
//
|
||||
// caricoProdFinLavDTO.setGestione("L");
|
||||
// caricoProdFinLavDTO.setDataOrd(ordine.getDataOrd());
|
||||
// caricoProdFinLavDTO.setNumOrd(ordine.getNumOrd());
|
||||
// caricoProdFinLavDTO.setCodJfas(ordine.getCodJfas());
|
||||
// caricoProdFinLavDTO.setFermaCreaDocs(true);
|
||||
//
|
||||
// documentProdService.caricoProdFinLav(caricoProdFinLavDTO);
|
||||
|
||||
ordiniSalvati.addAll(ordLav.getOrdLav());
|
||||
}
|
||||
|
||||
multiDBTransactionManager.commitAll();
|
||||
|
||||
if (!ordiniSalvati.isEmpty()) {
|
||||
sql = String.format(
|
||||
"SELECT gestione,\n" +
|
||||
"do.data_ord,\n" +
|
||||
"do.num_ord,\n" +
|
||||
"do.cod_jfas,\n" +
|
||||
"(SELECT MAX(dos.hr_num)\n" +
|
||||
" FROM dtb_ord_steps dos\n" +
|
||||
" WHERE do.gestione = dos.gestione\n" +
|
||||
" AND do.data_ord = dos.data_ord\n" +
|
||||
" AND do.num_ord = dos.num_ord) AS hr_num\n" +
|
||||
"FROM dtb_ordt do\n" +
|
||||
"WHERE do.gestione = 'L'\n" +
|
||||
" AND do.data_ord IN (%s)\n" +
|
||||
" AND do.num_ord IN (%s)\n",
|
||||
UtilityDB.listValueToString(ordiniSalvati.stream().map(DtbOrdt::getDataOrd).distinct().collect(java.util.stream.Collectors.toList())),
|
||||
UtilityDB.listValueToString(ordiniSalvati.stream().map(DtbOrdt::getNumOrd).distinct().collect(java.util.stream.Collectors.toList()))
|
||||
);
|
||||
|
||||
List<DtbOrdSteps> dtbOrdStepsToOpen = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, DtbOrdSteps.class);
|
||||
|
||||
if (dtbOrdStepsToOpen != null && !dtbOrdStepsToOpen.isEmpty()) {
|
||||
for (DtbOrdSteps dtbOrdSteps : dtbOrdStepsToOpen) {
|
||||
this.openStep(dtbOrdSteps.getDataOrd(), dtbOrdSteps.getNumOrd(), dtbOrdSteps.getGestione(), dtbOrdSteps.getCodJfas(), dtbOrdSteps.getHrNum());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
multiDBTransactionManager.rollbackAll();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,11 +660,11 @@ public class MrpDailyMaterialReqService {
|
||||
" CONVERT(VARCHAR(10), dtb_ordt.data_ord, 105)\n" +
|
||||
" + CASE WHEN dtb_ordt.flag_sospeso = 'S' THEN ' - Sospeso' ELSE '' END AS causale,\n" +
|
||||
" dtb_ordr.cod_mart,\n" +
|
||||
" CASE\n" +
|
||||
" dbo.relativeWorkDateConsLav(CASE\n" +
|
||||
" WHEN dtb_ordr.data_cons IS NULL OR dtb_ordr.data_cons < CAST(GETDATE() AS DATE) OR\n" +
|
||||
" dtb_ordt.flag_sospeso = 'S'\n" +
|
||||
" THEN CAST(GETDATE() AS DATE)\n" +
|
||||
" ELSE dtb_ordr.data_cons END AS data_mrp,\n" +
|
||||
" ELSE dtb_ordr.data_cons END , -IsNull(jtb_cicl.gg_tot, 0)) AS data_mrp,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN dtb_ordr.qta_cnf <> 0\n" +
|
||||
" THEN ([columnQtaOrd]) / (dtb_ordr.qta_cnf * dtb_ordr.rap_conv) \n" +
|
||||
@@ -723,6 +723,7 @@ public class MrpDailyMaterialReqService {
|
||||
" dtb_ord_steps.num_ord) step ON ordl.gestione = step.gestione\n" +
|
||||
" AND ordl.data_ord = step.data_ord\n" +
|
||||
" AND ordl.num_ord = step.num_ord\n" +
|
||||
" LEFT OUTER JOIN jtb_cicl ON dtb_ordr.cod_mart = jtb_cicl.cod_prod\n" +
|
||||
"WHERE dtb_ordt.gestione = 'V'\n" +
|
||||
" AND dtb_ordr.qta_ord > dtb_ordr.qta_evasa\n" +
|
||||
" AND dtb_ordt.flag_annulla = 'N'\n" +
|
||||
@@ -739,68 +740,7 @@ public class MrpDailyMaterialReqService {
|
||||
|
||||
private List<MrpDailyMaterialReqDetDTO> getOrdini(String gestione, String depositi, String articoli, Date dataMrp, String tableColli, boolean includiArrivi) throws Exception {
|
||||
String sqlOrdini;
|
||||
if (gestione.equalsIgnoreCase("V")) {
|
||||
sqlOrdini =
|
||||
"SELECT dtb_ordt.gestione,\n" +
|
||||
" dtb_ordt.data_ord,\n" +
|
||||
" dtb_ordt.cod_mdep,\n" +
|
||||
" dtb_ordt.num_ord,\n" +
|
||||
" dtb_ordt.cod_jcom,\n" +
|
||||
" dtb_ordt.flag_sospeso,\n" +
|
||||
" dtb_ordr.cod_mart,\n" +
|
||||
" dtb_ordt.gestione_rif,\n" +
|
||||
" dtb_ordr.partita_mag,\n" +
|
||||
" dtb_ordr.data_cons,\n" +
|
||||
" dtb_ordt.flag_evaso_prod,\n" +
|
||||
" dtb_ordr.unt_ord,\n" +
|
||||
" dtb_ordr.qta_cnf * dtb_ordr.rap_conv as qta_cnf,\n" +
|
||||
" dtb_ordr.colli_pedana,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN ((dtb_ordr.qta_ord - dtb_ordr.qta_Evasa) * dtb_ordr.rap_conv) < ISNULL(colli.qta_col, 0) THEN 0\n" +
|
||||
" ELSE ((dtb_ordr.qta_ord - dtb_ordr.qta_Evasa) * dtb_ordr.rap_conv) - ISNULL(colli.qta_col, 0) END AS qta_ord,\n" +
|
||||
" 'N' AS isOrdTrasf,\n" +
|
||||
" dtb_ordt.cod_anag,\n" +
|
||||
" CASE\n" +
|
||||
" WHEN dtb_ordr.partita_mag IS NOT NULL THEN\n" +
|
||||
" CASE\n" +
|
||||
" WHEN step.id_step_max > 0 AND dtb_ordt.flag_evaso_prod = 'I'\n" +
|
||||
" THEN 'L' -- In lavorazione\n" +
|
||||
" WHEN step.id_step_max = 0\n" +
|
||||
" THEN 'P' -- Pianificato in produzione\n" +
|
||||
" WHEN mtb_partita_mag.flag_stato = 'A'\n" +
|
||||
" THEN 'R'\n" +
|
||||
" ELSE NULL END\n" +
|
||||
" END AS stato_partita\n" +
|
||||
"FROM dtb_ordt\n" +
|
||||
" INNER JOIN dtb_ordr ON dtb_ordt.gestione = dtb_ordr.gestione AND\n" +
|
||||
" dtb_ordt.data_ord = dtb_ordr.data_ord AND\n" +
|
||||
" dtb_ordt.num_ord = dtb_ordr.num_ord\n" +
|
||||
" LEFT OUTER JOIN mtb_partita_mag ON dtb_ordr.cod_mart = mtb_partita_mag.cod_mart AND\n" +
|
||||
" dtb_ordr.partita_mag = mtb_partita_mag.partita_mag\n" +
|
||||
" LEFT OUTER JOIN dtb_ordt ordl\n" +
|
||||
" ON dtb_ordr.cod_mart = ordl.cod_prod AND dtb_ordr.partita_mag = ordl.partita_mag\n" +
|
||||
" AND (ordl.cod_jcom IS NULL OR ISNULL(dtb_ordt.cod_jcom, '') = ISNULL(ordl.cod_jcom, ''))\n" +
|
||||
" LEFT OUTER JOIN " + tableColli + " colli\n" +
|
||||
" ON dtb_ordt.gestione = colli.gestione AND dtb_ordr.data_ord = colli.data_ord AND\n" +
|
||||
" dtb_ordr.num_ord = colli.num_ord AND\n" +
|
||||
" dtb_ordr.riga_ord = colli.riga_ord\n" +
|
||||
" LEFT OUTER JOIN (SELECT dtb_ord_steps.gestione,\n" +
|
||||
" dtb_ord_steps.data_ord,\n" +
|
||||
" dtb_ord_steps.num_ord,\n" +
|
||||
" MAX(dtb_ord_steps.id_step) AS id_step_max\n" +
|
||||
" FROM dtb_ord_steps\n" +
|
||||
" GROUP BY dtb_ord_steps.gestione,\n" +
|
||||
" dtb_ord_steps.data_ord,\n" +
|
||||
" dtb_ord_steps.num_ord) step ON ordl.gestione = step.gestione\n" +
|
||||
" AND ordl.data_ord = step.data_ord\n" +
|
||||
" AND ordl.num_ord = step.num_ord\n" +
|
||||
"WHERE dtb_ordt.gestione = 'V'\n" +
|
||||
" AND dtb_ordr.qta_ord > dtb_ordr.qta_evasa\n" +
|
||||
" AND dtb_ordt.flag_annulla = 'N'\n" +
|
||||
" AND dtb_ordr.cod_mart IS NOT NULL\n" +
|
||||
" AND flag_Evaso = 'I'\n" +
|
||||
" AND dtb_ordt.flag_budget = 0";
|
||||
} else if (gestione.equalsIgnoreCase("A")) {
|
||||
if (gestione.equalsIgnoreCase("A")) {
|
||||
sqlOrdini =
|
||||
"SELECT dtb_ordt.gestione,\n" +
|
||||
" dtb_ordt.data_ord,\n" +
|
||||
|
||||
@@ -85,6 +85,13 @@ public class OrtoFruttaProductionService {
|
||||
"SETUP",
|
||||
"FASE_RACC");
|
||||
|
||||
String codDtipLavCar = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CRUSCOTTO_PRODUZIONE",
|
||||
"SETUP",
|
||||
"COD_DTIP_CAR");
|
||||
String serDocLavCar = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CRUSCOTTO_PRODUZIONE",
|
||||
"SETUP",
|
||||
"SER_DOC_CAR");
|
||||
|
||||
if (UtilityString.isNullOrEmpty(dto.getSerDocProvv()))
|
||||
dto.setSerDocProvv(serDocAcqCar);
|
||||
|
||||
@@ -94,18 +101,38 @@ public class OrtoFruttaProductionService {
|
||||
if (UtilityString.isNullOrEmpty(dto.getCodJfas())) {
|
||||
dto.setCodJfas(codJfas);
|
||||
}
|
||||
//controllo se il DDT richiesto è già occupato da un altro certificato
|
||||
//<editor-fold desc=" controllo se il Certificato richiesto è già occupato nell'anno">
|
||||
|
||||
String sql = "SELECT data_collo,ser_collo,num_collo,gestione\n" +
|
||||
"FROM mtb_colt\n" +
|
||||
"WHERE YEAR(data_doc) = YEAR(" + UtilityDB.valueDateToString(UtilityLocalDate.localDateToDate(dto.getDataDoc()), CommonConstants.DATE_FORMAT_YMD) + ")\n" +
|
||||
" AND num_doc = " + UtilityDB.valueToString(dto.getNumDoc()) + "\n" +
|
||||
" AND cod_anag = " + UtilityDB.valueToString(dto.getCodAnag()) + "\n" +
|
||||
"AND cod_dtip = " + UtilityDB.valueToString(codDtipLavCar) + "\n" +
|
||||
"and ser_doc = " + UtilityDB.valueToString(serDocLavCar) + "\n";
|
||||
MtbColt mtbcolt = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbColt.class);
|
||||
if (mtbcolt != null && (UtilityInteger.isNullOrZero(dto.getNumCollo()) || mtbcolt.equalsKey(new MtbColt(dto.getGestione(),dto.getDataCollo(),dto.getNumCollo(),dto.getSerCollo())))) {
|
||||
throw new Exception(String.format("Il certificato n. %d per l'anno %s è già stato registrato!",dto.getNumDoc(),UtilityLocalDate.formatDate(dto.getDataDoc(),"yyyy")));
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold desc=" controllo se il DDT richiesto è già occupato da un altro certificato">
|
||||
|
||||
sql = "SELECT data_collo,ser_collo,num_collo,gestione\n" +
|
||||
"FROM mtb_colt\n" +
|
||||
"WHERE data_doc_provv = " + UtilityDB.valueDateToString(UtilityLocalDate.localDateToDate(dto.getDataDocProvv()), CommonConstants.DATE_FORMAT_YMD) + "\n" +
|
||||
" AND num_doc_provv = " + UtilityDB.valueToString(dto.getNumDocProvv()) + "\n" +
|
||||
" AND cod_anag = " + UtilityDB.valueToString(dto.getCodAnag()) + "\n" +
|
||||
"AND cod_dtip_provv = " + UtilityDB.valueToString(dto.getCodDtipProvv()) + "\n" +
|
||||
"and ser_doc_provv = " + UtilityDB.valueToString(dto.getSerDocProvv()) + "\n";
|
||||
MtbColt mtbcolt = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbColt.class);
|
||||
mtbcolt = UtilityDB.executeSimpleQueryOnlyFirstRowDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbColt.class);
|
||||
if (mtbcolt != null && (UtilityInteger.isNullOrZero(dto.getNumCollo()) || mtbcolt.getNumCollo().compareTo(dto.getNumCollo()) != 0)) {
|
||||
throw new Exception("Il documento di trasporto inserito è già esistente!");
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
//</editor-fold>
|
||||
|
||||
String barcodeUl = null;
|
||||
@@ -224,12 +251,6 @@ public class OrtoFruttaProductionService {
|
||||
|
||||
//<editor-fold desc="Generazione Certificato">
|
||||
//Genero testata certificato di lavoro
|
||||
String codDtipLavCar = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CRUSCOTTO_PRODUZIONE",
|
||||
"SETUP",
|
||||
"COD_DTIP_CAR");
|
||||
String serDocLavCar = setupGest.getSetup(multiDBTransactionManager.getPrimaryConnection(), "CRUSCOTTO_PRODUZIONE",
|
||||
"SETUP",
|
||||
"SER_DOC_CAR");
|
||||
//se esiste un certificato per il carico in salvataggio con un numero diverso da quello selezionato lo vado a cancellare
|
||||
deleteOldCertificatoIfExists(activityId, codDtipLavCar, dto);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import it.integry.ems.rules.businessLogic.LoadColliService;
|
||||
import it.integry.ems.rules.businessLogic.dto.LoadColliDTO;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.service.dto.production.InsertPartitaMagRequestDTO;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.utility.UtilityEntity;
|
||||
@@ -1044,7 +1045,7 @@ public class ProductionService {
|
||||
}
|
||||
}
|
||||
|
||||
entityProcessor.processEntity(ordLav, multiDBTransactionManager);
|
||||
entityProcessor.processEntity(ordLav, true, multiDBTransactionManager);
|
||||
UtilityEntity.throwEntityException(ordLav);
|
||||
}
|
||||
}
|
||||
@@ -1615,4 +1616,110 @@ public class ProductionService {
|
||||
entityProcessor.processEntityList(docDaAggiornare, true);
|
||||
}
|
||||
}
|
||||
|
||||
public StbGestSetupDet getConfigControlloScadenzaMultipla(String codJfas) throws Exception {
|
||||
List<StbGestSetupDet> setupDetList = setupGest.getSetupDetList("MES", "SETUP", "CONTROLLO_SCADENZA_MULTIPLA");
|
||||
|
||||
if (setupDetList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
java.util.Optional<StbGestSetupDet> stbGestSetupDetOptional = setupDetList.stream()
|
||||
.filter(stbGestSetupDet -> stbGestSetupDet.getValColRif().equalsIgnoreCase(codJfas))
|
||||
.findFirst();
|
||||
|
||||
return stbGestSetupDetOptional.orElse(null);
|
||||
}
|
||||
|
||||
public List<EntityBase> insertPartitaMag(InsertPartitaMagRequestDTO dto, boolean saveEntity) throws Exception {
|
||||
String codMart = dto.getCodMart();
|
||||
String partitaMag = dto.getPartitaMag();
|
||||
String partitaMagProd = UtilityString.isNull(dto.getPartitaMagProd(), partitaMag);
|
||||
Date dataScad = dto.getDataScad();
|
||||
|
||||
StbGestSetupDet configControlloScadenzaMultipla = this.getConfigControlloScadenzaMultipla(dto.getCodJfas());
|
||||
|
||||
if (configControlloScadenzaMultipla != null && configControlloScadenzaMultipla.getValue().equalsIgnoreCase("S")) {
|
||||
// Controllo se esiste partita con stesso lotto e scadenza
|
||||
// sql = Query.format(
|
||||
// "SELECT partita_mag\n" +
|
||||
// "FROM mtb_partita_mag\n" +
|
||||
// "WHERE cod_mart = %s\n" +
|
||||
// "AND partita_mag_prod = %s\n" +
|
||||
// "AND data_scad = %s\n",
|
||||
// codMart,
|
||||
// partitaMag,
|
||||
// dataScad
|
||||
// );
|
||||
//
|
||||
// String partitaMagQuery = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
//
|
||||
// if (partitaMagQuery == null) {
|
||||
// La partita per data scad non esiste, leggere l'ultima e creane una nuova
|
||||
String sql = Query.format(
|
||||
"SELECT MAX(partita_mag)\n" +
|
||||
"FROM mtb_partita_mag\n" +
|
||||
"WHERE cod_mart = %s\n" +
|
||||
"AND partita_mag_prod = %s\n",
|
||||
codMart,
|
||||
partitaMag
|
||||
);
|
||||
|
||||
String lastPartitaMag = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(multiDBTransactionManager.getPrimaryConnection(), sql);
|
||||
|
||||
if (lastPartitaMag != null) {
|
||||
char lastPartitaChar = lastPartitaMag.charAt(lastPartitaMag.length() - 1);
|
||||
|
||||
if (Character.isDigit(lastPartitaChar)) {
|
||||
lastPartitaChar = 'A';
|
||||
} else {
|
||||
lastPartitaChar++;
|
||||
}
|
||||
|
||||
partitaMag += lastPartitaChar;
|
||||
}
|
||||
// } else {
|
||||
// partitaMag = partitaMagQuery;
|
||||
// }
|
||||
}
|
||||
|
||||
MtbPartitaMag mtbPartitaMag = new MtbPartitaMag()
|
||||
.setPartitaMag(partitaMag)
|
||||
.setPartitaMagProd(partitaMagProd)
|
||||
.setCodMart(codMart)
|
||||
.setDataScad(dataScad);
|
||||
|
||||
boolean setDescrizione = setupGest.getSetupBoolean("MTB_PARTITA_MAG", "SETUP", "SET_DESCRIZIONE_FROM_NOTE_ORDINE");
|
||||
|
||||
if (setDescrizione) {
|
||||
mtbPartitaMag.setDescrizione(dto.getNote());
|
||||
}
|
||||
|
||||
if (!saveEntity) {
|
||||
mtbPartitaMag.setOperation(OperationType.SELECT_OBJECT);
|
||||
|
||||
return Collections.singletonList(mtbPartitaMag);
|
||||
}
|
||||
|
||||
mtbPartitaMag.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
|
||||
DtbOrdt dtbOrdt = new DtbOrdt()
|
||||
.setGestione(dto.getGestione())
|
||||
.setDataOrd(dto.getDataOrd())
|
||||
.setNumOrd(dto.getNumOrd())
|
||||
.setCodJfas(dto.getCodJfas())
|
||||
.setPartitaMag(partitaMag);
|
||||
|
||||
dtbOrdt.setOperation(OperationType.UPDATE);
|
||||
|
||||
List<EntityBase> entityBaseList = new ArrayList<>();
|
||||
|
||||
entityBaseList.add(mtbPartitaMag);
|
||||
entityBaseList.add(dtbOrdt);
|
||||
|
||||
entityProcessor.processEntityList(entityBaseList, true);
|
||||
UtilityEntity.throwEntitiesException(entityBaseList);
|
||||
|
||||
return entityBaseList;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package it.integry.ems.retail.wms.dto;
|
||||
|
||||
import it.integry.ems_model.entity.DtbOrdt;
|
||||
import it.integry.ems_model.entity.MtbColt;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -11,6 +12,7 @@ public class RientroMerceRequestDTO {
|
||||
private String codMart;
|
||||
private String partitaMag;
|
||||
private BigDecimal qtaRientro;
|
||||
private DtbOrdt order;
|
||||
|
||||
|
||||
public MtbColt getSourceMtbColt() {
|
||||
@@ -57,4 +59,13 @@ public class RientroMerceRequestDTO {
|
||||
this.qtaRientro = qtaRientro;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DtbOrdt getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public RientroMerceRequestDTO setOrder(DtbOrdt order) {
|
||||
this.order = order;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,7 +488,7 @@ public class SystemController {
|
||||
if (!UtilityString.isNullOrEmpty(username) && !UtilityString.isNullOrEmpty(password)) {
|
||||
for (AvailableConnectionsModel availableConnectionsModel : settingsModel.getAvailableConnections()) {
|
||||
if (availableConnectionsModel.getInternalDb()) {
|
||||
HashMap<String, Object> tmpUserData = systemService.getUserdata(username, password, null, availableConnectionsModel.getProfileName());
|
||||
HashMap<String, Object> tmpUserData = systemService.getUserdata(username, password, null, availableConnectionsModel);
|
||||
if (tmpUserData != null) profilesWhereUserFound.add(availableConnectionsModel.getProfileName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package it.integry.ems.system.exchange.controller;
|
||||
|
||||
import it.integry.common.var.CommonConstants;
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.response.ServiceRestResponse;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.system.exchange.service.ExchangeDistinteImportService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Scope("request")
|
||||
@RequestMapping("exchange/distinte/")
|
||||
public class ExchangeDistinteImportController {
|
||||
|
||||
@Autowired
|
||||
private ExchangeDistinteImportService exchangeDistinteImportService;
|
||||
|
||||
@Autowired
|
||||
private RequestDataDTO requestDataDTO;
|
||||
|
||||
@GetMapping(value = "import")
|
||||
public @ResponseBody
|
||||
ServiceRestResponse importDistinte(@RequestParam(CommonConstants.PROFILE_DB) String profileDb,
|
||||
@RequestParam() String profileDbExchange) throws Exception {
|
||||
|
||||
|
||||
try (MultiDBTransactionManager internalDb = new MultiDBTransactionManager(profileDb);
|
||||
MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
|
||||
exchangeDistinteImportService.importDistinte(internalDb, exchangeDb, requestDataDTO);
|
||||
}
|
||||
return ServiceRestResponse.createPositiveResponse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package it.integry.ems.system.exchange.service;
|
||||
|
||||
import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.system.exchange.service.structure.ExchangeImportDataManagerService;
|
||||
import it.integry.ems.system.exchange.service.structure.ExchangeImportSchemaManagerService;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.entity.JtbCicl;
|
||||
import it.integry.ems_model.entity.JtbDistMate;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ExchangeDistinteImportService {
|
||||
|
||||
//TODO: To be remove, only for fast development
|
||||
private final String EXCHANGE_USER = "EXCHANGE";
|
||||
|
||||
@Autowired
|
||||
private EntityProcessor entityProcessor;
|
||||
|
||||
@Autowired
|
||||
private ExchangeImportSchemaManagerService exchangeImportSchemaManagerService;
|
||||
|
||||
@Autowired
|
||||
private ExchangeImportDataManagerService exchangeImportDataManagerService;
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
|
||||
public void importDistinte(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, RequestDataDTO requestDataDTO) throws Exception {
|
||||
boolean useTempTable = true;
|
||||
ExchangeImportSchemaManagerService.SchemaType schemaType = ExchangeImportSchemaManagerService.SchemaType.DistinteBase;
|
||||
|
||||
String testataTableName = null;
|
||||
String righeTableName = null;
|
||||
|
||||
if (schemaType == ExchangeImportSchemaManagerService.SchemaType.DistinteBase) {
|
||||
testataTableName = "jtb_cicl";
|
||||
righeTableName = "jtb_dist_mate";
|
||||
}
|
||||
|
||||
try {
|
||||
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), schemaType, useTempTable);
|
||||
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable,
|
||||
exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
||||
exchangeMultiDb.commitAll();
|
||||
|
||||
final List<JtbCicl> exchangeImportedData = retrieveDistinte(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false,
|
||||
testataTableName, righeTableName);
|
||||
|
||||
final List<JtbCicl> exchangeUpdatedData = retrieveDistinte(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable,
|
||||
testataTableName, righeTableName);
|
||||
|
||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||
.runSync(JtbCicl.class, exchangeImportedData, exchangeUpdatedData);
|
||||
|
||||
allData.stream()
|
||||
.filter(x -> x.getOperation() == OperationType.INSERT)
|
||||
.map(x -> (JtbCicl) x)
|
||||
.forEach(x -> {
|
||||
x.setFlagAttiva("S");
|
||||
x.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||
});
|
||||
|
||||
allData.removeIf(x -> x.getOperation() == OperationType.DELETE);
|
||||
|
||||
// allData.parallelStream()
|
||||
// .filter(x -> x.getOperation() == OperationType.DELETE)
|
||||
// .map(x -> (JtbCicl) x)
|
||||
// .forEach(x -> {
|
||||
// x.setFlagAttiva("N");
|
||||
// x.setOperation(OperationType.UPDATE);
|
||||
// });
|
||||
|
||||
final Exception[] firstExceptionToThrow = {null};
|
||||
|
||||
AtomicInteger importedCounter = new AtomicInteger();
|
||||
|
||||
for (EquatableEntityInterface<?> dataToSave : allData) {
|
||||
|
||||
JtbCicl distintaToSave = (JtbCicl) dataToSave;
|
||||
|
||||
logger.debug("Importate {} distinte di {}", importedCounter.incrementAndGet(), allData.size());
|
||||
try {
|
||||
entityProcessor.processEntity(distintaToSave, true, true, EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||
|
||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), distintaToSave, useTempTable, testataTableName);
|
||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), distintaToSave.getJtbDistMate(), useTempTable, righeTableName);
|
||||
|
||||
internalMultiDb.commitAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
} catch (Exception ex) {
|
||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||
|
||||
logger.error("Errore durante l'importazione della distinta [" +
|
||||
"cod prod: " + distintaToSave.getCodProd() + "]", ex);
|
||||
internalMultiDb.rollbackAll();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||
} finally {
|
||||
if (useTempTable)
|
||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), schemaType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<JtbCicl> retrieveDistinte(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable,
|
||||
String testataOriginalName, String righeOriginalName) throws Exception {
|
||||
String testataTableName = testataOriginalName + (useTempTable ? "_tmp" : "");
|
||||
String righeTableName = righeOriginalName + (useTempTable ? "_tmp" : "");
|
||||
|
||||
|
||||
final List<JtbCicl> testate = exchangeImportDataManagerService.retrieveDataFromExchange(connection, JtbCicl.class,
|
||||
testataTableName, null, retrieveAlreadyImported);
|
||||
|
||||
final List<JtbDistMate> righe = exchangeImportDataManagerService.retrieveDataFromExchange(connection, JtbDistMate.class,
|
||||
righeTableName, null, retrieveAlreadyImported);
|
||||
|
||||
final List<JtbCicl> orphanTestateToAdd = righe.parallelStream()
|
||||
.filter(riga ->
|
||||
testate.parallelStream()
|
||||
.noneMatch(testata ->
|
||||
Objects.hash(riga.getCodProd()) ==
|
||||
Objects.hash(testata.getCodProd()) &&
|
||||
|
||||
(Objects.equals(riga.getCodProd(), testata.getCodProd()))))
|
||||
.map(riga -> {
|
||||
JtbCicl testata = new JtbCicl();
|
||||
testata.setCodProd(riga.getCodProd());
|
||||
testata.setOperation(OperationType.UPDATE);
|
||||
return testata;
|
||||
})
|
||||
.filter(testataOrphan -> testate.stream().noneMatch(testataOrphan::equalsKey))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
testate.addAll(orphanTestateToAdd);
|
||||
|
||||
testate.parallelStream()
|
||||
.forEach(testata -> {
|
||||
testata.setUsername(EXCHANGE_USER);
|
||||
//testata.setUpdProgMaga(false);
|
||||
|
||||
testata.setJtbDistMate(righe.parallelStream()
|
||||
.filter(riga ->
|
||||
Objects.hash(testata.getCodProd()) == Objects.hash(riga.getCodProd()) &&
|
||||
|
||||
(Objects.equals(testata.getCodProd(), riga.getCodProd())))
|
||||
.collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
return testate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void singleUpdateImported(Connection connection, JtbCicl imported, boolean useTempTable, String tableName) throws Exception {
|
||||
final HashMap<String, Object> importedKey = new HashMap<String, Object>() {{
|
||||
put("cod_prod", imported.getCodProd());
|
||||
}};
|
||||
|
||||
exchangeImportDataManagerService.updateImportedStatus(connection, tableName, importedKey, useTempTable);
|
||||
}
|
||||
|
||||
private void singleUpdateImported(Connection connection, List<JtbDistMate> imported, boolean useTempTable, String tableName) throws Exception {
|
||||
final List<HashMap<String, Object>> importedRowKeys = imported.stream()
|
||||
.map(x -> new HashMap<String, Object>() {{
|
||||
put("cod_prod", x.getCodProd());
|
||||
put("id_riga", x.getIdRiga());
|
||||
}}).collect(Collectors.toList());
|
||||
exchangeImportDataManagerService.updateImportedStatus(connection, tableName, importedRowKeys, useTempTable);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -259,20 +259,20 @@ public class ExchangeDocumentImportService {
|
||||
}
|
||||
|
||||
|
||||
private void singleUpdateImported(Connection connection, DtbDoct importedDtbDoct, boolean useTempTable, String tableName) throws Exception {
|
||||
private void singleUpdateImported(Connection connection, DtbDoct imported, boolean useTempTable, String tableName) throws Exception {
|
||||
final HashMap<String, Object> importedKey = new HashMap<String, Object>() {{
|
||||
put("data_doc", importedDtbDoct.getDataDoc());
|
||||
put("ser_doc", importedDtbDoct.getSerDoc());
|
||||
put("num_doc", importedDtbDoct.getNumDoc());
|
||||
put("cod_anag", importedDtbDoct.getCodAnag());
|
||||
put("cod_dtip", importedDtbDoct.getCodDtip());
|
||||
put("data_doc", imported.getDataDoc());
|
||||
put("ser_doc", imported.getSerDoc());
|
||||
put("num_doc", imported.getNumDoc());
|
||||
put("cod_anag", imported.getCodAnag());
|
||||
put("cod_dtip", imported.getCodDtip());
|
||||
}};
|
||||
|
||||
exchangeImportDataManagerService.updateImportedStatus(connection, tableName, importedKey, useTempTable);
|
||||
}
|
||||
|
||||
private void singleUpdateImported(Connection connection, List<DtbDocr> importedDtbDocr, boolean useTempTable, String tableName) throws Exception {
|
||||
final List<HashMap<String, Object>> importedRowKeys = importedDtbDocr.stream()
|
||||
private void singleUpdateImported(Connection connection, List<DtbDocr> imported, boolean useTempTable, String tableName) throws Exception {
|
||||
final List<HashMap<String, Object>> importedRowKeys = imported.stream()
|
||||
.map(x -> new HashMap<String, Object>() {{
|
||||
put("data_doc", x.getDataDoc());
|
||||
put("ser_doc", x.getSerDoc());
|
||||
|
||||
@@ -200,6 +200,11 @@ public class ExchangeSystemManagerService {
|
||||
final ExchangeContrattiImportService beanContrattiVendita = ContextLoader.getCurrentWebApplicationContext().getBean(ExchangeContrattiImportService.class);
|
||||
beanContrattiVendita.importVendita(internalDb, exchangeDb, requestDataDTO);
|
||||
break;
|
||||
|
||||
case DistinteBase:
|
||||
final ExchangeDistinteImportService beanDistinteBase = ContextLoader.getCurrentWebApplicationContext().getBean(ExchangeDistinteImportService.class);
|
||||
beanDistinteBase.importDistinte(internalDb, exchangeDb, requestDataDTO);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ public class ExchangeImportSchemaManagerService {
|
||||
DocumentiAcquisto(15),
|
||||
ColliVendita(16),
|
||||
OrdiniVendita(17),
|
||||
ContrattiVendita(18);
|
||||
ContrattiVendita(18),
|
||||
DistinteBase(19);
|
||||
|
||||
|
||||
private final int value;
|
||||
@@ -147,6 +148,10 @@ public class ExchangeImportSchemaManagerService {
|
||||
put("vtb_offt_vend", VtbOfft.class);
|
||||
put("vtb_offr_vend", VtbOffr.class);
|
||||
}});
|
||||
put(SchemaType.DistinteBase, new HashMap<String, Class<? extends EntityInterface>>() {{
|
||||
put("jtb_cicl", JtbCicl.class);
|
||||
put("jtb_dist_mate", JtbDistMate.class);
|
||||
}});
|
||||
|
||||
}};
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package it.integry.ems.system.service;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.ems.Import.dto.AnomalieDTO;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.service.EntityProcessor;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.service.MapService;
|
||||
@@ -301,105 +300,106 @@ public class AnagImportService {
|
||||
if (UtilityString.streNull(profileSource).compareTo("") == 0) {
|
||||
throw new Exception("CONFIGURARE PROFILEDB EXCH2WINGEST IN STB_GEST_SETUP.");
|
||||
}
|
||||
DataSource dsExch2Wingest = new DataSource();
|
||||
dsExch2Wingest.initialize(profileSource);
|
||||
Connection connExch2Wingest = dsExch2Wingest.getConnection();
|
||||
|
||||
sql = "select distinct Addresses.country as nazione " +
|
||||
" from Addresses " +
|
||||
" WHERE Addresses.country NOT IN (SELECT nazione FROM " + dbPrimaryName + ".dbo.gtb_nazi)";
|
||||
try(MultiDBTransactionManager exchangeMultiDb = new MultiDBTransactionManager(profileSource)) {
|
||||
Connection exchangeConnection = exchangeMultiDb.getPrimaryConnection();
|
||||
|
||||
List<GtbNazi> gtbNazi = new ResultSetMapper()
|
||||
.mapQuerySetToList(connExch2Wingest, sql, GtbNazi.class, OperationType.INSERT);
|
||||
toBeProcessed.addAll(gtbNazi);
|
||||
sql = "select distinct Addresses.country as nazione " +
|
||||
" from Addresses " +
|
||||
" WHERE Addresses.country NOT IN (SELECT nazione FROM " + dbPrimaryName + ".dbo.gtb_nazi)";
|
||||
|
||||
sql = "select Companies.CompID as diacod," +
|
||||
" Companies.CompName as rag_soc," +
|
||||
" Companies.VatNum as part_iva, " +
|
||||
" CASE WHEN Companies.VatNum <> Companies.TaxCode THEN Companies.TaxCode ELSE null END as cod_fisc, " +
|
||||
" Addresses.addressId as cod_vdes, " +
|
||||
" Addresses.address as indirizzo, " +
|
||||
" Addresses.ZipCode as cap, " +
|
||||
" Addresses.City as citta, " +
|
||||
" Addresses.Prov as prov, " +
|
||||
" Addresses.Country as nazione, " +
|
||||
" Addresses.TelNum as telefono, " +
|
||||
" Addresses.Email as e_mail " +
|
||||
" from Companies, Addresses" +
|
||||
" where Companies.CompID = Addresses.CompID and (left(Companies.CompID,1)+Right(Companies.CompID, 4) not in (select cod_anag from " + dbPrimaryName + ".dbo.gtb_anag ) OR (Right(Addresses.addressId,5) <>'00000' AND left(Companies.CompID,1)+Right(Companies.CompID, 4)+ Right(Addresses.addressId,5) not in (select cod_anag + cod_vdes from " + dbPrimaryName + ".dbo.vtb_dest )))" +
|
||||
" order by Companies.CompID, Addresses.addressId ";
|
||||
List<GtbNazi> gtbNazi = new ResultSetMapper()
|
||||
.mapQuerySetToList(exchangeConnection, sql, GtbNazi.class, OperationType.INSERT);
|
||||
toBeProcessed.addAll(gtbNazi);
|
||||
|
||||
info = connExch2Wingest.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
res = info.executeQuery();
|
||||
while (res.next()) {
|
||||
diacod = res.getString("diacod");
|
||||
ragSoc = res.getString("rag_soc");
|
||||
partIva = UtilityString.right(UtilityString.streNull(res.getString("part_iva")).trim(), 20);
|
||||
codFisc = UtilityString.right(UtilityString.streNull(res.getString("cod_fisc")).trim(), 16);
|
||||
destinatario = res.getString("cod_vdes");
|
||||
codVdes = UtilityString.right(destinatario.trim(), 5);
|
||||
indirizzo = UtilityString.right(res.getString("indirizzo").trim(), 80);
|
||||
cap = res.getString("cap").trim();
|
||||
citta = UtilityString.right(res.getString("citta").trim(), 30);
|
||||
prov = UtilityString.right(res.getString("prov").trim(), 2);
|
||||
nazione = UtilityString.right(res.getString("nazione").trim(), 3);
|
||||
telefono = UtilityString.right(res.getString("telefono").trim(), 40);
|
||||
email = UtilityString.left(UtilityString.replaceSubString(res.getString("e_mail").trim(), " ", ""), 40);
|
||||
sql = "select Companies.CompID as diacod," +
|
||||
" Companies.CompName as rag_soc," +
|
||||
" Companies.VatNum as part_iva, " +
|
||||
" CASE WHEN Companies.VatNum <> Companies.TaxCode THEN Companies.TaxCode ELSE null END as cod_fisc, " +
|
||||
" Addresses.addressId as cod_vdes, " +
|
||||
" Addresses.address as indirizzo, " +
|
||||
" Addresses.ZipCode as cap, " +
|
||||
" Addresses.City as citta, " +
|
||||
" Addresses.Prov as prov, " +
|
||||
" Addresses.Country as nazione, " +
|
||||
" Addresses.TelNum as telefono, " +
|
||||
" Addresses.Email as e_mail " +
|
||||
" from Companies, Addresses" +
|
||||
" where Companies.CompID = Addresses.CompID and (left(Companies.CompID,1)+Right(Companies.CompID, 4) not in (select cod_anag from " + dbPrimaryName + ".dbo.gtb_anag ) OR (Right(Addresses.addressId,5) <>'00000' AND left(Companies.CompID,1)+Right(Companies.CompID, 4)+ Right(Addresses.addressId,5) not in (select cod_anag + cod_vdes from " + dbPrimaryName + ".dbo.vtb_dest )))" +
|
||||
" order by Companies.CompID, Addresses.addressId ";
|
||||
|
||||
codAnag = UtilityString.left(diacod, 1) + UtilityString.right(diacod, 4);
|
||||
info = exchangeConnection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
res = info.executeQuery();
|
||||
while (res.next()) {
|
||||
diacod = res.getString("diacod");
|
||||
ragSoc = res.getString("rag_soc");
|
||||
partIva = UtilityString.right(UtilityString.streNull(res.getString("part_iva")).trim(), 20);
|
||||
codFisc = UtilityString.right(UtilityString.streNull(res.getString("cod_fisc")).trim(), 16);
|
||||
destinatario = res.getString("cod_vdes");
|
||||
codVdes = UtilityString.right(destinatario.trim(), 5);
|
||||
indirizzo = UtilityString.right(res.getString("indirizzo").trim(), 80);
|
||||
cap = res.getString("cap").trim();
|
||||
citta = UtilityString.right(res.getString("citta").trim(), 30);
|
||||
prov = UtilityString.right(res.getString("prov").trim(), 2);
|
||||
nazione = UtilityString.right(res.getString("nazione").trim(), 3);
|
||||
telefono = UtilityString.right(res.getString("telefono").trim(), 40);
|
||||
email = UtilityString.left(UtilityString.replaceSubString(res.getString("e_mail").trim(), " ", ""), 40);
|
||||
|
||||
GtbAnag gtbAnag = new GtbAnag();
|
||||
gtbAnag.setCodAnag(codAnag);
|
||||
if (codVdes.compareTo("00000") == 0) {
|
||||
gtbAnag.setOperation(OperationType.INSERT);
|
||||
gtbAnag.setRagSoc(ragSoc);
|
||||
gtbAnag.setIndirizzo(indirizzo);
|
||||
gtbAnag.setCap(cap);
|
||||
gtbAnag.setCitta(citta);
|
||||
gtbAnag.setProv(prov);
|
||||
gtbAnag.setNazione(nazione);
|
||||
gtbAnag.setPartIva(partIva);
|
||||
gtbAnag.setCodFisc(codFisc);
|
||||
gtbAnag.setTelefono(telefono);
|
||||
gtbAnag.seteMail(email);
|
||||
gtbAnag.setDiacod(diacod);
|
||||
} else {
|
||||
gtbAnag.setOperation(OperationType.NO_OP);
|
||||
VtbDest vtbDest = new VtbDest();
|
||||
vtbDest.setOperation(OperationType.INSERT);
|
||||
vtbDest.setCodAnag(codAnag);
|
||||
vtbDest.setCodVdes(codVdes);
|
||||
vtbDest.setDestinatario(ragSoc);
|
||||
vtbDest.setCodEan(destinatario);
|
||||
vtbDest.setCap(cap);
|
||||
vtbDest.setCitta(citta);
|
||||
vtbDest.setProv(prov);
|
||||
vtbDest.setIndirizzo(UtilityString.right(indirizzo, 40));
|
||||
vtbDest.setNazione(nazione);
|
||||
vtbDest.setTel(telefono);
|
||||
vtbDest.seteMail(email);
|
||||
vtbDest.setCodFisc(codFisc);
|
||||
vtbDest.setPartIva(partIva);
|
||||
gtbAnag.getVtbDest().add(vtbDest);
|
||||
codAnag = UtilityString.left(diacod, 1) + UtilityString.right(diacod, 4);
|
||||
|
||||
GtbAnag gtbAnag = new GtbAnag();
|
||||
gtbAnag.setCodAnag(codAnag);
|
||||
if (codVdes.compareTo("00000") == 0) {
|
||||
gtbAnag.setOperation(OperationType.INSERT);
|
||||
gtbAnag.setRagSoc(ragSoc);
|
||||
gtbAnag.setIndirizzo(indirizzo);
|
||||
gtbAnag.setCap(cap);
|
||||
gtbAnag.setCitta(citta);
|
||||
gtbAnag.setProv(prov);
|
||||
gtbAnag.setNazione(nazione);
|
||||
gtbAnag.setPartIva(partIva);
|
||||
gtbAnag.setCodFisc(codFisc);
|
||||
gtbAnag.setTelefono(telefono);
|
||||
gtbAnag.seteMail(email);
|
||||
gtbAnag.setDiacod(diacod);
|
||||
} else {
|
||||
gtbAnag.setOperation(OperationType.NO_OP);
|
||||
VtbDest vtbDest = new VtbDest();
|
||||
vtbDest.setOperation(OperationType.INSERT);
|
||||
vtbDest.setCodAnag(codAnag);
|
||||
vtbDest.setCodVdes(codVdes);
|
||||
vtbDest.setDestinatario(ragSoc);
|
||||
vtbDest.setCodEan(destinatario);
|
||||
vtbDest.setCap(cap);
|
||||
vtbDest.setCitta(citta);
|
||||
vtbDest.setProv(prov);
|
||||
vtbDest.setIndirizzo(UtilityString.right(indirizzo, 40));
|
||||
vtbDest.setNazione(nazione);
|
||||
vtbDest.setTel(telefono);
|
||||
vtbDest.seteMail(email);
|
||||
vtbDest.setCodFisc(codFisc);
|
||||
vtbDest.setPartIva(partIva);
|
||||
gtbAnag.getVtbDest().add(vtbDest);
|
||||
}
|
||||
|
||||
if (UtilityString.left(diacod, 1).compareTo("C") == 0 && codVdes.compareTo("00000") == 0) {
|
||||
VtbClie vtbClie = new VtbClie();
|
||||
vtbClie.setOperation(OperationType.INSERT);
|
||||
vtbClie.setCodAnag(codAnag);
|
||||
gtbAnag.setVtbClie(vtbClie);
|
||||
}
|
||||
if (UtilityString.left(diacod, 1).compareTo("F") == 0 && codVdes.compareTo("00000") == 0) {
|
||||
AtbForn atbForn = new AtbForn();
|
||||
atbForn.setOperation(OperationType.INSERT);
|
||||
atbForn.setCodAnag(codAnag);
|
||||
gtbAnag.setAtbForn(atbForn);
|
||||
}
|
||||
|
||||
toBeProcessed.add(gtbAnag);
|
||||
}
|
||||
|
||||
if (UtilityString.left(diacod, 1).compareTo("C") == 0 && codVdes.compareTo("00000") == 0) {
|
||||
VtbClie vtbClie = new VtbClie();
|
||||
vtbClie.setOperation(OperationType.INSERT);
|
||||
vtbClie.setCodAnag(codAnag);
|
||||
gtbAnag.setVtbClie(vtbClie);
|
||||
}
|
||||
if (UtilityString.left(diacod, 1).compareTo("F") == 0 && codVdes.compareTo("00000") == 0) {
|
||||
AtbForn atbForn = new AtbForn();
|
||||
atbForn.setOperation(OperationType.INSERT);
|
||||
atbForn.setCodAnag(codAnag);
|
||||
gtbAnag.setAtbForn(atbForn);
|
||||
}
|
||||
|
||||
toBeProcessed.add(gtbAnag);
|
||||
res.close();
|
||||
info.close();
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
|
||||
if (!toBeProcessed.isEmpty()) {
|
||||
entitiesReturn = entityProcessor.processEntityList(toBeProcessed, true);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class SystemService {
|
||||
return new ServiceRestResponse(EsitoType.OK, nodeList);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getUserdata(String userName, String password, String md5User, String profileDB) throws Exception {
|
||||
public HashMap<String, Object> getUserdata(String userName, String password, String md5User, AvailableConnectionsModel connectionModel) throws Exception {
|
||||
String whereCond;
|
||||
if (userName != null && !UtilityString.isNullOrEmpty(userName.trim())) {
|
||||
String pswLower = password != null ? password.toLowerCase() : null;
|
||||
@@ -186,9 +186,8 @@ public class SystemService {
|
||||
|
||||
HashMap<String, Object> resultMap = null;
|
||||
|
||||
try {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(profileDB);
|
||||
try (MultiDBTransactionManager mdb = new MultiDBTransactionManager(connectionModel)){
|
||||
|
||||
String sql = "SELECT stb_user.user_name," +
|
||||
" stb_user.key_group," +
|
||||
" stb_user.full_name," +
|
||||
@@ -204,7 +203,7 @@ public class SystemService {
|
||||
" THEN 'N' " +
|
||||
" ELSE ISNULL(stb_user.flag_attivo, 'N') " +
|
||||
" END AS flag_attivo," +
|
||||
UtilityDB.valueToString(profileDB) + " AS profile_db " +
|
||||
UtilityDB.valueToString(connectionModel.getProfileName()) + " AS profile_db " +
|
||||
"FROM stb_user " +
|
||||
" LEFT OUTER JOIN wtb_depo ON stb_user.user_name = wtb_depo.user_name " +
|
||||
" LEFT OUTER JOIN mtb_depo ON wtb_depo.cod_mdep = mtb_depo.cod_mdep " +
|
||||
@@ -221,11 +220,10 @@ public class SystemService {
|
||||
}
|
||||
sql = UtilityDB.addwhereCond(sql, whereCond, false);
|
||||
|
||||
resultMap = UtilityDB.executeSimpleQueryOnlyFirstRow(ds.getConnection(), sql);
|
||||
ds.forceClose();
|
||||
resultMap = UtilityDB.executeSimpleQueryOnlyFirstRow(mdb.getPrimaryConnection(), sql);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("getUserdata (" + profileDB + ")", e);
|
||||
logger.error("getUserdata (" + connectionModel.getProfileName() + ")", e);
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
|
||||
Reference in New Issue
Block a user