diff --git a/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002111947.java b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002111947.java new file mode 100644 index 0000000000..f51813f34e --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002111947.java @@ -0,0 +1,33 @@ +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; +import it.integry.ems_model.entity.JtbFasi; + +public class Migration_20251002111947 extends BaseMigration implements MigrationModelInterface { + + @Override + public void up() throws Exception { + if (isHistoryDB()) + return; + + createSetup("MES", "SETUP", "VINCOLA_DATA_PROD_AL_LOTTO", "N", "Se true, sulle linee su cui è impostata la data produzione della partita verrà calcolata in base alla partita stessa (es. dal giorno giuliano selezionato)", false, "SI_NO", false, false, false, false, false, JtbFasi.ENTITY, false, null); + + if (isCustomer(IntegryCustomer.RossoGargano)){ + executeStatement("INSERT INTO stb_gest_setup_det (gest_name, section, key_section, tipo_setup, val_col_rif, value)\n" + + "SELECT N'MES',\n" + + " N'SETUP',\n" + + " N'VINCOLA_DATA_PROD_AL_LOTTO',\n" + + " N'" + JtbFasi.ENTITY + "',\n" + + " cod_jfas,\n" + + " 'S'\n" + + "FROM jtb_fasi\n" + + "WHERE cod_jfas IN ('E5')\n"); + } + } + + @Override + public void down() throws Exception { + } +} \ No newline at end of file diff --git a/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002112352.java b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002112352.java new file mode 100644 index 0000000000..b79ae8cfc9 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002112352.java @@ -0,0 +1,79 @@ +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_20251002112352 extends BaseMigration implements MigrationModelInterface { + + @Override + public void up() throws Exception { + if (isHistoryDB()) + return; + + + createOrUpdateFunction("f_suggestDataProdPartitaMag","CREATE FUNCTION [dbo].[f_suggestDataProdPartitaMag](@codMart VARCHAR(15),@partitaMag VARCHAR(20), @codJfas varchar(5))\n" + + " RETURNS DATE\n" + + "AS\n" + + "BEGIN\n" + + "\n" + + "RETURN NULL\n" + + "END\n" + ); + + if (isCustomer(IntegryCustomer.RossoGargano)){ + createOrUpdateFunction("f_suggestDataProdPartitaMag","CREATE FUNCTION [dbo].[f_suggestDataProdPartitaMag](@codMart VARCHAR(15), @partitaMag VARCHAR(20), @codJfas varchar(5))\n" + + " RETURNS DATE\n" + + " AS\n" + + " BEGIN\n" + + "\n" + + " DECLARE @idProduttore VARCHAR(10), @idProduttorePartita varchar(10);\n" + + " DECLARE @idLottoLav VARCHAR(5);\n" + + " DECLARE @codMdep VARCHAR(5);\n" + + " DECLARE @annoLottoLav smallint;\n" + + " DECLARE @ggGiuliano smallint;\n" + + " DECLARE @dataProd date;\n" + + "\n" + + "\n" + + " SELECT @codMdep = cod_mdep_lav from jtb_fasi where cod_jfas = @codJfas;\n" + + "\n" + + " SELECT @idProduttore = ISNULL(stb_gest_setup_depo.value, stb_gest_setup.value)\n" + + " FROM stb_gest_setup\n" + + " LEFT OUTER JOIN stb_gest_setup_depo ON stb_gest_setup.gest_name = stb_gest_setup_depo.gest_name AND\n" + + " stb_gest_setup.section = stb_gest_setup_depo.section AND\n" + + " stb_gest_setup.key_section = stb_gest_setup_depo.key_section\n" + + " AND stb_gest_setup_depo.cod_mdep = @codMdep\n" + + " WHERE stb_gest_setup.gest_name = 'DATI_AZIENDA'\n" + + " AND stb_gest_setup.section = 'SETUP'\n" + + " AND stb_gest_setup.key_section = 'COD_PRODUTTORE';\n" + + "\n" + + "\n" + + " SELECT @idProduttorePartita = SUBSTRING(@partitaMag, 1, LEN(@idProduttore));\n" + + "\n" + + " if not @idProduttorePartita = @idProduttore\n" + + " return null;\n" + + "\n" + + " select @partitaMag = REPLACE(@partitaMag, @idProduttore, '');\n" + + "\n" + + "\n" + + " SELECT @idLottoLav = SUBSTRING(@partitaMag, 1, 1);\n" + + " SELECT @annoLottoLav = anno from gtb_anni_divi where id_lotto_lav = @idLottoLav;\n" + + "\n" + + " if @annoLottoLav is null\n" + + " return null;\n" + + "\n" + + " SELECT @ggGiuliano = SUBSTRING(@partitaMag, 2, 3);\n" + + "\n" + + "\n" + + "\n" + + " SELECT @dataProd = DATEADD(DAY, @ggGiuliano - 1, DATEFROMPARTS(@annoLottoLav, 1, 1));\n" + + " return @dataProd\n" + + "\n" + + " END\n"); + } + } + + @Override + public void down() throws Exception { + } +} \ No newline at end of file diff --git a/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002113809.java b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002113809.java new file mode 100644 index 0000000000..aeee0864b3 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002113809.java @@ -0,0 +1,22 @@ +package it.integry.ems.migration.model; + +import it.integry.ems.migration._base.BaseMigration; +import it.integry.ems.migration._base.MigrationModelInterface; + +public class Migration_20251002113809 extends BaseMigration implements MigrationModelInterface { + + @Override + public void up() throws Exception { + if (isHistoryDB()) + return; + + if (!isTextiles()) return; + + dropIndex("ttb_qta_min_ord", "ix_unique_ttb_qta_min_ord"); + executeStatement("create unique index ix_unique_ttb_qta_min_ord on ttb_qta_min_ord (cod_line, cod_style, cod_grtg, range_taglie);"); + } + + @Override + public void down() throws Exception { + } +} \ No newline at end of file diff --git a/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002114819.java b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002114819.java new file mode 100644 index 0000000000..ad08db803f --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20251002114819.java @@ -0,0 +1,293 @@ +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_20251002114819 extends BaseMigration implements MigrationModelInterface { + + @Override + public void up() throws Exception { + if (isHistoryDB()) + return; + if (!isCustomer(IntegryCustomer.Biolevante)) return; + + + createOrUpdateFunction("f_pp_consuntivo_prod_tracc", "CREATE function [dbo].[f_pp_consuntivo_prod_tracc] (@as_codProdParent varchar(15), @as_partitaMagParent varchar(20), @ac_qtaProdParent numeric(20,5), @as_codProd varchar(15), @as_partitaMag varchar(20), @ac_qtaProd numeric(20, 5), @ai_livello integer, @as_item_id varchar(255), @ai_idRiga integer) \n" + + "RETURNS @dettCosti TABLE(livello integer, \n" + + " item_id varchar(255),\n" + + " cod_prod_parent varchar(15),\n" + + " partita_mag_parent varchar(20), \n" + + " qta_prod_parent numeric(20,5),\n" + + " cod_prod varchar(15),\n" + + " partita_mag varchar(20), \n" + + " qta_prod numeric(20,5),\n" + + " gruppo_conto varchar(40), \n" + + " conto varchar(40), \n" + + " descrizione_conto varchar(255), \n" + + " dettaglio_conto varchar(40),\n" + + " unt_mis varchar(5), \n" + + " qta_consumata numeric(20, 5)) AS\n" + + "Begin\n" + + " DECLARE \n" + + " @lc_qtaProd numeric(20,5), \n" + + " @ls_gruppoConto varchar(40), \n" + + " @ls_codMart varchar(15), \n" + + " @ls_partitaMag varchar(20), \n" + + " @ls_descrizione varchar(255), \n" + + " @ls_untMis varchar(5), \n" + + " @lc_qtaMP numeric(20,5), \n" + + " @li_existDist integer, \n" + + " @lc_rapporto numeric(20, 5),\n" + + " @lc_qtaProdScaricata numeric(20,5),\n" + + " @li_livello integer, \n" + + " @ls_itemID varchar(255),\n" + + " @li_idRiga integer,\n" + + " @ls_codMiscela varchar(15),\n" + + " @ls_posizione varchar(20),\n" + + " @ls_posizione_da varchar(20),\n" + + " @ls_posizione_a varchar(20)\n" + + "\n" + + " SELECT @ls_codMiscela = cod_mart FROM olvw_miscele_olio\n" + + "\n" + + " if @ai_idRiga is null\n" + + " begin\n" + + " SELECT @ai_livello = 1\n" + + " SELECT @as_item_id = '00001';\n" + + " end ;\n" + + " IF @as_item_id = '' \n" + + " begin\n" + + " Select @ls_posizione = mtb_depo_posizioni.posizione from mtb_partita_mag, mtb_depo_posizioni \n" + + " where mtb_depo_posizioni.posizione = mtb_partita_mag.posizione and\n" + + " mtb_partita_mag.cod_mart = @as_codProdParent and partita_mag = @as_partitaMagParent and\n" + + " mtb_depo_posizioni.flag_silos_liquidi = 1;\n" + + " If @ls_posizione is not null Select @as_item_id = 'SILOS' --Serve ad identificare le miscele di olio\n" + + " end\n" + + "\n" + + " /* Acquisizione quantita totale prodotta per prodotto-partita */\n" + + " Select @lc_qtaProd = ISNULL(sum(dtb_docr.qta_doc * dtb_docr.rap_conv * dtb_tipi.segno_qta_car), 0)\n" + + " from dtb_docr, \n" + + " dtb_tipi, \n" + + " mtb_aart, \n" + + " mtb_grup\n" + + " where dtb_docr.cod_dtip = dtb_tipi.cod_dtip and\n" + + " dtb_docr.cod_mart = mtb_aart.cod_mart and\n" + + " mtb_aart.cod_mgrp = mtb_Grup.cod_mgrp and\n" + + " dtb_docr.cod_mart = @as_codProd and\n" + + " dtb_docr.partita_mag = @as_partitaMag and\n" + + " dtb_tipi.gestione = 'L' and\n" + + " dtb_tipi.tipo_emissione = 'DIRETTA' and\n" + + " dtb_tipi.segno_qta_car <> 0\n" + + "\n" + + " /* Calcolo del rapporto della qta passata come parametro e di quella totale*/\n" + + " if @ac_qtaProd is not null\n" + + " if @lc_qtaProd = 0 select @lc_rapporto = 0 else select @lc_rapporto = @ac_qtaProd / @lc_qtaProd\n" + + " else\n" + + " begin \n" + + " select @lc_rapporto = 1\n" + + " select @ac_qtaProdParent = @lc_qtaProd\n" + + " end\n" + + " \n" + + " /* Acquisizione totale quantita' prodotta per prododo-partita_mag dagli scarichi\n" + + " E' necessario prendere la quantita dalla testata degli scarichi perche' ci \n" + + " potrebbero essere delle perdite rispetto alla quantita' caricata.\n" + + " N.B. al momento questa variabile viene acquisita solo per controllo in fase di debug\n" + + " */\n" + + " Select @lc_qtaProdScaricata = sum(dtb_doct.qta_prod*dtb_doct.rap_conv_prod * @lc_rapporto)\n" + + " From dtb_doct, \n" + + " dtb_tipi\n" + + " Where dtb_doct.cod_dtip = dtb_tipi.cod_dtip and\n" + + " dtb_tipi.gestione = 'L' and \n" + + " dtb_tipi.segno_qta_scar = 1 and\n" + + " dtb_doct.cod_prod = @as_codProd and\n" + + " ISNULL(dtb_doct.partita_mag, '') = ISNULL(@as_partitaMag, '')\n" + + " \n" + + "\n" + + " /* Acquisizione scarichi per prodotto-partita_mag */\n" + + " select @li_idRiga = 0;\n" + + " IF @as_codProd = @ls_codMiscela\n" + + " begin\n" + + " Select @ai_livello = @ai_livello+1\n" + + " end\n" + + " Declare csr_scarichi Cursor LOCAL SCROLL FOR\n" + + " Select PP_gruppiCostiMP.GruppoConto,\n" + + " dtb_docr.cod_mart, \n" + + " dtb_docr.partita_mag,\n" + + " dtb_docr.descrizione_estesa as descrizione,\n" + + " mtb_aart.unt_mis,\n" + + " sum(dtb_docr.qta_doc*dtb_docr.rap_conv*dtb_tipi.segno_qta_scar*@lc_rapporto) as Qta_mp\n" + + " From dtb_doct, \n" + + " dtb_docr, \n" + + " dtb_tipi, \n" + + " mtb_aart, \n" + + " mtb_grup, \n" + + " PP_gruppiCostiMP\n" + + " Where dtb_doct.cod_anag = dtb_docr.cod_anag and\n" + + " dtb_doct.cod_dtip = dtb_docr.cod_dtip and\n" + + " dtb_doct.data_doc = dtb_docr.data_doc and\n" + + " dtb_doct.ser_doc = dtb_docr.ser_doc and\n" + + " dtb_doct.num_doc = dtb_docr.num_doc and\n" + + " dtb_doct.cod_dtip = dtb_tipi.cod_dtip and\n" + + " dtb_tipi.gestione = 'L' and \n" + + " dtb_tipi.segno_qta_scar = 1 and\n" + + " dtb_docr.cod_mart = mtb_aart.cod_mart and\n" + + " mtb_aart.cod_mgrp = mtb_grup.cod_mgrp and\n" + + " dtb_docr.cod_mart = PP_gruppiCostiMP.cod_mart and\n" + + " dtb_doct.cod_prod = @as_codProd and\n" + + " ISNULL(dtb_doct.partita_mag, '') = ISNULL(@as_partitaMag, '')\n" + + " and NOT (dtb_docr.cod_mart = @as_codProd and ISNULL(dtb_docr.partita_mag, '') = ISNULL(@as_partitaMag, ''))\n" + + " group by PP_gruppiCostiMP.GruppoConto,\n" + + " dtb_docr.cod_mart, \n" + + " dtb_docr.partita_mag,\n" + + " dtb_docr.descrizione_estesa,\n" + + " mtb_aart.unt_mis\n" + + " union all\n" + + " \n" + + " Select PP_gruppiCostiMP.GruppoConto,\n" + + " car.cod_mart, \n" + + " car.partita_mag,\n" + + " car.descrizione_estesa as descrizione,\n" + + " mtb_aart.unt_mis,\n" + + " sum(car.qta_doc*car.rap_conv*dtb_tipi.segno_qta_scar*@lc_rapporto) as Qta_mp \n" + + " from dtb_doct inner join dtb_docr on dtb_doct.cod_anag = dtb_docr.cod_anag and\n" + + " dtb_doct.cod_dtip = dtb_docr.cod_dtip and\n" + + " dtb_doct.data_doc = dtb_docr.data_doc and\n" + + " dtb_doct.ser_doc = dtb_docr.ser_doc and\n" + + " dtb_doct.num_doc = dtb_docr.num_doc \n" + + " inner join dtb_tipi on dtb_doct.cod_dtip = dtb_tipi.cod_dtip \n" + + " inner join dtb_docr car on dtb_doct.activity_id = car.activity_id_row \n" + + " inner join dtb_tipi tipo_car on car.cod_dtip = tipo_car.cod_dtip\n" + + " inner join olvw_caratteristiche on car.cod_mart = olvw_caratteristiche.cod_mart\n" + + " inner join PP_gruppiCostiMP on car.cod_mart = PP_gruppiCostiMP.cod_mart\n" + + " inner join mtb_aart on car.cod_mart = mtb_aart.cod_mart \n" + + " inner join mtb_grup on mtb_aart.cod_mgrp = mtb_grup.cod_mgrp \n" + + " where tipo_car.gestione = 'L' and \n" + + " tipo_car.segno_qta_car - tipo_car.segno_qta_scar < 0 and \n" + + " olvw_caratteristiche.Confezionato = 'S' and \n" + + " dtb_tipi.gestione = 'L' and \n" + + " dtb_tipi.segno_qta_scar = 1 and\n" + + " dtb_doct.cod_prod = @as_codProd and\n" + + " ISNULL(dtb_doct.partita_mag, '') = ISNULL(@as_partitaMag, '')\n" + + " and NOT (dtb_docr.cod_mart = @as_codProd and ISNULL(dtb_docr.partita_mag, '') = ISNULL(@as_partitaMag, '')) \n" + + " group by PP_gruppiCostiMP.GruppoConto,\n" + + " car.cod_mart, \n" + + " car.partita_mag,\n" + + " car.descrizione_estesa,\n" + + " mtb_aart.unt_mis\n" + + " Order by PP_gruppiCostiMP.GruppoConto desc \n" + + " \n" + + " OPEN csr_scarichi\n" + + " FETCH NEXT FROM csr_scarichi INTO @ls_gruppoConto, @ls_codMart, @ls_partitaMag, @ls_descrizione, @ls_untMis, @lc_qtaMP\n" + + " WHILE @@FETCH_STATUS = 0\n" + + " begin\n" + + " IF ABS(@lc_qtaMP) > 0.01\n" + + " Begin\n" + + " select @li_idRiga = @li_idRiga + 1;\n" + + " SELECT @ls_itemID = @as_item_id + '_' + REPLICATE('0', 5 - len(CONVERT(varchar(15), @li_idRiga))) + CONVERT(varchar(15), @li_idRiga); \n" + + "\n" + + " /* verifica esistenza scarico, Indica che siamo in presenza di un semilavorato/lotto */\n" + + " select @li_existDist = count(*)\n" + + " from dtb_doct, dtb_tipi\n" + + " where dtb_doct.cod_prod = @ls_codMart and partita_mag = @ls_partitaMag and \n" + + " dtb_doct.cod_dtip = dtb_tipi.cod_dtip and\n" + + " dtb_tipi.segno_qta_scar = 1 and \n" + + " dtb_doct.gestione = 'L'\n" + + " \n" + + " \n" + + " /* Materia prima */\n" + + " if @li_existDist = 0 or @@NESTLEVEL >= 30\n" + + " begin\n" + + " insert into @dettCosti \n" + + " select @ai_livello,\n" + + " @ls_itemID,\n" + + " @as_codProdParent, \n" + + " @as_partitaMagParent, \n" + + " @ac_qtaProdParent, \n" + + " @as_codProd, \n" + + " @as_partitaMag, \n" + + " @lc_qtaProdScaricata, \n" + + " @ls_gruppoConto, \n" + + " @ls_codMart, \n" + + " @ls_descrizione, \n" + + " @ls_partitaMag, \n" + + " @ls_untMis, \n" + + " @lc_qtaMP\n" + + " end\n" + + " else\n" + + " Begin\n" + + " /* Semilavorato */\n" + + " \n" + + " Select @ls_posizione_a = mtb_depo_posizioni.posizione \n" + + " from mtb_partita_mag, mtb_depo_posizioni \n" + + " where mtb_depo_posizioni.posizione = mtb_partita_mag.posizione and\n" + + " mtb_partita_mag.cod_mart = @as_codProd and partita_mag = @as_partitaMag and\n" + + " mtb_depo_posizioni.flag_silos_liquidi = 1;\n" + + " Select @ls_posizione_da = mtb_depo_posizioni.posizione \n" + + " from mtb_partita_mag, mtb_depo_posizioni \n" + + " where mtb_depo_posizioni.posizione = mtb_partita_mag.posizione and\n" + + " mtb_partita_mag.cod_mart = @ls_codMart and partita_mag = @ls_partitaMag and\n" + + " mtb_depo_posizioni.flag_silos_liquidi = 1;\n" + + "\n" + + " If @ls_posizione_da is not null and\n" + + " (ISNULL(@ls_posizione_da,'') <> ISNULL(@ls_posizione_a,00) or \n" + + " @ls_posizione_da is null or @ls_posizione_a is null or \n" + + " (@ai_livello <1 and @as_codProd = @ls_codMiscela) or \n" + + " (ISNULL(@ls_posizione_da,'') = ISNULL(@ls_posizione_a,00) and @as_codProd= @ls_codMiscela))\n" + + " --Questa insert serve per trattare l'olio che proviene da altro serbatoio come una materia prima a partire dal 2° livello di ricorsione\n" + + " Begin\n" + + " insert into @dettCosti \n" + + " select @ai_livello,\n" + + " @ls_itemID,\n" + + " @as_codProdParent, \n" + + " @as_partitaMagParent, \n" + + " @ac_qtaProdParent, \n" + + " @as_codProd, \n" + + " @as_partitaMag, \n" + + " @lc_qtaProdScaricata, \n" + + " @ls_gruppoConto, \n" + + " @ls_codMart, \n" + + " @ls_descrizione, \n" + + " @ls_partitaMag, \n" + + " @ls_untMis, \n" + + " @lc_qtaMP;\n" + + " End\n" + + " \n" + + " /*Ricorsione su semilavorato-partita_mag*/\n" + + " If ISNULL(@ls_posizione_da,'') = ISNULL(@ls_posizione_a,00) and @as_codProd <> @ls_codMiscela or \n" + + " @ls_posizione_da is null or @ls_posizione_a is null or \n" + + " (@ai_livello <1 and @as_codProd = @ls_codMiscela)\n" + + " --La ricorsione non avviene sugli olii provenienti da altro serbatoio e neanche nel caso di Miscele fittizie create nello stesso serbatoio dell'olio di provenienza in assenza di polmone\n" + + " insert into @dettCosti \n" + + " select costi.livello, \n" + + " costi.item_id,\n" + + " @as_codProdParent, \n" + + " @as_partitaMagParent,\n" + + " @ac_qtaProdParent,\n" + + " costi.cod_prod, \n" + + " costi.partita_mag, \n" + + " costi.qta_prod,\n" + + " costi.gruppo_conto, \n" + + " costi.conto, \n" + + " costi.descrizione_conto, \n" + + " costi.dettaglio_conto,\n" + + " costi.unt_mis, \n" + + " costi.qta_consumata \n" + + " from dbo.f_pp_consuntivo_prod_tracc(@as_codProdParent, @as_partitaMagParent, @ac_qtaProdParent, @ls_codMart, @ls_partitaMag, @lc_qtaMP, @ai_livello, @ls_itemID, @li_idRiga) costi\n" + + " \n" + + " \n" + + " end\n" + + " end\n" + + " FETCH NEXT FROM csr_scarichi INTO @ls_gruppoConto, @ls_codMart, @ls_partitaMag, @ls_descrizione, @ls_untMis, @lc_qtaMP\n" + + " end\n" + + " close csr_scarichi\n" + + " deallocate csr_scarichi\n" + + " return\n" + + "END"); + } + + @Override + public void down() throws Exception { + + } + +}