Skip to content

Commit

Permalink
OHRM5X-2265: Fix dashboard - subunit pie chart issue on PHP 8.2 (oran…
Browse files Browse the repository at this point in the history
…gehrm#1714)

* OHRM5X-2264: Fix dashboard - time at work `Today` not localized

* OHRM5X-2266: Fix time - timezone values not loading in PHP 8.2

* OHRM5X-2267: Fix claim - event/expense unique issue when editing

---------

Co-authored-by: Devishke <[email protected]>
  • Loading branch information
ManulMax and devishke-orange authored Jul 7, 2023
1 parent 2877f3c commit 84ba8a2
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 19 deletions.
12 changes: 12 additions & 0 deletions installer/Migration/V5_5_0/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public function up(): void

$this->deleteClaimWorkflowStates();
$this->removeMarketplaceTables();
$this->updateI18nGroups();

$this->insertWorkflowState(
'INITIATED',
Expand Down Expand Up @@ -724,4 +725,15 @@ private function removeMarketplaceTables(): void
$this->getSchemaManager()->dropTable('ohrm_marketplace_addon');
}
}

private function updateI18nGroups(): void
{
$qb = $this->createQueryBuilder()
->update('ohrm_i18n_lang_string', 'langString')
->set('langString.group_id', ':groupId')
->setParameter('groupId', $this->getLangHelper()->getGroupIdByName('general'));
$qb->andWhere($qb->expr()->in('langString.unit_id', ':unitIdToChangeGroup'))
->setParameter('unitIdToChangeGroup', 'today')
->executeQuery();
}
}
3 changes: 0 additions & 3 deletions installer/Migration/V5_5_0/lang-string/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ langStrings:
-
value: 'to download the latest stable release.'
unitId: download_latest_release
-
value: 'Today'
unitId: today
-
value: 'Clear'
unitId: clear
Expand Down
10 changes: 6 additions & 4 deletions src/client/src/orangehrmClaimPlugin/pages/EditClaimEvent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ export default {
const {data} = response.data;
this.rules.name.push((value) => {
const index = data.findIndex(
(item) =>
value.trim().toLowerCase() !== this.name &&
item.name.toLowerCase() == value.trim().toLowerCase(),
(item) => item.name.toLowerCase() == value.trim().toLowerCase(),
);
return index === -1 || this.$t('general.already_exists');
if (index > -1) {
const {id} = data[index];
return id != this.id ? this.$t('general.already_exists') : true;
}
return true;
});
})
.finally(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,13 @@ export default {
const {data} = response.data;
this.rules.name.push((value) => {
const index = data.findIndex(
(item) =>
value.trim().toLowerCase() !== this.name &&
item.name.toLowerCase() == value.trim().toLowerCase(),
(item) => item.name.toLowerCase() == value.trim().toLowerCase(),
);
return index === -1 || this.$t('general.already_exists');
if (index > -1) {
const {id} = data[index];
return id != this.id ? this.$t('general.already_exists') : true;
}
return true;
});
})
.finally(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="orangehrm-attendance-card-bar">
<oxd-text tag="span" class="orangehrm-attendance-card-fulltime">
<b>{{ dayTotal.hours }}h</b> <b>{{ dayTotal.minutes }}m</b>
{{ $t('dashboard.today') }}
{{ $t('general.today') }}
</oxd-text>
<oxd-icon-button
name="stopwatch"
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/orangehrmAttendancePlugin/Api/TimezonesAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function ($item) use ($filterName) {
}
usort(
$timezones,
fn ($timezone1, $timezone2) => $timezone1['offset'] > $timezone2['offset']
fn ($timezone1, $timezone2) => $timezone1['offset'] > $timezone2['offset'] ? 1 : -1
);
return new EndpointCollectionResult(
ArrayModel::class,
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/orangehrmClaimPlugin/Api/ClaimExpenseTypeAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function getValidationRuleForCreate(): ParamRuleCollection
{
return new ParamRuleCollection(
$this->getValidationDecorator()->requiredParamRule(
$this->getNameRule(),
$this->getNameRule(false),
),
$this->getValidationDecorator()->notRequiredParamRule(
new ParamRule(
Expand All @@ -219,12 +219,19 @@ public function getValidationRuleForCreate(): ParamRuleCollection
}

/**
* @param bool $update
* @return ParamRule
*/
protected function getNameRule(): ParamRule
protected function getNameRule(bool $update): ParamRule
{
$entityProperties = new EntityUniquePropertyOption();
$ignoreValues = ['isDeleted' => true];
if ($update) {
$ignoreValues['getId'] = $this->getRequestParams()->getInt(
RequestParams::PARAM_TYPE_ATTRIBUTE,
CommonParams::PARAMETER_ID
);
}
$entityProperties->setIgnoreValues($ignoreValues);

return new ParamRule(
Expand Down Expand Up @@ -412,7 +419,7 @@ public function getValidationRuleForUpdate(): ParamRuleCollection
new Rule(Rules::BOOL_VAL)
),
$this->getValidationDecorator()->notRequiredParamRule(
$this->getNameRule(),
$this->getNameRule(true),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,23 @@ Update:
}
meta: [ ]

"update a claim event without changing name":
userId: 1
services:
claim.claim_service: OrangeHRM\Claim\Service\ClaimService
attributes:
id: 2
body:
name: 'medical'
description: 'medical expenses'
status: true
data:
id: 2
name: 'medical'
description: 'medical expenses'
status: true
meta: [ ]

Delete:
'with one id':
userId: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getEmployeeDistributionBySubunit(int $limit = 8): EmployeeDistri
usort(
$subunitCountPairs,
static function (SubunitCountPair $x, SubunitCountPair $y) {
return $x->getCount() < $y->getCount();
return ($x->getCount() < $y->getCount()) ? 1 : -1;
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,51 @@

namespace OrangeHRM\Tests\Dashboard\Service;

use OrangeHRM\Admin\Service\CompanyStructureService;
use OrangeHRM\Config\Config;
use OrangeHRM\Dashboard\Dao\ChartDao;
use OrangeHRM\Dashboard\Service\ChartService;
use OrangeHRM\Tests\Util\TestCase;
use OrangeHRM\Framework\Services;
use OrangeHRM\Tests\Util\KernelTestCase;
use OrangeHRM\Tests\Util\TestDataService;

/**
* @group Dashboard
* @group Service
*/
class ChartServiceTest extends TestCase
class ChartServiceTest extends KernelTestCase
{
protected string $fixture;
private ChartService $chartService;

/**
* Set up method
*/
protected function setUp(): void
{
$this->chartService = new ChartService();
$this->fixture = Config::get(
Config::PLUGINS_DIR
) . '/orangehrmDashboardPlugin/test/fixtures/ChartDao.yml';
TestDataService::populate($this->fixture);
$this->createKernelWithMockServices([
Services::COMPANY_STRUCTURE_SERVICE => new CompanyStructureService(),
]);
}

public function testGetChartDao(): void
{
$this->assertTrue($this->chartService->getChartDao() instanceof ChartDao);
}

public function testGetEmployeeDistributionBySubunit(): void
{
$distributionBySubunit = $this->chartService->getEmployeeDistributionBySubunit();
$subunitCountPairs = $distributionBySubunit->getSubunitCountPairs();
$this->assertEquals('0', $distributionBySubunit->getOtherEmployeeCount());
$this->assertEquals('9', $distributionBySubunit->getTotalSubunitCount());
$this->assertEquals('3', $distributionBySubunit->getUnassignedEmployeeCount());
$this->assertEquals('8', $distributionBySubunit->getLimit());
$this->assertEquals($distributionBySubunit->getTotalSubunitCount(), sizeof($subunitCountPairs));
}
}

0 comments on commit 84ba8a2

Please sign in to comment.