@kenyaemr/esm-billing-app 5.4.2-pre.2269 → 5.4.2-pre.2271

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.
@@ -1,57 +0,0 @@
1
- import { Button } from '@carbon/react';
2
- import { Printer } from '@carbon/react/icons';
3
- import { restBaseUrl, showModal } from '@openmrs/esm-framework';
4
- import React from 'react';
5
- import { useTranslation } from 'react-i18next';
6
- import { MappedBill, PaymentStatus } from '../../types';
7
- import startCase from 'lodash-es/startCase';
8
-
9
- interface ReceiptPrintButtonProps {
10
- bill: MappedBill;
11
- }
12
-
13
- const ReceiptPrintButton: React.FC<ReceiptPrintButtonProps> = ({ bill }) => {
14
- const { t } = useTranslation();
15
-
16
- const isPrintingDisabled = shouldDisablePrinting(bill);
17
-
18
- const handlePrintClick = () => {
19
- const dispose = showModal('print-preview-modal', {
20
- onClose: () => dispose(),
21
- title: `${t('receipt', 'Receipt')} ${bill?.receiptNumber} - ${startCase(bill?.patientName)}`,
22
- documentUrl: `/openmrs${restBaseUrl}/cashier/receipt?billId=${bill.id}`,
23
- });
24
- };
25
-
26
- return (
27
- <Button
28
- kind="secondary"
29
- size="sm"
30
- disabled={isPrintingDisabled}
31
- onClick={handlePrintClick}
32
- renderIcon={Printer}
33
- iconDescription={t('printReceipt', 'Print receipt')}>
34
- {t('printReceipt', 'Print receipt')}
35
- </Button>
36
- );
37
- };
38
-
39
- /**
40
- * Determines if receipt printing should be disabled based on bill status
41
- * @param bill - The bill to check
42
- * @returns true if printing should be disabled, false otherwise
43
- */
44
- function shouldDisablePrinting(bill: MappedBill): boolean {
45
- const hasPayments = bill?.payments?.length > 0;
46
- const hasExemptedItems = bill?.lineItems?.some((item) => item.paymentStatus === PaymentStatus.EXEMPTED);
47
-
48
- // If there are exempted items, we need special handling
49
- if (hasExemptedItems) {
50
- return !hasExemptedItems;
51
- }
52
-
53
- // For regular bills, disable if there are no payments
54
- return !hasPayments;
55
- }
56
-
57
- export default ReceiptPrintButton;