mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Merge master into feature-10422/ZeiterfassungInfomails
This commit is contained in:
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
/**
|
||||
* FH-Complete
|
||||
*
|
||||
* @package FHC-API
|
||||
* @author FHC-Team
|
||||
* @copyright Copyright (c) 2016, fhcomplete.org
|
||||
* @license GPLv3
|
||||
* @link http://fhcomplete.org
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*
|
||||
* Cronjobs to be run for sending emails informing about Zeiterfassungsreminder.
|
||||
*/
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class ZeiterfassungInfoJob extends JOB_Controller
|
||||
{
|
||||
|
||||
const URLAUBSFREIGABE_PATH = 'cis/private/profile/urlaubsfreigabe.php';
|
||||
const MONATSLISTEN_PATH = 'addons/casetime/cis/timesheet_overview.php';
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Load models
|
||||
$this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel');
|
||||
$this->load->model('ressource/Mitarbeiter_model', 'MitarbeiterModel');
|
||||
$this->load->model('ressource/Timesheet_model', 'TimesheetModel');
|
||||
$this->load->model('ressource/Zeitaufzeichnung_model', 'ZeitaufzeichnungModel');
|
||||
$this->load->model('ressource/Zeitsperre_model', 'ZeitsperreModel');
|
||||
$this->load->model('system/Benutzerrolle_model', 'BenutzerrolleModel');
|
||||
|
||||
// Load libraries
|
||||
$this->load->library('PermissionLib');
|
||||
|
||||
// Load helpers
|
||||
$this->load->helper('hlp_sancho_helper');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Sancho Reminder eMail to:
|
||||
* a) Supervisors, who have to approve vacation
|
||||
* b) Supervisors, who have to approve timesheets
|
||||
* c) Employees, who did not send last months timesheet yet
|
||||
* d) Employees, who have not recorded their working hours last week
|
||||
* e) Employees, who do not have a "Zeitmodel" yet
|
||||
*/
|
||||
public function sendMail()
|
||||
{
|
||||
$allMitarbeiter = $this->_getEmplyeeUids();
|
||||
|
||||
$vorgesetzte_to_approve_vacation = $this->_getVorgesetztetoApproveVacationList();
|
||||
$vorgesetzte_to_approve_timesheets = $this->_getVorgesetztetoApproveTimesheetList();
|
||||
|
||||
$mitarbeiter_to_send_timesheet_lastmonth = $this->_getEmployeeTimesheetList();
|
||||
$mitarbeiter_to_record_times_lastweek = $this->_getEmployeeLastWeeksTimeList();
|
||||
|
||||
$mailingList = array();
|
||||
|
||||
foreach ($allMitarbeiter as $ma)
|
||||
{
|
||||
$uid = $ma->uid;
|
||||
if(array_key_exists($uid, $vorgesetzte_to_approve_vacation))
|
||||
{
|
||||
$ma->SupVac = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ma->SupVac = false;
|
||||
}
|
||||
if(array_key_exists($uid, $vorgesetzte_to_approve_timesheets))
|
||||
{
|
||||
$ma->SupMonth = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ma->SupMonth = false;
|
||||
}
|
||||
if(array_key_exists($uid, $mitarbeiter_to_send_timesheet_lastmonth))
|
||||
{
|
||||
$ma->EmpMonth = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ma->EmpMonth = false;
|
||||
}
|
||||
if(array_key_exists($uid, $mitarbeiter_to_record_times_lastweek))
|
||||
{
|
||||
$ma->EmpWeek = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ma->EmpWeek = false;
|
||||
}
|
||||
|
||||
|
||||
if($ma->SupVac || $ma->SupMonth || $ma->EmpMonth || $ma->EmpWeek || $ma->EmpZeitMod)
|
||||
{
|
||||
array_push($mailingList, $ma);
|
||||
}
|
||||
|
||||
}
|
||||
$start = date("h:i:sa");
|
||||
|
||||
print_r(date("h:i:sa\n"));
|
||||
// Loop through 'container' of mail recipients
|
||||
foreach ($mailingList as $ma)
|
||||
{
|
||||
// Set mail recipient
|
||||
$to = $ma->uid.'@'. DOMAIN;
|
||||
|
||||
$supVac ='';
|
||||
$SupMonth ='';
|
||||
$EmpMonth ='';
|
||||
$EmpWeek ='';
|
||||
$EmpZeitMod ='';
|
||||
|
||||
//Generate Email Text
|
||||
$ma->SupVac ? $supVac = '->Du hast noch Urlaube freizugeben. Du findest die Ulaubsfreigabe unter: <a href="'.CIS_ROOT.'cis/index.php?menu='.CIS_ROOT. 'cis/menu.php?content_id=&content='.CIS_ROOT.self::URLAUBSFREIGABE_PATH.'">Urlaubstool</a><br><br>' : '';
|
||||
$ma->SupMonth ? $SupMonth = '->Du hast noch Monatslisten freizugeben. Du findest die Monatslistenfreigabe unter: <a href="'.CIS_ROOT.'cis/index.php?menu='.CIS_ROOT. 'cis/menu.php?content_id=&content='.CIS_ROOT.self::MONATSLISTEN_PATH.'">Monatslisten</a><br><br>' : '';
|
||||
$ma->EmpMonth ? $EmpMonth = '->Du musst noch die Monatsliste von letztem Monat abschicken.<br><br>' : '';
|
||||
$ma->EmpWeek ? $EmpWeek = '->Du musst noch Zeiten für letzte Woche eintragen.<br><br>' : '';
|
||||
$ma->EmpZeitMod ? $EmpZeitMod = '->Du hast noch kein Zeitmodell hinterlegt.<br><br>' : '';
|
||||
|
||||
// Prepare mail content
|
||||
$content_data_arr = array(
|
||||
'SupVac' => $supVac,
|
||||
'SupMonth' => $SupMonth,
|
||||
'EmpMonth' => $EmpMonth,
|
||||
'EmpWeek' => $EmpWeek,
|
||||
'EmpZeitMod' => $EmpZeitMod
|
||||
);
|
||||
|
||||
sendSanchoMail(
|
||||
'ZeiterfassungInfoMail',
|
||||
$content_data_arr,
|
||||
$to,
|
||||
'Zeiterfassung Erinnerung'
|
||||
);
|
||||
}
|
||||
$end = date("h:i:sa");
|
||||
print_r($end."\n");
|
||||
print_r(($start-$end."\n"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//******************************************************************************************************************
|
||||
// PRIVATE FUNCTIONS
|
||||
//******************************************************************************************************************
|
||||
|
||||
/**
|
||||
* Get all Supervisors that have yet to approve Vacations of Emploees
|
||||
* @return array - keys: supervisor name, values: number of emploees with pending vacation approval
|
||||
*/
|
||||
private function _getVorgesetztetoApproveVacationList()
|
||||
{
|
||||
$mResult = $this->ZeitsperreModel->getMitarbeiterListWithPendingVacation();
|
||||
$mitarbeiterList = getData($mResult);
|
||||
$vorgesetzte = array();
|
||||
$toSend = array();
|
||||
|
||||
foreach ($mitarbeiterList as $mitarbeiter)
|
||||
{
|
||||
$mitarbeiter_uid = $mitarbeiter->mitarbeiter_uid;
|
||||
$vorgesetzte [] = getData($this->MitarbeiterModel->getVorgesetzte($mitarbeiter_uid));
|
||||
}
|
||||
|
||||
foreach ($vorgesetzte as $v)
|
||||
{
|
||||
if(!(is_null($v)))
|
||||
{
|
||||
foreach ($v as $obj)
|
||||
{
|
||||
$name = $obj->vorgesetzter;
|
||||
|
||||
if (!(is_null($name)) && !array_key_exists($name, $toSend))
|
||||
{
|
||||
$toSend[$name] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$toSend[$name] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $toSend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Supervisors that have yet to approve Timesheets of Emploees
|
||||
* @return array - keys: supervisor name, values: number of emploees with pending timesheet approval
|
||||
*/
|
||||
private function _getVorgesetztetoApproveTimesheetList()
|
||||
{
|
||||
$mResult = $this->TimesheetModel->getPendingTimesheets();
|
||||
$mitarbeiterList = getData($mResult);
|
||||
$vorgesetzte = array();
|
||||
$toSend = array();
|
||||
|
||||
foreach ($mitarbeiterList as $mitarbeiter)
|
||||
{
|
||||
$uid = $mitarbeiter->uid;
|
||||
$vorgesetzte [] = getData($this->MitarbeiterModel->getVorgesetzte($uid));
|
||||
}
|
||||
|
||||
foreach ($vorgesetzte as $v)
|
||||
{
|
||||
if (!is_null($v))
|
||||
{
|
||||
foreach ($v as $obj)
|
||||
{
|
||||
$name = $obj->vorgesetzter;
|
||||
|
||||
if (!array_key_exists($name, $toSend))
|
||||
{
|
||||
$toSend[$name] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$toSend[$name] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $toSend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Mitarbeiter Names that have yet to send Timesheets of Last Month
|
||||
* @return array - array of Strings (mitarbeiter uids)
|
||||
*/
|
||||
private function _getEmployeeTimesheetList()
|
||||
{
|
||||
$mResult = $this->TimesheetModel->getUidofMissingTimesheetsLastMonth();
|
||||
$mitarbeiterList = getData($mResult);
|
||||
|
||||
$names = array();
|
||||
|
||||
foreach ($mitarbeiterList as $mitarbeiter)
|
||||
{
|
||||
$uid = $mitarbeiter->uid;
|
||||
if($this->MitarbeiterModel->isMitarbeiter($uid))
|
||||
$names [$uid] = $uid;
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Mitarbeiter Names that have yet to record last weeks times
|
||||
* @return array - array of Strings (mitarbeiter uids)
|
||||
*/
|
||||
private function _getEmployeeLastWeeksTimeList()
|
||||
{
|
||||
$mitarbeiter = $this->MitarbeiterModel->getPersonal(true,null,true)->retval;
|
||||
$zeitaufzeichnungLastWeek = $this->ZeitaufzeichnungModel->zeitaufzeichnungExistsForLastWeekList()->retval;
|
||||
$mitarbeiterLastWeekExists = array();
|
||||
$uids = array();
|
||||
|
||||
foreach ($zeitaufzeichnungLastWeek as $name)
|
||||
{
|
||||
$mitarbeiterLastWeekExists[] = $name->uid;
|
||||
}
|
||||
|
||||
foreach ($mitarbeiter as $ma)
|
||||
{
|
||||
$uid = $ma->uid;
|
||||
if(!in_array($uid,$mitarbeiterLastWeekExists))
|
||||
{
|
||||
$uids[$uid] = $uid;
|
||||
}
|
||||
}
|
||||
return $uids;
|
||||
}
|
||||
|
||||
private function _getEmplyeeUids()
|
||||
{
|
||||
$mitarbeiter = $this->MitarbeiterModel->getEmployeesZeitaufzeichnungspflichtig()->retval;
|
||||
$mitarbeiterUIDs = array();
|
||||
|
||||
foreach ($mitarbeiter as $ma)
|
||||
{
|
||||
$mitarbeiterObj = new StdClass();
|
||||
$mitarbeiterObj->uid = $ma->mitarbeiter_uid;
|
||||
//$mitarbeiterObj->vorname = $ma->vorname;
|
||||
$mitarbeiterObj->SupVac = false;
|
||||
$mitarbeiterObj->SupMonth = false;
|
||||
$mitarbeiterObj->EmpMonth = false;
|
||||
$mitarbeiterObj->EmpWeek = false;
|
||||
$mitarbeiterObj->EmpZeitMod = false;
|
||||
|
||||
array_push($mitarbeiterUIDs, $mitarbeiterObj);
|
||||
}
|
||||
|
||||
return $mitarbeiterUIDs;
|
||||
}
|
||||
|
||||
private function _filterMitarbeiter($allMitarbeiter)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -202,4 +202,11 @@ class Mitarbeiter_model extends DB_Model
|
||||
}
|
||||
return success($kurzbz);
|
||||
}
|
||||
|
||||
public function getEmployeesZeitaufzeichnungspflichtig()
|
||||
{
|
||||
$qry = "SELECT DISTINCT mitarbeiter_uid FROM bis.tbl_bisverwendung WHERE beginn <= now() and (ende >= now() OR ende is NULL) AND zeitaufzeichnungspflichtig is TRUE
|
||||
ORDER BY mitarbeiter_uid";
|
||||
return $this->execQuery($qry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
class Timesheet_model extends DB_Model
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'addon.tbl_casetime_timesheet';
|
||||
$this->pk = 'timesheet_id';
|
||||
}
|
||||
|
||||
public function getPendingTimesheets()
|
||||
{
|
||||
$qry = "SELECT
|
||||
DISTINCT uid
|
||||
FROM addon.tbl_casetime_timesheet
|
||||
WHERE abgeschicktamum IS NOT NULL
|
||||
AND genehmigtamum IS NULL
|
||||
ORDER BY uid";
|
||||
return $this->execQuery($qry);
|
||||
}
|
||||
|
||||
public function getUidofMissingTimesheetsLastMonth()
|
||||
{
|
||||
$qry = "SELECT
|
||||
DISTINCT uid
|
||||
FROM addon.tbl_casetime_timesheet
|
||||
WHERE date_trunc('month',datum) = (date_trunc('month', current_date-interval '1' month))
|
||||
AND abgeschicktamum IS NULL
|
||||
ORDER BY uid";
|
||||
return $this->execQuery($qry);
|
||||
}
|
||||
|
||||
public function getAllMissingZeitmodelle()
|
||||
{
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
$url = 'http://10.129.0.19:8080/sync/get_all_missing_zeitmodelle';
|
||||
|
||||
//$fields_string = '';
|
||||
curl_setopt($ch, CURLOPT_URL, $url ); //Url together with parameters
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Return data instead printing directly in Browser
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 7); //Timeout after 7 seconds
|
||||
curl_setopt($ch, CURLOPT_USERAGENT , "FH-Complete CaseTime Addon");
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
if(curl_errno($ch))
|
||||
{
|
||||
//print_r($ch);
|
||||
return 'Curl error: ' . curl_error($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
curl_close($ch);
|
||||
$data = json_decode($result);
|
||||
|
||||
if(isset($data->STATUS) && $data->STATUS=='OK')
|
||||
{
|
||||
//print_r($data);
|
||||
return $data->RESULT;
|
||||
}
|
||||
else
|
||||
//print_r($data);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,10 +15,21 @@ class Zeitaufzeichnung_model extends DB_Model
|
||||
public function deleteEntriesForCurrentDay()
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$qry = "DELETE FROM " . $this->dbTable . "
|
||||
WHERE start >= '" . $today . " 00:00:00'
|
||||
$qry = "DELETE FROM " . $this->dbTable . "
|
||||
WHERE start >= '" . $today . " 00:00:00'
|
||||
AND start <= '" . $today . " 23:59:59';";
|
||||
|
||||
return $this->execQuery($qry);
|
||||
}
|
||||
|
||||
public function zeitaufzeichnungExistsForLastWeekList()
|
||||
{
|
||||
$qry = "SELECT
|
||||
DISTINCT uid
|
||||
FROM campus.tbl_zeitaufzeichnung
|
||||
WHERE date_trunc('day',ende) >= (date_trunc('day', current_date-interval '7' day));";
|
||||
|
||||
return $this->execQuery($qry);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,24 @@ class Zeitsperre_model extends DB_Model
|
||||
public function deleteEntriesForCurrentDay()
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$qry = "DELETE FROM " . $this->dbTable . "
|
||||
$qry = "DELETE FROM " . $this->dbTable . "
|
||||
WHERE vondatum = '" . $today . "';";
|
||||
|
||||
return $this->execQuery($qry);
|
||||
}
|
||||
|
||||
public function getMitarbeiterListWithPendingVacation()
|
||||
{
|
||||
$qry = "SELECT
|
||||
DISTINCT mitarbeiter_uid
|
||||
FROM
|
||||
campus.tbl_zeitsperre
|
||||
WHERE
|
||||
freigabeamum is NULL
|
||||
AND zeitsperretyp_kurzbz='Urlaub'
|
||||
AND vondatum>=now()
|
||||
ORDER BY mitarbeiter_uid ASC;";
|
||||
return $this->execQuery($qry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user