1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
CREATE OR REPLACE FUNCTION gtc.migrationRemiseAPlatDesExercices()
RETURNS void
LANGUAGE plpgsql
AS
$body$
DECLARE
NOMBRE_MOIS_TENUE_ASS_GEN integer;
D_CONSO_CHAR varchar(10) =null;
D_SOCIAUX_CHAR varchar(10)= null;
D_SOCIAUX date = null;
D_CONSO date = null ;
D_DEBUT date = null;
D_FIN date = null;
TOP_SOCIAUX boolean = null;
DELAI_DEPOSE integer = null;
TOP_PP boolean =null;
TOP_CONSO boolean =null;
-- récupérer DELAI_AG depuis la table p_parametre
DELAI_AG CURSOR FOR select valeur from p_parametre where code_domaine='BIL' and code_sous_domaine='RELANCE' and cle='DELAI_TENUE_AG' and chrono=0;
DELAI integer =2;
-- declaration dun cursor pour la selection des registres
registre CURSOR FOR SELECT * FROM gtc.r_registre;
resultatRegistre RECORD; -- Le resultat de la selection des registres
id_registre integer;
--D_SOCIAUX CURSOR FOR SELECT cloture FROM r_societe WHERE identifiant_registre=registre.identifiant;
BEGIN
OPEN registre; -- ouvrir le cursor
LOOP
FETCH registre INTO resultatRegistre; -- fetch une ligne de registre dans un record
EXIT WHEN NOT FOUND; -- Plus rien a lire alors quitter la boucle
id_registre := resultatRegistre.identifiant;
-- si statut = A, I, ACP : on enchaine sur "Traitement dossier PP"
IF(registre.code_statut == 'A' || registre.code_statut =='I' || registre.code_statut=='ACP') THEN
RAISE NOTICE ' TRAITEMENT PERSONNE PHYSIQUE';
-- sinon si statut = B, C, D : on enchaine sur "Traitement dossier PM"
ELSEIF (registre.code_statut =='B' || registre.code_statut=='C' || registre.code_statut=='D') THEN
RAISE NOTICE ' TRAITEMENT PERSONNE MORALE';
TOP_PP = false;
IF ( EXISTS (SELECT * FROM r_personne_morale , r_societe WHERE r_personne_morale.identifiant = r_societe.identifiant_personne_morale AND identifiant_registre=registre.identifiant AND code_forme_juridique in(select code from t_forme_juridique where indic_obligation_depot=true))) THEN
TOP_SOCIAUX = true;
ELSEIF( EXISTS (SELECT * FROM r_relance_parametre , r_societe WHERE r_relance_parametre.identifiant = r_societe.identifiant_relance_parametre AND identifiant_registre=registre.identifiant AND indic_obligation_depot = true)) THEN
TOP_SOCIAUX = true;
ELSEIF( EXISTS (SELECT * FROM r_relance_parametre , r_societe WHERE r_relance_parametre.identifiant = r_societe.identifiant_relance_parametre AND identifiant_registre=registre.identifiant AND indic_depot_consolide = true)) THEN
TOP_CONSO = true;
END IF;
IF(TOP_SOCIAUX == false) THEN
IF ( EXISTS (SELECT * FROM r_exercice WHERE identifiant_registre= registre.identifiant AND code_type_comptes ='S')) THEN
TOP_SOCIAUX = true;
END IF;
IF(TOP_CONSO == false) THEN
IF (EXISTS (SELECT * FROM r_exercice WHERE identifiant_registre= registre.identifiant AND code_type_comptes ='C')) THEN
TOP_CONSO = true;
END IF;
/*
D_SOCIAUX =SELECT cloture FROM r_societe WHERE identifiant_registre=registre.identifiant;
D_CONSO= SELECT cloture FROM r_societe WHERE identifiant_registre=registre.identifiant;
D_FIN = SELECT date_radiation FROM r_registre WHERE identifiant_registre=registre.identifiant;
*/
IF(D_SOCIAUX ==null) THEN
IF(EXISTS(SELECT * FROM r_exercice,r_registre WHERE r_exercice.identifiant =r_registre.identifiant AND code_type_comptes='S' AND r_exercice.date_cloture IS NOT NULL AND r_exercice.date_cloture =(SELECT MAX(date_cloture) FROM r_exercice,r_registre WHERE r_exercice.identifiant =r_registre.identifiant AND code_type_comptes='S')))THEN
D_SOCIAUX_CHAR = to_char(D_SOCIAUX,'dd/YYYY');
END IF;
END IF;
-- Si TOP_CONSO = vrai et D_CONSO est nulle
IF(TOP_CONSO == true AND D_CONSO == null) THEN
IF(EXISTS(SELECT * FROM r_exercice,r_registre WHERE r_exercice.identifiant =r_registre.identifiant AND code_type_comptes='C' AND r_exercice.date_cloture IS NOT NULL AND r_exercice.date_cloture =(SELECT MAX(date_cloture) FROM r_exercice,r_registre WHERE r_exercice.identifiant =r_registre.identifiant AND code_type_comptes='S')))THEN
D_CONSO_CHAR = to_char(D_CONSO,'dd/YYYY');
ELSE
D_CONSO_CHAR = D_SOCIAUX_CHAR;
END IF;
END IF;
NOMBRE_MOIS_TENUE_ASS_GEN = (SELECT nombre_mois_tenue_assemblee_generale FROM r_relance_parametre,r_societe WHERE r_relance_parametre.identifiant=r_societe.identifiant_relance_parametre AND r_societe.identifiant_registre=registre.identifiant AND nombre_mois_tenue_assemblee_generale IS NOT NULL AND nombre_mois_tenue_assemblee_generale!=0);
IF(NOMBRE_MOIS_TENUE_ASS_GEN != NULL AND NOMBRE_MOIS_TENUE_ASS_GEN !=0 ) THEN
DELAI = DELAI + NOMBRE_MOIS_TENUE_ASS_GEN;
ELSE
DELAI = DELAI + DELAI_AG ;
END IF;
IF(TOP_SOCIAUX == true AND D_SOCIAUX !=NULL ) THEN
-- on enchaine sur "Traitement série exercice" pour SOCIAUX
ELSEIF(TOP_CONSO == true AND D_CONSO != NULL) THEN
--on enchaine sur "Traitement série exercice" pour CONSO
END IF;
END IF;
END IF ;
END IF ;
END LOOP; --fin boucle externe
CLOSE registre; -- fermer le cursor
RETURN;
END;
$body$
VOLATILE
COST 100;
COMMIT; |
Partager