Editing of the fees before sending / bugfixes
This commit is contained in:
@@ -12,16 +12,21 @@ import {
|
|||||||
incidentDescriptions,
|
incidentDescriptions,
|
||||||
incidentLevelDescriptions,
|
incidentLevelDescriptions,
|
||||||
UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION, UNLOCKED_INCIDENT_STANDALONE, UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION, UNLOCKED_INCIDENT_STANDALONE, UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
||||||
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE
|
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE, BOOKING_CANCELED_LATE, BOOKING_MOVED_TO_ANOTHER_DAY,
|
||||||
|
BOOKING_SHORTENED
|
||||||
} from '../../../constants/enums';
|
} from '../../../constants/enums';
|
||||||
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
||||||
import { deleteIncidents } from "../../../store/actions";
|
import { deleteIncidents, updateIncidentFees } from "../../../store/actions";
|
||||||
|
|
||||||
class SingleIncidentsTable extends Component {
|
class SingleIncidentsTable extends Component {
|
||||||
state = {
|
state = {
|
||||||
selectedUnlockedIncidentIds: [],
|
selectedUnlockedIncidentIds: [],
|
||||||
selectedUnscheduledIncidentIds: [],
|
selectedUnscheduledIncidentIds: [],
|
||||||
selectedBookingChangeIncidentIds: []
|
selectedBookingChangeIncidentIds: [],
|
||||||
|
changedUnlockedIncidentIds: {},
|
||||||
|
changedUnscheduledIncidentIds: {},
|
||||||
|
changedBookingChangeIncidentIds: {},
|
||||||
|
inputIdToFocus: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
onSelectChange = (selectedIncidents) => {
|
onSelectChange = (selectedIncidents) => {
|
||||||
@@ -82,6 +87,24 @@ class SingleIncidentsTable extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateChangedFees = () => {
|
||||||
|
const { dateRange, updateIncidentsById, memberId } = this.props;
|
||||||
|
const { changedUnlockedIncidentIds, changedUnscheduledIncidentIds, changedBookingChangeIncidentIds } = this.state;
|
||||||
|
|
||||||
|
const incidentFeesToUpdate = {
|
||||||
|
unlockedIncidentFees: changedUnlockedIncidentIds,
|
||||||
|
unscheduledIncidentFees: changedUnscheduledIncidentIds,
|
||||||
|
bookingChangeIncidentFees: changedBookingChangeIncidentIds
|
||||||
|
};
|
||||||
|
|
||||||
|
updateIncidentsById(dateRange, incidentFeesToUpdate, memberId);
|
||||||
|
this.setState({
|
||||||
|
changedUnlockedIncidentIds: {},
|
||||||
|
changedUnscheduledIncidentIds: {},
|
||||||
|
changedBookingChangeIncidentIds: {}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
const {
|
const {
|
||||||
loading,
|
loading,
|
||||||
@@ -94,12 +117,22 @@ class SingleIncidentsTable extends Component {
|
|||||||
const {
|
const {
|
||||||
selectedUnlockedIncidentIds,
|
selectedUnlockedIncidentIds,
|
||||||
selectedUnscheduledIncidentIds,
|
selectedUnscheduledIncidentIds,
|
||||||
selectedBookingChangeIncidentIds
|
selectedBookingChangeIncidentIds,
|
||||||
|
changedUnlockedIncidentIds,
|
||||||
|
changedUnscheduledIncidentIds,
|
||||||
|
changedBookingChangeIncidentIds,
|
||||||
|
inputIdToFocus
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
const totalSelected = selectedUnlockedIncidentIds.length + selectedUnscheduledIncidentIds.length + selectedBookingChangeIncidentIds.length;
|
const totalSelected = selectedUnlockedIncidentIds.length + selectedUnscheduledIncidentIds.length + selectedBookingChangeIncidentIds.length;
|
||||||
const numberOfSelectedText = totalSelected > 0 ? ` (${totalSelected})` : '';
|
const numberOfSelectedText = totalSelected > 0 ? ` (${totalSelected})` : '';
|
||||||
|
|
||||||
|
const totalChanged =
|
||||||
|
Object.keys(changedUnlockedIncidentIds).length +
|
||||||
|
Object.keys(changedUnscheduledIncidentIds).length +
|
||||||
|
Object.keys(changedBookingChangeIncidentIds).length;
|
||||||
|
const numberOfChangedText = totalChanged > 0 ? ` (${totalChanged})` : '';
|
||||||
|
|
||||||
const incidents = this.props.incidents ? this.props.incidents : [];
|
const incidents = this.props.incidents ? this.props.incidents : [];
|
||||||
incidents.forEach(incident => {
|
incidents.forEach(incident => {
|
||||||
incident.id = `${incident.incidentType}-${incident.incidentId}`;
|
incident.id = `${incident.incidentType}-${incident.incidentId}`;
|
||||||
@@ -122,6 +155,44 @@ class SingleIncidentsTable extends Component {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const priceChangeHandler = (element) => {
|
||||||
|
if (element && element.target){
|
||||||
|
const {value: newValue, id: incidentDescriptionID} = element.target;
|
||||||
|
const newValueFloat = parseFloat(newValue);
|
||||||
|
const incidentData = incidentDescriptionID.split('-');
|
||||||
|
const incidentType = parseInt(incidentData[0]) || null;
|
||||||
|
const incidentID = parseInt(incidentData[1]) || null;
|
||||||
|
|
||||||
|
if ((newValueFloat || (newValueFloat === 0) || (isNaN(newValueFloat))) && incidentType && incidentID){
|
||||||
|
const changedUnlockedIncidentIdsCopy = Object.assign({}, changedUnlockedIncidentIds);
|
||||||
|
const changedUnscheduledIncidentIdsCopy = Object.assign({}, changedUnscheduledIncidentIds);
|
||||||
|
const changedBookingChangeIncidentIdsCopy = Object.assign({}, changedBookingChangeIncidentIds);
|
||||||
|
|
||||||
|
switch (incidentType) {
|
||||||
|
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
|
case UNLOCKED_INCIDENT_STANDALONE:
|
||||||
|
changedUnlockedIncidentIdsCopy[incidentID] = newValueFloat;
|
||||||
|
this.setState({changedUnlockedIncidentIds: changedUnlockedIncidentIdsCopy, inputIdToFocus: incidentDescriptionID});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
|
changedUnscheduledIncidentIdsCopy[incidentID] = newValueFloat;
|
||||||
|
this.setState({changedUnscheduledIncidentIds: changedUnscheduledIncidentIdsCopy, inputIdToFocus: incidentDescriptionID});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BOOKING_MOVED_TO_ANOTHER_DAY:
|
||||||
|
case BOOKING_SHORTENED:
|
||||||
|
case BOOKING_CANCELED_LATE:
|
||||||
|
changedBookingChangeIncidentIdsCopy[incidentID] = newValueFloat;
|
||||||
|
this.setState({changedBookingChangeIncidentIds: changedBookingChangeIncidentIdsCopy, inputIdToFocus: incidentDescriptionID});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
tableHeaders.forEach((header) => {
|
tableHeaders.forEach((header) => {
|
||||||
const columnTitle = incidentsReportHeaderTitles[header];
|
const columnTitle = incidentsReportHeaderTitles[header];
|
||||||
|
|
||||||
@@ -143,6 +214,10 @@ class SingleIncidentsTable extends Component {
|
|||||||
Cell: props => {
|
Cell: props => {
|
||||||
let cellValue = '';
|
let cellValue = '';
|
||||||
let urlValue = undefined;
|
let urlValue = undefined;
|
||||||
|
let clickablePrice = undefined;
|
||||||
|
let priceAsNumber = undefined;
|
||||||
|
let priceInputID = undefined;
|
||||||
|
let priceFontColor = 'black';
|
||||||
|
|
||||||
switch (props.column.id) {
|
switch (props.column.id) {
|
||||||
case 'memberName':
|
case 'memberName':
|
||||||
@@ -198,9 +273,44 @@ class SingleIncidentsTable extends Component {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'totalChargeFee':
|
case 'totalChargeFee':
|
||||||
const totalFee = (props.row['_original'].incidentPrice || props.value) || 0;
|
clickablePrice = true;
|
||||||
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
let totalFee = 0;
|
||||||
cellValue = `$ ${totalFeeFormatted}`;
|
|
||||||
|
let changedIncidentsProxy;
|
||||||
|
switch (props.row['_original'].incidentType) {
|
||||||
|
case UNLOCKED_INCIDENT_STANDALONE:
|
||||||
|
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
|
changedIncidentsProxy = changedUnlockedIncidentIds;
|
||||||
|
break;
|
||||||
|
case UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
|
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
|
changedIncidentsProxy = changedUnscheduledIncidentIds;
|
||||||
|
break;
|
||||||
|
case BOOKING_CANCELED_LATE:
|
||||||
|
case BOOKING_MOVED_TO_ANOTHER_DAY:
|
||||||
|
case BOOKING_SHORTENED:
|
||||||
|
changedIncidentsProxy = changedBookingChangeIncidentIds;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const changedFee = changedIncidentsProxy[props.row['_original'].incidentId];
|
||||||
|
|
||||||
|
if (typeof changedFee === 'number'){
|
||||||
|
// Not undefined, maybe 0 or NaN
|
||||||
|
if (isNaN(changedFee)){
|
||||||
|
totalFee = '';
|
||||||
|
}else{
|
||||||
|
totalFee = changedFee;
|
||||||
|
priceFontColor = 'red';
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//Not defined, in this context means it is not changed
|
||||||
|
totalFee = parseFloat((props.row['_original'].incidentPrice || props.value) || 0).toFixed(2);
|
||||||
|
}
|
||||||
|
// const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
||||||
|
priceAsNumber = totalFee;
|
||||||
|
priceInputID = `${props.row['_original'].incidentType || ''}-${props.row['_original'].incidentId || ''}`;
|
||||||
|
// cellValue = `$ ${totalFeeFormatted}`;
|
||||||
columnContentsAlignment = columnAlignments.right;
|
columnContentsAlignment = columnAlignments.right;
|
||||||
break;
|
break;
|
||||||
case 'oldReservation':
|
case 'oldReservation':
|
||||||
@@ -217,10 +327,22 @@ class SingleIncidentsTable extends Component {
|
|||||||
cellValue = props.value;
|
cellValue = props.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openMemberSummaryOnMemberClick && urlValue){
|
if (clickablePrice){
|
||||||
return <NavLink to={urlValue}>{cellValue}</NavLink>
|
return <p>$ <input
|
||||||
|
id={priceInputID}
|
||||||
|
style={{ color: priceFontColor }}
|
||||||
|
type={'number'}
|
||||||
|
onChange={priceChangeHandler}
|
||||||
|
value={priceAsNumber}
|
||||||
|
autoFocus={priceInputID === inputIdToFocus}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
}else{
|
}else{
|
||||||
return <div style={{ textAlign: columnContentsAlignment, whiteSpace: 'pre' }}>{cellValue}</div>
|
if (openMemberSummaryOnMemberClick && urlValue){
|
||||||
|
return <NavLink to={urlValue}>{cellValue}</NavLink>
|
||||||
|
}else{
|
||||||
|
return <div style={{ textAlign: columnContentsAlignment, whiteSpace: 'pre' }}>{cellValue}</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -235,6 +357,9 @@ class SingleIncidentsTable extends Component {
|
|||||||
{
|
{
|
||||||
<Button disabled={loading || totalSelected === 0} onClick={this.deleteSelectedFees}>{`Delete selected ${numberOfSelectedText}`}</Button>
|
<Button disabled={loading || totalSelected === 0} onClick={this.deleteSelectedFees}>{`Delete selected ${numberOfSelectedText}`}</Button>
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
<Button disabled={loading || totalChanged === 0} onClick={this.updateChangedFees}>{`Save changed ${numberOfChangedText}`}</Button>
|
||||||
|
}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
{
|
{
|
||||||
!loading && incidents &&
|
!loading && incidents &&
|
||||||
@@ -252,7 +377,8 @@ class SingleIncidentsTable extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId})
|
deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId}),
|
||||||
|
updateIncidentsById: (dateRange, updatedIncidentsData, memberId) => updateIncidentFees(dispatch, {dateRange, updatedIncidentsData, memberId})
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(SingleIncidentsTable);
|
export default connect(null, mapDispatchToProps)(SingleIncidentsTable);
|
||||||
|
|||||||
@@ -103,6 +103,21 @@ export const deleteIncidents = (dispatch, deleteData) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateIncidentFees = (dispatch, updateData) => {
|
||||||
|
const pendingAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_PENDING : FETCH_INCIDENTS_PENDING;
|
||||||
|
const successAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_SUCCESS : FETCH_INCIDENTS_SUCCESS;
|
||||||
|
const failedAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_FAILED : FETCH_INCIDENTS_FAILED;
|
||||||
|
|
||||||
|
dispatch({type: pendingAction});
|
||||||
|
API.patch(`/integration/fees`, updateData)
|
||||||
|
.then(response => {
|
||||||
|
dispatch({type: successAction, payload: response.data});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({type: failedAction, payload: error.response});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const fetchMembersList = (dispatch) => {
|
export const fetchMembersList = (dispatch) => {
|
||||||
dispatch({type: FETCH_MEMBERS_PENDING});
|
dispatch({type: FETCH_MEMBERS_PENDING});
|
||||||
API.get('officeRnD/membersList')
|
API.get('officeRnD/membersList')
|
||||||
|
|||||||
@@ -2,15 +2,25 @@
|
|||||||
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
|
|
||||||
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase, deleteMappingById, updateMappingById } = require('../services/officeRnD/resources');
|
const {
|
||||||
|
getMappingsFromDatabase,
|
||||||
|
fetchOffices,
|
||||||
|
fetchResources,
|
||||||
|
saveNewMappingToDatabase,
|
||||||
|
deleteMappingById,
|
||||||
|
updateMappingById } = require('../services/officeRnD/resources');
|
||||||
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
|
const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports');
|
||||||
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration');
|
||||||
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees');
|
||||||
const { reformatMembershipsName } = require('../services/officeRnD/memberships');
|
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 { deleteUnlockedIncidentsById, deleteUnscheduledIncidentsById } = require('../services/integration/doorLockCharges');
|
const {
|
||||||
const { deleteBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges');
|
deleteUnlockedIncidentsById,
|
||||||
|
deleteUnscheduledIncidentsById,
|
||||||
|
updateUnscheduledIncidentsById,
|
||||||
|
updateUnlockedIncidentsById } = require('../services/integration/doorLockCharges');
|
||||||
|
const { deleteBookingChangeIncidentsById, updateBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges');
|
||||||
|
|
||||||
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
|
const { UI_TIMEZONE, DEFAULT_DATE_FORMAT, ALLOW_SENDING_FEES, integrationServiceErrors } = require('../constants/constants');
|
||||||
|
|
||||||
@@ -177,7 +187,7 @@ const addFees = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteFees= (req, res) => {
|
const deleteFees = (req, res) => {
|
||||||
const deleteData = req.body;
|
const deleteData = req.body;
|
||||||
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
|
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
|
||||||
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
|
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
|
||||||
@@ -220,6 +230,49 @@ const deleteFees= (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateFees = (req, res) => {
|
||||||
|
const updateData = req.body;
|
||||||
|
const dateRange = updateData.dateRange ? updateData.dateRange : null;
|
||||||
|
const incidents = updateData.updatedIncidentsData ? updateData.updatedIncidentsData : null;
|
||||||
|
const memberId = updateData.memberId ? updateData.memberId : null;
|
||||||
|
|
||||||
|
const unlockedIncidentFees = incidents.unlockedIncidentFees ? incidents.unlockedIncidentFees : {};
|
||||||
|
const unscheduledIncidentFees = incidents.unscheduledIncidentFees ? incidents.unscheduledIncidentFees : {};
|
||||||
|
const bookingChangeIncidentFees = incidents.bookingChangeIncidentFees ? incidents.bookingChangeIncidentFees : {};
|
||||||
|
|
||||||
|
req.params.startDate = dateRange.startDate ? dateRange.startDate : null;
|
||||||
|
req.params.endDate = dateRange.endDate ? dateRange.endDate : null;
|
||||||
|
|
||||||
|
if (unlockedIncidentFees && unscheduledIncidentFees && bookingChangeIncidentFees){
|
||||||
|
const asyncUpdateActions = [
|
||||||
|
updateUnlockedIncidentsById(unlockedIncidentFees),
|
||||||
|
updateUnscheduledIncidentsById(unscheduledIncidentFees),
|
||||||
|
updateBookingChangeIncidentsById(bookingChangeIncidentFees)
|
||||||
|
];
|
||||||
|
|
||||||
|
Promise.all(asyncUpdateActions)
|
||||||
|
.then(() => {
|
||||||
|
if (memberId){
|
||||||
|
req.params.memberId = memberId;
|
||||||
|
getMemberIncidents(req, res);
|
||||||
|
}else{
|
||||||
|
getAllIncidentsController(req, res);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log('Error updating incidents : ', error);
|
||||||
|
res.status(500).send();
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
if (memberId){
|
||||||
|
req.params.memberId = memberId;
|
||||||
|
getMemberIncidents(req, res);
|
||||||
|
}else{
|
||||||
|
getAllIncidentsController(req, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const checkProcessingStatus = (req, res) => {
|
const checkProcessingStatus = (req, res) => {
|
||||||
checkIfProcessing()
|
checkIfProcessing()
|
||||||
.then((processing) => {
|
.then((processing) => {
|
||||||
@@ -272,5 +325,6 @@ module.exports = {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
deleteFees
|
deleteFees,
|
||||||
|
updateFees
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ const {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
deleteFees
|
deleteFees,
|
||||||
|
updateFees
|
||||||
} = require('../controllers/integration');
|
} = require('../controllers/integration');
|
||||||
|
|
||||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||||
@@ -36,6 +37,7 @@ router.get('/officeRnD/membersList', fetchMembersList);
|
|||||||
|
|
||||||
router.post('/integration/addFees', addFees);
|
router.post('/integration/addFees', addFees);
|
||||||
router.delete('/integration/fees', deleteFees);
|
router.delete('/integration/fees', deleteFees);
|
||||||
|
router.patch('/integration/fees', updateFees);
|
||||||
|
|
||||||
router.get('/integration/processing', checkProcessingStatus);
|
router.get('/integration/processing', checkProcessingStatus);
|
||||||
|
|
||||||
@@ -44,6 +46,14 @@ router.get('/integration/report/practiceSummary/:year', getPracticeSummaryReport
|
|||||||
|
|
||||||
|
|
||||||
// temporary route, manually trigger door lock charge calculations
|
// temporary route, manually trigger door lock charge calculations
|
||||||
router.get('/calculate', (req, res) => { calculateDoorLockCharges(); res.send();});
|
router.get('/calculate', (req, res) => {
|
||||||
|
calculateDoorLockCharges()
|
||||||
|
.then(() => {
|
||||||
|
res.send('Done');
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
res.send(`Error \r\n ${err}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -283,6 +283,22 @@ const deleteBookingChangeIncidentsById = (incidentIds) => {
|
|||||||
return db.bookingChangeIncident.update({deleted: true},{where: filters});
|
return db.bookingChangeIncident.update({deleted: true},{where: filters});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateBookingChangeIncidentsById = (incidentFees) => {
|
||||||
|
const incidentIds = Object.keys(incidentFees);
|
||||||
|
|
||||||
|
const asyncUpdateActions = [];
|
||||||
|
|
||||||
|
incidentIds.forEach((incidentId) => {
|
||||||
|
const newFeeCharge = parseFloat(incidentFees[incidentId]);
|
||||||
|
|
||||||
|
if (newFeeCharge || (newFeeCharge === 0)){
|
||||||
|
asyncUpdateActions.push(db.bookingChangeIncident.update({chargeFee: newFeeCharge}, {where: {id: incidentId}}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(asyncUpdateActions);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getChargedCanceledReservations,
|
getChargedCanceledReservations,
|
||||||
getIncidentsFromChanges,
|
getIncidentsFromChanges,
|
||||||
@@ -290,5 +306,6 @@ module.exports = {
|
|||||||
getShorteningIncidentsForReservationId,
|
getShorteningIncidentsForReservationId,
|
||||||
getReservationsIncidentsForRemoval,
|
getReservationsIncidentsForRemoval,
|
||||||
deleteBookingChangeIncidents,
|
deleteBookingChangeIncidents,
|
||||||
deleteBookingChangeIncidentsById
|
deleteBookingChangeIncidentsById,
|
||||||
|
updateBookingChangeIncidentsById
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -80,6 +80,26 @@ const deleteUnscheduledIncidentsById = (incidentIds) => {
|
|||||||
return db.unscheduledIncident.update({deleted: true},{where: filters});
|
return db.unscheduledIncident.update({deleted: true},{where: filters});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateUnscheduledIncidentsById = (incidentFees) => {
|
||||||
|
const incidentIds = Object.keys(incidentFees);
|
||||||
|
|
||||||
|
const asyncUpdateActions = [];
|
||||||
|
|
||||||
|
incidentIds.forEach((incidentId) => {
|
||||||
|
const newFeeCharge = parseFloat(incidentFees[incidentId]);
|
||||||
|
|
||||||
|
if (newFeeCharge || (newFeeCharge === 0)){
|
||||||
|
asyncUpdateActions.push(db.unscheduledIncident.update({
|
||||||
|
totalChargeFee: newFeeCharge,
|
||||||
|
chargePrice: newFeeCharge,
|
||||||
|
timeIntervalsToCharge: 1
|
||||||
|
}, {where: {id: incidentId}}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(asyncUpdateActions);
|
||||||
|
};
|
||||||
|
|
||||||
const insertUnlockedIncidents = (incidents) => {
|
const insertUnlockedIncidents = (incidents) => {
|
||||||
const asyncJobs = [];
|
const asyncJobs = [];
|
||||||
incidents.forEach((incident) => {
|
incidents.forEach((incident) => {
|
||||||
@@ -106,7 +126,6 @@ const insertUnlockedIncidents = (incidents) => {
|
|||||||
bookingStart: start,
|
bookingStart: start,
|
||||||
bookingEnd: end,
|
bookingEnd: end,
|
||||||
unlockTimestamp,
|
unlockTimestamp,
|
||||||
incidentLevel,
|
|
||||||
},
|
},
|
||||||
defaults: {...incidentForDB},
|
defaults: {...incidentForDB},
|
||||||
}));
|
}));
|
||||||
@@ -124,6 +143,22 @@ const deleteUnlockedIncidentsById = (incidentIds) => {
|
|||||||
return db.unlockedIncident.update({deleted: true},{where: filters});
|
return db.unlockedIncident.update({deleted: true},{where: filters});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateUnlockedIncidentsById = (incidentFees) => {
|
||||||
|
const incidentIds = Object.keys(incidentFees);
|
||||||
|
|
||||||
|
const asyncUpdateActions = [];
|
||||||
|
|
||||||
|
incidentIds.forEach((incidentId) => {
|
||||||
|
const newFeeCharge = parseFloat(incidentFees[incidentId]);
|
||||||
|
|
||||||
|
if (newFeeCharge || (newFeeCharge === 0)){
|
||||||
|
asyncUpdateActions.push(db.unlockedIncident.update({incidentLevelPrice: newFeeCharge}, {where: {id: incidentId}}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(asyncUpdateActions);
|
||||||
|
};
|
||||||
|
|
||||||
const setUnlockedIncidentsLevel = (incidents) => {
|
const setUnlockedIncidentsLevel = (incidents) => {
|
||||||
return new Promise ((resolve, reject) => {
|
return new Promise ((resolve, reject) => {
|
||||||
const sortingFunction = (incidentA, incidentB) => {
|
const sortingFunction = (incidentA, incidentB) => {
|
||||||
@@ -162,7 +197,7 @@ const setUnlockedIncidentsLevel = (incidents) => {
|
|||||||
const incidentsWithLevel = [];
|
const incidentsWithLevel = [];
|
||||||
|
|
||||||
incidents.forEach((incident) => {
|
incidents.forEach((incident) => {
|
||||||
const memberLastIncident = membersLastIncident[incident.memberId];
|
const memberLastIncident = Object.assign({}, membersLastIncident[incident.memberId]);
|
||||||
|
|
||||||
const formattedIncident = {
|
const formattedIncident = {
|
||||||
reservation: incident.reservation,
|
reservation: incident.reservation,
|
||||||
@@ -850,5 +885,7 @@ const calculateDoorLockCharges = () => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
calculateDoorLockCharges,
|
calculateDoorLockCharges,
|
||||||
deleteUnlockedIncidentsById,
|
deleteUnlockedIncidentsById,
|
||||||
deleteUnscheduledIncidentsById
|
deleteUnscheduledIncidentsById,
|
||||||
|
updateUnlockedIncidentsById,
|
||||||
|
updateUnscheduledIncidentsById
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user