@openmrs/esm-billing-app 1.0.2-pre.711 → 1.0.2-pre.721
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/dist/4300.js +1 -1
- package/dist/4724.js +1 -1
- package/dist/4724.js.map +1 -1
- package/dist/4739.js +1 -1
- package/dist/4739.js.map +1 -1
- package/dist/7452.js +1 -1
- package/dist/7452.js.map +1 -1
- package/dist/8930.js +2 -0
- package/dist/8930.js.map +1 -0
- package/dist/942.js +1 -0
- package/dist/942.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-billing-app.js +1 -1
- package/dist/openmrs-esm-billing-app.js.buildmanifest.json +46 -70
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +2 -2
- package/src/bill-item-actions/bill-item-actions.scss +0 -4
- package/src/bill-item-actions/{edit-bill-item.component.tsx → edit-bill-item.modal.tsx} +58 -60
- package/src/bill-item-actions/edit-bill-item.test.tsx +5 -5
- package/src/billable-services/bill-waiver/bill-selection.component.tsx +2 -2
- package/src/billable-services/billable-services-home.component.tsx +1 -1
- package/src/billable-services/billable-services.component.tsx +110 -128
- package/src/billable-services/billable-services.scss +3 -0
- package/src/billable-services/billable-services.test.tsx +1 -3
- package/src/billable-services/cash-point/add-cash-point.modal.tsx +168 -0
- package/src/billable-services/cash-point/cash-point-configuration.component.tsx +16 -191
- package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
- package/src/billable-services/create-edit/add-billable-service.component.tsx +23 -26
- package/src/billable-services/create-edit/add-billable-service.scss +2 -5
- package/src/billable-services/create-edit/edit-billable-service.modal.tsx +50 -0
- package/src/billable-services/payment-modes/add-payment-mode.modal.tsx +121 -0
- package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +72 -0
- package/src/billable-services/payment-modes/payment-modes-config.component.tsx +125 -0
- package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -1
- package/src/billing-form/billing-checkin-form.component.tsx +2 -2
- package/src/billing-form/billing-form.component.tsx +2 -2
- package/src/helpers/functions.ts +5 -4
- package/src/index.ts +16 -6
- package/src/invoice/invoice-table.component.tsx +9 -2
- package/src/invoice/invoice.component.tsx +5 -1
- package/src/invoice/printable-invoice/print-receipt.component.tsx +2 -1
- package/src/modal/require-payment-modal.test.tsx +1 -1
- package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +17 -18
- package/src/routes.json +22 -2
- package/translations/en.json +12 -10
- package/dist/2352.js +0 -1
- package/dist/2352.js.map +0 -1
- package/dist/8638.js +0 -1
- package/dist/8638.js.map +0 -1
- package/dist/929.js +0 -2
- package/dist/929.js.map +0 -1
- package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
- /package/dist/{929.js.LICENSE.txt → 8930.js.LICENSE.txt} +0 -0
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Button,
|
|
4
|
-
DataTable,
|
|
5
|
-
TableContainer,
|
|
6
|
-
Table,
|
|
7
|
-
TableHead,
|
|
8
|
-
TableRow,
|
|
9
|
-
TableHeader,
|
|
10
|
-
TableBody,
|
|
11
|
-
TableCell,
|
|
12
|
-
Modal,
|
|
13
|
-
TextInput,
|
|
14
|
-
OverflowMenu,
|
|
15
|
-
OverflowMenuItem,
|
|
16
|
-
} from '@carbon/react';
|
|
17
|
-
import { Add } from '@carbon/react/icons';
|
|
18
|
-
import { useTranslation } from 'react-i18next';
|
|
19
|
-
import { useForm, Controller } from 'react-hook-form';
|
|
20
|
-
import { z } from 'zod';
|
|
21
|
-
import { zodResolver } from '@hookform/resolvers/zod';
|
|
22
|
-
import { showSnackbar, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
23
|
-
import { CardHeader } from '@openmrs/esm-patient-common-lib';
|
|
24
|
-
import styles from './payment-modes-config.scss';
|
|
25
|
-
|
|
26
|
-
// Validation schema
|
|
27
|
-
const paymentModeSchema = z.object({
|
|
28
|
-
name: z.string().min(1, 'Payment Mode Name is required'),
|
|
29
|
-
description: z.string().optional(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
type PaymentModeFormValues = z.infer<typeof paymentModeSchema>;
|
|
33
|
-
|
|
34
|
-
const PaymentModesConfig: React.FC = () => {
|
|
35
|
-
const { t } = useTranslation();
|
|
36
|
-
const [paymentModes, setPaymentModes] = useState([]);
|
|
37
|
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
38
|
-
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
|
39
|
-
const [selectedPaymentMode, setSelectedPaymentMode] = useState(null);
|
|
40
|
-
|
|
41
|
-
const {
|
|
42
|
-
control,
|
|
43
|
-
handleSubmit,
|
|
44
|
-
reset,
|
|
45
|
-
formState: { errors, isSubmitting },
|
|
46
|
-
} = useForm<PaymentModeFormValues>({
|
|
47
|
-
resolver: zodResolver(paymentModeSchema),
|
|
48
|
-
defaultValues: {
|
|
49
|
-
name: '',
|
|
50
|
-
description: '',
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const fetchPaymentModes = useCallback(async () => {
|
|
55
|
-
try {
|
|
56
|
-
const response = await openmrsFetch(`${restBaseUrl}/billing/paymentMode?v=full`);
|
|
57
|
-
setPaymentModes(response.data.results || []);
|
|
58
|
-
} catch (err) {
|
|
59
|
-
showSnackbar({
|
|
60
|
-
title: t('error', 'Error'),
|
|
61
|
-
subtitle: t('errorFetchingPaymentModes', 'An error occurred while fetching payment modes.'),
|
|
62
|
-
kind: 'error',
|
|
63
|
-
isLowContrast: false,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}, [t]);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
fetchPaymentModes();
|
|
70
|
-
}, [fetchPaymentModes]);
|
|
71
|
-
|
|
72
|
-
const onSubmit = async (data: PaymentModeFormValues) => {
|
|
73
|
-
// Check for duplicate payment mode name
|
|
74
|
-
const isDuplicate = paymentModes.some((mode) => mode.name.toLowerCase() === data.name.toLowerCase());
|
|
75
|
-
|
|
76
|
-
if (isDuplicate) {
|
|
77
|
-
showSnackbar({
|
|
78
|
-
title: t('error', 'Error'),
|
|
79
|
-
subtitle: t(
|
|
80
|
-
'duplicatePaymentModeError',
|
|
81
|
-
'A payment mode with the same name already exists. Please create another payment mode',
|
|
82
|
-
),
|
|
83
|
-
kind: 'error',
|
|
84
|
-
isLowContrast: false,
|
|
85
|
-
});
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const response = await openmrsFetch(`${restBaseUrl}/billing/paymentMode`, {
|
|
91
|
-
method: 'POST',
|
|
92
|
-
headers: {
|
|
93
|
-
'Content-Type': 'application/json',
|
|
94
|
-
},
|
|
95
|
-
body: JSON.stringify({
|
|
96
|
-
name: data.name,
|
|
97
|
-
description: data.description,
|
|
98
|
-
}),
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
if (response.ok) {
|
|
102
|
-
showSnackbar({
|
|
103
|
-
title: t('success', 'Success'),
|
|
104
|
-
subtitle: t('paymentModeSaved', 'Payment mode was successfully saved.'),
|
|
105
|
-
kind: 'success',
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
setIsModalOpen(false);
|
|
109
|
-
reset({ name: '', description: '' });
|
|
110
|
-
fetchPaymentModes();
|
|
111
|
-
} else {
|
|
112
|
-
const errorData = response.data || {};
|
|
113
|
-
showSnackbar({
|
|
114
|
-
title: t('error', 'Error'),
|
|
115
|
-
subtitle:
|
|
116
|
-
errorData.message || t('errorSavingPaymentMode', 'An error occurred while saving the payment mode.'),
|
|
117
|
-
kind: 'error',
|
|
118
|
-
isLowContrast: false,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
} catch (err) {
|
|
122
|
-
showSnackbar({
|
|
123
|
-
title: t('error', 'Error'),
|
|
124
|
-
subtitle: t('errorSavingPaymentMode', 'An error occurred while saving the payment mode.'),
|
|
125
|
-
kind: 'error',
|
|
126
|
-
isLowContrast: false,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const handleDelete = async () => {
|
|
132
|
-
if (!selectedPaymentMode) return;
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
await openmrsFetch(`${restBaseUrl}/billing/paymentMode/${selectedPaymentMode.uuid}`, {
|
|
136
|
-
method: 'DELETE',
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
showSnackbar({
|
|
140
|
-
title: t('success', 'Success'),
|
|
141
|
-
subtitle: t('paymentModeDeleted', 'Payment mode was successfully deleted.'),
|
|
142
|
-
kind: 'success',
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
setIsDeleteModalOpen(false);
|
|
146
|
-
setSelectedPaymentMode(null);
|
|
147
|
-
fetchPaymentModes();
|
|
148
|
-
} catch (err) {
|
|
149
|
-
showSnackbar({
|
|
150
|
-
title: t('error', 'Error'),
|
|
151
|
-
subtitle: t('errorDeletingPaymentMode', 'An error occurred while deleting the payment mode.'),
|
|
152
|
-
kind: 'error',
|
|
153
|
-
isLowContrast: false,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const rowData = paymentModes.map((mode) => ({
|
|
159
|
-
id: mode.uuid,
|
|
160
|
-
name: mode.name,
|
|
161
|
-
description: mode.description || '--',
|
|
162
|
-
}));
|
|
163
|
-
|
|
164
|
-
const headerData = [
|
|
165
|
-
{ key: 'name', header: t('name', 'Name') },
|
|
166
|
-
{ key: 'description', header: t('description', 'Description') },
|
|
167
|
-
{ key: 'actions', header: t('actions', 'Actions') },
|
|
168
|
-
];
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<div className={styles.container}>
|
|
172
|
-
<div className={styles.card}>
|
|
173
|
-
<CardHeader title={t('paymentModeHistory', 'Payment Mode History')}>
|
|
174
|
-
<Button renderIcon={Add} onClick={() => setIsModalOpen(true)} kind="ghost">
|
|
175
|
-
{t('addNewPaymentMode', 'Add New Payment Mode')}
|
|
176
|
-
</Button>
|
|
177
|
-
</CardHeader>
|
|
178
|
-
<div className={styles.historyContainer}>
|
|
179
|
-
<DataTable rows={rowData} headers={headerData} isSortable size="lg">
|
|
180
|
-
{({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => (
|
|
181
|
-
<TableContainer>
|
|
182
|
-
<Table className={styles.table} {...getTableProps()}>
|
|
183
|
-
<TableHead>
|
|
184
|
-
<TableRow>
|
|
185
|
-
{headers.map((header) => (
|
|
186
|
-
<TableHeader key={header.key} {...getHeaderProps({ header })}>
|
|
187
|
-
{header.header}
|
|
188
|
-
</TableHeader>
|
|
189
|
-
))}
|
|
190
|
-
</TableRow>
|
|
191
|
-
</TableHead>
|
|
192
|
-
<TableBody>
|
|
193
|
-
{rows.map((row) => (
|
|
194
|
-
<TableRow key={row.id} {...getRowProps({ row })}>
|
|
195
|
-
{row.cells.map((cell) =>
|
|
196
|
-
cell.info.header !== 'actions' ? (
|
|
197
|
-
<TableCell key={cell.id}>{cell.value}</TableCell>
|
|
198
|
-
) : (
|
|
199
|
-
<TableCell key={cell.id}>
|
|
200
|
-
<OverflowMenu>
|
|
201
|
-
<OverflowMenuItem
|
|
202
|
-
itemText={t('delete', 'Delete')}
|
|
203
|
-
onClick={() => {
|
|
204
|
-
const selected = paymentModes.find((p) => p.uuid === row.id);
|
|
205
|
-
setSelectedPaymentMode(selected);
|
|
206
|
-
setIsDeleteModalOpen(true);
|
|
207
|
-
}}
|
|
208
|
-
/>
|
|
209
|
-
</OverflowMenu>
|
|
210
|
-
</TableCell>
|
|
211
|
-
),
|
|
212
|
-
)}
|
|
213
|
-
</TableRow>
|
|
214
|
-
))}
|
|
215
|
-
</TableBody>
|
|
216
|
-
</Table>
|
|
217
|
-
</TableContainer>
|
|
218
|
-
)}
|
|
219
|
-
</DataTable>
|
|
220
|
-
</div>
|
|
221
|
-
</div>
|
|
222
|
-
|
|
223
|
-
{/* Modal for Adding New Payment Mode */}
|
|
224
|
-
<Modal
|
|
225
|
-
open={isModalOpen}
|
|
226
|
-
modalHeading={t('addPaymentMode', 'Add Payment Mode')}
|
|
227
|
-
onRequestClose={() => setIsModalOpen(false)}
|
|
228
|
-
onRequestSubmit={handleSubmit(onSubmit)}
|
|
229
|
-
primaryButtonText={t('save', 'Save')}
|
|
230
|
-
secondaryButtonText={t('cancel', 'Cancel')}
|
|
231
|
-
isPrimaryButtonDisabled={isSubmitting}>
|
|
232
|
-
<form>
|
|
233
|
-
<Controller
|
|
234
|
-
name="name"
|
|
235
|
-
control={control}
|
|
236
|
-
render={({ field }) => (
|
|
237
|
-
<TextInput
|
|
238
|
-
id="payment-mode-name"
|
|
239
|
-
labelText={t('paymentModeName', 'Payment Mode Name')}
|
|
240
|
-
placeholder={t('paymentModeNamePlaceholder', 'e.g., Cash, Credit Card')}
|
|
241
|
-
invalid={!!errors.name}
|
|
242
|
-
invalidText={errors.name?.message}
|
|
243
|
-
{...field}
|
|
244
|
-
/>
|
|
245
|
-
)}
|
|
246
|
-
/>
|
|
247
|
-
<Controller
|
|
248
|
-
name="description"
|
|
249
|
-
control={control}
|
|
250
|
-
render={({ field }) => (
|
|
251
|
-
<TextInput
|
|
252
|
-
id="payment-mode-description"
|
|
253
|
-
labelText={t('description', 'Description')}
|
|
254
|
-
placeholder={t('descriptionPlaceholder', 'e.g., Used for all cash transactions')}
|
|
255
|
-
invalid={!!errors.description}
|
|
256
|
-
invalidText={errors.description?.message}
|
|
257
|
-
{...field}
|
|
258
|
-
/>
|
|
259
|
-
)}
|
|
260
|
-
/>
|
|
261
|
-
</form>
|
|
262
|
-
</Modal>
|
|
263
|
-
|
|
264
|
-
{/* Modal for Deleting Payment Mode */}
|
|
265
|
-
<Modal
|
|
266
|
-
open={isDeleteModalOpen}
|
|
267
|
-
modalHeading={t('deletePaymentMode', 'Delete Payment Mode')}
|
|
268
|
-
onRequestClose={() => setIsDeleteModalOpen(false)}
|
|
269
|
-
onRequestSubmit={handleDelete}
|
|
270
|
-
primaryButtonText={t('delete', 'Delete')}
|
|
271
|
-
secondaryButtonText={t('cancel', 'Cancel')}
|
|
272
|
-
primaryButtonDanger
|
|
273
|
-
danger>
|
|
274
|
-
<p>{t('confirmDeleteMessage', 'Are you sure you want to delete this payment mode? Proceed cautiously.')}</p>
|
|
275
|
-
</Modal>
|
|
276
|
-
</div>
|
|
277
|
-
);
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
export default PaymentModesConfig;
|
|
File without changes
|