Corretta funzione per estrazione articolo miscela
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user