@openmrs/esm-billing-app 1.0.2-pre.92 → 1.0.2-pre.933
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/.eslintrc +16 -2
- package/README.md +54 -9
- package/__mocks__/bills.mock.ts +12 -0
- package/__mocks__/react-i18next.js +6 -5
- package/dist/1119.js +1 -1
- package/dist/1146.js +1 -2
- package/dist/1146.js.map +1 -1
- package/dist/1197.js +1 -1
- package/dist/1537.js +1 -0
- package/dist/1537.js.map +1 -0
- package/dist/1856.js +1 -0
- package/dist/1856.js.map +1 -0
- package/dist/2146.js +1 -1
- package/dist/2524.js +1 -0
- package/dist/2524.js.map +1 -0
- package/dist/2690.js +1 -1
- package/dist/3099.js +1 -1
- package/dist/3584.js +1 -1
- package/dist/3717.js +2 -0
- package/dist/3717.js.map +1 -0
- package/dist/4055.js +1 -1
- package/dist/4132.js +1 -1
- package/dist/4300.js +1 -1
- package/dist/4335.js +1 -1
- package/dist/4618.js +1 -1
- package/dist/4652.js +1 -1
- package/dist/4724.js +1 -0
- package/dist/4724.js.map +1 -0
- package/dist/4739.js +1 -1
- package/dist/4739.js.map +1 -1
- package/dist/4944.js +1 -1
- package/dist/5173.js +1 -1
- package/dist/5241.js +1 -1
- package/dist/5442.js +1 -1
- package/dist/5661.js +1 -1
- package/dist/6022.js +1 -1
- package/dist/6468.js +1 -1
- package/dist/6540.js +1 -1
- package/dist/6540.js.map +1 -1
- package/dist/6679.js +1 -1
- package/dist/6840.js +1 -1
- package/dist/6859.js +1 -1
- package/dist/7097.js +1 -1
- package/dist/7159.js +1 -1
- package/dist/723.js +1 -1
- package/dist/7255.js +1 -1
- package/dist/7255.js.map +1 -1
- package/dist/7617.js +1 -1
- package/dist/795.js +1 -1
- package/dist/8163.js +1 -1
- package/dist/8349.js +1 -1
- package/dist/8572.js +1 -0
- package/dist/8572.js.map +1 -0
- package/dist/8618.js +1 -1
- package/dist/8708.js +2 -0
- package/dist/{6557.js.LICENSE.txt → 8708.js.LICENSE.txt} +22 -0
- package/dist/8708.js.map +1 -0
- package/dist/890.js +1 -1
- package/dist/9214.js +1 -1
- package/dist/9538.js +1 -1
- package/dist/9569.js +1 -1
- package/dist/961.js +1 -1
- package/dist/961.js.map +1 -1
- package/dist/986.js +1 -1
- package/dist/9879.js +1 -1
- package/dist/9895.js +1 -1
- package/dist/9900.js +1 -1
- package/dist/9913.js +1 -1
- 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 +271 -285
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/e2e/README.md +19 -18
- package/e2e/core/test.ts +1 -1
- package/e2e/fixtures/api.ts +1 -1
- package/e2e/specs/sample-test.spec.ts +0 -1
- package/e2e/support/github/Dockerfile +1 -1
- package/package.json +18 -15
- package/src/bill-history/bill-history.component.tsx +20 -28
- package/src/bill-history/bill-history.scss +4 -94
- package/src/bill-history/bill-history.test.tsx +37 -78
- package/src/bill-item-actions/bill-item-actions.scss +21 -5
- package/src/bill-item-actions/edit-bill-item.modal.tsx +225 -0
- package/src/bill-item-actions/edit-bill-item.test.tsx +214 -40
- package/src/billable-services/bill-waiver/bill-selection.component.tsx +5 -5
- package/src/billable-services/bill-waiver/bill-waiver-form.component.tsx +28 -32
- package/src/billable-services/bill-waiver/patient-bills.component.tsx +7 -7
- package/src/billable-services/bill-waiver/utils.ts +13 -3
- package/src/billable-services/{create-edit/add-billable-service.scss → billable-service-form/billable-service-form.scss} +32 -64
- package/src/billable-services/billable-service-form/billable-service-form.test.tsx +898 -0
- package/src/billable-services/billable-service-form/billable-service-form.workspace.tsx +504 -0
- package/src/billable-services/billable-service.resource.ts +71 -27
- package/src/billable-services/billable-services-home.component.tsx +13 -42
- package/src/billable-services/billable-services-left-panel-link.component.tsx +48 -0
- package/src/billable-services/billable-services-left-panel-menu.component.tsx +46 -0
- package/src/billable-services/billable-services-menu-item/item.component.tsx +5 -4
- package/src/billable-services/billable-services.component.tsx +156 -152
- package/src/billable-services/billable-services.scss +29 -0
- package/src/billable-services/billable-services.test.tsx +6 -49
- package/src/billable-services/cash-point/add-cash-point.modal.tsx +170 -0
- package/src/billable-services/cash-point/cash-point-configuration.component.tsx +19 -193
- package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
- package/src/billable-services/dashboard/dashboard.component.tsx +0 -2
- package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +77 -0
- package/src/billable-services/payment-modes/payment-mode-form.modal.tsx +131 -0
- package/src/billable-services/payment-modes/payment-modes-config.component.tsx +139 -0
- package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -4
- package/src/billable-services-admin-card-link.component.test.tsx +2 -2
- package/src/billable-services-admin-card-link.component.tsx +1 -1
- package/src/billing-dashboard/billing-dashboard.scss +1 -1
- package/src/billing-form/billing-checkin-form.component.tsx +21 -17
- package/src/billing-form/billing-checkin-form.test.tsx +99 -26
- package/src/billing-form/billing-form.component.tsx +222 -292
- package/src/billing-form/billing-form.scss +143 -0
- package/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +1 -1
- package/src/billing.resource.ts +69 -74
- package/src/bills-table/bills-table.component.tsx +3 -3
- package/src/bills-table/bills-table.test.tsx +98 -54
- package/src/config-schema.ts +52 -24
- package/src/dashboard.meta.ts +4 -2
- package/src/helpers/functions.ts +5 -4
- package/src/index.ts +71 -9
- package/src/invoice/invoice-table.component.tsx +36 -70
- package/src/invoice/invoice-table.scss +8 -5
- package/src/invoice/invoice-table.test.tsx +273 -62
- package/src/invoice/invoice.component.tsx +39 -32
- package/src/invoice/invoice.scss +11 -4
- package/src/invoice/invoice.test.tsx +324 -120
- package/src/invoice/payments/invoice-breakdown/invoice-breakdown.scss +9 -9
- package/src/invoice/payments/payment-form/payment-form.component.tsx +43 -34
- package/src/invoice/payments/payment-form/payment-form.scss +5 -6
- package/src/invoice/payments/payment-form/payment-form.test.tsx +216 -66
- package/src/invoice/payments/payment-history/payment-history.component.tsx +6 -4
- package/src/invoice/payments/payment-history/payment-history.test.tsx +9 -14
- package/src/invoice/payments/payments.component.tsx +55 -67
- package/src/invoice/payments/payments.scss +4 -3
- package/src/invoice/payments/payments.test.tsx +282 -0
- package/src/invoice/payments/utils.ts +15 -27
- package/src/invoice/printable-invoice/print-receipt.component.tsx +3 -2
- package/src/invoice/printable-invoice/print-receipt.test.tsx +14 -25
- package/src/invoice/printable-invoice/printable-footer.component.tsx +2 -2
- package/src/invoice/printable-invoice/printable-footer.test.tsx +4 -13
- package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +12 -11
- package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +16 -14
- package/src/invoice/printable-invoice/printable-invoice.component.tsx +20 -34
- package/src/left-panel-link.test.tsx +1 -4
- package/src/metrics-cards/metrics-cards.component.tsx +16 -6
- package/src/metrics-cards/metrics-cards.scss +4 -0
- package/src/metrics-cards/metrics-cards.test.tsx +18 -5
- package/src/modal/require-payment-modal.test.tsx +27 -22
- package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +18 -19
- package/src/routes.json +44 -20
- package/src/types/index.ts +86 -23
- package/translations/am.json +132 -77
- package/translations/ar.json +133 -78
- package/translations/ar_SY.json +133 -78
- package/translations/bn.json +135 -80
- package/translations/de.json +133 -78
- package/translations/en.json +134 -79
- package/translations/en_US.json +133 -78
- package/translations/es.json +132 -77
- package/translations/es_MX.json +133 -78
- package/translations/fr.json +138 -83
- package/translations/he.json +132 -77
- package/translations/hi.json +133 -78
- package/translations/hi_IN.json +133 -78
- package/translations/id.json +133 -78
- package/translations/it.json +159 -104
- package/translations/ka.json +133 -78
- package/translations/km.json +132 -77
- package/translations/ku.json +133 -78
- package/translations/ky.json +133 -78
- package/translations/lg.json +133 -78
- package/translations/ne.json +133 -78
- package/translations/pl.json +133 -78
- package/translations/pt.json +133 -78
- package/translations/pt_BR.json +133 -78
- package/translations/qu.json +133 -78
- package/translations/ro_RO.json +220 -165
- package/translations/ru_RU.json +133 -78
- package/translations/si.json +133 -78
- package/translations/sw.json +133 -78
- package/translations/sw_KE.json +133 -78
- package/translations/tr.json +133 -78
- package/translations/tr_TR.json +133 -78
- package/translations/uk.json +133 -78
- package/translations/uz.json +133 -78
- package/translations/uz@Latn.json +133 -78
- package/translations/uz_UZ.json +133 -78
- package/translations/vi.json +133 -78
- package/translations/zh.json +133 -78
- package/translations/zh_CN.json +163 -108
- package/dist/1146.js.LICENSE.txt +0 -21
- package/dist/2352.js +0 -1
- package/dist/2352.js.map +0 -1
- package/dist/246.js +0 -1
- package/dist/246.js.map +0 -1
- package/dist/4689.js +0 -2
- package/dist/4689.js.map +0 -1
- package/dist/6557.js +0 -2
- package/dist/6557.js.map +0 -1
- package/dist/8638.js +0 -1
- package/dist/8638.js.map +0 -1
- package/dist/9968.js +0 -1
- package/dist/9968.js.map +0 -1
- package/src/bill-item-actions/edit-bill-item.component.tsx +0 -221
- package/src/billable-services/create-edit/add-billable-service.component.tsx +0 -401
- package/src/billable-services/create-edit/add-billable-service.test.tsx +0 -154
- package/src/billable-services/dashboard/service-metrics.component.tsx +0 -41
- package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
- package/src/invoice/payments/payments.component.test.tsx +0 -121
- /package/dist/{4689.js.LICENSE.txt → 3717.js.LICENSE.txt} +0 -0
|
@@ -1,182 +1,115 @@
|
|
|
1
|
-
import React, { useState
|
|
2
|
-
import fuzzy from 'fuzzy';
|
|
3
|
-
import isEmpty from 'lodash-es/isEmpty';
|
|
4
|
-
import {
|
|
5
|
-
Button,
|
|
6
|
-
ButtonSet,
|
|
7
|
-
Form,
|
|
8
|
-
InlineLoading,
|
|
9
|
-
RadioButton,
|
|
10
|
-
RadioButtonGroup,
|
|
11
|
-
Search,
|
|
12
|
-
Stack,
|
|
13
|
-
Table,
|
|
14
|
-
TableBody,
|
|
15
|
-
TableCell,
|
|
16
|
-
TableHead,
|
|
17
|
-
TableHeader,
|
|
18
|
-
TableRow,
|
|
19
|
-
} from '@carbon/react';
|
|
20
|
-
import { TrashCan } from '@carbon/react/icons';
|
|
21
|
-
import { mutate } from 'swr';
|
|
1
|
+
import React, { useState } from 'react';
|
|
22
2
|
import { useTranslation } from 'react-i18next';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
3
|
+
import { mutate } from 'swr';
|
|
4
|
+
import { Button, ButtonSet, ComboBox, Form, NumberInput, InlineLoading, InlineNotification } from '@carbon/react';
|
|
5
|
+
import { TrashCan } from '@carbon/react/icons';
|
|
6
|
+
import { useConfig, useLayoutType, showSnackbar, getCoreTranslation } from '@openmrs/esm-framework';
|
|
7
|
+
import { processBillItems, useBillableServices } from '../billing.resource';
|
|
8
|
+
import { calculateTotalAmount, convertToCurrency } from '../helpers/functions';
|
|
9
|
+
import type { BillingConfig } from '../config-schema';
|
|
10
|
+
import type { BillableItem, LineItem, ServicePrice } from '../types';
|
|
25
11
|
import { apiBasePath } from '../constants';
|
|
26
|
-
import { convertToCurrency } from '../helpers';
|
|
27
|
-
import { type BillabeItem } from '../types';
|
|
28
|
-
import { useFetchSearchResults, processBillItems } from '../billing.resource';
|
|
29
12
|
import styles from './billing-form.scss';
|
|
30
13
|
|
|
14
|
+
interface ExtendedLineItem extends LineItem {
|
|
15
|
+
selectedPaymentMethod?: ServicePrice;
|
|
16
|
+
availablePaymentMethods?: ServicePrice[];
|
|
17
|
+
}
|
|
18
|
+
|
|
31
19
|
type BillingFormProps = {
|
|
32
20
|
patientUuid: string;
|
|
33
21
|
closeWorkspace: () => void;
|
|
34
22
|
};
|
|
35
23
|
|
|
36
24
|
const BillingForm: React.FC<BillingFormProps> = ({ patientUuid, closeWorkspace }) => {
|
|
37
|
-
const { t } = useTranslation();
|
|
38
|
-
const { defaultCurrency, postBilledItems } = useConfig();
|
|
39
25
|
const isTablet = useLayoutType() === 'tablet';
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const [searchOptions, setSearchOptions] = useState([]);
|
|
43
|
-
const [billItems, setBillItems] = useState([]);
|
|
44
|
-
const [category, setCategory] = useState('');
|
|
45
|
-
const [saveDisabled, setSaveDisabled] = useState<boolean>(false);
|
|
26
|
+
const { t } = useTranslation();
|
|
27
|
+
const { defaultCurrency, postBilledItems } = useConfig<BillingConfig>();
|
|
46
28
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
47
|
-
const [
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
const [selectedItems, setSelectedItems] = useState<ExtendedLineItem[]>([]);
|
|
30
|
+
const { data, error, isLoading } = useBillableServices();
|
|
31
|
+
|
|
32
|
+
const selectBillableItem = (item: BillableItem) => {
|
|
33
|
+
if (!item) return;
|
|
34
|
+
|
|
35
|
+
const existingItem = selectedItems.find((selectedItem) => selectedItem.uuid === item.uuid);
|
|
36
|
+
if (existingItem) {
|
|
37
|
+
const updatedItem = { ...existingItem, quantity: existingItem.quantity + 1 };
|
|
38
|
+
setSelectedItems(
|
|
39
|
+
[...selectedItems].map((selectedItem) => (selectedItem.uuid === item.uuid ? updatedItem : selectedItem)),
|
|
40
|
+
);
|
|
41
|
+
return;
|
|
55
42
|
}
|
|
56
|
-
setCategory(choiceSelected === 'Stock Item' ? 'Stock Item' : 'Service');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const billItemSchema = z.object({
|
|
60
|
-
Qnty: z.number().min(1, t('quantityGreaterThanZero', 'Quantity must be at least one for all items.')), // zod logic
|
|
61
|
-
});
|
|
62
43
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
let
|
|
44
|
+
const availablePaymentMethods = item.servicePrices || [];
|
|
45
|
+
let defaultPrice = 0;
|
|
46
|
+
let selectedPaymentMethod = null;
|
|
66
47
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const parsedErrorMessage = JSON.parse(error.message);
|
|
72
|
-
showToast({
|
|
73
|
-
title: t('billItems', 'Save Bill'),
|
|
74
|
-
kind: 'error',
|
|
75
|
-
description: parsedErrorMessage[0].message,
|
|
76
|
-
});
|
|
48
|
+
if (availablePaymentMethods.length === 1) {
|
|
49
|
+
const price = availablePaymentMethods[0].price;
|
|
50
|
+
defaultPrice = typeof price === 'number' ? price : parseFloat(price);
|
|
51
|
+
selectedPaymentMethod = availablePaymentMethods[0];
|
|
77
52
|
}
|
|
78
53
|
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
const mappedItem: ExtendedLineItem = {
|
|
55
|
+
uuid: item.uuid,
|
|
56
|
+
display: item.name,
|
|
57
|
+
quantity: 1,
|
|
58
|
+
price: defaultPrice,
|
|
59
|
+
billableService: item.uuid,
|
|
60
|
+
paymentStatus: 'PENDING',
|
|
61
|
+
lineItemOrder: 0,
|
|
62
|
+
selectedPaymentMethod: selectedPaymentMethod,
|
|
63
|
+
availablePaymentMethods: availablePaymentMethods,
|
|
64
|
+
};
|
|
89
65
|
|
|
90
|
-
|
|
91
|
-
setGrandTotal(updatedGrandTotal);
|
|
66
|
+
setSelectedItems([...selectedItems, mappedItem]);
|
|
92
67
|
};
|
|
93
68
|
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
69
|
+
const updateQuantity = (uuid: string, quantity: number) => {
|
|
70
|
+
const updatedItems = [...selectedItems].map((item) => (item.uuid === uuid ? { ...item, quantity } : item));
|
|
71
|
+
setSelectedItems(updatedItems);
|
|
97
72
|
};
|
|
98
73
|
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
let updatedItems = [];
|
|
103
|
-
if (existingItemIndex >= 0) {
|
|
104
|
-
updatedItems = billItems.map((item, index) => {
|
|
105
|
-
if (index === existingItemIndex) {
|
|
106
|
-
const updatedQuantity = item.Qnty + 1;
|
|
107
|
-
return { ...item, Qnty: updatedQuantity, Total: updatedQuantity * item.Price };
|
|
108
|
-
}
|
|
109
|
-
return item;
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
const newItem = {
|
|
113
|
-
uuid: itemid,
|
|
114
|
-
Item: itemname,
|
|
115
|
-
Qnty: 1,
|
|
116
|
-
Price: itemPrice,
|
|
117
|
-
Total: itemPrice,
|
|
118
|
-
category: itemcategory,
|
|
119
|
-
};
|
|
120
|
-
updatedItems = [...billItems, newItem];
|
|
121
|
-
setAddedItems([...addedItems, newItem]);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
setBillItems(updatedItems);
|
|
125
|
-
calculateTotalAfterAddBillItem(updatedItems);
|
|
126
|
-
(document.getElementById('searchField') as HTMLInputElement).value = '';
|
|
74
|
+
const removeSelectedBillableItem = (uuid: string) => {
|
|
75
|
+
const updatedItems = [...selectedItems].filter((item) => item.uuid !== uuid);
|
|
76
|
+
setSelectedItems(updatedItems);
|
|
127
77
|
};
|
|
128
78
|
|
|
129
|
-
const
|
|
130
|
-
const updatedItems =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
79
|
+
const updatePaymentMethod = (itemUuid: string, paymentMethod: ServicePrice) => {
|
|
80
|
+
const updatedItems = [...selectedItems].map((item) =>
|
|
81
|
+
item.uuid === itemUuid
|
|
82
|
+
? {
|
|
83
|
+
...item,
|
|
84
|
+
selectedPaymentMethod: paymentMethod,
|
|
85
|
+
price: typeof paymentMethod.price === 'number' ? paymentMethod.price : parseFloat(paymentMethod.price),
|
|
86
|
+
priceName: paymentMethod.name,
|
|
87
|
+
priceUuid: paymentMethod.uuid,
|
|
88
|
+
}
|
|
89
|
+
: item,
|
|
90
|
+
);
|
|
91
|
+
setSelectedItems(updatedItems);
|
|
138
92
|
};
|
|
139
93
|
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
94
|
+
const validateSelectedItems = (): boolean => {
|
|
95
|
+
for (const item of selectedItems) {
|
|
96
|
+
if (item.availablePaymentMethods && item.availablePaymentMethods.length > 1 && !item.selectedPaymentMethod) {
|
|
97
|
+
showSnackbar({
|
|
98
|
+
title: t('validationError', 'Validation error'),
|
|
99
|
+
subtitle: t('paymentMethodRequired', 'Payment method is required for all items'),
|
|
100
|
+
kind: 'error',
|
|
101
|
+
});
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
147
104
|
}
|
|
105
|
+
return true;
|
|
106
|
+
};
|
|
148
107
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
?.map((item) => {
|
|
154
|
-
return {
|
|
155
|
-
uuid: item.uuid || '',
|
|
156
|
-
Item: item.commonName ? item.commonName : item.name,
|
|
157
|
-
Qnty: 1,
|
|
158
|
-
Price: item.commonName ? 10 : item.servicePrices[0]?.price,
|
|
159
|
-
Total: item.commonName ? 10 : item.servicePrices[0]?.price,
|
|
160
|
-
category: item.commonName ? 'StockItem' : 'Service',
|
|
161
|
-
};
|
|
162
|
-
})
|
|
163
|
-
.filter((item) => !existingItemUuids.has(item.uuid));
|
|
164
|
-
|
|
165
|
-
return debouncedSearchTerm
|
|
166
|
-
? fuzzy
|
|
167
|
-
.filter(debouncedSearchTerm, preprocessedData, {
|
|
168
|
-
extract: (o) => `${o.Item}`,
|
|
169
|
-
})
|
|
170
|
-
.sort((r1, r2) => r1.score - r2.score)
|
|
171
|
-
.map((result) => result.original)
|
|
172
|
-
: searchOptions;
|
|
173
|
-
}, [debouncedSearchTerm, isLoading, error, data, billItems, searchOptions]);
|
|
174
|
-
|
|
175
|
-
useEffect(() => {
|
|
176
|
-
setSearchOptions(filterItems);
|
|
177
|
-
}, [filterItems]);
|
|
108
|
+
const postBillItems = async () => {
|
|
109
|
+
if (!validateSelectedItems()) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
178
112
|
|
|
179
|
-
const postBillItems = () => {
|
|
180
113
|
setIsSubmitting(true);
|
|
181
114
|
const bill = {
|
|
182
115
|
cashPoint: postBilledItems.cashPoint,
|
|
@@ -187,165 +120,162 @@ const BillingForm: React.FC<BillingFormProps> = ({ patientUuid, closeWorkspace }
|
|
|
187
120
|
status: 'PENDING',
|
|
188
121
|
};
|
|
189
122
|
|
|
190
|
-
|
|
191
|
-
const lineItem:
|
|
192
|
-
quantity:
|
|
193
|
-
price: item.
|
|
194
|
-
priceName: 'Default',
|
|
195
|
-
priceUuid: postBilledItems.priceUuid,
|
|
123
|
+
selectedItems.forEach((item) => {
|
|
124
|
+
const lineItem: LineItem = {
|
|
125
|
+
quantity: item.quantity,
|
|
126
|
+
price: item.price,
|
|
196
127
|
lineItemOrder: 0,
|
|
197
128
|
paymentStatus: 'PENDING',
|
|
129
|
+
billableService: item.uuid,
|
|
198
130
|
};
|
|
199
131
|
|
|
200
|
-
|
|
201
|
-
lineItem.item = item.uuid;
|
|
202
|
-
} else {
|
|
203
|
-
lineItem.billableService = item.uuid;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
bill?.lineItems.push(lineItem);
|
|
132
|
+
bill.lineItems.push(lineItem);
|
|
207
133
|
});
|
|
208
134
|
|
|
209
135
|
const url = `${apiBasePath}bill`;
|
|
210
|
-
|
|
211
|
-
()
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const handleClearSearchTerm = () => {
|
|
231
|
-
setSearchOptions([]);
|
|
136
|
+
try {
|
|
137
|
+
await processBillItems(bill);
|
|
138
|
+
closeWorkspace();
|
|
139
|
+
mutate((key) => typeof key === 'string' && key.startsWith(url), undefined, { revalidate: true });
|
|
140
|
+
showSnackbar({
|
|
141
|
+
title: t('saveBill', 'Save bill'),
|
|
142
|
+
subtitle: t('billProcessedSuccessfully', 'Bill processed successfully'),
|
|
143
|
+
kind: 'success',
|
|
144
|
+
});
|
|
145
|
+
} catch (error) {
|
|
146
|
+
showSnackbar({
|
|
147
|
+
title: t('billProcessingError', 'Bill processing error'),
|
|
148
|
+
kind: 'error',
|
|
149
|
+
subtitle: error?.message,
|
|
150
|
+
});
|
|
151
|
+
} finally {
|
|
152
|
+
setIsSubmitting(false);
|
|
153
|
+
}
|
|
232
154
|
};
|
|
233
155
|
|
|
234
156
|
return (
|
|
235
157
|
<Form className={styles.form}>
|
|
236
158
|
<div className={styles.grid}>
|
|
237
|
-
|
|
238
|
-
<
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
closeButtonLabelText={t('clearSearchInput', 'Clear search input')}
|
|
254
|
-
className={styles.mt2}
|
|
255
|
-
placeholder={t('searchItems', 'Search items and services')}
|
|
256
|
-
labelText={t('searchItems', 'Search items and services')}
|
|
257
|
-
onKeyUp={handleSearchTermChange}
|
|
258
|
-
onClear={handleClearSearchTerm}
|
|
159
|
+
{isLoading ? (
|
|
160
|
+
<InlineLoading description={getCoreTranslation('loading') + '...'} />
|
|
161
|
+
) : error ? (
|
|
162
|
+
<InlineNotification
|
|
163
|
+
kind="error"
|
|
164
|
+
lowContrast
|
|
165
|
+
title={t('errorLoadingBillableServices', 'Error loading billable services')}
|
|
166
|
+
subtitle={error?.message}
|
|
167
|
+
/>
|
|
168
|
+
) : (
|
|
169
|
+
<ComboBox
|
|
170
|
+
id="searchItems"
|
|
171
|
+
onChange={({ selectedItem: item }: { selectedItem: BillableItem }) => selectBillableItem(item)}
|
|
172
|
+
itemToString={(item: BillableItem) => item?.name || ''}
|
|
173
|
+
items={data ?? []}
|
|
174
|
+
titleText={t('searchItems', 'Search items and services')}
|
|
259
175
|
/>
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
<
|
|
263
|
-
{
|
|
264
|
-
|
|
265
|
-
|
|
176
|
+
)}
|
|
177
|
+
{selectedItems && selectedItems.length > 0 && (
|
|
178
|
+
<div className={styles.selectedItemsContainer}>
|
|
179
|
+
<h4>{t('selectedItems', 'Selected items')}</h4>
|
|
180
|
+
{selectedItems.map((item) => (
|
|
181
|
+
<div key={item.uuid} className={styles.itemCard}>
|
|
182
|
+
<div className={styles.itemHeader}>
|
|
183
|
+
<span className={styles.itemName}>{item.display}</span>
|
|
266
184
|
<Button
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
{
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
<TableCell>
|
|
297
|
-
<input
|
|
298
|
-
type="number"
|
|
299
|
-
className={`form-control ${row.Qnty <= 0 ? styles.invalidInput : ''}`}
|
|
300
|
-
id={row.Item}
|
|
301
|
-
min={0}
|
|
302
|
-
max={100}
|
|
303
|
-
value={row.Qnty}
|
|
304
|
-
onChange={(e) => {
|
|
305
|
-
calculateTotal(e, row.Item);
|
|
306
|
-
row.Qnty = e.target.value;
|
|
185
|
+
kind="ghost"
|
|
186
|
+
size="sm"
|
|
187
|
+
renderIcon={TrashCan}
|
|
188
|
+
iconDescription={t('remove', 'Remove')}
|
|
189
|
+
onClick={() => removeSelectedBillableItem(item.uuid)}
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<div className={styles.itemControls}>
|
|
194
|
+
{item.availablePaymentMethods && item.availablePaymentMethods.length > 1 ? (
|
|
195
|
+
<div className={styles.controlSection}>
|
|
196
|
+
<label>{t('selectPaymentMethod', 'Select payment method')}</label>
|
|
197
|
+
<ComboBox
|
|
198
|
+
id={`payment-method-${item.uuid}`}
|
|
199
|
+
items={item.availablePaymentMethods}
|
|
200
|
+
size="md"
|
|
201
|
+
itemToString={(method: ServicePrice) =>
|
|
202
|
+
method
|
|
203
|
+
? `${method.name} - ${convertToCurrency(
|
|
204
|
+
typeof method.price === 'number' ? method.price : parseFloat(method.price),
|
|
205
|
+
defaultCurrency,
|
|
206
|
+
)}`
|
|
207
|
+
: ''
|
|
208
|
+
}
|
|
209
|
+
selectedItem={item.selectedPaymentMethod}
|
|
210
|
+
onChange={({ selectedItem }) => {
|
|
211
|
+
if (selectedItem) {
|
|
212
|
+
updatePaymentMethod(item.uuid, selectedItem);
|
|
213
|
+
}
|
|
307
214
|
}}
|
|
215
|
+
placeholder={t('selectPaymentMethod', 'Select payment method')}
|
|
216
|
+
titleText=""
|
|
308
217
|
/>
|
|
309
|
-
</
|
|
310
|
-
|
|
311
|
-
<
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
218
|
+
</div>
|
|
219
|
+
) : (
|
|
220
|
+
<div className={styles.controlSection}>
|
|
221
|
+
<label>{t('unitPrice', 'Unit price')}</label>
|
|
222
|
+
<span className={styles.priceDisplay}>{convertToCurrency(item.price, defaultCurrency)}</span>
|
|
223
|
+
</div>
|
|
224
|
+
)}
|
|
225
|
+
|
|
226
|
+
<div className={styles.controlSection}>
|
|
227
|
+
<label>{t('quantity', 'Quantity')}</label>
|
|
228
|
+
<NumberInput
|
|
229
|
+
disableWheel
|
|
230
|
+
hideSteppers
|
|
231
|
+
id={`quantity-${item.uuid}`}
|
|
232
|
+
min={1}
|
|
233
|
+
value={item.quantity}
|
|
234
|
+
size="md"
|
|
235
|
+
onChange={(_, { value }) => {
|
|
236
|
+
const number = parseFloat(String(value));
|
|
237
|
+
updateQuantity(item.uuid, isNaN(number) ? 1 : number);
|
|
238
|
+
}}
|
|
239
|
+
/>
|
|
240
|
+
</div>
|
|
241
|
+
|
|
242
|
+
<div className={styles.controlSection}>
|
|
243
|
+
<label>{t('total', 'Total')}</label>
|
|
244
|
+
<span className={styles.totalDisplay}>
|
|
245
|
+
{convertToCurrency(item.price * item.quantity, defaultCurrency)}
|
|
246
|
+
</span>
|
|
247
|
+
</div>
|
|
248
|
+
</div>
|
|
249
|
+
</div>
|
|
250
|
+
))}
|
|
251
|
+
|
|
252
|
+
<div className={styles.grandTotal}>
|
|
253
|
+
<strong>
|
|
254
|
+
{t('grandTotal', 'Grand total')}:{' '}
|
|
255
|
+
{convertToCurrency(calculateTotalAmount(selectedItems), defaultCurrency)}
|
|
256
|
+
</strong>
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
)}
|
|
348
260
|
</div>
|
|
261
|
+
|
|
262
|
+
<ButtonSet className={isTablet ? styles.tablet : styles.desktop}>
|
|
263
|
+
<Button className={styles.button} kind="secondary" disabled={isSubmitting} onClick={closeWorkspace}>
|
|
264
|
+
{t('discard', 'Discard')}
|
|
265
|
+
</Button>
|
|
266
|
+
<Button
|
|
267
|
+
className={styles.button}
|
|
268
|
+
kind="primary"
|
|
269
|
+
onClick={postBillItems}
|
|
270
|
+
disabled={isSubmitting || selectedItems.length === 0}
|
|
271
|
+
type="submit">
|
|
272
|
+
{isSubmitting ? (
|
|
273
|
+
<InlineLoading description={t('saving', 'Saving') + '...'} />
|
|
274
|
+
) : (
|
|
275
|
+
t('saveAndClose', 'Save and close')
|
|
276
|
+
)}
|
|
277
|
+
</Button>
|
|
278
|
+
</ButtonSet>
|
|
349
279
|
</Form>
|
|
350
280
|
);
|
|
351
281
|
};
|