Merge branch 'develop' into feature/JDK11
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit

This commit is contained in:
jenkins
2025-04-07 18:04:57 +02:00

View File

@@ -0,0 +1,178 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20250407154810 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
createOrUpdateTrigger("t_UpdProgPart", "CREATE TRIGGER [dbo].[t_UpdProgPart] ON [dbo].[ctb_parr] AFTER INSERT,UPDATE, DELETE\n" +
"AS \n" +
"BEGIN\t\n" +
"\tIF EXISTS (SELECT * FROM deleted)\n" +
"\tBEGIN\n" +
"\t\t--storno progressivi\n" +
"\t\tupdate ctb_part\n" +
"\t\t set ctb_part.dare_part = ctb_part.dare_part - tmp.dare_part,\n" +
"\t\t\t ctb_part.avere_part = ctb_part.avere_part - tmp.avere_part\n" +
"\t\t from ctb_part,\n" +
"\t\t\t ( select deleted.tipo_anag, \n" +
"\t\t\t\t\t\tdeleted.cod_anag, \n" +
"\t\t\t\t\t\tdeleted.anno_part, \n" +
"\t\t\t\t\t\tdeleted.ser_doc, \n" +
"\t\t\t\t\t\tdeleted.num_doc,\n" +
"\t\t\t\t\t\t(round(SUM((deleted.imp_dare/deleted.cambio_divi_cont) * ctb_part.cambio_divi_cont),gtb_divi.cifre_dec)) as dare_part,\n" +
"\t\t\t\t\t\t(round(SUM((deleted.imp_avere/deleted.cambio_divi_cont) * ctb_part.cambio_divi_cont),gtb_divi.cifre_dec)) as avere_part\n" +
"\t\t\t\t FROM deleted, ctb_part, gtb_divi\n" +
"\t\t\t\t where ctb_part.tipo_anag = deleted.tipo_anag AND\n" +
"\t\t\t\t\t\tctb_part.cod_anag = deleted.cod_anag AND\n" +
"\t\t\t\t\t\tctb_part.anno_part = deleted.anno_part AND\n" +
"\t\t\t\t\t\tctb_part.ser_doc = deleted.ser_doc AND\n" +
"\t\t\t\t\t\tctb_part.num_doc = deleted.num_doc and\n" +
"\t\t\t\t\t\tctb_part.cod_divi_cont = gtb_divi.cod_divi\n" +
"\t\t\t\tGROUP BY deleted.tipo_anag, \n" +
"\t\t\t\t\t\tdeleted.cod_anag, \n" +
"\t\t\t\t\t\tdeleted.anno_part, \n" +
"\t\t\t\t\t\tdeleted.ser_doc, \n" +
"\t\t\t\t\t\tdeleted.num_doc,\n" +
"\t\t\t\t\t\tgtb_divi.cifre_dec) tmp\n" +
"\t where ctb_part.tipo_anag = tmp.tipo_anag AND\n" +
"\t\t\t ctb_part.cod_anag = tmp.cod_anag AND\n" +
"\t\t\t ctb_part.anno_part = tmp.anno_part AND\n" +
"\t\t\t ctb_part.ser_doc = tmp.ser_doc AND\n" +
"\t\t\t ctb_part.num_doc = tmp.num_doc \n" +
"\tEND\n" +
"\t\t\n" +
"\tIF EXISTS (SELECT * FROM inserted)\n" +
"\tBEGIN\t\t\n" +
"\t\tupdate ctb_part\n" +
"\t\t set ctb_part.dare_part = ctb_part.dare_part + tmp.dare_part,\n" +
"\t\t\t ctb_part.avere_part = ctb_part.avere_part + tmp.avere_part\n" +
"\t\t from ctb_part,\n" +
"\t\t\t ( select inserted.tipo_anag, \n" +
"\t\t\t\t\t\tinserted.cod_anag, \n" +
"\t\t\t\t\t\tinserted.anno_part, \n" +
"\t\t\t\t\t\tinserted.ser_doc, \n" +
"\t\t\t\t\t\tinserted.num_doc,\n" +
"\t\t\t\t\t\t(round(SUM((inserted.imp_dare/inserted.cambio_divi_cont) * ctb_part.cambio_divi_cont),gtb_divi.cifre_dec)) as dare_part,\n" +
"\t\t\t\t\t\t(round(SUM((inserted.imp_avere/inserted.cambio_divi_cont) * ctb_part.cambio_divi_cont),gtb_divi.cifre_dec)) as avere_part\n" +
"\t\t\t\t FROM inserted, ctb_part, gtb_divi\n" +
"\t\t\t\t where ctb_part.tipo_anag = inserted.tipo_anag AND\n" +
"\t\t\t\t\t\tctb_part.cod_anag = inserted.cod_anag AND\n" +
"\t\t\t\t\t\tctb_part.anno_part = inserted.anno_part AND\n" +
"\t\t\t\t\t\tctb_part.ser_doc = inserted.ser_doc AND\n" +
"\t\t\t\t\t\tctb_part.num_doc = inserted.num_doc and\n" +
"\t\t\t\t\t\tctb_part.cod_divi_cont = gtb_divi.cod_divi\n" +
"\t\t\t\t\tGROUP BY inserted.tipo_anag, \n" +
"\t\t\t\t\t\tinserted.cod_anag, \n" +
"\t\t\t\t\t\tinserted.anno_part, \n" +
"\t\t\t\t\t\tinserted.ser_doc, \n" +
"\t\t\t\t\t\tinserted.num_doc,\n" +
"\t\t\t\t\t\tgtb_divi.cifre_dec) tmp\n" +
"\t where ctb_part.tipo_anag = tmp.tipo_anag AND\n" +
"\t\t\t ctb_part.cod_anag = tmp.cod_anag AND\n" +
"\t\t\t ctb_part.anno_part = tmp.anno_part AND\n" +
"\t\t\t ctb_part.ser_doc = tmp.ser_doc AND\n" +
"\t\t\t ctb_part.num_doc = tmp.num_doc \n" +
"\n" +
"\tEND\t\n" +
"END");
createOrUpdateTrigger("t_UpdProgScad", "CREATE TRIGGER [dbo].[t_UpdProgScad] ON [dbo].[ctb_scad] AFTER INSERT,UPDATE, DELETE\n" +
"AS \n" +
"\tBEGIN\n" +
"\n" +
"\t\t--AGGIORNA SALDO SCADENZE\n" +
"\t\tupdate ctb_part\n" +
"\t\t set ctb_part.dare_scad = scadenze.imp_dare,\n" +
"\t\t\t ctb_part.avere_scad = scadenze.imp_avere\n" +
"\t\t from ctb_part, \n" +
"\t\t\t (select tmp.tipo_anag, \n" +
"\t\t\t\t\t tmp.cod_anag, \n" +
"\t\t\t\t\t tmp.anno_part, \n" +
"\t\t\t\t\t tmp.ser_doc, \n" +
"\t\t\t\t\t tmp.num_doc ,\n" +
"\t\t\t\t\t sum(ctb_scad.imp_dare) as imp_dare, \n" +
"\t\t\t\t\t sum(ctb_scad.imp_avere)\tas imp_avere \n" +
"\t\t\t\t from ctb_scad, \n" +
"\t\t\t\t\t ( SELECT tipo_anag,\n" +
"\t\t\t\t\t\t\t cod_anag,\n" +
"\t\t\t\t\t\t\t anno_part,\n" +
"\t\t\t\t\t\t\t ser_doc,\n" +
"\t\t\t\t\t\t\t num_doc\n" +
"\t\t\t\t\t\tfrom inserted \n" +
"\t\t\t\t\t\tunion \n" +
"\t\t\t\t\t\tSELECT tipo_anag,\n" +
"\t\t\t\t\t\t\t cod_anag,\n" +
"\t\t\t\t\t\t\t anno_part,\n" +
"\t\t\t\t\t\t\t ser_doc,\n" +
"\t\t\t\t\t\t\t num_doc\n" +
"\t\t\t\t\t\tfrom deleted ) tmp\n" +
"\t where ctb_scad.tipo_anag = tmp.tipo_anag AND\n" +
"\t\t\t ctb_scad.cod_anag = tmp.cod_anag AND\n" +
"\t\t\t ctb_scad.anno_part = tmp.anno_part AND\n" +
"\t\t\t ctb_scad.ser_doc = tmp.ser_doc AND\n" +
"\t\t\t ctb_scad.num_doc = tmp.num_doc \n" +
"\t group by tmp.tipo_anag, \n" +
"\t\t\t\t\t tmp.cod_anag, \n" +
"\t\t\t\t\t tmp.anno_part, \n" +
"\t\t\t\t\t tmp.ser_doc, \n" +
"\t\t\t\t\t tmp.num_doc ) scadenze\n" +
"\t where ctb_part.tipo_anag = scadenze.tipo_anag AND\n" +
"\t\t\t ctb_part.cod_anag = scadenze.cod_anag AND\n" +
"\t\t\t ctb_part.anno_part = scadenze.anno_part AND\n" +
"\t\t\t ctb_part.ser_doc = scadenze.ser_doc AND\n" +
"\t\t\t ctb_part.num_doc = scadenze.num_doc ;\t\t\n" +
"\n" +
"\n" +
"\t\tIF EXISTS (SELECT * FROM deleted)\n" +
"\t\tBEGIN\n" +
"\t\tupdate ctb_titoli\n" +
"\t\t set ctb_titoli.importo_evaso = ctb_titoli.importo_evaso - tmp.importo\n" +
"\t\t from ctb_titoli,\t\t\t \n" +
"\t\t\t ( select deleted.cod_anag, \n" +
"\t\t\t\t\t\tdeleted.id_titolo,\n" +
"\t\t\t\t\t\tSUM(case ctb_part.tipo_partita when 1 then deleted.imp_dare when 0 then-deleted.imp_avere end) as importo\n" +
"\t\t\t\t FROM deleted, ctb_part\n" +
"\t\t\t\t WHERE deleted.id_titolo is not null and\n" +
"\t\t\t\t\t\tctb_part.tipo_anag = deleted.tipo_anag and \n" +
"\t\t\t\t\t\tctb_part.cod_anag = deleted.cod_anag and \n" +
"\t\t\t\t\t\tctb_part.anno_part = deleted.anno_part and \n" +
"\t\t\t\t\t\tctb_part.ser_doc = deleted.ser_doc and \n" +
"\t\t\t\t\t\tctb_part.num_doc = deleted.num_doc\n" +
"\t\t\t group by deleted.cod_anag, \n" +
"\t\t\t\t\t\tdeleted.id_titolo ) tmp\t\t\n" +
"\t where ctb_titoli.cod_anag = tmp.cod_anag AND\n" +
"\t\t\t ctb_titoli.id_titolo = tmp.id_titolo\n" +
"\tEND\n" +
"\t\t\n" +
"\tIF EXISTS (SELECT * FROM inserted)\n" +
"\tBEGIN\n" +
"\t\tupdate ctb_titoli\n" +
"\t\t set ctb_titoli.importo_evaso = ctb_titoli.importo_evaso + tmp.importo\n" +
"\t\t from ctb_titoli,\t\t\t \n" +
"\t\t\t ( select inserted.cod_anag, \n" +
"\t\t\t\t\t\tinserted.id_titolo,\n" +
"\t\t\t\t\t\tSUM(case ctb_part.tipo_partita when 1 then inserted.imp_dare when 0 then-inserted.imp_avere end) as importo\n" +
"\t\t\t\t FROM inserted, ctb_part\n" +
"\t\t\t\t WHERE inserted.id_titolo is not null and\n" +
"\t\t\t\t\t\tctb_part.tipo_anag = inserted.tipo_anag and \n" +
"\t\t\t\t\t\tctb_part.cod_anag = inserted.cod_anag and \n" +
"\t\t\t\t\t\tctb_part.anno_part = inserted.anno_part and \n" +
"\t\t\t\t\t\tctb_part.ser_doc = inserted.ser_doc and \n" +
"\t\t\t\t\t\tctb_part.num_doc = inserted.num_doc\n" +
"\t\t\t group by inserted.cod_anag, \n" +
"\t\t\t\t\t\tinserted.id_titolo ) tmp\t\t\n" +
"\t where ctb_titoli.cod_anag = tmp.cod_anag AND\n" +
"\t\t\t ctb_titoli.id_titolo = tmp.id_titolo\n" +
"\tEND\n" +
"END");
}
@Override
public void down() throws Exception {
}
}