Disable sending fees for current and future months
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import React, { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Button, Modal } from 'semantic-ui-react';
|
||||
import moment from 'moment';
|
||||
|
||||
import { addFeesToOrd } from '../../store/actions';
|
||||
import { defaultDateFormat } from '../../constants/constants';
|
||||
|
||||
class GenerateFeesInORDButton extends Component {
|
||||
state = { open: false };
|
||||
@@ -21,7 +23,25 @@ class GenerateFeesInORDButton extends Component {
|
||||
|
||||
render() {
|
||||
const { open, size } = this.state;
|
||||
const { singleMember, disabled } = this.props;
|
||||
const { singleMember, disabled, dateRange } = this.props;
|
||||
|
||||
let submitIsDisabled = disabled;
|
||||
|
||||
if (dateRange && dateRange.startDate) {
|
||||
const startDateMoment = moment(dateRange.startDate, defaultDateFormat);
|
||||
const currentMoment = moment();
|
||||
|
||||
const startMomentMonth = startDateMoment.month();
|
||||
const startMomentYear = startDateMoment.year();
|
||||
const currentMonth = currentMoment.month();
|
||||
const currentYear = currentMoment.year();
|
||||
|
||||
const monthSelectorIsInPast = (startMomentYear < currentYear) ||
|
||||
(startMomentYear === currentYear && startMomentMonth < currentMonth);
|
||||
|
||||
submitIsDisabled = disabled || !monthSelectorIsInPast;
|
||||
}
|
||||
|
||||
|
||||
const modalContent = singleMember ?
|
||||
'This will remove all existing fees in ORD for selected member in selected date range and generate new fees based on shown incident tables. Do you want to continue ?':
|
||||
@@ -29,7 +49,7 @@ class GenerateFeesInORDButton extends Component {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button disabled={disabled} onClick={this.show('tiny')}>Generate fees in ORD</Button>
|
||||
<Button disabled={submitIsDisabled} onClick={this.show('tiny')}>Generate fees in ORD</Button>
|
||||
|
||||
<Modal size={size} open={open} onClose={this.close}>
|
||||
<Modal.Header>Add fees to the ORD</Modal.Header>
|
||||
|
||||
@@ -10,7 +10,7 @@ const { reformatMembershipsName } = require('../services/officeRnD/memberships')
|
||||
const { checkBookingChanges } = require('../services/integration/checkBookingChange');
|
||||
const { checkIfProcessing } = require('../services/integration/processingStatus');
|
||||
|
||||
const { UI_TIMEZONE } = require('../constants/constants');
|
||||
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT } = require('../constants/constants');
|
||||
|
||||
const getKnownOfficeResourceMappings = (req, res) => {
|
||||
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources()];
|
||||
@@ -117,48 +117,61 @@ const addFees = (req, res) => {
|
||||
const dateRange = req.body && req.body.dateRange ? req.body.dateRange : {startDate: null, endDate: null};
|
||||
const { startDate, endDate } = dateRange;
|
||||
|
||||
if (startDate && endDate && Array.isArray(memberIds)){
|
||||
checkBookingChanges()
|
||||
.then(() => {
|
||||
deleteFeesFromORD(dateRange, memberIds)
|
||||
.then((invoicedFees) => {
|
||||
// TODO: Change this to parallel execution
|
||||
getMembersFeesForDateRange(dateRange, memberIds)
|
||||
.then(({allFees, memberships}) => {
|
||||
addFeesToORD(allFees, invoicedFees)
|
||||
.then((numberOfInsertedFees) => {
|
||||
reformatMembershipsName(memberships)
|
||||
.then(() => {
|
||||
res.send({
|
||||
status: 'ok',
|
||||
numberOfInsertedFees
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error reformatting memberships name');
|
||||
console.log(error);
|
||||
res.status(500).send(error);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error adding fees');
|
||||
res.status(500).send(error);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
res.status(500).send(error);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
res.status(500).send(error);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error with updating booking reservations');
|
||||
res.status(500).send(error);
|
||||
})
|
||||
const startDateMoment = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
|
||||
|
||||
if (startDate && endDate && startDateMoment.isValid() && Array.isArray(memberIds)){
|
||||
const currentMoment = moment.tz(UI_TIMEZONE);
|
||||
const startMomentMonth = startDateMoment.month();
|
||||
const startMomentYear = startDateMoment.year();
|
||||
const currentMonth = currentMoment.month();
|
||||
const currentYear = currentMoment.year();
|
||||
|
||||
if ((startMomentYear < currentYear) || (startMomentYear === currentYear && startMomentMonth < currentMonth)) {
|
||||
checkBookingChanges()
|
||||
.then(() => {
|
||||
deleteFeesFromORD(dateRange, memberIds)
|
||||
.then((invoicedFees) => {
|
||||
// TODO: Change this to parallel execution
|
||||
getMembersFeesForDateRange(dateRange, memberIds)
|
||||
.then(({allFees, memberships}) => {
|
||||
addFeesToORD(allFees, invoicedFees)
|
||||
.then((numberOfInsertedFees) => {
|
||||
reformatMembershipsName(memberships)
|
||||
.then(() => {
|
||||
res.send({
|
||||
status: 'ok',
|
||||
numberOfInsertedFees
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error reformatting memberships name');
|
||||
console.log(error);
|
||||
res.status(500).send(error);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error adding fees');
|
||||
res.status(500).send(error);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
res.status(500).send(error);
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
res.status(500).send(error);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error with updating booking reservations');
|
||||
res.status(500).send(error);
|
||||
})
|
||||
}else{
|
||||
console.log('Selected month/year pair is current month or in the future');
|
||||
res.status(400).send('Selected month/year pair is current month or in the future');
|
||||
}
|
||||
}else{
|
||||
console.log('Date range is missing to send fees to ORD');
|
||||
res.status(400).send('Date range is missing');
|
||||
|
||||
Reference in New Issue
Block a user