-
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) : added a refund option to the bill manager. (#296)
* feat: initial work on refund item functionality * fix: billable service uuid for refunded bills * refactor: filter out the refunded bill line items * feat: credit amount header * feat: highlighting for refunded bill item * refactor: comments out and adding a no refunded item fallback * fix: removed space on line item status * generated translations and index.ts * fix: background shade for only refunded line items
- Loading branch information
1 parent
baa4d7f
commit b07fe0b
Showing
8 changed files
with
190 additions
and
37 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
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
84 changes: 84 additions & 0 deletions
84
packages/esm-billing-app/src/billable-services/bill-manager/modals/refund-bill.modal.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,84 @@ | ||
import React, { useState } from 'react'; | ||
import { ModalHeader, ModalBody, ModalFooter, Button, Loading } from '@carbon/react'; | ||
import styles from './cancel-bill.scss'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { showSnackbar } from '@openmrs/esm-framework'; | ||
import { processBillItems } from '../../../billing.resource'; | ||
import { mutate } from 'swr'; | ||
import { LineItem, MappedBill } from '../../../types'; | ||
|
||
export const RefundBillModal: React.FC<{ | ||
onClose: () => void; | ||
bill: MappedBill; | ||
lineItem: LineItem; | ||
}> = ({ onClose, bill, lineItem }) => { | ||
const { t } = useTranslation(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const refundBillItems = () => { | ||
const lineItemToBeRefunded = { | ||
item: lineItem.uuid, | ||
quantity: lineItem.quantity, | ||
price: -lineItem.price, | ||
priceName: lineItem.priceName, | ||
priceUuid: lineItem.priceUuid, | ||
lineItemOrder: lineItem.lineItemOrder, | ||
paymentStatus: 'CREDITED', | ||
billableService: lineItem.billableService.split(':').at(0), | ||
}; | ||
|
||
const billWithRefund = { | ||
cashPoint: bill.cashPointUuid, | ||
cashier: bill.cashier.uuid, | ||
lineItems: [lineItemToBeRefunded], | ||
payments: bill.payments, | ||
patient: bill.patientUuid, | ||
status: bill.status, | ||
}; | ||
|
||
setIsLoading(true); | ||
onClose(); | ||
processBillItems(billWithRefund) | ||
.then(() => { | ||
mutate((key) => typeof key === 'string' && key.startsWith('/ws/rest/v1/cashier/bill'), undefined, { | ||
revalidate: true, | ||
}); | ||
showSnackbar({ | ||
title: t('billItems', 'Refund Items'), | ||
subtitle: 'Item has been successfully refunded.', | ||
kind: 'success', | ||
timeoutInMs: 3000, | ||
}); | ||
}) | ||
.catch((error) => { | ||
showSnackbar({ title: 'An error occurred trying to refund item', kind: 'error', subtitle: error.message }); | ||
}) | ||
.finally(() => setIsLoading(false)); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<ModalHeader onClose={onClose} className={styles.modalHeaderLabel} closeModal={onClose}> | ||
{t('refundBill', 'Refund Bill')} | ||
</ModalHeader> | ||
<ModalBody className={styles.modalHeaderHeading}> | ||
{t('refundBillDescription', 'Are you sure you want to refund this bill? Proceed cautiously.')} | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button kind="secondary" onClick={onClose}> | ||
{t('cancel', 'Cancel')} | ||
</Button> | ||
<Button kind="danger" onClick={refundBillItems}> | ||
{isLoading ? ( | ||
<div className={styles.loading_wrapper}> | ||
<Loading className={styles.button_spinner} withOverlay={false} small /> | ||
{t('processingPayment', 'Processing Payment')} | ||
</div> | ||
) : ( | ||
t('refund', 'Refund') | ||
)} | ||
</Button> | ||
</ModalFooter> | ||
</React.Fragment> | ||
); | ||
}; |
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
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