From ad3df119490986baccdf451c05d34578ea5b2f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Tue, 14 Feb 2023 12:31:58 +0100 Subject: [PATCH] =?UTF-8?q?Funktion=20zum=20Ermitteln=20der=20Zeitsperren?= =?UTF-8?q?=20der=20letzten=20Woche=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ressource/Zeitaufzeichnung_model.php | 37 ++--- .../models/ressource/Zeitsperre_model.php | 135 ++++++++++-------- 2 files changed, 97 insertions(+), 75 deletions(-) diff --git a/application/models/ressource/Zeitaufzeichnung_model.php b/application/models/ressource/Zeitaufzeichnung_model.php index a961705c7..4ebc3abe6 100644 --- a/application/models/ressource/Zeitaufzeichnung_model.php +++ b/application/models/ressource/Zeitaufzeichnung_model.php @@ -12,24 +12,27 @@ class Zeitaufzeichnung_model extends DB_Model $this->pk = 'zeitaufzeichnung_id'; } - public function deleteEntriesForCurrentDay() - { - $today = date('Y-m-d'); - $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));"; + public function deleteEntriesForCurrentDay() + { + $today = date('Y-m-d'); + $qry = "DELETE FROM " . $this->dbTable . " + WHERE start >= '" . $today . " 00:00:00' + AND start <= '" . $today . " 23:59:59';"; return $this->execQuery($qry); + } - } + /** + * Get list of Persons with Timerecordings within the last week + */ + 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 467d05d09..699282968 100644 --- a/application/models/ressource/Zeitsperre_model.php +++ b/application/models/ressource/Zeitsperre_model.php @@ -12,68 +12,87 @@ class Zeitsperre_model extends DB_Model $this->pk = 'zeitsperre_id'; } - /** - * Save or update Zeitsperre. - * - * @param $zeitsperretyp_kurzbz - * @param $mitarbeiter_uid - * @param $vonDatum - * @param $bisDatum - * @param null $vonStunde - * @param null $bisStunde - * @param null $bezeichnung - * @param null $vertretung_uid - * @param null $erreichbarkeit_kurzbz - * @param null $freigabeamum - * @param null $freigabevon - * @return array - */ - public function save($zeitsperretyp_kurzbz, $mitarbeiter_uid, $vonDatum, $bisDatum, - $vonStunde = null, $bisStunde = null, $bezeichnung = null, $vertretung_uid = null, - $erreichbarkeit_kurzbz = null, $freigabeamum = null, $freigabevon = null) - { - return $this->insert(array( - 'zeitsperretyp_kurzbz' => $zeitsperretyp_kurzbz, - 'mitarbeiter_uid' => $mitarbeiter_uid, - 'vondatum' => $vonDatum, - 'bisdatum' => $bisDatum, - 'vonstunde' => $vonStunde, - 'bisstunde' => $bisStunde, - 'bezeichnung' => $bezeichnung, - 'vertretung_uid' => $vertretung_uid, - 'insertvon' => getAuthUID(), - 'insertamum' => (new DateTime())->format('Y-m-d H:i:s'), - 'erreichbarkeit_kurzbz' => $erreichbarkeit_kurzbz, - 'freigabeamum' => $freigabeamum, - 'freigabevon' => $freigabevon - )); - } + /** + * Save or update Zeitsperre. + * + * @param $zeitsperretyp_kurzbz + * @param $mitarbeiter_uid + * @param $vonDatum + * @param $bisDatum + * @param null $vonStunde + * @param null $bisStunde + * @param null $bezeichnung + * @param null $vertretung_uid + * @param null $erreichbarkeit_kurzbz + * @param null $freigabeamum + * @param null $freigabevon + * @return array + */ + public function save($zeitsperretyp_kurzbz, $mitarbeiter_uid, $vonDatum, $bisDatum, + $vonStunde = null, $bisStunde = null, $bezeichnung = null, $vertretung_uid = null, + $erreichbarkeit_kurzbz = null, $freigabeamum = null, $freigabevon = null) + { + return $this->insert(array( + 'zeitsperretyp_kurzbz' => $zeitsperretyp_kurzbz, + 'mitarbeiter_uid' => $mitarbeiter_uid, + 'vondatum' => $vonDatum, + 'bisdatum' => $bisDatum, + 'vonstunde' => $vonStunde, + 'bisstunde' => $bisStunde, + 'bezeichnung' => $bezeichnung, + 'vertretung_uid' => $vertretung_uid, + 'insertvon' => getAuthUID(), + 'insertamum' => (new DateTime())->format('Y-m-d H:i:s'), + 'erreichbarkeit_kurzbz' => $erreichbarkeit_kurzbz, + 'freigabeamum' => $freigabeamum, + 'freigabevon' => $freigabevon + )); + } - /** - * Delete Zeitsperre. - * @return array|stdClass|null - */ - public function deleteEntriesForCurrentDay() - { - $today = date('Y-m-d'); - $qry = "DELETE FROM " . $this->dbTable . " - WHERE vondatum = '" . $today . "';"; + /** + * Delete Zeitsperre. + * @return array|stdClass|null + */ + public function deleteEntriesForCurrentDay() + { + $today = date('Y-m-d'); + $qry = "DELETE FROM " . $this->dbTable . " + WHERE vondatum = '" . $today . "';"; - return $this->execQuery($qry); - } + return $this->execQuery($qry); + } - public function getMitarbeiterListWithPendingVacation() - { - $qry = "SELECT + /** + * get Employees with pending Vacation entries + */ + 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); + } + + /** + * Get list of Persons with Zeitsperre within the last week + */ + public function zeitsperreExistsForLastWeekList() + { + $qry = "SELECT DISTINCT mitarbeiter_uid - FROM - campus.tbl_zeitsperre + FROM campus.tbl_zeitsperre WHERE - freigabeamum is NULL - AND zeitsperretyp_kurzbz='Urlaub' - AND vondatum>=now() - ORDER BY mitarbeiter_uid ASC;"; - return $this->execQuery($qry); - } + (vondatum >= now()-'7 days'::interval AND vondatum <= now()) + OR + (bisdatum >= now()-'7 days'::interval AND bisdatum <= now())"; + return $this->execQuery($qry); + + } }