return: date
lang: plpgsql
parameters:
  p0:
    type: text
    name: i_option
src: |
  DECLARE	
  	
  	_now_activite date;
  BEGIN
  	IF NOT EXISTS (SELECT * FROM activite.t_divers WHERE code = 'NOW') THEN
  		INSERT INTO activite.t_divers (code, texte, valeur, valeur_date, description, valeur2)
  		SELECT
  			'NOW',
  			'Date des derniers mouvements',
  			now_activite,
  			now_activite,	
  			'Date non modifiable',
  			''
  		FROM (SELECT MAX(date) AS now_activite FROM activite.p_mouvements_sejour WHERE est_mouvement_previsionnel <> '1') subview
  		WHERE 'NOW' NOT IN (SELECT code FROM activite.t_divers);
  	END IF;
  	IF i_option = 'FORCE' THEN
  		UPDATE activite.t_divers 
  		SET 
  			valeur_date = now_activite,
  			valeur = now_activite
  		FROM (SELECT MAX(date) AS now_activite FROM activite.p_mouvements_sejour WHERE est_mouvement_previsionnel <> '1') subview
  		WHERE code = 'NOW';
  	END IF;
  	
  	_now_activite = (SELECT valeur_date FROM activite.t_divers WHERE code = 'NOW');
  	
  	RETURN _now_activite;
  END;