Skip to content

Commit

Permalink
CM-731: create payroll from unpaid invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Feb 19, 2024
1 parent 3cd1f08 commit 88ab0e5
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 62 deletions.
11 changes: 8 additions & 3 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,24 @@ const formatPayrollGQL = (payroll) => `
${payroll?.paymentMethod ? `paymentMethod: "${payroll.paymentMethod}"` : ''}
${`status: ${PAYROLL_STATUS.PENDING_APPROVAL}`}
${
payroll.jsonExt
payroll?.jsonExt
? `jsonExt: ${JSON.stringify(payroll.jsonExt)}`
: ''
}
${
payroll.dateValidFrom
payroll?.dateValidFrom
? `dateValidFrom: "${payroll.dateValidFrom}"`
: ''
}
${
payroll.dateValidTo
payroll?.dateValidTo
? `dateValidTo: "${payroll.dateValidTo}"`
: ''
}
${
payroll?.fromFailedInvoicesPayrollId
? `fromFailedInvoicesPayrollId: "${payroll.fromFailedInvoicesPayrollId}"`
: ''
}
`;

Expand Down
40 changes: 27 additions & 13 deletions src/components/payroll/BenefitConsumptionSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@openimis/fe-core';
import PhotoCameraOutlinedIcon from '@material-ui/icons/PhotoCameraOutlined';
import { fetchBenefitConsumptions } from '../../actions';
import { DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS } from '../../constants';
import { BENEFIT_CONSUMPTION_STATUS, DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS } from '../../constants';
import BenefitConsumptionFilter from './BenefitConsumptionFilter';

function BenefitConsumptionSearcher({
Expand All @@ -19,6 +19,7 @@ function BenefitConsumptionSearcher({
benefitConsumptions,
benefitConsumptionsPageInfo,
benefitConsumptionsTotalCount,
isPayrollFromFailedInvoices,
payrollUuid,
}) {
const modulesManager = useModulesManager();
Expand Down Expand Up @@ -51,7 +52,8 @@ function BenefitConsumptionSearcher({
(benefitConsumption) => benefitConsumption?.receipt,
(benefitConsumption) => benefitConsumption?.amount,
(benefitConsumption) => benefitConsumption?.type,
(benefitConsumption) => benefitConsumption?.status,
(benefitConsumption) => (isPayrollFromFailedInvoices
? BENEFIT_CONSUMPTION_STATUS.APPROVE_FOR_PAYMENT : benefitConsumption?.status),
];

const rowIdentifier = (benefitConsumption) => benefitConsumption.id;
Expand All @@ -68,16 +70,28 @@ function BenefitConsumptionSearcher({
['status', true],
];

const defaultFilters = () => ({
isDeleted: {
value: false,
filter: 'isDeleted: false',
},
payrollUuid: {
value: payrollUuid,
filter: `payrollUuid: "${payrollUuid}"`,
},
});
const defaultFilters = () => {
const filters = {
isDeleted: {
value: false,
filter:
'isDeleted: false',
},
payrollUuid: {
value: payrollUuid,
filter:
`payrollUuid: "${payrollUuid}"`,
},
};
if (isPayrollFromFailedInvoices) {
filters.status = {
value: BENEFIT_CONSUMPTION_STATUS.ACCEPTED,
filter:
`status: ${BENEFIT_CONSUMPTION_STATUS.ACCEPTED}`,
};
}
return filters;
};

const benefitConsumptionFilter = ({ filters, onChangeFilters }) => (
<BenefitConsumptionFilter filters={filters} onChangeFilters={onChangeFilters} />
Expand All @@ -87,7 +101,7 @@ function BenefitConsumptionSearcher({
<div>
<Searcher
module="payroll"
FilterPane={benefitConsumptionFilter}
FilterPane={!isPayrollFromFailedInvoices && benefitConsumptionFilter}
fetch={fetch}
items={benefitConsumptions}
itemsPageInfo={benefitConsumptionsPageInfo}
Expand Down
10 changes: 8 additions & 2 deletions src/components/payroll/BenefitConsumptionTabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function BenefitConsumptionsTabLabel({
);
}

function BenefitConsumptionsTabPanel({ value, rights, payrollUuid }) {
function BenefitConsumptionsTabPanel({
value, rights, payrollUuid, isPayrollFromFailedInvoices,
}) {
return (
<PublishedComponent
pubRef="policyHolder.TabPanel"
Expand All @@ -33,7 +35,11 @@ function BenefitConsumptionsTabPanel({ value, rights, payrollUuid }) {
>
{
rights.includes(RIGHT_PAYROLL_SEARCH) && payrollUuid && (
<BenefitConsumptionSearcher rights={rights} payrollUuid={payrollUuid} />
<BenefitConsumptionSearcher
rights={rights}
payrollUuid={payrollUuid}
isPayrollFromFailedInvoices={isPayrollFromFailedInvoices}
/>
)
}
</PublishedComponent>
Expand Down
59 changes: 31 additions & 28 deletions src/components/payroll/PayrollHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
PublishedComponent,
TextInput,
withModulesManager,
decodeId,
} from '@openimis/fe-core';
import AdvancedFiltersDialog from './AdvancedFiltersDialog';
import { CLEARED_STATE_FILTER } from '../../constants';
Expand Down Expand Up @@ -71,27 +70,31 @@ class PayrollHeadPanel extends FormPanel {
};

render() {
const { edited, classes, intl } = this.props;
const {
edited, classes, intl, readOnly, isPayrollFromFailedInvoices,
} = this.props;
const payroll = { ...edited };
const { appliedCustomFilters, appliedFiltersRowStructure } = this.state;
const readOnly = Boolean(payroll?.id);
return (
<>
<AdvancedFiltersDialog
object={payroll?.paymentPlan?.benefitPlan
? JSON.parse(JSON.parse(payroll.paymentPlan.benefitPlan))
: null}
objectToSave={payroll}
moduleName="social_protection"
objectType="BenefitPlan"
setAppliedCustomFilters={this.setAppliedCustomFilters}
appliedCustomFilters={appliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
readOnly={readOnly}
/>
{!isPayrollFromFailedInvoices
&& (
<AdvancedFiltersDialog
object={payroll?.paymentPlan?.benefitPlan
? JSON.parse(JSON.parse(payroll.paymentPlan.benefitPlan))
: null}
objectToSave={payroll}
moduleName="social_protection"
objectType="BenefitPlan"
setAppliedCustomFilters={this.setAppliedCustomFilters}
appliedCustomFilters={appliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
readOnly={readOnly}
/>
)}
<Grid container className={classes.item}>
<Grid item xs={3} className={classes.item}>
<TextInput
Expand All @@ -100,7 +103,7 @@ class PayrollHeadPanel extends FormPanel {
value={payroll?.name}
required
onChange={(name) => this.updateAttribute('name', name)}
readOnly={readOnly}
readOnly={isPayrollFromFailedInvoices ? !isPayrollFromFailedInvoices : readOnly}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
Expand Down Expand Up @@ -133,18 +136,18 @@ class PayrollHeadPanel extends FormPanel {
filterLabels={false}
onChange={(paymentCycle) => this.updateAttribute('paymentCycle', paymentCycle)}
value={payroll?.paymentCycle}
readOnly={isPayrollFromFailedInvoices ? !isPayrollFromFailedInvoices : readOnly}
/>
</Grid>
{readOnly && !isPayrollFromFailedInvoices && (
<Grid item xs={3} className={classes.item}>
<PayrollStatusPicker
required
withNull={false}
readOnly={readOnly}
value={!!payroll?.status && payroll.status}
/>
</Grid>
{readOnly && (
<Grid item xs={3} className={classes.item}>
<PayrollStatusPicker
required
withNull={false}
readOnly={readOnly}
value={!!payroll?.status && payroll.status}
/>
</Grid>
)}
<Grid item xs={3} className={classes.item}>
<PaymentMethodPicker
Expand Down
6 changes: 4 additions & 2 deletions src/components/payroll/PayrollTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const useStyles = makeStyles((theme) => ({
}));

function PayrollTab({
rights, setConfirmedAction, payrollUuid, isInTask, payroll,
rights, setConfirmedAction, payrollUuid, isInTask, payroll, isPayrollFromFailedInvoices,
}) {
const classes = useStyles();

Expand Down Expand Up @@ -72,10 +72,11 @@ function PayrollTab({
tabStyle={tabStyle}
payrollUuid={payrollUuid}
isInTask={isInTask}
isPayrollFromFailedInvoices={isPayrollFromFailedInvoices}
/>
</div>
<div style={{ float: 'right', paddingRight: '16px' }}>
{payrollUuid && (
{payrollUuid && !isPayrollFromFailedInvoices && (
<Button
onClick={() => downloadPayrollData(payrollUuid, payroll.name)}
color="#DFEDEF"
Expand Down Expand Up @@ -105,6 +106,7 @@ function PayrollTab({
setConfirmedAction={setConfirmedAction}
payrollUuid={payrollUuid}
isInTask={isInTask}
isPayrollFromFailedInvoices={isPayrollFromFailedInvoices}
/>
</Paper>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/payroll/PayrollTaskTabPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
} from '../../constants';

function PayrollTaskTabLabel({
onChange, tabStyle, isSelected, modulesManager, payrollUuid, isInTask,
onChange, tabStyle, isSelected, modulesManager, payrollUuid, isInTask, isPayrollFromFailedInvoices,
}) {
const { formatMessage } = useTranslations(MODULE_NAME, modulesManager);
if (!payrollUuid || isInTask) {
if (!payrollUuid || isInTask || isPayrollFromFailedInvoices) {
return null;
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DialogTitle from '@material-ui/core/DialogTitle';
import {
useModulesManager,
useTranslations,
useHistory,
} from '@openimis/fe-core';
import {
Paper,
Expand All @@ -16,7 +17,12 @@ import {
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 {
MODULE_NAME,
BENEFIT_CONSUMPTION_STATUS,
PAYROLL_PAYROLL_ROUTE,
PAYROLL_FROM_FAILED_INVOICES_URL_PARAM,
} from '../../../constants';
import downloadPayroll from '../../../utils/export';

import BenefitConsumptionSearcherModal from '../BenefitConsumptionSearcherModal';
Expand All @@ -25,6 +31,9 @@ function PaymentReconcilationSummarytDialog({
classes,
payroll,
}) {
const history = useHistory();
const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager);
const [isOpen, setIsOpen] = useState(false);
const [totalBeneficiaries, setTotalBeneficiaries] = useState(0);
const [selectedBeneficiaries, setSelectedBeneficiaries] = useState(0);
Expand All @@ -39,8 +48,11 @@ function PaymentReconcilationSummarytDialog({
setIsOpen(false);
};

const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager);
const handleCreatePaymentForFailedInvoice = () => {
history.push(
`/${modulesManager.getRef(PAYROLL_PAYROLL_ROUTE)}/${payroll?.id}/${PAYROLL_FROM_FAILED_INVOICES_URL_PARAM}`,
);
};

useEffect(() => {
if (isOpen) {
Expand Down Expand Up @@ -160,7 +172,7 @@ function PaymentReconcilationSummarytDialog({
<div style={{ maxWidth: '3000px' }}>
<div style={{ float: 'left' }}>
<Button
onClick={() => {}}
onClick={handleCreatePaymentForFailedInvoice}
variant="contained"
color="primary"
disabled={totalBeneficiaries === selectedBeneficiaries}
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ export const BENEFIT_CONSUMPTION_STATUS_LIST = [
];

export const BENEFIT_PLAN_CONTENT_TYPE_ID = 175;

export const PAYROLL_FROM_FAILED_INVOICES_URL_PARAM = 'createPayrollFromFailedInvoices=true';
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const DEFAULT_CONFIG = {
{ path: ROUTE_PAYROLLS, component: PayrollsPage },
{ path: ROUTE_PAYROLLS_APPROVED, component: ApprovedPayrollsPage },
{ path: ROUTE_PAYROLLS_RECONCILED, component: ReconciledPayrollsPage },
{ path: `${ROUTE_PAYROLL}/:payroll_uuid?`, component: PayrollPage },
{ path: `${ROUTE_PAYROLL}/:payroll_uuid?/:createPayrollFromFailedInvoices?`, component: PayrollPage },
],
'invoice.MainMenu': [
{
Expand Down
Loading

0 comments on commit 88ab0e5

Please sign in to comment.