--01/11/2022
-- Prise en charge des nouveau champs dans l'audit du volontaire (bank accnt, etc)


CREATE OR REPLACE FUNCTION f_volontaire_audit()
  RETURNS trigger AS
$BODY$  BEGIN IF (TG_OP = 'DELETE') THEN INSERT INTO volontaire_audit
(
nvolontaire,
clanguemat,
netatcivil,
nrgpdstatus,
nprofession,
cvolontaire,
nprovenance,
cpaysnationalite,
cpaysresid,
dinscription,
ccivilite,
lnom,
lnomjf,
lnomusuel,
lprenom,
ladr1,
ladr2,
lcp,
llocalite,
dnaissance,
cidentitenat,
cpassport,
ltelpriv,
ltelbur,
lgsm,
lemail,
dfinwashout,
lcontactaccident,
bactif,
cusercre,
dcre,
cusermod,
dmod,
nidtype,
cid,
nmother,
nfather,
bisvolontaire,
nville,
ltelaccident,
bisreferrer,
cauditoperation,
caudituser,
dauditstamp,
naudit
)
VALUES
(
OLD.nvolontaire,
OLD.clanguemat,
OLD.netatcivil,
OLD.nrgpdstatus,
OLD.nprofession,
OLD.cvolontaire,
OLD.nprovenance,
OLD.cpaysnationalite,
OLD.cpaysresid,
OLD.dinscription,
OLD.ccivilite,
OLD.lnom,
OLD.lnomjf,
OLD.lnomusuel,
OLD.lprenom,
OLD.ladr1,
OLD.ladr2,
OLD.lcp,
OLD.llocalite,
OLD.dnaissance,
OLD.cidentitenat,
OLD.cpassport,
OLD.ltelpriv,
OLD.ltelbur,
OLD.lgsm,
OLD.lemail,
OLD.dfinwashout,
OLD.lcontactaccident,
OLD.bactif,
OLD.cusercre,
OLD.dcre,
OLD.cusermod,
OLD.dmod,
OLD.nidtype,
OLD.cid,
OLD.nmother,
OLD.nfather,
OLD.bisvolontaire,
OLD.nville,
OLD.ltelaccident,
OLD.bisreferrer,
OLD.lbank,
OLD.lswift ,
OLD.dsignrgpd,
OLD.bhealthy ,
 'D', user, now(), DEFAULT); RETURN OLD; ELSIF (TG_OP = 'UPDATE') THEN INSERT INTO volontaire_audit
(nvolontaire,
clanguemat,
netatcivil,
nrgpdstatus,
nprofession,
cvolontaire,
nprovenance,
cpaysnationalite,
cpaysresid,
dinscription,
ccivilite,
lnom,
lnomjf,
lnomusuel,
lprenom,
ladr1,
ladr2,
lcp,
llocalite,
dnaissance,
cidentitenat,
cpassport,
ltelpriv,
ltelbur,
lgsm,
lemail,
dfinwashout,
lcontactaccident,
bactif,
cusercre,
dcre,
cusermod,
dmod,
nidtype,
cid,
nmother,
nfather,
bisvolontaire,
nville,
ltelaccident,
bisreferrer,
lbank,
lswift,
dsignrgpd,
bhealthy,
cauditoperation,
caudituser,
dauditstamp,
naudit



)

VALUES (
NEW.nvolontaire,
NEW.clanguemat,
NEW.netatcivil,
NEW.nrgpdstatus,
NEW.nprofession,
NEW.cvolontaire,
NEW.nprovenance,
NEW.cpaysnationalite,
NEW.cpaysresid,
NEW.dinscription,
NEW.ccivilite,
NEW.lnom,
NEW.lnomjf,
NEW.lnomusuel,
NEW.lprenom,
NEW.ladr1,
NEW.ladr2,
NEW.lcp,
NEW.llocalite,
NEW.dnaissance,
NEW.cidentitenat,
NEW.cpassport,
NEW.ltelpriv,
NEW.ltelbur,
NEW.lgsm,
NEW.lemail,
NEW.dfinwashout,
NEW.lcontactaccident,
NEW.bactif,
NEW.cusercre,
NEW.dcre,
NEW.cusermod,
NEW.dmod,
NEW.nidtype,
NEW.cid,
NEW.nmother,
NEW.nfather,
NEW.bisvolontaire,
NEW.nville,
NEW.ltelaccident,
NEW.bisreferrer,
NEW.lbank,
NEW.lswift ,
NEW.dsignrgpd,
NEW.bhealthy ,
  'U', user, now(), DEFAULT); RETURN NEW;         ELSIF (TG_OP = 'INSERT') THEN

INSERT INTO volontaire_audit
(nvolontaire,
clanguemat,
netatcivil,
nrgpdstatus,
nprofession,
cvolontaire,
nprovenance,
cpaysnationalite,
cpaysresid,
dinscription,
ccivilite,
lnom,
lnomjf,
lnomusuel,
lprenom,
ladr1,
ladr2,
lcp,
llocalite,
dnaissance,
cidentitenat,
cpassport,
ltelpriv,
ltelbur,
lgsm,
lemail,
dfinwashout,
lcontactaccident,
bactif,
cusercre,
dcre,
cusermod,
dmod,
nidtype,
cid,
nmother,
nfather,
bisvolontaire,
nville,
ltelaccident,
bisreferrer,

lbank,
lswift,
dsignrgpd,
bhealthy,
cauditoperation,
caudituser,
dauditstamp,
naudit)

VALUES (
NEW.nvolontaire,
NEW.clanguemat,
NEW.netatcivil,
NEW.nrgpdstatus,
NEW.nprofession,
NEW.cvolontaire,
NEW.nprovenance,
NEW.cpaysnationalite,
NEW.cpaysresid,
NEW.dinscription,
NEW.ccivilite,
NEW.lnom,
NEW.lnomjf,
NEW.lnomusuel,
NEW.lprenom,
NEW.ladr1,
NEW.ladr2,
NEW.lcp,
NEW.llocalite,
NEW.dnaissance,
NEW.cidentitenat,
NEW.cpassport,
NEW.ltelpriv,
NEW.ltelbur,
NEW.lgsm,
NEW.lemail,
NEW.dfinwashout,
NEW.lcontactaccident,
NEW.bactif,
NEW.cusercre,
NEW.dcre,
NEW.cusermod,
NEW.dmod,
NEW.nidtype,
NEW.cid,
NEW.nmother,
NEW.nfather,
NEW.bisvolontaire,
NEW.nville,
NEW.ltelaccident,
NEW.bisreferrer,
NEW.lbank,
NEW.lswift ,
NEW.dsignrgpd,
NEW.bhealthy ,
  'U', user, now(), DEFAULT);
           RETURN NEW;         END IF;         RETURN NULL;   END; $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION f_volontaire_audit()
  OWNER TO postgres;
