Merge branch 'disable-sending-fees-for-current-and-future-months' into 'master'

Disable sending fees for current and future months

See merge request saburly/psihologija!58
This commit was merged in pull request #58.
This commit is contained in:
Bilal Catic
2019-09-06 05:54:45 +00:00
2 changed files with 78 additions and 45 deletions

View File

@@ -1,8 +1,10 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Button, Modal } from 'semantic-ui-react'; import { Button, Modal } from 'semantic-ui-react';
import moment from 'moment';
import { addFeesToOrd } from '../../store/actions'; import { addFeesToOrd } from '../../store/actions';
import { defaultDateFormat } from '../../constants/constants';
class GenerateFeesInORDButton extends Component { class GenerateFeesInORDButton extends Component {
state = { open: false }; state = { open: false };
@@ -21,7 +23,25 @@ class GenerateFeesInORDButton extends Component {
render() { render() {
const { open, size } = this.state; 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 ? 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 ?': '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 ( return (
<div> <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 size={size} open={open} onClose={this.close}>
<Modal.Header>Add fees to the ORD</Modal.Header> <Modal.Header>Add fees to the ORD</Modal.Header>

View File

@@ -10,7 +10,7 @@ const { reformatMembershipsName } = require('../services/officeRnD/memberships')
const { checkBookingChanges } = require('../services/integration/checkBookingChange'); const { checkBookingChanges } = require('../services/integration/checkBookingChange');
const { checkIfProcessing } = require('../services/integration/processingStatus'); 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 getKnownOfficeResourceMappings = (req, res) => {
const dataToFetch = [getMappingsFromDatabase(), fetchOffices(), fetchResources()]; 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 dateRange = req.body && req.body.dateRange ? req.body.dateRange : {startDate: null, endDate: null};
const { startDate, endDate } = dateRange; const { startDate, endDate } = dateRange;
if (startDate && endDate && Array.isArray(memberIds)){ const startDateMoment = moment.tz(dateRange.startDate, DEFAULT_DATE_FORMAT, UI_TIMEZONE);
checkBookingChanges()
.then(() => { if (startDate && endDate && startDateMoment.isValid() && Array.isArray(memberIds)){
deleteFeesFromORD(dateRange, memberIds) const currentMoment = moment.tz(UI_TIMEZONE);
.then((invoicedFees) => { const startMomentMonth = startDateMoment.month();
// TODO: Change this to parallel execution const startMomentYear = startDateMoment.year();
getMembersFeesForDateRange(dateRange, memberIds) const currentMonth = currentMoment.month();
.then(({allFees, memberships}) => { const currentYear = currentMoment.year();
addFeesToORD(allFees, invoicedFees)
.then((numberOfInsertedFees) => { if ((startMomentYear < currentYear) || (startMomentYear === currentYear && startMomentMonth < currentMonth)) {
reformatMembershipsName(memberships) checkBookingChanges()
.then(() => { .then(() => {
res.send({ deleteFeesFromORD(dateRange, memberIds)
status: 'ok', .then((invoicedFees) => {
numberOfInsertedFees // TODO: Change this to parallel execution
}); getMembersFeesForDateRange(dateRange, memberIds)
}) .then(({allFees, memberships}) => {
.catch((error) => { addFeesToORD(allFees, invoicedFees)
console.log('Error reformatting memberships name'); .then((numberOfInsertedFees) => {
console.log(error); reformatMembershipsName(memberships)
res.status(500).send(error); .then(() => {
}) res.send({
}) status: 'ok',
.catch((error) => { numberOfInsertedFees
console.log('Error adding fees'); });
res.status(500).send(error); })
}) .catch((error) => {
}) console.log('Error reformatting memberships name');
.catch((error) => { console.log(error);
console.log(error); res.status(500).send(error);
res.status(500).send(error); })
}) })
}) .catch((error) => {
.catch((error) => { console.log('Error adding fees');
console.log(error); res.status(500).send(error);
res.status(500).send(error); })
}); })
}) .catch((error) => {
.catch((error) => { console.log(error);
console.log('Error with updating booking reservations'); res.status(500).send(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{ }else{
console.log('Date range is missing to send fees to ORD'); console.log('Date range is missing to send fees to ORD');
res.status(400).send('Date range is missing'); res.status(400).send('Date range is missing');