-
Notifications
You must be signed in to change notification settings - Fork 47
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) : added a refund option to the bill manager. #296
Changes from all commits
6333a77
9d09092
d485e2e
a7a8900
b386ac2
a49c3ed
50386f5
accde82
2c36e08
cc8fa22
66ca36a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,15 @@ | |
.dataTableSkeleton { | ||
margin-top: 0.625rem; | ||
} | ||
|
||
.refundedItem { | ||
background-color: #fee2e2; | ||
} | ||
|
||
.refundedItem:hover { | ||
background-color: #fecaca !important; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was actually a last resort. I couldnt get anything else to work. But I did not try the |
||
} | ||
|
||
.refundedItem:active { | ||
background-color: #fca5a5 !important; | ||
} |
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', | ||
amosmachora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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'), | ||
amosmachora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using colors from carbon token system e.g