Skip to content

Commit

Permalink
CM-938: added possibility to delete invoice from payroll
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Jul 15, 2024
1 parent a472335 commit d56ca9e
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 29 deletions.
11 changes: 11 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ export function deletePayrolls(payroll, clientMutationLabel) {
);
}

export function deleteBenefitConsumption(benefit, clientMutationLabel) {
const uuid = isBase64Encoded(benefit.id) ? decodeId(benefit?.id) : benefit?.id;
const benefitUuids = `ids: ["${uuid}"]`;
return PERFORM_MUTATION(
MUTATION_SERVICE.BENEFIT_CONSUMPTION.DELETE,
benefitUuids,
ACTION_TYPE.DELETE_BENEFIT_CONSUMPTION,
clientMutationLabel,
);
}

export function createPayroll(payroll, clientMutationLabel) {
return PERFORM_MUTATION(
MUTATION_SERVICE.PAYROLL.CREATE,
Expand Down
122 changes: 96 additions & 26 deletions src/components/payroll/BenefitConsumptionSearcherModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import React, { useState } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import {
Searcher, useModulesManager, useTranslations,
} from '@openimis/fe-core';
import PhotoCameraOutlinedIcon from '@material-ui/icons/PhotoCameraOutlined';
import { fetchBenefitAttachments } from '../../actions';
import { DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS, PAYROLL_STATUS } from '../../constants';
import { fetchBenefitAttachments, deleteBenefitConsumption } from '../../actions';
import {
DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS, PAYROLL_STATUS,
} from '../../constants';
import BenefitConsumptionFilterModal from './BenefitConsumptionFilterModal';
import ErrorSummaryModal from './dialogs/ErrorSummaryModal';
import { mutationLabel } from '../../utils/string-utils';

function BenefitConsumptionSearcherModal({
fetchBenefitAttachments,
Expand All @@ -23,15 +31,50 @@ function BenefitConsumptionSearcherModal({
payrollUuid,
reconciledMode,
payrollDetail,
deleteBenefitConsumption,
}) {
const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager);
const [selectedBenefitAttachment, setSelectedBenefitAttachment] = useState(null);
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
const [benefitToDelete, setBenefitToDelete] = useState(null);

const fetch = (params) => {
fetchBenefitAttachments(modulesManager, params);
};

const defaultFilters = () => {
const filters = {
isDeleted: {
value: false,
filter: 'isDeleted: false',
},
payrollUuid: {
value: payrollUuid,
filter: `payrollUuid: "${payrollUuid}"`,
},
};
if (reconciledMode && payrollDetail.paymentMethod !== 'StrategyOnlinePayment') {
filters.benefit_Status = {
value: 'RECONCILED',
filter: `benefit_Status: ${PAYROLL_STATUS.RECONCILED}`,
};
}
return filters;
};

const defaultFiltersArray = () => {
const filters = [
'isDeleted: false',
`first: ${DEFAULT_PAGE_SIZE}`,
`payrollUuid: "${payrollUuid}"`,
];
if (reconciledMode && payrollDetail.paymentMethod !== 'StrategyOnlinePayment') {
filters.push(`benefit_Status: ${PAYROLL_STATUS.RECONCILED}`);
}
return filters;
};

const headers = () => [
'benefitConsumption.photo',
'benefitConsumption.individual.firstName',
Expand All @@ -45,14 +88,30 @@ function BenefitConsumptionSearcherModal({
'',
];

const confirmDeleteBenefitConsumption = (benefit) => {
setBenefitToDelete(benefit);
setOpenConfirmDialog(true);
};

const handleDeleteBenefitConsumption = () => {
deleteBenefitConsumption(
benefitToDelete.benefit,
formatMessageWithValues('payroll.mutation.deleteLabel', mutationLabel(benefitToDelete.benefit.code)),
);
setOpenConfirmDialog(false);
setBenefitToDelete(null);
const filters = defaultFiltersArray();
fetchBenefitAttachments(modulesManager, filters); // Refresh the searcher after deletion
};

const checkBenefitDueDate = (benefitAttachment) => {
if (!benefitAttachment.benefit.receipt) {
return ''; // return empty string if datePayed is null
}

return (
benefitAttachment.benefit && benefitAttachment.benefit.dateDue >= benefitAttachment.bill.datePayed)
? 'True' : 'False';
benefitAttachment.benefit && benefitAttachment.benefit.dateDue >= benefitAttachment.bill.datePayed
) ? 'True' : 'False';
};

const itemFormatters = () => [
Expand Down Expand Up @@ -84,7 +143,7 @@ function BenefitConsumptionSearcherModal({
</Button>
),
(benefitAttachment) => (
payrollDetail.paymentMethod === 'StrategyOnlinePayment' && payrollDetail.status === 'RECONCILED'
payrollDetail.paymentMethod === 'StrategyOnlinePayment' && payrollDetail.status === PAYROLL_STATUS.RECONCILED
&& benefitAttachment.benefit.status !== 'RECONCILED' && (
<Button
onClick={() => setSelectedBenefitAttachment(benefitAttachment)}
Expand All @@ -95,6 +154,18 @@ function BenefitConsumptionSearcherModal({
</Button>
)
),
(benefitAttachment) => (
payrollDetail.status === PAYROLL_STATUS.PENDING_APPROVAL
&& benefitAttachment.benefit.status !== 'PENDING_DELETION' && (
<Button
onClick={() => confirmDeleteBenefitConsumption(benefitAttachment)}
variant="contained"
style={{ backgroundColor: '#b80000', color: 'white' }}
>
{formatMessage('payroll.summary.benefit_delete')}
</Button>
)
),
];

const rowIdentifier = (benefitAttachment) => benefitAttachment.id;
Expand All @@ -108,26 +179,6 @@ function BenefitConsumptionSearcherModal({
['benefit_dateDue', true],
];

const defaultFilters = () => {
const filters = {
isDeleted: {
value: false,
filter: 'isDeleted: false',
},
payrollUuid: {
value: payrollUuid,
filter: `payrollUuid: "${payrollUuid}"`,
},
};
if (reconciledMode && payrollDetail.paymentMethod !== 'StrategyOnlinePayment') {
filters.benefit_Status = {
value: 'RECONCILED',
filter: `benefit_Status: ${PAYROLL_STATUS.RECONCILED}`,
};
}
return filters;
};

const benefitConsumptionFilterModal = ({ filters, onChangeFilters }) => (
<BenefitConsumptionFilterModal filters={filters} onChangeFilters={onChangeFilters} />
);
Expand Down Expand Up @@ -161,6 +212,25 @@ function BenefitConsumptionSearcherModal({
benefitAttachment={selectedBenefitAttachment}
/>
)}
<Dialog
open={openConfirmDialog}
onClose={() => setOpenConfirmDialog(false)}
>
<DialogTitle>{formatMessage('benefitConsumption.delete.confirm.title')}</DialogTitle>
<DialogContent>
<DialogContentText>
{formatMessage('benefitConsumption.delete.confirm.message')}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenConfirmDialog(false)} color="primary">
{formatMessage('benefitConsumption.cancel')}
</Button>
<Button onClick={handleDeleteBenefitConsumption} color="primary" autoFocus>
{formatMessage('benefitConsumption.confirm')}
</Button>
</DialogActions>
</Dialog>
</div>
);
}
Expand All @@ -175,7 +245,7 @@ const mapStateToProps = (state) => ({
});

const mapDispatchToProps = (dispatch) => bindActionCreators(
{ fetchBenefitAttachments },
{ fetchBenefitAttachments, deleteBenefitConsumption },
dispatch,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function PaymentPendingPayrollPaymentDialog({
top: '50%',
left: '50%',
transform: 'translate(-50%,-50%)',
width: '75%',
maxWidth: '75%',
width: '90%',
maxWidth: '90%',
},
}}
>
Expand Down
6 changes: 6 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ACTION_TYPE = {
MAKE_PAYMENT_PAYROLL: 'PAYROLL_MUTATION_MAKE_PAYMENT_PAYROLL',
GET_PAYROLL_PAYMENT_FILES: 'GET_PAYROLL_PAYMENT_FILES',
BENEFITS_SUMMARY: 'PAYROLL_BENEFITS_SUMMARY',
DELETE_BENEFIT_CONSUMPTION: 'BENEFIT_CONSUMPTION_MUTATION_DELETE_BENEFIT_CONSUMPTION',
};

export const MUTATION_SERVICE = {
Expand All @@ -49,6 +50,9 @@ export const MUTATION_SERVICE = {
REJECT: 'rejectPayroll',
MAKE_PAYMENT: 'makePaymentForPayroll',
},
BENEFIT_CONSUMPTION: {
DELETE: 'deleteBenefitConsumption',
},
};

const STORE_STATE = {
Expand Down Expand Up @@ -448,6 +452,8 @@ function reducer(
return dispatchMutationResp(state, MUTATION_SERVICE.PAYROLL.CREATE, action);
case SUCCESS(ACTION_TYPE.DELETE_PAYROLL):
return dispatchMutationResp(state, MUTATION_SERVICE.PAYROLL.DELETE, action);
case SUCCESS(ACTION_TYPE.DELETE_BENEFIT_CONSUMPTION):
return dispatchMutationResp(state, MUTATION_SERVICE.BENEFIT_CONSUMPTION.DELETE, action);
default:
return state;
}
Expand Down
8 changes: 7 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@
"payroll.payrollPaymentFilesSearcher.results": "{totalCount} Files Found",
"payroll.PayrollPaymentFilesTab.label": "Payment Files",
"payroll.summary.benefit_error": "Error",
"payroll.summary.benefit_delete": "Delete",
"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"
"payroll.errorSummary.title": "Error summary",

"payroll.benefitConsumption.confirm": "Confirm",
"payroll.benefitConsumption.cancel": "Cancel",
"payroll.benefitConsumption.delete.confirm.title": "Delete Benefit Consumption",
"payroll.benefitConsumption.delete.confirm.message": "Are you sure you want to delete the Benefit Consumption? Once you click confirm, additional approval on the task level is required to permanently delete it."
}

0 comments on commit d56ca9e

Please sign in to comment.