diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index 803e070ba..07fa2e9c7 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -39,21 +39,11 @@ class Status extends FHCAPI_Controller public function getHistoryPrestudent($prestudent_id) { - $this->load->model('system/Sprache_model', 'SpracheModel'); - $this->SpracheModel->addSelect('index'); - $result = $this->SpracheModel->loadWhere(array('sprache' => getUserLanguage())); + $result = $this->PrestudentstatusModel->getHistoryPrestudent($prestudent_id); - // Return language index - $lang = hasData($result) ? getData($result)[0]->index : 1; + $data = $this->getDataOrTerminateWithError($result); - $this->load->model('crm/Prestudent_model', 'PrestudentModel'); - - $result = $this->PrestudentModel->getHistoryPrestudent($prestudent_id, $lang); - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess((getData($result) ?: [])); + $this->terminateWithSuccess($data); } public function getStatusgruende() @@ -72,10 +62,9 @@ class Status extends FHCAPI_Controller $this->load->model('codex/Bismeldestichtag_model', 'BismeldestichtagModel'); $result = $this->BismeldestichtagModel->getLastReachedMeldestichtag(); - if (isError($result)) { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - return $this->terminateWithSuccess($result); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); } public function isLastStatus($prestudent_id) diff --git a/application/libraries/PrestudentstatusCheckLib.php b/application/libraries/PrestudentstatusCheckLib.php index 3b191619f..b238219a8 100644 --- a/application/libraries/PrestudentstatusCheckLib.php +++ b/application/libraries/PrestudentstatusCheckLib.php @@ -106,7 +106,7 @@ class PrestudentstatusCheckLib $status_kurzbz, $tudiensemester_kurzbz, $ausbildungssemester - ) + ) { $resultApp = $this->_getApplicationData($prestudent_id); if(isError($resultApp)) @@ -140,7 +140,7 @@ class PrestudentstatusCheckLib * @return error if invalid * @return error, if role does not exist, else count(roles) if it does */ - public function checkIfExistingStudentRolle($prestudent_id) + public function checkIfExistingStudentRolle($prestudent_id) { $resultApp = $this->_getApplicationData($prestudent_id); if(isError($resultApp)) @@ -169,7 +169,7 @@ class PrestudentstatusCheckLib * @param integer $prestudent_id * @return booleans $reihungstest_angetreten, error if not angetreten */ - public function checkIfAngetreten($prestudent_id) + public function checkIfAngetreten($prestudent_id) { $result = $this->_getApplicationData($prestudent_id); if(isError($result)) @@ -190,7 +190,7 @@ class PrestudentstatusCheckLib * @param integer $prestudent_id * @return booleans $zgv_code, error if not registered */ - public function checkIfZGVEingetragen($prestudent_id, $typ=null) + public function checkIfZGVEingetragen($prestudent_id, $typ=null) { $result = $this->_getApplicationData($prestudent_id); if(isError($result)) @@ -201,18 +201,18 @@ class PrestudentstatusCheckLib $studentName = trim ($result->vorname.' '.$result->nachname); if ($typ && $typ=='m' && !$result->zgvmas_code) - { + { return error($this->_ci->p->t('lehre', 'error_ZGVMasterNichtEingetragen', ['name' => $studentName])); } else return success($result->zgvmas_code); - + if(!$result->zgv_code) - { + { return error($this->_ci->p->t('lehre', 'error_ZGVNichtEingetragen', ['name' => $studentName])); } - + return success($result->zgv_code); } @@ -221,7 +221,7 @@ class PrestudentstatusCheckLib * @return error if invalid * @return error if no bewerberstatus, success otherwise */ - public function checkIfExistingBewerberstatus($prestudent_id) + public function checkIfExistingBewerberstatus($prestudent_id) { $result = $this->_getApplicationData($prestudent_id); if(isError($result)) @@ -239,7 +239,7 @@ class PrestudentstatusCheckLib return getData($result); } if(getData($result) == "0") - { + { return error($this->_ci->p->t('lehre','error_keinBewerber', ['name' => $studentName])); } return success(getData($result)); @@ -258,7 +258,7 @@ class PrestudentstatusCheckLib return getData($result); } if(getData($result) == "1") - { + { return error($this->_ci->p->t('lehre','error_dataVorMeldestichtag')); } return success(getData($result)); @@ -325,23 +325,53 @@ class PrestudentstatusCheckLib $new_status_datum_form = new DateTime($new_status_datum); $new_status_semesterstart_form = new DateTime($new_status_semesterstart); - $neuer_status = new stdClass(); - $neuer_status->status_kurzbz = $status_kurzbz; - $neuer_status->studiensemester_kurzbz = $new_status_studiensemester_kurzbz; - $neuer_status->datum = $new_status_datum; - $neuer_status->ausbildungssemester = $new_status_ausbildungssemester; - $neuer_status->studienplan_orgform_kurzbz = $new_studienplan_orgform_kurzbz; + if (!isEmptyArray($resultArr)) + { + // neuen Status zum Hinzufügen + $first_status = $resultArr[0]; + $neuer_status = new stdClass(); + $neuer_status->status_kurzbz = $status_kurzbz; + $neuer_status->studiensemester_kurzbz = $new_status_studiensemester_kurzbz; + $neuer_status->datum = $new_status_datum; + $neuer_status->ausbildungssemester = $new_status_ausbildungssemester; + $neuer_status->studienplan_orgform_kurzbz = $new_studienplan_orgform_kurzbz; + $neuer_status->matrikelnr = $first_status->matrikelnr; + $neuer_status->vorname = $first_status->vorname; + $neuer_status->nachname = $first_status->nachname; + + // Status, welcher gerade geändert wird, holen + $status_to_change = array_filter( + $resultArr, + function ($status) use ($status_kurzbz, $old_status_studiensemester, $old_status_ausbildungssemester) { + return + $status->status_kurzbz == $status_kurzbz + && $status->studiensemester_kurzbz == $old_status_studiensemester + && $status->ausbildungssemester == $old_status_ausbildungssemester; + } + ); + + if (!isEmptyArray($status_to_change)) + { + $status_to_change_index = key($status_to_change); + + // wenn sich Studiensemester und Ausbildungssemester nicht geändert haben... + if ($new_status_studiensemester_kurzbz == $old_status_studiensemester + && $new_status_ausbildungssemester == $old_status_ausbildungssemester) + { + // ...neuen status an selber stelle einfügen wie zu ändernder Status + $resultArr[$status_to_change_index] = (object) array_merge((array) $resultArr[$status_to_change_index], (array) $neuer_status); + $newStatusInserted = true; + } + else + { + // bei Status mit neuem Semester: alten Status entfernen + unset($resultArr[$status_to_change_index]); + } + } + } foreach ($resultArr as $row) { - // Status, der gerade in Bearbeitung ist, überspringen - if (isset($old_status_studiensemester) - && isset($old_status_ausbildungssemester) - && $row->status_kurzbz == $status_kurzbz - && $row->studiensemester_kurzbz == $old_status_studiensemester - && $row->ausbildungssemester == $old_status_ausbildungssemester) - continue; - $studiensemester_start = new DateTime($row->studiensemester_start); $status_datum = new DateTime($row->datum); @@ -350,15 +380,6 @@ class PrestudentstatusCheckLib if (!$newStatusInserted) { // neuer Status erstmals größer als Datum eines bestehenden Status -> neuen Status EINMALIG einfügen für spätere Statusprüfung - $neuer_status = new stdClass(); - $neuer_status->status_kurzbz = $status_kurzbz; - $neuer_status->studiensemester_kurzbz = $new_status_studiensemester_kurzbz; - $neuer_status->datum = $new_status_datum; - $neuer_status->ausbildungssemester = $new_status_ausbildungssemester; - $neuer_status->studienplan_orgform_kurzbz = $new_studienplan_orgform_kurzbz; - $neuer_status->matrikelnr = $row->matrikelnr; - $neuer_status->vorname = $row->vorname; - $neuer_status->nachname = $row->nachname; $statusArr[] = $neuer_status; $newStatusInserted = true; } @@ -478,10 +499,10 @@ class PrestudentstatusCheckLib * @param integer $prestudent_id * @return error if not valid, array with ApplicationData if valid */ - private function _getApplicationData($prestudent_id) + private function _getApplicationData($prestudent_id) { $this->_ci->PrestudentModel->addJoin('public.tbl_person p', 'ON (p.person_id = public.tbl_prestudent.person_id)'); - + $result = $this->_ci->PrestudentModel->load([ 'prestudent_id'=> $prestudent_id, ]); diff --git a/application/models/codex/Bismeldestichtag_model.php b/application/models/codex/Bismeldestichtag_model.php index 6c0858b35..bc01f6673 100644 --- a/application/models/codex/Bismeldestichtag_model.php +++ b/application/models/codex/Bismeldestichtag_model.php @@ -13,38 +13,24 @@ class Bismeldestichtag_model extends DB_Model public function getLastReachedMeldestichtag($studiensemester_kurzbz = null) { - $qry = " - SELECT - meldestichtag_id, meldestichtag, studiensemester_kurzbz, insertamum, insertvon, updateamum, updatevon - FROM - bis.tbl_bismeldestichtag - WHERE - meldestichtag < NOW() - "; + $this->addSelect('meldestichtag_id'); + $this->addSelect('meldestichtag'); + $this->addSelect('studiensemester_kurzbz'); + $this->addSelect('insertamum'); + $this->addSelect('insertvon'); + $this->addSelect('updateamum'); + $this->addSelect('updatevon'); - if (isset($studiensemester_kurzbz)) - { - $qry .= " - AND - studiensemester_kurzbz= ?"; + if ($studiensemester_kurzbz) { + $this->db->where('studiensemester_kurzbz', $studiensemester_kurzbz); } - $qry .= " - ORDER BY - meldestichtag DESC - LIMIT 1;"; - - $result = $this->execQuery($qry, array($studiensemester_kurzbz)); - - if (isError($result)) - { - return error($result); - } - if (!hasData($result)) { - return success("0",'Kein Meldestichtag vorhanden'); - } - return $result; + $this->addOrder('meldestichtag', 'DESC'); + $this->addLimit(1); + return $this->loadWhere([ + 'meldestichtag < NOW()' => null + ]); } /** diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index b783715c2..9721e473f 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -727,62 +727,4 @@ class Prestudent_model extends DB_Model return $this->execQuery($query, array($person_id)); } - - /** - * Gets history of prestudent, prestudent_id given - * @param int $prestudent_id - * @return object - */ - public function getHistoryPrestudent($prestudent_id, $index_lang) - { - $query = " - SELECT - ps.status_kurzbz, - ps.studiensemester_kurzbz, - ps.ausbildungssemester, - CASE WHEN ps.status_kurzbz IN ('Student', 'Diplomand','Abbrecher','Unterbrecher') - THEN CONCAT(lv.semester, lv.verband, lv.gruppe) - ELSE '' - END AS lehrverband, - ps.datum, - TO_CHAR(ps.datum::timestamp, 'DD.MM.YYYY') AS format_datum, - sp.bezeichnung, - ps.bestaetigtam, - TO_CHAR(ps.bestaetigtam::timestamp, 'DD.MM.YYYY') AS format_bestaetigtam, - ps.bewerbung_abgeschicktamum, - TO_CHAR(ps.bewerbung_abgeschicktamum::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS format_bewerbung_abgeschicktamum, - stg.statusgrund_kurzbz, - ps.orgform_kurzbz, - ps.prestudent_id, - sp.studienplan_id, - ps.anmerkung, - ps.bestaetigtvon, - ps.insertamum, - TO_CHAR(ps.insertamum::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS format_insertamum, - ps.insertvon, - ps.updateamum, - TO_CHAR(ps.updateamum::timestamp, 'DD.MM.YYYY HH24:MI:SS') AS format_updateamum, - ps.updatevon, - stg.beschreibung[?] as statusgrund_beschreibung - FROM - public.tbl_prestudentstatus ps - LEFT JOIN - public.tbl_student st USING (prestudent_id) - LEFT JOIN - public.tbl_studiengang sg ON (st.studiengang_kz = sg.studiengang_kz) - LEFT JOIN - lehre.tbl_studienplan sp USING (studienplan_id) - LEFT JOIN - public.tbl_status_grund stg USING (statusgrund_id) - LEFT JOIN - public.tbl_studentlehrverband lv ON - (st.student_uid = lv.student_uid - AND st.student_uid IS NOT NULL - AND lv.studiensemester_kurzbz = ps.studiensemester_kurzbz) - WHERE prestudent_id = ? - ORDER BY ps.datum DESC, ps.insertamum DESC, ps.ext_id DESC - "; - - return $this->execQuery($query, array($index_lang, $prestudent_id)); - } } diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 5223d5764..dac5fbb23 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -514,4 +514,70 @@ class Prestudentstatus_model extends DB_Model return $this->execQuery($qry, array($prestudent_id)); } + + /** + * Gets status history of a prestudent + * This function uses the language of the logged in user to + * translate the given statusgrund + * + * @param integer $prestudent_id + * + * @return stdClass + */ + public function getHistoryPrestudent($prestudent_id) + { + $this->addSelect('tbl_prestudentstatus.prestudent_id'); + $this->addSelect('tbl_prestudentstatus.status_kurzbz'); + $this->addSelect('tbl_prestudentstatus.studiensemester_kurzbz'); + $this->addSelect('tbl_prestudentstatus.ausbildungssemester'); + $this->addSelect('tbl_prestudentstatus.datum'); + $this->addSelect('tbl_prestudentstatus.insertamum'); + $this->addSelect('tbl_prestudentstatus.insertvon'); + $this->addSelect('tbl_prestudentstatus.updateamum'); + $this->addSelect('tbl_prestudentstatus.updatevon'); + $this->addSelect('tbl_prestudentstatus.orgform_kurzbz'); + $this->addSelect('tbl_prestudentstatus.bestaetigtam'); + $this->addSelect('tbl_prestudentstatus.bestaetigtvon'); + $this->addSelect('tbl_prestudentstatus.bewerbung_abgeschicktamum'); + $this->addSelect('tbl_prestudentstatus.anmerkung'); + $this->addSelect('plan.studienplan_id'); + $this->addSelect('plan.bezeichnung'); + $this->addSelect('grund.beschreibung[( + SELECT index + FROM public.tbl_sprache + WHERE sprache=' . $this->escape(getUserLanguage()) . ' + )] AS statusgrund_bezeichnung', false); + $this->addSelect("CASE + WHEN s.student_uid IS NOT NULL + AND tbl_prestudentstatus.status_kurzbz IN (" . implode(",", $this->escape([ + 'Student', + 'Diplomand', + 'Abbrecher', + 'Absolvent', + 'Ausserodentlicher', + 'Incoming', + 'Outgoing', + 'Unterbrecher' + ])) . ") + THEN lv.semester || lv.verband || lv.gruppe + ELSE '-' + END AS lehrverband", false); + + $this->addJoin('lehre.tbl_studienplan plan', 'studienplan_id', 'LEFT'); + $this->addJoin('public.tbl_status_grund grund', 'statusgrund_id', 'LEFT'); + $this->addJoin('public.tbl_student s', 'prestudent_id', 'LEFT'); + $this->addJoin( + 'public.tbl_studentlehrverband lv', + 's.student_uid IS NOT NULL AND s.student_uid=lv.student_uid AND tbl_prestudentstatus.studiensemester_kurzbz=lv.studiensemester_kurzbz', + 'LEFT' + ); + + $this->addOrder('tbl_prestudentstatus.datum', 'DESC'); + $this->addOrder('tbl_prestudentstatus.insertamum', 'DESC'); + $this->addOrder('tbl_prestudentstatus.ext_id', 'DESC'); + + return $this->loadWhere([ + 'tbl_prestudentstatus.prestudent_id' => $prestudent_id + ]); + } } diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js b/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js index b8002b64e..ae5a98958 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Prestudent/MultiStatus.js @@ -199,7 +199,6 @@ export default{ if (this.dataMeldestichtag && this.dataMeldestichtag > rowData.datum) { row.getElement().classList.add('disabled'); - } }, layout: 'fitDataFill', @@ -754,9 +753,10 @@ export default{ .catch(this.$fhcAlert.handleSystemError); this.$fhcApi .get('api/frontend/v1/stv/status/getLastBismeldestichtag/') - .then(result => result.data) .then(result => { - this.dataMeldestichtag = result.retval[0].meldestichtag; + this.dataMeldestichtag = result.data[0].meldestichtag; + if (this.$refs.table.tableBuilt) + this.$refs.table.tabulator.redraw(true); }) .catch(this.$fhcAlert.handleSystemError); },