diff --git a/packages/esm-billing-app/src/invoice/invoice.component.tsx b/packages/esm-billing-app/src/invoice/invoice.component.tsx index 74055bbcc..809ffd279 100644 --- a/packages/esm-billing-app/src/invoice/invoice.component.tsx +++ b/packages/esm-billing-app/src/invoice/invoice.component.tsx @@ -23,7 +23,7 @@ import { LineItem } from '../types'; import InvoiceTable from './invoice-table.component'; import styles from './invoice.scss'; import Payments from './payments/payments.component'; -import PrintPaidBillReceiptAction from './print-bill-receipt/print-receipt-action.component'; +import ReceiptPrintButton from './print-bill-receipt/receipt-print-button.component'; import PrintableInvoice from './printable-invoice/printable-invoice.component'; interface InvoiceDetailsProps { @@ -130,7 +130,7 @@ const Invoice: React.FC = () => {
- + - ); -}; - -export default PrintPaidBillReceiptAction; diff --git a/packages/esm-billing-app/src/invoice/print-bill-receipt/receipt-print-button.component.tsx b/packages/esm-billing-app/src/invoice/print-bill-receipt/receipt-print-button.component.tsx new file mode 100644 index 000000000..6ccc6a130 --- /dev/null +++ b/packages/esm-billing-app/src/invoice/print-bill-receipt/receipt-print-button.component.tsx @@ -0,0 +1,55 @@ +import { Button } from '@carbon/react'; +import { Printer } from '@carbon/react/icons'; +import { showModal } from '@openmrs/esm-framework'; +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { MappedBill, PaymentStatus } from '../../types'; + +interface ReceiptPrintButtonProps { + bill: MappedBill; +} + +const ReceiptPrintButton: React.FC = ({ bill }) => { + const { t } = useTranslation(); + + const isPrintingDisabled = shouldDisablePrinting(bill); + + const handlePrintClick = () => { + const dispose = showModal('paid-bill-receipt-print-preview-modal', { + onClose: () => dispose(), + bill, + }); + }; + + return ( + + ); +}; + +/** + * Determines if receipt printing should be disabled based on bill status + * @param bill - The bill to check + * @returns true if printing should be disabled, false otherwise + */ +function shouldDisablePrinting(bill: MappedBill): boolean { + const hasPayments = bill.payments.length > 0; + const hasExemptedItems = bill.lineItems.some((item) => item.paymentStatus === PaymentStatus.EXEMPTED); + + // If there are exempted items, we need special handling + if (hasExemptedItems) { + return !hasExemptedItems; + } + + // For regular bills, disable if there are no payments + return !hasPayments; +} + +export default ReceiptPrintButton; diff --git a/packages/esm-billing-app/translations/en.json b/packages/esm-billing-app/translations/en.json index 569b0e2ba..392a2691a 100644 --- a/packages/esm-billing-app/translations/en.json +++ b/packages/esm-billing-app/translations/en.json @@ -234,7 +234,6 @@ "printingInvoice": "Printing invoice...", "printInvoice": "Print invoice", "printReceipt": "Print receipt", - "printRecept": "Print receipt", "proceedToCare": "Proceed to care", "processClaim": "Process Claim", "processing": "Processing...",