diff --git a/core/class/class_alert_engine.php b/core/class/class_alert_engine.php
deleted file mode 100755
index 29b7b10da0d6fab42cc6b0b1cfd8cf621a4c3bd3..0000000000000000000000000000000000000000
--- a/core/class/class_alert_engine.php
+++ /dev/null
@@ -1,195 +0,0 @@
-<?php
-/**
-* alert_engine Class
-*
-* Contains all the specific functions of the diff engine
-* @package  core
-* @version 1.0
-* @since 10/2005
-* @license GPL
-* @author  Laurent Giovannoni  <dev@maarch.org>
-*/
-class alert_engine extends Database
-{
-    /**
-    * Redefinition of the alert_engine object constructor
-    */
-    function __construct()
-    {
-	   $args = func_get_args();
-	
-       if (count($args) < 1) parent::__construct();
-	
-       else parent::__construct($args[0]);
-    }
-
-    /**
-    *  Allow to know when the next Easter come
-    *
-    * @param date $year
-    */
-    public function WhenEasterCelebrates($year = null)
-    {
-        if (is_null($year))
-        {
-            $year = (int)date ('Y');
-        }
-        $iN = $year - 1900;
-        $iA = $iN%19;
-        $iB = floor (((7*$iA)+1)/19);
-        $iC = ((11*$iA)-$iB+4)%29;
-        $iD = floor ($iN/4);
-        $iE = ($iN-$iC+$iD+31)%7;
-        $time = 25-$iC-$iE;
-        if($time > 0)
-        {
-            $WhenEasterCelebrates = strtotime ($year.'/04/'.$time);
-        }
-        else
-        {
-            $WhenEasterCelebrates = strtotime ($year.'/03/'.(31+$time));
-        }
-        return $WhenEasterCelebrates;
-    }
-
-    /**
-    *  Allow to know when the next open day come
-    *
-    * @param date $Date in timestamp format
-    * @param int $Delta
-    * @param boolean $isMinus
-    */
-    public function WhenOpenDay($Date, $Delta, $isMinus = false, $calendarType = null)
-    { 
-        if ($calendarType <> 'calendar' && $calendarType <> 'workingDay') {
-            $calendarType = $_SESSION['features']['type_calendar'];
-        }
-
-        if (empty($calendarType)) {
-            $calendarType = 'workingDay';
-        }
-
-        if($calendarType == 'calendar') {
-            if ($isMinus) {
-                return date('Y-m-d H:i:s', $Date + (86400*-$Delta));
-            } else {
-                return date('Y-m-d H:i:s', $Date + (86400*$Delta));
-            }
-        } elseif($calendarType == 'workingDay') {
-            $Hollidays = array (
-                '1_1',
-                '1_5',
-                '8_5',
-                '14_7',
-                '15_8',
-                '1_11',
-                '11_11',
-                '25_12'
-            );
-            
-            //TODO: Case to erase because not used
-            if (!empty($_SESSION['features']['type_calendar'])) {
-                require_once 'core/class/class_db_pdo.php';
-                $db = new Database();
-                $stmt = $db->query("select * from parameters where id like 'alert_stop%'");
-                while ($result = $stmt->fetchObject()) {
-                    if ($result->param_value_date <> '') {
-                        $compare = $this->compare_date($result->param_value_date, date("d-m-Y"));
-                        //take the alert stop only if > now
-                        if ($compare == 'date1' || $compare == 'equal') {
-                            $dateExploded = explode("-", str_replace(" 00:00:00", "", $result->param_value_date));
-                            array_push($Hollidays, (int)$dateExploded[2] . "_" . (int)$dateExploded[1]);
-                        }
-                    }
-                }
-            }
-            
-            //var_dump($Hollidays);
-            
-            if (function_exists ('easter_date')) {
-                $WhenEasterCelebrates = easter_date((int)date('Y'), $Date);
-            } else {
-                $WhenEasterCelebrates = $this->getEaster((int)date('Y'), $Date);
-            }
-            $Hollidays[] = date ('j_n', $WhenEasterCelebrates);
-            $Hollidays[] = date ('j_n', $WhenEasterCelebrates + (86400*39));
-            $Hollidays[] = date ('j_n', $WhenEasterCelebrates + (86400*49));
-            $iEnd = $Delta * 86400;
-
-            $i = 0;
-            while ($i < $iEnd) {
-                $i = strtotime ('+1 day', $i);
-                if ($isMinus) {
-                    if (in_array(
-                        date('w', $Date-$i),array (0,6)
-                    ) || in_array (date ('j_n', $Date-$i), $Hollidays)
-                    ) {
-                        $iEnd = strtotime ('+1 day', $iEnd);
-                        $Delta ++;
-                    }
-                } else {
-                    if (
-                        in_array(
-                            date('w', $Date+$i),array (0,6)
-                        ) || in_array (date ('j_n', $Date+$i), $Hollidays)
-                    ) {
-                        $iEnd = strtotime ('+1 day', $iEnd);
-                        $Delta ++;
-                    }
-                }
-            }
-            if ($isMinus) {
-                return date('Y-m-d H:i:s', $Date + (86400*-$Delta));
-            } else {
-                return date('Y-m-d H:i:s', $Date + (86400*$Delta));
-            }
-        }      
-
-    }
-
-    /**
-    *  Allow to know the next date to treat
-    *
-    * @param int $delay Delay in days
-    * @param boolean $isMinus true if minus
-    */
-    public function date_max_treatment($delay, $isMinus = false)
-    {
-        $result = $this->WhenOpenDay(
-             strtotime (strftime("%Y")."-".strftime("%m")."-".strftime("%d")), 
-            $delay, 
-            $isMinus
-        );
-        return $result;
-    }
-    
-    /**
-    *  Allow to know the next date to treat
-    *
-    * @param int $delay Delay in days
-    * @param boolean $isMinus true if minus
-    */
-    public function processDelayDate($date, $delay, $isMinus = false)
-    {
-        $date = date('Y-m-d', $date);
-        $result = $this->WhenOpenDay(
-            $date, 
-            $delay, 
-            $isMinus
-        );
-        return $result;
-    }
-    
-    function dateFR2Time($date, $addHours = false)
-    {
-        if($addHours == false){
-        list($day, $month, $year) = explode('/', $date);
-        $timestamp = mktime(0, 0, 0, $month, $day, $year);
-        return $timestamp;
-        }elseif($addHours == true){
-        list($day, $month, $year) = explode('/', $date);
-        $timestamp = mktime(23, 59, 59, $month, $day, $year);
-        return $timestamp;   
-        }
-    }
-}
diff --git a/modules/notifications/batch/LoggerLog4php.php b/modules/notifications/batch/LoggerLog4php.php
deleted file mode 100755
index 900b13489c94f5e461aa96db89b1a0808cfffa6a..0000000000000000000000000000000000000000
--- a/modules/notifications/batch/LoggerLog4php.php
+++ /dev/null
@@ -1,314 +0,0 @@
-<?php
-
-/** Logger class
- *
- * @author Laurent Giovannoni <dev@maarch.org>
- **/
-
-class Logger4Php
-{
-
-    /**
-     * Array of errors levels
-     *
-     * @protected
-     **/
-    protected $error_levels = array('DEBUG' => 0, 'INFO' => 1, 'NOTICE' => 2, 'WARNING' => 3, 'ERROR' => 4);
-
-    /**
-     * Maps each handler with its log threshold.
-     *
-     * @protected
-     **/
-    protected $mapping;
-
-    /**
-     * Minimum log level
-     *
-     * @protected
-     **/
-    protected $threshold_level;
-
-    /**
-     * Path to log4Php library
-     *
-     * @protected
-     **/
-    protected $log4PhpLibrary;
-
-	/**
-     * Name of the logger
-     *
-     * @protected
-     **/
-    protected $log4PhpLogger;
-
-    /**
-     * Name of the business code
-     *
-     * @protected
-     **/
-    protected $log4PhpBusinessCode;
-
-    /**
-     * Path of the param of log4php
-     *
-     * @protected
-     **/
-    protected $log4PhpConfigPath;
-
-    /**
-     * Name of the batch
-     *
-     * @protected
-     **/
-    protected $log4PhpBatchName;
-
-    /** Class constructor
-     *
-     * Inits the threshold level
-     *
-     * @param $threshold_level (string) Threshold level (set to 'INFO' by default)
-     **/
-    function __construct($threshold_level = 'WARNING')
-    {
-        $this->threshold_level = $threshold_level;
-        $this->mapping = array_fill(0, count($this->error_levels), array());
-    }
-
-    /** Writes error message in current handlers
-     *
-     * writes only if the error level is greater or equal the threshold level
-     *
-     * @param $msg (string) Error message
-     * @param $error_level (string) Error level (set to 'INFO' by default)
-     * @param $error_code (integer) Error code (set to 0 by default)
-     **/
-    public function write($msg, $error_level = 'INFO', $error_code = 0, $other_params = array())
-    {
-		if (!array_key_exists($error_level, $this->error_levels)) {
-			$error_level = 'INFO';
-		}
-		$foundLogger = false;
-		if ($this->error_levels[$error_level] >= $this->error_levels[$this->threshold_level]) {
-			for ($i=$this->error_levels[$error_level];$i>=0;$i--) {
-				foreach ($this->mapping[$i] as $handler) {
-					$handler->write($msg, $error_level, $error_code, $other_params);
-					if (
-						get_class($handler) == 'FileHandler'
-						&& (isset($this->log4PhpLibrary)
-						&& !empty($this->log4PhpLibrary))
-					) {
-						if ($error_code == 0) {
-							$result = 'OK';
-						} else {
-							$result = 'KO';
-							$msg = '%error_code:' . $error_code . '% ' . $msg;
-						}
-						require_once($this->log4PhpLibrary);
-						$remote_ip = '127.0.0.1';
-						Logger::configure($this->log4PhpConfigPath);
-						$logger = Logger::getLogger($this->log4PhpLogger);
-						$searchPatterns = array('%ACCESS_METHOD%',
-							'%RESULT%',
-							'%BUSINESS_CODE%',
-							'%HOW%',
-							'%WHAT%',
-							'%REMOTE_IP%',
-							'%BATCH_NAME%'
-						);
-						$replacePatterns = array('Script',
-							$result,
-							$this->log4PhpBusinessCode,
-							'UP',
-							$msg,
-							$remote_ip,
-							$this->log4PhpBatchName
-						);
-						$logLine = str_replace($searchPatterns,
-							$replacePatterns,
-							'[%ACCESS_METHOD%][%RESULT%]'
-							. '[%BUSINESS_CODE%][%HOW%][%WHAT%][%BATCH_NAME%]'
-						);
-						$this->writeLog4php($logger, $logLine, $error_level);
-					}
-				}
-			}
-		}
-    }
-
-	/**
-	 *
-	 * write a log entry with a specific log level
-	 * @param object $logger Log4php logger
-	 * @param string $logLine Line we want to trace
-	 * @param enum $level Log level
-	 */
-	function writeLog4php($logger, $logLine, $level) {
-		switch ($level) {
-			case 'DEBUG':
-				$logger->debug($logLine);
-				break;
-			case 'INFO':
-				$logger->info($logLine);
-				break;
-			case 'WARNING':
-				$logger->warn($logLine);
-				break;
-			case 'ERROR':
-				$logger->error($logLine);
-				break;
-			case 'FATAL':
-				$logger->fatal($logLine);
-				break;
-		}
-	}
-
-    /** Adds a new handler in the current handlers array
-     *
-     * @param $handler (object) Handler object
-     **/
-    public function add_handler(&$handler, $error_level = NULL)
-    {
-        if(!isset($handler))
-            return false;
-
-        if(!isset($error_level) || !array_key_exists($error_level, $this->error_levels))
-        {
-            $error_level = $this->threshold_level;
-        }
-
-        $this->mapping[$this->error_levels[$error_level]][] = $handler;
-        return true;
-    }
-
-    /** Adds a new handler in the current handlers array
-     *
-     * @param $handler (object) Handler object
-     **/
-    public function change_handler_log_level(&$handler, $log_level )
-    {
-        if (!isset($handler) || !isset($log_level))
-            return false;
-
-        if (!array_key_exists($log_level, $this->error_levels)) {
-           return false;
-        }
-
-        for ($i=0; $i<count($this->mapping);$i++) {
-            for($j=0;$j<count($this->mapping[$i]);$j++) {
-                if($handler == $this->mapping[$i][$j]) {
-                    unset($this->mapping[$i][$j]);
-                }
-            }
-        }
-        $this->mapping = array_values($this->mapping);
-        $this->mapping[$this->error_levels[$log_level]][] = $handler;
-        return true;
-    }
-
-	/** Sets treshold level
-     *
-     * @param $treshold (string) treshold level
-     **/
-    public function set_threshold_level($treshold)
-    {
-        if (isset($treshold) && array_key_exists($treshold, $this->error_levels)) {
-            $this->threshold_level = $treshold;
-            return true;
-        }
-        $this->threshold_level = 'WARNING';
-        return false;
-    }
-
-	/** Sets log4Php library path
-     *
-     * @param $log4PhpLibrary (string) path
-     **/
-    public function set_log4PhpLibrary($log4PhpLibrary)
-    {
-        if (isset($log4PhpLibrary) && !empty($log4PhpLibrary)) {
-            if (file_exists($log4PhpLibrary)) {
-				$this->log4PhpLibrary = $log4PhpLibrary;
-				return true;
-			} else {
-				return false;
-			}
-        }
-        return false;
-    }
-
-    /** Sets log4php logger name
-     *
-     * @param $log4PhpLogger (string) logger name
-     **/
-    public function set_log4PhpLogger($log4PhpLogger)
-    {
-        if (isset($log4PhpLogger) && !empty($log4PhpLogger)) {
-            $this->log4PhpLogger = $log4PhpLogger;
-            return true;
-        }
-        $this->log4PhpLogger = 'loggerTechnique';
-        return false;
-    }
-
-	/** Sets log4php path to log4php xml config
-     *
-     * @param $log4PhpPath (string) path to log4php xml config
-     **/
-    public function set_log4PhpConfigPath($log4PhpConfigPath)
-    {
-        if (isset($log4PhpConfigPath) && !empty($log4PhpConfigPath)) {
-            if (file_exists($log4PhpConfigPath)) {
-				$this->log4PhpConfigPath = $log4PhpConfigPath;
-				return true;
-			} else {
-				return false;
-			}
-        }
-        return false;
-    }
-
-	/** Sets log4php business code
-     *
-     * @param $log4PhpBusinessCode (string) business code
-     **/
-    public function set_log4PhpBusinessCode($log4PhpBusinessCode)
-    {
-        if (isset($log4PhpBusinessCode) && !empty($log4PhpBusinessCode)) {
-			$this->log4PhpBusinessCode = $log4PhpBusinessCode;
-			return true;
-        }
-        $this->log4PhpBusinessCode = 'Maarch';
-        return false;
-    }
-
-    /** Sets log4php batch name
-     *
-     * @param $log4PhpBatchName (string) BatchName
-     **/
-    public function set_log4PhpBatchName($log4PhpBatchName)
-    {
-        if (isset($log4PhpBatchName) && !empty($log4PhpBatchName)) {
-			$this->log4PhpBatchName = $log4PhpBatchName;
-			return true;
-        }
-        $this->log4PhpBatchName = 'MaarchBatch';
-        return false;
-    }
-
-    /** Class destructor
-     *
-     * Calls handlers destructors
-     **/
-    function __destruct()
-    {
-        for($i=0; $i<count($this->mapping);$i++)
-        {
-            foreach($this->mapping[$i] as $handler)
-            {
-                unset($handler);
-            }
-        }
-    }
-}
diff --git a/modules/notifications/batch/basket_event_stack.php b/modules/notifications/batch/basket_event_stack.php
index 12be463a59b211ab00e44e65e5b9bbe8e0784bbc..89a80ce6155853067776b5f4fc8e9dd156b53dd5 100755
--- a/modules/notifications/batch/basket_event_stack.php
+++ b/modules/notifications/batch/basket_event_stack.php
@@ -151,7 +151,7 @@ while ($state != 'END') {
                 preg_match_all('#\[(\w+)]#', $event['event_info'], $result);
                 $basket_id = $result[1];
 
-                if ($event['table_name'] == $coll_table || $event['table_name'] == $coll_view) {
+                if ($event['table_name'] == 'res_letterbox' || $event['table_name'] == 'res_view_letterbox') {
                     $res_id = $event['record_id'];
                 } else {
                     continue;
@@ -191,9 +191,9 @@ while ($state != 'END') {
                         'events'       => $basket_list['events'],
                         'notification' => $notification,
                         'maarchUrl'    => $maarchUrl,
-                        'coll_id'      => $coll_id,
-                        'res_table'    => $coll_table,
-                        'res_view'     => $coll_view,
+                        'coll_id'      => 'letterbox_coll',
+                        'res_table'    => 'res_letterbox',
+                        'res_view'     => 'res_view_letterbox',
                     );
 
                     $html = \ContentManagement\controllers\MergeController::mergeNotification(['templateId' => $notification['template_id'], 'params' => $params]);
diff --git a/modules/notifications/batch/load_basket_event_stack.php b/modules/notifications/batch/load_basket_event_stack.php
index a545078048007d4e423321ca1cd77ca48c481337..19006da83142f72e7e8a270f17c3170f960dc505 100755
--- a/modules/notifications/batch/load_basket_event_stack.php
+++ b/modules/notifications/batch/load_basket_event_stack.php
@@ -113,10 +113,6 @@ try {
 \SrcCore\models\DatabasePDO::reset();
 new \SrcCore\models\DatabasePDO(['customId' => $customID]);
 
-$coll_id    = 'letterbox_coll';
-$coll_table = 'res_letterbox';
-$coll_view  = 'res_view_letterbox';
-
 $GLOBALS['errorLckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
                          . $customIDPath . $GLOBALS['batchName'] . '_error.lck';
 $GLOBALS['lckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
diff --git a/modules/notifications/batch/load_process_event_stack.php b/modules/notifications/batch/load_process_event_stack.php
index 58a08b0adc61614532c80fce9e847b2838e77ec1..503dd01ad8140fc596121f7266b9c85e9cdb5721 100755
--- a/modules/notifications/batch/load_process_event_stack.php
+++ b/modules/notifications/batch/load_process_event_stack.php
@@ -113,10 +113,6 @@ try {
 \SrcCore\models\DatabasePDO::reset();
 new \SrcCore\models\DatabasePDO(['customId' => $customID]);
 
-$coll_id    = 'letterbox_coll';
-$coll_table = 'res_letterbox';
-$coll_view  = 'res_view_letterbox';
-
 $GLOBALS['errorLckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
                          . $customIDPath . $GLOBALS['batchName'] . '_error.lck';
 $GLOBALS['lckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
diff --git a/modules/notifications/batch/load_stack_letterbox_alerts.php b/modules/notifications/batch/load_stack_letterbox_alerts.php
index 3bb7713ffa8bd6a58f8dd7c0597e64ede2bf1328..2d1596ea560db83b160fc532d50ed3856a8619e9 100755
--- a/modules/notifications/batch/load_stack_letterbox_alerts.php
+++ b/modules/notifications/batch/load_stack_letterbox_alerts.php
@@ -98,10 +98,6 @@ $GLOBALS['batchDirectory'] = $maarchDirectory . 'modules'
 
 set_include_path(get_include_path() . PATH_SEPARATOR . $maarchDirectory);
   
-// COLLECTION
-$collTable = 'res_letterbox';
-$collView = 'res_view_letterbox';
-  
 // INCLUDES
 try {
     Bt_myInclude($GLOBALS['maarchDirectory'] . 'vendor/autoload.php');
@@ -113,8 +109,6 @@ try {
     exit();
 }
 
-$alert_engine = new alert_engine($GLOBALS['configFile']);
-
 $GLOBALS['errorLckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
                          . $customIDPath . $GLOBALS['batchName'] . '_error.lck';
 $GLOBALS['lckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
diff --git a/modules/notifications/batch/process_event_stack.php b/modules/notifications/batch/process_event_stack.php
index cbeecb140e1378ca63b47141b2070151a7031f5c..21a8ebe056c4f0ef1c7e8a996ad08c0696bbf68c 100755
--- a/modules/notifications/batch/process_event_stack.php
+++ b/modules/notifications/batch/process_event_stack.php
@@ -66,7 +66,7 @@ while ($state != 'END') {
                 // Diffusion type specific res_id
                 Bt_writeLog(['level' => 'INFO', 'message' => "Getting document ids using diffusion type '".$notification['diffusion_type']."'"]);
                 $res_id = false;
-                if ($event['table_name'] == $coll_table || $event['table_name'] == $coll_view) {
+                if ($event['table_name'] == 'res_letterbox' || $event['table_name'] == 'res_view_letterbox') {
                     $res_id = $event['record_id'];
                 } else {
                     $res_id = \Notification\controllers\DiffusionTypesController::getItemsToNotify(['request' => 'res_id', 'notification' => $notification, 'event' => $event]);
@@ -121,7 +121,7 @@ while ($state != 'END') {
                 }
 
                 if (count($recipients) === 0) {
-                    Bt_writeLog(['level' => 'WARNING', 'message' => 'No recipient found']);
+                    Bt_writeLog(['level' => 'WARN', 'message' => 'No recipient found']);
                     \Notification\models\NotificationsEventsModel::update([
                         'set'   => ['exec_date' => 'CURRENT_TIMESTAMP', 'exec_result' => 'INFO: no recipient found'],
                         'where' => ['event_stack_sid = ?'],
@@ -153,9 +153,9 @@ while ($state != 'END') {
                     'events'       => $tmpNotif['events'],
                     'notification' => $notification,
                     'maarchUrl'    => $maarchUrl,
-                    'coll_id'      => $coll_id,
-                    'res_table'    => $coll_table,
-                    'res_view'     => $coll_view,
+                    'coll_id'      => 'letterbox_coll',
+                    'res_table'    => 'res_letterbox',
+                    'res_view'     => 'res_view_letterbox',
                 );
                 $html = \ContentManagement\controllers\MergeController::mergeNotification(['templateId' => $notification['template_id'], 'params' => $params]);
                 if (strlen($html) === 0) {
diff --git a/modules/notifications/batch/stack_letterbox_alerts.php b/modules/notifications/batch/stack_letterbox_alerts.php
index 76c35b0c026574eaa1040fa0bbfb189424338aad..bd0e914c13848f51d13393ad5e6d7e01259ae586 100755
--- a/modules/notifications/batch/stack_letterbox_alerts.php
+++ b/modules/notifications/batch/stack_letterbox_alerts.php
@@ -7,170 +7,121 @@ include('load_stack_letterbox_alerts.php');
 
 $state = 'LOAD_ALERTS_NOTIFS';
 while ($state <> 'END') {
-    if (isset($GLOBALS['logger'])) {
-        $GLOBALS['logger']->write('STATE:' . $state, 'INFO');
-    }
+    Bt_writeLog(['level' => 'INFO', 'message' => 'STATE:' . $state]);
+
     switch ($state) {
-    /**********************************************************************/
-    /*                          LOAD_ALERTS_NOTIFS                               */
-    /* Load parameters                                                    */
-    /**********************************************************************/
-    case 'LOAD_ALERTS_NOTIFS' :
-        $query = "SELECT count(1) as count FROM " 
-            . _NOTIFICATIONS_TABLE_NAME 
-            . " WHERE event_id IN ('alert1', 'alert2') ";
-        $stmt = Bt_doQuery($db, $query);
-        $totalAlertsToProcess = $stmt->fetchObject()->count;
-        $query = "SELECT notification_sid, event_id FROM " 
-            . _NOTIFICATIONS_TABLE_NAME 
-            . " WHERE event_id IN ('alert1', 'alert2') ";
-        $stmt = Bt_doQuery($db, $query);
-        if ($totalAlertsToProcess === 0) {
-            Bt_exitBatch(0, 'No alert parametered');
-        }
-        $logger->write($totalAlertsToProcess . " notifications parametered for mail alerts", 'INFO');
-        $GLOBALS['alert_notifs'] = array();
-        while ($alertRecordset = $stmt->fetchObject()) {
-            $GLOBALS['alert_notifs'][$alertRecordset->event_id][] = $alertRecordset->notification_sid;
-        }
-    
-        $state = 'LOAD_DOCTYPES';
-        break;
-    
-    /**********************************************************************/
-    /*                          LOAD_DOCTYPES                            */
-    /* Load parameters                                                   */
-    /**********************************************************************/
-    case 'LOAD_DOCTYPES' :
-        $query = "SELECT count(1) as count FROM doctypes";
-        $stmt = Bt_doQuery($db, $query);
-        $totalDocTypes = $stmt->fetchObject()->count;
-        $query = "SELECT * FROM doctypes";
-        $stmt = Bt_doQuery($db, $query);
-        $GLOBALS['doctypes'] = array();
-        while ($doctypeRecordset = $stmt->fetchObject()) {
-            $GLOBALS['doctypes'][$doctypeRecordset->type_id] = $doctypeRecordset;
-        }
-        $logger->write($totalDocTypes . " document types parametered", 'INFO');
-        $state = 'LIST_DOCS';
-        break;
-    /**********************************************************************/
-    /*                          LIST_DOCS                                 */
-    /* List the resources to proccess for alarms                          */
-    /**********************************************************************/
-    case 'LIST_DOCS' :
-        $query = "SELECT count(1) as count" 
-            . " FROM " . $collView
-            . " WHERE closing_date IS null"
-            . " AND status NOT IN ('CLO', 'DEL', 'END')"
-            . " AND (flag_alarm1 = 'N' OR flag_alarm2 = 'N')"
-            . " AND process_limit_date IS NOT NULL";
-        $stmt = Bt_doQuery($GLOBALS['db'], $query);
-        $totalDocsToProcess = $stmt->fetchObject()->count;
-        $query = "SELECT res_id, type_id, process_limit_date, flag_alarm1, flag_alarm2" 
-            . " FROM " . $collView
-            . " WHERE closing_date IS null"
-            . " AND status NOT IN ('CLO', 'DEL', 'END')"
-            . " AND (flag_alarm1 = 'N' OR flag_alarm2 = 'N')"
-            . " AND process_limit_date IS NOT NULL";
-        $stmt = Bt_doQuery($GLOBALS['db'], $query);
-        $currentDoc = 0;
-        if ($totalDocsToProcess === 0) {
-            Bt_exitBatch(0, 'No document to process');
-        }
-        $logger->write($totalDocsToProcess . " documents to process (i.e. not closed, at least one alert to send)", 'INFO');
-        $GLOBALS['docs'] = array();
-        while ($DocRecordset = $stmt->fetchObject()) {
-            $GLOBALS['docs'][] = $DocRecordset;
-        }
-        $state = 'A_DOC';
-        break;
+        /**********************************************************************/
+        /*                          LOAD_ALERTS_NOTIFS                               */
+        /* Load parameters                                                    */
+        /**********************************************************************/
+        case 'LOAD_ALERTS_NOTIFS':
+            $alertRecordset = \Notification\models\NotificationModel::get(['select' => ['notification_sid', 'event_id'], 'where' => ['event_id in (?)'], 'data' => [['alert1', 'alert2']]]);
+            if (empty($alertRecordset)) {
+                Bt_exitBatch(0, 'No alert set');
+            }
+            Bt_writeLog(['level' => 'INFO', 'message' => count($alertRecordset) . " notifications set for mail alerts"]);
+
+            $alertNotifs = [];
+            foreach ($alertRecordset as $value) {
+                $alertNotifs[$value['event_id']][] = $value['notification_sid'];
+            }
+            $state = 'LOAD_DOCTYPES';
+            break;
         
-    /**********************************************************************/
-    /*                          A_DOC                                     */
-    /* Add notification to event_stack for each notif to be sent          */
-    /**********************************************************************/
-    case 'A_DOC' :
-        if($currentDoc < $totalDocsToProcess) {
-            $myDoc = $GLOBALS['docs'][$currentDoc];
-            $myDoc->process_limit_date = str_replace("-", "/", $db->format_date($myDoc->process_limit_date));
-            $logger->write("Processing document #" . $myDoc->res_id, 'INFO');
-                
-            $myDoctype = $GLOBALS['doctypes'][$myDoc->type_id];
-            if(!$myDoctype) {
-                Bt_exitBatch(1, 'Unknown document type ' . $myDoc->type_id);
+        /**********************************************************************/
+        /*                          LOAD_DOCTYPES                            */
+        /* Load parameters                                                   */
+        /**********************************************************************/
+        case 'LOAD_DOCTYPES':
+            $doctypes = \Doctype\models\DoctypeModel::get();
+            $doctypes = array_column($doctypes, null, 'type_id');
+            Bt_writeLog(['level' => 'INFO', 'message' => count($doctypes) . " document types set"]);
+            $state = 'LIST_DOCS';
+            break;
+        /**********************************************************************/
+        /*                          LIST_DOCS                                 */
+        /* List the resources to proccess for alarms                          */
+        /**********************************************************************/
+        case 'LIST_DOCS':
+            $resources = \Resource\models\ResModel::get([
+                'select' => ['res_id', 'type_id', 'process_limit_date', 'flag_alarm1', 'flag_alarm2'],
+                'where' => ['closing_date IS null', 'status NOT IN (?)', '(flag_alarm1 = \'N\' OR flag_alarm2 = \'N\')', 'process_limit_date IS NOT NULL'],
+                'data'  => [['CLO', 'DEL', 'END']]
+            ]);
+            if (empty($resources)) {
+                Bt_exitBatch(0, 'No document to process');
             }
-            $logger->write("Document type id is #" . $myDoc->type_id, 'INFO');
+            $totalDocsToProcess = count($resources);
+            Bt_writeLog(['level' => 'INFO', 'message' => $totalDocsToProcess . " documents to process (i.e. not closed, at least one alert to send)"]);
+
+            $state = 'A_DOC';
+            break;
             
-            // Alert 1 = limit - n days
-            if($myDoc->flag_alarm1 != 'Y' && $myDoc->flag_alarm2 != 'Y') {
-                $convertedDate = $alert_engine->dateFR2Time($myDoc->process_limit_date);
-                $date = $alert_engine->WhenOpenDay($convertedDate, (integer)$myDoctype->delay1, true);
-                $process_date = $db->dateformat($date, '-');
-                echo PHP_EOL . "$myDoc->process_limit_date - " . (integer)$myDoctype->delay1 . " days : " . $process_date;
-                $compare = $alert_engine->compare_date($process_date, date("d-m-Y"));
-                echo PHP_EOL . $compare;
-                if($compare == 'date2' || $compare == 'equal') {
-                    $logger->write("Alarm 1 will be sent", 'INFO');
-                    $info = 'Relance 1 pour traitement du document No' . $myDoc->res_id . ' avant date limite.';  
-                    if(count($GLOBALS['alert_notifs']['alert1']) > 0) {
-                        foreach($GLOBALS['alert_notifs']['alert1'] as $notification_sid) {
-                            $query = "INSERT INTO " . _NOTIF_EVENT_STACK_TABLE_NAME
-                                . " (notification_sid, table_name, record_id, user_id, event_info"
-                                . ", event_date)" 
-                                . " VALUES(" . $notification_sid . ", '" 
-                                . $collView . "', '" . $myDoc->res_id . "', 'superadmin', '" . $info . "', " 
-                                . $db->current_datetime() . ")";
-                            Bt_doQuery($db, $query);
+        /**********************************************************************/
+        /*                          A_DOC                                     */
+        /* Add notification to event_stack for each notif to be sent          */
+        /**********************************************************************/
+        case 'A_DOC':
+            foreach ($resources as $myDoc) {
+                Bt_writeLog(['level' => 'INFO', 'message' => "Processing document #" . $myDoc['res_id']]);
+                    
+                $myDoctype = $doctypes[$myDoc['type_id']];
+                if (!$myDoctype) {
+                    Bt_writeLog(['level' => 'WARN', 'message' => 'Unknown document type ' . $myDoc['type_id']]);
+                    continue;
+                }
+                Bt_writeLog(['level' => 'INFO', 'message' => "Document type id is #" . $myDoc['type_id']]);
+                $user = \User\models\UserModel::getByLogin(['login' => 'superadmin', 'select' => ['id']]);
+
+                // Alert 1 = limit - n days
+                if ($myDoc['flag_alarm1'] != 'Y' && $myDoc['flag_alarm2'] != 'Y') {
+                    $processDate = \Resource\controllers\IndexingController::calculateProcessDate(['date' => $myDoc['process_limit_date'], 'delay' => $myDoctype['delay1'], 'sub' => true]);
+                    if (strtotime($processDate) <= time()) {
+                        Bt_writeLog(['level' => 'INFO', 'message' => "Alarm 1 will be sent"]);
+                        $info = 'Relance 1 pour traitement du document No' . $myDoc['res_id'] . ' avant date limite.';
+                        if (count($alertNotifs['alert1']) > 0) {
+                            foreach ($alertNotifs['alert1'] as $notification_sid) {
+                                \Notification\models\NotificationsEventsModel::create([
+                                    'notification_sid' => $notification_sid,
+                                    'table_name'       => 'res_view_letterbox',
+                                    'record_id'        => $myDoc['res_id'],
+                                    'user_id'          => $user['id'],
+                                    'event_info'       => $info
+                                ]);
+                            }
                         }
+                        \Resource\models\ResModel::update(['set' => ['flag_alarm1' => 'Y', 'alarm1_date' => 'CURRENT_TIMESTAMP'], 'where' => ['res_id = ?'], 'data' => [$myDoc['res_id']]]);
                     }
-                    $query = "UPDATE res_letterbox SET flag_alarm1 = 'Y', alarm1_date = " . $db->current_datetime()
-                        . " WHERE res_id = " . $myDoc->res_id;
-                    Bt_doQuery($db, $query);
                 }
-            }
-            // Alert 2 = limit + n days
-            if($myDoc->flag_alarm2 != 'Y') {
-                $convertedDate = $alert_engine->dateFR2Time($myDoc->process_limit_date);
-                $date = $alert_engine->WhenOpenDay($convertedDate, (integer)$myDoctype->delay2);
-                $process_date = $db->dateformat($date, '-');
-                echo PHP_EOL . "$myDoc->process_limit_date + " . (integer)$myDoctype->delay2 . " days : " . $process_date;
-                $compare = $alert_engine->compare_date($process_date, date("d-m-Y"));
-                echo PHP_EOL . $compare;
-                if($compare == 'date2' || $compare == 'equal') {
-                    $logger->write("Alarm 2 will be sent", 'INFO');
-                    $info = 'Relance 2 pour traitement du document No' . $myDoc->res_id . ' apres date limite.';  
-                    if(count($GLOBALS['alert_notifs']['alert2']) > 0) {
-                        foreach($GLOBALS['alert_notifs']['alert2'] as $notification_sid) {
-                            $query = "INSERT INTO " . _NOTIF_EVENT_STACK_TABLE_NAME
-                                . " (notification_sid, table_name, record_id, user_id, event_info"
-                                . ", event_date)" 
-                                . " VALUES(" . $notification_sid . ", '" 
-                                . $collView . "', '" . $myDoc->res_id . "', 'superadmin', '" . $info . "', " 
-                                . $db->current_datetime() . ")";
-                            Bt_doQuery($db, $query);
+
+                // Alert 2 = limit + n days
+                if ($myDoc['flag_alarm2'] != 'Y') {
+                    $processDate = \Resource\controllers\IndexingController::calculateProcessDate(['date' => $myDoc['process_limit_date'], 'delay' => $myDoctype['delay2']]);
+                    if (strtotime($processDate) <= time()) {
+                        Bt_writeLog(['level' => 'INFO', 'message' => "Alarm 2 will be sent"]);
+                        $info = 'Relance 2 pour traitement du document No' . $myDoc['res_id'] . ' apres date limite.';
+                        if (count($alertNotifs['alert2']) > 0) {
+                            foreach ($alertNotifs['alert2'] as $notification_sid) {
+                                \Notification\models\NotificationsEventsModel::create([
+                                    'notification_sid' => $notification_sid,
+                                    'table_name'       => 'res_view_letterbox',
+                                    'record_id'        => $myDoc['res_id'],
+                                    'user_id'          => $user['id'],
+                                    'event_info'       => $info
+                                ]);
+                            }
                         }
+                        \Resource\models\ResModel::update(['set' => ['flag_alarm1' => 'Y', 'flag_alarm2' => 'Y', 'alarm2_date' => 'CURRENT_TIMESTAMP'], 'where' => ['res_id = ?'], 'data' => [$myDoc['res_id']]]);
                     }
-                    $query = "UPDATE res_letterbox SET flag_alarm1 = 'Y', flag_alarm2 = 'Y', alarm2_date = " . $db->current_datetime()
-                        . " WHERE res_id = " . $myDoc->res_id;
-                    Bt_doQuery($db, $query);
                 }
             }
-            $currentDoc++;
-            $state = 'A_DOC';
-        } else {
             $state = 'END';
-        }
-        
-        break;
+            break;
     }
 }
 
-$GLOBALS['logger']->write('End of process', 'INFO');
-Bt_logInDataBase(
-    $totalDocsToProcess, 0, 'process without error'
-);
-//$GLOBALS['db']->disconnect();
+Bt_writeLog(['level' => 'INFO', 'message' => 'End of process']);
+Bt_logInDataBase($totalDocsToProcess, 0, 'process without error');
+
 unlink($GLOBALS['lckFile']);
 exit($GLOBALS['exitCode']);
-?>
diff --git a/src/app/docserver/models/DocserverTypeModelAbstract.php b/src/app/docserver/models/DocserverTypeModelAbstract.php
index 64f961240bebb59983aa4ce6eca0e51eb97d458d..c38dd3ff9c9ea049292b74375dfc9a5999b81336 100755
--- a/src/app/docserver/models/DocserverTypeModelAbstract.php
+++ b/src/app/docserver/models/DocserverTypeModelAbstract.php
@@ -33,7 +33,6 @@ class DocserverTypeModelAbstract
             'limit'     => empty($aArgs['limit']) ? 0 : $aArgs['limit']
         ]);
 
-
         return $aDocserverTypes;
     }
 
diff --git a/src/app/notification/models/NotificationModelAbstract.php b/src/app/notification/models/NotificationModelAbstract.php
index d550b9fb189c1c8bfaab426427d1375687afdceb..a1230d068e11b4252c9134605cf48952490a70ba 100755
--- a/src/app/notification/models/NotificationModelAbstract.php
+++ b/src/app/notification/models/NotificationModelAbstract.php
@@ -25,11 +25,16 @@ abstract class NotificationModelAbstract
 {
     public static function get(array $aArgs = [])
     {
-        ValidatorModel::arrayType($aArgs, ['select']);
+        ValidatorModel::arrayType($aArgs, ['select', 'where', 'orderBy']);
+        ValidatorModel::intType($aArgs, ['limit']);
 
         $aNotifications = DatabaseModel::select([
-            'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
-            'table'  => ['notifications'],
+            'select'    => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
+            'table'     => ['notifications'],
+            'where'     => empty($aArgs['where']) ? [] : $aArgs['where'],
+            'data'      => empty($aArgs['data']) ? [] : $aArgs['data'],
+            'order_by'  => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'],
+            'limit'     => empty($aArgs['limit']) ? 0 : $aArgs['limit']
         ]);
 
         return $aNotifications;
diff --git a/src/app/resource/controllers/IndexingController.php b/src/app/resource/controllers/IndexingController.php
index feba1514d99d29f5afe685b66d601a5a9c5e7558..1d3dd4af728ab9945f7aa6156fd0a1727909b641 100755
--- a/src/app/resource/controllers/IndexingController.php
+++ b/src/app/resource/controllers/IndexingController.php
@@ -360,7 +360,11 @@ class IndexingController
             $processDelayUpdated = 1;
             for ($i = 1; $i <= $args['delay']; $i++) {
                 $tmpDate = new \DateTime($args['date']);
-                $tmpDate->add(new \DateInterval("P{$i}D"));
+                if ($args['sub']) {
+                    $tmpDate->sub(new \DateInterval("P{$i}D"));
+                } else {
+                    $tmpDate->add(new \DateInterval("P{$i}D"));
+                }
                 if (in_array($tmpDate->format('N'), [6, 7]) || in_array($tmpDate->format('d-m'), $hollidays)) {
                     ++$args['delay'];
                 }
@@ -369,10 +373,18 @@ class IndexingController
                 }
             }
 
-            $date->add(new \DateInterval("P{$processDelayUpdated}D"));
+            if ($args['sub']) {
+                $date->sub(new \DateInterval("P{$processDelayUpdated}D"));
+            } else {
+                $date->add(new \DateInterval("P{$processDelayUpdated}D"));
+            }
         } else {
             // Calendar or empty delay
-            $date->add(new \DateInterval("P{$args['delay']}D"));
+            if ($args['sub']) {
+                $date->sub(new \DateInterval("P{$args['delay']}D"));
+            } else {
+                $date->add(new \DateInterval("P{$args['delay']}D"));
+            }
         }
 
         return $date->format('Y-m-d');