From f0ef091c5ff3f92c6d029d722a05b47a1eb9040e Mon Sep 17 00:00:00 2001 From: Cris Date: Wed, 20 Jan 2021 11:48:07 +0100 Subject: [PATCH] Added logic & GUI adaptations for rejecting Anrechnungen . Added rejecting-methods in Controller and Library Signed-off-by: cris-technikum --- .../ApproveAnrechnungUebersicht.php | 42 +++++++++++++- application/libraries/AnrechnungLib.php | 44 ++++++++++++++ .../anrechnung/approveAnrechnungUebersicht.js | 58 +++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php index 4eea98369..48b8e2aa8 100644 --- a/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php +++ b/application/controllers/lehre/anrechnung/ApproveAnrechnungUebersicht.php @@ -18,7 +18,8 @@ class approveAnrechnungUebersicht extends Auth_Controller array( 'index' => 'lehre/anrechnung_genehmigen:rw', 'download' => 'lehre/anrechnung_genehmigen:rw', - 'approve' => 'lehre/anrechnung_genehmigen:rw' + 'approve' => 'lehre/anrechnung_genehmigen:rw', + 'reject' => 'lehre/anrechnung_genehmigen:rw' ) ); @@ -127,6 +128,45 @@ class approveAnrechnungUebersicht extends Auth_Controller } } + public function reject() + { + $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'); + $rejected = getData($this->AnrechnungstatusModel->load('rejected'))[0]; + $rejected = getUserLanguage() == 'German' + ? $rejected->bezeichnung_mehrsprachig[0] + : $rejected->bezeichnung_mehrsprachig[1]; + + foreach ($data as $item) + { + // Approve Anrechnung + if(getData($this->anrechnunglib->rejectAnrechnung($item['anrechnung_id']))) + { + $json[]= array( + 'anrechnung_id' => $item['anrechnung_id'], + 'status_bezeichnung' => $rejected + ); + } + } + + // 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 d2324c4e9..8e8ef2eb7 100644 --- a/application/libraries/AnrechnungLib.php +++ b/application/libraries/AnrechnungLib.php @@ -202,6 +202,50 @@ class AnrechnungLib return success(true); // has been approved } + public function rejectAnrechnung($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); // dont reject + } + + // Start DB transaction + $this->ci->db->trans_start(false); + + // Insert new status approved + $result = $this->ci->AnrechnungModel->saveAnrechnungstatus($anrechnung_id, self::ANRECHNUNGSTATUS_REJECTED); + + // 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); // rejected + } + private function _setAnrechnungDataObject($anrechnung) { $anrechnung_data = new StdClass(); diff --git a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js index 21acc3d10..c746a835c 100644 --- a/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js +++ b/public/js/lehre/anrechnung/approveAnrechnungUebersicht.js @@ -132,4 +132,62 @@ $(function(){ ); }); + // Reject Anrechnungen + $("#reject-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; + } + + // Confirm before rejecting + if(!confirm('Wollen Sie wirklich die gewählten Anträge ablehnen?')) + { + return; + } + + // Prepare data object for ajax call + let data = { + 'data': selected_data + }; + + FHC_AjaxClient.ajaxCallPost( + FHC_JS_DATA_STORAGE_OBJECT.called_path + "/reject", + 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 abgelehnt."); + } + }, + errorCallback: function (jqXHR, textStatus, errorThrown) + { + FHC_DialogLib.alertError("Systemfehler
Bitte kontaktieren Sie Ihren Administrator."); + } + } + ); + }); + }); \ No newline at end of file