diff --git a/application/controllers/jobs/ZeiterfassungInfoJob.php b/application/controllers/jobs/ZeiterfassungInfoJob.php
new file mode 100644
index 000000000..d4e924468
--- /dev/null
+++ b/application/controllers/jobs/ZeiterfassungInfoJob.php
@@ -0,0 +1,313 @@
+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: Urlaubstool
' : '';
+ $ma->SupMonth ? $SupMonth = '->Du hast noch Monatslisten freizugeben. Du findest die Monatslistenfreigabe unter: Monatslisten
' : '';
+ $ma->EmpMonth ? $EmpMonth = '->Du musst noch die Monatsliste von letztem Monat abschicken.
' : '';
+ $ma->EmpWeek ? $EmpWeek = '->Du musst noch Zeiten für letzte Woche eintragen.
' : '';
+ $ma->EmpZeitMod ? $EmpZeitMod = '->Du hast noch kein Zeitmodell hinterlegt.
' : '';
+
+ // 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)
+ {
+ }
+
+
+}
diff --git a/application/models/ressource/Mitarbeiter_model.php b/application/models/ressource/Mitarbeiter_model.php
index 90c30927f..fc8378988 100644
--- a/application/models/ressource/Mitarbeiter_model.php
+++ b/application/models/ressource/Mitarbeiter_model.php
@@ -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);
+ }
}
diff --git a/application/models/ressource/Timesheet_model.php b/application/models/ressource/Timesheet_model.php
new file mode 100644
index 000000000..5c3e96a5d
--- /dev/null
+++ b/application/models/ressource/Timesheet_model.php
@@ -0,0 +1,77 @@
+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;
+ }
+ }
+ }
+
+}
diff --git a/application/models/ressource/Zeitaufzeichnung_model.php b/application/models/ressource/Zeitaufzeichnung_model.php
index b44861d13..a961705c7 100644
--- a/application/models/ressource/Zeitaufzeichnung_model.php
+++ b/application/models/ressource/Zeitaufzeichnung_model.php
@@ -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);
+
+ }
}
diff --git a/application/models/ressource/Zeitsperre_model.php b/application/models/ressource/Zeitsperre_model.php
index 078d29d8b..467d05d09 100644
--- a/application/models/ressource/Zeitsperre_model.php
+++ b/application/models/ressource/Zeitsperre_model.php
@@ -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);
+ }
+
}