From c34ffedb4239043e5f96d50ff80b921cfdfc89f7 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Wed, 21 Jan 2026 10:59:16 +0100 Subject: [PATCH] Autocomplete Field Vertretung Form with ISO fields for hours Admin functionality for seeing Timelocks of uid in route Backend with CI-Validations Phrases --- application/controllers/Cis/Zeitsperren.php | 2 +- .../api/frontend/v1/Zeitsperren.php | 215 ++++++++++++++- .../models/ressource/Zeitsperre_model.php | 100 ++++++- public/css/Cis4/Zeitsperren.css | 10 + public/js/api/factory/cis/zeitsperren.js | 8 +- .../components/Cis/Zeitsperren/Zeitsperren.js | 260 +++++++++++++----- system/phrasesupdate.php | 246 ++++++++++++++++- 7 files changed, 754 insertions(+), 87 deletions(-) diff --git a/application/controllers/Cis/Zeitsperren.php b/application/controllers/Cis/Zeitsperren.php index e337b2f98..baa09b8c6 100644 --- a/application/controllers/Cis/Zeitsperren.php +++ b/application/controllers/Cis/Zeitsperren.php @@ -25,6 +25,6 @@ class Zeitsperren extends Auth_Controller 'uid'=>getAuthUID(), ); - $this->load->view('CisRouterView/CisRouterView.php',['viewData' => $viewData, 'route' => 'zeitsperren']); + $this->load->view('CisRouterView/CisRouterView.php', ['viewData' => $viewData, 'route' => 'zeitsperren']); } } diff --git a/application/controllers/api/frontend/v1/Zeitsperren.php b/application/controllers/api/frontend/v1/Zeitsperren.php index b5ff1105b..66efa81a7 100644 --- a/application/controllers/api/frontend/v1/Zeitsperren.php +++ b/application/controllers/api/frontend/v1/Zeitsperren.php @@ -24,7 +24,8 @@ class Zeitsperren extends FHCAPI_Controller // Load language phrases $this->loadPhrases([ 'ui', - 'person' + 'person', + 'zeitsperren' ]); // Load models @@ -32,10 +33,21 @@ class Zeitsperren extends FHCAPI_Controller $this->load->model('ressource/Zeitsperretyp_model', 'ZeitsperretypModel'); $this->load->model('ressource/Erreichbarkeit_model', 'ErreichbarkeitModel'); $this->load->model('ressource/Stunde_model', 'StundeModel'); + $this->load->model('ressource/Zeitaufzeichnung_model', 'ZeitaufzeichnungModel'); } public function getZeitsperrenUser($uid) { + //check if $uid is passedUser + $loggedInUser = getAuthUID(); + if($loggedInUser != $uid) { + $this->load->library('PermissionLib'); + $isAdmin = $this->permissionlib->isBerechtigt('admin'); + if(!$isAdmin) { + $this->terminateWithError($this->p->t('ui', 'noAdmin'), self::ERROR_TYPE_GENERAL); + } + } + $result = $this->ZeitsperreModel->getZeitsperrenUser($uid); if (isError($result)) { @@ -75,7 +87,7 @@ class Zeitsperren extends FHCAPI_Controller public function loadZeitsperre($zeitsperre_id) { - $result = $this->ZeitsperreModel->addSelect( + $this->ZeitsperreModel->addSelect( 'campus.tbl_zeitsperre.*, typ.*, ma.person_id AS ma_person_id, ma.vorname AS ma_vorname, ma.nachname AS ma_nachname, ma.titelpre AS ma_titelpre, ma.titelpost AS ma_titelpost' @@ -95,16 +107,25 @@ class Zeitsperren extends FHCAPI_Controller public function add($mitarbeiter_uid) { + $loggedInUser = getAuthUID(); + + if($mitarbeiter_uid != $loggedInUser) + $this->terminateWithError($this->p->t('ui', 'noPermission'), self::ERROR_TYPE_GENERAL); + $this->form_validation->set_rules('zeitsperretyp_kurzbz', 'Grund Zeitsperre', 'required', [ 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'Grund Zeitsperre']) ]); - $this->form_validation->set_rules('vondatum', 'VON-DATUM', 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'VON-DATUM']) + $this->form_validation->set_rules('vondatum', 'VonDatum', 'required|is_valid_date', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'VonDatum']), + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'VonDatum']) ]); - $this->form_validation->set_rules('bisdatum', 'BIS-DATUM', 'required', [ - 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'BIS-DATUM']) + $this->form_validation->set_rules('bisdatum', 'BisDatum', 'required|is_valid_date|callback_check_von_bis_datum|callback_check_diff_intval', [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field' => 'BisDatum']), + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field' => 'BisDatum']), + 'check_von_bis_datum' => $this->p->t('zeitsperre', 'error_VonDatumGroesserAlsBisDatum'), + 'check_diff_intval' => $this->p->t('zeitsperre', 'error_zeitraumAuffallendHoch') ]); if ($this->form_validation->run() == false) @@ -123,10 +144,23 @@ class Zeitsperren extends FHCAPI_Controller $vertretung_uid = $this->input->post('vertretung_uid'); $zeitsperretyp_kurzbz = $this->input->post('zeitsperretyp_kurzbz'); - // $this->terminateWithError("for later: Stunden Timestamps: VON " . $vonIso . " BIS " . $bisIso, self::ERROR_TYPE_GENERAL); + //check if existing zeitsperre + $result = $this->ZeitsperreModel->getSperreByDate($mitarbeiter_uid, $vondatum, $vonstunde, true); + $data = $this->getDataOrTerminateWithError($result); + if(hasData($result)) + { + $this->terminateWithError($this->p->t('zeitsperren', 'error_existingZeitsperre', ['typ'=> current($data)->zeitsperretyp_kurzbz]), self::ERROR_TYPE_GENERAL); + } - $uid = getAuthUID(); + //check if existing zeitaufzeichnung + if(in_array($zeitsperretyp_kurzbz, Zeitsperre_model::BLOCKIERENDE_ZEITSPERREN)) + { + $result = $this->ZeitsperreModel->existsZeitaufzeichnung($mitarbeiter_uid, $vondatum, $bisdatum); + + if(hasData($result)) + $this->terminateWithError($this->p->t('zeitsperren', 'error_existingZeitaufzeichnung'), self::ERROR_TYPE_GENERAL); + } $result = $this->ZeitsperreModel->insert( [ @@ -139,7 +173,7 @@ class Zeitsperren extends FHCAPI_Controller 'erreichbarkeit_kurzbz' => $erreichbarkeit_kurzbz, 'zeitsperretyp_kurzbz' => $zeitsperretyp_kurzbz, 'vertretung_uid' => $vertretung_uid, - 'insertvon' => $uid, + 'insertvon' => $loggedInUser, 'insertamum' => date('c'), ] ); @@ -148,17 +182,156 @@ class Zeitsperren extends FHCAPI_Controller $this->terminateWithSuccess($data); } - public function update() + public function update($zeitsperre_id) { + //check if loggedin User is owner of the zeitsperre + $loggedInUser = getAuthUID(); + $result = $this->ZeitsperreModel->load($zeitsperre_id); + $data = $this->getDataOrTerminateWithError($result); + $uid = current($data)->mitarbeiter_uid; + if($uid != $loggedInUser) + $this->terminateWithError($this->p->t('ui', 'noPermission'), self::ERROR_TYPE_GENERAL); + + if(!$zeitsperre_id) + { + return $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Zeitsperre_id']), self::ERROR_TYPE_GENERAL); + } + //get current params + $array_update = [ + 'bezeichnung', + 'vondatum', + 'vonstunde', + 'bisdatum', + 'bisstunde', + // 'vonISO', //Timestamp für Stunde + // 'bisISO', //Timestamp für Stunde + 'erreichbarkeit_kurzbz', + 'vertretung_uid', + 'zeitsperretyp_kurzbz', + 'mitarbeiter_uid', + ]; + $post = $this->input->post(); + $update = []; + + foreach ($array_update as $prop) + { + if (array_key_exists($prop, $post)) + { + $update[$prop] = $post[$prop]; + } + } + + // Validation + $rulesDefined = false; //necessary, otherwise CI validation will always be triggered, even without rules + foreach ($update as $key => $val) { + switch ($key) { + case 'zeitsperretyp_kurzbz': + $this->form_validation->set_rules( + $key, + 'Grund Zeitsperre', + 'required', + ['required' => $this->p->t('ui', 'error_fieldRequired', ['field'=>'Grund Zeitsperre'])] + ); + $rulesDefined = true; + break; + case 'vondatum': + $this->form_validation->set_rules( + $key, + 'VonDatum', + 'required|is_valid_date', + [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field'=>'VonDatum']), + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field'=>'VonDatum']) + ] + ); + $rulesDefined = true; + break; + case 'bisdatum': + $rules = 'required|is_valid_date'; + if (array_key_exists('vondatum', $update)) { + $rules .= '|callback_check_von_bis_datum|callback_check_diff_intval'; + } + $this->form_validation->set_rules( + $key, + 'BisDatum', + $rules, + [ + 'required' => $this->p->t('ui', 'error_fieldRequired', ['field'=>'BisDatum']), + 'is_valid_date' => $this->p->t('ui', 'error_notValidDate', ['field'=>'BisDatum']), + 'check_von_bis_datum' => $this->p->t('zeitsperre', 'error_VonDatumGroesserAlsBisDatum'), + 'check_diff_intval' => $this->p->t('zeitsperre', 'error_zeitraumAuffallendHoch') + ] + ); + $rulesDefined = true; + break; + } + } + + if ($rulesDefined && $this->form_validation->run() == false) { + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } + + if(array_key_exists('vondatum', $post) || array_key_exists('bisdatum', $post)) + { + $result = $this->ZeitsperreModel->load($zeitsperre_id); + $data = $this->getDataOrTerminateWithError($result); + $data = current($data); + + $mitarbeiter_uid = array_key_exists('mitarbeiter_uid', $post) ? $update['mitarbeiter_uid'] : $data->mitarbeiter_uid; + $vondatum = array_key_exists('vondatum', $post) ? $update['vondatum'] : $data->vondatum; + $bisdatum = array_key_exists('bisdatum', $post) ? $update['bisdatum'] : $data->bisdatum; + $vonstunde = array_key_exists('vonstunde', $post) ? $update['vonstunde'] : $data->vonstunde; + $zeitsperretyp_kurzbz = array_key_exists('zeitsperretyp_kurzbz', $post) ? $update['zeitsperretyp_kurzbz'] : $data->zeitsperretyp_kurzbz; + + $result = $this->ZeitsperreModel->getSperreByDate($mitarbeiter_uid, $vondatum, $vonstunde, true); + $data = $this->getDataOrTerminateWithError($result); + + if(hasData($result)) + { + $this->terminateWithError($this->p->t('zeitsperren', 'error_existingZeitsperre', ['typ'=> current($data)->zeitsperretyp_kurzbz]), self::ERROR_TYPE_GENERAL); + } + + //check if existing zeitaufzeichnung + if(in_array($zeitsperretyp_kurzbz, Zeitsperre_model::BLOCKIERENDE_ZEITSPERREN)) + { + $result = $this->ZeitsperreModel->existsZeitaufzeichnung($mitarbeiter_uid, $vondatum, $bisdatum); + + if(hasData($result)) + $this->terminateWithError($this->p->t('zeitsperren', 'error_existingZeitaufzeichnung'), self::ERROR_TYPE_GENERAL); + } + } + + if (!empty($update)) { + $update['updatevon'] = $loggedInUser; + $update['updateamum'] = date('c'); + $result = $this->ZeitsperreModel->update($zeitsperre_id, $update); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + else + $this->terminateWithSuccess("no update"); } public function delete($zeitsperre_id) { + if (!is_numeric($zeitsperre_id) || (int)$zeitsperre_id <= 0) { $this->terminateWithError($this->p->t('ui', 'error_missingId', ['id' => 'Zeitsperre_id']), self::ERROR_TYPE_GENERAL); } + + //check if loggedin User is owner of the zeitsperre + $loggedInUser = getAuthUID(); + $result = $this->ZeitsperreModel->load($zeitsperre_id); + $data = $this->getDataOrTerminateWithError($result); + $uid = current($data)->mitarbeiter_uid; + + if($uid != $loggedInUser) + $this->terminateWithError($this->p->t('ui', 'noPermission'), self::ERROR_TYPE_GENERAL); + $result = $this->ZeitsperreModel->delete( array('zeitsperre_id' => $zeitsperre_id) ); @@ -169,4 +342,26 @@ class Zeitsperren extends FHCAPI_Controller $this->terminateWithSuccess((getData($result) ?: [])); } + public function check_von_bis_datum($bisdatum) + { + $vondatum = $this->input->post('vondatum'); + + return $vondatum <= $bisdatum; + } + + public function check_diff_intval($bisdatum) + { + $vondatum = $this->input->post('vondatum'); + + // Intervall in days + $vonTs = strtotime($vondatum); + $bisTs = strtotime($bisdatum); + + $tage = ($bisTs - $vonTs) / 86400; + + // if intervall > 14 + return $tage <= 14; + } + + } diff --git a/application/models/ressource/Zeitsperre_model.php b/application/models/ressource/Zeitsperre_model.php index aa90cab59..c7dc9dfff 100644 --- a/application/models/ressource/Zeitsperre_model.php +++ b/application/models/ressource/Zeitsperre_model.php @@ -12,6 +12,8 @@ class Zeitsperre_model extends DB_Model $this->pk = 'zeitsperre_id'; } + const BLOCKIERENDE_ZEITSPERREN = ['Krank','Urlaub','ZA','DienstV','PflegeU','DienstF','CovidSB','CovidKS']; + /** * Save or update Zeitsperre. * @@ -70,12 +72,17 @@ class Zeitsperre_model extends DB_Model * * @return array */ - public function getZeitsperrenUser($uid, $bisgrenze=true) + public function getZeitsperrenUser($uid, $bisgrenze = true) { $qry = " - SELECT tbl_zeitsperre.*, tbl_zeitsperretyp.*, tbl_erreichbarkeit.farbe AS erreichbarkeit_farbe, tbl_erreichbarkeit.beschreibung AS erreichbarkeit_beschreibung + SELECT + tbl_zeitsperre.*, tbl_zeitsperretyp.*, tbl_erreichbarkeit.farbe AS erreichbarkeit_farbe, + tbl_erreichbarkeit.beschreibung AS erreichbarkeit_beschreibung, + CONCAT (ps.vorname, ' ', ps.nachname) as vertretung FROM (campus.tbl_zeitsperre JOIN campus.tbl_zeitsperretyp USING (zeitsperretyp_kurzbz)) LEFT JOIN campus.tbl_erreichbarkeit USING (erreichbarkeit_kurzbz) + LEFT JOIN public.tbl_benutzer ON campus.tbl_zeitsperre.vertretung_uid = public.tbl_benutzer.uid + LEFT JOIN public.tbl_person ps USING (person_id) WHERE mitarbeiter_uid= ? "; @@ -91,6 +98,93 @@ class Zeitsperre_model extends DB_Model $qry.= " ORDER BY vondatum DESC"; - return $this->execQuery($qry, array('mitarbeiter_uid' => $uid)); + return $this->execQuery($qry, array('mitarbeiter_uid' => $uid)); + } + + /** + * check a date for existing zeitsperre + * + * @param $uid mitarbeiteruid + * @param $datum datum to check + * @param $stunde stunde (default = null) + * @param bool $nurblockierend if only hr relevante zeitsperren have to be checked + * + * @return array + */ + public function getSperreByDate($uid, $datum, $stunde = null, $nurblockierend = false) + { + $parametersArray = [$datum, $datum]; + + $qry = " + SELECT + * + FROM + campus.tbl_zeitsperre + WHERE + vondatum <= ? + AND bisdatum>= ?"; + + if($nurblockierend) + { + $qry .= " AND zeitsperretyp_kurzbz IN ('" + . implode("','", self::BLOCKIERENDE_ZEITSPERREN) + . "')"; + } + + if(!is_null($stunde)) + { + $parametersArray = array_merge( + $parametersArray, + [$datum, $stunde, $datum, $datum, $stunde, $datum] + ); + + $qry.=" AND + ((vondatum= ? AND vonstunde<= ? OR vonstunde is null OR vondatum<> ?) AND + (bisdatum= ? AND bisstunde>= ? OR bisstunde is null OR bisdatum<> ?))"; + } + + array_push($parametersArray, $uid); + + $qry .= "AND mitarbeiter_uid= ? "; + + return $this->execQuery($qry, $parametersArray); + } + + /** + * check a date for existing zeitsperre + * + * @param $uid mitarbeiteruid + * @param $vondatum datum in Format IS0 + * @param $bisdatum datum in Format ISO + * + * @return array + */ + public function existsZeitaufzeichnung($uid, $vonDay, $bisDay) + { + try { + $from = new DateTime($vonDay); + $to = new DateTime($bisDay); + } catch (Exception $e) { + throw new Exception("Invalid date format"); + } + + //remove hour stamps + $from->setTime(0, 0, 0); + $to->setTime(0, 0, 0)->modify('+1 day'); + + $fromSql = $from->format('Y-m-d'); + $toSql = $to->format('Y-m-d'); + $params = [$uid, $fromSql, $toSql]; + + $qry = " + SELECT * + FROM campus.tbl_zeitaufzeichnung + WHERE uid = ? + AND start >= ? + AND ende < ? "; + + $result = $this->execQuery($qry, $params); + + return $result; } } diff --git a/public/css/Cis4/Zeitsperren.css b/public/css/Cis4/Zeitsperren.css index 7ba9eae9e..dac3d3988 100644 --- a/public/css/Cis4/Zeitsperren.css +++ b/public/css/Cis4/Zeitsperren.css @@ -27,3 +27,13 @@ padding-left: 36px !important; padding-right: 36px !important; } + +.info-feedback { + display: block; + font-size: 0.875em; + color: #0d6efd; /* Bootstrap primary */ +} + +.is-info { + border-color: #0d6efd; +} diff --git a/public/js/api/factory/cis/zeitsperren.js b/public/js/api/factory/cis/zeitsperren.js index ea37fc0e6..2a73a5e79 100644 --- a/public/js/api/factory/cis/zeitsperren.js +++ b/public/js/api/factory/cis/zeitsperren.js @@ -47,6 +47,13 @@ export default { params }; }, + editZeitsperre(zeitsperre_id, params) { + return { + method: 'post', + url: '/api/frontend/v1/Zeitsperren/update/' + zeitsperre_id, + params + }; + }, loadZeitsperre(zeitsperre_id) { return { method: 'get', @@ -54,7 +61,6 @@ export default { }; }, deleteZeitsperre(zeitsperre_id) { - console.log("zeitsperre_id " + zeitsperre_id); return { method: 'post', url: '/api/frontend/v1/Zeitsperren/delete/' + zeitsperre_id diff --git a/public/js/components/Cis/Zeitsperren/Zeitsperren.js b/public/js/components/Cis/Zeitsperren/Zeitsperren.js index a2829b4f8..489860970 100644 --- a/public/js/components/Cis/Zeitsperren/Zeitsperren.js +++ b/public/js/components/Cis/Zeitsperren/Zeitsperren.js @@ -18,6 +18,7 @@ export default { data(){ return { uid: null, + statusNew: true, timeRecordingLockedUntil: '2015-08-31', //TODO(Manu) check if needed typesTimeLocks: ["Urlaub", "PflegeU", "ZA", "Krank", "DienstF", "DienstV", "CovidSB", "CovidKS"], typesHideStunden: ["Urlaub", "ZA", "Krank", "DienstF", "DienstV", "CovidSB", "CovidKS"], @@ -26,6 +27,7 @@ export default { listStunden: [], tabulatorOptions: null, tabulatorEvents: [], + originalData: {}, zeitsperreData: { vondatum : new Date(), bisdatum: new Date(), @@ -36,6 +38,7 @@ export default { vonstunde: null, bisstunde: null }, + changedData: {}, selectedVertretung: null, filteredMitarbeiter: [], abortController: { @@ -57,20 +60,18 @@ export default { "Bundesheer": "i) " + this.$p.t('zeitsperren', 'bundesheer'), "Volksschultag": "j) " + this.$p.t('zeitsperren', 'volksschultag')}; }, + showInfo(){ + return this.zeitsperreData.zeitsperretyp_kurzbz === 'DienstF'; + }, }, methods: { - actionNewZeitsperre(){ - console.log("actionNewZeitsperre "); - }, actionEditZeitsperre(zeitsperre_id){ - console.log("actionEditZeitsperre " + zeitsperre_id); + this.statusNew = false; return this.$api .call(ApiTimelocks.loadZeitsperre(zeitsperre_id)) .then(response => { - console.log(response); - this.zeitsperreData = response.data; - - //this.getMaData(this.zeitsperreData.mitarbeiter); + this.originalData = structuredClone(response.data); + this.zeitsperreData = structuredClone(response.data); this.selectedVertretung = { label: this.getPersonLabel(this.zeitsperreData.ma_titelpre, this.zeitsperreData.ma_nachname, this.zeitsperreData.ma_vorname, this.zeitsperreData.ma_titelpost, this.zeitsperreData.vertretung_uid), @@ -90,16 +91,31 @@ export default { .then(() => this.deleteZeitsperre(zeitsperre_id)) .catch(this.$fhcAlert.handleSystemError); }, - addZeitsperre(){ + saveZeitsperre(zeitsperreId = null) { + const isNew = !zeitsperreId; + + let payload = isNew + ? { ...this.zeitsperreData } // add + : this.getChangedFields(this.originalData, // edit + this.zeitsperreData); + + if (!isNew && Object.keys(payload).length === 0) { + return Promise.resolve(); + } + + const request = isNew + ? ApiTimelocks.addZeitsperre(this.uid, payload) + : ApiTimelocks.editZeitsperre(zeitsperreId, payload); + return this.$refs.dataZeitsperre - .call(ApiTimelocks.addZeitsperre(this.uid, this.zeitsperreData)) - .then(response => { + .call(request) + .then(() => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); - }) - .catch(this.$fhcAlert.handleSystemError) - .finally(() => { + + this.reset(); this.reload(); - }); + }) + .catch(this.$fhcAlert.handleSystemError); }, deleteZeitsperre(zeitsperre_id){ return this.$api @@ -149,6 +165,21 @@ export default { if (this.$refs.table) this.$refs.table.reloadTable(); }, + reset(){ + this.statusNew = true; + this.selectedVertretung = null; + this.zeitsperreData = { + vondatum : new Date(), + bisdatum: new Date(), + vonISO : "00:00:00", //later + bisISO: "23:59:59", //later + erreichbarkeit_kurzbz: 'n', + zeitsperretyp_kurzbz: 'Arzt', + vonstunde: null, + bisstunde: null + }; + this.originalData = {}; + }, handleChangeVonStunde(){ let stunde = this.zeitsperreData.vonstunde; const result = this.listStunden.find(item => item.stunde === stunde); @@ -162,21 +193,56 @@ export default { let stunde = this.zeitsperreData.bisstunde; const result = this.listStunden.find(item => item.stunde === stunde); if (!result) { - this.zeitsperreData.vonISO = '23:59:59'; + this.zeitsperreData.bisISO = '23:59:59'; return; } this.zeitsperreData.bisISO = result.ende; - } + }, + handleStunden(){ + if (this.typesHideStunden.includes(this.zeitsperreData.zeitsperretyp_kurzbz)){ + this.zeitsperreData.vonstunde = null; + this.zeitsperreData.bisstunde = null; + this.zeitsperreData.vonISO = '00:00:00'; + this.zeitsperreData.bisISO = '23:59:59'; + } + }, + copyDateForBis(){ + this.zeitsperreData.bisdatum = this.zeitsperreData.vondatum; + }, + getChangedFields(original, current) { + const diff = {}; + + Object.keys(current).forEach((key) => { + if (current[key] !== original[key]) { + diff[key] = current[key]; + } + }); + return diff; + }, }, watch: { selectedVertretung(newVal) { - this.zeitsperreData.vertretung_uid = newVal?.mitarbeiter_uid || 'keine Vertretung'; + this.zeitsperreData.vertretung_uid = newVal?.mitarbeiter_uid || null; }, + 'zeitsperreData.zeitsperretyp_kurzbz'(newVal) { + if (newVal === 'DienstV') { + // set first key as default + if (!this.zeitsperreData.bezeichnung) { + const firstKey = Object.keys(this.dienstverhinderungen)[0]; + this.zeitsperreData.bezeichnung = firstKey; + } + } else { + this.zeitsperreData.bezeichnung = ''; + } + } }, created() { this.$api.call(ApiAuthinfo.getAuthUID()).then(res => { - this.uid = res.data.uid; - //TODO(Manu) check if uid via props is better + + //check if there is a user, passed via route + const urlUid = this.$route?.query?.uid; + this.uid = urlUid ? urlUid : res.data.uid; + this.tabulatorOptions = { ajaxURL: 'dummy', ajaxRequestFunc: () => @@ -213,10 +279,18 @@ export default { }, {title:"vonstunde", field:"vonstunde", visible: false}, {title:"bisstunde", field:"bisstunde", visible: false}, - {title:"Vertretung", field:"vertretung_uid"}, + {title:"Vertretung", field:"vertretung"}, {title:"Erreichbarkeit", field:"erreichbarkeit_beschreibung"}, {title:"zeitsperre_id", field:"zeitsperre_id", visible: false}, {title:"mitarbeiter_uid", field:"mitarbeiter_uid", visible: false}, + {title:"freigabeamum", field:"freigabeamum", visible: false, + formatter: function (cell) { + const value = cell.getValue(); + return value === null + ? '' + : ''; + } + }, {title: 'Aktionen', field: 'actions', minWidth: 150, // Ensures Action-buttons will be always fully displayed formatter: (cell, formatterParams, onRendered) => { @@ -245,7 +319,7 @@ export default { button.title = this.$p.t('ui', 'loeschen'); button.addEventListener('click', () => //this.deleteZeitsperre(cell.getData().zeitsperre_id) - this.actionDeleteZeitsperre(cell.getData().zeitsperre_id) //TODO(Manu) not working with prompt + this.actionDeleteZeitsperre(cell.getData().zeitsperre_id) ); if(cell.getData().zeitsperretyp_kurzbz == 'Urlaub' || cell.getData().zeitsperretyp_kurzbz == 'ZVerfueg'){ button.disabled = true; @@ -262,6 +336,50 @@ export default { }, ] }; + this.tabulatorEvents = [ + { + event: 'tableBuilt', + handler: async() => { + await this.$p.loadCategory(['global', 'person', 'zeitsperren', 'ui', 'abschlusspruefung']); + + let cm = this.$refs.table.tabulator.columnManager; + + cm.getColumnByField('bezeichnung').component.updateDefinition({ + title: this.$p.t('person', 'grund') + }); + cm.getColumnByField('beschreibung').component.updateDefinition({ + title: this.$p.t('global', 'bezeichnung') + }); + cm.getColumnByField('vondatum').component.updateDefinition({ + title: this.$p.t('ui', 'von') + }); + cm.getColumnByField('bisdatum').component.updateDefinition({ + title: this.$p.t('global', 'bis') + }); + cm.getColumnByField('vonstunde').component.updateDefinition({ + title: this.$p.t('zeitsperren', 'stunde_von') + }); + cm.getColumnByField('bisstunde').component.updateDefinition({ + title: this.$p.t('zeitsperren', 'stunde_bis') + }); + cm.getColumnByField('vertretung').component.updateDefinition({ + title: this.$p.t('person', 'vertretung') + }); + + cm.getColumnByField('erreichbarkeit_beschreibung').component.updateDefinition({ + title: this.$p.t('person', 'erreichbarkeit') + }); + cm.getColumnByField('freigabeamum').component.updateDefinition({ + title: this.$p.t('abschlusspruefung', 'freigabe') + }); + + /* cm.getColumnByField('actions').component.updateDefinition({ + title: this.$p.t('global', 'aktionen') + });*/ + + } + } + ]; }); this.$api @@ -286,54 +404,33 @@ export default { .catch(this.$fhcAlert.handleSystemError); }, - -/* created(){ - this.$api - .call(ApiAuthinfo.getAuthUID()) - .then(res => { - this.uid = res.data.uid; - }); - - - },*/ - /* - - :label="$p.t('global/name')" - - :new-btn-label="this.$p.t('profil', 'zeitsperren')" - {title:"bezeichnung", field:"bezeichnung"}, - {title:"updateamum", field:"updateamum"}, - {title:"updatevon", field:"updatevon"}, - {title:"insertamum", field:"insertamum"}, - {title:"insertvon", field:"insertvon"}, - {title:"freigabevon", field:"freigabevon"}, - {title:"freigabeamum", field:"freigabeamum"}, - - {{zeitsperreData}}
- {{listTypenErreichbarkeit}}person - */ - - template: /* html */`
-

Meine Zeitsperren ({{uid}})

+

{{$p.t('zeitsperren', 'header_zeitsperren')}} ({{uid}})

+
+
+ Dienstfreistellungen nur in Absprache mit HR Service eintragen! +
@@ -363,7 +460,7 @@ export default {
-
+
+
+ +
@@ -398,6 +504,7 @@ export default { {{std.stunde}} ({{std.beginn}} - {{std.ende}}) +