aggiunta migrazione per la funzione ftx_calcCostoProd aggiunti nuovi campi per slim2k
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-09-18 17:37:32 +02:00
parent 29963759f2
commit 4dedea79cf

View File

@@ -0,0 +1,82 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20250918173720 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createOrUpdateFunction("[getNumDoc4NumDocForn]", "-- =============================================\n" +
"-- Author: <Author,,Name>\n" +
"-- Create date: <Create Date,,>\n" +
"-- Description: <Description,,>\n" +
"-- =============================================\n" +
"CREATE FUNCTION [dbo].[getNumDoc4NumDocForn]\n" +
"( \n" +
" @numdocorig varchar(60), @annoComp varchar(4)\n" +
")\n" +
"\n" +
"RETURNS @numTable TABLE \n" +
"(\n" +
" num_doc_orig varchar(max), num_doc int\n" +
")\n" +
"AS\n" +
"BEGIN\n" +
" \n" +
" declare @sep varchar(5), @numDoc varchar(60), @rowc int, @numDocForn varchar(60)\n" +
"\n" +
" select @numDocForn = LTRIM(RTRIM(@numdocOrig))\n" +
"\n" +
" declare @tmpChar table (sep varchar(5));\n" +
" declare @splitString table (numOrig varchar(60), numNew varchar(60), is_numeric int);\n" +
"\n" +
" SET @numDocForn = REPLACE(@numDocForn, '-', ',');\n" +
" SET @numDocForn = REPLACE(@numDocForn, '.', ',');\n" +
" SET @numDocForn = REPLACE(@numDocForn, ' ', ',');\n" +
" SET @numDocForn = REPLACE(@numDocForn, '/', ',');\n" +
" SET @numDocForn = REPLACE(@numDocForn, '', ',');\n" +
" \n" +
" ;with tab_p as (\n" +
" select value_string as num_new, \n" +
" COUNT(*) over (partition by (select 1)) as tot_row, \n" +
" ROW_NUMBER() over (order by (select 1)) as id,\n" +
" LEN(value_string) as lunghezza\n" +
" from dbo.parseStringIntoArray(@numDocForn, ',')\n" +
" where ISNUMERIC(value_string) = 1 )\n" +
"\n" +
" \n" +
" \n" +
" insert into @numTable\n" +
" select @numdocOrig as num_doc_forn, try_cast(num_new as int ) as num_doc\n" +
" from (\n" +
" select * from tab_p ) t\n" +
" where (tot_row = 1 or (tot_row > 1 AND \n" +
" num_new <> cast(@annoComp as varchar) and\n" +
" num_new <> cast(right(@annoComp,2) as varchar) )) AND \n" +
" try_cast(num_new as int ) is not null \n" +
" union \n" +
" select @numdocOrig, @numDocForn\n" +
" where not exists (select * from tab_p) and TRY_CAST(@numDocForn as int) is not null\n" +
" union \n" +
" select @numdocOrig, TRY_CAST(Right(@numDocForn,6) as int)\n" +
" where TRY_CAST(Right(@numDocForn,6) as int) is not null\n" +
" and not exists (select * from tab_p)\n" +
" and TRY_CAST(@numDocForn as int) is null \n" +
" \n" +
" \n" +
"\n" +
" RETURN \n" +
"END");
}
@Override
public void down() throws Exception {
}
}