From da79186ecfe3ecb5b844a041317ced32e4d2239c Mon Sep 17 00:00:00 2001 From: Jan Date: Tue, 6 Feb 2024 15:56:59 +0100 Subject: [PATCH] CM-487: initial adjustments --- src/actions.js | 81 ++------- src/components/payroll/PayrollFilter.js | 89 ++++----- src/constants.js | 29 ++- src/index.js | 6 +- ...lFilter.js => BenefitConsumptionFilter.js} | 64 ++++--- .../payroll/BenefitConsumptionSearcher.js | 113 ++++++++++++ .../payroll/BenefitConsumptionTabPanel.js | 44 +++++ src/pages/payroll/PayrollBillSearcher.js | 172 ------------------ src/pages/payroll/PayrollBillTabPanel.js | 47 ----- src/pages/payroll/PayrollHeadPanel.js | 124 ++++++------- src/pages/payroll/PayrollPage.js | 5 +- src/pages/payroll/PayrollTab.js | 4 +- src/pickers/BenefitConsumptionStatusPicker.js | 26 +++ src/reducer.js | 64 +++---- src/translations/en.json | 30 +-- 15 files changed, 415 insertions(+), 483 deletions(-) rename src/pages/payroll/{PayrollBillFilter.js => BenefitConsumptionFilter.js} (63%) create mode 100644 src/pages/payroll/BenefitConsumptionSearcher.js create mode 100644 src/pages/payroll/BenefitConsumptionTabPanel.js delete mode 100644 src/pages/payroll/PayrollBillSearcher.js delete mode 100644 src/pages/payroll/PayrollBillTabPanel.js create mode 100644 src/pickers/BenefitConsumptionStatusPicker.js diff --git a/src/actions.js b/src/actions.js index 9327b3a..8b02edf 100644 --- a/src/actions.js +++ b/src/actions.js @@ -1,9 +1,9 @@ import { - formatPageQueryWithCount, - formatQuery, + decodeId, formatGQLString, formatMutation, - decodeId, + formatPageQueryWithCount, + formatQuery, graphql, } from '@openimis/fe-core'; @@ -22,7 +22,7 @@ export const PAYMENT_POINT_PROJECTION = (modulesManager) => [ `ppm ${modulesManager.getProjection('admin.UserPicker.projection')}`, ]; -const BILL_FULL_PROJECTION = () => [ +const BENEFIT_CONSUMPTION_PROJECTION = () => [ 'id', 'isDeleted', 'jsonExt', @@ -30,58 +30,20 @@ const BILL_FULL_PROJECTION = () => [ 'dateUpdated', 'dateValidFrom', 'dateValidTo', - 'replacementUuid', - 'thirdpartyType', - 'thirdpartyTypeName', - 'thirdpartyId', - 'thirdparty', - 'codeTp', - 'code', - 'codeExt', - 'dateDue', - 'datePayed', - 'amountDiscount', - 'amountNet', - 'amountTotal', - 'taxAnalysis', - 'status', - 'currencyTpCode', - 'currencyCode', - 'note', - 'terms', - 'paymentReference', - 'subjectType', - 'subjectTypeName', - 'subjectId', - 'subject', - 'dateBill', -]; - -const BENEFIT_PLAN_FULL_PROJECTION = () => [ 'id', - 'isDeleted', - 'dateCreated', - 'dateUpdated', - 'version', - 'dateValidFrom', - 'dateValidTo', - 'description', - 'replacementUuid', 'code', - 'name', - 'type', - 'maxBeneficiaries', - 'ceilingPerBeneficiary', - 'jsonExt', + 'individual {firstName, lastName}', + 'benefitAttachment {bill {id, code, terms}}', ]; const PAYROLL_PROJECTION = (modulesManager) => [ 'id', 'name', 'paymentMethod', - `benefitPlan { ${BENEFIT_PLAN_FULL_PROJECTION().join(' ')} }`, + 'paymentPlan { code }', `paymentPoint { ${PAYMENT_POINT_PROJECTION(modulesManager).join(' ')} }`, - `bill { ${BILL_FULL_PROJECTION().join(' ')} } `, + 'paymentCycle { runYear, runMonth }', + 'benefitConsumption{id, code,individual {firstName, lastName}, benefitAttachment{bill{id, code, terms}}}', 'jsonExt', 'status', 'dateValidFrom', @@ -93,26 +55,21 @@ const PAYMENT_METHOD_PROJECTION = () => [ 'paymentMethods {name}', ]; -const formatPaymentPointGQL = (paymentPoint) => { - const paymentPointGQL = ` +const formatPaymentPointGQL = (paymentPoint) => ` ${paymentPoint?.id ? `id: "${paymentPoint.id}"` : ''} ${paymentPoint?.name ? `name: "${formatGQLString(paymentPoint.name)}"` : ''} ${paymentPoint?.location ? `locationId: ${decodeId(paymentPoint.location.id)}` : ''} ${paymentPoint?.ppm ? `ppmId: "${decodeId(paymentPoint.ppm.id)}"` : ''} `; - return paymentPointGQL; -}; -const formatPayrollGQL = (payroll) => { - const payrollGQL = ` +const formatPayrollGQL = (payroll) => ` ${payroll?.id ? `id: "${payroll.id}"` : ''} ${payroll?.name ? `name: "${formatGQLString(payroll.name)}"` : ''} ${payroll?.paymentPoint ? `paymentPointId: "${decodeId(payroll.paymentPoint.id)}"` : ''} - ${payroll?.benefitPlan ? `benefitPlanId: "${decodeId(payroll.benefitPlan.id)}"` : ''} + ${payroll?.paymentPlan ? `paymentPlanId: "${decodeId(payroll.paymentPlan.id)}"` : ''} + ${payroll?.paymentCycle ? `paymentCycleId: "${decodeId(payroll.paymentCycle.id)}"` : ''} ${payroll?.paymentMethod ? `paymentMethod: "${payroll.paymentMethod}"` : ''} - ${payroll.includedUnpaid !== null && payroll.includedUnpaid !== undefined - ? `includedUnpaid: ${payroll.includedUnpaid}` : 'includedUnpaid: false'} - ${`status: ${PAYROLL_STATUS.CREATED}`} + ${`status: ${PAYROLL_STATUS.PENDING_APPROVAL}`} ${ payroll.jsonExt ? `jsonExt: ${JSON.stringify(payroll.jsonExt)}` @@ -129,8 +86,6 @@ const formatPayrollGQL = (payroll) => { : '' } `; - return payrollGQL; -}; const PERFORM_MUTATION = (mutationType, mutationInput, ACTION, clientMutationLabel) => { const mutation = formatMutation(mutationType, mutationInput, clientMutationLabel); @@ -221,14 +176,14 @@ export function createPayroll(payroll, clientMutationLabel) { ); } -export function fetchPayrollBills(modulesManager, params) { - const payload = formatPageQueryWithCount('billByPayroll', params, BILL_FULL_PROJECTION()); - return graphql(payload, ACTION_TYPE.GET_PAYROLL_BILLS); +export function fetchBenefitConsumptions(modulesManager, params) { + const payload = formatPageQueryWithCount('benefitConsumption', params, BENEFIT_CONSUMPTION_PROJECTION()); + return graphql(payload, ACTION_TYPE.GET_BENEFIT_CONSUMPTION); } export const clearPayrollBills = () => (dispatch) => { dispatch({ - type: CLEAR(ACTION_TYPE.GET_PAYROLL_BILLS), + type: CLEAR(ACTION_TYPE.GET_BENEFIT_CONSUMPTION), }); }; diff --git a/src/components/payroll/PayrollFilter.js b/src/components/payroll/PayrollFilter.js index 69d2024..c84abbf 100644 --- a/src/components/payroll/PayrollFilter.js +++ b/src/components/payroll/PayrollFilter.js @@ -74,49 +74,52 @@ function PayrollFilter({ onChange={onChangeStringFilter('name', CONTAINS_LOOKUP)} /> - - onChangeFilters([ - { - id: 'benefitPlan_Id', - value: benefitPlan, - filter: `benefitPlan_Id: "${benefitPlan?.id && decodeId(benefitPlan.id)}"`, - }, - ])} - /> - - )} - /> - - onChangeFilters([ - { - id: 'paymentPoint_Id', - value: paymentPoint, - filter: `paymentPoint_Id: "${paymentPoint?.id && decodeId(paymentPoint.id)}"`, - }, - ])} - /> - - )} - /> + + onChangeFilters([ + { + id: 'paymentPlan_Id', + value: paymentPlan, + filter: `paymentPlan_Id: "${paymentPlan?.id && decodeId(paymentPlan.id)}"`, + }, + ])} + /> + + + onChangeFilters([ + { + id: 'paymentPoint_Id', + value: paymentPoint, + filter: `paymentPoint_Id: "${paymentPoint?.id && decodeId(paymentPoint.id)}"`, + }, + ])} + /> + + + onChangeFilters([ + { + id: 'paymentCycle_Id', + value: paymentCycle, + filter: `paymentCycle_Id: "${paymentCycle?.id && decodeId(paymentCycle.id)}"`, + }, + ])} + /> + rights.includes(RIGHT_PAYROLL_SEARCH), }, ], - 'payroll.TabPanel.label': [PayrollBillsTabLabel], - 'payroll.TabPanel.panel': [PayrollBillsTabPanel], + 'payroll.TabPanel.label': [BenefitConsumptionsTabLabel], + 'payroll.TabPanel.panel': [BenefitConsumptionsTabPanel], 'tasksManagement.tasks': [{ text: , tableHeaders: PayrollTaskTableHeaders, diff --git a/src/pages/payroll/PayrollBillFilter.js b/src/pages/payroll/BenefitConsumptionFilter.js similarity index 63% rename from src/pages/payroll/PayrollBillFilter.js rename to src/pages/payroll/BenefitConsumptionFilter.js index 6856401..074ec76 100644 --- a/src/pages/payroll/PayrollBillFilter.js +++ b/src/pages/payroll/BenefitConsumptionFilter.js @@ -12,6 +12,7 @@ import { NumberInput, } from '@openimis/fe-core'; import { CONTAINS_LOOKUP, DEFAULT_DEBOUNCE_TIME } from '../../constants'; +import BenefitConsumptionStatusPicker from '../../pickers/BenefitConsumptionStatusPicker'; const useStyles = makeStyles((theme) => ({ form: { @@ -22,7 +23,7 @@ const useStyles = makeStyles((theme) => ({ }, })); -function PayrollBillFilter({ filters, onChangeFilters }) { +function BenefitConsumptionFilter({ filters, onChangeFilters }) { const modulesManager = useModulesManager(); const classes = useStyles(); const { formatMessage } = useTranslations('payroll', modulesManager); @@ -66,31 +67,25 @@ function PayrollBillFilter({ filters, onChangeFilters }) { return ( - - @@ -99,22 +94,37 @@ function PayrollBillFilter({ filters, onChangeFilters }) { onChangeFilters([ { - id: 'dateBill', + id: 'dateDue', value: v, - filter: `dateBill: "${v}"`, + filter: `dateDue: "${v}"`, }, ])} /> - + + + + + + ); } -export default PayrollBillFilter; +export default BenefitConsumptionFilter; diff --git a/src/pages/payroll/BenefitConsumptionSearcher.js b/src/pages/payroll/BenefitConsumptionSearcher.js new file mode 100644 index 0000000..c753c6d --- /dev/null +++ b/src/pages/payroll/BenefitConsumptionSearcher.js @@ -0,0 +1,113 @@ +/* eslint-disable no-param-reassign */ +import React, { useState } from 'react'; +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; + +import { + Searcher, useHistory, useModulesManager, useTranslations, +} from '@openimis/fe-core'; +import { fetchBenefitConsumptions } from '../../actions'; +import { DEFAULT_PAGE_SIZE, ROWS_PER_PAGE_OPTIONS } from '../../constants'; +import BenefitConsumptionFilter from './BenefitConsumptionFilter'; + +function BenefitConsumptionSearcher({ + fetchBenefitConsumptions, + fetchingBenefitConsumptions, + fetchedBenefitConsumptions, + errorBenefitConsumptions, + benefitConsumptions, + benefitConsumptionsPageInfo, + benefitConsumptionsTotalCount, + payrollUuid, +}) { + const history = useHistory(); + const modulesManager = useModulesManager(); + const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager); + + const fetch = (params) => fetchBenefitConsumptions(modulesManager, params); + + const headers = () => [ + 'benefitConsumption.individual', + 'benefitConsumption.photo', + 'benefitConsumption.code', + 'benefitConsumption.dateDue', + 'benefitConsumption.receipt', + 'benefitConsumption.amount', + 'benefitConsumption.type', + 'benefitConsumption.status', + ]; + + const itemFormatters = () => [ + (benefitConsumption) => benefitConsumption?.individual?.firstName, + (benefitConsumption) => benefitConsumption?.photo, + (benefitConsumption) => benefitConsumption?.code, + (benefitConsumption) => benefitConsumption?.dateDue, + (benefitConsumption) => benefitConsumption?.receipt, + (benefitConsumption) => benefitConsumption?.amount, + (benefitConsumption) => benefitConsumption?.type, + (benefitConsumption) => benefitConsumption?.status, + ]; + + const rowIdentifier = (benefitConsumption) => benefitConsumption.id; + + const sorts = () => [ + ['individual', true], + ['photo', true], + ['code', true], + ['dateDue', true], + ['receipt', true], + ['amount', true], + ['type', true], + ['status', true], + ]; + + const defaultFilters = () => ({ + isDeleted: { + value: false, + filter: 'isDeleted: false', + }, + // payrollUuid: { + // value: payrollUuid, + // filter: `payrollUuid: "${payrollUuid}"`, + // }, + }); + + return ( +
+ +
+ ); +} + +const mapStateToProps = (state) => ({ + fetchingBenefitConsumptions: state.payroll.fetchingBenefitConsumptions, + fetchedBenefitConsumptions: state.payroll.fetchedBenefitConsumptions, + errorBenefitConsumptions: state.payroll.errorBenefitConsumptions, + benefitConsumptions: state.payroll.benefitConsumptions, + benefitConsumptionsPageInfo: state.payroll.benefitConsumptionsPageInfo, + benefitConsumptionsTotalCount: state.payroll.benefitConsumptionsTotalCount, +}); + +const mapDispatchToProps = (dispatch) => bindActionCreators( + { fetchBenefitConsumptions }, + dispatch, +); + +export default connect(mapStateToProps, mapDispatchToProps)(BenefitConsumptionSearcher); diff --git a/src/pages/payroll/BenefitConsumptionTabPanel.js b/src/pages/payroll/BenefitConsumptionTabPanel.js new file mode 100644 index 0000000..7b406cc --- /dev/null +++ b/src/pages/payroll/BenefitConsumptionTabPanel.js @@ -0,0 +1,44 @@ +import React from 'react'; +import { Tab } from '@material-ui/core'; +import { PublishedComponent, useTranslations } from '@openimis/fe-core'; +import { + BENEFIT_CONSUMPTION_LIST_TAB_VALUE, + MODULE_NAME, + RIGHT_PAYROLL_SEARCH, +} from '../../constants'; +import BenefitConsumptionSearcher from './BenefitConsumptionSearcher'; + +function BenefitConsumptionsTabLabel({ + onChange, tabStyle, isSelected, modulesManager, +}) { + const { formatMessage } = useTranslations(MODULE_NAME, modulesManager); + return ( + + ); +} + +function BenefitConsumptionsTabPanel({ value, rights, payrollUuid }) { + console.log(payrollUuid, 'aaaaa') + return ( + + { + rights.includes(RIGHT_PAYROLL_SEARCH) && payrollUuid && ( + + ) + } + + ); +} + +export { BenefitConsumptionsTabLabel, BenefitConsumptionsTabPanel }; diff --git a/src/pages/payroll/PayrollBillSearcher.js b/src/pages/payroll/PayrollBillSearcher.js deleted file mode 100644 index 37451d3..0000000 --- a/src/pages/payroll/PayrollBillSearcher.js +++ /dev/null @@ -1,172 +0,0 @@ -/* eslint-disable no-param-reassign */ -import React, { useState } from 'react'; -import { bindActionCreators } from 'redux'; -import { connect } from 'react-redux'; - -import { IconButton, Tooltip } from '@material-ui/core'; -import EditIcon from '@material-ui/icons/Edit'; - -import { - Searcher, - useHistory, - useModulesManager, - useTranslations, - PublishedComponent, -} from '@openimis/fe-core'; -import { fetchPayrollBills } from '../../actions'; -import { - DEFAULT_PAGE_SIZE, - GET_SUBJECT_AND_THIRDPARTY_TYPE_PICKER_REF, - INVOICE_BILL_ROUTE, - RIGHT_BILL_SEARCH, - RIGHT_BILL_UPDATE, - ROWS_PER_PAGE_OPTIONS, -} from '../../constants'; -import PayrollBillFilter from './PayrollBillFilter'; - -function PayrollBillSearcher({ - rights, - fetchPayrollBills, - fetchingBills, - fetchedBills, - errorBills, - bills, - billsPageInfo, - billsTotalCount, -}) { - const history = useHistory(); - const modulesManager = useModulesManager(); - const { formatMessage, formatMessageWithValues } = useTranslations('payroll', modulesManager); - - const openBill = (bill) => rights.includes(RIGHT_BILL_SEARCH) && history.push( - `/${modulesManager.getRef(INVOICE_BILL_ROUTE)}/${bill?.id}`, - ); - - const onDoubleClick = (bill) => openBill(bill); - - const [payrollUuid] = useState(''); - - const fetch = (params) => { - const currentPath = window.location.pathname; - const pathSegments = currentPath.split('/'); - const payrollIndex = pathSegments.indexOf('payroll'); - if (payrollIndex !== -1 && payrollIndex < pathSegments.length - 1) { - const uuid = pathSegments[payrollIndex + 1]; - const index = params.findIndex((element) => element.startsWith('payrollUuid:')); - if (index !== -1) { - params[index] = `payrollUuid: "${uuid}"`; - } - fetchPayrollBills(modulesManager, params); - } - }; - - const headers = () => { - const headers = [ - 'bills.subject', - 'bills.thirdparty', - 'bills.code', - 'bills.dateBill', - 'bills.amountTotal', - 'bills.status.label', - ]; - if (rights.includes(RIGHT_BILL_UPDATE)) { - headers.push('emptyLabel'); - } - return headers; - }; - - const getSubjectAndThirdpartyTypePicker = modulesManager.getRef(GET_SUBJECT_AND_THIRDPARTY_TYPE_PICKER_REF); - - const itemFormatters = () => { - const formatters = [ - (bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill?.subjectTypeName, bill?.subject), - (bill) => getSubjectAndThirdpartyTypePicker(modulesManager, bill?.thirdpartyTypeName, bill?.thirdparty), - (bill) => bill?.code, - (bill) => bill?.dateBill, - (bill) => bill?.amountTotal, - (bill) => ( - - ), - ]; - if (rights.includes(RIGHT_BILL_UPDATE)) { - formatters.push((bill) => ( - - openBill(bill)} - > - - - - )); - } - return formatters; - }; - - const rowIdentifier = (bill) => bill.id; - - const sorts = () => [ - ['subjectType', true], - ['thirdpartyType', true], - ['code', true], - ['dateBill', true], - ['amountTotal', true], - ['status', true], - ]; - - const defaultFilters = () => ({ - isDeleted: { - value: false, - filter: 'isDeleted: false', - }, - payrollUuid: { - value: payrollUuid, - filter: `payrollUuid: "${payrollUuid}"`, - }, - }); - - return ( -
- -
- ); -} - -const mapStateToProps = (state) => ({ - fetchingBills: state.payroll.fetchingPayrollBills, - fetchedBills: state.payroll.fetchedPayrollBills, - errorBills: state.payroll.errorPayrollBills, - bills: state.payroll.payrollBills, - billsPageInfo: state.payroll.payrollBillsPageInfo, - billsTotalCount: state.payroll.payrollBillsTotalCount, -}); - -const mapDispatchToProps = (dispatch) => bindActionCreators( - { fetchPayrollBills }, - dispatch, -); - -export default connect(mapStateToProps, mapDispatchToProps)(PayrollBillSearcher); diff --git a/src/pages/payroll/PayrollBillTabPanel.js b/src/pages/payroll/PayrollBillTabPanel.js deleted file mode 100644 index b0b271e..0000000 --- a/src/pages/payroll/PayrollBillTabPanel.js +++ /dev/null @@ -1,47 +0,0 @@ -import React from 'react'; -import { Tab } from '@material-ui/core'; -import { PublishedComponent, useTranslations } from '@openimis/fe-core'; -import { MODULE_NAME, PAYROLL_BILLS_LIST_TAB_VALUE, RIGHT_BILL_SEARCH } from '../../constants'; -import PayrollBillSearcher from './PayrollBillSearcher'; - -function PayrollBillsTabLabel({ - onChange, tabStyle, isSelected, modulesManager, -}) { - const { formatMessage } = useTranslations(MODULE_NAME, modulesManager); - return ( - - ); -} - -function PayrollBillsTabPanel({ value, rights, payrollUuid }) { - let uuidPayroll = null; - const currentPath = window.location.pathname; - const pathSegments = currentPath.split('/'); - const payrollIndex = pathSegments.indexOf('payroll'); - if (payrollIndex !== -1 && payrollIndex < pathSegments.length - 1) { - const uuid = pathSegments[payrollIndex + 1]; - uuidPayroll = uuid; - } - return ( - - { - rights.includes(RIGHT_BILL_SEARCH) && uuidPayroll && ( - - ) - } - - ); -} - -export { PayrollBillsTabLabel, PayrollBillsTabPanel }; diff --git a/src/pages/payroll/PayrollHeadPanel.js b/src/pages/payroll/PayrollHeadPanel.js index f7f6489..21aadd1 100644 --- a/src/pages/payroll/PayrollHeadPanel.js +++ b/src/pages/payroll/PayrollHeadPanel.js @@ -2,16 +2,16 @@ import React from 'react'; import { injectIntl } from 'react-intl'; -import { Grid, Checkbox, FormControlLabel } from '@material-ui/core'; -import { withTheme, withStyles } from '@material-ui/core/styles'; +import { Checkbox, FormControlLabel, Grid } from '@material-ui/core'; +import { withStyles, withTheme } from '@material-ui/core/styles'; import { - TextInput, - FormPanel, - withModulesManager, - PublishedComponent, ControlledField, formatMessage, + FormPanel, + PublishedComponent, + TextInput, + withModulesManager, } from '@openimis/fe-core'; import AdvancedFiltersDialog from '../../components/payroll/AdvancedFiltersDialog'; import { CLEARED_STATE_FILTER } from '../../constants'; @@ -46,7 +46,7 @@ class PayrollHeadPanel extends FormPanel { try { const jsonData = JSON.parse(jsonExt); const advancedCriteria = jsonData.advanced_criteria || []; - const parsedFilters = advancedCriteria.map(({ custom_filter_condition }) => { + return advancedCriteria.map(({ custom_filter_condition }) => { const [field, filter, typeValue] = custom_filter_condition.split('__'); const [type, value] = typeValue.split('='); return { @@ -57,7 +57,6 @@ class PayrollHeadPanel extends FormPanel { value, }; }); - return parsedFilters; } catch (error) { return []; } @@ -76,23 +75,22 @@ class PayrollHeadPanel extends FormPanel { const payroll = { ...edited }; const { appliedCustomFilters, appliedFiltersRowStructure } = this.state; const readOnly = Boolean(payroll?.id); + console.log(payroll) return ( <> - {payroll !== undefined && ( - - )} + - - this.updateAttribute('benefitPlan', benefitPlan)} - value={payroll?.benefitPlan} - readOnly={readOnly} - /> - - )} - /> - - this.updateAttribute('paymentPoint', paymentPoint)} - value={payroll?.paymentPoint} - readOnly={readOnly} - /> -
- )} - /> + + this.updateAttribute('paymentPlan', paymentPlan)} + value={payroll?.paymentPlan} + readOnly={readOnly} + /> + + + this.updateAttribute('paymentPoint', paymentPoint)} + value={payroll?.paymentPoint} + readOnly={readOnly} + /> + + + this.updateAttribute('paymentCycle', paymentCycle)} + value={payroll?.paymentCycle} + readOnly={readOnly} + /> + {readOnly && ( - - this.updateAttribute('includedUnpaid', event.target.checked)} - disabled={!!readOnly} - /> - )} - /> - ); diff --git a/src/pages/payroll/PayrollPage.js b/src/pages/payroll/PayrollPage.js index 2fb8019..e695d5c 100644 --- a/src/pages/payroll/PayrollPage.js +++ b/src/pages/payroll/PayrollPage.js @@ -91,9 +91,11 @@ function PayrollPage({ const mandatoryFieldsEmpty = () => { if ( editedPayroll?.name - && editedPayroll?.benefitPlan + && editedPayroll?.paymentPlan + && editedPayroll?.paymentCycle && editedPayroll?.dateValidFrom && editedPayroll?.dateValidTo + && editedPayroll?.paymentMethod && !editedPayroll?.isDeleted) return false; return true; }; @@ -149,6 +151,7 @@ function PayrollPage({ actions={actions} setConfirmedAction={setConfirmedAction} saveTooltip={formatMessage('tooltip.save')} + payrollUuid={payrollUuid} /> ) diff --git a/src/pages/payroll/PayrollTab.js b/src/pages/payroll/PayrollTab.js index 1e06a59..62c650e 100644 --- a/src/pages/payroll/PayrollTab.js +++ b/src/pages/payroll/PayrollTab.js @@ -3,7 +3,7 @@ import { Paper, Grid } from '@material-ui/core'; import { Contributions } from '@openimis/fe-core'; import { makeStyles } from '@material-ui/styles'; import { - PAYROLL_BILLS_LIST_TAB_VALUE, + BENEFIT_CONSUMPTION_LIST_TAB_VALUE, PAYROLL_TABS_LABEL_CONTRIBUTION_KEY, PAYROLL_TABS_PANEL_CONTRIBUTION_KEY, } from '../../constants'; @@ -32,7 +32,7 @@ const useStyles = makeStyles((theme) => ({ function PayrollTab({ rights, setConfirmedAction, payrollUuid }) { const classes = useStyles(); - const [activeTab, setActiveTab] = useState(PAYROLL_BILLS_LIST_TAB_VALUE); + const [activeTab, setActiveTab] = useState(BENEFIT_CONSUMPTION_LIST_TAB_VALUE); const isSelected = (tab) => tab === activeTab; diff --git a/src/pickers/BenefitConsumptionStatusPicker.js b/src/pickers/BenefitConsumptionStatusPicker.js new file mode 100644 index 0000000..9aa5e91 --- /dev/null +++ b/src/pickers/BenefitConsumptionStatusPicker.js @@ -0,0 +1,26 @@ +import React from 'react'; +import { ConstantBasedPicker } from '@openimis/fe-core'; + +import { BENEFIT_CONSUMPTION_STATUS_LIST } from '../constants'; + +function BenefitConsumptionStatusPicker(props) { + const { + required, withNull, readOnly, onChange, value, nullLabel, withLabel, + } = props; + return ( + + ); +} + +export default BenefitConsumptionStatusPicker; diff --git a/src/reducer.js b/src/reducer.js index 588d92b..3516bac 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -26,7 +26,7 @@ export const ACTION_TYPE = { SEARCH_PAYROLLS: 'PAYROLL_PAYROLLS', GET_PAYMENT_POINT: 'PAYROLL_PAYMENT_POINT', GET_PAYROLL: 'PAYROLL_GET_PAYROLL', - GET_PAYROLL_BILLS: 'PAYROLL_PAYROLL_BILLS', + GET_BENEFIT_CONSUMPTION: 'PAYROLL_BENEFIT_CONSUMPTION', GET_PAYMENT_METHODS: 'PAYROLL_PAYMENT_METHODS', }; @@ -68,12 +68,12 @@ const STORE_STATE = { payroll: {}, errorPayroll: null, - fetchingPayrollBills: true, - payrollBills: [], - payrollBillsTotalCount: 0, - fetchedPayrollBills: false, - errorPayrollBills: null, - payrollBillsPageInfo: {}, + fetchingBenefitConsumptions: true, + benefitConsumption: [], + benefitConsumptionTotalCount: 0, + fetchedBenefitConsumption: false, + errorBenefitConsumption: null, + benefitConsumptionsPageInfo: {}, fetchingPaymentMethods: true, paymentMethods: [], @@ -81,8 +81,6 @@ const STORE_STATE = { errorPaymentMethods: null, }; -const getEnumValue = (enumElement) => enumElement?.substring(ENUM_PREFIX_LENGTH); - function reducer( state = STORE_STATE, action, @@ -213,44 +211,42 @@ function reducer( errorPayroll: null, payrollBills: [], }; - case REQUEST(ACTION_TYPE.GET_PAYROLL_BILLS): + case REQUEST(ACTION_TYPE.GET_BENEFIT_CONSUMPTION): return { ...state, - fetchingPayrollBills: true, - fetchedPayrollBills: false, - payrollBills: [], - errorPayrollBills: null, - payrollBillsPageInfo: {}, - payrollBillsTotalCount: 0, + fetchingBenefitConsumptions: true, + fetchedBenefitConsumptions: false, + benefitConsumptions: [], + errorBenefitConsumptions: null, + benefitConsumptionsPageInfo: {}, + benefitConsumptionsTotalCount: 0, }; - case SUCCESS(ACTION_TYPE.GET_PAYROLL_BILLS): + case SUCCESS(ACTION_TYPE.GET_BENEFIT_CONSUMPTION): return { ...state, - fetchingPayrollBills: false, - fetchedPayrollBills: true, - payrollBills: parseData(action.payload.data.billByPayroll)?.map((bill) => ({ - ...bill, - id: decodeId(bill.id), - status: getEnumValue(bill?.status), + fetchingBenefitConsumptions: false, + fetchedBenefitConsumptions: true, + benefitConsumptions: parseData(action.payload.data.billByPayroll)?.map((benefitConsumption) => ({ + ...benefitConsumption, + id: decodeId(benefitConsumption.id), })), - payrollBillsPageInfo: pageInfo(action.payload.data.billByPayroll), - payrollBillsTotalCount: action.payload.data.billByPayroll?.totalCount ?? 0, - errorPayrollBills: formatGraphQLError(action.payload), + benefitConsumptionsPageInfo: pageInfo(action.payload.data.billByPayroll), + benefitConsumptionsTotalCount: action.payload.data.billByPayroll?.totalCount ?? 0, + errorBenefitConsumptions: formatGraphQLError(action.payload), }; - case ERROR(ACTION_TYPE.GET_PAYROLL_BILLS): + case ERROR(ACTION_TYPE.GET_BENEFIT_CONSUMPTION): return { ...state, - fetchingPayrollBills: false, + fetchingBenefitConsumptions: false, errorPayroll: formatServerError(action.payload), }; - case CLEAR(ACTION_TYPE.GET_PAYROLL_BILLS): + case CLEAR(ACTION_TYPE.GET_BENEFIT_CONSUMPTION): return { ...state, - fetchingPayrollBills: true, - fetchedPayrollBills: false, - payrollBill: null, - errorPayrollBill: null, - payrollBills: [], + fetchingBenefitConsumptions: false, + fetchedBenefitConsumptions: false, + errorBenefitConsumptions: null, + benefitConsumptions: [], }; case REQUEST(ACTION_TYPE.GET_PAYMENT_METHODS): return { diff --git a/src/translations/en.json b/src/translations/en.json index 7b22bb9..9fe621d 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -31,26 +31,26 @@ "payroll.payroll.delete.confirm.title": "Delete Payroll {name}", "payroll.payroll.delete.confirm.message": "Are you sure you want to delete the Payroll? This will result in permanent, irreversible changes.", "payroll.payrollPage.title": "Payroll", - "payroll.PayrollBillsTab.label": "Bills", + "payroll.PayrollBenefitConsumptionTab.label": "Benefit Consumptions", "payroll.tooltip.any": "Any", "payroll.paymentPointPicker.label": "Payment Point", "payroll.paymentPointPicker.placeholder": "Payment Point", "payroll.viewDetailsButton.tooltip": "Details", - "payroll.bills.pageTitle": "Bills", - "payroll.bills.searcherResultsTitle": "{billsTotalCount} Bills Found", - "payroll.bills.subject": "Subject", - "payroll.bills.thirdparty": "Sender", - "payroll.bills.code": "Code", - "payroll.bills.dateBill": "Date Bill", - "payroll.bills.amountTotal": "Amount Total", - "payroll.bills.status.label": "Status", - "payroll.bills.status.DRAFT": "Draft", - "payroll.bills.status.VALIDATED": "Validated", - "payroll.bills.status.PAYED": "Payed", - "payroll.bills.status.CANCELLED": "Cancelled", - "payroll.bills.status.DELETED": "Deleted", - "payroll.bills.status.SUSPENDED": "Suspended", + "payroll.benefitConsumption.pageTitle": "Benefit Consumptions", + "payroll.benefitConsumption.searcherResultsTitle": "{benefitConsumptionsTotalCount} Benefit Consumptions Found", + "payroll.benefitConsumption.subject": "Subject", + "payroll.benefitConsumption.thirdparty": "Sender", + "payroll.benefitConsumption.code": "Code", + "payroll.benefitConsumption.dateBill": "Date Bill", + "payroll.benefitConsumption.amountTotal": "Amount Total", + "payroll.benefitConsumption.status.label": "Status", + "payroll.benefitConsumption.status.DRAFT": "Draft", + "payroll.benefitConsumption.status.VALIDATED": "Validated", + "payroll.benefitConsumption.status.PAYED": "Payed", + "payroll.benefitConsumption.status.CANCELLED": "Cancelled", + "payroll.benefitConsumption.status.DELETED": "Deleted", + "payroll.benefitConsumption.status.SUSPENDED": "Suspended", "payroll.tooltip.save": "Save", "payroll.tooltip.delete": "Delete",