diff --git a/application/controllers/system/infocenter/Rueckstellung.php b/application/controllers/system/infocenter/Rueckstellung.php index 7872a1112..c30c258ba 100644 --- a/application/controllers/system/infocenter/Rueckstellung.php +++ b/application/controllers/system/infocenter/Rueckstellung.php @@ -22,6 +22,8 @@ class Rueckstellung extends Auth_Controller $this->load->model('crm/Rueckstellung_model', 'RueckstellungModel'); $this->load->model('crm/RueckstellungStatus_model', 'RueckstellungStatusModel'); $this->load->model('person/Person_model', 'PersonModel'); + $this->load->library('PersonLogLib'); + $this->_setAuthUID(); // sets property uid $this->_ci =& get_instance(); // get code igniter instance @@ -43,11 +45,17 @@ class Rueckstellung extends Auth_Controller $result = array( 'von' => $fullName, 'bezeichnung' => $rueckstellung->bezeichnung, - 'bis' => $rueckstellung->datum_bis + 'bis' => $rueckstellung->datum_bis, + 'status_kurzbz' => $rueckstellung->status_kurzbz ); + + if ($rueckstellung->status_kurzbz === 'parked' && $rueckstellung->datum_bis < date('Y-m-d')) + { + $this->_ci->RueckstellungModel->delete(array('person_id' => $person_id, 'status_kurzbz' => 'parked')); + $result = null; + } } - - + $this->outputJsonSuccess($result); } @@ -57,8 +65,19 @@ class Rueckstellung extends Auth_Controller $datum_bis = $this->input->post('datum_bis'); $status_kurzbz = $this->input->post('status_kurzbz'); - $result = $this->_ci->RueckstellungModel->set($person_id, date_format(date_create($datum_bis), 'Y-m-d'), $status_kurzbz, $this->_uid); + $result = $this->_ci->RueckstellungModel->insert( + array('person_id' => $person_id, + 'status_kurzbz' => $status_kurzbz, + 'datum_bis' => date_format(date_create($datum_bis), 'Y-m-d'), + 'insertvon' => $this->_uid + ) + ); + + if (isError($result)) + $this->terminateWithJsonError(getError($result)); + $this->_log($person_id, $status_kurzbz); + $this->outputJson($result); } @@ -66,23 +85,13 @@ class Rueckstellung extends Auth_Controller { $person_id = $this->input->post('person_id'); $status = $this->input->post('status'); - - $rueckstellungd = $this->_ci->RueckstellungModel->getByPersonId($person_id, $status); - - if (isError($rueckstellungd)) - $this->terminateWithJsonError($this->p->t('ui', 'fehlerBeimLesen')); - - - if (hasData($rueckstellungd)) - { - $rueckstellungd = getData($rueckstellungd)[0]; - $result = $this->_ci->RueckstellungModel->delete($rueckstellungd->rueckstellung_id); - - if (isError($result)) - $this->terminateWithJsonError($this->_ci->p->t('ui', 'fehlerBeimSpeichern')); - - $this->outputJson($result); - } + + $result = $this->_ci->RueckstellungModel->delete(array('person_id' => $person_id, 'status_kurzbz' => $status)); + + if (isError($result)) + $this->terminateWithJsonError($this->_ci->p->t('ui', 'fehlerBeimSpeichern')); + + $this->outputJson($result); } public function getStatus($aktiv = true) @@ -124,4 +133,23 @@ class Rueckstellung extends Auth_Controller if (!$this->_uid) show_error('User authentification failed'); } + + private function _log($person_id, $status_kurzbz) + { + $message = "Person $person_id set to $status_kurzbz"; + + $this->_ci->personloglib->log( + $person_id, + 'Action', + array( + 'name' => 'Person status set', + 'message' => $message, + 'success' => true + ), + 'bewerbung', + 'infocenter', + null, + $this->_uid + ); + } } \ No newline at end of file diff --git a/application/models/crm/Rueckstellung_model.php b/application/models/crm/Rueckstellung_model.php index 4d4821132..d2c39ffde 100644 --- a/application/models/crm/Rueckstellung_model.php +++ b/application/models/crm/Rueckstellung_model.php @@ -30,14 +30,4 @@ class Rueckstellung_model extends DB_Model return $this->loadWhere($where); } - - public function set($person_id, $datum_bis, $status_kurzbz, $uid) - { - $exists = $this->getByPersonId($person_id, $status_kurzbz); - - if (hasData($exists)) - return error("Rueckstellung entry already exists"); - - return $this->insert(array('person_id' => $person_id, 'status_kurzbz' => $status_kurzbz, 'datum_bis' => $datum_bis, 'insertvon' => $uid)); - } } \ No newline at end of file diff --git a/public/js/infocenter/rueckstellung.js b/public/js/infocenter/rueckstellung.js index a8bf9ca84..dbecb99f8 100644 --- a/public/js/infocenter/rueckstellung.js +++ b/public/js/infocenter/rueckstellung.js @@ -73,7 +73,10 @@ var Rueckstellung = { { successCallback: function(data, textStatus, jqXHR) { if (FHC_AjaxClient.hasData(data)) + { Rueckstellung.get(personid); + InfocenterDetails._refreshLog() + } else { onRueckstellungError(); @@ -152,7 +155,7 @@ var Rueckstellung = { var callbackforundo = function () { - Rueckstellung.delete(personid); + Rueckstellung.delete(personid, rueckstellungobj.status_kurzbz); } var rueckstellunghtml = rueckstellungdtext+'     '+