@kenyaemr/esm-billing-app 5.4.2-pre.2137 → 5.4.2-pre.2141

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.
Files changed (42) hide show
  1. package/.turbo/turbo-build.log +108 -80
  2. package/dist/574.js +1 -1
  3. package/dist/919.js +1 -0
  4. package/dist/919.js.map +1 -0
  5. package/dist/{746.js → 933.js} +3 -3
  6. package/dist/{746.js.map → 933.js.map} +1 -1
  7. package/dist/kenyaemr-esm-billing-app.js +1 -1
  8. package/dist/kenyaemr-esm-billing-app.js.buildmanifest.json +86 -86
  9. package/dist/main.js +3 -3
  10. package/dist/main.js.map +1 -1
  11. package/dist/routes.json +1 -1
  12. package/package.json +1 -1
  13. package/src/bill-deposit/components/dashboard/bill-deposit-dashboard.component.tsx +35 -0
  14. package/src/bill-deposit/components/forms/add-deposit.workspace.scss +26 -0
  15. package/src/bill-deposit/components/forms/add-deposit.workspace.tsx +212 -0
  16. package/src/{billing-form/bill-deposit/bill-deposit.scss → bill-deposit/components/forms/deposit-transactions/deposit-transaction.workspace.scss} +10 -17
  17. package/src/bill-deposit/components/forms/deposit-transactions/deposit-transaction.workspace.tsx +254 -0
  18. package/src/bill-deposit/components/modal/delete-deposit.modal.tsx +58 -0
  19. package/src/bill-deposit/components/modal/reverse-transaction.modal.tsx +59 -0
  20. package/src/bill-deposit/components/search/bill-deposit-search.component.tsx +106 -0
  21. package/src/bill-deposit/components/search/bill-deposit-search.scss +107 -0
  22. package/src/bill-deposit/components/search/components/deposit-table.tsx +150 -0
  23. package/src/bill-deposit/components/search/components/patient-info.tsx +38 -0
  24. package/src/bill-deposit/components/search/components/patient-search.tsx +24 -0
  25. package/src/bill-deposit/components/search/components/transaction-list/transaction-list.component.tsx +65 -0
  26. package/src/bill-deposit/components/search/components/transaction-list/transaction-list.scss +5 -0
  27. package/src/bill-deposit/constants/bill-deposit.constants.ts +25 -0
  28. package/src/bill-deposit/hooks/useBillDeposit.ts +43 -0
  29. package/src/bill-deposit/styles/bill-deposit-dashboard.scss +11 -0
  30. package/src/bill-deposit/types/bill-deposit.types.ts +61 -0
  31. package/src/bill-deposit/utils/bill-deposit.utils.ts +94 -0
  32. package/src/index.ts +23 -2
  33. package/src/past-patient-bills/patient-bills-dashboard/empty-patient-bill.component.tsx +29 -12
  34. package/src/past-patient-bills/patient-bills-dashboard/patient-bills-dashboard.scss +1 -0
  35. package/src/root.component.tsx +2 -0
  36. package/src/routes.json +22 -3
  37. package/src/types/index.ts +1 -0
  38. package/translations/en.json +3 -0
  39. package/dist/912.js +0 -1
  40. package/dist/912.js.map +0 -1
  41. package/src/billing-form/bill-deposit/bill-deposit.workspace.tsx +0 -236
  42. /package/dist/{746.js.LICENSE.txt → 933.js.LICENSE.txt} +0 -0
@@ -1,236 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { useTranslation } from 'react-i18next';
3
- import { useForm, Controller } from 'react-hook-form';
4
- import { zodResolver } from '@hookform/resolvers/zod';
5
- import z, { isDirty, isValid } from 'zod';
6
- import classNames from 'classnames';
7
- import {
8
- type DefaultWorkspaceProps,
9
- ResponsiveWrapper,
10
- restBaseUrl,
11
- showSnackbar,
12
- useConfig,
13
- useLayoutType,
14
- } from '@openmrs/esm-framework';
15
- import { Button, ButtonSet, InlineLoading, NumberInput, DropdownSkeleton, Dropdown } from '@carbon/react';
16
- import styles from './bill-deposit.scss';
17
- import { BillingConfig } from '../../config-schema';
18
- import { processBillItems, usePaymentModes } from '../../billing.resource';
19
- import { BillingService, PaymentMethod } from '../../types';
20
- import { mutate } from 'swr';
21
- import useBillableServices from '../../hooks/useBillableServices';
22
-
23
- type BillDepositWorkspaceProps = DefaultWorkspaceProps & {
24
- patientUuid: string;
25
- patient: fhir.Patient;
26
- };
27
-
28
- const BillDepositWorkspace: React.FC<BillDepositWorkspaceProps> = ({
29
- patientUuid,
30
- patient,
31
- closeWorkspace,
32
- closeWorkspaceWithSavedChanges,
33
- promptBeforeClosing,
34
- }) => {
35
- const { t } = useTranslation();
36
- const { cashPointUuid, cashierUuid } = useConfig<BillingConfig>();
37
- const { paymentModes, isLoading: isPaymentModesLoading } = usePaymentModes();
38
- const { billableServices, isLoading: isBillableServicesLoading } = useBillableServices();
39
- const isTablet = useLayoutType() === 'tablet';
40
- const defaultPaymentStatus = 'PAID';
41
- const billDepositFormSchema = z.object({
42
- amount: z
43
- .number()
44
- .min(0, { message: t('amountToBeDepositedInvalidText', 'Amount to be deposited is must be greater than 0') }),
45
- paymentMode: z.object({
46
- uuid: z.string(),
47
- name: z.string(),
48
- description: z.string().optional(),
49
- retired: z.boolean().optional(),
50
- retireReason: z.null().optional(),
51
- auditInfo: z.any().optional(),
52
- attributeTypes: z.array(z.any()).optional(),
53
- sortOrder: z.null().optional(),
54
- resourceVersion: z.string().optional(),
55
- }) as z.ZodType<PaymentMethod>,
56
- billableService: z.object({
57
- uuid: z.string(),
58
- name: z.string(),
59
- shortName: z.string(),
60
- serviceStatus: z.string(),
61
- serviceType: z.object({
62
- display: z.string(),
63
- }),
64
- servicePrices: z.array(
65
- z.object({
66
- uuid: z.string(),
67
- name: z.string(),
68
- paymentMode: z.object({
69
- uuid: z.string(),
70
- name: z.string(),
71
- }),
72
- price: z.number(),
73
- }),
74
- ),
75
- description: z.string().optional(),
76
- retired: z.boolean().optional(),
77
- retireReason: z.null().optional(),
78
- }) as z.ZodType<BillingService>,
79
- });
80
- const {
81
- control,
82
- handleSubmit,
83
- formState: { isSubmitting, errors },
84
- watch,
85
- } = useForm<z.infer<typeof billDepositFormSchema>>({
86
- resolver: zodResolver(billDepositFormSchema),
87
- });
88
-
89
- const handleCreateBill = async (formData: z.infer<typeof billDepositFormSchema>) => {
90
- const billableService = formData.billableService;
91
- const servicePrice = billableService?.servicePrices.find((price) => price.uuid === formData.paymentMode.uuid);
92
- // if the service price is greater than the amount, then the payment status is paid, otherwise it is pending
93
- const paymentStatus = Number(formData.amount) >= Number(servicePrice?.price) ? 'PAID' : 'PENDING';
94
- const createBillPayload = {
95
- cashPoint: cashPointUuid,
96
- cashier: cashierUuid,
97
- patient: patientUuid,
98
- status: paymentStatus,
99
- lineItems: [
100
- {
101
- billableService: billableService.uuid,
102
- lineItemOrder: 0,
103
- quantity: 1,
104
- price: servicePrice?.price,
105
- paymentStatus: paymentStatus,
106
- priceUuid: '',
107
- priceName: billableService.name,
108
- },
109
- ],
110
- payments: [
111
- {
112
- amount: servicePrice?.price,
113
- amountTendered: formData.amount,
114
- attributes: [],
115
- instanceType: servicePrice.paymentMode.uuid,
116
- },
117
- ],
118
- };
119
- const response = await processBillItems(createBillPayload);
120
- if (response.ok) {
121
- showSnackbar({
122
- title: t('success', 'Success'),
123
- kind: 'success',
124
- subtitle: t('billDepositSuccess', 'Bill deposit successful'),
125
- isLowContrast: true,
126
- });
127
- mutate((key) => typeof key === 'string' && key.startsWith(`${restBaseUrl}/cashier/bill`), undefined, {
128
- revalidate: true,
129
- });
130
- closeWorkspaceWithSavedChanges();
131
- } else {
132
- showSnackbar({
133
- title: t('error', 'Error'),
134
- kind: 'error',
135
- subtitle: t('billDepositError', 'Bill deposit failed'),
136
- isLowContrast: true,
137
- });
138
- }
139
- };
140
-
141
- useEffect(() => {
142
- if (isDirty) {
143
- promptBeforeClosing(() => true);
144
- }
145
- // eslint-disable-next-line react-hooks/exhaustive-deps
146
- }, [isDirty, promptBeforeClosing]);
147
-
148
- const billableService = Array.from(watch('billableService')?.servicePrices ?? []);
149
-
150
- return (
151
- <form className={styles.form} onSubmit={handleSubmit(handleCreateBill)}>
152
- <div className={styles.formContainer}>
153
- <ResponsiveWrapper>
154
- {isBillableServicesLoading ? (
155
- <DropdownSkeleton />
156
- ) : (
157
- <Controller
158
- control={control}
159
- name="billableService"
160
- render={({ field }) => (
161
- <Dropdown
162
- {...field}
163
- onChange={({ selectedItem }) => field.onChange(selectedItem)}
164
- id="billable-service"
165
- invalidText={t('invalidBillableService', 'Invalid billable service')}
166
- itemToString={(item) => item.name}
167
- items={billableServices ?? []}
168
- label={t('selectBillableService', 'Select billable service')}
169
- titleText={t('service', 'Service')}
170
- />
171
- )}
172
- />
173
- )}
174
- </ResponsiveWrapper>
175
- <ResponsiveWrapper>
176
- {isPaymentModesLoading ? (
177
- <DropdownSkeleton />
178
- ) : (
179
- <Controller
180
- control={control}
181
- name="paymentMode"
182
- render={({ field }) => (
183
- <Dropdown
184
- {...field}
185
- id="payment-mode"
186
- invalidText={t('invalidPaymentMode', 'Invalid payment mode')}
187
- itemToString={(item) => `${item.name} - ${item.price}`}
188
- items={billableService ?? []}
189
- onChange={({ selectedItem }) => field.onChange(selectedItem)}
190
- label={t('paymentMode', 'Payment mode')}
191
- titleText={t('paymentMode', 'Payment mode')}
192
- type="default"
193
- warnText={t('pleaseSelectPaymentMode', 'Please select a payment mode')}
194
- invalid={!!errors.paymentMode}
195
- />
196
- )}
197
- />
198
- )}
199
- </ResponsiveWrapper>
200
- <ResponsiveWrapper>
201
- <Controller
202
- control={control}
203
- name="amount"
204
- render={({ field }) => (
205
- <NumberInput
206
- {...field}
207
- onChange={(e) => field.onChange(Number(e.target.value))}
208
- helperText={t(
209
- 'amountToBeDepositedHelperText',
210
- 'Amount to be deposited for the patient before receiving services',
211
- )}
212
- label={t('amountToBeDeposited', 'Amount to be deposited')}
213
- invalidText={t('amountToBeDepositedInvalidText', 'Amount to be deposited is invalid')}
214
- invalid={!!errors.amount}
215
- />
216
- )}
217
- />
218
- </ResponsiveWrapper>
219
- </div>
220
- <ButtonSet className={classNames({ [styles.tablet]: isTablet, [styles.desktop]: !isTablet })}>
221
- <Button className={styles.button} kind="secondary" onClick={closeWorkspace}>
222
- {t('cancel', 'Cancel')}
223
- </Button>
224
- <Button className={styles.button} disabled={!isValid || !isDirty || isSubmitting} kind="primary" type="submit">
225
- {isSubmitting ? (
226
- <InlineLoading className={styles.spinner} description={t('postingDeposit', 'Posting deposit...')} />
227
- ) : (
228
- <span>{t('postDeposit', 'Post deposit')}</span>
229
- )}
230
- </Button>
231
- </ButtonSet>
232
- </form>
233
- );
234
- };
235
-
236
- export default BillDepositWorkspace;
File without changes