Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) KHP3-7240 : Add ability to print receipt for exempted services and partial payments #534

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading