@openmrs/esm-stock-management-app 1.0.1-pre.783 → 1.0.1-pre.785
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/index.ts +1 -0
- package/__mocks__/operation-type.mock.ts +532 -0
- package/dist/155.js +1 -0
- package/dist/155.js.map +1 -0
- package/dist/172.js +1 -1
- package/dist/20.js +1 -1
- package/dist/290.js +1 -1
- package/dist/493.js +2 -0
- package/dist/493.js.map +1 -0
- package/dist/606.js +1 -1
- package/dist/627.js +1 -1
- package/dist/914.js +1 -0
- package/dist/914.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-stock-management-app.js +1 -1
- package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +75 -51
- package/dist/openmrs-esm-stock-management-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/core/utils/utils.ts +29 -0
- package/src/index.ts +4 -0
- package/src/routes.json +9 -0
- package/src/stock-items/add-stock-item/transactions/printout/transactions-stockcard-printout.component.tsx +8 -12
- package/src/stock-items/add-stock-item/transactions/transactions.component.tsx +8 -12
- package/src/stock-items/stock-items.resource.ts +5 -5
- package/src/stock-lookups/stock-lookups.resource.ts +2 -2
- package/src/stock-operations/edit-stock-operation/edit-stock-operation-action-menu.component.tsx +41 -16
- package/src/stock-operations/{add-stock-operation/received-items.component.tsx → received-items.component.tsx} +1 -1
- package/src/stock-operations/stock-operation-reference.component.tsx +64 -0
- package/src/stock-operations/stock-operation-status/stock-operation-status-row.tsx +77 -0
- package/src/stock-operations/stock-operation-status/stock-operation-status.scss +32 -0
- package/src/stock-operations/stock-operation-status/stock-operation-status.tsx +45 -0
- package/src/stock-operations/stock-operation-types-selector/stock-operation-types-selector.component.tsx +30 -29
- package/src/stock-operations/stock-operation.utils.tsx +16 -79
- package/src/stock-operations/stock-operations-dialog/stock-operations-issue-stock-button.component.tsx +27 -39
- package/src/stock-operations/stock-operations-dialog/stock-operations-print-button.component.tsx +51 -59
- package/src/stock-operations/{stock-item-selector/stock-item-selector.resource.tsx → stock-operations-forms/hooks/useFilterableStockItems.ts} +4 -4
- package/src/stock-operations/stock-operations-forms/hooks/useFilteredOperationTypesByRoles.ts +30 -0
- package/src/stock-operations/stock-operations-forms/hooks/useOperationTypePermisions.ts +29 -0
- package/src/stock-operations/stock-operations-forms/hooks/useParties.ts +73 -0
- package/src/stock-operations/{users-selector/users-selector.resource.tsx → stock-operations-forms/hooks/useSearchUser.ts} +9 -7
- package/src/stock-operations/{batch-no-selector/batch-no-selector.resource.tsx → stock-operations-forms/hooks/useStockItemBatchNumbers.ts} +3 -3
- package/src/stock-operations/stock-operations-forms/hooks/useStockOperationLinks.ts +20 -0
- package/src/stock-operations/stock-operations-forms/input-components/batch-no-selector.component.tsx +72 -0
- package/src/stock-operations/stock-operations-forms/input-components/batch-no-selector.test.tsx +90 -0
- package/src/stock-operations/{add-stock-operation/stock-item-search/stock-item-search.scss → stock-operations-forms/input-components/input-components-styles.scss} +2 -2
- package/src/stock-operations/stock-operations-forms/input-components/qty-uim-selector.test.tsx +157 -0
- package/src/stock-operations/stock-operations-forms/input-components/quantity-uom-selector.component.tsx +53 -0
- package/src/stock-operations/stock-operations-forms/input-components/stock-item-search.component.tsx +56 -0
- package/src/stock-operations/stock-operations-forms/input-components/stock-operation-reason-selector.component.tsx +59 -0
- package/src/stock-operations/stock-operations-forms/input-components/stock-operation-reason-selector.test.tsx +216 -0
- package/src/stock-operations/{batch-no-selector → stock-operations-forms/input-components}/unique-batch-no-entry-input.component.tsx +12 -7
- package/src/stock-operations/stock-operations-forms/input-components/user-selector.test.tsx +110 -0
- package/src/stock-operations/stock-operations-forms/input-components/users-selector.component.tsx +111 -0
- package/src/stock-operations/stock-operations-forms/step1.test.tsx +303 -0
- package/src/stock-operations/stock-operations-forms/step2.test.tsx +250 -0
- package/src/stock-operations/stock-operations-forms/step3.test.tsx +223 -0
- package/src/stock-operations/stock-operations-forms/steps/base-operation-details-form-step.tsx +241 -0
- package/src/stock-operations/stock-operations-forms/steps/quantity-uom-cell.component.tsx +33 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-availability-cell.component.tsx +51 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-operation-item-batch-no-cell.component.tsx +40 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-operation-item-cell.component.tsx +38 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-operation-item-expiry-cell.component.tsx +41 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-operation-items-form-step.component.tsx +281 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-operation-items-form-step.scc.scss +64 -0
- package/src/stock-operations/stock-operations-forms/steps/stock-operation-submission-form-step.component.tsx +236 -0
- package/src/stock-operations/stock-operations-forms/stock-issue-form-initializer-with-related-requisition-operation.component.tsx +55 -0
- package/src/stock-operations/stock-operations-forms/stock-item-form/stock-item-form.scss +41 -0
- package/src/stock-operations/stock-operations-forms/stock-item-form/stock-item-form.workspace.tsx +197 -0
- package/src/stock-operations/stock-operations-forms/stock-operation-form-header.component.tsx +166 -0
- package/src/stock-operations/stock-operations-forms/stock-operation-form.component.tsx +200 -0
- package/src/stock-operations/stock-operations-forms/stock-operation-form.scss +111 -0
- package/src/stock-operations/stock-operations-forms/stock-operation-related-link.component.tsx +45 -0
- package/src/stock-operations/stock-operations-forms/stock-operation-stepper/stepper.scss +41 -0
- package/src/stock-operations/stock-operations-forms/stock-operation-stepper/stock-operation-stepper.component.tsx +52 -0
- package/src/stock-operations/stock-operations-forms/stock-operations-form-utils.ts +32 -0
- package/src/stock-operations/stock-operations-table.component.tsx +20 -56
- package/src/stock-operations/stock-operations.resource.ts +16 -13
- package/src/stock-operations/validation-schema.ts +72 -14
- package/dist/766.js +0 -2
- package/dist/766.js.map +0 -1
- package/dist/822.js +0 -1
- package/dist/822.js.map +0 -1
- package/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx +0 -349
- package/src/stock-operations/add-stock-operation/add-stock-operation.resource.tsx +0 -27
- package/src/stock-operations/add-stock-operation/add-stock-operation.scss +0 -60
- package/src/stock-operations/add-stock-operation/add-stock-operation.test.tsx +0 -192
- package/src/stock-operations/add-stock-operation/add-stock-operation.utils.tsx +0 -152
- package/src/stock-operations/add-stock-operation/add-stock-utils.ts +0 -103
- package/src/stock-operations/add-stock-operation/base-operation-details.component.tsx +0 -439
- package/src/stock-operations/add-stock-operation/base-operation-details.scss +0 -30
- package/src/stock-operations/add-stock-operation/stock-item-search/stock-item-search.component.tsx +0 -70
- package/src/stock-operations/add-stock-operation/stock-items-addition-row.component.tsx +0 -357
- package/src/stock-operations/add-stock-operation/stock-items-addition-row.resource.tsx +0 -0
- package/src/stock-operations/add-stock-operation/stock-items-addition-row.scss +0 -12
- package/src/stock-operations/add-stock-operation/stock-items-addition-row.test.tsx +0 -10
- package/src/stock-operations/add-stock-operation/stock-items-addition.component.scss +0 -17
- package/src/stock-operations/add-stock-operation/stock-items-addition.component.tsx +0 -254
- package/src/stock-operations/add-stock-operation/stock-operation-context/useStockOperationContext.tsx +0 -16
- package/src/stock-operations/add-stock-operation/stock-operation-reference.component.tsx +0 -39
- package/src/stock-operations/add-stock-operation/stock-operation-related-link.component.tsx +0 -38
- package/src/stock-operations/add-stock-operation/stock-operation-status.component.tsx +0 -170
- package/src/stock-operations/add-stock-operation/stock-operation-submission.component.tsx +0 -189
- package/src/stock-operations/add-stock-operation/stock-operation-submission.test.tsx +0 -138
- package/src/stock-operations/add-stock-operation/types.ts +0 -55
- package/src/stock-operations/add-stock-operation/validationSchema.ts +0 -54
- package/src/stock-operations/batch-no-selector/batch-no-selector.component.tsx +0 -114
- package/src/stock-operations/batch-no-selector/batch-no-selector.scss +0 -0
- package/src/stock-operations/batch-no-selector/batch-no-selector.test.tsx +0 -101
- package/src/stock-operations/party-selector/party-selector.component.tsx +0 -59
- package/src/stock-operations/qty-uom-selector/qty-uom-selector.component.tsx +0 -65
- package/src/stock-operations/qty-uom-selector/qty-uom-selector.resource.tsx +0 -0
- package/src/stock-operations/qty-uom-selector/qty-uom-selector.scss +0 -0
- package/src/stock-operations/qty-uom-selector/qty-uom-selector.test.tsx +0 -10
- package/src/stock-operations/stock-item-selector/stock-item-selector.component.tsx +0 -69
- package/src/stock-operations/stock-item-selector/stock-item-selector.scss +0 -0
- package/src/stock-operations/stock-item-selector/stock-item-selector.test.tsx +0 -10
- package/src/stock-operations/stock-operation-reason-selector/stock-operation-reason-selector.component.tsx +0 -62
- package/src/stock-operations/users-selector/users-selector.component.tsx +0 -75
- /package/dist/{766.js.LICENSE.txt → 493.js.LICENSE.txt} +0 -0
package/src/stock-operations/stock-operations-forms/steps/base-operation-details-form-step.tsx
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
import { Button, Column, ComboBox, DatePicker, DatePickerInput, InlineLoading, Stack, TextArea } from '@carbon/react';
|
2
|
+
import { ErrorState } from '@openmrs/esm-framework';
|
3
|
+
import React, { ChangeEvent, FC, useEffect, useMemo } from 'react';
|
4
|
+
import { Controller, useFormContext } from 'react-hook-form';
|
5
|
+
import { useTranslation } from 'react-i18next';
|
6
|
+
import { DATE_PICKER_CONTROL_FORMAT, DATE_PICKER_FORMAT, MAIN_STORE_LOCATION_TAG } from '../../../constants';
|
7
|
+
import { Party } from '../../../core/api/types/Party';
|
8
|
+
import { StockOperationDTO } from '../../../core/api/types/stockOperation/StockOperationDTO';
|
9
|
+
import { OperationType, StockOperationType } from '../../../core/api/types/stockOperation/StockOperationType';
|
10
|
+
import { StockOperationItemDtoSchema } from '../../validation-schema';
|
11
|
+
import useOperationTypePermisions from '../hooks/useOperationTypePermisions';
|
12
|
+
import useParties from '../hooks/useParties';
|
13
|
+
import StockOperationReasonSelector from '../input-components/stock-operation-reason-selector.component';
|
14
|
+
import UsersSelector from '../input-components/users-selector.component';
|
15
|
+
import styles from '../stock-operation-form.scss';
|
16
|
+
import { TextInput } from '@carbon/react';
|
17
|
+
|
18
|
+
type BaseOperationDetailsFormStepProps = {
|
19
|
+
stockOperation?: StockOperationDTO;
|
20
|
+
stockOperationType: StockOperationType;
|
21
|
+
onNext?: () => void;
|
22
|
+
};
|
23
|
+
|
24
|
+
const BaseOperationDetailsFormStep: FC<BaseOperationDetailsFormStepProps> = ({
|
25
|
+
stockOperation,
|
26
|
+
stockOperationType,
|
27
|
+
onNext,
|
28
|
+
}) => {
|
29
|
+
const { t } = useTranslation();
|
30
|
+
const operationTypePermision = useOperationTypePermisions(stockOperationType);
|
31
|
+
const {
|
32
|
+
destinationParties,
|
33
|
+
sourceParties,
|
34
|
+
isLoading: isPartiesLoading,
|
35
|
+
error: patiesError,
|
36
|
+
sourceTags,
|
37
|
+
destinationTags,
|
38
|
+
} = useParties(stockOperationType);
|
39
|
+
const form = useFormContext<StockOperationItemDtoSchema>();
|
40
|
+
const isStockIssueOperation = useMemo(
|
41
|
+
() => OperationType.STOCK_ISSUE_OPERATION_TYPE === stockOperationType.operationType,
|
42
|
+
[stockOperationType],
|
43
|
+
);
|
44
|
+
// initialize location fields
|
45
|
+
useEffect(() => {
|
46
|
+
// Prefill default locaton with current location if is a new operation
|
47
|
+
if (!stockOperation) {
|
48
|
+
if (stockOperationType?.hasSource) {
|
49
|
+
const shouldLockSource = sourceTags.length === 1 && sourceTags[0] === MAIN_STORE_LOCATION_TAG;
|
50
|
+
if (shouldLockSource && sourceParties?.length) {
|
51
|
+
const party = sourceParties[0];
|
52
|
+
form.setValue('sourceUuid', party.uuid);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
if (stockOperationType?.hasDestination) {
|
57
|
+
const shouldLockDestination = destinationTags.length === 1 && destinationTags[0] === MAIN_STORE_LOCATION_TAG;
|
58
|
+
if (shouldLockDestination && destinationParties?.length) {
|
59
|
+
const party = destinationParties[0];
|
60
|
+
form.setValue('destinationUuid', party.uuid);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}, [sourceParties, destinationParties, stockOperation, stockOperationType, form, destinationTags, sourceTags]);
|
65
|
+
|
66
|
+
if (isPartiesLoading)
|
67
|
+
return (
|
68
|
+
<InlineLoading
|
69
|
+
status="active"
|
70
|
+
role="progressbar"
|
71
|
+
iconDescription="Loading"
|
72
|
+
description={t('loadingData', 'Loading data...')}
|
73
|
+
/>
|
74
|
+
);
|
75
|
+
|
76
|
+
if (patiesError)
|
77
|
+
return (
|
78
|
+
<ErrorState error={patiesError} headerTitle={t('partieserror', 'Error launching base operation details form')} />
|
79
|
+
);
|
80
|
+
|
81
|
+
return (
|
82
|
+
<Stack gap={4} className={styles.grid}>
|
83
|
+
<div className={styles.heading}>
|
84
|
+
<h4>{`${stockOperationType.name} ${t('details', 'Details')}`}</h4>
|
85
|
+
<div className={styles.btnSet}>
|
86
|
+
{typeof onNext === 'function' && (
|
87
|
+
<Button kind="primary" onClick={onNext} role="button">
|
88
|
+
{t('next', 'Next')}
|
89
|
+
</Button>
|
90
|
+
)}
|
91
|
+
</div>
|
92
|
+
</div>
|
93
|
+
<Column>
|
94
|
+
<Controller
|
95
|
+
control={form.control}
|
96
|
+
name="operationDate"
|
97
|
+
render={({ field, fieldState: { error } }) => (
|
98
|
+
<DatePicker
|
99
|
+
readOnly={field.disabled}
|
100
|
+
id={`operationDate`}
|
101
|
+
datePickerType="single"
|
102
|
+
locale="en"
|
103
|
+
className={styles.datePickerInput}
|
104
|
+
{...field}
|
105
|
+
value={field.value}
|
106
|
+
dateFormat={DATE_PICKER_CONTROL_FORMAT}
|
107
|
+
onChange={([newDate]) => {
|
108
|
+
field.onChange(newDate);
|
109
|
+
}}
|
110
|
+
>
|
111
|
+
<DatePickerInput
|
112
|
+
autoComplete="off"
|
113
|
+
id={`operationDate-input`}
|
114
|
+
name="operationDate-input"
|
115
|
+
placeholder={DATE_PICKER_FORMAT}
|
116
|
+
labelText={t('operationDate', 'Operation Date')}
|
117
|
+
invalid={error?.message}
|
118
|
+
invalidText={error?.message}
|
119
|
+
size="xl"
|
120
|
+
/>
|
121
|
+
</DatePicker>
|
122
|
+
)}
|
123
|
+
/>
|
124
|
+
</Column>
|
125
|
+
{stockOperation?.operationNumber && (
|
126
|
+
<TextInput
|
127
|
+
id="operationNoLbl"
|
128
|
+
value={stockOperation?.operationNumber}
|
129
|
+
readOnly={true}
|
130
|
+
labelText={t('operationNumber', 'Operation Number')}
|
131
|
+
/>
|
132
|
+
)}
|
133
|
+
<Column>
|
134
|
+
<Controller
|
135
|
+
control={form.control}
|
136
|
+
name="sourceUuid"
|
137
|
+
render={({ field, fieldState: { error } }) => (
|
138
|
+
<ComboBox
|
139
|
+
titleText={
|
140
|
+
isStockIssueOperation
|
141
|
+
? t('destination', 'destination')
|
142
|
+
: stockOperationType?.hasDestination || stockOperation?.destinationUuid
|
143
|
+
? t('from', 'From')
|
144
|
+
: t('location', 'Location')
|
145
|
+
}
|
146
|
+
readOnly={field.disabled}
|
147
|
+
name={'sourceUuid'}
|
148
|
+
id={'sourceUuid'}
|
149
|
+
size={'xl'}
|
150
|
+
items={sourceParties}
|
151
|
+
onChange={(data: { selectedItem: Party }) => {
|
152
|
+
field.onChange(data.selectedItem?.uuid);
|
153
|
+
}}
|
154
|
+
initialSelectedItem={sourceParties.find((p) => p.uuid === field.value)}
|
155
|
+
selectedItem={sourceParties.find((p) => p.uuid === field.value)}
|
156
|
+
itemToString={(item?: Party) => (item && item?.name ? `${item?.name}` : '')}
|
157
|
+
shouldFilterItem={() => true}
|
158
|
+
placeholder={
|
159
|
+
stockOperationType.hasDestination || stockOperation?.destinationUuid
|
160
|
+
? t('chooseASource', 'Choose a source')
|
161
|
+
: t('chooseALocation', 'Choose a location')
|
162
|
+
}
|
163
|
+
ref={field.ref}
|
164
|
+
invalid={error?.message}
|
165
|
+
invalidText={error?.message}
|
166
|
+
/>
|
167
|
+
)}
|
168
|
+
/>
|
169
|
+
</Column>
|
170
|
+
{(stockOperationType.hasDestination || stockOperation?.destinationUuid) && (
|
171
|
+
<Column>
|
172
|
+
<Controller
|
173
|
+
control={form.control}
|
174
|
+
name="destinationUuid"
|
175
|
+
render={({ field, fieldState: { error } }) => (
|
176
|
+
<ComboBox
|
177
|
+
readOnly={field.disabled}
|
178
|
+
titleText={
|
179
|
+
isStockIssueOperation
|
180
|
+
? t('source', 'Source')
|
181
|
+
: stockOperationType?.hasSource || stockOperation?.atLocationUuid
|
182
|
+
? t('to', 'To')
|
183
|
+
: t('location', 'Location')
|
184
|
+
}
|
185
|
+
name={'destinationUuid'}
|
186
|
+
id={'destinationUuid'}
|
187
|
+
size={'xl'}
|
188
|
+
items={destinationParties}
|
189
|
+
onChange={(data: { selectedItem: Party }) => {
|
190
|
+
field.onChange(data.selectedItem?.uuid);
|
191
|
+
}}
|
192
|
+
initialSelectedItem={destinationParties.find((p) => p.uuid === field.value)}
|
193
|
+
selectedItem={destinationParties.find((p) => p.uuid === field.value)}
|
194
|
+
itemToString={(item?: Party) => (item && item?.name ? `${item?.name}` : '')}
|
195
|
+
shouldFilterItem={() => true}
|
196
|
+
placeholder={
|
197
|
+
stockOperationType?.hasSource || stockOperation?.atLocationUuid
|
198
|
+
? t('chooseADestination', 'Choose a destination')
|
199
|
+
: t('location', 'Location')
|
200
|
+
}
|
201
|
+
ref={field.ref}
|
202
|
+
invalid={error?.message}
|
203
|
+
invalidText={error?.message}
|
204
|
+
/>
|
205
|
+
)}
|
206
|
+
/>
|
207
|
+
</Column>
|
208
|
+
)}
|
209
|
+
<UsersSelector />
|
210
|
+
{operationTypePermision.requiresStockAdjustmentReason && (
|
211
|
+
<Column>
|
212
|
+
<StockOperationReasonSelector />
|
213
|
+
</Column>
|
214
|
+
)}
|
215
|
+
<Column>
|
216
|
+
<Controller
|
217
|
+
control={form.control}
|
218
|
+
name="remarks"
|
219
|
+
render={({ field, fieldState: { error } }) => (
|
220
|
+
<TextArea
|
221
|
+
{...field}
|
222
|
+
readOnly={field.disabled}
|
223
|
+
disabled={false}
|
224
|
+
maxCount={250}
|
225
|
+
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => {
|
226
|
+
field.onChange(e.target.value);
|
227
|
+
}}
|
228
|
+
placeholder={t('enterRemarks', 'Enter remarks') + ' ...'}
|
229
|
+
id={'remarks'}
|
230
|
+
labelText={t('remarks', 'Remarks')}
|
231
|
+
invalid={error?.message}
|
232
|
+
invalidText={error?.message}
|
233
|
+
/>
|
234
|
+
)}
|
235
|
+
/>
|
236
|
+
</Column>
|
237
|
+
</Stack>
|
238
|
+
);
|
239
|
+
};
|
240
|
+
|
241
|
+
export default BaseOperationDetailsFormStep;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
2
|
+
import { useStockItem } from '../../../stock-items/stock-items.resource';
|
3
|
+
import { InlineLoading } from '@carbon/react';
|
4
|
+
import { showSnackbar } from '@openmrs/esm-framework';
|
5
|
+
import { useTranslation } from 'react-i18next';
|
6
|
+
|
7
|
+
type QuantityUomCellProps = {
|
8
|
+
stockItemPackagingUOMUuid: string;
|
9
|
+
stockItemUuid: string;
|
10
|
+
};
|
11
|
+
|
12
|
+
const QuantityUomCell: React.FC<QuantityUomCellProps> = ({ stockItemPackagingUOMUuid, stockItemUuid }) => {
|
13
|
+
const { isLoading, error, item } = useStockItem(stockItemUuid);
|
14
|
+
const { t } = useTranslation();
|
15
|
+
const uomName = useMemo(() => {
|
16
|
+
return item?.packagingUnits?.find((unit) => unit.uuid === stockItemPackagingUOMUuid)?.packagingUomName;
|
17
|
+
}, [item, stockItemPackagingUOMUuid]);
|
18
|
+
|
19
|
+
useEffect(() => {
|
20
|
+
if (error) {
|
21
|
+
showSnackbar({
|
22
|
+
kind: 'error',
|
23
|
+
title: t('packagingUomError', 'Error loading stockItemPackagingUOM name'),
|
24
|
+
subtitle: error?.message,
|
25
|
+
});
|
26
|
+
}
|
27
|
+
}, [error, t]);
|
28
|
+
if (isLoading) return <InlineLoading status="active" iconDescription="Loading" />;
|
29
|
+
if (error) return <>--</>;
|
30
|
+
return <>{uomName}</>;
|
31
|
+
};
|
32
|
+
|
33
|
+
export default QuantityUomCell;
|
package/src/stock-operations/stock-operations-forms/steps/stock-availability-cell.component.tsx
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
import { InlineLoading } from '@carbon/react';
|
2
|
+
import { showSnackbar } from '@openmrs/esm-framework';
|
3
|
+
import React, { useEffect, useMemo } from 'react';
|
4
|
+
import { useTranslation } from 'react-i18next';
|
5
|
+
import { useStockItemBatchInformationHook } from '../../../stock-items/add-stock-item/batch-information/batch-information.resource';
|
6
|
+
import styles from './stock-operation-items-form-step.scc.scss';
|
7
|
+
const StockAvailability: React.FC<{ stockItemUuid: string }> = ({ stockItemUuid }) => {
|
8
|
+
const { items, isLoading, error } = useStockItemBatchInformationHook({
|
9
|
+
stockItemUuid: stockItemUuid,
|
10
|
+
includeBatchNo: true,
|
11
|
+
});
|
12
|
+
const { t } = useTranslation();
|
13
|
+
|
14
|
+
const totalQuantity = useMemo(() => {
|
15
|
+
if (!items?.length) return 0;
|
16
|
+
return items.reduce((total, batch) => {
|
17
|
+
return total + (Number(batch.quantity) || 0);
|
18
|
+
}, 0);
|
19
|
+
}, [items]);
|
20
|
+
const commonUOM = useMemo(() => {
|
21
|
+
if (!items?.length) return '';
|
22
|
+
return items[0]?.quantityUoM || '';
|
23
|
+
}, [items]);
|
24
|
+
|
25
|
+
useEffect(() => {
|
26
|
+
if (error) {
|
27
|
+
showSnackbar({
|
28
|
+
kind: 'error',
|
29
|
+
title: t('stockAvailabilityError', 'Error loading stock availability'),
|
30
|
+
subtitle: error?.message,
|
31
|
+
});
|
32
|
+
}
|
33
|
+
}, [error, t]);
|
34
|
+
|
35
|
+
if (isLoading) return <InlineLoading status="active" iconDescription="Loading" />;
|
36
|
+
if (error) return <>--</>;
|
37
|
+
|
38
|
+
return (
|
39
|
+
<div className={styles.availability}>
|
40
|
+
{totalQuantity > 0 ? (
|
41
|
+
<span>
|
42
|
+
Available: {totalQuantity.toLocaleString()} {commonUOM}
|
43
|
+
</span>
|
44
|
+
) : (
|
45
|
+
<span className={styles.outOfStock}>Out of Stock</span>
|
46
|
+
)}
|
47
|
+
</div>
|
48
|
+
);
|
49
|
+
};
|
50
|
+
|
51
|
+
export default StockAvailability;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { InlineLoading } from '@carbon/react';
|
2
|
+
import React, { useMemo } from 'react';
|
3
|
+
import { useTranslation } from 'react-i18next';
|
4
|
+
import { StockOperationType } from '../../../core/api/types/stockOperation/StockOperationType';
|
5
|
+
import useOperationTypePermisions from '../hooks/useOperationTypePermisions';
|
6
|
+
import { useStockItemBatchNumbers } from '../hooks/useStockItemBatchNumbers';
|
7
|
+
|
8
|
+
type StockOperationitemBatchNoCellProps = {
|
9
|
+
operation: StockOperationType;
|
10
|
+
stockBatchUuid?: string;
|
11
|
+
batchNo?: string;
|
12
|
+
stockItemUuid: string;
|
13
|
+
};
|
14
|
+
|
15
|
+
const StockOperationItemBatchNoCell: React.FC<StockOperationitemBatchNoCellProps> = ({
|
16
|
+
operation,
|
17
|
+
batchNo,
|
18
|
+
stockBatchUuid,
|
19
|
+
stockItemUuid,
|
20
|
+
}) => {
|
21
|
+
const operationTypePermision = useOperationTypePermisions(operation);
|
22
|
+
const { isLoading, stockItemBatchNos } = useStockItemBatchNumbers(stockItemUuid);
|
23
|
+
const { t } = useTranslation();
|
24
|
+
const _batchno = useMemo(
|
25
|
+
() => stockItemBatchNos?.find((item) => item.uuid === stockBatchUuid)?.batchNo,
|
26
|
+
[stockItemBatchNos, stockBatchUuid],
|
27
|
+
);
|
28
|
+
|
29
|
+
if (isLoading) <InlineLoading description={t('loading', 'Loading')} iconDescription={t('loading', 'Loading')} />;
|
30
|
+
|
31
|
+
if (operationTypePermision.requiresBatchUuid && !operationTypePermision.requiresActualBatchInfo)
|
32
|
+
return <p>{_batchno ?? '--'}</p>;
|
33
|
+
|
34
|
+
if (operationTypePermision.requiresActualBatchInfo || operationTypePermision.requiresBatchUuid)
|
35
|
+
return <p>{batchNo ?? '--'}</p>;
|
36
|
+
|
37
|
+
return <p>--</p>;
|
38
|
+
};
|
39
|
+
|
40
|
+
export default StockOperationItemBatchNoCell;
|
package/src/stock-operations/stock-operations-forms/steps/stock-operation-item-cell.component.tsx
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import React, { useCallback, useEffect } from 'react';
|
2
|
+
import { useStockItem } from '../../../stock-items/stock-items.resource';
|
3
|
+
import { useTranslation } from 'react-i18next';
|
4
|
+
import { showSnackbar } from '@openmrs/esm-framework';
|
5
|
+
import { InlineLoading } from '@carbon/react';
|
6
|
+
import { StockItemDTO } from '../../../core/api/types/stockItem/StockItem';
|
7
|
+
import { URL_STOCK_ITEM } from '../../../constants';
|
8
|
+
import { Link } from 'react-router-dom';
|
9
|
+
|
10
|
+
type StockOperationItemCellProps = {
|
11
|
+
stockItemUuid: string;
|
12
|
+
};
|
13
|
+
|
14
|
+
const StockOperationItemCell: React.FC<StockOperationItemCellProps> = ({ stockItemUuid }) => {
|
15
|
+
const { isLoading, error, item } = useStockItem(stockItemUuid);
|
16
|
+
const { t } = useTranslation();
|
17
|
+
|
18
|
+
useEffect(() => {
|
19
|
+
if (error) {
|
20
|
+
showSnackbar({
|
21
|
+
kind: 'error',
|
22
|
+
title: t('stockItemError', 'Error loading stock item'),
|
23
|
+
subtitle: error?.message,
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}, [error, t]);
|
27
|
+
|
28
|
+
if (isLoading) return <InlineLoading status="active" iconDescription="Loading" />;
|
29
|
+
if (error) return <>--</>;
|
30
|
+
|
31
|
+
return (
|
32
|
+
<Link target={'_blank'} to={URL_STOCK_ITEM(stockItemUuid)}>
|
33
|
+
{(item as StockItemDTO)?.commonName || 'No name available'}
|
34
|
+
</Link>
|
35
|
+
);
|
36
|
+
};
|
37
|
+
|
38
|
+
export default StockOperationItemCell;
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { InlineLoading } from '@carbon/react';
|
2
|
+
import React, { useMemo } from 'react';
|
3
|
+
import { useTranslation } from 'react-i18next';
|
4
|
+
import { formatForDatePicker } from '../../../constants';
|
5
|
+
import { StockOperationType } from '../../../core/api/types/stockOperation/StockOperationType';
|
6
|
+
import useOperationTypePermisions from '../hooks/useOperationTypePermisions';
|
7
|
+
import { useStockItemBatchNumbers } from '../hooks/useStockItemBatchNumbers';
|
8
|
+
|
9
|
+
type StockoperationItemExpiryCellProps = {
|
10
|
+
operation: StockOperationType;
|
11
|
+
stockBatchUuid?: string;
|
12
|
+
expiration?: Date;
|
13
|
+
stockItemUuid: string;
|
14
|
+
};
|
15
|
+
|
16
|
+
const StockoperationItemExpiryCell: React.FC<StockoperationItemExpiryCellProps> = ({
|
17
|
+
operation,
|
18
|
+
stockItemUuid,
|
19
|
+
expiration,
|
20
|
+
stockBatchUuid,
|
21
|
+
}) => {
|
22
|
+
const operationTypePermision = useOperationTypePermisions(operation);
|
23
|
+
const { isLoading, stockItemBatchNos } = useStockItemBatchNumbers(stockItemUuid);
|
24
|
+
const { t } = useTranslation();
|
25
|
+
const _expiration = useMemo(
|
26
|
+
() => stockItemBatchNos?.find((item) => item.uuid === stockBatchUuid)?.expiration,
|
27
|
+
[stockItemBatchNos, stockBatchUuid],
|
28
|
+
);
|
29
|
+
|
30
|
+
if (isLoading) <InlineLoading description={t('loading', 'Loading')} iconDescription={t('loading', 'Loading')} />;
|
31
|
+
|
32
|
+
if (operationTypePermision.requiresBatchUuid && !operationTypePermision.requiresActualBatchInfo)
|
33
|
+
return <p>{_expiration ? formatForDatePicker(_expiration) : '--'}</p>;
|
34
|
+
|
35
|
+
if (operationTypePermision.requiresActualBatchInfo || operationTypePermision.requiresBatchUuid)
|
36
|
+
return <p>{expiration ? formatForDatePicker(expiration) : '--'}</p>;
|
37
|
+
|
38
|
+
return <p>--</p>;
|
39
|
+
};
|
40
|
+
|
41
|
+
export default StockoperationItemExpiryCell;
|