mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-26 00:19:28 +00:00
Adapted & Enhanced Withdrawing of Approvement
. Added 'genehmigt von' . Moved out to Model and added db rollback Signed-off-by: cris-technikum <hainberg@technikum-wien.at>
This commit is contained in:
@@ -280,34 +280,20 @@ class approveAnrechnungDetail extends Auth_Controller
|
||||
|
||||
if (!is_numeric($anrechnung_id))
|
||||
{
|
||||
show_error('Wrong parameter.');
|
||||
$this->terminateWithJsonError($this->p->t('ui', 'errorFelderFehlen'));
|
||||
}
|
||||
|
||||
// Get last Anrechnungstatus
|
||||
if (!$result = getData($this->AnrechnungModel->getLastAnrechnungstatus($anrechnung_id))[0])
|
||||
{
|
||||
show_error('Failed loading Anrechnung');
|
||||
}
|
||||
|
||||
$last_status = $result->status_kurzbz;
|
||||
$anrechnungstatus_id = $result->anrechnungstatus_id;
|
||||
|
||||
// Return if last status is not approved / rejected
|
||||
if ($last_status != self::ANRECHNUNGSTATUS_APPROVED && $last_status != self::ANRECHNUNGSTATUS_REJECTED)
|
||||
{
|
||||
return $this->outputJsonError('Nothing to withdraw. Application is still in progress.');
|
||||
}
|
||||
|
||||
// Withdraw status approved / rejected
|
||||
$result = $this->AnrechnungModel->deleteAnrechnungstatus($anrechnungstatus_id);
|
||||
|
||||
// Delete last status approved / rejected.
|
||||
// If last status is 'approved', Genehmigung is resetted.
|
||||
$result = $this->AnrechnungModel->withdrawApprovement($anrechnung_id);
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
return $this->outputJsonError('Could not withdraw this application.');
|
||||
$this->terminateWithJsonError(getError($result));
|
||||
}
|
||||
|
||||
// Success output to AJAX
|
||||
return $this->outputJsonSuccess(array(
|
||||
$this->outputJsonSuccess(array(
|
||||
'status_bezeichnung' => $this->anrechnunglib->getLastAnrechnungstatus($anrechnung_id))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ class Anrechnung_model extends DB_Model
|
||||
{
|
||||
const ANRECHNUNGSTATUS_PROGRESSED_BY_STGL = 'inProgressDP';
|
||||
|
||||
const ANRECHNUNGSTATUS_APPROVED = 'approved';
|
||||
const ANRECHNUNGSTATUS_REJECTED = 'rejected';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@@ -148,4 +151,53 @@ class Anrechnung_model extends DB_Model
|
||||
|
||||
return $this->execQuery($qry, array($anrechnungstatus_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete last status approved / rejected.
|
||||
* If last status is 'approved', Genehmigung is resetted.
|
||||
*
|
||||
* @param $anrechnung_id
|
||||
* @return array
|
||||
*/
|
||||
public function withdrawApprovement($anrechnung_id)
|
||||
{
|
||||
// Get last Anrechnungstatus
|
||||
if (!$result = getData($this->AnrechnungModel->getLastAnrechnungstatus($anrechnung_id))[0])
|
||||
{
|
||||
return error('Failed loading Anrechnung');
|
||||
}
|
||||
|
||||
$last_status = $result->status_kurzbz;
|
||||
$anrechnungstatus_id = $result->anrechnungstatus_id;
|
||||
|
||||
// Exit, if last status is not approved / rejected
|
||||
if ($last_status != self::ANRECHNUNGSTATUS_APPROVED && $last_status != self::ANRECHNUNGSTATUS_REJECTED)
|
||||
{
|
||||
return error('Nothing to withdraw. Application is still in progress');
|
||||
}
|
||||
|
||||
// Start DB transaction
|
||||
$this->db->trans_start(false);
|
||||
|
||||
// If Anrechnung was approved
|
||||
if ($last_status == self::ANRECHNUNGSTATUS_APPROVED)
|
||||
{
|
||||
// Reset Genehmigung
|
||||
$this->AnrechnungModel->update($anrechnung_id, array('genehmigt_von' => NULL));
|
||||
}
|
||||
|
||||
// Delete last status approved / rejected
|
||||
$this->AnrechnungModel->deleteAnrechnungstatus($anrechnungstatus_id);
|
||||
|
||||
// Transaction complete
|
||||
$this->db->trans_complete();
|
||||
|
||||
if ($this->db->trans_status() === false)
|
||||
{
|
||||
$this->db->trans_rollback();
|
||||
return error('Failed withdrawing Genehmigung', EXIT_ERROR);
|
||||
}
|
||||
return success();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user