Skip to content

Commit

Permalink
(feat) KHP3-7240 : Add ability to print receipt for exempted services…
Browse files Browse the repository at this point in the history
… and partial payments
  • Loading branch information
donaldkibet committed Jan 8, 2025
1 parent ad56e2d commit 71abba6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ const BillingTabs = () => {
<TabPanel>
<BillsTable />
</TabPanel>
<TabPanel>
<PatientBillsScreen />
</TabPanel>
<TabPanel>{/* <PatientBillsScreen /> */}</TabPanel>
</TabPanels>
</Tabs>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/esm-billing-app/src/invoice/invoice.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -130,7 +130,7 @@ const Invoice: React.FC = () => {
</section>
</div>
<div className={styles.actionArea}>
<PrintPaidBillReceiptAction bill={bill} />
<ReceiptPrintButton bill={bill} />
<Button
onClick={handlePrint}
kind="tertiary"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<ReceiptPrintButtonProps> = ({ bill }) => {
const { t } = useTranslation();

const isPrintingDisabled = shouldDisablePrinting(bill);

const handlePrintClick = () => {
const dispose = showModal('paid-bill-receipt-print-preview-modal', {
onClose: () => dispose(),
bill,
});
};

return (
<Button
kind="secondary"
size="sm"
disabled={isPrintingDisabled}
onClick={handlePrintClick}
renderIcon={Printer}
iconDescription={t('printReceipt', 'Print receipt')}>
{t('printReceipt', 'Print receipt')}
</Button>
);
};

/**
* 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;
1 change: 0 additions & 1 deletion packages/esm-billing-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down

0 comments on commit 71abba6

Please sign in to comment.