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 <hainberg@technikum-wien.at>
This commit is contained in:
cris-technikum
2021-01-20 11:02:15 +01:00
parent 403304e1a7
commit 964bd40c14
4 changed files with 195 additions and 2 deletions
+56
View File
@@ -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();