diff --git a/application/controllers/api/frontend/v1/stv/Konto.php b/application/controllers/api/frontend/v1/stv/Konto.php index 12892d2f7..1f6b963bb 100644 --- a/application/controllers/api/frontend/v1/stv/Konto.php +++ b/application/controllers/api/frontend/v1/stv/Konto.php @@ -39,7 +39,8 @@ class Konto extends FHCAPI_Controller 'getBuchungstypen' => 'student/stammdaten:r', // alle? 'checkDoubles' => ['admin:r', 'assistenz:r'], 'insert' => ['admin:w', 'assistenz:w'], - 'update' => ['admin:w', 'assistenz:w'] + 'update' => ['admin:w', 'assistenz:w'], + 'delete' => ['admin:w', 'assistenz:w'] ]); // Load models @@ -64,11 +65,12 @@ class Konto extends FHCAPI_Controller $this->load->library('form_validation'); $person_id = $this->input->post('person_id'); - if (!$person_id || !is_array($person_id)) + if (!$person_id || !is_array($person_id)) { $this->form_validation->set_rules('person_id', 'Person ID', 'required'); - if (!$this->form_validation->run()) - $this->terminateWithValidationErrors($this->form_validation->error_array()); + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + } $studiengang_kz = $this->input->post('studiengang_kz'); @@ -251,14 +253,14 @@ class Konto extends FHCAPI_Controller $result = []; foreach ($person_ids as $person_id) { $id = $this->KontoModel->insert(array_merge($data, ['person_id' => $person_id])); - if (isError($id)) + if (isError($id)) { $this->addError(getError($id), self::ERROR_TYPE_GENERAL); - else { + } else { $data = $this->KontoModel->withAdditionalInfo()->load(getData($id)); if (isError($data)) $this->addError(getError($data), self::ERROR_TYPE_GENERAL); else - $result[] = getData($data); + $result[] = current(getData($data)); } } @@ -327,4 +329,50 @@ class Konto extends FHCAPI_Controller $this->terminateWithSuccess($result); } + + /** + * Delete Buchung + * + * @return void + */ + public function delete() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('buchungsnr', 'Buchungsnr', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + + $buchungsnr = $this->input->post('buchungsnr'); + + $result = $this->KontoModel->load($buchungsnr); + #$result = $this->getDataOrTerminateWithError($result); + if (isError($result)) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $result = $result->retval; + + if (!$result) + $this->terminateWithError('buchung not found', self::ERROR_TYPE_GENERAL); + + $_POST['studiengang_kz'] = current($result)->studiengang_kz; + + $this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'has_permissions_for_stg[admin:rw,assistenz:rw]'); + + Events::trigger('konto_delete_validation', $this->form_validation); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + + Events::trigger('konto_delete', $buchungsnr); + + $result = $this->KontoModel->delete($buchungsnr); + #$this->getDataOrTerminateWithError($result); + if (isError($result)) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess(); + } } diff --git a/public/js/api/stv/konto.js b/public/js/api/stv/konto.js index 0e4069f2c..090bd30e2 100644 --- a/public/js/api/stv/konto.js +++ b/public/js/api/stv/konto.js @@ -25,6 +25,9 @@ export default { edit(data) { return this.$fhcApi.post('api/frontend/v1/stv/konto/update', data); }, + delete(buchungsnr) { + return this.$fhcApi.post('api/frontend/v1/stv/konto/delete', {buchungsnr}); + }, getBuchungstypen() { return this.$fhcApi.get('api/frontend/v1/stv/konto/getBuchungstypen'); } diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Konto.js b/public/js/components/Stv/Studentenverwaltung/Details/Konto.js index 849754050..155c51ee2 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Konto.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Konto.js @@ -154,6 +154,19 @@ export default { ); container.append(button); + button = document.createElement('button'); + button.className = 'btn btn-outline-secondary'; + button.innerHTML = ''; + button.addEventListener('click', () => + this.$fhcAlert + .confirmDelete() + .then(result => result ? cell.getData().buchungsnr : Promise.reject({handled:true})) + .then(this.$fhcApi.factory.stv.konto.delete) + .then(() => cell.getRow().delete()) + .catch(this.$fhcAlert.handleSystemError) + ); + container.append(button); + return container; }, frozen: true @@ -182,7 +195,7 @@ export default { updateData(data) { if (!data) return this.reload(); - this.$refs.table.tabulator.updateData(data); + this.$refs.table.tabulator.updateOrAddData(data); }, actionNew() { this.$refs.new.open(); @@ -221,6 +234,7 @@ export default { table-only :side-menu="false" :tabulator-options="tabulatorOptions" + reload new-btn-show new-btn-label="Buchung" :new-btn-disabled="stg_kz === ''" diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index abeb972a5..f4dd30a21 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -26573,6 +26573,26 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'sap', + 'phrase' => 'msg_buchung_deleted', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Buchungszuordnung SAP geloescht: SalesOrder: {sap_sales_order_id}', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Buchungszuordnung SAP deleted: SalesOrder: {sap_sales_order_id}', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), );