Skip to content

Commit 84ba8a2

Browse files
OHRM5X-2265: Fix dashboard - subunit pie chart issue on PHP 8.2 (orangehrm#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 <devishke@orangehrmlive.com>
1 parent 2877f3c commit 84ba8a2

File tree

10 files changed

+82
-19
lines changed

10 files changed

+82
-19
lines changed

installer/Migration/V5_5_0/Migration.php

+12
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ public function up(): void
303303

304304
$this->deleteClaimWorkflowStates();
305305
$this->removeMarketplaceTables();
306+
$this->updateI18nGroups();
306307

307308
$this->insertWorkflowState(
308309
'INITIATED',
@@ -724,4 +725,15 @@ private function removeMarketplaceTables(): void
724725
$this->getSchemaManager()->dropTable('ohrm_marketplace_addon');
725726
}
726727
}
728+
729+
private function updateI18nGroups(): void
730+
{
731+
$qb = $this->createQueryBuilder()
732+
->update('ohrm_i18n_lang_string', 'langString')
733+
->set('langString.group_id', ':groupId')
734+
->setParameter('groupId', $this->getLangHelper()->getGroupIdByName('general'));
735+
$qb->andWhere($qb->expr()->in('langString.unit_id', ':unitIdToChangeGroup'))
736+
->setParameter('unitIdToChangeGroup', 'today')
737+
->executeQuery();
738+
}
727739
}

installer/Migration/V5_5_0/lang-string/general.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ langStrings:
55
-
66
value: 'to download the latest stable release.'
77
unitId: download_latest_release
8-
-
9-
value: 'Today'
10-
unitId: today
118
-
129
value: 'Clear'
1310
unitId: clear

src/client/src/orangehrmClaimPlugin/pages/EditClaimEvent.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ export default {
146146
const {data} = response.data;
147147
this.rules.name.push((value) => {
148148
const index = data.findIndex(
149-
(item) =>
150-
value.trim().toLowerCase() !== this.name &&
151-
item.name.toLowerCase() == value.trim().toLowerCase(),
149+
(item) => item.name.toLowerCase() == value.trim().toLowerCase(),
152150
);
153-
return index === -1 || this.$t('general.already_exists');
151+
if (index > -1) {
152+
const {id} = data[index];
153+
return id != this.id ? this.$t('general.already_exists') : true;
154+
}
155+
return true;
154156
});
155157
})
156158
.finally(() => {

src/client/src/orangehrmClaimPlugin/pages/claimExpenseTypes/EditClaimExpenseType.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ export default {
147147
const {data} = response.data;
148148
this.rules.name.push((value) => {
149149
const index = data.findIndex(
150-
(item) =>
151-
value.trim().toLowerCase() !== this.name &&
152-
item.name.toLowerCase() == value.trim().toLowerCase(),
150+
(item) => item.name.toLowerCase() == value.trim().toLowerCase(),
153151
);
154-
return index === -1 || this.$t('general.already_exists');
152+
if (index > -1) {
153+
const {id} = data[index];
154+
return id != this.id ? this.$t('general.already_exists') : true;
155+
}
156+
return true;
155157
});
156158
})
157159
.finally(() => {

src/client/src/orangehrmDashboardPlugin/components/EmployeeAttendanceWidget.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<div class="orangehrm-attendance-card-bar">
4646
<oxd-text tag="span" class="orangehrm-attendance-card-fulltime">
4747
<b>{{ dayTotal.hours }}h</b> <b>{{ dayTotal.minutes }}m</b>
48-
{{ $t('dashboard.today') }}
48+
{{ $t('general.today') }}
4949
</oxd-text>
5050
<oxd-icon-button
5151
name="stopwatch"

src/plugins/orangehrmAttendancePlugin/Api/TimezonesAPI.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function ($item) use ($filterName) {
114114
}
115115
usort(
116116
$timezones,
117-
fn ($timezone1, $timezone2) => $timezone1['offset'] > $timezone2['offset']
117+
fn ($timezone1, $timezone2) => $timezone1['offset'] > $timezone2['offset'] ? 1 : -1
118118
);
119119
return new EndpointCollectionResult(
120120
ArrayModel::class,

src/plugins/orangehrmClaimPlugin/Api/ClaimExpenseTypeAPI.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function getValidationRuleForCreate(): ParamRuleCollection
201201
{
202202
return new ParamRuleCollection(
203203
$this->getValidationDecorator()->requiredParamRule(
204-
$this->getNameRule(),
204+
$this->getNameRule(false),
205205
),
206206
$this->getValidationDecorator()->notRequiredParamRule(
207207
new ParamRule(
@@ -219,12 +219,19 @@ public function getValidationRuleForCreate(): ParamRuleCollection
219219
}
220220

221221
/**
222+
* @param bool $update
222223
* @return ParamRule
223224
*/
224-
protected function getNameRule(): ParamRule
225+
protected function getNameRule(bool $update): ParamRule
225226
{
226227
$entityProperties = new EntityUniquePropertyOption();
227228
$ignoreValues = ['isDeleted' => true];
229+
if ($update) {
230+
$ignoreValues['getId'] = $this->getRequestParams()->getInt(
231+
RequestParams::PARAM_TYPE_ATTRIBUTE,
232+
CommonParams::PARAMETER_ID
233+
);
234+
}
228235
$entityProperties->setIgnoreValues($ignoreValues);
229236

230237
return new ParamRule(
@@ -412,7 +419,7 @@ public function getValidationRuleForUpdate(): ParamRuleCollection
412419
new Rule(Rules::BOOL_VAL)
413420
),
414421
$this->getValidationDecorator()->notRequiredParamRule(
415-
$this->getNameRule(),
422+
$this->getNameRule(true),
416423
),
417424
);
418425
}

src/plugins/orangehrmClaimPlugin/test/fixtures/testcases/ClaimExpenseTypeAPITestCases.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,23 @@ Update:
554554
}
555555
meta: [ ]
556556

557+
"update a claim event without changing name":
558+
userId: 1
559+
services:
560+
claim.claim_service: OrangeHRM\Claim\Service\ClaimService
561+
attributes:
562+
id: 2
563+
body:
564+
name: 'medical'
565+
description: 'medical expenses'
566+
status: true
567+
data:
568+
id: 2
569+
name: 'medical'
570+
description: 'medical expenses'
571+
status: true
572+
meta: [ ]
573+
557574
Delete:
558575
'with one id':
559576
userId: 1

src/plugins/orangehrmDashboardPlugin/Service/ChartService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getEmployeeDistributionBySubunit(int $limit = 8): EmployeeDistri
5050
usort(
5151
$subunitCountPairs,
5252
static function (SubunitCountPair $x, SubunitCountPair $y) {
53-
return $x->getCount() < $y->getCount();
53+
return ($x->getCount() < $y->getCount()) ? 1 : -1;
5454
}
5555
);
5656

src/plugins/orangehrmDashboardPlugin/test/Service/ChartServiceTest.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,51 @@
1919

2020
namespace OrangeHRM\Tests\Dashboard\Service;
2121

22+
use OrangeHRM\Admin\Service\CompanyStructureService;
23+
use OrangeHRM\Config\Config;
2224
use OrangeHRM\Dashboard\Dao\ChartDao;
2325
use OrangeHRM\Dashboard\Service\ChartService;
24-
use OrangeHRM\Tests\Util\TestCase;
26+
use OrangeHRM\Framework\Services;
27+
use OrangeHRM\Tests\Util\KernelTestCase;
28+
use OrangeHRM\Tests\Util\TestDataService;
2529

2630
/**
2731
* @group Dashboard
2832
* @group Service
2933
*/
30-
class ChartServiceTest extends TestCase
34+
class ChartServiceTest extends KernelTestCase
3135
{
36+
protected string $fixture;
3237
private ChartService $chartService;
3338

39+
/**
40+
* Set up method
41+
*/
3442
protected function setUp(): void
3543
{
3644
$this->chartService = new ChartService();
45+
$this->fixture = Config::get(
46+
Config::PLUGINS_DIR
47+
) . '/orangehrmDashboardPlugin/test/fixtures/ChartDao.yml';
48+
TestDataService::populate($this->fixture);
49+
$this->createKernelWithMockServices([
50+
Services::COMPANY_STRUCTURE_SERVICE => new CompanyStructureService(),
51+
]);
3752
}
3853

3954
public function testGetChartDao(): void
4055
{
4156
$this->assertTrue($this->chartService->getChartDao() instanceof ChartDao);
4257
}
58+
59+
public function testGetEmployeeDistributionBySubunit(): void
60+
{
61+
$distributionBySubunit = $this->chartService->getEmployeeDistributionBySubunit();
62+
$subunitCountPairs = $distributionBySubunit->getSubunitCountPairs();
63+
$this->assertEquals('0', $distributionBySubunit->getOtherEmployeeCount());
64+
$this->assertEquals('9', $distributionBySubunit->getTotalSubunitCount());
65+
$this->assertEquals('3', $distributionBySubunit->getUnassignedEmployeeCount());
66+
$this->assertEquals('8', $distributionBySubunit->getLimit());
67+
$this->assertEquals($distributionBySubunit->getTotalSubunitCount(), sizeof($subunitCountPairs));
68+
}
4369
}

0 commit comments

Comments
 (0)