From 51486145d8f5eaeb67b53126819e750d9b700312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Tue, 14 Feb 2023 11:51:34 +0100 Subject: [PATCH] Timesheet Model und Zeiterfassungjob in Extension verschoben --- .../controllers/jobs/ZeiterfassungInfoJob.php | 477 ------------------ .../project/Projekt_ressource_model.php | 21 +- .../models/ressource/Mitarbeiter_model.php | 12 +- .../models/ressource/Timesheet_model.php | 74 --- 4 files changed, 23 insertions(+), 561 deletions(-) delete mode 100644 application/controllers/jobs/ZeiterfassungInfoJob.php delete mode 100644 application/models/ressource/Timesheet_model.php diff --git a/application/controllers/jobs/ZeiterfassungInfoJob.php b/application/controllers/jobs/ZeiterfassungInfoJob.php deleted file mode 100644 index 81efea602..000000000 --- a/application/controllers/jobs/ZeiterfassungInfoJob.php +++ /dev/null @@ -1,477 +0,0 @@ -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'); - $this->load->model('person/Person_model', 'PersonModel'); - $this->load->model('project/Projekt_ressource_model', 'ProjektRessourceModel'); - - // 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 - * f) Emplyoyees, who are projectleaders - */ - 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(); - - $mitarbeiter_without_zeitmodell = $this->_filterMitarbeiter(); - $mitarbeiter_projektleiter = $this->_getProjektleiter(); - - $cnt_sup_to_approve_vacation = 0; - $cnt_sup_to_approve_timesheets = 0; - $cnt_ma_to_send_timesheet = 0; - $cnt_ma_to_record_times_lastweek = 0; - $cnt_ma_without_zeitmodell = 0; - $cnt_ma_projektleitend = 0; - $cnt_mails_total = 0; - - $mailingList = array(); - - foreach ($allMitarbeiter as $ma) - { - $uid = $ma->uid; - if(array_key_exists($uid, $vorgesetzte_to_approve_vacation)) - { - $ma->SupVac = true; - $cnt_sup_to_approve_vacation++; - } - else - { - $ma->SupVac = false; - } - if(array_key_exists($uid, $vorgesetzte_to_approve_timesheets)) - { - $ma->SupMonth = true; - $cnt_sup_to_approve_timesheets++; - } - else - { - $ma->SupMonth = false; - } - if(array_key_exists($uid, $mitarbeiter_to_send_timesheet_lastmonth)) - { - $ma->EmpMonth = true; - $cnt_ma_to_send_timesheet++; - } - else - { - $ma->EmpMonth = false; - } - if(array_key_exists($uid, $mitarbeiter_to_record_times_lastweek)) - { - $ma->EmpWeek = true; - $cnt_ma_to_record_times_lastweek++; - } - else - { - $ma->EmpWeek = false; - } - if(array_key_exists($uid, $mitarbeiter_without_zeitmodell)) - { - $ma->EmpZeitMod = true; - $cnt_ma_without_zeitmodell++; - } - else - { - $ma->EmpZeitMod = false; - } - //projektleiter - if(array_key_exists($uid, $mitarbeiter_projektleiter)) - { - $ma->EmpProLei = true; - $cnt_ma_projektleitend++; - } - else - { - $ma->EmpProLei = false; - } - - if($ma->SupVac || $ma->SupMonth || $ma->EmpMonth || $ma->EmpWeek || $ma->EmpZeitMod || $ma->EmpProLei) - { - array_push($mailingList, $ma); - $cnt_mails_total++; - } - } - $start = date("h:i:sa"); - - // Loop through 'container' of mail recipients - foreach ($mailingList as $ma) - { - // Set mail recipient - $to = $ma->uid.'@'. DOMAIN; - - $ma_name = getData($this->PersonModel->getFullName($ma->uid)); - $supVac =''; - $SupMonth =''; - $EmpMonth =''; - $EmpWeek =''; - $EmpZeitMod =''; - $EmpProLei =''; - - if(array_key_exists($ma->uid, $mitarbeiter_projektleiter)) - { - $projekteMa = implode(', ', $mitarbeiter_projektleiter[$ma->uid]); - } - - //Generate Email Text - $ma->SupVac ? $supVac = 'Du hast noch Urlaube freizugeben. Du findest die Urlaubsfreigabe 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.

' : ''; - $ma->EmpProLei ? $EmpProLei = 'Bitte kontrolliere die Aufzeichnungen deiner Projekte ('. $projekteMa. '): - Projektaufzeichnungen

' : ''; - - - // Prepare mail content - $content_data_arr = array( - 'ma_name' => $ma_name, - 'SupVac' => $supVac, - 'SupMonth' => $SupMonth, - 'EmpMonth' => $EmpMonth, - 'EmpWeek' => $EmpWeek, - 'EmpZeitMod' => $EmpZeitMod, - 'EmpProLei' => $EmpProLei - ); - - sendSanchoMail( - 'Sancho_InfoMailZeiterfassung', - $content_data_arr, - $to, - 'Zeiterfassung Erinnerung', - DEFAULT_SANCHO_HEADER_IMG, - DEFAULT_SANCHO_FOOTER_IMG - ); - } - $end = date("h:i:sa"); - - //Logs Viewer - $this->logInfo('START Job Report: Infomail Zeiterfassung (' . $start . ')'); - $this->logInfo($cnt_sup_to_approve_vacation . " Urlaub(e) freizugeben"); - $this->logInfo($cnt_sup_to_approve_timesheets . " Monatsliste(n) zu bestaetigen"); - $this->logInfo($cnt_ma_to_send_timesheet ." Monatsliste(n) abzuschicken"); - $this->logInfo($cnt_ma_to_record_times_lastweek ." fehlende Zeitaufzeichnung(en) letzte Woche"); - $this->logInfo($cnt_ma_without_zeitmodell . " Zeitmodell(e) nicht hinterlegt "); - $this->logInfo($cnt_ma_projektleitend . " projektleitende(r) Mitarbeiter*in"); - $this->logInfo($cnt_mails_total . " gesendete Mails Total"); - $this->logInfo("ENDE Job Report: Infomail Zeiterfassung (" . $end . ")"); - - 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(); - $toSend = array(); - if (hasData($mResult)) - { - $mitarbeiterList = getData($mResult); - $vorgesetzte = 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; - } - } - } - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - 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(); - if (hasData($mResult)) - { - $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; - } - } - } - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - 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(); - $names = array(); - if (hasData($mResult)) - { - $mitarbeiterList = getData($mResult); - $cnt_timesheetsToSend = 0; - - foreach ($mitarbeiterList as $mitarbeiter) - { - $uid = $mitarbeiter->uid; - if($this->MitarbeiterModel->isMitarbeiter($uid)) - { - $names[$uid] = $uid; - $cnt_timesheetsToSend++; - } - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - return $names; - } - - /** - * Get all Mitarbeiter Names that have yet to record last weeks times - * @return array - array of Strings (mitarbeiter uids) - */ - private function _getEmployeeLastWeeksTimeList() - { - $mResult = $this->MitarbeiterModel->getPersonal(true, null, true); - $mitarbeiter = getData($mResult); - $zResult = $this->ZeitaufzeichnungModel->zeitaufzeichnungExistsForLastWeekList(); - $zeitaufzeichnungLastWeek = getData($zResult); - $mitarbeiterLastWeekExists = array(); - $uids = array(); - - if (hasData($zResult)) - { - foreach ($zeitaufzeichnungLastWeek as $name) - { - $mitarbeiterLastWeekExists[] = $name->uid; - } - } - elseif (isError($zResult)) - { - show_error(getError($zResult)); - } - - if (hasData($mResult)) - { - foreach ($mitarbeiter as $ma) - { - $uid = $ma->uid; - if(!in_array($uid, $mitarbeiterLastWeekExists)) - { - $uids[$uid] = $uid; - } - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - return $uids; - } - - private function _getEmplyeeUids() - { - $mResult = $this->MitarbeiterModel->getEmployeesZeitaufzeichnungspflichtig(); - $mitarbeiter = getData($mResult); - $mitarbeiterUIDs = array(); - - if (hasData($mResult)) - { - foreach ($mitarbeiter as $ma) - { - $mitarbeiterObj = new StdClass(); - $mitarbeiterObj->uid = $ma->mitarbeiter_uid; - $mitarbeiterObj->SupVac = false; - $mitarbeiterObj->SupMonth = false; - $mitarbeiterObj->EmpMonth = false; - $mitarbeiterObj->EmpWeek = false; - $mitarbeiterObj->EmpZeitMod = false; - - array_push($mitarbeiterUIDs, $mitarbeiterObj); - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - return $mitarbeiterUIDs; - } - - - private function _filterMitarbeiter() - { - $mResult = $this->MitarbeiterModel->getPersonal(true, null, true); - $mitarbeiter = getData($mResult); - - $zResult = $this->TimesheetModel->getAllMissingZeitmodelle(); - $zeitmodelle = $zResult[1]; - - $mitarbeiterWithoutZeitmodell = array(); - $uids = array(); - - if (!is_null($zResult)) - { - foreach ($zeitmodelle as $zm) - { - array_push($uids, strtolower($zm[0])); - } - } - if (hasData($mResult)) - { - foreach ($mitarbeiter as $ma) - { - $uid = $ma->uid; - if(!in_array($uid, $uids)) - { - $mitarbeiterWithoutZeitmodell[$uid] = $uid; - } - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - - return $mitarbeiterWithoutZeitmodell; - } - - private function _getProjektleiter() - { - $mResult = $this->MitarbeiterModel->getEmployeesZeitaufzeichnungspflichtig(); - $mitarbeiter = getData($mResult); - - $pResult = $this->ProjektRessourceModel->getProjektleiterActiveProjects(); - $projektleiter = getData($pResult); - - $projektleitendeMitarbeiter = array(); - if(hasData($pResult) && hasData($mResult)) - { - foreach ($projektleiter as $pl) - { - foreach ($mitarbeiter as $ma) - { - if($pl->mitarbeiter_uid == $ma->mitarbeiter_uid) - { - $projektleitendeMitarbeiter[$pl->mitarbeiter_uid][]= $pl->titel; - } - } - } - } - elseif (isError($mResult)) - { - show_error(getError($mResult)); - } - elseif (isError($pResult)) - { - show_error(getError($pResult)); - } - return $projektleitendeMitarbeiter; - } -} diff --git a/application/models/project/Projekt_ressource_model.php b/application/models/project/Projekt_ressource_model.php index 0ca33e0ed..aed5e8056 100644 --- a/application/models/project/Projekt_ressource_model.php +++ b/application/models/project/Projekt_ressource_model.php @@ -14,13 +14,18 @@ class Projekt_ressource_model extends DB_Model public function getProjektleiterActiveProjects() { - $qry = "SELECT DISTINCT r.mitarbeiter_uid, p.projekt_kurzbz, p.titel - FROM fue.tbl_projekt p - JOIN fue.tbl_projekt_ressource pr using (projekt_kurzbz) - JOIN fue.tbl_ressource r on (pr.ressource_id = r.ressource_id) - wHERE((p.beginn<=now() or p.beginn is null) - AND (p.ende >=now() OR p.ende is null)) - AND pr.funktion_kurzbz = 'Leitung'"; - return $this->execQuery($qry); + $qry = " + SELECT DISTINCT + r.mitarbeiter_uid, p.projekt_kurzbz, p.titel + FROM + fue.tbl_projekt p + JOIN fue.tbl_projekt_ressource pr using (projekt_kurzbz) + JOIN fue.tbl_ressource r on (pr.ressource_id = r.ressource_id) + wHERE + ((p.beginn<=now() or p.beginn is null) + AND (p.ende >=now() OR p.ende is null)) + AND pr.funktion_kurzbz = 'Leitung' + "; + return $this->execQuery($qry); } } diff --git a/application/models/ressource/Mitarbeiter_model.php b/application/models/ressource/Mitarbeiter_model.php index fc8378988..7f288ce4e 100644 --- a/application/models/ressource/Mitarbeiter_model.php +++ b/application/models/ressource/Mitarbeiter_model.php @@ -205,8 +205,16 @@ class Mitarbeiter_model extends DB_Model 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"; + $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 deleted file mode 100644 index 419b7f7fb..000000000 --- a/application/models/ressource/Timesheet_model.php +++ /dev/null @@ -1,74 +0,0 @@ -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)) - { - return 'Curl error: ' . curl_error($ch); - curl_close($ch); - } - else - { - curl_close($ch); - $data = json_decode($result); - - if(isset($data->STATUS) && $data->STATUS=='OK') - { - return $data->RESULT; - } - else - return $data; - } - } - } - -}