@openmrs/esm-billing-app 1.0.2-pre.86 → 1.0.2-pre.863

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 (214) hide show
  1. package/.eslintrc +16 -2
  2. package/README.md +54 -9
  3. package/__mocks__/bills.mock.ts +12 -0
  4. package/__mocks__/react-i18next.js +6 -5
  5. package/dist/1119.js +1 -1
  6. package/dist/1146.js +1 -2
  7. package/dist/1146.js.map +1 -1
  8. package/dist/1197.js +1 -1
  9. package/dist/1856.js +1 -0
  10. package/dist/1856.js.map +1 -0
  11. package/dist/2146.js +1 -1
  12. package/dist/2177.js +2 -0
  13. package/dist/2177.js.LICENSE.txt +9 -0
  14. package/dist/2177.js.map +1 -0
  15. package/dist/2524.js +1 -0
  16. package/dist/2524.js.map +1 -0
  17. package/dist/2690.js +1 -1
  18. package/dist/3041.js +1 -0
  19. package/dist/3041.js.map +1 -0
  20. package/dist/3099.js +1 -1
  21. package/dist/3584.js +1 -1
  22. package/dist/3717.js +2 -0
  23. package/dist/3717.js.map +1 -0
  24. package/dist/4055.js +1 -1
  25. package/dist/4132.js +1 -1
  26. package/dist/4225.js +1 -0
  27. package/dist/4225.js.map +1 -0
  28. package/dist/4300.js +1 -1
  29. package/dist/4335.js +1 -1
  30. package/dist/4344.js +1 -0
  31. package/dist/4344.js.map +1 -0
  32. package/dist/4618.js +1 -1
  33. package/dist/4652.js +1 -1
  34. package/dist/4724.js +1 -0
  35. package/dist/4724.js.map +1 -0
  36. package/dist/4739.js +1 -1
  37. package/dist/4739.js.map +1 -1
  38. package/dist/4944.js +1 -1
  39. package/dist/5173.js +1 -1
  40. package/dist/5241.js +1 -1
  41. package/dist/5422.js +1 -0
  42. package/dist/5422.js.map +1 -0
  43. package/dist/5442.js +1 -1
  44. package/dist/5661.js +1 -1
  45. package/dist/6022.js +1 -1
  46. package/dist/6295.js +2 -0
  47. package/dist/{6525.js.LICENSE.txt → 6295.js.LICENSE.txt} +16 -4
  48. package/dist/6295.js.map +1 -0
  49. package/dist/6468.js +1 -1
  50. package/dist/6540.js +1 -1
  51. package/dist/6540.js.map +1 -1
  52. package/dist/6606.js +1 -0
  53. package/dist/6606.js.map +1 -0
  54. package/dist/6679.js +1 -1
  55. package/dist/6840.js +1 -1
  56. package/dist/6859.js +1 -1
  57. package/dist/7097.js +1 -1
  58. package/dist/7159.js +1 -1
  59. package/dist/723.js +1 -1
  60. package/dist/7617.js +1 -1
  61. package/dist/795.js +1 -1
  62. package/dist/8163.js +1 -1
  63. package/dist/8349.js +1 -1
  64. package/dist/8618.js +1 -1
  65. package/dist/890.js +1 -1
  66. package/dist/9214.js +1 -1
  67. package/dist/9538.js +1 -1
  68. package/dist/9569.js +1 -1
  69. package/dist/961.js +1 -1
  70. package/dist/961.js.map +1 -1
  71. package/dist/986.js +1 -1
  72. package/dist/9879.js +1 -1
  73. package/dist/9895.js +1 -1
  74. package/dist/9900.js +1 -1
  75. package/dist/9913.js +1 -1
  76. package/dist/main.js +1 -1
  77. package/dist/main.js.map +1 -1
  78. package/dist/openmrs-esm-billing-app.js +1 -1
  79. package/dist/openmrs-esm-billing-app.js.buildmanifest.json +388 -282
  80. package/dist/openmrs-esm-billing-app.js.map +1 -1
  81. package/dist/routes.json +1 -1
  82. package/e2e/README.md +19 -18
  83. package/e2e/core/test.ts +1 -1
  84. package/e2e/fixtures/api.ts +1 -1
  85. package/e2e/specs/sample-test.spec.ts +0 -1
  86. package/e2e/support/github/Dockerfile +1 -1
  87. package/package.json +13 -10
  88. package/src/bill-history/bill-history.component.tsx +20 -28
  89. package/src/bill-history/bill-history.scss +4 -94
  90. package/src/bill-history/bill-history.test.tsx +37 -78
  91. package/src/bill-item-actions/bill-item-actions.scss +21 -5
  92. package/src/bill-item-actions/edit-bill-item.modal.tsx +225 -0
  93. package/src/bill-item-actions/edit-bill-item.test.tsx +214 -40
  94. package/src/billable-services/bill-waiver/bill-selection.component.tsx +5 -5
  95. package/src/billable-services/bill-waiver/bill-waiver-form.component.tsx +28 -32
  96. package/src/billable-services/bill-waiver/patient-bills.component.tsx +7 -7
  97. package/src/billable-services/bill-waiver/utils.ts +13 -3
  98. package/src/billable-services/billable-service.resource.ts +42 -26
  99. package/src/billable-services/billable-services-home.component.tsx +4 -4
  100. package/src/billable-services/billable-services.component.tsx +149 -148
  101. package/src/billable-services/billable-services.scss +3 -0
  102. package/src/billable-services/billable-services.test.tsx +6 -49
  103. package/src/billable-services/cash-point/add-cash-point.modal.tsx +168 -0
  104. package/src/billable-services/cash-point/cash-point-configuration.component.tsx +19 -193
  105. package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
  106. package/src/billable-services/create-edit/add-billable-service.component.tsx +365 -299
  107. package/src/billable-services/create-edit/add-billable-service.scss +7 -68
  108. package/src/billable-services/create-edit/add-billable-service.test.tsx +167 -81
  109. package/src/billable-services/create-edit/edit-billable-service.modal.tsx +51 -0
  110. package/src/billable-services/dashboard/service-metrics.component.tsx +11 -3
  111. package/src/billable-services/payment-modes/add-payment-mode.modal.tsx +121 -0
  112. package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +74 -0
  113. package/src/billable-services/payment-modes/payment-modes-config.component.tsx +125 -0
  114. package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -4
  115. package/src/billing-dashboard/billing-dashboard.scss +1 -1
  116. package/src/billing-form/billing-checkin-form.component.tsx +21 -17
  117. package/src/billing-form/billing-checkin-form.test.tsx +99 -26
  118. package/src/billing-form/billing-form.component.tsx +222 -292
  119. package/src/billing-form/billing-form.scss +143 -0
  120. package/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +1 -1
  121. package/src/billing.resource.ts +69 -74
  122. package/src/bills-table/bills-table.component.tsx +3 -3
  123. package/src/bills-table/bills-table.test.tsx +98 -54
  124. package/src/config-schema.ts +52 -24
  125. package/src/dashboard.meta.ts +4 -2
  126. package/src/helpers/functions.ts +5 -4
  127. package/src/index.ts +17 -6
  128. package/src/invoice/invoice-table.component.tsx +36 -70
  129. package/src/invoice/invoice-table.scss +8 -5
  130. package/src/invoice/invoice-table.test.tsx +273 -62
  131. package/src/invoice/invoice.component.tsx +39 -32
  132. package/src/invoice/invoice.scss +11 -4
  133. package/src/invoice/invoice.test.tsx +324 -120
  134. package/src/invoice/payments/invoice-breakdown/invoice-breakdown.scss +9 -9
  135. package/src/invoice/payments/payment-form/payment-form.component.tsx +43 -34
  136. package/src/invoice/payments/payment-form/payment-form.scss +5 -6
  137. package/src/invoice/payments/payment-form/payment-form.test.tsx +216 -66
  138. package/src/invoice/payments/payment-history/payment-history.component.tsx +6 -4
  139. package/src/invoice/payments/payment-history/payment-history.test.tsx +9 -14
  140. package/src/invoice/payments/payments.component.tsx +55 -67
  141. package/src/invoice/payments/payments.scss +4 -3
  142. package/src/invoice/payments/payments.test.tsx +282 -0
  143. package/src/invoice/payments/utils.ts +15 -27
  144. package/src/invoice/printable-invoice/print-receipt.component.tsx +3 -2
  145. package/src/invoice/printable-invoice/print-receipt.test.tsx +14 -25
  146. package/src/invoice/printable-invoice/printable-footer.component.tsx +2 -2
  147. package/src/invoice/printable-invoice/printable-footer.test.tsx +4 -13
  148. package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +12 -11
  149. package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +16 -14
  150. package/src/invoice/printable-invoice/printable-invoice.component.tsx +20 -34
  151. package/src/left-panel-link.test.tsx +1 -4
  152. package/src/metrics-cards/metrics-cards.component.tsx +12 -2
  153. package/src/metrics-cards/metrics-cards.scss +4 -0
  154. package/src/metrics-cards/metrics-cards.test.tsx +18 -5
  155. package/src/modal/require-payment-modal.test.tsx +27 -22
  156. package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +18 -19
  157. package/src/routes.json +25 -7
  158. package/src/types/index.ts +81 -23
  159. package/translations/am.json +125 -74
  160. package/translations/ar.json +126 -75
  161. package/translations/ar_SY.json +126 -75
  162. package/translations/bn.json +128 -77
  163. package/translations/de.json +126 -75
  164. package/translations/en.json +126 -75
  165. package/translations/en_US.json +126 -75
  166. package/translations/es.json +125 -74
  167. package/translations/es_MX.json +126 -75
  168. package/translations/fr.json +131 -80
  169. package/translations/he.json +125 -74
  170. package/translations/hi.json +126 -75
  171. package/translations/hi_IN.json +126 -75
  172. package/translations/id.json +126 -75
  173. package/translations/it.json +152 -101
  174. package/translations/ka.json +126 -75
  175. package/translations/km.json +125 -74
  176. package/translations/ku.json +126 -75
  177. package/translations/ky.json +126 -75
  178. package/translations/lg.json +126 -75
  179. package/translations/ne.json +126 -75
  180. package/translations/pl.json +126 -75
  181. package/translations/pt.json +126 -75
  182. package/translations/pt_BR.json +126 -75
  183. package/translations/qu.json +126 -75
  184. package/translations/ro_RO.json +216 -165
  185. package/translations/ru_RU.json +126 -75
  186. package/translations/si.json +126 -75
  187. package/translations/sw.json +126 -75
  188. package/translations/sw_KE.json +126 -75
  189. package/translations/tr.json +126 -75
  190. package/translations/tr_TR.json +126 -75
  191. package/translations/uk.json +126 -75
  192. package/translations/uz.json +126 -75
  193. package/translations/uz@Latn.json +126 -75
  194. package/translations/uz_UZ.json +126 -75
  195. package/translations/vi.json +126 -75
  196. package/translations/zh.json +126 -75
  197. package/translations/zh_CN.json +158 -107
  198. package/dist/1146.js.LICENSE.txt +0 -21
  199. package/dist/2352.js +0 -1
  200. package/dist/2352.js.map +0 -1
  201. package/dist/246.js +0 -1
  202. package/dist/246.js.map +0 -1
  203. package/dist/6525.js +0 -2
  204. package/dist/6525.js.map +0 -1
  205. package/dist/8556.js +0 -2
  206. package/dist/8556.js.map +0 -1
  207. package/dist/8638.js +0 -1
  208. package/dist/8638.js.map +0 -1
  209. package/dist/9968.js +0 -1
  210. package/dist/9968.js.map +0 -1
  211. package/src/bill-item-actions/edit-bill-item.component.tsx +0 -221
  212. package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
  213. package/src/invoice/payments/payments.component.test.tsx +0 -121
  214. /package/dist/{8556.js.LICENSE.txt → 3717.js.LICENSE.txt} +0 -0
@@ -1,46 +1,20 @@
1
1
  import React from 'react';
2
- import { useTranslation } from 'react-i18next';
3
- import { render, screen, fireEvent, act } from '@testing-library/react';
4
- import { showModal } from '@openmrs/esm-framework';
5
- import InvoiceTable from './invoice-table.component';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { render, screen, waitFor } from '@testing-library/react';
4
+ import { getDefaultsFromConfigSchema, showModal, useConfig } from '@openmrs/esm-framework';
6
5
  import { type MappedBill } from '../types';
6
+ import { configSchema, type BillingConfig } from '../config-schema';
7
+ import InvoiceTable from './invoice-table.component';
7
8
 
8
- // Mocking dependencies
9
- jest.mock('react-i18next', () => ({
10
- useTranslation: jest.fn(() => ({
11
- t: jest.fn((key, fallback) => fallback || key),
12
- i18n: { language: 'en' },
13
- })),
14
- }));
15
-
16
- jest.mock('@openmrs/esm-framework', () => ({
17
- showModal: jest.fn(),
18
- useConfig: jest.fn(() => ({
19
- defaultCurrency: 'USD',
20
- showEditBillButton: true,
21
- })),
22
- useDebounce: jest.fn((value) => value),
23
- useLayoutType: jest.fn(() => 'desktop'),
24
- isDesktop: jest.fn(() => true),
25
- }));
9
+ const mockUseConfig = jest.mocked(useConfig<BillingConfig>);
10
+ const mockShowModal = jest.mocked(showModal);
26
11
 
27
12
  jest.mock('../helpers', () => ({
28
13
  convertToCurrency: jest.fn((price) => `USD ${price}`),
29
14
  }));
30
15
 
31
16
  describe('InvoiceTable', () => {
32
- const mockT = jest.fn((key) => key);
33
-
34
- beforeEach(() => {
35
- (useTranslation as jest.Mock).mockReturnValue({ t: mockT, i18n: { language: 'en' } });
36
- jest.useFakeTimers();
37
- });
38
-
39
- afterEach(() => {
40
- jest.useRealTimers();
41
- });
42
-
43
- const bill: MappedBill = {
17
+ const defaultBill: MappedBill = {
44
18
  uuid: 'bill-uuid',
45
19
  id: 123,
46
20
  patientUuid: 'patient-uuid',
@@ -95,57 +69,294 @@ describe('InvoiceTable', () => {
95
69
  tenderedAmount: 300,
96
70
  };
97
71
 
98
- it('renders the table and displays line items correctly', () => {
99
- render(<InvoiceTable bill={bill} />);
72
+ beforeEach(() => {
73
+ mockUseConfig.mockReturnValue({
74
+ ...getDefaultsFromConfigSchema(configSchema),
75
+ defaultCurrency: 'USD',
76
+ });
77
+ });
78
+
79
+ it('should render table headers correctly', () => {
80
+ render(<InvoiceTable bill={defaultBill} />);
81
+
82
+ expect(screen.getByText(/line items/i)).toBeInTheDocument();
83
+ expect(screen.getByText(/items to be billed/i)).toBeInTheDocument();
84
+ expect(screen.getByRole('columnheader', { name: /number/i })).toBeInTheDocument();
85
+ expect(screen.getByRole('columnheader', { name: /bill item/i })).toBeInTheDocument();
86
+ expect(screen.getByRole('columnheader', { name: /bill code/i })).toBeInTheDocument();
87
+ expect(screen.getByRole('columnheader', { name: /status/i })).toBeInTheDocument();
88
+ expect(screen.getByRole('columnheader', { name: /quantity/i })).toBeInTheDocument();
89
+ expect(screen.getByRole('columnheader', { name: /price/i })).toBeInTheDocument();
90
+ expect(screen.getByRole('columnheader', { name: /total/i })).toBeInTheDocument();
91
+ });
92
+
93
+ it('should render line items correctly', () => {
94
+ render(<InvoiceTable bill={defaultBill} />);
100
95
 
101
96
  expect(screen.getByText('Item 1')).toBeInTheDocument();
102
97
  expect(screen.getByText('Item 2')).toBeInTheDocument();
103
98
  expect(screen.getByTestId('receipt-number-0')).toHaveTextContent('12345');
99
+ expect(screen.getByTestId('receipt-number-1')).toHaveTextContent('12345');
100
+ });
101
+
102
+ it('should display loading skeleton when bill is loading', () => {
103
+ render(<InvoiceTable bill={defaultBill} isLoadingBill={true} />);
104
+
105
+ expect(screen.getByTestId('loader')).toBeInTheDocument();
106
+ expect(screen.queryByText(/line items/i)).not.toBeInTheDocument();
104
107
  });
105
108
 
106
- it('renders the edit button and calls showModal when clicked', () => {
107
- render(<InvoiceTable bill={bill} />);
109
+ it('should display payment status for each line item', () => {
110
+ render(<InvoiceTable bill={defaultBill} />);
111
+
112
+ expect(screen.getByText('PAID')).toBeInTheDocument();
113
+ expect(screen.getByText('PENDING')).toBeInTheDocument();
114
+ });
115
+
116
+ it('should display correct quantities', () => {
117
+ render(<InvoiceTable bill={defaultBill} />);
118
+
119
+ // Item 1 has quantity 1, Item 2 has quantity 2
120
+ const rows = screen.getAllByRole('row');
121
+ expect(rows).toHaveLength(3); // Header row + 2 data rows
122
+ });
123
+
124
+ it('should calculate and display line item totals correctly', () => {
125
+ const billWithCalculation: MappedBill = {
126
+ ...defaultBill,
127
+ lineItems: [
128
+ {
129
+ uuid: '1',
130
+ item: 'Service A',
131
+ paymentStatus: 'PENDING',
132
+ quantity: 3,
133
+ price: 100,
134
+ display: '',
135
+ voided: false,
136
+ voidReason: '',
137
+ billableService: 'Service A',
138
+ priceName: '',
139
+ priceUuid: '',
140
+ lineItemOrder: 0,
141
+ resourceVersion: '',
142
+ },
143
+ ],
144
+ };
145
+
146
+ render(<InvoiceTable bill={billWithCalculation} />);
147
+
148
+ // Total should be 3 * 100 = 300
149
+ expect(screen.getByText('USD 300')).toBeInTheDocument();
150
+ });
151
+
152
+ it('should render edit buttons for all line items', () => {
153
+ render(<InvoiceTable bill={defaultBill} />);
154
+
155
+ const editButton1 = screen.getByTestId('edit-button-1');
156
+ const editButton2 = screen.getByTestId('edit-button-2');
157
+
158
+ expect(editButton1).toBeInTheDocument();
159
+ expect(editButton2).toBeInTheDocument();
160
+ });
161
+
162
+ it('should open edit modal when edit button is clicked', async () => {
163
+ const user = userEvent.setup();
164
+ render(<InvoiceTable bill={defaultBill} />);
108
165
 
109
166
  const editButton = screen.getByTestId('edit-button-1');
110
- fireEvent.click(editButton);
111
- expect(showModal).toHaveBeenCalledWith('edit-bill-line-item-dialog', expect.anything());
167
+ await user.click(editButton);
168
+
169
+ expect(mockShowModal).toHaveBeenCalledTimes(1);
170
+ expect(mockShowModal).toHaveBeenCalledWith(
171
+ 'edit-bill-line-item-modal',
172
+ expect.objectContaining({
173
+ bill: defaultBill,
174
+ item: expect.objectContaining({ uuid: '1' }),
175
+ }),
176
+ );
112
177
  });
113
178
 
114
- it('displays a skeleton loader when the bill is loading', () => {
115
- render(<InvoiceTable bill={bill} isLoadingBill={true} />);
179
+ it('should filter line items based on search term', async () => {
180
+ const user = userEvent.setup();
181
+ render(<InvoiceTable bill={defaultBill} />);
116
182
 
117
- expect(screen.getByTestId('loader')).toBeInTheDocument();
183
+ const searchInput = screen.getByPlaceholderText(/search this table/i);
184
+ await user.type(searchInput, 'Item 2');
185
+
186
+ await waitFor(() => {
187
+ expect(screen.queryByText('Item 1')).not.toBeInTheDocument();
188
+ expect(screen.getByText('Item 2')).toBeInTheDocument();
189
+ });
118
190
  });
119
191
 
120
- it('filters line items based on the search term', () => {
121
- render(<InvoiceTable bill={bill} />);
122
- const searchInput = screen.getByPlaceholderText('searchThisTable'); //
192
+ it('should show all items when search is cleared', async () => {
193
+ const user = userEvent.setup();
194
+ render(<InvoiceTable bill={defaultBill} />);
123
195
 
124
- fireEvent.change(searchInput, { target: { value: 'Item 2' } });
196
+ const searchInput = screen.getByPlaceholderText(/search this table/i);
125
197
 
126
- expect(screen.queryByText('Item 1')).not.toBeInTheDocument();
127
- expect(screen.getByText('Item 2')).toBeInTheDocument();
198
+ // Search for Item 1
199
+ await user.type(searchInput, 'Item 1');
200
+
201
+ await waitFor(() => {
202
+ expect(screen.queryByText('Item 2')).not.toBeInTheDocument();
203
+ });
204
+
205
+ // Clear search
206
+ await user.clear(searchInput);
207
+
208
+ await waitFor(() => {
209
+ expect(screen.getByText('Item 1')).toBeInTheDocument();
210
+ expect(screen.getByText('Item 2')).toBeInTheDocument();
211
+ });
128
212
  });
129
213
 
130
- it('correctly handles row selection', () => {
131
- const onSelectItem = jest.fn();
132
- render(<InvoiceTable bill={bill} onSelectItem={onSelectItem} />);
214
+ it('should display empty state when no line items exist', () => {
215
+ const emptyBill: MappedBill = {
216
+ ...defaultBill,
217
+ lineItems: [],
218
+ };
133
219
 
134
- const checkboxes = screen.getAllByLabelText('Select row');
135
- fireEvent.click(checkboxes[0]);
220
+ render(<InvoiceTable bill={emptyBill} />);
136
221
 
137
- expect(onSelectItem).toHaveBeenCalledWith([bill.lineItems[0]]);
222
+ expect(screen.getByText(/no matching items to display/i)).toBeInTheDocument();
223
+ expect(screen.getByText(/check the filters above/i)).toBeInTheDocument();
138
224
  });
139
225
 
140
- it('resets isRedirecting to false after timeout', () => {
141
- render(<InvoiceTable bill={bill} />);
226
+ it('should show empty state when search has no results', async () => {
227
+ const user = userEvent.setup();
228
+ render(<InvoiceTable bill={defaultBill} />);
229
+
230
+ const searchInput = screen.getByPlaceholderText(/search this table/i);
231
+ await user.type(searchInput, 'NonexistentItem');
142
232
 
143
- const button = screen.getByTestId('edit-button-1');
144
- fireEvent.click(button);
145
- act(() => {
146
- jest.advanceTimersByTime(1000);
233
+ await waitFor(() => {
234
+ expect(screen.getByText(/no matching items to display/i)).toBeInTheDocument();
235
+ expect(screen.getByText(/check the filters above/i)).toBeInTheDocument();
147
236
  });
237
+ });
238
+
239
+ it('should handle line items with zero price', () => {
240
+ const billWithZeroPrice: MappedBill = {
241
+ ...defaultBill,
242
+ lineItems: [
243
+ {
244
+ uuid: '1',
245
+ item: 'Free Service',
246
+ paymentStatus: 'PAID',
247
+ quantity: 1,
248
+ price: 0,
249
+ display: '',
250
+ voided: false,
251
+ voidReason: '',
252
+ billableService: 'Free Service',
253
+ priceName: '',
254
+ priceUuid: '',
255
+ lineItemOrder: 0,
256
+ resourceVersion: '',
257
+ },
258
+ ],
259
+ };
260
+
261
+ render(<InvoiceTable bill={billWithZeroPrice} />);
262
+
263
+ // USD 0 appears for both price and total
264
+ expect(screen.getAllByText('USD 0').length).toBeGreaterThan(0);
265
+ });
266
+
267
+ it('should handle line items with zero quantity', () => {
268
+ const billWithZeroQuantity: MappedBill = {
269
+ ...defaultBill,
270
+ lineItems: [
271
+ {
272
+ uuid: '1',
273
+ item: 'Service',
274
+ paymentStatus: 'PENDING',
275
+ quantity: 0,
276
+ price: 100,
277
+ display: '',
278
+ voided: false,
279
+ voidReason: '',
280
+ billableService: 'Service',
281
+ priceName: '',
282
+ priceUuid: '',
283
+ lineItemOrder: 0,
284
+ resourceVersion: '',
285
+ },
286
+ ],
287
+ };
288
+
289
+ render(<InvoiceTable bill={billWithZeroQuantity} />);
290
+
291
+ // Total should be 0 * 100 = 0
292
+ expect(screen.getByText('USD 0')).toBeInTheDocument();
293
+ });
294
+
295
+ it('should use billableService name when available, otherwise use item name', () => {
296
+ const billWithBillableService: MappedBill = {
297
+ ...defaultBill,
298
+ lineItems: [
299
+ {
300
+ uuid: '1',
301
+ item: 'Item Name',
302
+ billableService: 'Billable Service Name',
303
+ paymentStatus: 'PAID',
304
+ quantity: 1,
305
+ price: 100,
306
+ display: '',
307
+ voided: false,
308
+ voidReason: '',
309
+ priceName: '',
310
+ priceUuid: '',
311
+ lineItemOrder: 0,
312
+ resourceVersion: '',
313
+ },
314
+ {
315
+ uuid: '2',
316
+ item: 'Item Without Billable',
317
+ billableService: '',
318
+ paymentStatus: 'PENDING',
319
+ quantity: 1,
320
+ price: 200,
321
+ display: '',
322
+ voided: false,
323
+ voidReason: '',
324
+ priceName: '',
325
+ priceUuid: '',
326
+ lineItemOrder: 1,
327
+ resourceVersion: '',
328
+ },
329
+ ],
330
+ };
331
+
332
+ render(<InvoiceTable bill={billWithBillableService} />);
333
+
334
+ expect(screen.getByText('Billable Service Name')).toBeInTheDocument();
335
+ expect(screen.getByText('Item Without Billable')).toBeInTheDocument();
336
+ });
337
+
338
+ it('should display line item numbers starting from 1', () => {
339
+ render(<InvoiceTable bill={defaultBill} />);
340
+
341
+ // Check the table body for numbered rows
342
+ const rows = screen.getAllByRole('row');
343
+ // First row is header, so data rows start at index 1
344
+ expect(rows.length).toBeGreaterThan(2);
345
+ });
346
+
347
+ it('should pass correct currency to convertToCurrency helper', () => {
348
+ render(<InvoiceTable bill={defaultBill} />);
349
+
350
+ // Verify prices are formatted with USD - multiple occurrences expected
351
+ expect(screen.getAllByText('USD 100').length).toBeGreaterThan(0);
352
+ expect(screen.getAllByText('USD 200').length).toBeGreaterThan(0);
353
+ });
354
+
355
+ it('should render search input in expanded state', () => {
356
+ render(<InvoiceTable bill={defaultBill} />);
148
357
 
149
- expect(button).not.toBeDisabled();
358
+ const searchInput = screen.getByPlaceholderText(/search this table/i);
359
+ expect(searchInput).toBeInTheDocument();
360
+ expect(searchInput).toBeVisible();
150
361
  });
151
362
  });
@@ -4,15 +4,15 @@ import { Printer } from '@carbon/react/icons';
4
4
  import { useParams } from 'react-router-dom';
5
5
  import { useReactToPrint } from 'react-to-print';
6
6
  import { useTranslation } from 'react-i18next';
7
- import { ExtensionSlot, useConfig, usePatient } from '@openmrs/esm-framework';
8
- import { ErrorState } from '@openmrs/esm-patient-common-lib';
9
- import { convertToCurrency } from '../helpers';
10
- import { type LineItem } from '../types';
11
- import { useBill } from '../billing.resource';
7
+ import { ExtensionSlot, showSnackbar, useConfig, usePatient } from '@openmrs/esm-framework';
12
8
  import InvoiceTable from './invoice-table.component';
13
9
  import Payments from './payments/payments.component';
14
10
  import PrintReceipt from './printable-invoice/print-receipt.component';
15
11
  import PrintableInvoice from './printable-invoice/printable-invoice.component';
12
+ import { ErrorState } from '@openmrs/esm-patient-common-lib';
13
+ import { convertToCurrency } from '../helpers';
14
+ import { useBill, useDefaultFacility } from '../billing.resource';
15
+ import type { BillingConfig } from '../config-schema';
16
16
  import styles from './invoice.scss';
17
17
 
18
18
  interface InvoiceDetailsProps {
@@ -22,25 +22,20 @@ interface InvoiceDetailsProps {
22
22
 
23
23
  const Invoice: React.FC = () => {
24
24
  const { t } = useTranslation();
25
+ const { data } = useDefaultFacility();
25
26
  const { billUuid, patientUuid } = useParams();
26
27
  const { patient, isLoading: isLoadingPatient } = usePatient(patientUuid);
27
28
  const { bill, isLoading: isLoadingBill, error, mutate } = useBill(billUuid);
28
29
  const [isPrinting, setIsPrinting] = useState(false);
29
- const [selectedLineItems, setSelectedLineItems] = useState<LineItem[]>([]);
30
30
  const componentRef = useRef<HTMLDivElement>(null);
31
31
  const onBeforeGetContentResolve = useRef<(() => void) | null>(null);
32
- const { defaultCurrency } = useConfig();
33
- const handleSelectItem = (lineItems: LineItem[]) => {
34
- setSelectedLineItems(lineItems);
35
- };
32
+ const { defaultCurrency } = useConfig<BillingConfig>();
36
33
 
37
34
  const handleAfterPrint = useCallback(() => {
38
35
  onBeforeGetContentResolve.current = null;
39
36
  setIsPrinting(false);
40
37
  }, []);
41
38
 
42
- const reactToPrintContent = useCallback(() => componentRef.current, []);
43
-
44
39
  const handleOnBeforeGetContent = useCallback(() => {
45
40
  return new Promise<void>((resolve) => {
46
41
  if (patient && bill) {
@@ -51,11 +46,17 @@ const Invoice: React.FC = () => {
51
46
  }, [bill, patient]);
52
47
 
53
48
  const handlePrint = useReactToPrint({
54
- content: reactToPrintContent,
49
+ contentRef: componentRef,
55
50
  documentTitle: `Invoice ${bill?.receiptNumber} - ${patient?.name?.[0]?.given?.join(' ')} ${patient?.name?.[0].family}`,
56
- onBeforeGetContent: handleOnBeforeGetContent,
51
+ onBeforePrint: handleOnBeforeGetContent,
57
52
  onAfterPrint: handleAfterPrint,
58
- removeAfterPrint: true,
53
+ preserveAfterPrint: false,
54
+ onPrintError: (_, error) =>
55
+ showSnackbar({
56
+ title: t('errorPrintingInvoice', 'Error printing invoice'),
57
+ kind: 'error',
58
+ subtitle: error.message,
59
+ }),
59
60
  });
60
61
 
61
62
  useEffect(() => {
@@ -64,11 +65,14 @@ const Invoice: React.FC = () => {
64
65
  }
65
66
  }, [isPrinting]);
66
67
 
67
- useEffect(() => {
68
- const unPaidLineItems = bill?.lineItems?.filter((item) => item.paymentStatus === 'PENDING') ?? [];
69
- setSelectedLineItems(unPaidLineItems);
70
- }, [bill?.lineItems]);
71
-
68
+ // Do not remove this comment. Adds the translation keys for the invoice details
69
+ /**
70
+ * t('totalAmount', 'Total amount')
71
+ * t('amountTendered', 'Amount tendered')
72
+ * t('invoiceNumber', 'Invoice #')
73
+ * t('dateAndTime', 'Date and time')
74
+ * t('invoiceStatus', 'Invoice status')
75
+ */
72
76
  const invoiceDetails = {
73
77
  'Total Amount': convertToCurrency(bill?.totalAmount, defaultCurrency),
74
78
  'Amount Tendered': convertToCurrency(bill?.tenderedAmount, defaultCurrency),
@@ -77,14 +81,12 @@ const Invoice: React.FC = () => {
77
81
  'Invoice Status': bill?.status,
78
82
  };
79
83
 
80
- if (isLoadingPatient && isLoadingBill) {
84
+ if (isLoadingPatient || isLoadingBill) {
81
85
  return (
82
86
  <div className={styles.invoiceContainer}>
83
87
  <InlineLoading
84
88
  className={styles.loader}
85
- status="active"
86
- iconDescription="Loading"
87
- description="Loading patient header..."
89
+ description={`${t('loadingBillInfo', 'Loading bill information')}...`}
88
90
  />
89
91
  </div>
90
92
  );
@@ -109,10 +111,10 @@ const Invoice: React.FC = () => {
109
111
  </section>
110
112
  <div>
111
113
  <Button
112
- disabled={isPrinting}
114
+ disabled={isPrinting || isLoadingPatient || isLoadingBill}
113
115
  onClick={handlePrint}
114
116
  renderIcon={(props) => <Printer size={24} {...props} />}
115
- iconDescription="Print bill"
117
+ iconDescription={t('printBill', 'Print bill')}
116
118
  size="md">
117
119
  {t('printBill', 'Print bill')}
118
120
  </Button>
@@ -120,20 +122,25 @@ const Invoice: React.FC = () => {
120
122
  </div>
121
123
  </div>
122
124
 
123
- <InvoiceTable bill={bill} isLoadingBill={isLoadingBill} onSelectItem={handleSelectItem} />
124
- <Payments bill={bill} mutate={mutate} selectedLineItems={selectedLineItems} />
125
-
126
- <div className={styles.printContainer} ref={componentRef}>
127
- {isPrinting && <PrintableInvoice bill={bill} patient={patient} isLoading={isLoadingPatient} />}
125
+ <div className={styles.invoiceContent}>
126
+ <InvoiceTable bill={bill} isLoadingBill={isLoadingBill} />
127
+ <Payments bill={bill} mutate={mutate} />
128
128
  </div>
129
+
130
+ {bill && patient && (
131
+ <div className={styles.printContainer}>
132
+ <PrintableInvoice bill={bill} patient={patient} defaultFacility={data} componentRef={componentRef} />
133
+ </div>
134
+ )}
129
135
  </div>
130
136
  );
131
137
  };
132
138
 
133
139
  function InvoiceDetails({ label, value }: InvoiceDetailsProps) {
140
+ const { t } = useTranslation();
134
141
  return (
135
142
  <div>
136
- <h1 className={styles.label}>{label}</h1>
143
+ <h1 className={styles.label}>{t(label)}</h1>
137
144
  <span className={styles.value}>{value}</span>
138
145
  </div>
139
146
  );
@@ -73,21 +73,28 @@
73
73
  flex-direction: row;
74
74
  }
75
75
 
76
+ .invoiceContent {
77
+ margin: layout.$spacing-05;
78
+ }
79
+
76
80
  .billDetail {
77
81
  font-weight: bold;
78
82
  color: colors.$cool-gray-90;
79
83
  }
80
84
 
81
- @media screen {
82
- .printContainer {
83
- background-color: colors.$white;
84
- display: none;
85
+ .printContainer {
86
+ background-color: colors.$white;
87
+ display: none;
88
+
89
+ @media print {
90
+ display: block !important;
85
91
  }
86
92
  }
87
93
 
88
94
  @media print {
89
95
  html,
90
96
  body {
97
+ display: block !important;
91
98
  background-color: colors.$white !important;
92
99
  }
93
100
  }