sistemata GetSaldoContoAnalitico
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-07-04 12:06:15 +02:00
parent a023f429a2
commit 2574e37e9a

View File

@@ -0,0 +1,59 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20250704120543 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createOrUpdateFunction("[GetSaldoContoAnalitico]", "CREATE FUNCTION [dbo].[GetSaldoContoAnalitico]\n" +
"( \n" +
" @codCcon varchar(6), @codAnag varchar(5), @dataFine datetime\n" +
")\n" +
"RETURNS TABLE \n" +
"AS\n" +
"RETURN \n" +
"( \n" +
"with periodo_fisc as (\n" +
"select anno\n" +
"from gtb_periodo_fisc\n" +
"where IsNull(@dataFine, CAST(getDate() as date)) between data_iniz and data_fine )\n" +
",mov as (\n" +
"SELECT ctb_movr.cod_ccon, \n" +
" ctb_movr.cod_anag, \n" +
" Sum(imp_dare - imp_avere) as importo_mov \n" +
" FROM ctb_movt\n" +
" inner join ctb_movr on ctb_movt.num_cmov = ctb_movr.num_cmov\n" +
" inner join ctb_caus on ctb_movt.cod_ccau = ctb_caus.cod_ccau,\n" +
" (select * from gtb_periodo_fisc inner join azienda on gtb_periodo_fisc.anno = azienda.anno_contab ) periodo\n" +
" WHERE ctb_caus.flag_ap_ch = 'N' AND\n" +
" ctb_movt.data_cmov BETWEEN periodo.data_iniz AND IsNull(@dataFine, CAST(getDate() as date)) AND\n" +
" (@codCcon is null or ctb_movr.cod_ccon = @codCcon ) AND\n" +
" (@codAnag is null OR ctb_movr.cod_anag = @codAnag ) \n" +
" group by ctb_movr.cod_ccon, ctb_movr.cod_anag\n" +
")\n" +
"\n" +
" SELECT IsNull(ctb_sana.cod_ccon, mov.cod_ccon) as cod_ccon, \n" +
" IsNull(ctb_sana.cod_anag, mov.cod_anag) as cod_anag, \n" +
" sum(IsNull(saldo_iniz, 0) + ISNULL(mov.importo_mov, 0)) as saldo\n" +
" FROM ctb_sana \n" +
" inner join azienda ON ctb_sana.anno = azienda.anno_contab \n" +
" full outer join mov on ctb_sana.cod_ccon = mov.cod_ccon and IsNull(ctb_sana.cod_anag, '') = IsNull(mov.cod_anag, '')\n" +
" WHERE (@codCcon is null or ctb_sana.cod_ccon = @codCcon ) AND\n" +
" (@codAnag is null or ctb_sana.cod_anag = @codAnag)\n" +
" group by IsNull(ctb_sana.cod_ccon, mov.cod_ccon), \n" +
" IsNull(ctb_sana.cod_anag, mov.cod_anag) \n" +
" )");
}
@Override
public void down() throws Exception {
}
}