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-932: added make payment button for digital strategy #53

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
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,
);
}
2 changes: 2 additions & 0 deletions src/components/payroll/BenefitConsumptionSearcherModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function BenefitConsumptionSearcherModal({
'benefitConsumption.dateDue',
'benefitConsumption.payedOnTime',
'benefitConsumption.paymentDate',
'benefitConsumption.status',
'',
];

Expand Down Expand Up @@ -68,6 +69,7 @@ function BenefitConsumptionSearcherModal({
? ''
: benefitAttachment?.bill?.datePayed
),
(benefitAttachment) => benefitAttachment?.benefit?.status,
(benefitAttachment) => (
<Button
onClick={() => {}}
Expand Down
38 changes: 36 additions & 2 deletions src/components/payroll/dialogs/PaymentApproveForPaymentSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
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 @@
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,14 @@
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);
console.log(approved);

Check warning on line 71 in src/components/payroll/dialogs/PaymentApproveForPaymentSummary.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
sniedzielski marked this conversation as resolved.
Show resolved Hide resolved
setApprovedBeneficiaries(approved);

let totalAmount = 0;
let reconciledAmount = 0;
Expand Down Expand Up @@ -99,6 +108,14 @@
);
};

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

const downloadPayrollData = (payrollUuid, payrollName) => {
downloadPayroll(payrollUuid, payrollName);
};
Expand Down Expand Up @@ -188,7 +205,11 @@
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 +245,18 @@
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 +283,7 @@
closePayroll,
rejectPayroll,
fetchPayroll,
makePaymentForPayroll,
}, dispatch);

export default connect(mapStateToProps, mapDispatchToProps)(PaymentApproveForPaymentDialog);
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
1 change: 1 addition & 0 deletions 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
Loading