@ampath/esm-dha-workflow-app 4.0.0-next.451 → 4.0.0-next.453

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 (117) hide show
  1. package/dist/1100.js +1 -1
  2. package/dist/1435.js +1 -1
  3. package/dist/1435.js.map +1 -1
  4. package/dist/2257.js +2 -0
  5. package/dist/2257.js.map +1 -0
  6. package/dist/2535.js +1 -1
  7. package/dist/2592.js +1 -1
  8. package/dist/2663.js +1 -1
  9. package/dist/2687.js +1 -1
  10. package/dist/2808.js +1 -1
  11. package/dist/2848.js +1 -1
  12. package/dist/2904.js +1 -0
  13. package/dist/2904.js.map +1 -0
  14. package/dist/3.js +1 -1
  15. package/dist/3016.js +1 -1
  16. package/dist/3182.js +1 -1
  17. package/dist/3196.js +1 -1
  18. package/dist/3242.js +1 -1
  19. package/dist/3288.js +1 -1
  20. package/dist/3612.js +1 -1
  21. package/dist/3794.js +1 -1
  22. package/dist/3897.js +1 -1
  23. package/dist/3949.js +1 -1
  24. package/dist/3949.js.map +1 -1
  25. package/dist/408.js +1 -1
  26. package/dist/409.js +1 -1
  27. package/dist/4300.js +1 -1
  28. package/dist/4399.js +1 -1
  29. package/dist/{7269.js → 4457.js} +1 -1
  30. package/dist/4457.js.map +1 -0
  31. package/dist/4535.js +1 -0
  32. package/dist/4535.js.map +1 -0
  33. package/dist/4569.js +1 -1
  34. package/dist/474.js +1 -1
  35. package/dist/5119.js +1 -1
  36. package/dist/5138.js +1 -1
  37. package/dist/5179.js +1 -1
  38. package/dist/5244.js +1 -1
  39. package/dist/5353.js +1 -1
  40. package/dist/5377.js +1 -1
  41. package/dist/5377.js.map +1 -1
  42. package/dist/5500.js +1 -1
  43. package/dist/5771.js +1 -0
  44. package/dist/5771.js.map +1 -0
  45. package/dist/5805.js +1 -1
  46. package/dist/6048.js +1 -1
  47. package/dist/6055.js +1 -1
  48. package/dist/6206.js +1 -1
  49. package/dist/6279.js +1 -1
  50. package/dist/6682.js +1 -1
  51. package/dist/6802.js +1 -1
  52. package/dist/72.js +1 -1
  53. package/dist/7694.js +1 -1
  54. package/dist/7698.js +1 -1
  55. package/dist/7734.js +1 -1
  56. package/dist/8137.js +1 -1
  57. package/dist/8167.js +1 -1
  58. package/dist/818.js +1 -1
  59. package/dist/8735.js +1 -1
  60. package/dist/8961.js +1 -1
  61. package/dist/902.js +1 -1
  62. package/dist/9134.js +1 -1
  63. package/dist/9429.js +1 -1
  64. package/dist/9442.js +1 -1
  65. package/dist/968.js +1 -1
  66. package/dist/9770.js +1 -1
  67. package/dist/9879.js +1 -1
  68. package/dist/9974.js +1 -1
  69. package/dist/esm-dha-workflow-app.js +1 -1
  70. package/dist/esm-dha-workflow-app.js.buildmanifest.json +214 -166
  71. package/dist/main.js +1 -1
  72. package/dist/main.js.map +1 -1
  73. package/dist/routes.json +1 -1
  74. package/package.json +1 -1
  75. package/src/billing/dashboard/v3/finalize-bill/bill-line-items/bill-line-items.component.tsx +101 -0
  76. package/src/billing/dashboard/v3/finalize-bill/bill-line-items/bill-line-items.scss +69 -0
  77. package/src/billing/dashboard/v3/finalize-bill/finalize-bill-confirmation.modal.scss +11 -0
  78. package/src/billing/dashboard/v3/finalize-bill/finalize-bill-confirmation.modal.tsx +72 -0
  79. package/src/billing/dashboard/v3/finalize-bill/finalize-bill.component.scss +68 -0
  80. package/src/billing/dashboard/v3/finalize-bill/finalize-bill.component.tsx +261 -0
  81. package/src/billing/dashboard/v3/finalize-bill/finalize-bill.resource.ts +68 -0
  82. package/src/billing/dashboard/v3/finalize-bill/helpers/functions.ts +85 -0
  83. package/src/billing/dashboard/v3/finalize-bill/helpers/index.ts +1 -0
  84. package/src/billing/dashboard/v3/finalize-bill/payments/invoice-breakdown/invoice-breakdown.component.tsx +17 -0
  85. package/src/billing/dashboard/v3/finalize-bill/payments/invoice-breakdown/invoice-breakdown.scss +29 -0
  86. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.component.tsx +60 -0
  87. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.scss +53 -0
  88. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.test.tsx +211 -0
  89. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.utils.ts +87 -0
  90. package/src/billing/dashboard/v3/finalize-bill/payments/payment-history/payment-history.component.tsx +77 -0
  91. package/src/billing/dashboard/v3/finalize-bill/payments/payment-history/payment-history.test.tsx +158 -0
  92. package/src/billing/dashboard/v3/finalize-bill/payments/payments.component.tsx +238 -0
  93. package/src/billing/dashboard/v3/finalize-bill/payments/payments.scss +77 -0
  94. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/print-receipt.component.tsx +43 -0
  95. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/print-receipt.scss +14 -0
  96. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/print-receipt.test.tsx +133 -0
  97. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-footer.component.tsx +19 -0
  98. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-footer.scss +17 -0
  99. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-footer.test.tsx +22 -0
  100. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice-header.component.tsx +109 -0
  101. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice-header.scss +62 -0
  102. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice-header.test.tsx +159 -0
  103. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice.component.tsx +221 -0
  104. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice.scss +55 -0
  105. package/src/billing/dashboard/v3/finalize-bill/types.ts +248 -0
  106. package/src/billing/dashboard/v3/patient-bill-details/patient-visit-details.tsx +43 -8
  107. package/src/billing/dashboard/v3/patient-bill-details/patient-visit.scss +7 -0
  108. package/src/config-schema.ts +33 -3
  109. package/src/index.ts +12 -9
  110. package/src/routes.json +8 -0
  111. package/translations/en.json +1 -0
  112. package/dist/7269.js.map +0 -1
  113. package/dist/7949.js +0 -2
  114. package/dist/7949.js.map +0 -1
  115. package/dist/7958.js +0 -1
  116. package/dist/7958.js.map +0 -1
  117. /package/dist/{7949.js.LICENSE.txt → 2257.js.LICENSE.txt} +0 -0
@@ -0,0 +1,101 @@
1
+ import React, { useMemo } from "react";
2
+ import { LineItem } from "../types";
3
+ import { useTranslation } from "react-i18next";
4
+ import { convertToCurrency, getLineItemTotal } from "../helpers";
5
+ import styles from './bill-line-items.scss'
6
+ import { DataTable, Layer, Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow, TableToolbarSearch, Tile } from "@carbon/react";
7
+ import { isDesktop, useLayoutType } from "@openmrs/esm-framework";
8
+ import classNames from "classnames";
9
+
10
+ interface BillLineItemsProps {
11
+ lineItems: Array<LineItem> | undefined
12
+ }
13
+
14
+ const BillLineItems: React.FC<BillLineItemsProps> = ({ lineItems }) => {
15
+ const { t } = useTranslation();
16
+ const layout = useLayoutType();
17
+ const responsiveSize = isDesktop(layout) ? 'sm' : 'lg';
18
+
19
+ const defaultCurrency = 'KES';
20
+
21
+ const tableHeaders = [
22
+ { header: t('number', 'Number'), key: 'no', width: 7 }, // Width as a percentage
23
+ { header: t('billItem', 'Bill item'), key: 'billItem', width: 25 },
24
+ { header: t('status', 'Status'), key: 'status', width: 25 },
25
+ { header: t('quantity', 'Quantity'), key: 'quantity', width: 15 },
26
+ { header: t('price', 'Price'), key: 'price', width: 24 },
27
+ { header: t('total', 'Total'), key: 'total', width: 15 },
28
+ ];
29
+
30
+ const tableRows = useMemo(
31
+ () =>
32
+ lineItems?.map((item, index) => ({
33
+ no: `${index + 1}`,
34
+ id: `${item.uuid}`,
35
+ billItem: item.billableService ? item.billableService : item?.item,
36
+ status: item.status,
37
+ quantity: item.quantity,
38
+ price: convertToCurrency(item.price, defaultCurrency),
39
+ total: convertToCurrency(getLineItemTotal(item), defaultCurrency),
40
+ })) ?? [],
41
+ [lineItems, defaultCurrency],
42
+ );
43
+
44
+ return (
45
+ <div className={styles.lineItemsWrapper}>
46
+ <DataTable
47
+ headers={tableHeaders}
48
+ rows={tableRows}
49
+ size={responsiveSize}
50
+ useZebraStyles
51
+ overflowMenuOnHover={isDesktop(layout)}>
52
+ {({ rows, headers, getRowProps, getTableProps }) => (
53
+ <TableContainer
54
+ description={
55
+ <span className={styles.tableDescription}>
56
+ <span>{t('itemsToBeBilled', 'Items to be billed')}</span>
57
+ </span>
58
+ }
59
+ title={t('lineItems', 'Line items')}>
60
+ <Table
61
+ {...getTableProps()}
62
+ aria-label={t('invoiceLineItems', 'Invoice line items')}
63
+ className={classNames(styles.invoiceTable, 'billingTable')}>
64
+ <TableHead>
65
+ <TableRow>
66
+ {headers.map((header) => (
67
+ <TableHeader key={header.key}>{header.header}</TableHeader>
68
+ ))}
69
+ </TableRow>
70
+ </TableHead>
71
+ <TableBody>
72
+ {rows.map((row) => {
73
+ return (
74
+ <TableRow {...getRowProps({ row })}>
75
+ {row.cells.map((cell) => (
76
+ <TableCell key={cell.id}>{cell.value}</TableCell>
77
+ ))}
78
+ </TableRow>
79
+ );
80
+ })}
81
+ </TableBody>
82
+ </Table>
83
+ </TableContainer>
84
+ )}
85
+ </DataTable>
86
+ {lineItems?.length === 0 && (
87
+ <div className={styles.filterEmptyState}>
88
+ <Layer>
89
+ <Tile className={styles.filterEmptyStateTile}>
90
+ <p className={styles.filterEmptyStateContent}>
91
+ {t('noMatchingItemsToDisplay', 'No matching items to display')}
92
+ </p>
93
+ </Tile>
94
+ </Layer>
95
+ </div>
96
+ )}
97
+ </div>
98
+ )
99
+ }
100
+
101
+ export default BillLineItems;
@@ -0,0 +1,69 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+ @use '@openmrs/esm-styleguide/src/vars' as *;
5
+
6
+ .lineItemsWrapper {
7
+ border: 1px solid colors.$gray-20;
8
+ background-color: colors.$white;
9
+ margin-bottom: layout.$spacing-05;
10
+ }
11
+
12
+ .filterEmptyState {
13
+ align-items: center;
14
+ background-color: white;
15
+ display: flex;
16
+ justify-content: center;
17
+ padding: layout.$spacing-09 !important;
18
+ text-align: center;
19
+ }
20
+
21
+ .filterEmptyStateTile {
22
+ margin: auto;
23
+ }
24
+
25
+ .filterEmptyStateContent {
26
+ @include type.type-style('heading-compact-02');
27
+ color: $text-02;
28
+ margin-bottom: layout.$spacing-03;
29
+ }
30
+
31
+ .filterEmptyStateHelper {
32
+ @include type.type-style('body-compact-01');
33
+ color: $text-02;
34
+ }
35
+
36
+ .searchbox {
37
+ height: 3rem;
38
+
39
+ input:focus {
40
+ outline: 2px solid colors.$orange-40 !important;
41
+ }
42
+ }
43
+
44
+ .invoiceTable {
45
+ width: 100%;
46
+
47
+ td {
48
+ border-bottom: none !important;
49
+ }
50
+ }
51
+
52
+ .tableDescription {
53
+ display: flex;
54
+ align-items: flex-start;
55
+ margin-top: layout.$spacing-02;
56
+ column-gap: layout.$spacing-01;
57
+
58
+ ::after {
59
+ content: '';
60
+ display: block;
61
+ width: layout.$spacing-07;
62
+ padding-top: 0.188rem;
63
+ border-bottom: 0.375rem solid var(--brand-03);
64
+ }
65
+
66
+ &>span {
67
+ @include type.type-style('body-01');
68
+ }
69
+ }
@@ -0,0 +1,11 @@
1
+ :global(.omrs-modals-container) > :global(.cds--modal-container) {
2
+ position: fixed !important;
3
+ inset: 50% auto auto 50% !important;
4
+ max-block-size: calc(100vh - 2rem) !important;
5
+ margin: 0 !important;
6
+ transform: translate(-50%, -50%) !important;
7
+ }
8
+
9
+ .modalBody {
10
+ box-sizing: border-box;
11
+ }
@@ -0,0 +1,72 @@
1
+ import React, { useState } from 'react';
2
+ import { Button, InlineLoading, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
3
+ import { showSnackbar } from '@openmrs/esm-framework';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { finalizeBill } from './finalize-bill.resource';
6
+ import styles from './finalize-bill-confirmation.modal.scss';
7
+
8
+ interface FinalizeBillConfirmationModalProps {
9
+ billUuid: string;
10
+ closeModal: () => void;
11
+ onMutate?: () => Promise<unknown> | unknown;
12
+ }
13
+
14
+ const FinalizeBillConfirmationModal: React.FC<FinalizeBillConfirmationModalProps> = ({
15
+ billUuid,
16
+ closeModal,
17
+ onMutate,
18
+ }) => {
19
+ const { t } = useTranslation();
20
+ const [isFinalizing, setIsFinalizing] = useState(false);
21
+ const [errorMessage, setErrorMessage] = useState('');
22
+
23
+ const handleFinalize = async () => {
24
+ if (!billUuid || isFinalizing) {
25
+ return;
26
+ }
27
+
28
+ setIsFinalizing(true);
29
+ setErrorMessage('');
30
+ try {
31
+ await finalizeBill(billUuid);
32
+ await onMutate?.();
33
+ showSnackbar({
34
+ kind: 'success',
35
+ title: t('billFinalized', 'Bill finalized'),
36
+ subtitle: t('billFinalizedSuccess', 'Bill has been finalized successfully.'),
37
+ });
38
+ closeModal();
39
+ } catch (error: unknown) {
40
+ const message = error instanceof Error ? error.message : String(error);
41
+ setErrorMessage(message || t('finalizeBillFailed', 'Unable to finalize this bill. Please try again.'));
42
+ } finally {
43
+ setIsFinalizing(false);
44
+ }
45
+ };
46
+
47
+ return (
48
+ <>
49
+ <ModalHeader closeModal={closeModal} title={t('finalizeBill', 'Finalize bill')} />
50
+ <ModalBody className={styles.modalBody}>
51
+ <p>
52
+ {t(
53
+ 'finalizeBillConfirmation',
54
+ 'Are you sure you want to finalize this bill? Once finalized, no further modifications will be allowed.',
55
+ )}
56
+ </p>
57
+ {errorMessage ? <p role="alert">{errorMessage}</p> : null}
58
+ {isFinalizing ? <InlineLoading description={t('finalizing', 'Finalizing bill...')} /> : null}
59
+ </ModalBody>
60
+ <ModalFooter>
61
+ <Button kind="secondary" disabled={isFinalizing} onClick={closeModal}>
62
+ {t('cancel', 'Cancel')}
63
+ </Button>
64
+ <Button kind="danger" disabled={isFinalizing || !billUuid} onClick={handleFinalize}>
65
+ {isFinalizing ? t('finalizing', 'Finalizing...') : t('confirmFinalizeBill', 'Confirm finalization')}
66
+ </Button>
67
+ </ModalFooter>
68
+ </>
69
+ );
70
+ };
71
+
72
+ export default FinalizeBillConfirmationModal;
@@ -0,0 +1,68 @@
1
+ @use '@carbon/layout';
2
+ @use '@carbon/type';
3
+
4
+ .billHeader {
5
+ background: #ffffff;
6
+ border: 1px solid #e0e0e0;
7
+ display: grid;
8
+ gap: layout.$spacing-05;
9
+ grid-template-columns: 2fr 1fr;
10
+ margin-bottom: layout.$spacing-05;
11
+ padding: layout.$spacing-05;
12
+ }
13
+
14
+ .billIdentity,
15
+ .billSummary {
16
+ display: grid;
17
+ gap: layout.$spacing-03;
18
+ }
19
+
20
+ .billTitle {
21
+ @include type.type-style('heading-compact-02');
22
+ margin: 0;
23
+ }
24
+
25
+ .billMeta,
26
+ .summaryRow {
27
+ align-items: center;
28
+ display: flex;
29
+ justify-content: space-between;
30
+ gap: layout.$spacing-05;
31
+ }
32
+
33
+ .billMeta {
34
+ @include type.type-style('body-compact-01');
35
+ color: #525252;
36
+ }
37
+
38
+ .summaryRow {
39
+ @include type.type-style('body-compact-01');
40
+ }
41
+
42
+ .summaryValue {
43
+ font-weight: 600;
44
+ }
45
+
46
+ .discountValue {
47
+ color: #8a3ffc;
48
+ font-weight: 600;
49
+ }
50
+
51
+ .receiptActions {
52
+ display: flex;
53
+ gap: layout.$spacing-03;
54
+ justify-content: flex-end;
55
+ margin-top: layout.$spacing-04;
56
+ }
57
+
58
+ .discountTypeOptions {
59
+ display: flex;
60
+ gap: layout.$spacing-05;
61
+ margin-bottom: layout.$spacing-05;
62
+ }
63
+
64
+ @media (max-width: 672px) {
65
+ .billHeader {
66
+ grid-template-columns: 1fr;
67
+ }
68
+ }
@@ -0,0 +1,261 @@
1
+ import React, { useState } from 'react';
2
+ import { useBill, mapBillProperties, processBillPayment } from './finalize-bill.resource';
3
+ import { Button, InlineLoading, Modal, ModalBody, ModalFooter, ModalHeader, NumberInput, Tag } from '@carbon/react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import BillLineItems from './bill-line-items/bill-line-items.component';
6
+ import Payments from './payments/payments.component';
7
+ import PrintReceipt from './payments/printable-invoice/print-receipt.component';
8
+ import { formatDate, parseDate, showModal, showSnackbar } from '@openmrs/esm-framework';
9
+ import { convertToCurrency } from './helpers';
10
+ import { BillStatus } from './types';
11
+ import { fetchPaymentModes } from '../../../../shared/services/billing.resource';
12
+ import styles from './finalize-bill.component.scss';
13
+
14
+ interface FinalizeBillProps {
15
+ billUuid: string;
16
+ closeModal: () => void;
17
+ }
18
+
19
+ const FinalizeBill: React.FC<FinalizeBillProps> = ({ billUuid, closeModal }) => {
20
+ const { bill, isLoading, isValidating, mutate } = useBill(billUuid);
21
+ const { t } = useTranslation();
22
+ const [isDiscountModalOpen, setIsDiscountModalOpen] = useState(false);
23
+ const [discountType, setDiscountType] = useState<'AMOUNT' | 'PERCENT'>('AMOUNT');
24
+ const [discountPercentage, setDiscountPercentage] = useState('');
25
+ const [discountAmount, setDiscountAmount] = useState('');
26
+ const [isApplyingDiscount, setIsApplyingDiscount] = useState(false);
27
+
28
+ const handleFinalizeBill = () => {
29
+ let dispose: () => void;
30
+ dispose = showModal('finalize-bill-confirmation-modal', {
31
+ billUuid,
32
+ onMutate: mutate,
33
+ closeModal: () => dispose(),
34
+ size: 'md',
35
+ });
36
+ };
37
+
38
+ const mappedBill = bill ? mapBillProperties(bill) : null;
39
+ const subtotal = mappedBill?.totalAmount ?? 0;
40
+ const netAmount = mappedBill?.netAmount ?? subtotal;
41
+ const discount = Math.max(0, subtotal - netAmount);
42
+ const tenderedAmount = mappedBill?.tenderedAmount ?? 0;
43
+ const amountDue = netAmount - tenderedAmount;
44
+ const isPaid = mappedBill?.status === BillStatus.PAID;
45
+
46
+ const closeDiscountModal = () => {
47
+ if (!isApplyingDiscount) {
48
+ setIsDiscountModalOpen(false);
49
+ setDiscountAmount('');
50
+ setDiscountPercentage('');
51
+ }
52
+ };
53
+
54
+ const applyDiscount = async () => {
55
+ const percentage = Number(discountPercentage || 0);
56
+ const fixedAmount = Number(discountAmount || 0);
57
+ const appliedAmount =
58
+ discountType === 'PERCENT' ? Math.round((amountDue * percentage) / 100) : fixedAmount;
59
+
60
+ if (appliedAmount <= 0 || appliedAmount > amountDue) {
61
+ showSnackbar({
62
+ kind: 'error',
63
+ title: t('invalidDiscount', 'Invalid discount'),
64
+ subtitle: t('discountRangeInvalid', 'Discount must be greater than zero and not exceed the balance.'),
65
+ });
66
+ return;
67
+ }
68
+
69
+ setIsApplyingDiscount(true);
70
+ try {
71
+ const paymentModes = await fetchPaymentModes();
72
+ const discountMode = paymentModes.find((mode) =>
73
+ ['waiver', 'discount', 'waived'].includes(mode.name.trim().toLowerCase()),
74
+ );
75
+
76
+ if (!discountMode) {
77
+ throw new Error(t('discountPaymentModeMissing', 'A waiver or discount payment mode was not found.'));
78
+ }
79
+
80
+ await processBillPayment(
81
+ {
82
+ instanceType: discountMode.uuid,
83
+ amount: appliedAmount,
84
+ amountTendered: appliedAmount,
85
+ },
86
+ billUuid,
87
+ );
88
+ await mutate();
89
+ showSnackbar({
90
+ kind: 'success',
91
+ title: t('discountApplied', 'Discount applied'),
92
+ subtitle: t('discountAppliedSuccessfully', 'The discount was applied successfully.'),
93
+ });
94
+ setDiscountAmount('');
95
+ setDiscountPercentage('');
96
+ setIsDiscountModalOpen(false);
97
+ } catch (error: unknown) {
98
+ showSnackbar({
99
+ kind: 'error',
100
+ title: t('discountApplicationFailed', 'Discount application failed'),
101
+ subtitle: error instanceof Error ? error.message : String(error),
102
+ });
103
+ } finally {
104
+ setIsApplyingDiscount(false);
105
+ }
106
+ };
107
+
108
+ const discountInputValid =
109
+ discountType === 'PERCENT'
110
+ ? discountPercentage !== '' && Number(discountPercentage) >= 1 && Number(discountPercentage) <= 100
111
+ : discountAmount !== '' &&
112
+ Number(discountAmount) >= 1 &&
113
+ Number(discountAmount) <= amountDue;
114
+
115
+ return (
116
+ <>
117
+ <ModalHeader closeModal={closeModal} title={t('finalizeBill', 'Finalize bill')} />
118
+ <ModalBody>
119
+ {!bill && (isLoading || isValidating) ? (
120
+ <InlineLoading
121
+ title={t('loading', 'Loading...')}
122
+ description={t('loadingPatientBill', 'Loading patient bill...')}
123
+ />
124
+ ) : null}
125
+ {bill && mappedBill ? (
126
+ <>
127
+ <div className={styles.billHeader}>
128
+ <div className={styles.billIdentity}>
129
+ <h3 className={styles.billTitle}>{t('billSummary', 'Bill summary')}</h3>
130
+ <Tag size="sm" type={amountDue <= 0 ? 'green' : isPaid ? 'blue' : 'red'}>
131
+ {mappedBill.status}
132
+ </Tag>
133
+ <div className={styles.billMeta}>
134
+ <span>{mappedBill.patientName}</span>
135
+ <span>{mappedBill.identifier}</span>
136
+ </div>
137
+ <div className={styles.billMeta}>
138
+ <span>
139
+ {t('invoiceNo', 'Invoice #')}: {mappedBill.receiptNumber || '--'}
140
+ </span>
141
+ <span>
142
+ {t('invoiceDate', 'Invoice date')}:{' '}
143
+ {mappedBill.dateCreated
144
+ ? formatDate(parseDate(mappedBill.dateCreated), { mode: 'wide', noToday: true, time: false })
145
+ : '--'}
146
+ </span>
147
+ </div>
148
+ </div>
149
+
150
+ <div>
151
+ <div className={styles.billSummary}>
152
+ <div className={styles.summaryRow}>
153
+ <span>{t('subtotal', 'Subtotal')}</span>
154
+ <span className={styles.summaryValue}>{convertToCurrency(subtotal, 'KES')}</span>
155
+ </div>
156
+ {discount > 0 ? (
157
+ <div className={styles.summaryRow}>
158
+ <span>{t('discount', 'Discount')}</span>
159
+ <span className={styles.discountValue}>-{convertToCurrency(discount, 'KES')}</span>
160
+ </div>
161
+ ) : null}
162
+ <div className={styles.summaryRow}>
163
+ <span>{t('totalAmount', 'Total amount')}</span>
164
+ <span className={styles.summaryValue}>{convertToCurrency(netAmount, 'KES')}</span>
165
+ </div>
166
+ <div className={styles.summaryRow}>
167
+ <span>{t('totalPaid', 'Paid')}</span>
168
+ <span className={styles.summaryValue}>{convertToCurrency(tenderedAmount, 'KES')}</span>
169
+ </div>
170
+ <div className={styles.summaryRow}>
171
+ <span>{t('amountDue', 'Balance')}</span>
172
+ <span className={styles.summaryValue}>{convertToCurrency(amountDue, 'KES')}</span>
173
+ </div>
174
+ </div>
175
+ <div className={styles.receiptActions}>
176
+ {amountDue > 0 && !isPaid ? (
177
+ <Button kind="secondary" onClick={() => setIsDiscountModalOpen(true)}>
178
+ {t('applyDiscount', 'Apply Discount')}
179
+ </Button>
180
+ ) : null}
181
+ {isPaid ? <PrintReceipt billUuid={billUuid} /> : null}
182
+ </div>
183
+ </div>
184
+ </div>
185
+
186
+ <BillLineItems lineItems={bill.lineItems} />
187
+
188
+ <Payments bill={bill} mutate={mutate} onFinalizeBill={handleFinalizeBill} />
189
+ </>
190
+ ) : null}
191
+ </ModalBody>
192
+ <ModalFooter>
193
+ <Button kind="secondary" onClick={closeModal}>
194
+ {t('close', 'Close')}
195
+ </Button>
196
+ </ModalFooter>
197
+
198
+ <Modal
199
+ open={isDiscountModalOpen}
200
+ modalHeading={t('applyDiscount', 'Apply Discount')}
201
+ primaryButtonText={isApplyingDiscount ? t('applying', 'Applying...') : t('submit', 'Submit')}
202
+ secondaryButtonText={t('cancel', 'Cancel')}
203
+ primaryButtonDisabled={isApplyingDiscount || !discountInputValid}
204
+ onRequestClose={closeDiscountModal}
205
+ onRequestSubmit={applyDiscount}
206
+ size="sm"
207
+ >
208
+ <div className={styles.discountTypeOptions}>
209
+ <label htmlFor="discount-type-amount">
210
+ <input
211
+ type="radio"
212
+ id="discount-type-amount"
213
+ name="discount-type"
214
+ value="AMOUNT"
215
+ checked={discountType === 'AMOUNT'}
216
+ onChange={() => setDiscountType('AMOUNT')}
217
+ />{' '}
218
+ {t('amount', 'Amount')}
219
+ </label>
220
+ <label htmlFor="discount-type-percent">
221
+ <input
222
+ type="radio"
223
+ id="discount-type-percent"
224
+ name="discount-type"
225
+ value="PERCENT"
226
+ checked={discountType === 'PERCENT'}
227
+ onChange={() => setDiscountType('PERCENT')}
228
+ />{' '}
229
+ {t('percentage', 'Percentage')}
230
+ </label>
231
+ </div>
232
+
233
+ {discountType === 'PERCENT' ? (
234
+ <NumberInput
235
+ id="discount-percentage"
236
+ label={t('discountPercentage', 'Discount Percentage')}
237
+ min={0}
238
+ max={100}
239
+ value={discountPercentage}
240
+ invalid={discountPercentage !== '' && (Number(discountPercentage) < 1 || Number(discountPercentage) > 100)}
241
+ invalidText={t('discountPercentageInvalid', 'Percentage must be between 1 and 100')}
242
+ onChange={(_event, state) => setDiscountPercentage(String(state.value))}
243
+ />
244
+ ) : (
245
+ <NumberInput
246
+ id="discount-amount"
247
+ label={t('discountAmount', 'Discount Amount')}
248
+ min={0}
249
+ max={amountDue}
250
+ value={discountAmount}
251
+ invalid={discountAmount !== '' && (Number(discountAmount) < 1 || Number(discountAmount) > amountDue)}
252
+ invalidText={t('discountAmountInvalid', 'Amount must be greater than zero and not exceed the balance')}
253
+ onChange={(_event, state) => setDiscountAmount(String(state.value))}
254
+ />
255
+ )}
256
+ </Modal>
257
+ </>
258
+ );
259
+ };
260
+
261
+ export default FinalizeBill;
@@ -0,0 +1,68 @@
1
+ import { openmrsFetch, restBaseUrl, SessionLocation, useSession } from "@openmrs/esm-framework";
2
+ import { BillStatus, MappedBill, PatientInvoice, PaymentRequestPayload } from "./types";
3
+ import useSWR from "swr";
4
+ import { parsePatientDisplay } from "./helpers";
5
+
6
+ export const finalizeBill = (billUuid: string) => {
7
+ const url = `${restBaseUrl}/billing/bill/${billUuid}`;
8
+ return openmrsFetch(url, {
9
+ method: 'POST',
10
+ body: { status: BillStatus.POSTED },
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ },
14
+ });
15
+ };
16
+
17
+ export const processBillPayment = (payload: PaymentRequestPayload, billUuid: string) => {
18
+ const url = `${restBaseUrl}/billing/bill/${billUuid}/payment`;
19
+
20
+ return openmrsFetch(url, {
21
+ method: 'POST',
22
+ body: payload,
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ },
26
+ });
27
+ };
28
+
29
+ export function useBill(billUuid: string) {
30
+ const url = `${restBaseUrl}/billing/bill/${billUuid}`;
31
+ const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: PatientInvoice }>(
32
+ billUuid ? url : null,
33
+ openmrsFetch,
34
+ );
35
+
36
+ let bill = data?.data as PatientInvoice;
37
+
38
+ return { bill, error, isLoading, isValidating, mutate };
39
+ }
40
+
41
+ export const mapBillProperties = (bill: PatientInvoice): MappedBill => {
42
+ const activeLineItems = bill?.lineItems?.filter((item) => !item.voided) ?? [];
43
+ const { identifier, name } = parsePatientDisplay(bill?.patient?.display);
44
+
45
+ return {
46
+ ...bill,
47
+ patientName: name,
48
+ identifier: identifier,
49
+ patientUuid: bill?.patient?.uuid,
50
+ visitUuid: bill?.visit?.uuid,
51
+ cashPointUuid: bill?.cashPoint?.uuid,
52
+ cashPointName: bill?.cashPoint?.name,
53
+ cashPointLocation: bill?.cashPoint?.location?.display,
54
+ status: bill.status as BillStatus,
55
+ lineItems: activeLineItems,
56
+ billingService: activeLineItems.map((lineItem) => lineItem?.item || lineItem?.billableService || '--').join(' '),
57
+ totalAmount: bill.total,
58
+ netAmount: bill.amountAfterDiscount,
59
+ tenderedAmount: (bill?.payments ?? [])
60
+ .map((item) => item.amountTendered ?? 0)
61
+ .reduce((prev, curr) => prev + curr, 0),
62
+ };
63
+ };
64
+
65
+ export function useDefaultFacility(): { data: SessionLocation | null } {
66
+ const { sessionLocation } = useSession();
67
+ return { data: sessionLocation };
68
+ }