Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge branch 'pu/pm/HRWTRCorrectionParentUpdate' into 'pu/pm/HRFreeTi…
Browse files Browse the repository at this point in the history
…meStatusTypeAcl'

tweak(HR WTR) apply correction requests to wtrs on acceptance

See merge request tine20/tine20!1918
  • Loading branch information
paulmhh committed Mar 14, 2022
2 parents 9f9fd41 + ce22940 commit 3f4b4f1
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
34 changes: 33 additions & 1 deletion tine20/HumanResources/Controller/DailyWTReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class HumanResources_Controller_DailyWTReport extends Tinebase_Controller_Record
protected $_requiredFilterACLsync = [HumanResources_Model_DivisionGrants::READ_TIME_DATA];
protected $_requiredFilterACLexport = [HumanResources_Model_DivisionGrants::READ_TIME_DATA];

protected $allowCorrectionUpdate = false;

/**
* the constructor
*
Expand Down Expand Up @@ -757,10 +759,12 @@ protected function _inspectBeforeUpdate($_record, $_oldRecord)
$allowedProperties = [
'evaluation_period_start_correction' => true,
'evaluation_period_end_correction' => true,
'working_time_correction' => true,
'working_time_target_correction' => true,
'user_remark' => true,
];
if ($this->allowCorrectionUpdate) {
$allowedProperties[HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION] = true;
}
foreach ($_record->getFields() as $prop) {
if (!isset($allowedProperties[$prop])) {
$_record->{$prop} = $_oldRecord->{$prop};
Expand Down Expand Up @@ -796,4 +800,32 @@ protected function _inspectAfterUpdate($updatedRecord, $record, $currentRecord)
}
}
}

public function recalcCorrection(string $id)
{
$correction = 0;
foreach (HumanResources_Controller_WTRCorrection::getInstance()->search(
Tinebase_Model_Filter_FilterGroup::getFilterForModel(HumanResources_Model_WTRCorrection::class,[
['field' => HumanResources_Model_WTRCorrection::FLD_WTR_DAILY, 'operator' => 'equals', 'value' => $id],
['field' => HumanResources_Model_WTRCorrection::FLD_STATUS, 'operator' => 'equals', 'value' => HumanResources_Config::WTR_CORRECTION_STATUS_ACCEPTED],
])) as $c) {
$correction += intval($c->{HumanResources_Model_WTRCorrection::FLD_CORRECTION});
}

$oldAclVal = $this->doContainerACLChecks(false);
$oldCorrectionVal = $this->allowCorrectionUpdate;
$this->allowCorrectionUpdate = true;
$raii = new Tinebase_RAII(function() use($oldAclVal, $oldCorrectionVal) {
$this->doContainerACLChecks($oldAclVal);
$this->allowCorrectionUpdate = $oldCorrectionVal;
});

$record = $this->get($id);
if (intval($record->{HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION}) !== $correction) {
$record->{HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION} = $correction;
$this->update($record);
}

unset($raii);
}
}
34 changes: 33 additions & 1 deletion tine20/HumanResources/Controller/MonthlyWTReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class HumanResources_Controller_MonthlyWTReport extends Tinebase_Controller_Reco
protected $_requiredFilterACLsync = [HumanResources_Model_DivisionGrants::READ_TIME_DATA];
protected $_requiredFilterACLexport = [HumanResources_Model_DivisionGrants::READ_TIME_DATA];

protected $allowCorrectionUpdate = false;

/**
* the constructor
*
Expand Down Expand Up @@ -223,8 +225,10 @@ protected function _inspectBeforeUpdate($_record, $_oldRecord)
if (isset($this->_requestContext[self::RC_JSON_REQUEST])) {
$allowedProperties = [
HumanResources_Model_MonthlyWTReport::FLDS_IS_CLEARED => true,
HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION => true,
];
if ($this->allowCorrectionUpdate) {
$allowedProperties[HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION] = true;
}
foreach ($_record->getFields() as $prop) {
if (!isset($allowedProperties[$prop])) {
$_record->{$prop} = $_oldRecord->{$prop};
Expand Down Expand Up @@ -304,4 +308,32 @@ protected function _inspectAfterUpdate($updatedRecord, $record, $currentRecord)
}
}
}

public function recalcCorrection(string $id)
{
$correction = 0;
foreach (HumanResources_Controller_WTRCorrection::getInstance()->search(
Tinebase_Model_Filter_FilterGroup::getFilterForModel(HumanResources_Model_WTRCorrection::class,[
['field' => HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY, 'operator' => 'equals', 'value' => $id],
['field' => HumanResources_Model_WTRCorrection::FLD_STATUS, 'operator' => 'equals', 'value' => HumanResources_Config::WTR_CORRECTION_STATUS_ACCEPTED],
])) as $c) {
$correction += intval($c->{HumanResources_Model_WTRCorrection::FLD_CORRECTION});
}

$oldAclVal = $this->doContainerACLChecks(false);
$oldCorrectionVal = $this->allowCorrectionUpdate;
$this->allowCorrectionUpdate = true;
$raii = new Tinebase_RAII(function() use($oldAclVal, $oldCorrectionVal) {
$this->doContainerACLChecks($oldAclVal);
$this->allowCorrectionUpdate = $oldCorrectionVal;
});

$record = $this->get($id);
if (intval($record->{HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION}) !== $correction) {
$record->{HumanResources_Model_MonthlyWTReport::FLDS_WORKING_TIME_CORRECTION} = $correction;
$this->update($record);
}

unset($raii);
}
}
44 changes: 44 additions & 0 deletions tine20/HumanResources/Controller/WTRCorrection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,49 @@ protected function _inspect($record)
HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY . ' or ' .
HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY . ' needs to be set');
}
if ($record->{HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY} &&
$record->{HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY}) {
throw new Tinebase_Exception_Record_Validation(HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY . ' and '
. HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY . ' must not be both set');
}
}

protected function _inspectAfterCreate($_createdRecord, Tinebase_Record_Interface $_record)
{
parent::_inspectAfterCreate($_createdRecord, $_record);
/** @var HumanResources_Model_WTRCorrection $_createdRecord */
$this->updateParent($_createdRecord);
}

protected function _inspectAfterUpdate($updatedRecord, $record, $currentRecord)
{
parent::_inspectAfterUpdate($updatedRecord, $record, $currentRecord);
/** @var HumanResources_Model_WTRCorrection $updatedRecord */
$this->updateParent($updatedRecord);
if ($record->getIdFromProperty(HumanResources_Model_WTRCorrection::FLD_WTR_DAILY)
!== $currentRecord->getIdFromProperty(HumanResources_Model_WTRCorrection::FLD_WTR_DAILY) ||
$record->getIdFromProperty(HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY)
!== $currentRecord->getIdFromProperty(HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY)) {
$this->updateParent($currentRecord);
}
}

protected function _inspectAfterDelete(Tinebase_Record_Interface $record)
{
parent::_inspectAfterDelete($record);
/** @var HumanResources_Model_WTRCorrection $record */
$this->updateParent($record);
}

protected function updateParent(HumanResources_Model_WTRCorrection $record)
{
if ($record->{HumanResources_Model_WTRCorrection::FLD_WTR_DAILY}) {
$ctrl = HumanResources_Controller_DailyWTReport::getInstance();
$id = $record->getIdFromProperty(HumanResources_Model_WTRCorrection::FLD_WTR_DAILY);
} else {
$ctrl = HumanResources_Controller_MonthlyWTReport::getInstance();
$id = $record->getIdFromProperty(HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY);
}
$ctrl->recalcCorrection($id);
}
}
22 changes: 21 additions & 1 deletion tine20/HumanResources/Model/DailyWTReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @subpackage Model
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Cornelius Weiss <c.weiss@metaways.de>
* @copyright Copyright (c) 2018-2019 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2018-2022 Metaways Infosystems GmbH (http://www.metaways.de)
*/

/**
Expand Down Expand Up @@ -132,6 +132,12 @@ class HumanResources_Model_DailyWTReport extends Tinebase_Record_Abstract
],
],

self::JSON_EXPANDER => [
Tinebase_Record_Expander::EXPANDER_PROPERTIES => [
HumanResources_Model_MonthlyWTReport::FLDS_CORRECTIONS => [],
],
],

'fields' => [
'employee_id' => [
self::LABEL => 'Employee',
Expand Down Expand Up @@ -340,6 +346,20 @@ class HumanResources_Model_DailyWTReport extends Tinebase_Record_Abstract
self::DEFAULT_VAL => 0,
self::COPY_OMIT => true,
],
HumanResources_Model_MonthlyWTReport::FLDS_CORRECTIONS => [
self::TYPE => self::TYPE_RECORDS,
self::LABEL => 'Working Time Correction Requests', // _('Working Time Correction Requests')
self::NULLABLE => true,
self::DOCTRINE_IGNORE => true,
self::CONFIG => [
self::APP_NAME => HumanResources_Config::APP_NAME,
self::MODEL_NAME => HumanResources_Model_WTRCorrection::MODEL_NAME_PART,
self::REF_ID_FIELD => HumanResources_Model_WTRCorrection::FLD_WTR_DAILY,
],
self::UI_CONFIG => [
self::READ_ONLY => true,
],
],
]
];

Expand Down
23 changes: 22 additions & 1 deletion tine20/HumanResources/Model/MonthlyWTReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @subpackage Model
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Paul Mehrer <p.mehrer@metaways.de>
* @copyright Copyright (c) 2019 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2019-2022 Metaways Infosystems GmbH (http://www.metaways.de)
*/

/**
Expand All @@ -30,6 +30,7 @@ class HumanResources_Model_MonthlyWTReport extends Tinebase_Record_Abstract
const MODEL_NAME_PART = 'MonthlyWTReport';
const TABLE_NAME = 'humanresources_wt_monthlyreport';

const FLDS_CORRECTIONS = 'corrections';
const FLDS_MONTH = 'month';
const FLDS_EMPLOYEE_ID = 'employee_id';
const FLDS_DAILY_WT_REPORTS = 'dailywtreports';
Expand Down Expand Up @@ -100,6 +101,12 @@ class HumanResources_Model_MonthlyWTReport extends Tinebase_Record_Abstract
],
],

self::JSON_EXPANDER => [
Tinebase_Record_Expander::EXPANDER_PROPERTIES => [
self::FLDS_CORRECTIONS => [],
],
],

self::FIELDS => [
self::FLDS_EMPLOYEE_ID => [
self::LABEL => 'Employee', // _('Employee')
Expand Down Expand Up @@ -213,6 +220,20 @@ class HumanResources_Model_MonthlyWTReport extends Tinebase_Record_Abstract
self::SHY => true,
self::TYPE => self::TYPE_VIRTUAL,
],
self::FLDS_CORRECTIONS => [
self::TYPE => self::TYPE_RECORDS,
self::LABEL => 'Working Time Correction Requests', // _('Working Time Correction Requests')
self::NULLABLE => true,
self::DOCTRINE_IGNORE => true,
self::CONFIG => [
self::APP_NAME => HumanResources_Config::APP_NAME,
self::MODEL_NAME => HumanResources_Model_WTRCorrection::MODEL_NAME_PART,
self::REF_ID_FIELD => HumanResources_Model_WTRCorrection::FLD_WTR_MONTHLY,
],
self::UI_CONFIG => [
self::READ_ONLY => true,
],
],
],
];

Expand Down

0 comments on commit 3f4b4f1

Please sign in to comment.