Skip to content
Snippets Groups Projects
Commit 5640231c authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Modification du message pour un code utilisateur déjà utilisé

parent 5b14029d
No related branches found
No related tags found
No related merge requests found
CREATE OR REPLACE TRIGGER "INTERVENANT_CK"
BEFORE INSERT OR UPDATE OF source_id, source_code, histo_destruction, code, statut_id, utilisateur_code ON intervenant
CREATE
OR REPLACE TRIGGER "INTERVENANT_CK"
BEFORE INSERT OR
UPDATE of source_id, source_code, histo_destruction, code, statut_id, utilisateur_code
ON intervenant
FOR EACH ROW
DECLARE
pragma autonomous_transaction;
imp NUMERIC;
cs NUMERIC;
imp
NUMERIC;
cs
NUMERIC;
BEGIN
IF :NEW.histo_destruction IS NOT NULL THEN
IF
:NEW.histo_destruction IS NOT NULL THEN
RETURN;
END IF;
SELECT importable INTO imp FROM source WHERE id = :NEW.SOURCE_ID;
IF imp = 1 THEN
SELECT importable
INTO imp
FROM source
WHERE id = :new.source_id;
IF
imp = 1 THEN
-- Contrôle du bon remplissage du source_code
IF :NEW.source_code IS NULL THEN
......@@ -21,25 +31,33 @@ BEGIN
END IF;
-- Contrôle de l'unicité de STATUT_ID
SELECT COUNT(*) INTO cs FROM INTERVENANT WHERE
id <> :NEW.id AND histo_destruction IS NULL
AND code = :NEW.code
AND annee_id = :NEW.annee_id
AND statut_id = :NEW.statut_id
SELECT COUNT(*)
INTO cs
FROM intervenant
WHERE id <> :new.id
AND histo_destruction IS NULL
AND code = :new.code
AND annee_id = :new.annee_id
AND statut_id = :new.statut_id
;
IF cs > 0 THEN
IF
cs > 0 THEN
raise_application_error(-20101, 'Un intervenant ne peut pas avoir deux fois le même statut le même année');
END IF;
-- On ne peut pas assicoer un même login à plusieurs intervenants
SELECT COUNT(*) INTO cs FROM INTERVENANT WHERE
id <> :NEW.id AND histo_destruction IS NULL
AND code <> :NEW.code
AND annee_id = :NEW.annee_id
AND utilisateur_code = :NEW.utilisateur_code
SELECT COUNT(*)
INTO cs
FROM intervenant
WHERE id <> :new.id
AND histo_destruction IS NULL
AND code <> :new.code
AND annee_id = :new.annee_id
AND utilisateur_code = :new.utilisateur_code
;
IF cs > 0 THEN
raise_application_error(-20101, 'L''utilisateur est déjà utilisé pour un autre intervenant. Merci d''en choisir un autre.');
IF
cs > 0 THEN
raise_application_error(-20101, 'L''utilisateur est déjà utilisé pour un autre intervenant. Merci d''en choisir un autre.' || ' Pour le nouveau dossier ID: '|| :NEW.id|| ', Code: '|| :NEW.code || ', utilisateur_code: '||:NEW.utilisateur_code );
END IF;
END;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment