@openmrs/esm-billing-app 1.1.2-pre.9 → 1.2.0

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 (390) hide show
  1. package/.turbo/cache/31f1dfc7f71601df-meta.json +1 -0
  2. package/.turbo/cache/31f1dfc7f71601df.tar.zst +0 -0
  3. package/.turbo/turbo-build.log +13 -42
  4. package/__mocks__/bills.mock.ts +3 -2
  5. package/dist/1480.js +1 -0
  6. package/dist/1480.js.map +1 -0
  7. package/dist/1564.js +1 -0
  8. package/dist/1564.js.map +1 -0
  9. package/dist/1578.js +1 -0
  10. package/dist/1578.js.map +1 -0
  11. package/dist/1646.js +1 -0
  12. package/dist/1646.js.map +1 -0
  13. package/dist/1869.js +1 -0
  14. package/dist/1869.js.map +1 -0
  15. package/dist/1877.js +1 -0
  16. package/dist/1877.js.map +1 -0
  17. package/dist/1899.js +1 -0
  18. package/dist/1899.js.map +1 -0
  19. package/dist/196.js +2 -0
  20. package/dist/196.js.map +1 -0
  21. package/dist/2250.js +43 -0
  22. package/dist/2250.js.map +1 -0
  23. package/dist/2269.js +1 -0
  24. package/dist/2269.js.map +1 -0
  25. package/dist/2317.js +1 -0
  26. package/dist/2317.js.map +1 -0
  27. package/dist/2416.js +1 -0
  28. package/dist/2416.js.map +1 -0
  29. package/dist/2489.js +1 -0
  30. package/dist/2489.js.map +1 -0
  31. package/dist/282.js +1 -0
  32. package/dist/282.js.map +1 -0
  33. package/dist/2881.js +1 -0
  34. package/dist/2881.js.map +1 -0
  35. package/dist/2997.js +1 -0
  36. package/dist/2997.js.map +1 -0
  37. package/dist/3378.js +1 -0
  38. package/dist/3378.js.map +1 -0
  39. package/dist/3379.js +1 -0
  40. package/dist/3379.js.map +1 -0
  41. package/dist/3784.js +1 -0
  42. package/dist/3784.js.map +1 -0
  43. package/dist/3963.js +1 -0
  44. package/dist/3963.js.map +1 -0
  45. package/dist/4106.js +1 -0
  46. package/dist/4106.js.map +1 -0
  47. package/dist/4111.js +1 -0
  48. package/dist/4111.js.map +1 -0
  49. package/dist/434.js +1 -0
  50. package/dist/434.js.map +1 -0
  51. package/dist/4348.js +1 -0
  52. package/dist/4348.js.map +1 -0
  53. package/dist/4383.js +1 -0
  54. package/dist/4383.js.map +1 -0
  55. package/dist/4658.js +1 -0
  56. package/dist/4658.js.map +1 -0
  57. package/dist/4870.js +1 -0
  58. package/dist/4870.js.map +1 -0
  59. package/dist/4928.js +1 -0
  60. package/dist/4928.js.map +1 -0
  61. package/dist/5098.js +1 -0
  62. package/dist/5098.js.map +1 -0
  63. package/dist/5117.js +1 -0
  64. package/dist/5117.js.map +1 -0
  65. package/dist/5132.js +1 -0
  66. package/dist/5132.js.map +1 -0
  67. package/dist/5145.js +1 -0
  68. package/dist/5145.js.map +1 -0
  69. package/dist/5390.js +1 -0
  70. package/dist/5390.js.map +1 -0
  71. package/dist/5503.js +1 -0
  72. package/dist/5503.js.map +1 -0
  73. package/dist/556.js +1 -0
  74. package/dist/556.js.map +1 -0
  75. package/dist/5644.js +1 -0
  76. package/dist/5644.js.map +1 -0
  77. package/dist/5898.js +1 -0
  78. package/dist/5898.js.map +1 -0
  79. package/dist/5940.js +1 -0
  80. package/dist/5940.js.map +1 -0
  81. package/dist/6047.js +1 -0
  82. package/dist/6047.js.map +1 -0
  83. package/dist/6237.js +1 -0
  84. package/dist/6237.js.map +1 -0
  85. package/dist/6362.js +1 -0
  86. package/dist/6362.js.map +1 -0
  87. package/dist/6371.js +1 -0
  88. package/dist/6371.js.map +1 -0
  89. package/dist/6377.js +1 -0
  90. package/dist/6377.js.map +1 -0
  91. package/dist/6444.js +1 -0
  92. package/dist/6444.js.map +1 -0
  93. package/dist/6508.js +1 -0
  94. package/dist/6508.js.map +1 -0
  95. package/dist/6594.js +1 -0
  96. package/dist/6594.js.map +1 -0
  97. package/dist/6724.js +1 -0
  98. package/dist/6724.js.map +1 -0
  99. package/dist/6904.js +1 -0
  100. package/dist/6904.js.map +1 -0
  101. package/dist/7045.js +1 -0
  102. package/dist/7045.js.map +1 -0
  103. package/dist/7175.js +1 -0
  104. package/dist/7175.js.map +1 -0
  105. package/dist/7182.js +1 -0
  106. package/dist/7182.js.map +1 -0
  107. package/dist/7247.js +1 -0
  108. package/dist/7247.js.map +1 -0
  109. package/dist/7742.js +1 -0
  110. package/dist/7742.js.map +1 -0
  111. package/dist/7912.js +1 -0
  112. package/dist/7912.js.map +1 -0
  113. package/dist/8358.js +1 -0
  114. package/dist/8358.js.map +1 -0
  115. package/dist/8359.js +1 -0
  116. package/dist/8359.js.map +1 -0
  117. package/dist/8695.js +1 -0
  118. package/dist/8695.js.map +1 -0
  119. package/dist/903.js +1 -0
  120. package/dist/903.js.map +1 -0
  121. package/dist/9072.js +1 -0
  122. package/dist/9072.js.map +1 -0
  123. package/dist/9414.js +1 -0
  124. package/dist/9414.js.map +1 -0
  125. package/dist/9655.js +11 -0
  126. package/dist/9655.js.map +1 -0
  127. package/dist/9806.js +1 -0
  128. package/dist/9806.js.map +1 -0
  129. package/dist/990.js +1 -0
  130. package/dist/990.js.map +1 -0
  131. package/dist/main.js +17 -2
  132. package/dist/main.js.map +1 -1
  133. package/dist/openmrs-esm-billing-app.js +6 -1
  134. package/dist/openmrs-esm-billing-app.js.buildmanifest.json +643 -436
  135. package/dist/openmrs-esm-billing-app.js.map +1 -1
  136. package/dist/routes.json +1 -1
  137. package/e2e/commands/billing-operations.ts +21 -0
  138. package/e2e/commands/types.ts +9 -1
  139. package/e2e/pages/discounts-page.ts +75 -0
  140. package/e2e/pages/index.ts +1 -0
  141. package/e2e/pages/invoice-page.ts +7 -7
  142. package/e2e/specs/bill-discounts.spec.ts +255 -0
  143. package/e2e/specs/billing-dashboard.spec.ts +3 -3
  144. package/e2e/specs/billing-patient-chart.spec.ts +2 -2
  145. package/package.json +13 -22
  146. package/rspack.config.js +1 -0
  147. package/src/bill-history/bill-action-menu.component.tsx +20 -2
  148. package/src/bill-history/bill-history.test.tsx +23 -22
  149. package/src/bill-item-actions/edit-bill-item.modal.tsx +1 -1
  150. package/src/bill-item-actions/edit-bill-item.test.tsx +29 -27
  151. package/src/billable-services/billable-service-form/billable-service-form.test.tsx +74 -73
  152. package/src/billable-services/billable-services-home.component.tsx +4 -2
  153. package/src/billable-services/billable-services.test.tsx +8 -7
  154. package/src/billable-services/dashboard/dashboard.test.tsx +3 -2
  155. package/src/billable-services-admin-card-link.test.tsx +2 -1
  156. package/src/billing-dashboard/billing-dashboard.test.tsx +19 -3
  157. package/src/billing-form/billing-checkin-form.component.tsx +7 -3
  158. package/src/billing-form/billing-checkin-form.test.tsx +22 -21
  159. package/src/billing-form/billing-form.resource.test.ts +7 -6
  160. package/src/billing-form/billing-form.test.tsx +77 -40
  161. package/src/billing-form/billing-form.workspace.tsx +25 -6
  162. package/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +6 -2
  163. package/src/billing.resource.test.ts +43 -41
  164. package/src/billing.resource.ts +65 -16
  165. package/src/bills-table/bills-table.component.tsx +15 -4
  166. package/src/bills-table/bills-table.test.tsx +72 -71
  167. package/src/config-schema.ts +0 -7
  168. package/src/discounts/admin/discount-requests-left-panel-link.component.tsx +43 -0
  169. package/src/discounts/admin/discount-requests.component.tsx +316 -0
  170. package/src/discounts/admin/discount-requests.scss +133 -0
  171. package/src/discounts/admin/discount-requests.test.tsx +104 -0
  172. package/src/discounts/admin/review-bill-discounts/bill-line-items-table/bill-line-items-table.component.tsx +42 -0
  173. package/src/discounts/admin/review-bill-discounts/bill-line-items-table/bill-line-items-table.scss +76 -0
  174. package/src/discounts/admin/review-bill-discounts/bill-payments-table/bill-payments-table.component.tsx +50 -0
  175. package/src/discounts/admin/review-bill-discounts/bill-payments-table/bill-payments-table.scss +63 -0
  176. package/src/discounts/admin/review-bill-discounts/bill-receipt-rail/bill-receipt-rail.component.tsx +73 -0
  177. package/src/discounts/admin/review-bill-discounts/bill-receipt-rail/bill-receipt-rail.scss +54 -0
  178. package/src/discounts/admin/review-bill-discounts/bill-totals-summary/bill-totals-summary.component.tsx +95 -0
  179. package/src/discounts/admin/review-bill-discounts/bill-totals-summary/bill-totals-summary.scss +128 -0
  180. package/src/discounts/admin/review-bill-discounts/discount-card/discount-card.component.tsx +158 -0
  181. package/src/discounts/admin/review-bill-discounts/discount-card/discount-card.scss +164 -0
  182. package/src/discounts/admin/review-bill-discounts/discount-review-stack/discount-review-stack.component.tsx +86 -0
  183. package/src/discounts/admin/review-bill-discounts/discount-review-stack/discount-review-stack.scss +40 -0
  184. package/src/discounts/admin/review-bill-discounts/review-bill-discounts.modal.scss +14 -0
  185. package/src/discounts/admin/review-bill-discounts/review-bill-discounts.modal.test.tsx +153 -0
  186. package/src/discounts/admin/review-bill-discounts/review-bill-discounts.modal.tsx +167 -0
  187. package/src/discounts/admin/review-bill-discounts/review-bill-discounts.utils.ts +42 -0
  188. package/src/discounts/discounts-table.component.tsx +109 -0
  189. package/src/discounts/discounts-table.scss +37 -0
  190. package/src/discounts/discounts-table.test.tsx +67 -0
  191. package/src/discounts/discounts.resource.ts +71 -0
  192. package/src/discounts/request-discount.modal.scss +88 -0
  193. package/src/discounts/request-discount.modal.test.tsx +161 -0
  194. package/src/discounts/request-discount.modal.tsx +253 -0
  195. package/src/index.ts +52 -21
  196. package/src/invoice/invoice-table.component.tsx +116 -18
  197. package/src/invoice/invoice-table.test.tsx +165 -13
  198. package/src/invoice/invoice.component.tsx +111 -7
  199. package/src/invoice/invoice.test.tsx +366 -66
  200. package/src/invoice/line-item-action-menu.component.tsx +31 -1
  201. package/src/invoice/payments/payment-form/payment-form.test.tsx +20 -19
  202. package/src/invoice/payments/payment-history/payment-history.test.tsx +13 -10
  203. package/src/invoice/payments/payments.component.tsx +20 -6
  204. package/src/invoice/payments/payments.test.tsx +88 -23
  205. package/src/invoice/printable-invoice/print-receipt.test.tsx +10 -28
  206. package/src/invoice/printable-invoice/printable-footer.test.tsx +5 -4
  207. package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +3 -3
  208. package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +26 -11
  209. package/src/invoice/printable-invoice/printable-invoice.component.tsx +38 -15
  210. package/src/left-panel-link.test.tsx +3 -3
  211. package/src/metrics-cards/metrics-cards.test.tsx +11 -10
  212. package/src/modal/delete-bill-confirmation.modal.test.tsx +134 -0
  213. package/src/modal/delete-bill-confirmation.modal.tsx +98 -0
  214. package/src/modal/delete-line-item-confirmation.modal.test.tsx +11 -9
  215. package/src/modal/finalize-bill-confirmation.modal.test.tsx +10 -8
  216. package/src/modal/require-payment-modal.test.tsx +12 -11
  217. package/src/payment-status-tag/payment-status-tag.component.tsx +50 -0
  218. package/src/payment-status-tag/payment-status-tag.scss +6 -0
  219. package/src/payment-status-tag/payment-status-tag.test.tsx +113 -0
  220. package/src/refunds/admin/refund-requests-left-panel-link.component.tsx +43 -0
  221. package/src/refunds/admin/refund-requests.component.tsx +324 -0
  222. package/src/refunds/admin/refund-requests.scss +133 -0
  223. package/src/refunds/admin/refund-requests.test.tsx +99 -0
  224. package/src/refunds/admin/review-bill-refunds/bill-line-items-table/bill-line-items-table.component.tsx +42 -0
  225. package/src/refunds/admin/review-bill-refunds/bill-line-items-table/bill-line-items-table.scss +76 -0
  226. package/src/refunds/admin/review-bill-refunds/bill-payments-table/bill-payments-table.component.tsx +50 -0
  227. package/src/refunds/admin/review-bill-refunds/bill-payments-table/bill-payments-table.scss +63 -0
  228. package/src/refunds/admin/review-bill-refunds/bill-receipt-rail/bill-receipt-rail.component.tsx +84 -0
  229. package/src/refunds/admin/review-bill-refunds/bill-receipt-rail/bill-receipt-rail.scss +54 -0
  230. package/src/refunds/admin/review-bill-refunds/bill-totals-summary/bill-totals-summary.component.tsx +83 -0
  231. package/src/refunds/admin/review-bill-refunds/bill-totals-summary/bill-totals-summary.scss +65 -0
  232. package/src/refunds/admin/review-bill-refunds/refund-card/refund-card.component.tsx +170 -0
  233. package/src/refunds/admin/review-bill-refunds/refund-card/refund-card.scss +155 -0
  234. package/src/refunds/admin/review-bill-refunds/refund-review-stack/refund-review-stack.component.tsx +86 -0
  235. package/src/refunds/admin/review-bill-refunds/refund-review-stack/refund-review-stack.scss +40 -0
  236. package/src/refunds/admin/review-bill-refunds/review-bill-refunds.modal.scss +14 -0
  237. package/src/refunds/admin/review-bill-refunds/review-bill-refunds.modal.test.tsx +313 -0
  238. package/src/refunds/admin/review-bill-refunds/review-bill-refunds.modal.tsx +188 -0
  239. package/src/refunds/admin/review-bill-refunds/review-bill-refunds.utils.ts +66 -0
  240. package/src/refunds/refunds-table.component.tsx +137 -0
  241. package/src/refunds/refunds-table.scss +37 -0
  242. package/src/refunds/refunds-table.test.tsx +105 -0
  243. package/src/refunds/refunds.resource.test.ts +44 -0
  244. package/src/refunds/refunds.resource.ts +42 -0
  245. package/src/refunds/refunds.types.test.ts +15 -0
  246. package/src/refunds/request-refund.modal.scss +84 -0
  247. package/src/refunds/request-refund.modal.test.tsx +204 -0
  248. package/src/refunds/request-refund.modal.tsx +218 -0
  249. package/src/routes.json +36 -2
  250. package/src/types/index.ts +116 -1
  251. package/src/visit-bills/visit-bills-panel.component.tsx +151 -0
  252. package/src/visit-bills/visit-bills-panel.scss +31 -0
  253. package/src/visit-bills/visit-bills-panel.test.tsx +113 -0
  254. package/tools/empty-module.ts +1 -0
  255. package/tools/setup-tests.ts +9 -9
  256. package/translations/am.json +154 -16
  257. package/translations/ar.json +154 -16
  258. package/translations/ar_SY.json +154 -16
  259. package/translations/bn.json +154 -16
  260. package/translations/cs.json +154 -16
  261. package/translations/de.json +154 -16
  262. package/translations/en.json +154 -16
  263. package/translations/en_US.json +154 -16
  264. package/translations/es.json +154 -16
  265. package/translations/es_MX.json +154 -16
  266. package/translations/fr.json +154 -16
  267. package/translations/he.json +154 -16
  268. package/translations/hi.json +154 -16
  269. package/translations/hi_IN.json +154 -16
  270. package/translations/id.json +154 -16
  271. package/translations/it.json +154 -16
  272. package/translations/ka.json +154 -16
  273. package/translations/km.json +154 -16
  274. package/translations/ku.json +154 -16
  275. package/translations/ky.json +154 -16
  276. package/translations/lg.json +154 -16
  277. package/translations/ne.json +154 -16
  278. package/translations/pl.json +154 -16
  279. package/translations/pt.json +154 -16
  280. package/translations/pt_BR.json +154 -16
  281. package/translations/qu.json +154 -16
  282. package/translations/ro_RO.json +154 -16
  283. package/translations/ru_RU.json +154 -16
  284. package/translations/si.json +154 -16
  285. package/translations/sq.json +154 -16
  286. package/translations/sw.json +154 -16
  287. package/translations/sw_KE.json +154 -16
  288. package/translations/tr.json +154 -16
  289. package/translations/tr_TR.json +154 -16
  290. package/translations/uk.json +154 -16
  291. package/translations/uz.json +154 -16
  292. package/translations/uz@Latn.json +154 -16
  293. package/translations/uz_UZ.json +154 -16
  294. package/translations/vi.json +154 -16
  295. package/translations/zh.json +154 -16
  296. package/translations/zh_CN.json +179 -41
  297. package/translations/zh_TW.json +154 -16
  298. package/tsconfig.json +3 -3
  299. package/vitest.config.js +28 -0
  300. package/.turbo/cache/4e30f71f570fc412-meta.json +0 -1
  301. package/.turbo/cache/4e30f71f570fc412.tar.zst +0 -0
  302. package/dist/1119.js +0 -1
  303. package/dist/1197.js +0 -1
  304. package/dist/1435.js +0 -1
  305. package/dist/1435.js.map +0 -1
  306. package/dist/1807.js +0 -1
  307. package/dist/1807.js.map +0 -1
  308. package/dist/2146.js +0 -1
  309. package/dist/2177.js +0 -2
  310. package/dist/2177.js.LICENSE.txt +0 -9
  311. package/dist/2177.js.map +0 -1
  312. package/dist/2690.js +0 -1
  313. package/dist/2704.js +0 -1
  314. package/dist/2704.js.map +0 -1
  315. package/dist/3002.js +0 -1
  316. package/dist/3002.js.map +0 -1
  317. package/dist/3041.js +0 -1
  318. package/dist/3041.js.map +0 -1
  319. package/dist/3099.js +0 -1
  320. package/dist/3184.js +0 -2
  321. package/dist/3184.js.LICENSE.txt +0 -14
  322. package/dist/3184.js.map +0 -1
  323. package/dist/3584.js +0 -1
  324. package/dist/4055.js +0 -1
  325. package/dist/4132.js +0 -1
  326. package/dist/4225.js +0 -1
  327. package/dist/4225.js.map +0 -1
  328. package/dist/4300.js +0 -1
  329. package/dist/4335.js +0 -1
  330. package/dist/439.js +0 -1
  331. package/dist/4618.js +0 -1
  332. package/dist/4652.js +0 -1
  333. package/dist/4944.js +0 -1
  334. package/dist/5173.js +0 -1
  335. package/dist/5241.js +0 -1
  336. package/dist/5422.js +0 -1
  337. package/dist/5422.js.map +0 -1
  338. package/dist/5442.js +0 -1
  339. package/dist/5661.js +0 -1
  340. package/dist/6022.js +0 -1
  341. package/dist/6404.js +0 -1
  342. package/dist/6404.js.map +0 -1
  343. package/dist/6468.js +0 -1
  344. package/dist/6540.js +0 -2
  345. package/dist/6540.js.LICENSE.txt +0 -9
  346. package/dist/6540.js.map +0 -1
  347. package/dist/6589.js +0 -1
  348. package/dist/6606.js +0 -1
  349. package/dist/6606.js.map +0 -1
  350. package/dist/6679.js +0 -1
  351. package/dist/6792.js +0 -1
  352. package/dist/6792.js.map +0 -1
  353. package/dist/6840.js +0 -1
  354. package/dist/6859.js +0 -1
  355. package/dist/7097.js +0 -1
  356. package/dist/7159.js +0 -1
  357. package/dist/723.js +0 -1
  358. package/dist/7255.js +0 -1
  359. package/dist/7255.js.map +0 -1
  360. package/dist/7617.js +0 -1
  361. package/dist/795.js +0 -1
  362. package/dist/8163.js +0 -1
  363. package/dist/8341.js +0 -2
  364. package/dist/8341.js.LICENSE.txt +0 -52
  365. package/dist/8341.js.map +0 -1
  366. package/dist/8349.js +0 -1
  367. package/dist/8371.js +0 -1
  368. package/dist/8421.js +0 -1
  369. package/dist/8421.js.map +0 -1
  370. package/dist/8618.js +0 -1
  371. package/dist/890.js +0 -1
  372. package/dist/9214.js +0 -1
  373. package/dist/9538.js +0 -1
  374. package/dist/9569.js +0 -1
  375. package/dist/961.js +0 -2
  376. package/dist/961.js.LICENSE.txt +0 -19
  377. package/dist/961.js.map +0 -1
  378. package/dist/986.js +0 -1
  379. package/dist/9879.js +0 -1
  380. package/dist/9895.js +0 -1
  381. package/dist/9900.js +0 -1
  382. package/dist/9913.js +0 -1
  383. package/dist/main.js.LICENSE.txt +0 -62
  384. package/src/billable-services/bill-waiver/bill-selection.component.tsx +0 -76
  385. package/src/billable-services/bill-waiver/bill-waiver-form.component.tsx +0 -107
  386. package/src/billable-services/bill-waiver/bill-waiver-form.scss +0 -34
  387. package/src/billable-services/bill-waiver/bill-waiver.component.tsx +0 -34
  388. package/src/billable-services/bill-waiver/bill-waiver.scss +0 -10
  389. package/src/billable-services/bill-waiver/patient-bills.component.tsx +0 -134
  390. package/webpack.config.js +0 -1
@@ -0,0 +1,137 @@
1
+ import React, { useCallback, useMemo, useState } from 'react';
2
+ import classNames from 'classnames';
3
+ import { useTranslation } from 'react-i18next';
4
+ import {
5
+ Button,
6
+ DataTable,
7
+ InlineLoading,
8
+ Table,
9
+ TableBody,
10
+ TableCell,
11
+ TableContainer,
12
+ TableHead,
13
+ TableHeader,
14
+ TableRow,
15
+ } from '@carbon/react';
16
+ import { isDesktop, showSnackbar, useConfig, useLayoutType, useSession } from '@openmrs/esm-framework';
17
+ import type { BillingConfig } from '../config-schema';
18
+ import { convertToCurrency } from '../helpers';
19
+ import { actOnRefund } from './refunds.resource';
20
+ import { RefundStatus, type BillRefund, type MappedBill } from '../types';
21
+ import styles from './refunds-table.scss';
22
+
23
+ interface Props {
24
+ bill: MappedBill;
25
+ onMutate?: () => void;
26
+ }
27
+
28
+ function resolveScope(r: BillRefund, bill: MappedBill, fallback: string) {
29
+ if (!r.lineItemUuid) return fallback;
30
+ const li = bill.lineItems?.find((l) => l.uuid === r.lineItemUuid);
31
+ return li?.item || li?.billableService || fallback;
32
+ }
33
+
34
+ const RefundsTable: React.FC<Props> = ({ bill, onMutate }) => {
35
+ const { t } = useTranslation();
36
+ const { defaultCurrency } = useConfig<BillingConfig>();
37
+ const session = useSession();
38
+ const layout = useLayoutType();
39
+ const responsiveSize = isDesktop(layout) ? 'sm' : 'lg';
40
+ const [processingId, setProcessingId] = useState<string | null>(null);
41
+
42
+ const tableHeaders = [
43
+ { header: t('refundItem', 'Item'), key: 'item' },
44
+ { header: t('refundAmount', 'Refund amount'), key: 'amount' },
45
+ { header: t('reason', 'Reason'), key: 'reason' },
46
+ { header: t('status', 'Status'), key: 'status' },
47
+ { header: t('action', 'Action'), key: 'action' },
48
+ ];
49
+
50
+ const refunds = useMemo(() => (bill.refunds ?? []).filter((r) => !r.voided), [bill.refunds]);
51
+
52
+ const handleProcess = useCallback(
53
+ async (r: BillRefund) => {
54
+ setProcessingId(r.uuid);
55
+ try {
56
+ await actOnRefund(r.uuid, { status: RefundStatus.COMPLETED, completer: session.user?.uuid });
57
+ showSnackbar({ title: t('refundProcessed', 'Refund processed'), kind: 'success' });
58
+ onMutate?.();
59
+ } catch (err: unknown) {
60
+ const subtitle = (err as any)?.responseBody?.error?.message ?? (err instanceof Error ? err.message : undefined);
61
+ showSnackbar({ title: t('refundProcessFailed', 'Could not process refund'), subtitle, kind: 'error' });
62
+ } finally {
63
+ setProcessingId(null);
64
+ }
65
+ },
66
+ [onMutate, session.user?.uuid, t],
67
+ );
68
+
69
+ const tableRows = useMemo(
70
+ () =>
71
+ (refunds ?? []).map((r) => ({
72
+ id: r.uuid,
73
+ item: resolveScope(r, bill, t('wholeBill', 'Whole bill')),
74
+ amount: convertToCurrency(r.refundAmount, defaultCurrency),
75
+ reason: r.reason,
76
+ status: t(r.status.toLowerCase(), r.status),
77
+ action: (
78
+ <Button
79
+ kind="primary"
80
+ size="sm"
81
+ disabled={processingId === r.uuid || r.status !== RefundStatus.APPROVED}
82
+ onClick={() => handleProcess(r)}>
83
+ {processingId === r.uuid ? (
84
+ <InlineLoading description={t('processing', 'Processing') + '...'} />
85
+ ) : (
86
+ t('processRefund', 'Process refund')
87
+ )}
88
+ </Button>
89
+ ),
90
+ })),
91
+ [refunds, bill, defaultCurrency, processingId, t, handleProcess],
92
+ );
93
+
94
+ if (!refunds || refunds.length === 0) {
95
+ return null;
96
+ }
97
+
98
+ return (
99
+ <div className={styles.refundsWrapper}>
100
+ <DataTable headers={tableHeaders} rows={tableRows} size={responsiveSize} useZebraStyles>
101
+ {({ rows, headers, getRowProps, getTableProps }) => (
102
+ <TableContainer
103
+ description={
104
+ <span className={styles.tableDescription}>
105
+ <span>{t('refundsOnBill', 'Refunds on this bill')}</span>
106
+ </span>
107
+ }
108
+ title={t('refunds', 'Refunds')}>
109
+ <Table
110
+ {...getTableProps()}
111
+ aria-label={t('billRefunds', 'Bill refunds')}
112
+ className={classNames(styles.refundsTable, 'billingTable')}>
113
+ <TableHead>
114
+ <TableRow>
115
+ {headers.map((header) => (
116
+ <TableHeader key={header.key}>{header.header}</TableHeader>
117
+ ))}
118
+ </TableRow>
119
+ </TableHead>
120
+ <TableBody>
121
+ {rows.map((row) => (
122
+ <TableRow key={row.id} {...getRowProps({ row })}>
123
+ {row.cells.map((cell) => (
124
+ <TableCell key={cell.id}>{cell.value}</TableCell>
125
+ ))}
126
+ </TableRow>
127
+ ))}
128
+ </TableBody>
129
+ </Table>
130
+ </TableContainer>
131
+ )}
132
+ </DataTable>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ export default RefundsTable;
@@ -0,0 +1,37 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+ @use '@openmrs/esm-styleguide/src/vars' as *;
5
+
6
+ .refundsWrapper {
7
+ border: 1px solid colors.$gray-20;
8
+ background-color: colors.$white;
9
+ margin-bottom: layout.$spacing-05;
10
+ }
11
+
12
+ .refundsTable {
13
+ width: 100%;
14
+
15
+ td {
16
+ border-bottom: none !important;
17
+ }
18
+ }
19
+
20
+ .tableDescription {
21
+ display: flex;
22
+ align-items: flex-start;
23
+ margin-top: layout.$spacing-02;
24
+ column-gap: layout.$spacing-01;
25
+
26
+ ::after {
27
+ content: '';
28
+ display: block;
29
+ width: layout.$spacing-07;
30
+ padding-top: 0.188rem;
31
+ border-bottom: 0.375rem solid var(--brand-03);
32
+ }
33
+
34
+ & > span {
35
+ @include type.type-style('body-01');
36
+ }
37
+ }
@@ -0,0 +1,105 @@
1
+ import React from 'react';
2
+ import { describe, expect, it, vi, beforeEach } from 'vitest';
3
+ import { render, screen, waitFor } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { useSession, useConfig } from '@openmrs/esm-framework';
6
+ import RefundsTable from './refunds-table.component';
7
+ import { actOnRefund } from './refunds.resource';
8
+ import { RefundStatus, type MappedBill } from '../types';
9
+
10
+ vi.mock('@openmrs/esm-framework', () => ({
11
+ useSession: vi.fn(),
12
+ useConfig: vi.fn(),
13
+ useLayoutType: () => 'desktop',
14
+ isDesktop: () => true,
15
+ showSnackbar: vi.fn(),
16
+ restBaseUrl: '/ws/rest/v1',
17
+ }));
18
+ vi.mock('./refunds.resource');
19
+
20
+ globalThis.i18next = { language: 'en-US' } as any;
21
+
22
+ const mockRefund = (overrides = {}) => ({
23
+ uuid: 'r1',
24
+ billUuid: 'b1',
25
+ lineItemUuid: null,
26
+ refundAmount: 500,
27
+ reason: 'overcharged',
28
+ initiator: { uuid: 'u1', display: 'cashier' },
29
+ approver: null,
30
+ completer: null,
31
+ dateApproved: null,
32
+ dateCompleted: null,
33
+ dateCreated: '2026-05-21T00:00:00.000+0000',
34
+ status: RefundStatus.REQUESTED,
35
+ voided: false,
36
+ ...overrides,
37
+ });
38
+
39
+ const makeBill = (refunds: any[] = []): MappedBill => ({ uuid: 'b1', lineItems: [], refunds }) as unknown as MappedBill;
40
+
41
+ beforeEach(() => {
42
+ vi.clearAllMocks();
43
+ vi.mocked(useSession).mockReturnValue({ user: { uuid: 'u-cashier' } } as any);
44
+ vi.mocked(useConfig).mockReturnValue({ defaultCurrency: 'USD' } as any);
45
+ });
46
+
47
+ describe('RefundsTable', () => {
48
+ it('returns null when bill has no refunds', () => {
49
+ const { container } = render(<RefundsTable bill={makeBill([])} />);
50
+ expect(container).toBeEmptyDOMElement();
51
+ });
52
+
53
+ it('renders rows for each refund', () => {
54
+ render(<RefundsTable bill={makeBill([mockRefund(), mockRefund({ uuid: 'r2', status: RefundStatus.APPROVED })])} />);
55
+ expect(screen.getByText(/requested/i)).toBeInTheDocument();
56
+ expect(screen.getByText(/approved/i)).toBeInTheDocument();
57
+ });
58
+
59
+ it('enables the "Process refund" button only for APPROVED non-voided rows', () => {
60
+ render(
61
+ <RefundsTable
62
+ bill={makeBill([
63
+ mockRefund({ uuid: 'r1', status: RefundStatus.REQUESTED }),
64
+ mockRefund({ uuid: 'r2', status: RefundStatus.APPROVED }),
65
+ ])}
66
+ />,
67
+ );
68
+ const buttons = screen.getAllByRole('button', { name: /process refund/i });
69
+ expect(buttons).toHaveLength(2);
70
+ expect(buttons[0]).toBeDisabled();
71
+ expect(buttons[1]).toBeEnabled();
72
+ });
73
+
74
+ it('calls actOnRefund with COMPLETED status on process click', async () => {
75
+ const onMutate = vi.fn();
76
+ vi.mocked(actOnRefund).mockResolvedValue({} as any);
77
+ const user = userEvent.setup();
78
+ render(
79
+ <RefundsTable bill={makeBill([mockRefund({ uuid: 'r2', status: RefundStatus.APPROVED })])} onMutate={onMutate} />,
80
+ );
81
+ await user.click(screen.getByRole('button', { name: /process refund/i }));
82
+ await waitFor(() =>
83
+ expect(actOnRefund).toHaveBeenCalledWith('r2', { status: RefundStatus.COMPLETED, completer: 'u-cashier' }),
84
+ );
85
+ expect(onMutate).toHaveBeenCalled();
86
+ });
87
+
88
+ // Finding 3: null session.user must not crash handleProcess
89
+ it('passes undefined as completer and does not throw when session.user is null', async () => {
90
+ vi.mocked(useSession).mockReturnValue({ user: null } as any);
91
+ vi.mocked(actOnRefund).mockResolvedValue({} as any);
92
+ const user = userEvent.setup();
93
+ render(<RefundsTable bill={makeBill([mockRefund({ uuid: 'r2', status: RefundStatus.APPROVED })])} />);
94
+ await user.click(screen.getByRole('button', { name: /process refund/i }));
95
+ await waitFor(() =>
96
+ expect(actOnRefund).toHaveBeenCalledWith('r2', { status: RefundStatus.COMPLETED, completer: undefined }),
97
+ );
98
+ });
99
+
100
+ // Finding 5: voided APPROVED refunds must not appear in the table
101
+ it('does not render a row or process button for voided APPROVED refunds', () => {
102
+ render(<RefundsTable bill={makeBill([mockRefund({ uuid: 'r3', status: RefundStatus.APPROVED, voided: true })])} />);
103
+ expect(screen.queryByRole('button', { name: /process refund/i })).not.toBeInTheDocument();
104
+ });
105
+ });
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it, vi, beforeEach } from 'vitest';
2
+ import { openmrsFetch } from '@openmrs/esm-framework';
3
+ import { requestRefund, actOnRefund, voidRefund } from './refunds.resource';
4
+ import { RefundStatus } from '../types';
5
+
6
+ vi.mock('@openmrs/esm-framework', () => ({
7
+ openmrsFetch: vi.fn(),
8
+ restBaseUrl: '/ws/rest/v1',
9
+ }));
10
+
11
+ beforeEach(() => vi.clearAllMocks());
12
+
13
+ describe('requestRefund', () => {
14
+ it('POSTs to billRefund endpoint', async () => {
15
+ vi.mocked(openmrsFetch).mockResolvedValue({ data: { uuid: 'r-new' } } as any);
16
+ await requestRefund({ bill: 'b1', refundAmount: 500, reason: 'overcharged' });
17
+ expect(openmrsFetch).toHaveBeenCalledWith(
18
+ expect.stringContaining('billRefund'),
19
+ expect.objectContaining({ method: 'POST' }),
20
+ );
21
+ });
22
+ });
23
+
24
+ describe('actOnRefund', () => {
25
+ it('POSTs to billRefund/:uuid', async () => {
26
+ vi.mocked(openmrsFetch).mockResolvedValue({ data: { uuid: 'r1' } } as any);
27
+ await actOnRefund('r1', { status: RefundStatus.APPROVED, approver: 'u1' });
28
+ expect(openmrsFetch).toHaveBeenCalledWith(
29
+ expect.stringContaining('billRefund/r1'),
30
+ expect.objectContaining({ method: 'POST' }),
31
+ );
32
+ });
33
+ });
34
+
35
+ describe('voidRefund', () => {
36
+ it('DELETEs with reason query param', async () => {
37
+ vi.mocked(openmrsFetch).mockResolvedValue({} as any);
38
+ await voidRefund('r1', 'entered in error');
39
+ expect(openmrsFetch).toHaveBeenCalledWith(
40
+ expect.stringContaining('billRefund/r1?reason='),
41
+ expect.objectContaining({ method: 'DELETE' }),
42
+ );
43
+ });
44
+ });
@@ -0,0 +1,42 @@
1
+ import { openmrsFetch, useOpenmrsFetchAll } from '@openmrs/esm-framework';
2
+ import { apiBasePath } from '../constants';
3
+ import type { BillRefund, DecideRefundPayload, PatientInvoice, RefundStatus, RequestRefundPayload } from '../types';
4
+
5
+ const refundUrl = `${apiBasePath}billRefund`;
6
+ const billUrl = `${apiBasePath}bill`;
7
+
8
+ interface UseRefundRequestsArgs {
9
+ statuses: RefundStatus[];
10
+ }
11
+
12
+ export function useRefundRequests({ statuses }: UseRefundRequestsArgs) {
13
+ const qs = new URLSearchParams({
14
+ refundStatus: statuses.join(','),
15
+ v: 'default',
16
+ });
17
+ const url = `${billUrl}?${qs.toString()}`;
18
+ const { data, isLoading, error, mutate, isValidating } = useOpenmrsFetchAll<PatientInvoice>(url);
19
+ return { bills: data ?? [], isLoading, error, mutate, isValidating };
20
+ }
21
+
22
+ export async function requestRefund(payload: RequestRefundPayload): Promise<BillRefund> {
23
+ const response = await openmrsFetch<BillRefund>(refundUrl, {
24
+ method: 'POST',
25
+ headers: { 'Content-Type': 'application/json' },
26
+ body: payload,
27
+ });
28
+ return response.data;
29
+ }
30
+
31
+ export async function actOnRefund(uuid: string, payload: DecideRefundPayload): Promise<BillRefund> {
32
+ const response = await openmrsFetch<BillRefund>(`${refundUrl}/${uuid}`, {
33
+ method: 'POST',
34
+ headers: { 'Content-Type': 'application/json' },
35
+ body: payload,
36
+ });
37
+ return response.data;
38
+ }
39
+
40
+ export async function voidRefund(uuid: string, reason: string): Promise<void> {
41
+ await openmrsFetch(`${refundUrl}/${uuid}?reason=${encodeURIComponent(reason)}`, { method: 'DELETE' });
42
+ }
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { BillStatus, RefundStatus } from '../types';
3
+
4
+ describe('RefundStatus', () => {
5
+ it('exports all four statuses', () => {
6
+ expect(RefundStatus.REQUESTED).toBe('REQUESTED');
7
+ expect(RefundStatus.APPROVED).toBe('APPROVED');
8
+ expect(RefundStatus.REJECTED).toBe('REJECTED');
9
+ expect(RefundStatus.COMPLETED).toBe('COMPLETED');
10
+ });
11
+
12
+ it('BillStatus includes PARTIALLY_REFUNDED', () => {
13
+ expect(BillStatus.PARTIALLY_REFUNDED).toBe('PARTIALLY_REFUNDED');
14
+ });
15
+ });
@@ -0,0 +1,84 @@
1
+ @use '@carbon/styles/scss/spacing' as *;
2
+ @use '@carbon/styles/scss/type' as *;
3
+
4
+ .modalBody {
5
+ padding-bottom: $spacing-05;
6
+ }
7
+
8
+ .scopePanel {
9
+ background: var(--cds-layer);
10
+ border-left: 3px solid var(--cds-border-interactive);
11
+ padding: $spacing-04 $spacing-05;
12
+ }
13
+
14
+ .scopePrimary {
15
+ @include type-style('heading-compact-01');
16
+ color: var(--cds-text-primary);
17
+ margin-bottom: $spacing-02;
18
+ word-break: break-word;
19
+ }
20
+
21
+ .scopeMeta {
22
+ @include type-style('label-01');
23
+ color: var(--cds-text-secondary);
24
+ display: flex;
25
+ flex-wrap: wrap;
26
+ list-style: none;
27
+ margin: 0;
28
+ padding: 0;
29
+
30
+ li+li::before {
31
+ content: '·';
32
+ margin: 0 $spacing-03;
33
+ color: var(--cds-text-helper);
34
+ }
35
+ }
36
+
37
+ .scopeTotal {
38
+ color: var(--cds-text-primary);
39
+ font-variant-numeric: tabular-nums;
40
+ }
41
+
42
+ .summaryCard {
43
+ background: var(--cds-layer);
44
+ padding: $spacing-04 $spacing-05;
45
+ display: grid;
46
+ grid-template-columns: 1fr auto;
47
+ row-gap: $spacing-03;
48
+ column-gap: $spacing-05;
49
+ align-items: baseline;
50
+ }
51
+
52
+ .summaryLabel {
53
+ @include type-style('body-compact-01');
54
+ color: var(--cds-text-secondary);
55
+ }
56
+
57
+ .summaryValue {
58
+ @include type-style('body-compact-01');
59
+ color: var(--cds-text-primary);
60
+ font-variant-numeric: tabular-nums;
61
+ text-align: right;
62
+ }
63
+
64
+ .summaryRefund {
65
+ color: var(--cds-text-error);
66
+ }
67
+
68
+ .summaryDivider {
69
+ grid-column: 1 / -1;
70
+ height: 1px;
71
+ background: var(--cds-border-subtle);
72
+ }
73
+
74
+ .summaryTotalLabel {
75
+ @include type-style('heading-compact-01');
76
+ color: var(--cds-text-primary);
77
+ }
78
+
79
+ .summaryTotalValue {
80
+ @include type-style('heading-compact-01');
81
+ color: var(--cds-text-primary);
82
+ font-variant-numeric: tabular-nums;
83
+ text-align: right;
84
+ }
@@ -0,0 +1,204 @@
1
+ import React from 'react';
2
+ import { describe, expect, it, vi, beforeEach } from 'vitest';
3
+ import { render, screen, waitFor } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { showSnackbar } from '@openmrs/esm-framework';
6
+ import RequestRefundModal from './request-refund.modal';
7
+ import { requestRefund } from './refunds.resource';
8
+
9
+ vi.mock('@openmrs/esm-framework', () => ({
10
+ showSnackbar: vi.fn(),
11
+ useConfig: vi.fn().mockReturnValue({ defaultCurrency: 'USD' }),
12
+ getCoreTranslation: (key: string) => key,
13
+ restBaseUrl: '/ws/rest/v1',
14
+ }));
15
+ vi.mock('./refunds.resource');
16
+
17
+ globalThis.i18next = { language: 'en-US' } as any;
18
+
19
+ const closeModal = vi.fn();
20
+ const onMutate = vi.fn();
21
+
22
+ beforeEach(() => vi.clearAllMocks());
23
+
24
+ describe('RequestRefundModal', () => {
25
+ it('blocks submit when reason is empty', () => {
26
+ render(
27
+ <RequestRefundModal
28
+ closeModal={closeModal}
29
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000, receiptNumber: 'INV-1' }}
30
+ remainingRefundable={5000}
31
+ onMutate={onMutate}
32
+ />,
33
+ );
34
+ expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
35
+ });
36
+
37
+ it('shows a clear message when no refundable amount remains', async () => {
38
+ const user = userEvent.setup();
39
+ render(
40
+ <RequestRefundModal
41
+ closeModal={closeModal}
42
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
43
+ remainingRefundable={0}
44
+ onMutate={onMutate}
45
+ />,
46
+ );
47
+ await user.type(screen.getByLabelText(/amount/i), '1');
48
+ expect(screen.getByText(/no refundable amount remaining/i)).toBeInTheDocument();
49
+ expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
50
+ });
51
+
52
+ it('blocks submit when amount exceeds remainingRefundable', async () => {
53
+ const user = userEvent.setup();
54
+ render(
55
+ <RequestRefundModal
56
+ closeModal={closeModal}
57
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
58
+ remainingRefundable={300}
59
+ onMutate={onMutate}
60
+ />,
61
+ );
62
+ await user.type(screen.getByLabelText(/amount/i), '500');
63
+ await user.type(screen.getByLabelText(/reason/i), 'overcharged');
64
+ expect(screen.getByRole('button', { name: /submit request/i })).toBeDisabled();
65
+ expect(screen.getByText(/cannot exceed/i)).toBeInTheDocument();
66
+ });
67
+
68
+ it('submits a valid request and closes', async () => {
69
+ vi.mocked(requestRefund).mockResolvedValue({ uuid: 'r-new' } as any);
70
+ const user = userEvent.setup();
71
+ render(
72
+ <RequestRefundModal
73
+ closeModal={closeModal}
74
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
75
+ remainingRefundable={5000}
76
+ onMutate={onMutate}
77
+ />,
78
+ );
79
+ await user.type(screen.getByLabelText(/amount/i), '500');
80
+ await user.type(screen.getByLabelText(/reason/i), 'overcharged');
81
+ await user.click(screen.getByRole('button', { name: /submit request/i }));
82
+ await waitFor(() =>
83
+ expect(requestRefund).toHaveBeenCalledWith({
84
+ bill: 'b1',
85
+ refundAmount: 500,
86
+ reason: 'overcharged',
87
+ }),
88
+ );
89
+ await waitFor(() => expect(closeModal).toHaveBeenCalled());
90
+ expect(onMutate).toHaveBeenCalled();
91
+ expect(showSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'success' }));
92
+ });
93
+
94
+ it('submits with lineItem uuid when lineItem prop is provided', async () => {
95
+ vi.mocked(requestRefund).mockResolvedValue({ uuid: 'r-new' } as any);
96
+ const user = userEvent.setup();
97
+ render(
98
+ <RequestRefundModal
99
+ closeModal={closeModal}
100
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
101
+ lineItem={{ uuid: 'li1', display: 'Consultation', total: 1000 }}
102
+ remainingRefundable={1000}
103
+ onMutate={onMutate}
104
+ />,
105
+ );
106
+ await user.type(screen.getByLabelText(/amount/i), '200');
107
+ await user.type(screen.getByLabelText(/reason/i), 'duplicate charge');
108
+ await user.click(screen.getByRole('button', { name: /submit request/i }));
109
+ await waitFor(() =>
110
+ expect(requestRefund).toHaveBeenCalledWith(
111
+ expect.objectContaining({ bill: 'b1', lineItem: 'li1', refundAmount: 200 }),
112
+ ),
113
+ );
114
+ });
115
+
116
+ it('shows already-refunded row when prior refunds exist on a discounted bill', async () => {
117
+ const user = userEvent.setup();
118
+ render(
119
+ <RequestRefundModal
120
+ closeModal={closeModal}
121
+ // bill.total=200, discount=50 → amountAfterDiscount=150, prior refund=40 → remainingRefundable=110
122
+ bill={{ uuid: 'b1', total: 200, amountAfterDiscount: 150 }}
123
+ remainingRefundable={110}
124
+ onMutate={onMutate}
125
+ />,
126
+ );
127
+ await user.type(screen.getByLabelText(/amount/i), '30');
128
+
129
+ expect(screen.getByText(/already refunded/i)).toBeInTheDocument();
130
+ // summary shows amountAfterDiscount (150) as bill total, prior refund (40), and remainder (80)
131
+ expect(screen.getByText('$150.00')).toBeInTheDocument();
132
+ expect(screen.getByText('$80.00')).toBeInTheDocument();
133
+ });
134
+
135
+ it('hides already-refunded row when there are no prior refunds', async () => {
136
+ const user = userEvent.setup();
137
+ render(
138
+ <RequestRefundModal
139
+ closeModal={closeModal}
140
+ bill={{ uuid: 'b1', total: 200, amountAfterDiscount: 150 }}
141
+ remainingRefundable={150}
142
+ onMutate={onMutate}
143
+ />,
144
+ );
145
+ await user.type(screen.getByLabelText(/amount/i), '30');
146
+
147
+ expect(screen.queryByText(/already refunded/i)).not.toBeInTheDocument();
148
+ });
149
+
150
+ it('shows already-refunded row for a line item with a prior completed refund', async () => {
151
+ const user = userEvent.setup();
152
+ render(
153
+ <RequestRefundModal
154
+ closeModal={closeModal}
155
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
156
+ // line total=100, completed refund=20 → remainingRefundable=80
157
+ lineItem={{ uuid: 'li1', display: 'Lab Test', total: 100 }}
158
+ remainingRefundable={80}
159
+ onMutate={onMutate}
160
+ />,
161
+ );
162
+ await user.type(screen.getByLabelText(/amount/i), '50');
163
+
164
+ expect(screen.getByText(/already refunded/i)).toBeInTheDocument();
165
+ // amount after refund: remainingRefundable − amount = 80 − 50 = 30
166
+ expect(screen.getByText('$30.00')).toBeInTheDocument();
167
+ });
168
+
169
+ it('hides already-refunded row for a line item with no prior refunds', async () => {
170
+ const user = userEvent.setup();
171
+ render(
172
+ <RequestRefundModal
173
+ closeModal={closeModal}
174
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
175
+ lineItem={{ uuid: 'li1', display: 'Lab Test', total: 100 }}
176
+ remainingRefundable={100}
177
+ onMutate={onMutate}
178
+ />,
179
+ );
180
+ await user.type(screen.getByLabelText(/amount/i), '50');
181
+
182
+ expect(screen.queryByText(/already refunded/i)).not.toBeInTheDocument();
183
+ });
184
+
185
+ it('shows an error snackbar and keeps modal open on failure', async () => {
186
+ vi.mocked(requestRefund).mockRejectedValue({
187
+ responseBody: { error: { message: 'billing.error.refund.exceedsTotal' } },
188
+ });
189
+ const user = userEvent.setup();
190
+ render(
191
+ <RequestRefundModal
192
+ closeModal={closeModal}
193
+ bill={{ uuid: 'b1', total: 5000, amountAfterDiscount: 5000 }}
194
+ remainingRefundable={5000}
195
+ onMutate={onMutate}
196
+ />,
197
+ );
198
+ await user.type(screen.getByLabelText(/amount/i), '100');
199
+ await user.type(screen.getByLabelText(/reason/i), 'x');
200
+ await user.click(screen.getByRole('button', { name: /submit request/i }));
201
+ await waitFor(() => expect(showSnackbar).toHaveBeenCalledWith(expect.objectContaining({ kind: 'error' })));
202
+ expect(closeModal).not.toHaveBeenCalled();
203
+ });
204
+ });