From 964bd40c143affb66eb368eb3d51b33b0dd64fd5 Mon Sep 17 00:00:00 2001 From: cris-technikum Date: Wed, 20 Jan 2021 11:02:15 +0100 Subject: [PATCH] Added logic & GUI adaptations for approving Anrechnungen . Added approve-methods in Controller and Library . Added row selection checks to avoid selecting approved and rejected Antraege Signed-off-by: cris-technikum --- .../ApproveAnrechnungUebersicht.php | 51 +++++++++++- application/libraries/AnrechnungLib.php | 56 +++++++++++++ .../approveAnrechnungUebersichtData.php | 8 +- .../anrechnung/approveAnrechnungUebersicht.js | 82 +++++++++++++++++++ 4 files changed, 195 insertions(+), 2 deletions(-) diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php index 140fec28f..4eea98369 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php @@ -5,18 +5,26 @@ class approveAnrechnungUebersicht extends Auth_Controller { const BERECHTIGUNG_ANRECHNUNG_GENEHMIGEN = 'lehre/anrechnung_genehmigen'; + + const ANRECHNUNGSTATUS_PROGRESSED_BY_STGL = 'inProgressDP'; + const ANRECHNUNGSTATUS_PROGRESSED_BY_KF = 'inProgressKF'; + const ANRECHNUNGSTATUS_APPROVED = 'approved'; + const ANRECHNUNGSTATUS_REJECTED = 'rejected'; + public function __construct() { // Set required permissions parent::__construct( array( 'index' => 'lehre/anrechnung_genehmigen:rw', - 'download' => 'lehre/anrechnung_genehmigen:rw' + 'download' => 'lehre/anrechnung_genehmigen:rw', + 'approve' => 'lehre/anrechnung_genehmigen:rw' ) ); // Load models $this->load->model('education/Anrechnung_model', 'AnrechnungModel'); + $this->load->model('education/Anrechnungstatus_model', 'AnrechnungstatusModel'); $this->load->model('content/DmsVersion_model', 'DmsVersionModel'); // Load libraries @@ -78,6 +86,47 @@ class approveAnrechnungUebersicht extends Auth_Controller $this->load->view('lehre/anrechnung/approveAnrechnungUebersicht.php', $viewData); } + /** + * Approve multiple Anrechnungen. + */ + public function approve() + { + $data = $this->input->post('data'); + + if(isEmptyArray($data)) + { + return $this->outputJsonError('Fehler beim Übertragen der Daten.'); + } + + // Get statusbezeichnung for 'approved' + $this->AnrechnungstatusModel->addSelect('bezeichnung_mehrsprachig'); + $approved = getData($this->AnrechnungstatusModel->load('approved'))[0]; + + foreach ($data as $item) + { + // Approve Anrechnung + if(getData($this->anrechnunglib->approveAnrechnung($item['anrechnung_id']))) + { + $json[]= array( + 'anrechnung_id' => $item['anrechnung_id'], + 'status_bezeichnung' => getUserLanguage() == 'German' + ? $approved->bezeichnung_mehrsprachig[0] + : $approved->bezeichnung_mehrsprachig[1] + ); + } + } + + // Output json to ajax + if (isset($json) && !isEmptyArray($json)) + { + return $this->outputJsonSuccess($json); + } + else + { + return $this->outputJsonError('Es wurden keine Anrechnungen genehmigt.'); + } + } + /** * Download and open uploaded document (Nachweisdokument). */ diff --git a/application/libraries/AnrechnungLib.php b/application/libraries/AnrechnungLib.php index 4a8f0f962..d2324c4e9 100644 --- a/application/libraries/AnrechnungLib.php +++ b/application/libraries/AnrechnungLib.php @@ -4,6 +4,11 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class AnrechnungLib { + const ANRECHNUNGSTATUS_PROGRESSED_BY_STGL = 'inProgressDP'; + const ANRECHNUNGSTATUS_PROGRESSED_BY_KF = 'inProgressKF'; + const ANRECHNUNGSTATUS_APPROVED = 'approved'; + const ANRECHNUNGSTATUS_REJECTED = 'rejected'; + public function __construct() { $this->ci =& get_instance(); @@ -146,6 +151,57 @@ class AnrechnungLib return $status; } + /** + * Approve Anrechnung. + * Checks last status of Anrechnung and will only approve if last status is not approved or rejected. + * @param $anrechnung_id + * @return array + * @throws Exception + */ + public function approveAnrechnung($anrechnung_id) + { + // Check last Anrechnungstatus + if (!$result = getData($this->ci->AnrechnungModel->getLastAnrechnungstatus($anrechnung_id))[0]) + { + show_error(getError($result)); + } + + $status_kurzbz = $result->status_kurzbz; + + // Exit if already approved or rejected + if ($status_kurzbz == self::ANRECHNUNGSTATUS_APPROVED || $status_kurzbz == self::ANRECHNUNGSTATUS_REJECTED) // TODO: in js: bereits genehmigte nicht clickable! + { + return success(false); // has not been approved + } + + // Start DB transaction + $this->ci->db->trans_start(false); + + // Insert new status approved + $result = $this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_APPROVED); + + // Update genehmigt von + $result = $this->ci->AnrechnungModel->update( + $anrechnung_id, + array( + 'genehmigt_von' => getAuthUID(), + 'updateamum' => (new DateTime())->format('Y-m-d H:m:i'), + 'updatevon' => getAuthUID() + ) + ); + + // Transaction complete! + $this->ci->db->trans_complete(); + + if ($this->ci->db->trans_status() === false || isError($result)) + { + $this->ci->db->trans_rollback(); + show_error($result->msg, EXIT_ERROR); + } + + return success(true); // has been approved + } + private function _setAnrechnungDataObject($anrechnung) { $anrechnung_data = new StdClass(); diff --git a/application/views/lehre/anrechnung/approveAnrechnungUebersichtData.php b/application/views/lehre/anrechnung/approveAnrechnungUebersichtData.php index df7f84a12..4bb88653e 100644 --- a/application/views/lehre/anrechnung/approveAnrechnungUebersichtData.php +++ b/application/views/lehre/anrechnung/approveAnrechnungUebersichtData.php @@ -79,7 +79,13 @@ $filterWidgetArray = array( }, tableWidgetFooter: { selectButtons: true - } + }, + selectableCheck: function(row){ + return func_selectableCheck(row); + }, + rowUpdated:function(row){ + func_rowUpdated(row); + }, }', // tabulator properties 'datasetRepFieldsDefs' => '{ anrechnung_id: {visible: false}, diff --git a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js index 527961d09..f62210aba 100644 --- a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js +++ b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js @@ -1,6 +1,11 @@ const BASE_URL = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router; const APPROVE_ANRECHNUNG_DETAIL_URI = "lehre/anrechnung/ApproveAnrechnungDetail"; +const ANRECHNUNGSTATUS_PROGRESSED_BY_STGL = 'inProgressDP'; +const ANRECHNUNGSTATUS_PROGRESSED_BY_KF = 'inProgressKF'; +const ANRECHNUNGSTATUS_APPROVED = 'approved'; +const ANRECHNUNGSTATUS_REJECTED = 'rejected'; + // TABULATOR FUNCTIONS // --------------------------------------------------------------------------------------------------------------------- // Returns relative height (depending on screen size) @@ -27,6 +32,30 @@ function func_tableBuilt(table) { ); } +// Formats row selectable/unselectable +function func_selectableCheck(row){ + let status_kurzbz = row.getData().status_kurzbz; + + return (status_kurzbz != ANRECHNUNGSTATUS_APPROVED && status_kurzbz != ANRECHNUNGSTATUS_REJECTED); +} + +// Performes after row was updated +function func_rowUpdated(row){ + // TODO: check better solution... + // status_kurzbz is not updated until page reload...therefor use the updated status_bezeichnung + let status_bezeichnung = row.getData().status_bezeichnung; + + // Deselect and disable new selection of updated rows, but not when + if (status_bezeichnung == 'genehmigt' || + status_bezeichnung == 'approved' || + status_bezeichnung == 'abgelehnt' || + status_bezeichnung == 'rejected') + { + row.deselect(); + row.getElement().style["pointerEvents"] = "none"; + } +} + // Formats null values to '-' var format_nullToMinus = function(cell, formatterParams){ return (cell.getValue() == null) ? '-' : cell.getValue(); @@ -35,4 +64,57 @@ var format_nullToMinus = function(cell, formatterParams){ $(function(){ + // Approve Anrechnungen + $("#approve-anrechnungen").click(function(){ + // Get selected rows data + let selected_data = $('#tableWidgetTabulator').tabulator('getSelectedData') + .map(function(data){ + // reduce to necessary fields + return { + 'anrechnung_id' : data.anrechnung_id, + } + }); + + // Alert and exit if no anrechnung is selected + if (selected_data.length == 0) + { + FHC_DialogLib.alertInfo('Bitte wählen Sie erst zumindest einen Antrag auf Anrechnung'); + return; + } + + + // Prepare data object for ajax call + let data = { + 'data': selected_data + }; + + FHC_AjaxClient.ajaxCallPost( + FHC_JS_DATA_STORAGE_OBJECT.called_path + "/approve", + data, + { + successCallback: function (data, textStatus, jqXHR) + { + if (data.error && data.retval != null) + { + // Print error message + FHC_DialogLib.alertWarning(data.retval); + } + + if (!data.error && data.retval != null) + { + // Update status 'genehmigt' + $('#tableWidgetTabulator').tabulator('updateData', data.retval); + + // Print success message + FHC_DialogLib.alertSuccess(data.retval.length + " Anrechnungsanträge wurden genehmigt."); + } + }, + errorCallback: function (jqXHR, textStatus, errorThrown) + { + FHC_DialogLib.alertError("Systemfehler
Bitte kontaktieren Sie Ihren Administrator."); + } + } + ); + }); + }); \ No newline at end of file