-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) KHP3-7240 : Add ability to print receipt for exempted services…
… and partial payments
- Loading branch information
1 parent
ad56e2d
commit 71abba6
Showing
5 changed files
with
58 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
packages/esm-billing-app/src/invoice/print-bill-receipt/print-receipt-action.component.tsx
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
packages/esm-billing-app/src/invoice/print-bill-receipt/receipt-print-button.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters