Update su funzione f_getCostSpes e aggiunta setup per escludere i colli dalla giacenza mrp
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20240507142922 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
|
||||
createOrUpdateFunction("f_GetCostoSpecArt", "CREATE FUNCTION [dbo].[f_GetCostoSpecArt](@adt_dataValore datetime, @as_codMart varchar(15))\n" +
|
||||
"RETURNS numeric(20,5) AS\n" +
|
||||
"BEGIN\n" +
|
||||
" declare @lc_costoUntSpec numeric(20, 5);\n" +
|
||||
"\n" +
|
||||
" /* Ricerca ultima data di valorizzazione specifica minore o uglale a dataValore Richiesto */\n" +
|
||||
" select @lc_costoUntSpec = ISNULL(mtb_aart_spec.costo_unt_spec, 0)\n" +
|
||||
" from mtb_aart_spec\n" +
|
||||
" where mtb_aart_spec.cod_mart = @as_codMart\n" +
|
||||
" and mtb_aart_spec.data_iniz_val = (select max(mtb_aart_spec.data_iniz_val)\n" +
|
||||
" from mtb_aart_spec\n" +
|
||||
" where mtb_aart_spec.cod_mart = @as_codMart\n" +
|
||||
" and mtb_aart_spec.data_iniz_val <= @adt_dataValore)\n" +
|
||||
"\n" +
|
||||
" SELECT @lc_costoUntSpec = ISNULL(@lc_costoUntSpec, 0)\n" +
|
||||
" \n" +
|
||||
" RETURN @lc_costoUntSpec\n" +
|
||||
"END");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,7 +58,8 @@ public class MrpDailyMaterialReqService {
|
||||
Map<String, List<MRPDailyDatiDepoDTO>> listDepositi = getDatiDepo(depositi, articoli);
|
||||
logger.debug(MrpDailyMaterialReqService.class.getSimpleName() + " - getDatiDepo: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
|
||||
String tableNameColli = getColliV(depositi, articoli);
|
||||
String tableNameColli= getColliV(depositi, articoli, UtilityString.equalsIgnoreCase(setupSection.get("CONSIDERA_COLLI_GIACENZA"), "S"));
|
||||
|
||||
logger.debug(MrpDailyMaterialReqService.class.getSimpleName() + " - getColliV: Timing " + ((new Date().getTime() - startDate.getTime()) / 1000) + " secs");
|
||||
|
||||
List<MrpDailyMaterialReqDetDTO> mrpDailyMaterialReqDetDTO = getGiacenza(depositi, articoli, tableNameColli);
|
||||
@@ -490,46 +491,62 @@ public class MrpDailyMaterialReqService {
|
||||
return sql;
|
||||
}
|
||||
|
||||
private String getColliV(String depositi, String articoli) throws Exception {
|
||||
private String getColliV(String depositi, String articoli, boolean consideraColli) throws Exception {
|
||||
|
||||
String tableName = UtilityDB.defTmpTabName("t1_");
|
||||
String
|
||||
sql =
|
||||
"\tSELECT mtb_colt.cod_mdep, \n" +
|
||||
"\t\t\tmtb_colr.gestione, \n" +
|
||||
"\t\t\tmtb_colr.data_ord, \n" +
|
||||
"\t\t\tmtb_colr.num_ord, \n" +
|
||||
"\t\t\tmtb_colr.riga_ord, \n" +
|
||||
"\t\t\tmtb_colr.cod_mart, \n" +
|
||||
"\t\t\tSUM(mtb_colr.qta_col) AS qta_col\n" +
|
||||
" INTO %s \n" +
|
||||
" FROM mtb_colt\n" +
|
||||
"\t\t\tINNER JOIN mtb_colr\n" +
|
||||
" ON mtb_colt.gestione = mtb_colr.gestione AND\n" +
|
||||
" mtb_colt.data_collo = mtb_colr.data_collo AND\n" +
|
||||
" mtb_colt.ser_collo = mtb_colr.ser_collo AND\n" +
|
||||
" mtb_colt.num_collo = mtb_colr.num_collo\n" + " WHERE mtb_colt.gestione = 'V'\n" +
|
||||
" AND mtb_colt.segno = -1\n" +
|
||||
" AND mtb_colt.cod_dtip IS NULL\n" +
|
||||
" AND mtb_colt.data_collo >= dbo.f_getFirstDayOfMonth(DATEADD(MONTH, -3, CAST(GETDATE() AS DATE)))\n" +
|
||||
" AND mtb_colt.cod_mdep IN ('%s') \n" +
|
||||
" AND mtb_colr.cod_mart IN ('%s') \n" +
|
||||
"\tGROUP BY mtb_colt.cod_mdep ,\n" +
|
||||
"\t\t\tmtb_colr.gestione, \n" +
|
||||
"\t\t\tmtb_colr.data_ord, \n" +
|
||||
"\t\t\tmtb_colr.num_ord, \n" +
|
||||
"\t\t\tmtb_colr.riga_ord, \n" +
|
||||
"\t\t\tmtb_colr.cod_mart";
|
||||
String sql = "";
|
||||
if (consideraColli) {
|
||||
sql =
|
||||
"\tSELECT mtb_colt.cod_mdep, \n" +
|
||||
"\t\t\tmtb_colr.gestione, \n" +
|
||||
"\t\t\tmtb_colr.data_ord, \n" +
|
||||
"\t\t\tmtb_colr.num_ord, \n" +
|
||||
"\t\t\tmtb_colr.riga_ord, \n" +
|
||||
"\t\t\tmtb_colr.cod_mart, \n" +
|
||||
"\t\t\tSUM(mtb_colr.qta_col) AS qta_col\n" +
|
||||
" INTO %s \n" +
|
||||
" FROM mtb_colt\n" +
|
||||
"\t\t\tINNER JOIN mtb_colr\n" +
|
||||
" ON mtb_colt.gestione = mtb_colr.gestione AND\n" +
|
||||
" mtb_colt.data_collo = mtb_colr.data_collo AND\n" +
|
||||
" mtb_colt.ser_collo = mtb_colr.ser_collo AND\n" +
|
||||
" mtb_colt.num_collo = mtb_colr.num_collo\n" + " WHERE mtb_colt.gestione = 'V'\n" +
|
||||
" AND mtb_colt.segno = -1\n" +
|
||||
" AND mtb_colt.cod_dtip IS NULL\n" +
|
||||
" AND mtb_colt.data_collo >= dbo.f_getFirstDayOfMonth(DATEADD(MONTH, -3, CAST(GETDATE() AS DATE)))\n" +
|
||||
" AND mtb_colt.cod_mdep IN ('%s') \n" +
|
||||
" AND mtb_colr.cod_mart IN ('%s') \n" +
|
||||
"\tGROUP BY mtb_colt.cod_mdep ,\n" +
|
||||
"\t\t\tmtb_colr.gestione, \n" +
|
||||
"\t\t\tmtb_colr.data_ord, \n" +
|
||||
"\t\t\tmtb_colr.num_ord, \n" +
|
||||
"\t\t\tmtb_colr.riga_ord, \n" +
|
||||
"\t\t\tmtb_colr.cod_mart";
|
||||
|
||||
sql = String.format(sql, tableName, depositi, articoli);
|
||||
multiDBTransactionManager.prepareStatement(sql).execute();
|
||||
multiDBTransactionManager.commitAll();
|
||||
sql = String.format(sql, tableName, depositi, articoli);
|
||||
multiDBTransactionManager.prepareStatement(sql).execute();
|
||||
multiDBTransactionManager.commitAll();
|
||||
} else {
|
||||
sql =
|
||||
"CREATE TABLE " + tableName + " ("+
|
||||
"cod_mdep varchar(5)," +
|
||||
"gestione varchar(1)," +
|
||||
"data_ord datetime," +
|
||||
"num_ord int," +
|
||||
"riga_ord int," +
|
||||
"cod_mart varchar(15), " +
|
||||
"qta_col numeric(20,5))";
|
||||
|
||||
multiDBTransactionManager.prepareStatement(sql).execute();
|
||||
multiDBTransactionManager.commitAll();
|
||||
|
||||
}
|
||||
// CREAZIONE INDICE
|
||||
sql = "CREATE INDEX ix_" + tableName + " ON " + tableName + " (cod_mdep, cod_mart)";
|
||||
multiDBTransactionManager.prepareStatement(sql).execute();
|
||||
multiDBTransactionManager.commitAll();
|
||||
|
||||
|
||||
return tableName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user