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

CM-951: added button to display error for digital means of payment #54

Merged
merged 3 commits into from
Jun 25, 2024
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
12 changes: 11 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const BENEFIT_CONSUMPTION_SUMMARY_PROJECTION = () => [
];

const BENEFIT_ATTACHMENT_PROJECTION = () => [
'benefit{id, status, code, dateDue, receipt, individual {firstName, lastName}}',
'benefit{id, status, code, dateDue, receipt, individual {firstName, lastName}, jsonExt}',
'bill{id, code, terms, amountTotal, datePayed}',
];

Expand Down Expand Up @@ -290,3 +290,13 @@ export function rejectPayroll(payroll, clientMutationLabel) {
clientMutationLabel,
);
}

export function makePaymentForPayroll(payroll, clientMutationLabel) {
const payrollUuids = `ids: ["${payroll?.id}"]`;
return PERFORM_MUTATION(
MUTATION_SERVICE.PAYROLL.MAKE_PAYMENT,
payrollUuids,
ACTION_TYPE.MAKE_PAYMENT_PAYROLL,
clientMutationLabel,
);
}
28 changes: 26 additions & 2 deletions src/components/payroll/BenefitConsumptionSearcherModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-param-reassign */
import React from 'react';
import React, { useState } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Button from '@material-ui/core/Button';
Expand All @@ -10,6 +10,7 @@ import PhotoCameraOutlinedIcon from '@material-ui/icons/PhotoCameraOutlined';
import { fetchBenefitAttachments } from '../../actions';
import { DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS, PAYROLL_STATUS } from '../../constants';
import BenefitConsumptionFilterModal from './BenefitConsumptionFilterModal';
import ErrorSummaryModal from './dialogs/ErrorSummaryModal';

function BenefitConsumptionSearcherModal({
fetchBenefitAttachments,
Expand All @@ -21,9 +22,11 @@ function BenefitConsumptionSearcherModal({
benefitAttachmentsTotalCount,
payrollUuid,
reconciledMode,
payrollDetail,
}) {
const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager);
const [selectedBenefitAttachment, setSelectedBenefitAttachment] = useState(null);

const fetch = (params) => {
fetchBenefitAttachments(modulesManager, params);
Expand All @@ -38,6 +41,7 @@ function BenefitConsumptionSearcherModal({
'benefitConsumption.dateDue',
'benefitConsumption.payedOnTime',
'benefitConsumption.paymentDate',
'benefitConsumption.status',
'',
];

Expand Down Expand Up @@ -68,6 +72,7 @@ function BenefitConsumptionSearcherModal({
? ''
: benefitAttachment?.bill?.datePayed
),
(benefitAttachment) => benefitAttachment?.benefit?.status,
(benefitAttachment) => (
<Button
onClick={() => {}}
Expand All @@ -78,6 +83,18 @@ function BenefitConsumptionSearcherModal({
{formatMessage('payroll.summary.confirm')}
</Button>
),
(benefitAttachment) => (
payrollDetail.paymentMethod === 'StrategyOnlinePayment' && payrollDetail.status === 'RECONCILED'
&& benefitAttachment.benefit.status !== 'RECONCILED' && (
<Button
onClick={() => setSelectedBenefitAttachment(benefitAttachment)}
variant="contained"
style={{ backgroundColor: '#b80000', color: 'white' }}
>
{formatMessage('payroll.summary.benefit_error')}
</Button>
)
),
];

const rowIdentifier = (benefitAttachment) => benefitAttachment.id;
Expand All @@ -102,7 +119,7 @@ function BenefitConsumptionSearcherModal({
filter: `payrollUuid: "${payrollUuid}"`,
},
};
if (reconciledMode) {
if (reconciledMode && payrollDetail.paymentMethod !== 'StrategyOnlinePayment') {
filters.benefit_Status = {
value: 'RECONCILED',
filter: `benefit_Status: ${PAYROLL_STATUS.RECONCILED}`,
Expand Down Expand Up @@ -137,6 +154,13 @@ function BenefitConsumptionSearcherModal({
rowIdentifier={rowIdentifier}
defaultFilters={defaultFilters()}
/>
{selectedBenefitAttachment && (
<ErrorSummaryModal
open={!!selectedBenefitAttachment}
onClose={() => setSelectedBenefitAttachment(null)}
benefitAttachment={selectedBenefitAttachment}
/>
)}
</div>
);
}
Expand Down
53 changes: 53 additions & 0 deletions src/components/payroll/dialogs/ErrorSummaryModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import {
Modal, Backdrop, Fade, Box, Typography, Button,
} from '@material-ui/core';
import { useTranslations, useModulesManager } from '@openimis/fe-core';

function ErrorSummaryModal({ open, onClose, benefitAttachment }) {
const modulesManager = useModulesManager();
const { formatMessage } = useTranslations('payroll', modulesManager);

const jsonExt = benefitAttachment?.benefit?.jsonExt ? JSON.parse(benefitAttachment.benefit.jsonExt) : {};
const outputGateway = `${jsonExt?.output_gateway}`;

return (
<Modal
open={open}
onClose={onClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={open}>
<Box
p={4}
style={{
backgroundColor: 'white', margin: 'auto', maxWidth: 400, outline: 'none',
}}
>
<Typography variant="h6">{formatMessage('payroll.errorSummary.title')}</Typography>
{/* Conditional rendering based on output_gateway */}
{outputGateway === null || outputGateway === 'undefined' ? (
<Typography>
{formatMessage('payroll.errorSummary.outputGateway.noInfo')}
</Typography>
) : (
<Typography>
{outputGateway}
</Typography>
)}
<Box display="flex" justifyContent="center" mt={2}>
<Button onClick={onClose} variant="contained" color="primary">
{formatMessage('payroll.errorSummary.close')}
</Button>
</Box>
</Box>
</Fade>
</Modal>
);
}

export default ErrorSummaryModal;
39 changes: 36 additions & 3 deletions src/components/payroll/dialogs/PaymentApproveForPaymentSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import Typography from '@material-ui/core/Typography';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { MODULE_NAME, BENEFIT_CONSUMPTION_STATUS } from '../../../constants';
import { closePayroll, fetchPayroll, rejectPayroll } from '../../../actions';
import {
closePayroll, fetchPayroll, makePaymentForPayroll, rejectPayroll,
} from '../../../actions';
import { mutationLabel } from '../../../utils/string-utils';
import BenefitConsumptionSearcherModal from '../BenefitConsumptionSearcherModal';
import downloadPayroll from '../../../utils/export';
Expand All @@ -29,12 +31,14 @@ function PaymentApproveForPaymentDialog({
rejectPayroll,
payrollDetail,
fetchPayroll,
makePaymentForPayroll,
}) {
const modulesManager = useModulesManager();
const [payrollUuid] = useState(payrollDetail?.id ?? null);
const [isOpen, setIsOpen] = useState(false);
const [totalBeneficiaries, setTotalBeneficiaries] = useState(0);
const [selectedBeneficiaries, setSelectedBeneficiaries] = useState(0);
const [approvedBeneficiaries, setApprovedBeneficiaries] = useState(0);
const [totalBillAmount, setTotalBillAmount] = useState(0);
const [totalReconciledBillAmount, setTotalReconciledBillAmount] = useState(0);

Expand All @@ -58,9 +62,13 @@ function PaymentApproveForPaymentDialog({
const selected = payroll.benefitConsumption.filter(
(benefit) => benefit.status === BENEFIT_CONSUMPTION_STATUS.RECONCILED,
).length;
const approved = payroll.benefitConsumption.filter(
(benefit) => benefit.status === BENEFIT_CONSUMPTION_STATUS.APPROVE_FOR_PAYMENT,
).length;

setTotalBeneficiaries(total);
setSelectedBeneficiaries(selected);
setApprovedBeneficiaries(approved);

let totalAmount = 0;
let reconciledAmount = 0;
Expand Down Expand Up @@ -99,6 +107,14 @@ function PaymentApproveForPaymentDialog({
);
};

const makePaymentForPayrollCallback = () => {
handleClose();
makePaymentForPayroll(
payrollDetail,
formatMessageWithValues('payroll.mutation.closeLabel', mutationLabel(payrollDetail)),
);
};

const downloadPayrollData = (payrollUuid, payrollName) => {
downloadPayroll(payrollUuid, payrollName);
};
Expand Down Expand Up @@ -170,7 +186,7 @@ function PaymentApproveForPaymentDialog({
<div
style={{ backgroundColor: '#DFEDEF' }}
>
<BenefitConsumptionSearcherModal payrollUuid={payrollDetail.id} />
<BenefitConsumptionSearcherModal payrollUuid={payrollDetail.id} payrollDetail={payrollDetail} />
</div>
</DialogContent>
<DialogActions
Expand All @@ -188,7 +204,11 @@ function PaymentApproveForPaymentDialog({
onClick={() => closePayrollCallback(payrollDetail)}
variant="contained"
color="primary"
disabled={selectedBeneficiaries === 0}
disabled={
payrollDetail.paymentMethod === 'StrategyOnlinePayment'
? approvedBeneficiaries === 0
: selectedBeneficiaries === 0
}
style={{
margin: '0 16px',
marginBottom: '15px',
Expand Down Expand Up @@ -224,6 +244,18 @@ function PaymentApproveForPaymentDialog({
paddingRight: '16px',
}}
>
{payrollDetail.paymentMethod === 'StrategyOnlinePayment' && (
<Button
onClick={() => makePaymentForPayrollCallback(payrollDetail)}
variant="contained"
color="primary"
style={{
margin: '0 16px',
}}
>
{formatMessage('payroll.summary.makePayment')}
</Button>
)}
<Button
onClick={handleClose}
variant="outlined"
Expand All @@ -250,6 +282,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
closePayroll,
rejectPayroll,
fetchPayroll,
makePaymentForPayroll,
}, dispatch);

export default connect(mapStateToProps, mapDispatchToProps)(PaymentApproveForPaymentDialog);
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ function PaymentReconcilationSummarytDialog({
top: '50%',
left: '50%',
transform: 'translate(-50%,-50%)',
width: '75%',
maxWidth: '75%',
width: '90%',
maxWidth: '90%',
},
}}
>
Expand Down Expand Up @@ -164,7 +164,7 @@ function PaymentReconcilationSummarytDialog({
<div
style={{ backgroundColor: '#DFEDEF' }}
>
<BenefitConsumptionSearcherModal payrollUuid={payrollDetail.id} reconciledMode />
<BenefitConsumptionSearcherModal payrollUuid={payrollDetail.id} payrollDetail={payrollDetail} reconciledMode />
</div>
</DialogContent>
<DialogActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function PaymentPendingPayrollPaymentDialog({
<div
style={{ backgroundColor: '#DFEDEF' }}
>
<BenefitConsumptionSearcherModal payrollUuid={payrollDetail.id} />
<BenefitConsumptionSearcherModal payrollUuid={payrollDetail.id} payrollDetail={payrollDetail} />
</div>
</DialogContent>
<DialogActions
Expand Down
2 changes: 2 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const ACTION_TYPE = {
GET_PAYMENT_METHODS: 'PAYROLL_PAYMENT_METHODS',
CLOSE_PAYROLL: 'PAYROLL_MUTATION_CLOSE_PAYROLL',
REJECT_PAYROLL: 'PAYROLL_MUTATION_REJECT_PAYROLL',
MAKE_PAYMENT_PAYROLL: 'PAYROLL_MUTATION_MAKE_PAYMENT_PAYROLL',
GET_PAYROLL_PAYMENT_FILES: 'GET_PAYROLL_PAYMENT_FILES',
BENEFITS_SUMMARY: 'PAYROLL_BENEFITS_SUMMARY',
};
Expand All @@ -46,6 +47,7 @@ export const MUTATION_SERVICE = {
DELETE: 'deletePayroll',
CLOSE: 'closePayroll',
REJECT: 'rejectPayroll',
MAKE_PAYMENT: 'makePaymentForPayroll',
},
};

Expand Down
8 changes: 7 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"payroll.viewReconciliationSummary": "View Reconciliation Summary",
"payroll.reconciliationSummary": "View Reconciliation Summary: {payrollName}",
"payroll.summary.confirm": "Confirm",
"payroll.summary.makePayment": "Make Payment",
"payroll.summary.name": "Name",
"payroll.summary.amount": "Amount",
"payroll.summary.receipt": "Receipt",
Expand Down Expand Up @@ -135,5 +136,10 @@
"payroll.payrollPaymentFile.error": "Error",
"payrollPaymentFile.download": "Download",
"payroll.payrollPaymentFilesSearcher.results": "{totalCount} Files Found",
"payroll.PayrollPaymentFilesTab.label": "Payment Files"
"payroll.PayrollPaymentFilesTab.label": "Payment Files",
"payroll.summary.benefit_error": "Error",
"payroll.errorSummary.close": "Close",
"payroll.errorSummary.outputGateway": "Output from payment gateway",
"payroll.errorSummary.outputGateway.noInfo": " There is no information from payment gateway why invoice is not reconciled. Please contact to administrator for further investigation!",
"payroll.errorSummary.title": "Error summary"
}
Loading