diff --git a/application/controllers/api/frontend/v1/stv/Pruefung.php b/application/controllers/api/frontend/v1/stv/Pruefung.php index e205c85b8..4521c2033 100644 --- a/application/controllers/api/frontend/v1/stv/Pruefung.php +++ b/application/controllers/api/frontend/v1/stv/Pruefung.php @@ -18,6 +18,8 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); +use \DateTime as DateTime; + /** * This controller operates between (interface) the JS (GUI) and the back-end * Provides data to the ajax get calls about addresses @@ -111,7 +113,7 @@ class Pruefung extends FHCAPI_Controller // Load language phrases $this->loadPhrases([ - 'global', 'ui','lehre' + 'global', 'ui', 'lehre', 'exam' ]); } @@ -172,174 +174,11 @@ class Pruefung extends FHCAPI_Controller * * @param lehrveranstaltung_id, student_uid, lehreinheit_id * - * @return values on success - * retval 0: pruefung inserted - * reval 1: pruefung and zeugnisnote inserted - * retval 2: pruefung inserted, no insert Zeugnisnote - * (change after date of examination) - * retval 3: pruefung of type Termin2 inserted - * and pruefung of type Termin1 as well - * retval 5: prueufungen Termin 2 and 1 inserted - * and no insert Zeugnisnote (change after date of examination) + * @return void */ public function insertPruefung() { - $authUID = getAuthUID(); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('lehrveranstaltung_id', $this->p->t('lehre', 'lehrveranstaltung'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehrveranstaltung')]), - ]); - $this->form_validation->set_rules('lehreinheit_id', $this->p->t('lehre', 'lehreinheit'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehreinheit')]), - ]); - $this->form_validation->set_rules('pruefungstyp_kurzbz', $this->p->t('lehre', 'pruefung'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('global', 'typ')]), - ]); - $this->form_validation->set_rules( - 'datum', - $this->p->t('global', 'datum'), - ['is_valid_date'] - ); - - if ($this->form_validation->run() == false) - { - $this->terminateWithValidationErrors($this->form_validation->error_array()); - } - - //calculate studiensemester_kurzbz this from lehreinheit (case newPruefung) - $studiensemester_kurzbz = $this->input->post('studiensemester_kurzbz'); - if (!$studiensemester_kurzbz) - { - $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); - - $result = $this->LehreinheitModel->load($this->input->post('lehreinheit_id')); - - $lehreinheit = $this->getDataOrTerminateWithError($result); - $studiensemester_kurzbz = current($lehreinheit)->studiensemester_kurzbz; - - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - } - - $result = $this->PruefungModel->insert([ - 'lehreinheit_id' => $this->input->post('lehreinheit_id'), - 'student_uid' => $this->input->post('student_uid'), - 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), - 'datum' => $this->input->post('datum'), - 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), - 'note' => $this->input->post('note'), - 'anmerkung' => $this->input->post('anmerkung'), - 'insertamum' => date('c'), - 'insertvon' => $authUID, - ]); - - $this->getDataOrTerminateWithError($result); - - //check if existing zeugnisnote - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); - - $result = $this->ZeugnisnoteModel->loadWhere(array( - 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), - 'student_uid' => $this->input->post('student_uid'), - 'studiensemester_kurzbz' => $studiensemester_kurzbz)); - - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - - if (!hasData($result)) - { - //insert zeugnisnote, if not existing - $result = $this->ZeugnisnoteModel->insert(array( - 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), - 'student_uid' => $this->input->post('student_uid'), - 'studiensemester_kurzbz' => $studiensemester_kurzbz, - 'note' => $this->input->post('note'), - 'uebernahmedatum' => date('c'), - 'benotungsdatum' => $this->input->post('datum'), - 'insertamum' => date('c'), - 'insertvon' => $authUID - )); - - if (isError($result)) - { - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - } - $this->terminateWithSuccess(1); - } - - $return_code = 0; - - //handling Termin1 if not existing - if($this->input->post('pruefungstyp_kurzbz') == "Termin2") - { - $resultP = $this->PruefungModel->loadWhere(array( - 'lehreinheit_id' => $this->input->post('lehreinheit_id'), - 'student_uid' => $this->input->post('student_uid'), - 'pruefungstyp_kurzbz' => 'Termin1')); - - if (isError($resultP)) - { - $this->terminateWithError(getError($resultP), self::ERROR_TYPE_GENERAL); - } - if(!hasData($resultP)) - { - //check if existing Zeugnisnote - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); - $this->ZeugnisnoteModel->addJoin('lehre.tbl_lehreinheit', 'lehrveranstaltung_id'); - - $resultP = $this->ZeugnisnoteModel->loadWhere(array( - 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), - 'student_uid' => $this->input->input->post('student_uid'), - 'lehre.tbl_zeugnisnote.studiensemester_kurzbz' => $studiensemester_kurzbz)); - if (isError($resultP)) - { - $this->terminateWithError(getError($resultP), self::ERROR_TYPE_GENERAL); - } - if (!hasData($resultP)) - { - $this->terminateWithError("Zeugnisnote existiert nicht", self::ERROR_TYPE_GENERAL); - } - $dataNote = current(getData($resultP)); - - $resultN = $this->PruefungModel->insert([ - 'lehreinheit_id' => $this->input->post('lehreinheit_id'), - 'student_uid' => $this->input->post('student_uid'), - 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), - 'datum' => $dataNote->benotungsdatum, - 'pruefungstyp_kurzbz' => 'Termin1', - 'note' => $dataNote->note, - 'punkte' => $dataNote->punkte, - 'anmerkung' => 'automatisiert aus Zeugnisnote erstellt', - 'insertamum' => date('c'), - 'insertvon' => $authUID, - ]); - - if (isError($resultN)) { - $this->terminateWithError(getError($resultN), self::ERROR_TYPE_GENERAL); - } - $return_code = 3; - } - } - - $note = current(getData($result)); - $uebernahmedatum = new DateTime($note->uebernahmedatum); - $benotungsdatum = new DateTime($note->benotungsdatum); - - $checkDate = $uebernahmedatum === '' || $benotungsdatum > $uebernahmedatum - ? $benotungsdatum - : $uebernahmedatum; - - if ($checkDate >= $this->input->post('datum') && $note !== $note->note) - { - $this->terminateWithSuccess($return_code + 2); - } - $this->terminateWithSuccess($return_code + 2); + $this->insertOrUpdatePruefung(); } /** @@ -348,8 +187,6 @@ class Pruefung extends FHCAPI_Controller * @param pruefung_id * * @return success or error - * - * no impact on lehre.tbl_zeugnisnote */ public function updatePruefung($pruefung_id) { @@ -359,48 +196,7 @@ class Pruefung extends FHCAPI_Controller if (!$oldpruefung) show_404(); // Pruefung that should be updated does not exist - $authUID = getAuthUID(); - - $this->load->library('form_validation'); - - $this->form_validation->set_rules('lehrveranstaltung_id', $this->p->t('lehre', 'lehrveranstaltung'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehrveranstaltung')]), - ]); - $this->form_validation->set_rules('lehreinheit_id', $this->p->t('lehre', 'lehreinheit'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehreinheit')]), - ]); - $this->form_validation->set_rules('pruefungstyp_kurzbz', $this->p->t('lehre', 'pruefung'), 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('global', 'typ')]), - ]); - $this->form_validation->set_rules( - 'datum', - $this->p->t('global', 'datum'), - ['is_valid_date'] - ); - - if ($this->form_validation->run() == false) - { - $this->terminateWithValidationErrors($this->form_validation->error_array()); - } - - $result = $this->PruefungModel->update( - [ - 'pruefung_id' => $pruefung_id - ], - [ 'lehreinheit_id' => $this->input->post('lehreinheit_id'), - 'student_uid' => $this->input->post('student_uid'), - 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), - 'note' => $this->input->post('note'), - 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), - 'datum' => $this->input->post('datum'), - 'anmerkung' => $this->input->post('anmerkung'), - 'updatevon' => $authUID, - 'updateamum' => date('c'), - ] - ); - $this->getDataOrTerminateWithError($result); - - return $this->outputJsonSuccess(true); + $this->insertOrUpdatePruefung($pruefung_id); } /** @@ -574,4 +370,198 @@ class Pruefung extends FHCAPI_Controller return $this->terminateWithSuccess($data); } + + protected function insertOrUpdatePruefung($pruefung_id=null) + { + $authUID = getAuthUID(); + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('lehreinheit_id', $this->p->t('lehre', 'lehreinheit'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('lehre', 'lehreinheit')]), + ]); + $this->form_validation->set_rules('pruefungstyp_kurzbz', $this->p->t('lehre', 'pruefung'), 'required', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('global', 'typ')]), + ]); + $this->form_validation->set_rules( + 'datum', + $this->p->t('global', 'datum'), + ['is_valid_date'] + ); + + if ($this->form_validation->run() == false) + { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $this->PruefungModel->db->trans_start(); + + if ($this->input->post('pruefungstyp_kurzbz') == "Termin2") + { + //Wenn ein 2. Termin angelegt wird, und kein 1. Termin vorhanden ist, + //dann wird auch ein 1. Termin angelegt mit der derzeitigen Zeugnisnote + $resultP = $this->PruefungModel->loadWhere(array( + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'pruefungstyp_kurzbz' => 'Termin1')); + + $termin1 = $this->getDataOrTerminateWithError($resultP); + if (!$termin1) + { + //check if existing Zeugnisnote + $this->ZeugnisnoteModel->addJoin('lehre.tbl_lehreinheit', 'lehrveranstaltung_id'); + + $this->ZeugnisnoteModel->db->where( + 'lehre.tbl_zeugnisnote.studiensemester_kurzbz', + 'lehre.tbl_lehreinheit.studiensemester_kurzbz', + false + ); + $resultP = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $this->input->post('lehrveranstaltung_id'), + 'student_uid' => $this->input->post('student_uid') + )); + + $zeugnisnoten = $this->getDataOrTerminateWithError($resultP); + if ($zeugnisnoten) + { + $zeugnisnote = current($zeugnisnoten); + + $resultN = $this->PruefungModel->insert([ + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'datum' => $zeugnisnote->benotungsdatum, + 'pruefungstyp_kurzbz' => 'Termin1', + 'note' => $zeugnisnote->note, + 'punkte' => $zeugnisnote->punkte, + 'anmerkung' => 'automatisiert aus Zeugnisnote erstellt', + 'insertamum' => date('c'), + 'insertvon' => $authUID, + ]); + + $this->getDataOrTerminateWithError($resultN); + } + //Wenn keine Zeugnisnote vorhanden ist, dann wird kein + //1.Termin angelegt + } + } + + if(intval($pruefung_id) > 0) + { + $result = $this->PruefungModel->update( + [ + 'pruefung_id' => $pruefung_id + ], + [ 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'note' => $this->input->post('note'), + 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), + 'datum' => $this->input->post('datum'), + 'anmerkung' => $this->input->post('anmerkung'), + 'updatevon' => $authUID, + 'updateamum' => date('c'), + ] + ); + } + else + { + $result = $this->PruefungModel->insert([ + 'lehreinheit_id' => $this->input->post('lehreinheit_id'), + 'student_uid' => $this->input->post('student_uid'), + 'mitarbeiter_uid' => $this->input->post('mitarbeiter_uid'), + 'datum' => $this->input->post('datum'), + 'pruefungstyp_kurzbz' => $this->input->post('pruefungstyp_kurzbz'), + 'note' => $this->input->post('note'), + 'anmerkung' => $this->input->post('anmerkung'), + 'insertamum' => date('c'), + 'insertvon' => $authUID, + 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null + ]); + } + + $this->getDataOrTerminateWithError($result); + + //get studiensemester_kurzbz and lehreveranstaltung_id from lehreinheit + $this->load->model('education/Lehreinheit_model', 'LehreinheitModel'); + + $result = $this->LehreinheitModel->load($this->input->post('lehreinheit_id')); + + $lehreinheiten = $this->getDataOrTerminateWithError($result); + + if (!$lehreinheiten) { + $this->terminateWithValidationErrors([ + 'lehreinheit_id' => $this->p->t('ui', 'error_fieldNotFound', [ + 'field' => $this->p->t('lehre', 'lehreinheit') + ]) + ]); + } + $lehreinheit = current($lehreinheiten); + $studiensemester_kurzbz = $lehreinheit->studiensemester_kurzbz; + $lehrveranstaltung_id = $lehreinheit->lehrveranstaltung_id; + + //check if existing zeugnisnote + $result = $this->ZeugnisnoteModel->loadWhere(array( + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz + )); + + $zeugnisnoten = $this->getDataOrTerminateWithError($result); + + if (!$zeugnisnoten) + { + //insert zeugnisnote, if not existing + $result = $this->ZeugnisnoteModel->insert(array( + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'note' => $this->input->post('note'), + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $this->input->post('datum'), + 'insertamum' => date('c'), + 'insertvon' => $authUID, + 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null + )); + + $this->getDataOrTerminateWithError($result); + + $this->PruefungModel->db->trans_complete(); + $this->terminateWithSuccess(); + } + + $note = current($zeugnisnoten); + $uebernahmedatum = new DateTime($note->uebernahmedatum); + $benotungsdatum = new DateTime($note->benotungsdatum); + $pruefungsdatum = new DateTime($this->input->post('datum')); + + $checkDate = $note->uebernahmedatum === '' || $benotungsdatum > $uebernahmedatum + ? $benotungsdatum + : $uebernahmedatum; + + if ($checkDate > $pruefungsdatum && $this->input->post('note') !== $note->note) + { + $this->PruefungModel->db->trans_complete(); + $this->terminateWithSuccess($this->p->t('exam', 'hinweis_changeAfterExamDate')); + } + + //update zeugnisnote, if existing and valid datum + $result = $this->ZeugnisnoteModel->update([ + 'lehrveranstaltung_id' => $lehrveranstaltung_id, + 'student_uid' => $this->input->post('student_uid'), + 'studiensemester_kurzbz' => $studiensemester_kurzbz + ], [ + 'note' => $this->input->post('note'), + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $this->input->post('datum'), + 'updateamum' => date('c'), + 'updatevon' => $authUID, + 'punkte' => $this->input->post('punkte') ? str_replace(',', '.', $this->input->post('punkte')) : null + ]); + + $this->PruefungModel->db->trans_complete(); + $this->terminateWithSuccess(); + } } diff --git a/application/views/Studentenverwaltung.php b/application/views/Studentenverwaltung.php index 16b8c0045..1cd28d735 100644 --- a/application/views/Studentenverwaltung.php +++ b/application/views/Studentenverwaltung.php @@ -22,7 +22,8 @@ 'public/css/components/function.css' ], 'customJSs' => [ - 'vendor/vuejs/vuedatepicker_js/vue-datepicker.iife.js' + 'vendor/vuejs/vuedatepicker_js/vue-datepicker.iife.js', + 'vendor/moment/luxonjs/luxon.min.js' #'vendor/npm-asset/primevue/tree/tree.min.js', #'vendor/npm-asset/primevue/toast/toast.min.js' ], diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js b/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js index 4dd3139ab..62cd47547 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Pruefung/Pruefunglist.js @@ -46,8 +46,6 @@ export default{ {title: "Punkte", field: "punkte", visible: false}, { title: 'Aktionen', field: 'actions', - minWidth: 150, - maxWidth: 150, formatter: (cell, formatterParams, onRendered) => { let container = document.createElement('div'); container.className = "d-flex gap-2"; @@ -93,7 +91,7 @@ export default{ layoutColumnsOnNewData: false, height: 'auto', index: 'pruefung_id', - persistenceID: 'stv-details-pruefung-list' + persistenceID: 'stv-details-pruefung-list-2025112402' }, tabulatorEvents: [ { @@ -148,7 +146,6 @@ export default{ listMas: [], listMarks: [], zeugnisData: [], - checkData:[], filter: false, statusNew: true, isStartDropDown: false, @@ -181,7 +178,7 @@ export default{ this.pruefungData.student_uid = this.uid; this.pruefungData.note = 9; - this.pruefungData.datum = new Date(); + this.pruefungData.datum = luxon.DateTime.now().setZone(FHC_JS_DATA_STORAGE_OBJECT.timezone).toISODate(); this.pruefungData.pruefungstyp_kurzbz = null; if(lv_id){ this.pruefungData.lehrveranstaltung_id = lv_id; @@ -193,7 +190,7 @@ export default{ this.isStartDropDown = false; this.loadPruefung(pruefung_id).then(() => { this.pruefungData.note = 9; - this.pruefungData.datum = new Date(); + this.pruefungData.datum = luxon.DateTime.now().setZone(FHC_JS_DATA_STORAGE_OBJECT.timezone).toISODate(); this.pruefungData.pruefungstyp_kurzbz = null; this.pruefungData.anmerkung = null; this.prepareDropdowns(); @@ -229,9 +226,8 @@ export default{ return this.$refs.examData .call(ApiStvExam.addPruefung(this.pruefungData)) .then(response => { - this.checkData = response.data; - if (this.checkData === 2 || this.checkData === 5) - this.$fhcAlert.alertInfo(this.$p.t('exam', 'hinweis_changeAfterExamDate')); + if (response.data) + this.$fhcAlert.alertDefault('info', 'Info', response.data, true); else this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.hideModal('pruefungModal'); @@ -243,12 +239,13 @@ export default{ }); }, updatePruefung(pruefung_id){ - this.checkChangeAfterExamDate(); return this.$refs.examData .call(ApiStvExam.updatePruefung(pruefung_id, this.pruefungData)) .then(response => { - this.checkData = response.data; - this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); + if (response.data) + this.$fhcAlert.alertDefault('info', 'Info', response.data, true); + else + this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.hideModal('pruefungModal'); this.resetModal(); }).catch(this.$fhcAlert.handleSystemError) @@ -266,27 +263,6 @@ export default{ else this.showHint = false; }, - checkChangeAfterExamDate() { - const data = { - student_uid: this.pruefungData.student_uid, - studiensemester_kurzbz: this.pruefungData.studiensemester_kurzbz, - lehrveranstaltung_id: this.pruefungData.lehrveranstaltung_id - }; - return this.$api - .call(ApiStvExam.checkZeugnisnoteLv(data)) - .then(result => { - this.zeugnisData = result.data; - let checkDate = this.zeugnisData[0].uebernahmedatum === '' || - this.zeugnisData[0].benotungsdatum > this.zeugnisData[0].uebernahmedatum - ? this.zeugnisData[0].benotungsdatum - : this.zeugnisData[0].uebernahmedatum; - if (checkDate >= this.pruefungData.datum - && this.pruefungData.note !== this.zeugnisData[0].note) { - this.$fhcAlert.alertInfo(this.$p.t('exam', 'hinweis_changeAfterExamDate')); - } - }) - .catch(this.$fhcAlert.handleSystemError); - }, deletePruefung(pruefung_id) { return this.$api .call(ApiStvExam.deletePruefung(pruefung_id)) @@ -534,6 +510,7 @@ export default{ container-class="mb-3" type="DatePicker" v-model="pruefungData.datum" + model-type="yyyy-MM-dd" name="datum" :label="$p.t('global/datum')" auto-apply