Skip to content

Commit defea96

Browse files
authored
OHRM5X-2219: Add claim - include employee filter to employee claims (orangehrm#1705)
* OHRM5X-2178: Fix attachment file size issue * OHRM5X-2218: Fix "Deleted" tag is not being displayed for deleted event and expense types that have been used for claim requests * OHRM5X-2233: Fix doesn't show the "Inactive" tag for the inactive event and expense type
1 parent 8f433d3 commit defea96

25 files changed

+426
-59
lines changed

src/client/src/core/util/helper/__tests__/filesize.spec.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('core/util/helper/filesize', () => {
2626

2727
test('convertFilesizeToString::convert 1000 bytes', () => {
2828
const result = convertFilesizeToString(1000);
29-
expect(result).toBe('1000 B');
29+
expect(result).toBe('1 kB');
3030
});
3131

3232
test('convertFilesizeToString::convert 1024 bytes', () => {
@@ -41,36 +41,46 @@ describe('core/util/helper/filesize', () => {
4141

4242
test('convertFilesizeToString::convert 1500 bytes', () => {
4343
const result = convertFilesizeToString(1500, 2);
44-
expect(result).toBe('1.46 kB');
44+
expect(result).toBe('1.50 kB');
4545
});
4646

4747
test('convertFilesizeToString::convert 1800 bytes', () => {
4848
const result = convertFilesizeToString(1800, 2);
49-
expect(result).toBe('1.76 kB');
49+
expect(result).toBe('1.80 kB');
5050
});
5151

5252
test('convertFilesizeToString::convert 1000000 bytes', () => {
53-
const result = convertFilesizeToString(1000000, 2);
54-
expect(result).toBe('976.56 kB');
53+
const result = convertFilesizeToString(999999, 2);
54+
expect(result).toBe('1000.00 kB');
5555
});
5656

5757
test('convertFilesizeToString::convert 1024 kB', () => {
5858
const result = convertFilesizeToString(1048576, 2);
59-
expect(result).toBe('1.00 MB');
59+
expect(result).toBe('1.05 MB');
6060
});
6161

6262
test('convertFilesizeToString::convert 1024 MB', () => {
6363
const result = convertFilesizeToString(1024 * 1024 * 1024, 2);
64-
expect(result).toBe('1.00 GB');
64+
expect(result).toBe('1.07 GB');
6565
});
6666

6767
test('convertFilesizeToString::convert 1024 bytes (string type)', () => {
6868
const result = convertFilesizeToString('1024', 2);
69-
expect(result).toBe('1.00 kB');
69+
expect(result).toBe('1.02 kB');
7070
});
7171

7272
test('convertFilesizeToString::convert 1024 bytes (without suffix)', () => {
7373
const result = convertFilesizeToString(1024, 2, false);
74-
expect(result).toBe('1.00');
74+
expect(result).toBe('1.02');
75+
});
76+
77+
test('convertFilesizeToString::convert 1024 kB', () => {
78+
const result = convertFilesizeToString(1000 * 1000, 2);
79+
expect(result).toBe('1.00 MB');
80+
});
81+
82+
test('convertFilesizeToString::convert 1024 MB', () => {
83+
const result = convertFilesizeToString(1000 * 1000 * 1000, 2);
84+
expect(result).toBe('1.00 GB');
7585
});
7686
});

src/client/src/core/util/helper/filesize.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
*/
1818

1919
const BYTE = 1;
20-
const KILO_BYTE = 1024;
21-
const MEGA_BYTE = 1048576; // 1024 * 1024
22-
const GIGA_BYTE = 1073741824; // 1024 * 1024 * 1024
20+
const KILO_BYTE = 1000;
21+
const MEGA_BYTE = 1000000; // 1000 * 1000
22+
const GIGA_BYTE = 1000000000; // 1000 * 1000 * 1000
2323

2424
/**
2525
* @param {string|number} value

src/client/src/orangehrmClaimPlugin/components/EditExpenseModal.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ export default {
174174
this.expense.amount = parseFloat(data.amount).toFixed(2);
175175
this.selectedOption = {
176176
id: data.expenseType.id,
177-
label: data.expenseType.name,
177+
label: data.expenseType.isDeleted
178+
? `${data.expenseType.name} (${this.$t('general.deleted')})`
179+
: !data.expenseType.status
180+
? `${data.expenseType.name} (${this.$t('performance.inactive')})`
181+
: data.expenseType.name,
178182
};
179183
})
180184
.finally(() => {

src/client/src/orangehrmClaimPlugin/pages/assignClaim/AssignClaim.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</oxd-grid-item>
5050
<oxd-grid-item>
5151
<oxd-input-field
52-
v-model="claimEvent.name"
52+
v-model="formattedEventName"
5353
:label="$t('claim.event')"
5454
disabled
5555
/>
@@ -186,6 +186,13 @@ export default {
186186
}
187187
return false;
188188
},
189+
formattedEventName() {
190+
return this.claimEvent.isDeleted
191+
? `${this.claimEvent.name} ${this.$t('general.deleted')}`
192+
: !this.claimEvent.status
193+
? `${this.claimEvent.name} (${this.$t('performance.inactive')})`
194+
: this.claimEvent.name;
195+
},
189196
},
190197

191198
beforeMount() {

src/client/src/orangehrmClaimPlugin/pages/employeeClaims/EmployeeClaims.vue

+17-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
:years="yearsArray"
7272
/>
7373
</oxd-grid-item>
74+
<oxd-grid-item>
75+
<include-employee-dropdown v-model="filters.includeEmployees">
76+
</include-employee-dropdown>
77+
</oxd-grid-item>
7478
</oxd-grid>
7579
</oxd-form-row>
7680
<oxd-divider />
@@ -140,6 +144,8 @@ import {
140144
validSelection,
141145
endDateShouldBeAfterStartDate,
142146
} from '@/core/util/validation/rules';
147+
import IncludeEmployeeDropdownVue from '@ohrm/core/components/dropdown/IncludeEmployeeDropdown.vue';
148+
import usei18n from '@/core/util/composable/usei18n';
143149

144150
const defaultFilters = {
145151
referenceId: '',
@@ -164,6 +170,7 @@ export default {
164170
'claim-event-dropdown': ClaimEventDropdown,
165171
'status-dropdown': StatusDropdown,
166172
'employee-autocomplete': EmployeeAutocomplete,
173+
'include-employee-dropdown': IncludeEmployeeDropdownVue,
167174
},
168175
props: {
169176
empNumber: {
@@ -172,7 +179,15 @@ export default {
172179
},
173180
},
174181
setup() {
175-
const filters = ref({...defaultFilters});
182+
const {$t} = usei18n();
183+
const filters = ref({
184+
includeEmployees: {
185+
id: 1,
186+
param: 'onlyCurrent',
187+
label: $t('general.current_employees_only'),
188+
},
189+
...defaultFilters,
190+
});
176191
const {$tEmpName} = useEmployeeNameTranslate();
177192
const {sortDefinition, sortField, sortOrder, onSort} = useSort({
178193
sortDefinition: defaultSortOrder,
@@ -194,6 +209,7 @@ export default {
194209
status: filters.value.status ? filters.value.status?.id : null,
195210
fromDate: filters.value.fromDate,
196211
toDate: filters.value.toDate,
212+
includeEmployees: filters.value.includeEmployees?.param,
197213
sortField:
198214
sortField.value === 'claimRequest.claimEvent.name'
199215
? 'claimEvent.name'

src/client/src/orangehrmClaimPlugin/pages/submitClaim/SubmitClaim.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</oxd-grid-item>
4141
<oxd-grid-item>
4242
<oxd-input-field
43-
v-model="claimEvent.name"
43+
v-model="formattedEventName"
4444
:label="$t('claim.event')"
4545
disabled
4646
/>
@@ -169,6 +169,13 @@ export default {
169169
}
170170
return false;
171171
},
172+
formattedEventName() {
173+
return this.claimEvent.isDeleted
174+
? `${this.claimEvent.name} (${this.$t('general.deleted')})`
175+
: !this.claimEvent.status
176+
? `${this.claimEvent.name} (${this.$t('performance.inactive')})`
177+
: this.claimEvent.name;
178+
},
172179
},
173180

174181
beforeMount() {

src/plugins/orangehrmClaimPlugin/Api/EmployeeClaimRequestAPI.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class EmployeeClaimRequestAPI extends Endpoint implements CrudEndpoint
8989
WorkflowStateMachine::CLAIM_ACTION_CANCEL => 'CANCEL',
9090
WorkflowStateMachine::CLAIM_ACTION_REJECT => 'REJECT'
9191
];
92+
public const FILTER_INCLUDE_EMPLOYEES = 'includeEmployees';
9293

9394
/**
9495
* @OA\Post(
@@ -291,6 +292,12 @@ protected function setClaimRequest(ClaimRequest $claimRequest, int $empNumber):
291292
* @OA\Schema(type="DateTime")
292293
* ),
293294
* @OA\Parameter(
295+
* name="includeEmployees",
296+
* in="query",
297+
* required=false,
298+
* @OA\Schema(type="string", enum=ClaimRequestSearchFilterParams::INCLUDE_EMPLOYEES)
299+
* ),
300+
* @OA\Parameter(
294301
* name="model",
295302
* in="query",
296303
* required=false,
@@ -332,6 +339,7 @@ public function getAll(): EndpointResult
332339
$this->setSortingAndPaginationParams($employeeClaimRequestSearchFilterParams);
333340
$this->getCommonFilterParams($employeeClaimRequestSearchFilterParams);
334341
$this->setEmpNumbers($employeeClaimRequestSearchFilterParams);
342+
$this->setIncludeEmployees($employeeClaimRequestSearchFilterParams);
335343

336344
$claimRequests = $this->getClaimService()->getClaimDao()
337345
->getClaimRequestList($employeeClaimRequestSearchFilterParams);
@@ -403,6 +411,28 @@ protected function setEmpNumbers(ClaimRequestSearchFilterParams $claimRequestSea
403411
}
404412
}
405413

414+
/**
415+
* @param ClaimRequestSearchFilterParams $employeeClaimRequestSearchFilterParams
416+
*/
417+
private function setIncludeEmployees(ClaimRequestSearchFilterParams $employeeClaimRequestSearchFilterParams)
418+
{
419+
$employeeClaimRequestSearchFilterParams->setIncludeEmployees(
420+
$this->getRequestParams()->getString(
421+
RequestParams::PARAM_TYPE_QUERY,
422+
self::FILTER_INCLUDE_EMPLOYEES,
423+
$this->getDefaultIncludeEmployees()
424+
)
425+
);
426+
}
427+
428+
/**
429+
* @return string
430+
*/
431+
private function getDefaultIncludeEmployees(): string
432+
{
433+
return ClaimRequestSearchFilterParams::INCLUDE_EMPLOYEES_ONLY_CURRENT;
434+
}
435+
406436
/**
407437
* @param ClaimRequestSearchFilterParams $claimRequestSearchFilterParams
408438
*/
@@ -482,7 +512,13 @@ protected function getCommonParamRuleCollectionGetAll(): ParamRuleCollection
482512
new Rule(Rules::STRING_TYPE),
483513
new Rule(Rules::IN, [array_keys(self::MODEL_MAP)])
484514
)
485-
)
515+
),
516+
$this->getValidationDecorator()->notRequiredParamRule(
517+
new ParamRule(
518+
self::FILTER_INCLUDE_EMPLOYEES,
519+
new Rule(Rules::IN, [EmployeeClaimRequestSearchFilterParams::INCLUDE_EMPLOYEES])
520+
)
521+
),
486522
);
487523
}
488524

src/plugins/orangehrmClaimPlugin/Api/Model/ClaimExpenseModel.php

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
* type="object",
4646
* @OA\Property(property="id", type="integer"),
4747
* @OA\Property(property="name", type="string"),
48+
* @OA\Property(property="status", type="boolean"),
49+
* @OA\Property(property="isDeleted", type="boolean"),
4850
* ),
4951
* @OA\Property(
5052
* property="amount",
@@ -68,6 +70,8 @@ public function __construct(ClaimExpense $claimExpense)
6870
'id',
6971
['getExpenseType', 'getId'],
7072
['getExpenseType', 'getName'],
73+
['getExpenseType', 'getStatus'],
74+
['getExpenseType', 'isDeleted'],
7175
'amount',
7276
'note',
7377
['getDecorator', 'getDate']
@@ -78,6 +82,8 @@ public function __construct(ClaimExpense $claimExpense)
7882
'id',
7983
['expenseType', 'id'],
8084
['expenseType', 'name'],
85+
['expenseType', 'status'],
86+
['expenseType', 'isDeleted'],
8187
'amount',
8288
'note',
8389
'date'

src/plugins/orangehrmClaimPlugin/Api/Model/ClaimRequestModel.php

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* type="object",
3636
* @OA\Property(property="id", type="integer"),
3737
* @OA\Property(property="name", type="string"),
38+
* @OA\Property(property="status", type="boolean"),
39+
* @OA\Property(property="isDeleted", type="boolean"),
3840
* ),
3941
* @OA\Property(
4042
* property="currency",
@@ -59,6 +61,8 @@ public function __construct(ClaimRequest $claimRequest)
5961
'referenceId',
6062
['getClaimEvent', 'getId'],
6163
['getClaimEvent', 'getName'],
64+
['getClaimEvent', 'getStatus'],
65+
['getClaimEvent','isDeleted'],
6266
['getCurrencyType', 'getId'],
6367
['getCurrencyType', 'getName'],
6468
'description',
@@ -71,6 +75,8 @@ public function __construct(ClaimRequest $claimRequest)
7175
'referenceId',
7276
['claimEvent', 'id'],
7377
['claimEvent', 'name'],
78+
['claimEvent', 'status'],
79+
['claimEvent', 'isDeleted'],
7480
['currencyType', 'id'],
7581
['currencyType', 'name'],
7682
'remarks',

src/plugins/orangehrmClaimPlugin/Dao/ClaimDao.php

+12
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ protected function getClaimRequestPaginator(ClaimRequestSearchFilterParams $myCl
507507
$q->setParameter('toDate', $myClaimRequestSearchFilterParams->getToDate());
508508
}
509509

510+
if ($myClaimRequestSearchFilterParams->getIncludeEmployees() === null ||
511+
$myClaimRequestSearchFilterParams->getIncludeEmployees() ===
512+
ClaimRequestSearchFilterParams::INCLUDE_EMPLOYEES_ONLY_CURRENT
513+
) {
514+
$q->andWhere($q->expr()->isNull('employee.employeeTerminationRecord'));
515+
} elseif (
516+
$myClaimRequestSearchFilterParams->getIncludeEmployees() ===
517+
ClaimRequestSearchFilterParams::INCLUDE_EMPLOYEES_ONLY_PAST
518+
) {
519+
$q->andWhere($q->expr()->isNotNull('employee.employeeTerminationRecord'));
520+
}
521+
510522
$q->andWhere('claimRequest.isDeleted = :isDeleted');
511523
$q->setParameter('isDeleted', false);
512524

src/plugins/orangehrmClaimPlugin/Dto/ClaimRequestSearchFilterParams.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,31 @@
2121

2222
use DateTime;
2323
use OrangeHRM\Core\Dto\FilterParams;
24+
use OrangeHRM\ORM\ListSorter;
2425

2526
class ClaimRequestSearchFilterParams extends FilterParams
2627
{
28+
public const INCLUDE_EMPLOYEES_ONLY_CURRENT = 'onlyCurrent';
29+
public const INCLUDE_EMPLOYEES_ONLY_PAST = 'onlyPast';
30+
public const INCLUDE_EMPLOYEES_CURRENT_AND_PAST = 'currentAndPast';
31+
32+
public const INCLUDE_EMPLOYEES = [
33+
self::INCLUDE_EMPLOYEES_ONLY_CURRENT,
34+
self::INCLUDE_EMPLOYEES_ONLY_PAST,
35+
self::INCLUDE_EMPLOYEES_CURRENT_AND_PAST,
36+
];
2737
public const ALLOWED_SORT_FIELDS = [
2838
'claimRequest.referenceId',
2939
'claimRequest.status',
3040
'claimEvent.name',
3141
'claimRequest.submittedDate'
3242
];
3343

44+
/**
45+
* @var string|null
46+
*/
47+
private ?string $includeEmployees = self::INCLUDE_EMPLOYEES_ONLY_CURRENT;
48+
3449
/**
3550
* @var string|null
3651
*/
@@ -64,7 +79,23 @@ class ClaimRequestSearchFilterParams extends FilterParams
6479
public function __construct()
6580
{
6681
$this->setSortField('claimRequest.referenceId');
67-
$this->setSortOrder('DESC');
82+
$this->setSortOrder(ListSorter::DESCENDING);
83+
}
84+
85+
/**
86+
* @return string|null
87+
*/
88+
public function getIncludeEmployees(): ?string
89+
{
90+
return $this->includeEmployees;
91+
}
92+
93+
/**
94+
* @param string|null $includeEmployees
95+
*/
96+
public function setIncludeEmployees(?string $includeEmployees): void
97+
{
98+
$this->includeEmployees = $includeEmployees;
6899
}
69100

70101
/**

0 commit comments

Comments
 (0)