getSetting('Notifications: Send Document Expiry Emails') != '1'){ LogManager::getInstance()->info("Notifications: Send Document Expiry Emails is set to No. Do not send emails"); return; } //Get documents $dayList = array(); $dayList[30] = 'expire_notification_month'; $dayList[7] = 'expire_notification_week'; $dayList[1] = 'expire_notification_day'; $dayList[0] = 'expire_notification'; foreach($dayList as $k => $v){ $this->expiryDayNotification($k, $v); } $this->getExpireDocumentHTMLByEmployee(); $this->sendEmployeeEmails($this->employeeEmails, "IceHrm Employee Document Expiry Reminder"); } private function expiryDayNotification($day, $param){ $date = date('Y-m-d', strtotime("+".$day." days")); $employeeDocument = new EmployeeDocument(); $employeeDocuments = $employeeDocument->Find("valid_until IS NOT NULL and valid_until = ? and (expire_notification_last > ? or expire_notification_last = -1) and status = ?", array($date, $day, 'Active')); if(!$employeeDocuments){ LogManager::getInstance()->error("Error :".$employeeDocument->ErrorMsg()); return; } $query = "valid_until IS NOT NULL and valid_until = $date and (expire_notification_last > $day or expire_notification_last == -1) and status = 'Active';"; LogManager::getInstance()->debug($query); foreach($employeeDocuments as $doc){ LogManager::getInstance()->debug("Employee Doc :".print_r($doc, true)); if(empty($doc->document)){ continue; } $document = null; if(isset($this->documentCache[$doc->id])){ $document = $this->documentCache[$doc->id]; }else{ $document = new Document(); $document->Load("id = ?",array($doc->document)); $this->documentCache[$document->id] = $document; } if($document->$param == "Yes"){ if(!isset($this->notificationList[$doc->employee])){ $this->notificationList[$doc->employee] = array(); } $this->notificationList[$doc->employee][] = array($doc, $document, $day); } $doc->expire_notification_last = $day; $doc->Save(); } } private function getExpireDocumentHTMLByEmployee(){ $row = '
#_name_# - Expire in #_days_# day(s)