Compare commits
1 Commits
master
...
delete-fee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc56ed3f03 |
@@ -1,142 +0,0 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
import moment from 'moment';
|
|
||||||
|
|
||||||
import { Form, Message, Grid } from 'semantic-ui-react';
|
|
||||||
|
|
||||||
import { defaultDateFormat } from '../../constants/constants';
|
|
||||||
|
|
||||||
class DateRangePicker extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
const initialStartDate = props.startDate ? moment(props.startDate, defaultDateFormat) : moment().startOf('month');
|
|
||||||
let initialEndDate = props.endDate ? moment(props.endDate, defaultDateFormat) : moment();
|
|
||||||
|
|
||||||
if (initialStartDate > initialEndDate){
|
|
||||||
initialEndDate = initialStartDate.add(1, 'day');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
startDate: initialStartDate,
|
|
||||||
endDate: initialEndDate,
|
|
||||||
error: null,
|
|
||||||
startDateLabel: props.startDateLabel || 'Start date',
|
|
||||||
endDateLabel: props.endDateLabel || 'End date',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
onStartDateChange(event) {
|
|
||||||
const { endDate, startDateLabel, endDateLabel } = this.state;
|
|
||||||
|
|
||||||
const newStartDate = moment(event.target.value, defaultDateFormat);
|
|
||||||
if (newStartDate > endDate){
|
|
||||||
this.setState({
|
|
||||||
error: `${startDateLabel} cannot be after ${endDateLabel}`
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.setState({startDate: newStartDate, error: null});
|
|
||||||
}
|
|
||||||
|
|
||||||
onEndDateChange(event) {
|
|
||||||
const { startDate, startDateLabel, endDateLabel } = this.state;
|
|
||||||
|
|
||||||
const newEndDate = moment(event.target.value, defaultDateFormat);
|
|
||||||
if (newEndDate < startDate){
|
|
||||||
this.setState({
|
|
||||||
error: `${startDateLabel} cannot be after ${endDateLabel}`
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.setState({endDate: newEndDate, error: null});
|
|
||||||
}
|
|
||||||
|
|
||||||
onDismiss() {
|
|
||||||
this.setState({error: null});
|
|
||||||
}
|
|
||||||
|
|
||||||
onButtonClick() {
|
|
||||||
const { onDatesUpdate } = this.props;
|
|
||||||
const { startDate, endDate } = this.state;
|
|
||||||
|
|
||||||
if (onDatesUpdate){
|
|
||||||
onDatesUpdate({
|
|
||||||
startDate: startDate.format(defaultDateFormat),
|
|
||||||
endDate: endDate.format(defaultDateFormat),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.onButtonClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { startDate, endDate, error, startDateLabel, endDateLabel } = this.state;
|
|
||||||
const { inlineButton } = this.props;
|
|
||||||
|
|
||||||
const buttonLabel = this.props.buttonLabel || 'Save';
|
|
||||||
|
|
||||||
const startDateValue = startDate.format(defaultDateFormat);
|
|
||||||
const endDateValue = endDate.format(defaultDateFormat);
|
|
||||||
|
|
||||||
const buttonRender = (
|
|
||||||
<Grid.Column width={inlineButton ? 3 : null}>
|
|
||||||
{ inlineButton && <label>{'\u00A0'}</label> }
|
|
||||||
<Form.Button onClick={this.onButtonClick.bind(this)}>{buttonLabel}</Form.Button>
|
|
||||||
</Grid.Column>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Form>
|
|
||||||
<Grid stackable columns={inlineButton ? null : 'equal'}>
|
|
||||||
<Grid.Row>
|
|
||||||
<Grid.Column width={inlineButton ? 7 : null}>
|
|
||||||
<label>{startDateLabel}</label>
|
|
||||||
<Form.Input
|
|
||||||
fluid
|
|
||||||
required
|
|
||||||
type="date"
|
|
||||||
value={startDateValue}
|
|
||||||
onChange={this.onStartDateChange.bind(this)}
|
|
||||||
/>
|
|
||||||
</Grid.Column>
|
|
||||||
<Grid.Column width={inlineButton ? 6 : null}>
|
|
||||||
<label>{endDateLabel}</label>
|
|
||||||
<Form.Input
|
|
||||||
fluid
|
|
||||||
required
|
|
||||||
type="date"
|
|
||||||
value={endDateValue}
|
|
||||||
onChange={this.onEndDateChange.bind(this)}
|
|
||||||
/>
|
|
||||||
</Grid.Column>
|
|
||||||
{
|
|
||||||
inlineButton && buttonRender
|
|
||||||
}
|
|
||||||
</Grid.Row>
|
|
||||||
{ error &&
|
|
||||||
<Grid.Row>
|
|
||||||
<Grid.Column>
|
|
||||||
<Message color="orange" onDismiss={this.onDismiss.bind(this)}>
|
|
||||||
<Message.Header>Wrong date</Message.Header>
|
|
||||||
<p><b>{startDateLabel}</b> has to be before <b>{endDateLabel}</b></p>
|
|
||||||
</Message>
|
|
||||||
</Grid.Column>
|
|
||||||
</Grid.Row>
|
|
||||||
}
|
|
||||||
{
|
|
||||||
!inlineButton &&
|
|
||||||
<Grid.Row>
|
|
||||||
{buttonRender}
|
|
||||||
</Grid.Row>
|
|
||||||
}
|
|
||||||
</Grid>
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DateRangePicker;
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,384 +1,167 @@
|
|||||||
import React, { Component } from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { Loader } from 'semantic-ui-react';
|
||||||
import { Loader, Button } from 'semantic-ui-react';
|
import ReactTable from 'react-table';
|
||||||
import 'react-table/react-table.css';
|
import 'react-table/react-table.css';
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
|
|
||||||
import SelectTable from "../../SelectTable";
|
|
||||||
|
|
||||||
import {incidentsReportHeaderTitles} from '../../../constants/constants';
|
import {incidentsReportHeaderTitles} from '../../../constants/constants';
|
||||||
import {
|
import {
|
||||||
incidentTableTypes,
|
incidentTableTypes,
|
||||||
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, BOOKING_CANCELED_LATE, BOOKING_MOVED_TO_ANOTHER_DAY,
|
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE
|
||||||
BOOKING_SHORTENED
|
|
||||||
} from '../../../constants/enums';
|
} from '../../../constants/enums';
|
||||||
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
||||||
import { deleteIncidents, updateIncidentFees } from "../../../store/actions";
|
|
||||||
|
|
||||||
class SingleIncidentsTable extends Component {
|
|
||||||
state = {
|
|
||||||
selectedUnlockedIncidentIds: [],
|
|
||||||
selectedUnscheduledIncidentIds: [],
|
|
||||||
selectedBookingChangeIncidentIds: [],
|
|
||||||
changedUnlockedIncidentIds: {},
|
|
||||||
changedUnscheduledIncidentIds: {},
|
|
||||||
changedBookingChangeIncidentIds: {},
|
|
||||||
inputIdToFocus: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
onSelectChange = (selectedIncidents) => {
|
const SingleIncidentsTable = props => {
|
||||||
const newSelectedUnlockedIncidentIds = [];
|
const {
|
||||||
const newSelectedUnscheduledIncidentIds = [];
|
loading,
|
||||||
const newSelectedBookingChangeIncidentIds = [];
|
title,
|
||||||
|
openMemberSummaryOnMemberClick,
|
||||||
|
hideMemberName,
|
||||||
|
tableType
|
||||||
|
} = props;
|
||||||
|
const incidents = props.incidents ? props.incidents : [];
|
||||||
|
const columns = [];
|
||||||
|
|
||||||
selectedIncidents.forEach(incident => {
|
if (incidents && incidents.length > 0){
|
||||||
const incidentDetails = incident.split('-');
|
let tableHeaders;
|
||||||
// incident is described as : select-incidentType-incidentId
|
switch (tableType) {
|
||||||
if (Array.isArray(incidentDetails) && incidentDetails.length > 2){
|
case incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS:
|
||||||
const incidentType = parseInt(incidentDetails[1]);
|
tableHeaders = doorLockRelatedWithReservationIncidentHeaders;
|
||||||
const incidentId = parseInt(incidentDetails[2]);
|
break;
|
||||||
|
case incidentTableTypes.STANDALONE_INCIDENTS:
|
||||||
switch (incidentType) {
|
tableHeaders = standaloneDoorLockIncidentHeaders;
|
||||||
case 2:
|
break;
|
||||||
case 5:
|
case incidentTableTypes.BOOKING_CHANGE_INCIDENTS:
|
||||||
newSelectedUnlockedIncidentIds.push(incidentId);
|
tableHeaders = bookingChangeIncidentHeaders;
|
||||||
break;
|
break;
|
||||||
case 3:
|
default:
|
||||||
case 4:
|
break;
|
||||||
case 6:
|
|
||||||
newSelectedUnscheduledIncidentIds.push(incidentId);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
newSelectedBookingChangeIncidentIds.push(incidentId);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
selectedUnlockedIncidentIds: newSelectedUnlockedIncidentIds,
|
|
||||||
selectedUnscheduledIncidentIds: newSelectedUnscheduledIncidentIds,
|
|
||||||
selectedBookingChangeIncidentIds: newSelectedBookingChangeIncidentIds
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
deleteSelectedFees = () => {
|
|
||||||
const { dateRange, deleteIncidentsById, memberId } = this.props;
|
|
||||||
const { selectedUnlockedIncidentIds, selectedUnscheduledIncidentIds, selectedBookingChangeIncidentIds } = this.state;
|
|
||||||
|
|
||||||
const incidentsToDelete = {
|
|
||||||
unlockedIncidentIds: selectedUnlockedIncidentIds,
|
|
||||||
unscheduledIncidentIds: selectedUnscheduledIncidentIds,
|
|
||||||
bookingChangeIncidentIds: selectedBookingChangeIncidentIds
|
|
||||||
};
|
|
||||||
|
|
||||||
deleteIncidentsById(dateRange, incidentsToDelete, memberId);
|
|
||||||
this.setState({
|
|
||||||
selectedUnlockedIncidentIds: [],
|
|
||||||
selectedUnscheduledIncidentIds: [],
|
|
||||||
selectedBookingChangeIncidentIds: []
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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(){
|
|
||||||
const {
|
|
||||||
loading,
|
|
||||||
title,
|
|
||||||
openMemberSummaryOnMemberClick,
|
|
||||||
hideMemberName,
|
|
||||||
tableType
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
const {
|
|
||||||
selectedUnlockedIncidentIds,
|
|
||||||
selectedUnscheduledIncidentIds,
|
|
||||||
selectedBookingChangeIncidentIds,
|
|
||||||
changedUnlockedIncidentIds,
|
|
||||||
changedUnscheduledIncidentIds,
|
|
||||||
changedBookingChangeIncidentIds,
|
|
||||||
inputIdToFocus
|
|
||||||
} = this.state;
|
|
||||||
|
|
||||||
const totalSelected = selectedUnlockedIncidentIds.length + selectedUnscheduledIncidentIds.length + selectedBookingChangeIncidentIds.length;
|
|
||||||
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 : [];
|
|
||||||
incidents.forEach(incident => {
|
|
||||||
incident.id = `${incident.incidentType}-${incident.incidentId}`;
|
|
||||||
});
|
|
||||||
const columns = [];
|
|
||||||
|
|
||||||
if (incidents && incidents.length > 0){
|
|
||||||
let tableHeaders;
|
|
||||||
switch (tableType) {
|
|
||||||
case incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS:
|
|
||||||
tableHeaders = doorLockRelatedWithReservationIncidentHeaders;
|
|
||||||
break;
|
|
||||||
case incidentTableTypes.STANDALONE_INCIDENTS:
|
|
||||||
tableHeaders = standaloneDoorLockIncidentHeaders;
|
|
||||||
break;
|
|
||||||
case incidentTableTypes.BOOKING_CHANGE_INCIDENTS:
|
|
||||||
tableHeaders = bookingChangeIncidentHeaders;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
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) => {
|
|
||||||
const columnTitle = incidentsReportHeaderTitles[header];
|
|
||||||
|
|
||||||
let showColumn = true;
|
|
||||||
if (header === 'memberName' && hideMemberName){
|
|
||||||
showColumn = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (columnTitle && showColumn){
|
|
||||||
const columnAlignments = {
|
|
||||||
left: 'left',
|
|
||||||
right: 'right',
|
|
||||||
};
|
|
||||||
let columnContentsAlignment = columnAlignments.left;
|
|
||||||
|
|
||||||
columns.push({
|
|
||||||
Header: incidentsReportHeaderTitles[header],
|
|
||||||
accessor: header,
|
|
||||||
Cell: props => {
|
|
||||||
let cellValue = '';
|
|
||||||
let urlValue = undefined;
|
|
||||||
let clickablePrice = undefined;
|
|
||||||
let priceAsNumber = undefined;
|
|
||||||
let priceInputID = undefined;
|
|
||||||
let priceFontColor = 'black';
|
|
||||||
|
|
||||||
switch (props.column.id) {
|
|
||||||
case 'memberName':
|
|
||||||
const memberId = props.row['_original'].memberId;
|
|
||||||
urlValue = `/specific-member-incidents-report/${memberId}`;
|
|
||||||
cellValue = props.value;
|
|
||||||
break;
|
|
||||||
case 'resourceName':
|
|
||||||
if (props.row['_original'].resourceName){
|
|
||||||
cellValue = props.row['_original'].resourceName || '---';
|
|
||||||
}else{
|
|
||||||
const oldResourceName = props.row['_original'].oldResourceName || '---';
|
|
||||||
const newResourceName = props.row['_original'].newResourceName || '---';
|
|
||||||
if (oldResourceName !== newResourceName){
|
|
||||||
cellValue = `${oldResourceName}\n${newResourceName}`;
|
|
||||||
}else{
|
|
||||||
cellValue = oldResourceName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'reservation':
|
|
||||||
const bookingStart = props.row['_original'].bookingStart;
|
|
||||||
const bookingEnd = props.row['_original'].bookingEnd;
|
|
||||||
cellValue = `${bookingStart}\n${bookingEnd}`;
|
|
||||||
break;
|
|
||||||
case 'doorLockTimestamps':
|
|
||||||
const unlockTimestamp = props.row['_original'].unlockTimestamp;
|
|
||||||
const lockTimestamp = props.row['_original'].lockTimestamp;
|
|
||||||
cellValue = `${unlockTimestamp ? unlockTimestamp : '---'}\n${lockTimestamp ? lockTimestamp : '---'}`;
|
|
||||||
break;
|
|
||||||
case 'incidentType':
|
|
||||||
cellValue = incidentDescriptions[props.value];
|
|
||||||
break;
|
|
||||||
case 'incidentLevel':
|
|
||||||
cellValue = incidentLevelDescriptions[props.value];
|
|
||||||
break;
|
|
||||||
case 'feeDescription':
|
|
||||||
const { incidentType, incidentLevel, timeIntervalsToCharge } = props.row['_original'];
|
|
||||||
|
|
||||||
switch (incidentType) {
|
|
||||||
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
|
||||||
case UNLOCKED_INCIDENT_STANDALONE:
|
|
||||||
cellValue = `${incidentLevelDescriptions[incidentLevel]}`;
|
|
||||||
break;
|
|
||||||
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
|
||||||
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
|
||||||
case UNSCHEDULED_INCIDENT_STANDALONE:
|
|
||||||
cellValue = `${timeIntervalsToCharge} x 5 min`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cellValue = '';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'totalChargeFee':
|
|
||||||
clickablePrice = true;
|
|
||||||
let totalFee = 0;
|
|
||||||
|
|
||||||
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;
|
|
||||||
break;
|
|
||||||
case 'oldReservation':
|
|
||||||
const oldBookingStart = props.row['_original'].oldBookingStart;
|
|
||||||
const oldBookingEnd = props.row['_original'].oldBookingEnd;
|
|
||||||
cellValue = `${oldBookingStart}\n${oldBookingEnd}`;
|
|
||||||
break;
|
|
||||||
case 'newReservation':
|
|
||||||
const newBookingStart = props.row['_original'].newBookingStart || '---';
|
|
||||||
const newBookingEnd = props.row['_original'].newBookingEnd || '---';
|
|
||||||
cellValue = `${newBookingStart}\n${newBookingEnd}`;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cellValue = props.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clickablePrice){
|
|
||||||
return <p>$ <input
|
|
||||||
id={priceInputID}
|
|
||||||
style={{ color: priceFontColor }}
|
|
||||||
type={'number'}
|
|
||||||
onChange={priceChangeHandler}
|
|
||||||
value={priceAsNumber}
|
|
||||||
autoFocus={priceInputID === inputIdToFocus}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
}else{
|
|
||||||
if (openMemberSummaryOnMemberClick && urlValue){
|
|
||||||
return <NavLink to={urlValue}>{cellValue}</NavLink>
|
|
||||||
}else{
|
|
||||||
return <div style={{ textAlign: columnContentsAlignment, whiteSpace: 'pre' }}>{cellValue}</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
tableHeaders.forEach((header) => {
|
||||||
<div>
|
const columnTitle = incidentsReportHeaderTitles[header];
|
||||||
<h4>{title}</h4>
|
|
||||||
<Loader active={loading} />
|
let showColumn = true;
|
||||||
{
|
if (header === 'memberName' && hideMemberName){
|
||||||
<Button disabled={loading || totalSelected === 0} onClick={this.deleteSelectedFees}>{`Delete selected ${numberOfSelectedText}`}</Button>
|
showColumn = false;
|
||||||
}
|
}
|
||||||
{
|
|
||||||
<Button disabled={loading || totalChanged === 0} onClick={this.updateChangedFees}>{`Save changed ${numberOfChangedText}`}</Button>
|
if (columnTitle && showColumn){
|
||||||
}
|
const columnAlignments = {
|
||||||
<br/><br/>
|
left: 'left',
|
||||||
{
|
right: 'right',
|
||||||
!loading && incidents &&
|
};
|
||||||
<SelectTable
|
let columnContentsAlignment = columnAlignments.left;
|
||||||
data={incidents}
|
|
||||||
multiSort={false}
|
columns.push({
|
||||||
columns={columns}
|
Header: incidentsReportHeaderTitles[header],
|
||||||
keyField="id"
|
accessor: header,
|
||||||
onSelectChange={this.onSelectChange}
|
Cell: props => {
|
||||||
/>
|
let cellValue = '';
|
||||||
}
|
let urlValue = undefined;
|
||||||
</div>
|
|
||||||
);
|
switch (props.column.id) {
|
||||||
|
case 'memberName':
|
||||||
|
const memberId = props.row['_original'].memberId;
|
||||||
|
urlValue = `/specific-member-incidents-report/${memberId}`;
|
||||||
|
cellValue = props.value;
|
||||||
|
break;
|
||||||
|
case 'resourceName':
|
||||||
|
if (props.row['_original'].resourceName){
|
||||||
|
cellValue = props.row['_original'].resourceName || '---';
|
||||||
|
}else{
|
||||||
|
const oldResourceName = props.row['_original'].oldResourceName || '---';
|
||||||
|
const newResourceName = props.row['_original'].newResourceName || '---';
|
||||||
|
if (oldResourceName !== newResourceName){
|
||||||
|
cellValue = `${oldResourceName}\n${newResourceName}`;
|
||||||
|
}else{
|
||||||
|
cellValue = oldResourceName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'reservation':
|
||||||
|
const bookingStart = props.row['_original'].bookingStart;
|
||||||
|
const bookingEnd = props.row['_original'].bookingEnd;
|
||||||
|
cellValue = `${bookingStart}\n${bookingEnd}`;
|
||||||
|
break;
|
||||||
|
case 'doorLockTimestamps':
|
||||||
|
const unlockTimestamp = props.row['_original'].unlockTimestamp;
|
||||||
|
const lockTimestamp = props.row['_original'].lockTimestamp;
|
||||||
|
cellValue = `${unlockTimestamp ? unlockTimestamp : '---'}\n${lockTimestamp ? lockTimestamp : '---'}`;
|
||||||
|
break;
|
||||||
|
case 'incidentType':
|
||||||
|
cellValue = incidentDescriptions[props.value];
|
||||||
|
break;
|
||||||
|
case 'incidentLevel':
|
||||||
|
cellValue = incidentLevelDescriptions[props.value];
|
||||||
|
break;
|
||||||
|
case 'feeDescription':
|
||||||
|
const { incidentType, incidentLevel, timeIntervalsToCharge } = props.row['_original'];
|
||||||
|
|
||||||
|
switch (incidentType) {
|
||||||
|
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
|
case UNLOCKED_INCIDENT_STANDALONE:
|
||||||
|
cellValue = `${incidentLevelDescriptions[incidentLevel]}`;
|
||||||
|
break;
|
||||||
|
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
|
case UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
|
cellValue = `${timeIntervalsToCharge} x 5 min`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cellValue = '';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'totalChargeFee':
|
||||||
|
const totalFee = (props.row['_original'].incidentPrice || props.value) || 0;
|
||||||
|
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
||||||
|
cellValue = `$ ${totalFeeFormatted}`;
|
||||||
|
columnContentsAlignment = columnAlignments.right;
|
||||||
|
break;
|
||||||
|
case 'oldReservation':
|
||||||
|
const oldBookingStart = props.row['_original'].oldBookingStart;
|
||||||
|
const oldBookingEnd = props.row['_original'].oldBookingEnd;
|
||||||
|
cellValue = `${oldBookingStart}\n${oldBookingEnd}`;
|
||||||
|
break;
|
||||||
|
case 'newReservation':
|
||||||
|
const newBookingStart = props.row['_original'].newBookingStart || '---';
|
||||||
|
const newBookingEnd = props.row['_original'].newBookingEnd || '---';
|
||||||
|
cellValue = `${newBookingStart}\n${newBookingEnd}`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cellValue = props.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (openMemberSummaryOnMemberClick && urlValue){
|
||||||
|
return <NavLink to={urlValue}>{cellValue}</NavLink>
|
||||||
|
}else{
|
||||||
|
return <div style={{ textAlign: columnContentsAlignment, whiteSpace: 'pre' }}>{cellValue}</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
return (
|
||||||
deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId}),
|
<div>
|
||||||
updateIncidentsById: (dateRange, updatedIncidentsData, memberId) => updateIncidentFees(dispatch, {dateRange, updatedIncidentsData, memberId})
|
<h4>{title}</h4>
|
||||||
});
|
<Loader active={loading} />
|
||||||
|
{
|
||||||
|
!loading && incidents &&
|
||||||
|
<ReactTable
|
||||||
|
data={incidents}
|
||||||
|
multiSort={false}
|
||||||
|
columns={columns}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(SingleIncidentsTable);
|
export default SingleIncidentsTable;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '../../constants/enums';
|
} from '../../constants/enums';
|
||||||
|
|
||||||
export default function MemberIncidentsTables (props) {
|
export default function MemberIncidentsTables (props) {
|
||||||
const { pendingIncidents, incidents, hideMemberName, dateRange, memberId } = props;
|
const { pendingIncidents, incidents, hideMemberName } = props;
|
||||||
|
|
||||||
const incidentsRelatedToReservations = [];
|
const incidentsRelatedToReservations = [];
|
||||||
const standaloneIncidents = [];
|
const standaloneIncidents = [];
|
||||||
@@ -46,8 +46,6 @@ export default function MemberIncidentsTables (props) {
|
|||||||
openMemberSummaryOnMemberClick
|
openMemberSummaryOnMemberClick
|
||||||
hideMemberName={hideMemberName}
|
hideMemberName={hideMemberName}
|
||||||
tableType={incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS}
|
tableType={incidentTableTypes.INCIDENTS_RELATED_TO_RESERVATIONS}
|
||||||
dateRange={dateRange}
|
|
||||||
memberId={memberId}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -58,8 +56,6 @@ export default function MemberIncidentsTables (props) {
|
|||||||
openMemberSummaryOnMemberClick
|
openMemberSummaryOnMemberClick
|
||||||
hideMemberName={hideMemberName}
|
hideMemberName={hideMemberName}
|
||||||
tableType={incidentTableTypes.STANDALONE_INCIDENTS}
|
tableType={incidentTableTypes.STANDALONE_INCIDENTS}
|
||||||
dateRange={dateRange}
|
|
||||||
memberId={memberId}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -70,8 +66,6 @@ export default function MemberIncidentsTables (props) {
|
|||||||
openMemberSummaryOnMemberClick
|
openMemberSummaryOnMemberClick
|
||||||
hideMemberName={hideMemberName}
|
hideMemberName={hideMemberName}
|
||||||
tableType={incidentTableTypes.BOOKING_CHANGE_INCIDENTS}
|
tableType={incidentTableTypes.BOOKING_CHANGE_INCIDENTS}
|
||||||
dateRange={dateRange}
|
|
||||||
memberId={memberId}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
import Table from 'react-table';
|
|
||||||
import SelectTableHOC from 'react-table/lib/hoc/selectTable';
|
|
||||||
|
|
||||||
const SelectTableElement = SelectTableHOC(Table);
|
|
||||||
|
|
||||||
class SelectTable extends Component {
|
|
||||||
static defaultProps = {
|
|
||||||
keyField: "id"
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggle a single checkbox for select table
|
|
||||||
*/
|
|
||||||
toggleSelection = (key, shift, row) => {
|
|
||||||
// start off with the existing state
|
|
||||||
let selection = [...this.state.selection];
|
|
||||||
const keyIndex = selection.indexOf(key);
|
|
||||||
|
|
||||||
// check to see if the key exists
|
|
||||||
if (keyIndex >= 0) {
|
|
||||||
// it does exist so we will remove it using destructing
|
|
||||||
selection = [
|
|
||||||
...selection.slice(0, keyIndex),
|
|
||||||
...selection.slice(keyIndex + 1)
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
// it does not exist so add it
|
|
||||||
selection.push(key);
|
|
||||||
}
|
|
||||||
// update the state
|
|
||||||
this.props.onSelectChange(selection);
|
|
||||||
this.setState({ selection });
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggle all checkboxes for select table
|
|
||||||
*/
|
|
||||||
toggleAll = () => {
|
|
||||||
const { keyField } = this.props;
|
|
||||||
const selectAll = !this.state.selectAll;
|
|
||||||
const selection = [];
|
|
||||||
|
|
||||||
if (selectAll) {
|
|
||||||
// we need to get at the internals of ReactTable
|
|
||||||
const wrappedInstance = this.checkboxTable.getWrappedInstance();
|
|
||||||
// the 'sortedData' property contains the currently accessible records based on the filter and sort
|
|
||||||
const currentRecords = wrappedInstance.getResolvedState().sortedData;
|
|
||||||
// we just push all the IDs onto the selection array
|
|
||||||
currentRecords.forEach(item => {
|
|
||||||
selection.push(`select-${item._original[keyField]}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.props.onSelectChange(selection);
|
|
||||||
this.setState({ selectAll, selection });
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not a row is selected for select table
|
|
||||||
*/
|
|
||||||
isSelected = key => {
|
|
||||||
return this.state.selection.includes(`select-${key}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
rowFn = (state, rowInfo, column, instance) => {
|
|
||||||
const { selection } = this.state;
|
|
||||||
|
|
||||||
return {
|
|
||||||
onClick: (e, handleOriginal) => {
|
|
||||||
// console.log("It was in this row:", rowInfo);
|
|
||||||
|
|
||||||
// IMPORTANT! React-Table uses onClick internally to trigger
|
|
||||||
// events like expanding SubComponents and pivots.
|
|
||||||
// By default a custom 'onClick' handler will override this functionality.
|
|
||||||
// If you want to fire the original onClick handler, call the
|
|
||||||
// 'handleOriginal' function.
|
|
||||||
if (handleOriginal) {
|
|
||||||
handleOriginal();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
background:
|
|
||||||
rowInfo &&
|
|
||||||
selection.includes(`select-${rowInfo.original.id}`) &&
|
|
||||||
"lightgreen"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
state = {
|
|
||||||
selectAll: false,
|
|
||||||
selection: []
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<SelectTableElement
|
|
||||||
{...this.props}
|
|
||||||
ref={r => (this.checkboxTable = r)}
|
|
||||||
toggleSelection={this.toggleSelection}
|
|
||||||
selectAll={this.state.selectAll}
|
|
||||||
selectType="checkbox"
|
|
||||||
toggleAll={this.toggleAll}
|
|
||||||
isSelected={this.isSelected}
|
|
||||||
getTrProps={this.rowFn}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default SelectTable;
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
export const CONTAINER_WIDTH_PERCENTAGE = 90;
|
|
||||||
|
|
||||||
export const defaultDateFormat = 'YYYY-MM-DD';
|
export const defaultDateFormat = 'YYYY-MM-DD';
|
||||||
|
|
||||||
export const doorLockRelatedWithReservationIncidentHeaders = [
|
export const doorLockRelatedWithReservationIncidentHeaders = [
|
||||||
@@ -7,7 +5,6 @@ export const doorLockRelatedWithReservationIncidentHeaders = [
|
|||||||
'resourceName',
|
'resourceName',
|
||||||
'memberName',
|
'memberName',
|
||||||
'reservation',
|
'reservation',
|
||||||
'doorLockTimestamps',
|
|
||||||
'incidentType',
|
'incidentType',
|
||||||
'feeDescription',
|
'feeDescription',
|
||||||
'totalChargeFee'
|
'totalChargeFee'
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import { Container, Message } from 'semantic-ui-react';
|
|||||||
|
|
||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
import { mainMenuItems } from '../../constants/menuItems';
|
import { mainMenuItems } from '../../constants/menuItems';
|
||||||
import {CONTAINER_WIDTH_PERCENTAGE} from "../../constants/constants";
|
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<Container style={ {width: `${CONTAINER_WIDTH_PERCENTAGE}%`} }>
|
<Container>
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>SIMA SPACE </h3>
|
<h3>SIMA SPACE </h3>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ import { connect } from 'react-redux';
|
|||||||
import { Container } from 'semantic-ui-react';
|
import { Container } from 'semantic-ui-react';
|
||||||
|
|
||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
import DateRangePicker from '../../components/DateRangePicker';
|
import MonthSelector from '../../components/MonthSelector';
|
||||||
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
|
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
|
||||||
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
|
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
|
||||||
|
|
||||||
import { fetchIncidents } from '../../store/actions';
|
import { fetchIncidents } from '../../store/actions';
|
||||||
import { CONTAINER_WIDTH_PERCENTAGE } from '../../constants/constants';
|
|
||||||
|
|
||||||
class IncidentsReport extends Component {
|
class IncidentsReport extends Component {
|
||||||
state = {dateRange: null};
|
state = {dateRange: null};
|
||||||
@@ -34,11 +33,11 @@ class IncidentsReport extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container style={ {width: `${CONTAINER_WIDTH_PERCENTAGE}%`} }>
|
<Container>
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>Incidents Report</h3>
|
<h3>Incidents Report</h3>
|
||||||
<hr/>
|
<hr/>
|
||||||
<DateRangePicker buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate} inlineButton />
|
<MonthSelector buttonLabel="Show report" onDatesUpdate={this.onDatesUpdate} inlineButton />
|
||||||
<br/>
|
<br/>
|
||||||
<GenerateFeesInORDButton
|
<GenerateFeesInORDButton
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
@@ -47,7 +46,7 @@ class IncidentsReport extends Component {
|
|||||||
<br/><br/>
|
<br/><br/>
|
||||||
<hr/>
|
<hr/>
|
||||||
<br/>
|
<br/>
|
||||||
<MemberIncidentsTables pendingIncidents={loading} incidents={incidents} dateRange={dateRange} />
|
<MemberIncidentsTables pendingIncidents={loading} incidents={incidents} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { Container, Button, Loader, Input, Message, Grid } from 'semantic-ui-rea
|
|||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
|
|
||||||
import { fetchMemberPracticeSummaryReport } from '../../store/actions';
|
import { fetchMemberPracticeSummaryReport } from '../../store/actions';
|
||||||
import {CONTAINER_WIDTH_PERCENTAGE} from "../../constants/constants";
|
|
||||||
|
|
||||||
class MemberPracticeSummaryReport extends Component {
|
class MemberPracticeSummaryReport extends Component {
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ class MemberPracticeSummaryReport extends Component {
|
|||||||
error = fetchReportError ? fetchReportError : error;
|
error = fetchReportError ? fetchReportError : error;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container style={ {width: `${CONTAINER_WIDTH_PERCENTAGE}%`} }>
|
<Container>
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>Member Practice Summary Report</h3>
|
<h3>Member Practice Summary Report</h3>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|||||||
@@ -76,71 +76,67 @@ class SingleMapping extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
try {
|
const { singleMapping: { officeSlug, resourceSlug } } = this.props;
|
||||||
const {singleMapping: {officeSlug, resourceSlug}} = this.props;
|
const { officeId, resourceId, officeOptions, allResourceOptions, pendingMappings } = this.props;
|
||||||
const {officeId, resourceId, officeOptions, allResourceOptions, pendingMappings} = this.props;
|
const { showDeletePrompt, newOfficeId, newResourceId } = this.state;
|
||||||
const {showDeletePrompt, newOfficeId, newResourceId} = this.state;
|
|
||||||
|
|
||||||
const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
const selectedOfficeId = newOfficeId ? newOfficeId : officeId;
|
||||||
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
const selectedResourceId = newResourceId ? newResourceId : resourceId;
|
||||||
|
|
||||||
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
|
const resourceOptions = allResourceOptions && officeId ? allResourceOptions[selectedOfficeId].roomOptions : [];
|
||||||
|
|
||||||
const enableActions = !pendingMappings;
|
const enableActions = !pendingMappings;
|
||||||
const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null));
|
const enableSave = enableActions && ((newOfficeId !== null) || (newResourceId !== null));
|
||||||
const saveIconColor = enableSave ? 'green' : null;
|
const saveIconColor = enableSave ? 'green' : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<PromptMessage
|
<PromptMessage
|
||||||
onClose={this.onPromptClose}
|
onClose={this.onPromptClose}
|
||||||
onActionNo={this.onPromptClose}
|
onActionNo={this.onPromptClose}
|
||||||
onActionYes={this.onPromptYes}
|
onActionYes={this.onPromptYes}
|
||||||
title={'Delete mapping'}
|
title={'Delete mapping'}
|
||||||
message={'Do you want to delete this mapping ?'}
|
message={'Do you want to delete this mapping ?'}
|
||||||
show={showDeletePrompt}
|
show={showDeletePrompt}
|
||||||
|
/>
|
||||||
|
<Table.Cell>
|
||||||
|
<Label size={'big'}>{`[${officeSlug}-${resourceSlug}]`}</Label>
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell>
|
||||||
|
<Dropdown
|
||||||
|
options={officeOptions}
|
||||||
|
defaultValue={officeId}
|
||||||
|
onChange={this.onOfficeChange}
|
||||||
/>
|
/>
|
||||||
<Table.Cell>
|
</Table.Cell>
|
||||||
<Label size={'big'}>{`[${officeSlug}-${resourceSlug}]`}</Label>
|
<Table.Cell>
|
||||||
</Table.Cell>
|
<Dropdown
|
||||||
<Table.Cell>
|
options={resourceOptions}
|
||||||
<Dropdown
|
value={selectedResourceId}
|
||||||
options={officeOptions}
|
onChange={this.onResourceChange}
|
||||||
defaultValue={officeId}
|
/>
|
||||||
onChange={this.onOfficeChange}
|
</Table.Cell>
|
||||||
/>
|
<Table.Cell>
|
||||||
</Table.Cell>
|
<Icon
|
||||||
<Table.Cell>
|
circular
|
||||||
<Dropdown
|
name={'check'}
|
||||||
options={resourceOptions}
|
size={'large'}
|
||||||
value={selectedResourceId}
|
disabled={!enableSave}
|
||||||
onChange={this.onResourceChange}
|
link={enableSave || null}
|
||||||
/>
|
color={saveIconColor}
|
||||||
</Table.Cell>
|
onClick={this.onMappingUpdate}
|
||||||
<Table.Cell>
|
/>
|
||||||
<Icon
|
<Icon
|
||||||
circular
|
circular
|
||||||
name={'check'}
|
name={'trash'}
|
||||||
size={'large'}
|
size={'large'}
|
||||||
disabled={!enableSave}
|
disabled={!enableActions}
|
||||||
link={enableSave || null}
|
link={enableActions || null}
|
||||||
color={saveIconColor}
|
onClick={this.deleteMapping}
|
||||||
onClick={this.onMappingUpdate}
|
/>
|
||||||
/>
|
</Table.Cell>
|
||||||
<Icon
|
</Table.Row>
|
||||||
circular
|
);
|
||||||
name={'trash'}
|
|
||||||
size={'large'}
|
|
||||||
disabled={!enableActions}
|
|
||||||
link={enableActions || null}
|
|
||||||
onClick={this.deleteMapping}
|
|
||||||
/>
|
|
||||||
</Table.Cell>
|
|
||||||
</Table.Row>
|
|
||||||
);
|
|
||||||
}catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { Container, Message, Loader, Table } from 'semantic-ui-react';
|
|||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
import { fetchMappings } from '../../store/actions';
|
import { fetchMappings } from '../../store/actions';
|
||||||
import SingleMapping from './components/SingleMapping';
|
import SingleMapping from './components/SingleMapping';
|
||||||
import {CONTAINER_WIDTH_PERCENTAGE} from "../../constants/constants";
|
|
||||||
|
|
||||||
class RoomOfficeNameMapping extends Component {
|
class RoomOfficeNameMapping extends Component {
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ class RoomOfficeNameMapping extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container style={ {width: `${CONTAINER_WIDTH_PERCENTAGE}%`} }>
|
<Container>
|
||||||
<Loader active={pendingMappings} />
|
<Loader active={pendingMappings} />
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>Room Office Mapping</h3>
|
<h3>Room Office Mapping</h3>
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ import { connect } from 'react-redux';
|
|||||||
import { Container, Grid } from 'semantic-ui-react';
|
import { Container, Grid } from 'semantic-ui-react';
|
||||||
|
|
||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
import DateRangePicker from '../../components/DateRangePicker';
|
import MonthSelector from '../../components/MonthSelector';
|
||||||
import MemberSelector from './components/MemberSelector';
|
import MemberSelector from './components/MemberSelector';
|
||||||
import MemberSummary from './components/MemberSummary';
|
import MemberSummary from './components/MemberSummary';
|
||||||
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
|
import MemberIncidentsTables from '../../components/MemberIncidentsTables';
|
||||||
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
|
import GenerateFeesInORDButton from '../../components/GenerateFeesInORDButton';
|
||||||
|
|
||||||
import { fetchMemberIncidents } from '../../store/actions';
|
import { fetchMemberIncidents } from '../../store/actions';
|
||||||
import {CONTAINER_WIDTH_PERCENTAGE} from "../../constants/constants";
|
|
||||||
|
|
||||||
class SpecificMemberIncidentsReport extends Component {
|
class SpecificMemberIncidentsReport extends Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
@@ -49,7 +48,7 @@ class SpecificMemberIncidentsReport extends Component {
|
|||||||
const addFeesButtonDisabled = !memberId || !dateRange || loading;
|
const addFeesButtonDisabled = !memberId || !dateRange || loading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container style={ {width: `${CONTAINER_WIDTH_PERCENTAGE}%`} }>
|
<Container>
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>Member Incidents Report</h3>
|
<h3>Member Incidents Report</h3>
|
||||||
<hr/>
|
<hr/>
|
||||||
@@ -59,7 +58,7 @@ class SpecificMemberIncidentsReport extends Component {
|
|||||||
<MemberSelector onMemberSelect={this.onMemberSelectionUpdate.bind(this)} defaultMemberId={memberId} />
|
<MemberSelector onMemberSelect={this.onMemberSelectionUpdate.bind(this)} defaultMemberId={memberId} />
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
<DateRangePicker inlineButton onDatesUpdate={this.onDateRangeUpdate.bind(this)}/>
|
<MonthSelector inlineButton onDatesUpdate={this.onDateRangeUpdate.bind(this)}/>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
<Grid.Row>
|
<Grid.Row>
|
||||||
@@ -83,13 +82,7 @@ class SpecificMemberIncidentsReport extends Component {
|
|||||||
<Grid.Row/>
|
<Grid.Row/>
|
||||||
<Grid.Row>
|
<Grid.Row>
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
<MemberIncidentsTables
|
<MemberIncidentsTables incidents={memberIncidents} pendingIncidents={loading} hideMemberName/>
|
||||||
incidents={memberIncidents}
|
|
||||||
pendingIncidents={loading}
|
|
||||||
hideMemberName
|
|
||||||
dateRange={dateRange}
|
|
||||||
memberId={memberId}
|
|
||||||
/>
|
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import { Container, Form } from 'semantic-ui-react';
|
|||||||
import MainMenu from '../../components/MainMenu';
|
import MainMenu from '../../components/MainMenu';
|
||||||
import FileUpload from './components/FileUpload';
|
import FileUpload from './components/FileUpload';
|
||||||
import UploadResults from './components/UploadResults';
|
import UploadResults from './components/UploadResults';
|
||||||
import {CONTAINER_WIDTH_PERCENTAGE} from "../../constants/constants";
|
|
||||||
|
|
||||||
function UploadDLockData() {
|
function UploadDLockData() {
|
||||||
return (
|
return (
|
||||||
<Container style={ {width: `${CONTAINER_WIDTH_PERCENTAGE}%`} }>
|
<Container>
|
||||||
<MainMenu/>
|
<MainMenu/>
|
||||||
<h3>DLock Data</h3>
|
<h3>DLock Data</h3>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|||||||
@@ -88,36 +88,6 @@ export const fetchIncidents = (dispatch, dateRange) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteIncidents = (dispatch, deleteData) => {
|
|
||||||
const pendingAction = deleteData.memberId ? FETCH_MEMBER_INCIDENTS_PENDING : FETCH_INCIDENTS_PENDING;
|
|
||||||
const successAction = deleteData.memberId ? FETCH_MEMBER_INCIDENTS_SUCCESS : FETCH_INCIDENTS_SUCCESS;
|
|
||||||
const failedAction = deleteData.memberId ? FETCH_MEMBER_INCIDENTS_FAILED : FETCH_INCIDENTS_FAILED;
|
|
||||||
|
|
||||||
dispatch({type: pendingAction});
|
|
||||||
API.delete(`/integration/fees`, { data: deleteData })
|
|
||||||
.then(response => {
|
|
||||||
dispatch({type: successAction, payload: response.data});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
dispatch({type: failedAction, payload: error.response});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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')
|
||||||
|
|||||||
@@ -14,37 +14,37 @@ const unlockedIncidentLevelsPrices = {
|
|||||||
id: 0,
|
id: 0,
|
||||||
title: 'UNLOCKED_0',
|
title: 'UNLOCKED_0',
|
||||||
price: parseInt(process.env.UNLOCK_0) || 0,
|
price: parseInt(process.env.UNLOCK_0) || 0,
|
||||||
description: 'first month - warning',
|
description: 'First month - warning',
|
||||||
},
|
},
|
||||||
UNLOCKED_1: {
|
UNLOCKED_1: {
|
||||||
id: 1,
|
id: 1,
|
||||||
title: 'UNLOCKED_1',
|
title: 'UNLOCKED_1',
|
||||||
price: parseInt(process.env.UNLOCK_1) || 10,
|
price: parseInt(process.env.UNLOCK_1) || 10,
|
||||||
description: 'second month',
|
description: 'Second month',
|
||||||
},
|
},
|
||||||
UNLOCKED_2: {
|
UNLOCKED_2: {
|
||||||
id: 2,
|
id: 2,
|
||||||
title: 'UNLOCKED_2',
|
title: 'UNLOCKED_2',
|
||||||
price: parseInt(process.env.UNLOCK_2) || 20,
|
price: parseInt(process.env.UNLOCK_2) || 20,
|
||||||
description: 'third month',
|
description: 'Third month',
|
||||||
},
|
},
|
||||||
UNLOCKED_3: {
|
UNLOCKED_3: {
|
||||||
id: 3,
|
id: 3,
|
||||||
title: 'UNLOCKED_3',
|
title: 'UNLOCKED_3',
|
||||||
price: parseInt(process.env.UNLOCK_3) || 30,
|
price: parseInt(process.env.UNLOCK_3) || 30,
|
||||||
description: 'fourth month',
|
description: 'Fourth month',
|
||||||
},
|
},
|
||||||
UNLOCKED_4: {
|
UNLOCKED_4: {
|
||||||
id: 4,
|
id: 4,
|
||||||
title: 'UNLOCKED_4',
|
title: 'UNLOCKED_4',
|
||||||
price: parseInt(process.env.UNLOCK_4) || 40,
|
price: parseInt(process.env.UNLOCK_4) || 40,
|
||||||
description: 'fifth month',
|
description: 'Fifth month',
|
||||||
},
|
},
|
||||||
UNLOCKED_5: {
|
UNLOCKED_5: {
|
||||||
id: 5,
|
id: 5,
|
||||||
title: 'UNLOCKED_5',
|
title: 'UNLOCKED_5',
|
||||||
price: parseInt(process.env.UNLOCK_5) || 50,
|
price: parseInt(process.env.UNLOCK_5) || 50,
|
||||||
description: 'sixth month and onward',
|
description: 'Sixth month and onward',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const csvParserErrors = {
|
const csvParserErrors = {
|
||||||
@@ -57,8 +57,6 @@ const csvParserErrors = {
|
|||||||
const officeRnDAPIErrors = {
|
const officeRnDAPIErrors = {
|
||||||
FAILED_TO_FETCH_MEMBERS: 'Failed to fetch members',
|
FAILED_TO_FETCH_MEMBERS: 'Failed to fetch members',
|
||||||
FAILED_TO_FETCH_BOOKINGS: 'Failed to fetch booking reservations',
|
FAILED_TO_FETCH_BOOKINGS: 'Failed to fetch booking reservations',
|
||||||
FAILED_TO_CREATE_BOOKINGS: 'Failed to create booking reservations',
|
|
||||||
FAILED_TO_DELETE_BOOKINGS: 'Failed to delete booking reservations',
|
|
||||||
FAILED_TO_FETCH_FEES: 'Failed to fetch existing fees from ORD',
|
FAILED_TO_FETCH_FEES: 'Failed to fetch existing fees from ORD',
|
||||||
FAILED_TO_FETCH_PLANS: 'Failed to fetch plans from ORD',
|
FAILED_TO_FETCH_PLANS: 'Failed to fetch plans from ORD',
|
||||||
FAILED_TO_DELETE_FEES: 'Failed to delete fees in ORD',
|
FAILED_TO_DELETE_FEES: 'Failed to delete fees in ORD',
|
||||||
@@ -97,21 +95,20 @@ const incidentType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const incidentTypeExplanations = {};
|
const incidentTypeExplanations = {};
|
||||||
incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION] = 'door left unlocked';
|
incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION] = 'Door left unlocked';
|
||||||
incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_STANDALONE] = 'door left unlocked';
|
incidentTypeExplanations[incidentType.UNLOCKED_INCIDENT_STANDALONE] = 'Door left unlocked';
|
||||||
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION] = 'room used before reservation';
|
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION] = 'Room used before reservation';
|
||||||
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION] = 'room used after reservation';
|
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION] = 'Room used after reservation';
|
||||||
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_STANDALONE] = 'room used without reservation';
|
incidentTypeExplanations[incidentType.UNSCHEDULED_INCIDENT_STANDALONE] = 'Room used without reservation';
|
||||||
incidentTypeExplanations[incidentType.BOOKING_MOVED_TO_ANOTHER_DAY] = 'reservation moved to another day in less than 24 hrs';
|
incidentTypeExplanations[incidentType.BOOKING_MOVED_TO_ANOTHER_DAY] = 'Reservation moved to another day';
|
||||||
incidentTypeExplanations[incidentType.BOOKING_SHORTENED] = 'reservation shortened after grace period';
|
incidentTypeExplanations[incidentType.BOOKING_SHORTENED] = 'Reservation shortened after grace period';
|
||||||
incidentTypeExplanations[incidentType.BOOKING_CANCELED_LATE] = 'reservation cancelled after grace period';
|
incidentTypeExplanations[incidentType.BOOKING_CANCELED_LATE] = 'Reservation cancelled after grace period';
|
||||||
|
|
||||||
const UI_TIMEZONE = process.env.UI_TIMEZONE || 'America/Los_Angeles';
|
const UI_TIMEZONE = process.env.UI_TIMEZONE || 'America/Los_Angeles';
|
||||||
|
|
||||||
const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD';
|
const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD';
|
||||||
|
|
||||||
const MAX_BACK_TO_BACK_DIFFERENCE = parseInt(process.env.MAX_BACK_TO_BACK_DIFFERENCE) || 0;
|
const MAX_BACK_TO_BACK_DIFFERENCE = parseInt(process.env.MAX_BACK_TO_BACK_DIFFERENCE) || 0;
|
||||||
const UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH = parseInt(process.env.UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH) || 7;
|
|
||||||
const UNSCHEDULED_TIME_RESOLUTION = parseInt(process.env.UNSCHEDULED_USE_TIME_RESOLUTION) || 5;
|
const UNSCHEDULED_TIME_RESOLUTION = parseInt(process.env.UNSCHEDULED_USE_TIME_RESOLUTION) || 5;
|
||||||
const UNSCHEDULED_CHARGE_PRICE = parseFloat(process.env.UNSCHEDULED_USE_CHARGE_PRICE) || 5;
|
const UNSCHEDULED_CHARGE_PRICE = parseFloat(process.env.UNSCHEDULED_USE_CHARGE_PRICE) || 5;
|
||||||
|
|
||||||
@@ -138,9 +135,10 @@ const CUSTOM_FEES_PREFIXES = process.env.CUSTOM_FEES_PREFIXES.split(',')
|
|||||||
|
|
||||||
const UNPAID_FEE_STATUS = 'not_paid';
|
const UNPAID_FEE_STATUS = 'not_paid';
|
||||||
|
|
||||||
const ALLOW_SENDING_FEES = parseInt(process.env.ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS) ? true : false;
|
const ALLOW_SENDING_FEES = !!parseInt(process.env.ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS);
|
||||||
|
|
||||||
const TRIM_DLOCK_NAMES_LENGTH = parseInt(process.env.TRIM_DLOCK_NAMES_LENGTH) || 22;
|
const MAX_FEES_TO_DELETE = parseInt(process.env.MAX_FEES_TO_DELETE) || 10;
|
||||||
|
const FEES_DELETE_DELAY = parseInt(process.env.FEES_DELETE_DELAY) || 0;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
VALID_CSV_HEADERS,
|
VALID_CSV_HEADERS,
|
||||||
@@ -157,7 +155,6 @@ module.exports = {
|
|||||||
UI_TIMEZONE,
|
UI_TIMEZONE,
|
||||||
DEFAULT_DATE_FORMAT,
|
DEFAULT_DATE_FORMAT,
|
||||||
MAX_BACK_TO_BACK_DIFFERENCE,
|
MAX_BACK_TO_BACK_DIFFERENCE,
|
||||||
UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH,
|
|
||||||
UNSCHEDULED_TIME_RESOLUTION,
|
UNSCHEDULED_TIME_RESOLUTION,
|
||||||
UNSCHEDULED_CHARGE_PRICE,
|
UNSCHEDULED_CHARGE_PRICE,
|
||||||
BOOKING_CHANGE_PERCENTAGE_CHARGE,
|
BOOKING_CHANGE_PERCENTAGE_CHARGE,
|
||||||
@@ -168,5 +165,6 @@ module.exports = {
|
|||||||
UNPAID_FEE_STATUS,
|
UNPAID_FEE_STATUS,
|
||||||
CUSTOM_FEES_PREFIXES,
|
CUSTOM_FEES_PREFIXES,
|
||||||
ALLOW_SENDING_FEES,
|
ALLOW_SENDING_FEES,
|
||||||
TRIM_DLOCK_NAMES_LENGTH
|
MAX_FEES_TO_DELETE,
|
||||||
|
FEES_DELETE_DELAY
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,25 +2,13 @@
|
|||||||
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
|
|
||||||
const {
|
const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase, deleteMappingById, updateMappingById } = require('../services/officeRnD/resources');
|
||||||
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,
|
|
||||||
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');
|
||||||
|
|
||||||
@@ -187,92 +175,6 @@ const addFees = (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteFees = (req, res) => {
|
|
||||||
const deleteData = req.body;
|
|
||||||
const dateRange = deleteData.dateRange ? deleteData.dateRange : null;
|
|
||||||
const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null;
|
|
||||||
const memberId = deleteData.memberId ? deleteData.memberId : null;
|
|
||||||
|
|
||||||
const unlockedIncidentIds = incidents.unlockedIncidentIds ? incidents.unlockedIncidentIds : [];
|
|
||||||
const unscheduledIncidentIds = incidents.unscheduledIncidentIds ? incidents.unscheduledIncidentIds : [];
|
|
||||||
const bookingChangeIncidentIds = incidents.bookingChangeIncidentIds ? incidents.bookingChangeIncidentIds : [];
|
|
||||||
|
|
||||||
req.params.startDate = dateRange.startDate ? dateRange.startDate : null;
|
|
||||||
req.params.endDate = dateRange.endDate ? dateRange.endDate : null;
|
|
||||||
|
|
||||||
if (Array.isArray(unlockedIncidentIds) && Array.isArray(unscheduledIncidentIds) && Array.isArray(bookingChangeIncidentIds)){
|
|
||||||
const asyncDeleteActions = [
|
|
||||||
deleteUnlockedIncidentsById(unlockedIncidentIds),
|
|
||||||
deleteUnscheduledIncidentsById(unscheduledIncidentIds),
|
|
||||||
deleteBookingChangeIncidentsById(bookingChangeIncidentIds)
|
|
||||||
];
|
|
||||||
|
|
||||||
Promise.all(asyncDeleteActions)
|
|
||||||
.then(() => {
|
|
||||||
if (memberId){
|
|
||||||
req.params.memberId = memberId;
|
|
||||||
getMemberIncidents(req, res);
|
|
||||||
}else{
|
|
||||||
getAllIncidentsController(req, res);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log('Error deleting incidents : ', error);
|
|
||||||
res.status(500).send();
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
if (memberId){
|
|
||||||
req.params.memberId = memberId;
|
|
||||||
getMemberIncidents(req, res);
|
|
||||||
}else{
|
|
||||||
getAllIncidentsController(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) => {
|
||||||
@@ -325,6 +227,4 @@ module.exports = {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
deleteFees,
|
|
||||||
updateFees
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ EARLIEST_UNLOCK=Time in minutes
|
|||||||
|
|
||||||
UI_TIMEZONE=Timezone for user interface | https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | example : America/Los_Angeles
|
UI_TIMEZONE=Timezone for user interface | https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | example : America/Los_Angeles
|
||||||
|
|
||||||
UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH=Time in minutes when first unscheduled use charge will be applied
|
|
||||||
UNSCHEDULED_USE_TIME_RESOLUTION=Time in minutes
|
UNSCHEDULED_USE_TIME_RESOLUTION=Time in minutes
|
||||||
UNSCHEDULED_USE_CHARGE_PRICE=Charge price
|
UNSCHEDULED_USE_CHARGE_PRICE=Charge price
|
||||||
|
|
||||||
@@ -42,7 +41,8 @@ CUSTOM_FEES_PREFIXES=Array of prefixes to recognize manually added fees. Comma-s
|
|||||||
|
|
||||||
ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS=0 - false => Sending fees is disabled for current and future months, 1 - true => Sending fees is never disabled
|
ALLOW_SENDING_FEES_FOR_CURRENT_AND_FUTURE_MONTHS=0 - false => Sending fees is disabled for current and future months, 1 - true => Sending fees is never disabled
|
||||||
|
|
||||||
TRIM_DLOCK_NAMES_LENGTH=Length of names in DLOCK files that will be taken to compare with ORD member names
|
MAX_FEES_TO_DELETE=Max number of fees to delete (from ORD) in one API call
|
||||||
|
FEES_DELETE_DELAY=Number of miliseconds to wait between two API calls to delete fees (from ORD)
|
||||||
|
|
||||||
#More about pool option : http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html
|
#More about pool option : http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html
|
||||||
DB_POOL_MAX_CONNECTIONS=Maximum number of connection in pool (ex. 18)
|
DB_POOL_MAX_CONNECTIONS=Maximum number of connection in pool (ex. 18)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.addColumn('unlockedIncidents', 'deleted', {
|
|
||||||
type: Sequelize.BOOLEAN,
|
|
||||||
defaultValue: false,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.removeColumn('unlockedIncidents', 'deleted');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.addColumn('unscheduledIncidents', 'deleted', {
|
|
||||||
type: Sequelize.BOOLEAN,
|
|
||||||
defaultValue: false,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.removeColumn('unscheduledIncidents', 'deleted');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -22,7 +22,6 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
incidentLevelPrice: DataTypes.FLOAT,
|
incidentLevelPrice: DataTypes.FLOAT,
|
||||||
unlockTimestamp: DataTypes.DATE,
|
unlockTimestamp: DataTypes.DATE,
|
||||||
deleted: DataTypes.BOOLEAN
|
|
||||||
}, {});
|
}, {});
|
||||||
unlockedIncident.associate = function(models) {
|
unlockedIncident.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
totalChargeFee: DataTypes.FLOAT,
|
totalChargeFee: DataTypes.FLOAT,
|
||||||
unlockTimestamp: DataTypes.DATE,
|
unlockTimestamp: DataTypes.DATE,
|
||||||
lockTimestamp: DataTypes.DATE,
|
lockTimestamp: DataTypes.DATE,
|
||||||
deleted: DataTypes.BOOLEAN
|
|
||||||
}, {});
|
}, {});
|
||||||
unscheduledIncident.associate = function(models) {
|
unscheduledIncident.associate = function(models) {
|
||||||
// associations can be defined here
|
// associations can be defined here
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ const {
|
|||||||
addFees,
|
addFees,
|
||||||
checkProcessingStatus,
|
checkProcessingStatus,
|
||||||
getPracticeSummaryReport,
|
getPracticeSummaryReport,
|
||||||
deleteFees,
|
|
||||||
updateFees
|
|
||||||
} = require('../controllers/integration');
|
} = require('../controllers/integration');
|
||||||
|
|
||||||
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges');
|
||||||
@@ -36,8 +34,6 @@ router.get('/integration/report/allIncidents/:startDate/:endDate', getAllInciden
|
|||||||
router.get('/officeRnD/membersList', fetchMembersList);
|
router.get('/officeRnD/membersList', fetchMembersList);
|
||||||
|
|
||||||
router.post('/integration/addFees', addFees);
|
router.post('/integration/addFees', addFees);
|
||||||
router.delete('/integration/fees', deleteFees);
|
|
||||||
router.patch('/integration/fees', updateFees);
|
|
||||||
|
|
||||||
router.get('/integration/processing', checkProcessingStatus);
|
router.get('/integration/processing', checkProcessingStatus);
|
||||||
|
|
||||||
@@ -46,14 +42,6 @@ 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) => {
|
router.get('/calculate', (req, res) => { calculateDoorLockCharges(); res.send();});
|
||||||
calculateDoorLockCharges()
|
|
||||||
.then(() => {
|
|
||||||
res.send('Done');
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
res.send(`Error \r\n ${err}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ const {
|
|||||||
VALID_CSV_HEADERS,
|
VALID_CSV_HEADERS,
|
||||||
doorLockEvents,
|
doorLockEvents,
|
||||||
csvParserErrors,
|
csvParserErrors,
|
||||||
TRIM_DLOCK_NAMES_LENGTH
|
|
||||||
} = require('../../constants/constants');
|
} = require('../../constants/constants');
|
||||||
|
|
||||||
const { fetchAllMembers } = require('../officeRnD/members');
|
const { fetchAllMembers } = require('../officeRnD/members');
|
||||||
const { getMappingsFromDatabase } = require('../officeRnD/resources');
|
const { getMappingsFromDatabase } = require('../officeRnD/resources');
|
||||||
const { getFirstReservationInBlock, getFirstPreviousBooking } = require('../officeRnD/bookings');
|
const { getFirstReservationInBlock } = require('../officeRnD/bookings');
|
||||||
|
|
||||||
const extractMappingFromFileName = (fileName) => {
|
const extractMappingFromFileName = (fileName) => {
|
||||||
const contentBetweenBracketsRegex = /\[(.*?)\]/;
|
const contentBetweenBracketsRegex = /\[(.*?)\]/;
|
||||||
@@ -54,12 +53,7 @@ const parseDoorLockDataFile = (file) => {
|
|||||||
const membersMap = {};
|
const membersMap = {};
|
||||||
const unknownMembersMap = {};
|
const unknownMembersMap = {};
|
||||||
|
|
||||||
allMembers.forEach((member) => {
|
allMembers.forEach((member) => membersMap[member.name] = member);
|
||||||
const limitedMemberName = member.name ? member.name.substring(0, TRIM_DLOCK_NAMES_LENGTH) || undefined : undefined;
|
|
||||||
if (limitedMemberName){
|
|
||||||
membersMap[limitedMemberName] = member;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const mappingFromFileName = extractMappingFromFileName(file.name);
|
const mappingFromFileName = extractMappingFromFileName(file.name);
|
||||||
const mappingObject = checkIfMappingExsists(mappingFromFileName, mappings);
|
const mappingObject = checkIfMappingExsists(mappingFromFileName, mappings);
|
||||||
@@ -116,20 +110,18 @@ const parseDoorLockDataFile = (file) => {
|
|||||||
const firstEntry = results[i];
|
const firstEntry = results[i];
|
||||||
const secondEntry = results[i+1];
|
const secondEntry = results[i+1];
|
||||||
|
|
||||||
const trimmedName = firstEntry && firstEntry.name ? firstEntry.name.substring(0, TRIM_DLOCK_NAMES_LENGTH) || undefined : undefined;
|
if (firstEntry && (firstEntry.event === USER_ENTRY_EVENT)){
|
||||||
|
const memberObject = membersMap[firstEntry.name];
|
||||||
if (firstEntry && trimmedName && (firstEntry.event === USER_ENTRY_EVENT)){
|
|
||||||
const memberObject = membersMap[trimmedName];
|
|
||||||
|
|
||||||
if (!memberObject){
|
if (!memberObject){
|
||||||
//Check if member is already labeled as unknown
|
//Check if member is already labeled as unknown
|
||||||
const unknownMember = unknownMembersMap[trimmedName];
|
const unknownMember = unknownMembersMap[firstEntry.name];
|
||||||
|
|
||||||
if (!unknownMember){
|
if (!unknownMember){
|
||||||
unknownMembersMap[trimmedName] = trimmedName;
|
unknownMembersMap[firstEntry.name] = firstEntry.name;
|
||||||
unknownMembersToReport.push({
|
unknownMembersToReport.push({
|
||||||
error: csvParserErrors.UNKNOWN_MEMBER,
|
error: csvParserErrors.UNKNOWN_MEMBER,
|
||||||
details: trimmedName,
|
details: firstEntry.name,
|
||||||
file: file.name,
|
file: file.name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -145,7 +137,7 @@ const parseDoorLockDataFile = (file) => {
|
|||||||
//Verify that member is registered in OfficeRnD system
|
//Verify that member is registered in OfficeRnD system
|
||||||
if (memberObject){
|
if (memberObject){
|
||||||
const entryData = {
|
const entryData = {
|
||||||
memberName: trimmedName,
|
memberName: firstEntry.name,
|
||||||
memberNumber: firstEntry['user no'],
|
memberNumber: firstEntry['user no'],
|
||||||
memberId: memberObject.memberId,
|
memberId: memberObject.memberId,
|
||||||
timestamp,
|
timestamp,
|
||||||
@@ -205,14 +197,6 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
|
|||||||
|
|
||||||
const toTimestamp = reservation.end;
|
const toTimestamp = reservation.end;
|
||||||
|
|
||||||
// if (reservation.memberId === '5ce785af422bdd00967fb781') {
|
|
||||||
// console.log('=======================');
|
|
||||||
// console.log('\tStart : ', moment.tz(reservation.start, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\tEnd : ', moment.tz(reservation.end, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// console.log('\tFrom time : ', fromTimestamp);
|
|
||||||
// console.log('\tTo time : ', toTimestamp);
|
|
||||||
// }
|
|
||||||
|
|
||||||
const filters = {
|
const filters = {
|
||||||
memberId,
|
memberId,
|
||||||
@@ -238,25 +222,7 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
|
|||||||
|
|
||||||
const entriesBeforeReservationStart = entries.filter((entry) => moment.utc(entry.timestamp).isBefore(reservation.start));
|
const entriesBeforeReservationStart = entries.filter((entry) => moment.utc(entry.timestamp).isBefore(reservation.start));
|
||||||
|
|
||||||
// if (memberId === '5ce785af422bdd00967fb781') {
|
|
||||||
// console.log('Start : ', moment.tz(reservation.start, UI_TIMEZONE).format('DD.MM HH:mm'));
|
|
||||||
// console.log('End : ', moment.tz(reservation.end, UI_TIMEZONE).format('DD.MM HH:mm'));
|
|
||||||
// console.log('\tPrevious reservation ');
|
|
||||||
// console.log('\tStart : ', previousReservation ? moment.tz(previousReservation.start, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
|
|
||||||
// console.log('\tEnd : ', previousReservation ? moment.tz(previousReservation.end, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
|
|
||||||
// console.log('\t---------------------------');
|
|
||||||
// console.log('\tSearch for entries : ');
|
|
||||||
// console.log('\tFrom : ', fromTimestamp ? moment.tz(fromTimestamp, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
|
|
||||||
// console.log('\tTo : ', toTimestamp ? moment.tz(toTimestamp, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
|
|
||||||
// console.log('\t---------------------------');
|
|
||||||
// console.log('\tEntries before reservation start : ');
|
|
||||||
// }
|
|
||||||
|
|
||||||
entriesBeforeReservationStart.forEach((entry) => {
|
entriesBeforeReservationStart.forEach((entry) => {
|
||||||
// if (memberId === '5ce785af422bdd00967fb781') {
|
|
||||||
// console.log('\t', entry.event, '\t', moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM HH:mm'));
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (!eventFound) {
|
if (!eventFound) {
|
||||||
if (entry.event === doorLockEvents.USER_UNLOCKED) {
|
if (entry.event === doorLockEvents.USER_UNLOCKED) {
|
||||||
if (pairedLockEntry) {
|
if (pairedLockEntry) {
|
||||||
@@ -274,25 +240,13 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (eventFound){
|
if (eventFound){
|
||||||
// if (memberId === '5ce785af422bdd00967fb781') {
|
|
||||||
// console.log('\t=> FOUND UNLOCK ENTRY - NO NEED TO LOOK AFTER <=');
|
|
||||||
// }
|
|
||||||
resolve(candidateUnlockEntry);
|
resolve(candidateUnlockEntry);
|
||||||
} else {
|
} else {
|
||||||
candidateUnlockEntry = null;
|
candidateUnlockEntry = null;
|
||||||
const numberOfEntriesLeft = entries.length - entriesBeforeReservationStart.length;
|
const numberOfEntriesLeft = entries.length - entriesBeforeReservationStart.length;
|
||||||
const entriesAfterReservationStart = entries.slice(0, numberOfEntriesLeft);
|
const entriesAfterReservationStart = entries.slice(0, numberOfEntriesLeft);
|
||||||
const invertedEntriesAfterReservationStart = entriesAfterReservationStart.reverse();
|
|
||||||
|
|
||||||
// if (memberId === '5ce785af422bdd00967fb781') {
|
|
||||||
// console.log('\t-----------------------------');
|
|
||||||
// console.log('\tEntries after reservation start : ');
|
|
||||||
// }
|
|
||||||
invertedEntriesAfterReservationStart.forEach((entry) => {
|
|
||||||
// if (memberId === '5ce785af422bdd00967fb781') {
|
|
||||||
// console.log('\t', entry.event, '\t', moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM HH:mm'));
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
entriesAfterReservationStart.forEach((entry) => {
|
||||||
if (!eventFound) {
|
if (!eventFound) {
|
||||||
if (entry.event === doorLockEvents.USER_UNLOCKED) {
|
if (entry.event === doorLockEvents.USER_UNLOCKED) {
|
||||||
eventFound = true;
|
eventFound = true;
|
||||||
@@ -333,7 +287,7 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
|
|||||||
resourceId,
|
resourceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const order = [['timestamp', 'DESC']];
|
const order = [['timestamp', 'ASC']];
|
||||||
|
|
||||||
db.doorLockEvent.findAll({
|
db.doorLockEvent.findAll({
|
||||||
attributes,
|
attributes,
|
||||||
@@ -341,31 +295,47 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
|
|||||||
order,
|
order,
|
||||||
})
|
})
|
||||||
.then((entries) => {
|
.then((entries) => {
|
||||||
|
let candidateLockEntry = null;
|
||||||
|
let pairedUnlockEntry = null;
|
||||||
|
let eventFound = false;
|
||||||
|
|
||||||
const entriesBeforeReservationEnd = entries.filter(entry => moment.utc(entry.timestamp).isBefore(reservation.end));
|
const entriesAfterReservationEnd = entries.filter((entry) => moment.utc(entry.timestamp).isAfter(reservation.end));
|
||||||
|
|
||||||
if (entriesBeforeReservationEnd.length > 0){
|
entriesAfterReservationEnd.forEach((entry) => {
|
||||||
const lastEntryInReservationTime = entriesBeforeReservationEnd[0];
|
if (!eventFound) {
|
||||||
if (lastEntryInReservationTime.event === doorLockEvents.USER_LOCKED){
|
if (entry.event === doorLockEvents.USER_LOCKED) {
|
||||||
resolve(lastEntryInReservationTime);
|
if (pairedUnlockEntry) {
|
||||||
return;
|
pairedUnlockEntry = null;
|
||||||
|
candidateLockEntry = null;
|
||||||
|
} else {
|
||||||
|
candidateLockEntry = entry;
|
||||||
|
eventFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entry.event === doorLockEvents.USER_UNLOCKED){
|
||||||
|
pairedUnlockEntry = entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (eventFound){
|
||||||
|
resolve(candidateLockEntry);
|
||||||
|
} else {
|
||||||
|
candidateLockEntry = null;
|
||||||
|
const numberOfEntriesLeft = entries.length - entriesAfterReservationEnd.length;
|
||||||
|
const entriesBeforeReservationEnd = entries.slice(0, numberOfEntriesLeft);
|
||||||
|
|
||||||
|
entriesBeforeReservationEnd.reverse().forEach((entry) => {
|
||||||
|
if (!eventFound) {
|
||||||
|
if (entry.event === doorLockEvents.USER_LOCKED) {
|
||||||
|
eventFound = true;
|
||||||
|
candidateLockEntry = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
resolve(candidateLockEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Phase 2
|
|
||||||
const numberOfEntriesLeft = entries.length - entriesBeforeReservationEnd.length;
|
|
||||||
const entriesAfterReservationEnd = entries.slice(0, numberOfEntriesLeft).reverse();
|
|
||||||
if (entriesAfterReservationEnd.length > 0){
|
|
||||||
const firstEntryAfterReservation = entriesAfterReservationEnd[0];
|
|
||||||
if (firstEntryAfterReservation.event === doorLockEvents.USER_LOCKED){
|
|
||||||
resolve(firstEntryAfterReservation);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(null);
|
|
||||||
})
|
})
|
||||||
.catch((error) => reject(error));
|
.catch((error) => reject(error));
|
||||||
});
|
});
|
||||||
@@ -373,7 +343,7 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
|
|||||||
|
|
||||||
const getEntriesBetween = (fromTimestamp, toTimestamp, resourceId) => {
|
const getEntriesBetween = (fromTimestamp, toTimestamp, resourceId) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!resourceId){
|
if (!fromTimestamp || !toTimestamp || !resourceId){
|
||||||
resolve([]);
|
resolve([]);
|
||||||
}else {
|
}else {
|
||||||
const andTimestampFilters = [];
|
const andTimestampFilters = [];
|
||||||
@@ -425,25 +395,11 @@ const getLastEntryForReservation = (reservation) => {
|
|||||||
const order = [['timestamp', 'DESC']];
|
const order = [['timestamp', 'DESC']];
|
||||||
|
|
||||||
db.doorLockEvent.findAll({where: filters, order})
|
db.doorLockEvent.findAll({where: filters, order})
|
||||||
.then(async(entries) => {
|
.then((entries) => {
|
||||||
if (entries && entries.length > 0){
|
if (entries && entries.length > 0){
|
||||||
resolve(entries[0]);
|
resolve(entries[0]);
|
||||||
} else {
|
} else {
|
||||||
//No entry found in this block of reservations, now check if there is unlock entry for the first reservation in block, before reservation start time
|
resolve (undefined);
|
||||||
|
|
||||||
try {
|
|
||||||
const firstPreviousBookingBeforeFirstInBlock = await getFirstPreviousBooking(firstReservationInBlock);
|
|
||||||
const unlockEntryForFirstInBlock = await getUnlockEntryForReservation(firstReservationInBlock, firstPreviousBookingBeforeFirstInBlock);
|
|
||||||
|
|
||||||
if (unlockEntryForFirstInBlock){
|
|
||||||
resolve(unlockEntryForFirstInBlock);
|
|
||||||
}else{
|
|
||||||
resolve(undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => reject(error));
|
.catch((error) => reject(error));
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ const getIncidentsFromChanges = (changes) => {
|
|||||||
reservationsForAdditionalCheck.push(reservationId);
|
reservationsForAdditionalCheck.push(reservationId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// console.log('\t\tNo');
|
console.log('\t\tNo');
|
||||||
// Reservation moved to another day
|
// Reservation moved to another day
|
||||||
// Add cancellation charge
|
// Add cancellation charge
|
||||||
const chargeFee = oldReservationLength * reservationHourlyRate * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
const chargeFee = oldReservationLength * reservationHourlyRate * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
|
||||||
@@ -274,31 +274,6 @@ const deleteBookingChangeIncidents = (incidents) => {
|
|||||||
return Promise.all(asyncActions);
|
return Promise.all(asyncActions);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteBookingChangeIncidentsById = (incidentIds) => {
|
|
||||||
const filters = {
|
|
||||||
id: {
|
|
||||||
[Op.in]: incidentIds
|
|
||||||
}
|
|
||||||
};
|
|
||||||
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,
|
||||||
@@ -306,6 +281,4 @@ module.exports = {
|
|||||||
getShorteningIncidentsForReservationId,
|
getShorteningIncidentsForReservationId,
|
||||||
getReservationsIncidentsForRemoval,
|
getReservationsIncidentsForRemoval,
|
||||||
deleteBookingChangeIncidents,
|
deleteBookingChangeIncidents,
|
||||||
deleteBookingChangeIncidentsById,
|
|
||||||
updateBookingChangeIncidentsById
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,24 +88,7 @@ const getAllBookingsForMembersInDateRange = (dateRange, memberIds) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteBookingsRemovedFromORD = (reservationIds) => {
|
|
||||||
if (!Array.isArray(reservationIds)){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filter = {
|
|
||||||
reservationId: {
|
|
||||||
[Op.notIn]: reservationIds
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return db.bookingReservation.destroy({
|
|
||||||
where: filter
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getActiveBookingsForMembersInDateRange,
|
getActiveBookingsForMembersInDateRange,
|
||||||
getAllBookingsForMembersInDateRange,
|
getAllBookingsForMembersInDateRange,
|
||||||
deleteBookingsRemovedFromORD
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
||||||
const { fetchResources } = require('../officeRnD/resources');
|
const { fetchResources } = require('../officeRnD/resources');
|
||||||
const { fetchRates } = require('../officeRnD/rates');
|
const { fetchRates } = require('../officeRnD/rates');
|
||||||
const { deleteBookingsRemovedFromORD } = require('./bookings');
|
|
||||||
const { officeRnDAPIErrors } = require('../../constants/constants');
|
const { officeRnDAPIErrors } = require('../../constants/constants');
|
||||||
const {
|
const {
|
||||||
getIncidentsFromChanges,
|
getIncidentsFromChanges,
|
||||||
@@ -24,38 +23,23 @@ const checkBookingChanges = () => {
|
|||||||
|
|
||||||
const ratesMap = {};
|
const ratesMap = {};
|
||||||
rates.forEach(rate => {
|
rates.forEach(rate => {
|
||||||
const { rateId, price, weekendPrice } = rate;
|
const { rateId, price } = rate;
|
||||||
ratesMap[rateId] = {
|
ratesMap[rateId] = price;
|
||||||
price,
|
|
||||||
weekendPrice
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const resourcesMap = {};
|
const resourcesMap = {};
|
||||||
resources.forEach(resource => {
|
resources.forEach(resource => {
|
||||||
const { resourceId, rate } = resource;
|
const { resourceId, rate } = resource;
|
||||||
resource.price = ratesMap[rate] || {price: 0, weekendPrice: 0};
|
resource.price = ratesMap[rate] || 0;
|
||||||
resourcesMap[resourceId] = resource;
|
resourcesMap[resourceId] = resource;
|
||||||
});
|
});
|
||||||
|
|
||||||
const reservationsInORD = [];
|
bulkWriteReservationsWithChangesTracking(reservations, resourcesMap)
|
||||||
reservations.forEach(reservation => {
|
.then((changes) => {
|
||||||
const { reservationId } = reservation;
|
|
||||||
reservationsInORD.push(reservationId);
|
|
||||||
});
|
|
||||||
|
|
||||||
const asyncActions = [deleteBookingsRemovedFromORD(reservationsInORD), bulkWriteReservationsWithChangesTracking(reservations, resourcesMap)];
|
|
||||||
|
|
||||||
Promise.all(asyncActions)
|
|
||||||
.then((asyncActionResults) => {
|
|
||||||
const changes = asyncActionResults[1];
|
|
||||||
// console.log(changes);
|
|
||||||
bulkWriteChanges(changes)
|
bulkWriteChanges(changes)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
getIncidentsFromChanges(changes)
|
getIncidentsFromChanges(changes)
|
||||||
.then(({incidents, reservationsForAdditionalCheck}) => {
|
.then(({incidents, reservationsForAdditionalCheck}) => {
|
||||||
// console.log('=====INCIDENTS=====');
|
|
||||||
// console.log(incidents);
|
|
||||||
bulkWriteBookingChangeIncidents(incidents)
|
bulkWriteBookingChangeIncidents(incidents)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
getReservationsIncidentsForRemoval(reservationsForAdditionalCheck)
|
getReservationsIncidentsForRemoval(reservationsForAdditionalCheck)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
const db = require('../../models/index');
|
const db = require('../../models/index');
|
||||||
const Op = require('sequelize').Op;
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
doorLockEvents,
|
doorLockEvents,
|
||||||
@@ -10,18 +9,16 @@ const {
|
|||||||
unlockedIncidentLevelsPrices,
|
unlockedIncidentLevelsPrices,
|
||||||
UNSCHEDULED_CHARGE_PRICE,
|
UNSCHEDULED_CHARGE_PRICE,
|
||||||
MAX_BACK_TO_BACK_DIFFERENCE,
|
MAX_BACK_TO_BACK_DIFFERENCE,
|
||||||
UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH,
|
|
||||||
UNSCHEDULED_TIME_RESOLUTION,
|
UNSCHEDULED_TIME_RESOLUTION,
|
||||||
UI_TIMEZONE
|
UI_TIMEZONE
|
||||||
} = require('../../constants/constants');
|
} = require('../../constants/constants');
|
||||||
const { getUnlockEntryForReservation, getLockEntryForReservation, getEntriesBetween, getLastEntryForReservation } = require('../doorLock/doorLock');
|
const { getUnlockEntryForReservation, getLockEntryForReservation, getEntriesBetween, getLastEntryForReservation } = require('../doorLock/doorLock');
|
||||||
const { getAllFinishedBookings, getFirstPreviousBooking, getFirstNextBooking, getLastReservationInBlock } = require('../officeRnD/bookings');
|
const { getAllFinishedBookings, getFirstPreviousBooking, getFirstNextBooking } = require('../officeRnD/bookings');
|
||||||
|
|
||||||
const getSortedIncidentsForMember = (memberId) => {
|
const getSortedIncidentsForMember = (memberId) => {
|
||||||
const attributes = ['bookingStart', 'incidentLevel', 'incidentLevelPrice', 'unlockTimestamp'];
|
const attributes = ['bookingStart', 'incidentLevel', 'incidentLevelPrice', 'unlockTimestamp'];
|
||||||
const filters = {
|
const filters = {
|
||||||
memberId,
|
memberId
|
||||||
deleted: false
|
|
||||||
};
|
};
|
||||||
const order = [['unlockTimestamp', 'DESC']];
|
const order = [['unlockTimestamp', 'DESC']];
|
||||||
|
|
||||||
@@ -51,7 +48,6 @@ const insertUnscheduledIncidents = (incidents) => {
|
|||||||
totalChargeFee,
|
totalChargeFee,
|
||||||
unlockTimestamp,
|
unlockTimestamp,
|
||||||
lockTimestamp,
|
lockTimestamp,
|
||||||
deleted: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
asyncJobs.push(db.unscheduledIncident.findOrCreate({
|
asyncJobs.push(db.unscheduledIncident.findOrCreate({
|
||||||
@@ -71,35 +67,6 @@ const insertUnscheduledIncidents = (incidents) => {
|
|||||||
return Promise.all(asyncJobs);
|
return Promise.all(asyncJobs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteUnscheduledIncidentsById = (incidentIds) => {
|
|
||||||
const filters = {
|
|
||||||
id: {
|
|
||||||
[Op.in]: incidentIds
|
|
||||||
}
|
|
||||||
};
|
|
||||||
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) => {
|
||||||
@@ -115,7 +82,6 @@ const insertUnlockedIncidents = (incidents) => {
|
|||||||
unlockTimestamp,
|
unlockTimestamp,
|
||||||
incidentLevel,
|
incidentLevel,
|
||||||
incidentLevelPrice,
|
incidentLevelPrice,
|
||||||
deleted: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
asyncJobs.push(db.unlockedIncident.findOrCreate({
|
asyncJobs.push(db.unlockedIncident.findOrCreate({
|
||||||
@@ -126,6 +92,7 @@ const insertUnlockedIncidents = (incidents) => {
|
|||||||
bookingStart: start,
|
bookingStart: start,
|
||||||
bookingEnd: end,
|
bookingEnd: end,
|
||||||
unlockTimestamp,
|
unlockTimestamp,
|
||||||
|
incidentLevel,
|
||||||
},
|
},
|
||||||
defaults: {...incidentForDB},
|
defaults: {...incidentForDB},
|
||||||
}));
|
}));
|
||||||
@@ -134,31 +101,6 @@ const insertUnlockedIncidents = (incidents) => {
|
|||||||
return Promise.all(asyncJobs);
|
return Promise.all(asyncJobs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteUnlockedIncidentsById = (incidentIds) => {
|
|
||||||
const filters = {
|
|
||||||
id: {
|
|
||||||
[Op.in]: incidentIds
|
|
||||||
}
|
|
||||||
};
|
|
||||||
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) => {
|
||||||
@@ -197,7 +139,7 @@ const setUnlockedIncidentsLevel = (incidents) => {
|
|||||||
const incidentsWithLevel = [];
|
const incidentsWithLevel = [];
|
||||||
|
|
||||||
incidents.forEach((incident) => {
|
incidents.forEach((incident) => {
|
||||||
const memberLastIncident = Object.assign({}, membersLastIncident[incident.memberId]);
|
const memberLastIncident = membersLastIncident[incident.memberId];
|
||||||
|
|
||||||
const formattedIncident = {
|
const formattedIncident = {
|
||||||
reservation: incident.reservation,
|
reservation: incident.reservation,
|
||||||
@@ -212,8 +154,8 @@ const setUnlockedIncidentsLevel = (incidents) => {
|
|||||||
formattedIncident.incidentLevel = unlockedIncidentLevelsPrices.UNLOCKED_0.title;
|
formattedIncident.incidentLevel = unlockedIncidentLevelsPrices.UNLOCKED_0.title;
|
||||||
formattedIncident.incidentLevelPrice = unlockedIncidentLevelsPrices.UNLOCKED_0.price;
|
formattedIncident.incidentLevelPrice = unlockedIncidentLevelsPrices.UNLOCKED_0.price;
|
||||||
} else {
|
} else {
|
||||||
const lastIncidentTime = moment.tz(memberLastIncident.incidentTimestamp, UI_TIMEZONE).startOf('month');
|
const lastIncidentTime = moment.utc(memberLastIncident.incidentTimestamp).startOf('month');
|
||||||
const currentIncidentTime = moment.tz(incident.unlockTimestamp, UI_TIMEZONE).startOf('month');
|
const currentIncidentTime = moment.utc(incident.unlockTimestamp).startOf('month');
|
||||||
const timeDiff = Math.abs(lastIncidentTime.diff(currentIncidentTime, 'months'));
|
const timeDiff = Math.abs(lastIncidentTime.diff(currentIncidentTime, 'months'));
|
||||||
|
|
||||||
if (timeDiff >= (parseInt(process.env.UNLOCK_STREAK_REPAIR_AFTER) || 6)){
|
if (timeDiff >= (parseInt(process.env.UNLOCK_STREAK_REPAIR_AFTER) || 6)){
|
||||||
@@ -273,7 +215,7 @@ const analyseReservation = (reservation) => {
|
|||||||
const previousReservationEnd = moment.utc(previousReservation.end);
|
const previousReservationEnd = moment.utc(previousReservation.end);
|
||||||
timeDifferenceFromPreviousReservation = currentReservationStart.diff(previousReservationEnd, 'minutes');
|
timeDifferenceFromPreviousReservation = currentReservationStart.diff(previousReservationEnd, 'minutes');
|
||||||
}
|
}
|
||||||
const previousReservationIsBackToBack = timeDifferenceFromPreviousReservation <= MAX_BACK_TO_BACK_DIFFERENCE;
|
const previousReservationIsBackToBack = timeDifferenceFromPreviousReservation < MAX_BACK_TO_BACK_DIFFERENCE;
|
||||||
|
|
||||||
|
|
||||||
let timeDifferenceBeforeNextReservation = MAX_BACK_TO_BACK_DIFFERENCE + 100;
|
let timeDifferenceBeforeNextReservation = MAX_BACK_TO_BACK_DIFFERENCE + 100;
|
||||||
@@ -281,17 +223,14 @@ const analyseReservation = (reservation) => {
|
|||||||
const nextReservationStart = moment.utc(nextReservation.start);
|
const nextReservationStart = moment.utc(nextReservation.start);
|
||||||
timeDifferenceBeforeNextReservation = nextReservationStart.diff(currentReservationEnd, 'minutes');
|
timeDifferenceBeforeNextReservation = nextReservationStart.diff(currentReservationEnd, 'minutes');
|
||||||
}
|
}
|
||||||
const nextReservationIsBackToBack = timeDifferenceBeforeNextReservation <= MAX_BACK_TO_BACK_DIFFERENCE;
|
const nextReservationIsBackToBack = timeDifferenceBeforeNextReservation < MAX_BACK_TO_BACK_DIFFERENCE;
|
||||||
|
|
||||||
let timeDifferenceFromUnlockEntry = 0;
|
let timeDifferenceFromUnlockEntry = 0;
|
||||||
if (unlockEntry) {
|
if (unlockEntry) {
|
||||||
const unlockTime = moment.utc(unlockEntry.timestamp);
|
const unlockTime = moment.utc(unlockEntry.timestamp);
|
||||||
timeDifferenceFromUnlockEntry = currentReservationStart.diff(unlockTime, 'minutes');
|
timeDifferenceFromUnlockEntry = currentReservationStart.diff(unlockTime, 'minutes');
|
||||||
}
|
}
|
||||||
|
const timeIntervalsToChargeBefore = Math.floor(timeDifferenceFromUnlockEntry / UNSCHEDULED_TIME_RESOLUTION);
|
||||||
let timeIntervalsToChargeBefore = Math.floor(timeDifferenceFromUnlockEntry / UNSCHEDULED_TIME_RESOLUTION);
|
|
||||||
timeIntervalsToChargeBefore -= 1; // Remove first N minutes, N = UNSCHEDULED_TIME_RESOLUTION
|
|
||||||
|
|
||||||
const totalChargeFeeBefore = timeIntervalsToChargeBefore * UNSCHEDULED_CHARGE_PRICE;
|
const totalChargeFeeBefore = timeIntervalsToChargeBefore * UNSCHEDULED_CHARGE_PRICE;
|
||||||
const chargeBefore = totalChargeFeeBefore > 0;
|
const chargeBefore = totalChargeFeeBefore > 0;
|
||||||
|
|
||||||
@@ -300,54 +239,10 @@ const analyseReservation = (reservation) => {
|
|||||||
const lockTime = moment.utc(lockEntry.timestamp);
|
const lockTime = moment.utc(lockEntry.timestamp);
|
||||||
timeDifferenceFromLockEntry = lockTime.diff(currentReservationEnd, 'minutes');
|
timeDifferenceFromLockEntry = lockTime.diff(currentReservationEnd, 'minutes');
|
||||||
}
|
}
|
||||||
let timeIntervalsToChargeAfter = Math.floor(timeDifferenceFromLockEntry / UNSCHEDULED_TIME_RESOLUTION);
|
const timeIntervalsToChargeAfter = Math.floor(timeDifferenceFromLockEntry / UNSCHEDULED_TIME_RESOLUTION);
|
||||||
timeIntervalsToChargeAfter -= 1; // Remove first N minutes, N = UNSCHEDULED_TIME_RESOLUTION
|
|
||||||
|
|
||||||
const totalChargeFeeAfter = timeIntervalsToChargeAfter * UNSCHEDULED_CHARGE_PRICE;
|
const totalChargeFeeAfter = timeIntervalsToChargeAfter * UNSCHEDULED_CHARGE_PRICE;
|
||||||
const chargeAfter = totalChargeFeeAfter > 0;
|
const chargeAfter = totalChargeFeeAfter > 0;
|
||||||
|
|
||||||
// const reservationMoment = moment.tz(reservation.start, reservation.timezone);
|
|
||||||
// if (reservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-11-21 00:00:16+00')) {
|
|
||||||
// console.log('\r\n\r\n==== ANALYSE RESERVATION ==== ');
|
|
||||||
// console.log('\tStart : ', reservationMoment.format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\tEnd : ', moment.tz(reservation.end, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// console.log('\tFirst previous reservation : ');
|
|
||||||
// if (previousReservation) {
|
|
||||||
// console.log('\t\tStart : ', moment.tz(previousReservation.start, previousReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tEnd : ', moment.tz(previousReservation.end, previousReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\t\tNO PREVIOUS RESERVATION');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// console.log('\tFirst next reservation : ');
|
|
||||||
// if (nextReservation) {
|
|
||||||
// console.log('\t\tStart : ', moment.tz(nextReservation.start, nextReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tEnd : ', moment.tz(nextReservation.end, nextReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\t\tNO NEXT RESERVATION');
|
|
||||||
// }
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// if (unlockEntry) {
|
|
||||||
// console.log('\tUnlock entry : ', moment.tz(unlockEntry.timestamp, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\tUnlock entry : NO UNLOCK ENTRY');
|
|
||||||
// }
|
|
||||||
// if (lockEntry) {
|
|
||||||
// console.log('\tLock entry : ', moment.tz(lockEntry.timestamp, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\tLock entry : NO LOCK ENTRY');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// console.log('\tTime before : ');
|
|
||||||
// console.log('\t\tOriginal : ', timeDifferenceFromUnlockEntry);
|
|
||||||
// console.log('\t\tModified : ', timeIntervalsToChargeBefore);
|
|
||||||
// console.log('\tTime after : ');
|
|
||||||
// console.log('\t\tOriginal : ', timeDifferenceFromLockEntry);
|
|
||||||
// console.log('\t\tModified : ', timeIntervalsToChargeAfter);
|
|
||||||
// }
|
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
currentReservation: reservation,
|
currentReservation: reservation,
|
||||||
previousReservation,
|
previousReservation,
|
||||||
@@ -400,248 +295,10 @@ const getIncidentData = (reservation) => {
|
|||||||
timeIntervalsToChargeAfter,
|
timeIntervalsToChargeAfter,
|
||||||
} = result;
|
} = result;
|
||||||
const incidents = [];
|
const incidents = [];
|
||||||
|
const incidentsAsyncJobs = [];
|
||||||
const { resourceId } = currentReservation;
|
const { resourceId } = currentReservation;
|
||||||
|
|
||||||
// const reservationMoment = moment.tz(currentReservation.start, currentReservation.timezone);
|
// 0a. Check for unscheduled use between current and previous reservation
|
||||||
// if (currentReservation.memberId === '5d240cd34a3efa00882d9526') {
|
|
||||||
// console.log('\r\n\r\n==== ANALYSE RESERVATION [GET INCIDENT DATA] ==== ');
|
|
||||||
// console.log('\tStart : ', reservationMoment.format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\tEnd : ', moment.tz(currentReservation.end, currentReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// console.log('\tFirst previous reservation : is back to back [', previousReservationIsBackToBack ? 'T' : 'F' , ']');
|
|
||||||
// if (previousReservation) {
|
|
||||||
// console.log('\t\tStart : ', moment.tz(previousReservation.start, previousReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tEnd : ', moment.tz(previousReservation.end, previousReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\t\tNO PREVIOUS RESERVATION');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// console.log('\tFirst next reservation : is back to back [', nextReservationIsBackToBack ? 'T' : 'F', ']');
|
|
||||||
// if (nextReservation) {
|
|
||||||
// console.log('\t\tStart : ', moment.tz(nextReservation.start, nextReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tEnd : ', moment.tz(nextReservation.end, nextReservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\t\tNO NEXT RESERVATION');
|
|
||||||
// }
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// if (unlockEntry) {
|
|
||||||
// console.log('\tUnlock entry : ', moment.tz(unlockEntry.timestamp, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\tUnlock entry : NO UNLOCK ENTRY');
|
|
||||||
// }
|
|
||||||
// if (lockEntry) {
|
|
||||||
// console.log('\tLock entry : ', moment.tz(lockEntry.timestamp, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// } else {
|
|
||||||
// console.log('\tLock entry : NO LOCK ENTRY');
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//**********************
|
|
||||||
|
|
||||||
const emptyReservation = {
|
|
||||||
reservationId: null,
|
|
||||||
start: null,
|
|
||||||
end: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
// 1. Check if member entered before reservation start time
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\r\n\r\nChecking if member entered before reservation start time :');
|
|
||||||
// console.log('\tunlockEntry : ', unlockEntry && unlockEntry.timestamp ? unlockEntry.timestamp : 'NO UNLOCK ENTRY');
|
|
||||||
// console.log('\tCharge before : ', chargeBefore);
|
|
||||||
// console.log('\tThere is prev. res : ', previousReservationIsBackToBack);
|
|
||||||
// }
|
|
||||||
if (unlockEntry && chargeBefore && !previousReservationIsBackToBack) {
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\tIncident : YES');
|
|
||||||
// }
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
|
||||||
reservation,
|
|
||||||
unlockTimestamp: unlockEntry.timestamp,
|
|
||||||
lockTimestamp: null,
|
|
||||||
memberId: reservation.memberId,
|
|
||||||
resourceId: reservation.resourceId,
|
|
||||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
|
||||||
timeIntervalsToCharge: timeIntervalsToChargeBefore,
|
|
||||||
totalChargeFee: totalChargeFeeBefore,
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\tIncident : NO');
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Check if member left after reservation end time
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\r\n\r\nChecking if member left after reservation end time :');
|
|
||||||
// console.log('\tlockEntry : ', lockEntry && lockEntry.timestamp ? lockEntry.timestamp : 'NO LOCK ENTRY');
|
|
||||||
// console.log('\tCharge after : ', chargeAfter);
|
|
||||||
// console.log('\tThere is res after : ', nextReservationIsBackToBack);
|
|
||||||
// }
|
|
||||||
if (lockEntry && chargeAfter && !nextReservationIsBackToBack) {
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\tIncident : YES');
|
|
||||||
// }
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
|
||||||
reservation,
|
|
||||||
unlockTimestamp: null,
|
|
||||||
lockTimestamp: lockEntry.timestamp,
|
|
||||||
memberId: reservation.memberId,
|
|
||||||
resourceId: reservation.resourceId,
|
|
||||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
|
||||||
timeIntervalsToCharge: timeIntervalsToChargeAfter,
|
|
||||||
totalChargeFee: totalChargeFeeAfter,
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\tIncident : NO');
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Check if member forgot to lock the door
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\r\n\r\nChecking if member left unlocked door :');
|
|
||||||
// console.log('\tunlockEntry : ', unlockEntry && unlockEntry.timestamp ? unlockEntry.timestamp : 'NO UNLOCK ENTRY');
|
|
||||||
// console.log('\tlockEntry : ', lockEntry && lockEntry.timestamp ? lockEntry.timestamp : 'NO LOCK ENTRY');
|
|
||||||
// console.log('\tThere is res before: ', previousReservationIsBackToBack);
|
|
||||||
// console.log('\tThere is res after : ', nextReservationIsBackToBack);
|
|
||||||
// }
|
|
||||||
let forgotToLockAsyncCheck;
|
|
||||||
let asyncUnscheduledUseTest = [];
|
|
||||||
if (!lockEntry && !nextReservationIsBackToBack){
|
|
||||||
|
|
||||||
// Special check
|
|
||||||
|
|
||||||
const checkForUnscheduledUseInBrakeBetweenReservations = async () => {
|
|
||||||
try {
|
|
||||||
if (nextReservation) {
|
|
||||||
const lastReservationInBlockAfterBrake = await getLastReservationInBlock(nextReservation);
|
|
||||||
|
|
||||||
const fromTimestamp = nextReservation.start;
|
|
||||||
const toTimestamp = lastReservationInBlockAfterBrake.end;
|
|
||||||
|
|
||||||
const entriesInBlock = await getEntriesBetween(fromTimestamp, toTimestamp, reservation.resourceId);
|
|
||||||
|
|
||||||
// const reservationMoment = moment.tz(reservation.start, reservation.timezone);
|
|
||||||
// if (reservation.memberId === '5d240cd34a3efa00882d9526') {
|
|
||||||
// console.log('\r\n\r\n==== ANALYSE RESERVATION [GET INCIDENT DATA] ==== ');
|
|
||||||
// console.log('\tStart : ', reservationMoment.format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\tEnd : ', moment.tz(reservation.end, reservation.timezone).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t----------------------------------');
|
|
||||||
// console.log('\tLast reservation in block after brake :');
|
|
||||||
// console.log('\t\tStart : ', moment.tz(lastReservationInBlockAfterBrake.start, UI_TIMEZONE).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tEnd : ', moment.tz(lastReservationInBlockAfterBrake.end, UI_TIMEZONE).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\tSearch entries : ');
|
|
||||||
// console.log('\t\tFrom :', moment.tz(fromTimestamp, UI_TIMEZONE).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tTo :', moment.tz(toTimestamp, UI_TIMEZONE).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\tFirst entry : ');
|
|
||||||
// }
|
|
||||||
|
|
||||||
const addStandaloneUnscheduledIncident = () => {
|
|
||||||
|
|
||||||
const unlockMoment = reservation.end ? moment.utc(reservation.end) : null;
|
|
||||||
const lockMoment = nextReservation.start ? moment.utc(nextReservation.start) : null;
|
|
||||||
|
|
||||||
if (unlockMoment && lockMoment) {
|
|
||||||
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
|
||||||
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
|
||||||
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
|
||||||
if (timeIntervalsToCharge > 0) {
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
|
||||||
reservation: emptyReservation,
|
|
||||||
unlockTimestamp: reservation.end,
|
|
||||||
lockTimestamp: nextReservation.start,
|
|
||||||
memberId: reservation.memberId,
|
|
||||||
resourceId: reservation.resourceId,
|
|
||||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
|
||||||
timeIntervalsToCharge,
|
|
||||||
totalChargeFee,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (Array.isArray(entriesInBlock) && entriesInBlock.length > 0) {
|
|
||||||
const firstEntry = entriesInBlock[0];
|
|
||||||
// console.log('\t\tTimestamp : ', moment.tz(firstEntry.timestamp, UI_TIMEZONE).format('DD.MM, HH:mm'));
|
|
||||||
// console.log('\t\tEvent : ', firstEntry.event);
|
|
||||||
if (firstEntry && firstEntry.event &&
|
|
||||||
firstEntry.memberId === reservation.memberId &&
|
|
||||||
firstEntry.event === doorLockEvents.USER_LOCKED) {
|
|
||||||
|
|
||||||
addStandaloneUnscheduledIncident();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const reservationAfterLastReservationInBlock = await getFirstNextBooking(nextReservation);
|
|
||||||
|
|
||||||
if (reservationAfterLastReservationInBlock) {
|
|
||||||
const lastReservationLockEntry = await getLockEntryForReservation(lastReservationInBlockAfterBrake, reservationAfterLastReservationInBlock);
|
|
||||||
if (lastReservationLockEntry) {
|
|
||||||
addStandaloneUnscheduledIncident();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch (e) {
|
|
||||||
console.log('ERROR while checking for unscheduled use in brake between reservations ');
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (unlockEntry){
|
|
||||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
|
||||||
// console.log('\tIncident : YES [#1]');
|
|
||||||
// }
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
|
||||||
unlockTimestamp: unlockEntry.timestamp,
|
|
||||||
memberId: reservation.memberId,
|
|
||||||
resourceId: unlockEntry.resourceId,
|
|
||||||
reservation: reservation && reservation.dataValues ? reservation.dataValues : emptyReservation,
|
|
||||||
});
|
|
||||||
|
|
||||||
asyncUnscheduledUseTest.push(checkForUnscheduledUseInBrakeBetweenReservations());
|
|
||||||
} else {
|
|
||||||
// No lock entry, no unlock entry and no reservation after this one
|
|
||||||
// This is either :
|
|
||||||
// 1. Last reservation in block of N reservations
|
|
||||||
// 1a. Member locked before entering this reservation
|
|
||||||
// 1b. Member forgot to lock the door <<< Only this is real incident
|
|
||||||
// 2. One reservation, but member never entered
|
|
||||||
|
|
||||||
if (previousReservationIsBackToBack){
|
|
||||||
// To ensure that this is last reservation in block (there is previous but no next reservation back to back)
|
|
||||||
// Now, just check if member actually locked before in the reservation time
|
|
||||||
|
|
||||||
forgotToLockAsyncCheck = getLastEntryForReservation(reservation);
|
|
||||||
forgotToLockAsyncCheck
|
|
||||||
.then((lastEntry) => {
|
|
||||||
if (lastEntry) {
|
|
||||||
if (lastEntry && lastEntry.event === doorLockEvents.USER_UNLOCKED) {
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
|
||||||
unlockTimestamp: lastEntry.timestamp,
|
|
||||||
memberId: lastEntry.memberId,
|
|
||||||
resourceId: lastEntry.resourceId,
|
|
||||||
reservation: reservation && reservation.dataValues ? reservation.dataValues : emptyReservation,
|
|
||||||
});
|
|
||||||
|
|
||||||
asyncUnscheduledUseTest.push(checkForUnscheduledUseInBrakeBetweenReservations());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => reject(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 4. Check for unscheduled use between current and previous reservation
|
|
||||||
const analysePreviousJob = [];
|
const analysePreviousJob = [];
|
||||||
if (previousReservation && !previousReservationIsBackToBack){
|
if (previousReservation && !previousReservationIsBackToBack){
|
||||||
analysePreviousJob.push(analyseReservation(previousReservation));
|
analysePreviousJob.push(analyseReservation(previousReservation));
|
||||||
@@ -649,6 +306,7 @@ const getIncidentData = (reservation) => {
|
|||||||
analysePreviousJob.push(undefined);
|
analysePreviousJob.push(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
incidentsAsyncJobs.push(
|
||||||
Promise.all(analysePreviousJob)
|
Promise.all(analysePreviousJob)
|
||||||
.then(([previousReservationResults]) => {
|
.then(([previousReservationResults]) => {
|
||||||
let fromTimestamp;
|
let fromTimestamp;
|
||||||
@@ -656,39 +314,6 @@ const getIncidentData = (reservation) => {
|
|||||||
|
|
||||||
if (previousReservationResults){
|
if (previousReservationResults){
|
||||||
const previousReservationLockEntry = previousReservationResults.lockEntry;
|
const previousReservationLockEntry = previousReservationResults.lockEntry;
|
||||||
const previousReservationUnlockEntry = previousReservationResults.unlockEntry;
|
|
||||||
|
|
||||||
//Special check for bookings with break between
|
|
||||||
// Check this for duplication, previous special check in step 3. can catch this scenario
|
|
||||||
// if (previousReservation &&
|
|
||||||
// !previousReservationIsBackToBack &&
|
|
||||||
// previousReservation.memberId === currentReservation.memberId &&
|
|
||||||
// previousReservationUnlockEntry && !previousReservationLockEntry &&
|
|
||||||
// !unlockEntry && lockEntry //current reservation unlock / lock entries
|
|
||||||
// ) {
|
|
||||||
//
|
|
||||||
// const unlockMoment = previousReservation.end ? moment.utc(previousReservation.end) : null;
|
|
||||||
// const lockMoment = currentReservation.start ? moment.utc(currentReservation.start) : null;
|
|
||||||
//
|
|
||||||
// if (unlockMoment && lockMoment){
|
|
||||||
// const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
|
||||||
// const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
|
||||||
// const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
|
||||||
// if (timeIntervalsToCharge > 0) {
|
|
||||||
// incidents.push({
|
|
||||||
// incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
|
||||||
// reservation: emptyReservation,
|
|
||||||
// unlockTimestamp: previousReservation.end,
|
|
||||||
// lockTimestamp: currentReservation.start,
|
|
||||||
// memberId: currentReservation.memberId,
|
|
||||||
// resourceId,
|
|
||||||
// chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
|
||||||
// timeIntervalsToCharge,
|
|
||||||
// totalChargeFee,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fromTimestamp = previousReservationLockEntry && previousReservationLockEntry.timestamp ?
|
fromTimestamp = previousReservationLockEntry && previousReservationLockEntry.timestamp ?
|
||||||
previousReservationLockEntry.timestamp : previousReservation.end;
|
previousReservationLockEntry.timestamp : previousReservation.end;
|
||||||
@@ -700,55 +325,27 @@ const getIncidentData = (reservation) => {
|
|||||||
unlockEntry.timestamp : reservation.start;
|
unlockEntry.timestamp : reservation.start;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's skip this if previous reservation is back-to-back
|
incidentsAsyncJobs.push(
|
||||||
let getEntriesAsyncCheck;
|
getEntriesBetween(fromTimestamp, toTimestamp, resourceId)
|
||||||
if (previousReservation && previousReservationIsBackToBack){
|
.then((entriesBetween) => {
|
||||||
//Skip
|
incidentsAsyncJobs.push(
|
||||||
}else{
|
new Promise((resolve, reject) => {
|
||||||
getEntriesAsyncCheck = getEntriesBetween(fromTimestamp, toTimestamp, resourceId);
|
let pairUnlockEntry = null;
|
||||||
}
|
let pairLockEntry = null;
|
||||||
|
|
||||||
//Now wait for "forgotToLockAsyncCheck", and possible "getEntriesBetween" to finish
|
entriesBetween.forEach((entry) => {
|
||||||
Promise.all([forgotToLockAsyncCheck, getEntriesAsyncCheck, asyncUnscheduledUseTest])
|
if (entry && entry.event){
|
||||||
.then((asyncActionResults) => {
|
switch(entry.event){
|
||||||
const entriesBetween = asyncActionResults[1];
|
case doorLockEvents.USER_UNLOCKED:
|
||||||
if (Array.isArray(entriesBetween)){
|
if (!pairUnlockEntry){
|
||||||
let pairUnlockEntry = null;
|
pairUnlockEntry = entry;
|
||||||
let pairLockEntry = null;
|
}else{
|
||||||
|
const emptyReservation = {
|
||||||
|
reservationId: null,
|
||||||
|
start: null,
|
||||||
|
end: null,
|
||||||
|
};
|
||||||
|
|
||||||
//Inspect all entries and insert detected incidents
|
|
||||||
entriesBetween.forEach((entry) => {
|
|
||||||
// console.log('\tEvent : ', entry.event);
|
|
||||||
// console.log('\tEvent : ', entry.timestamp ? moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
|
|
||||||
if (entry && entry.event){
|
|
||||||
switch(entry.event){
|
|
||||||
case doorLockEvents.USER_UNLOCKED:
|
|
||||||
if (!pairUnlockEntry){
|
|
||||||
pairUnlockEntry = entry;
|
|
||||||
}else{
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
|
||||||
reservation: emptyReservation,
|
|
||||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
|
||||||
memberId: pairUnlockEntry.memberId,
|
|
||||||
resourceId,
|
|
||||||
});
|
|
||||||
|
|
||||||
pairLockEntry = null;
|
|
||||||
pairUnlockEntry = entry;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case doorLockEvents.USER_LOCKED:
|
|
||||||
if (pairUnlockEntry && !pairLockEntry){
|
|
||||||
pairLockEntry = entry;
|
|
||||||
|
|
||||||
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
|
||||||
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
|
||||||
|
|
||||||
const entriesOnSameDay = lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day');
|
|
||||||
const sameMember = pairUnlockEntry.memberId === pairLockEntry.memberId;
|
|
||||||
|
|
||||||
if ((entriesOnSameDay && !sameMember) || (!entriesOnSameDay)){
|
|
||||||
incidents.push({
|
incidents.push({
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||||
reservation: emptyReservation,
|
reservation: emptyReservation,
|
||||||
@@ -756,63 +353,156 @@ const getIncidentData = (reservation) => {
|
|||||||
memberId: pairUnlockEntry.memberId,
|
memberId: pairUnlockEntry.memberId,
|
||||||
resourceId,
|
resourceId,
|
||||||
});
|
});
|
||||||
}else if (entriesOnSameDay && sameMember){
|
|
||||||
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
pairLockEntry = null;
|
||||||
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
pairUnlockEntry = entry;
|
||||||
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
}
|
||||||
if (timeIntervalsToCharge > 0){
|
break;
|
||||||
|
case doorLockEvents.USER_LOCKED:
|
||||||
|
if (pairUnlockEntry && !pairLockEntry){
|
||||||
|
pairLockEntry = entry;
|
||||||
|
const emptyReservation = {
|
||||||
|
reservationId: null,
|
||||||
|
start: null,
|
||||||
|
end: null,
|
||||||
|
};
|
||||||
|
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
||||||
|
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
||||||
|
|
||||||
|
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){
|
||||||
|
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
||||||
|
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
||||||
|
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
||||||
|
if (timeIntervalsToCharge > 0){
|
||||||
|
incidents.push({
|
||||||
|
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
||||||
|
reservation: emptyReservation,
|
||||||
|
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||||
|
lockTimestamp: pairLockEntry.timestamp,
|
||||||
|
memberId: pairUnlockEntry.memberId,
|
||||||
|
resourceId,
|
||||||
|
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||||
|
timeIntervalsToCharge,
|
||||||
|
totalChargeFee,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
const emptyReservation = {
|
||||||
|
reservationId: null,
|
||||||
|
start: null,
|
||||||
|
end: null,
|
||||||
|
};
|
||||||
|
|
||||||
incidents.push({
|
incidents.push({
|
||||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||||
reservation: emptyReservation,
|
reservation: emptyReservation,
|
||||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||||
lockTimestamp: pairLockEntry.timestamp,
|
|
||||||
memberId: pairUnlockEntry.memberId,
|
memberId: pairUnlockEntry.memberId,
|
||||||
resourceId,
|
resourceId,
|
||||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
|
||||||
timeIntervalsToCharge,
|
|
||||||
totalChargeFee,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pairUnlockEntry = null;
|
||||||
|
pairLockEntry = null;
|
||||||
|
}else{
|
||||||
|
if (!pairUnlockEntry){
|
||||||
|
pairLockEntry = entry;
|
||||||
|
//Only lock entry, ignore now
|
||||||
|
}
|
||||||
|
pairLockEntry = null;
|
||||||
|
pairUnlockEntry = null;
|
||||||
}
|
}
|
||||||
pairUnlockEntry = null;
|
}
|
||||||
pairLockEntry = null;
|
|
||||||
}else{
|
|
||||||
pairLockEntry = null;
|
|
||||||
pairUnlockEntry = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (pairUnlockEntry){
|
|
||||||
incidents.push({
|
|
||||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
|
||||||
reservation: emptyReservation,
|
|
||||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
|
||||||
memberId: pairUnlockEntry.memberId,
|
|
||||||
resourceId,
|
|
||||||
});
|
});
|
||||||
|
resolve(null);
|
||||||
pairLockEntry = null;
|
}));
|
||||||
pairUnlockEntry = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resolve(incidents);
|
|
||||||
})
|
})
|
||||||
.catch(error => reject(error));
|
.catch((error) => reject(error)));
|
||||||
})
|
})
|
||||||
.catch(error => reject(error));
|
.catch((error) => reject(error)));
|
||||||
//
|
|
||||||
// Promise.all(incidentsAsyncJobs)
|
// 1. Check if member entered before reservation start time
|
||||||
// .then(() => {
|
if (unlockEntry && chargeBefore && !previousReservationIsBackToBack) {
|
||||||
// // console.log('\tDone with Async jobs for reservation ');
|
incidents.push({
|
||||||
// // console.log('\t\tStart : ', reservationMoment.format('DD.MM, HH:mm'));
|
incidentType: incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
||||||
// // console.log('\t\tEnd : ', moment.tz(currentReservation.end, currentReservation.timezone).format('DD.MM, HH:mm'));
|
reservation,
|
||||||
//
|
unlockTimestamp: unlockEntry.timestamp,
|
||||||
// setTimeout(() => {resolve(incidents)}, 10000);
|
lockTimestamp: null,
|
||||||
// // resolve(incidents);
|
memberId: reservation.memberId,
|
||||||
// })
|
resourceId: reservation.resourceId,
|
||||||
// .catch((error) => reject(error));
|
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||||
|
timeIntervalsToCharge: timeIntervalsToChargeBefore,
|
||||||
|
totalChargeFee: totalChargeFeeBefore,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Check if member left after reservation end time
|
||||||
|
if (lockEntry && chargeAfter && !nextReservationIsBackToBack) {
|
||||||
|
incidents.push({
|
||||||
|
incidentType: incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
||||||
|
reservation,
|
||||||
|
unlockTimestamp: null,
|
||||||
|
lockTimestamp: lockEntry.timestamp,
|
||||||
|
memberId: reservation.memberId,
|
||||||
|
resourceId: reservation.resourceId,
|
||||||
|
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||||
|
timeIntervalsToCharge: timeIntervalsToChargeAfter,
|
||||||
|
totalChargeFee: totalChargeFeeAfter,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Check if member forgot to lock the door
|
||||||
|
if (!lockEntry && !nextReservationIsBackToBack){
|
||||||
|
const emptyReservation = {
|
||||||
|
reservationId: null,
|
||||||
|
start: null,
|
||||||
|
end: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (unlockEntry){
|
||||||
|
|
||||||
|
incidents.push({
|
||||||
|
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
||||||
|
unlockTimestamp: unlockEntry.timestamp,
|
||||||
|
memberId: reservation.memberId,
|
||||||
|
resourceId: unlockEntry.resourceId,
|
||||||
|
reservation: reservation && reservation.dataValues ? reservation.dataValues : emptyReservation,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// No lock entry, no unlock entry and no reservation after this one
|
||||||
|
// This is either :
|
||||||
|
// 1. Last reservation in block of N reservations
|
||||||
|
// 1a. Member locked before entering this reservation
|
||||||
|
// 1b. Member forgot to lock the door <<< Only this is real incident
|
||||||
|
// 2. One reservation, but member never entered
|
||||||
|
|
||||||
|
if (previousReservationIsBackToBack){
|
||||||
|
// To ensure that this is last reservation in block (there is previous but no next reservation back to back)
|
||||||
|
// Now, just check if member actually locked before in the reservation time
|
||||||
|
incidentsAsyncJobs.push(
|
||||||
|
getLastEntryForReservation(reservation)
|
||||||
|
.then((lastEntry) => {
|
||||||
|
if (lastEntry && lastEntry.event === doorLockEvents.USER_UNLOCKED){
|
||||||
|
incidents.push({
|
||||||
|
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
||||||
|
unlockTimestamp: lastEntry.timestamp,
|
||||||
|
memberId: lastEntry.memberId,
|
||||||
|
resourceId: lastEntry.resourceId,
|
||||||
|
reservation: reservation && reservation.dataValues ? reservation.dataValues : emptyReservation,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => reject(error)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all(incidentsAsyncJobs)
|
||||||
|
.then(() => {
|
||||||
|
resolve(incidents);
|
||||||
|
})
|
||||||
|
.catch((error) => reject(error));
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((error) => reject(error));
|
.catch((error) => reject(error));
|
||||||
@@ -883,9 +573,5 @@ const calculateDoorLockCharges = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
calculateDoorLockCharges,
|
calculateDoorLockCharges
|
||||||
deleteUnlockedIncidentsById,
|
|
||||||
deleteUnscheduledIncidentsById,
|
|
||||||
updateUnlockedIncidentsById,
|
|
||||||
updateUnscheduledIncidentsById
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ const createFeeFromIncident = (incident) => {
|
|||||||
memberId,
|
memberId,
|
||||||
officeId,
|
officeId,
|
||||||
officeName,
|
officeName,
|
||||||
officeSlug,
|
|
||||||
resourceName,
|
resourceName,
|
||||||
oldResourceName,
|
oldResourceName,
|
||||||
newResourceName,
|
newResourceName,
|
||||||
@@ -46,10 +45,6 @@ const createFeeFromIncident = (incident) => {
|
|||||||
let bookingTimeExplanation = '';
|
let bookingTimeExplanation = '';
|
||||||
let incidentTimeExplanation = '';
|
let incidentTimeExplanation = '';
|
||||||
|
|
||||||
let additionalDateTimeExplanation = '';
|
|
||||||
|
|
||||||
let spacing = '';
|
|
||||||
|
|
||||||
let roomExplanation = '';
|
let roomExplanation = '';
|
||||||
let dateExplanation = '';
|
let dateExplanation = '';
|
||||||
|
|
||||||
@@ -67,8 +62,7 @@ const createFeeFromIncident = (incident) => {
|
|||||||
|
|
||||||
switch (incidentTypeNumber) {
|
switch (incidentTypeNumber) {
|
||||||
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
case incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
|
||||||
spacing = ' ';
|
roomExplanation = resourceName;
|
||||||
roomExplanation = resourceName || 'Unknown';
|
|
||||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
||||||
@@ -80,8 +74,7 @@ const createFeeFromIncident = (incident) => {
|
|||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
case incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
|
||||||
spacing = ' ';
|
roomExplanation = resourceName;
|
||||||
roomExplanation = resourceName || 'Unknown';
|
|
||||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
||||||
@@ -93,8 +86,7 @@ const createFeeFromIncident = (incident) => {
|
|||||||
quantity = +timeIntervalsToCharge.toFixed(2);
|
quantity = +timeIntervalsToCharge.toFixed(2);
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
case incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
|
||||||
spacing = ' ';
|
roomExplanation = resourceName;
|
||||||
roomExplanation = resourceName || 'Unknown';
|
|
||||||
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = bookingStartMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${bookingStartMoment.clone().format('HH:mm')} to ${bookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `lock : ${lockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `lock : ${lockMoment.clone().format('HH:mm')}`;
|
||||||
@@ -106,8 +98,7 @@ const createFeeFromIncident = (incident) => {
|
|||||||
quantity = +timeIntervalsToCharge.toFixed(2);
|
quantity = +timeIntervalsToCharge.toFixed(2);
|
||||||
break;
|
break;
|
||||||
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
case incidentType.UNLOCKED_INCIDENT_STANDALONE:
|
||||||
spacing = ' ';
|
roomExplanation = resourceName;
|
||||||
roomExplanation = resourceName || 'Unknown';
|
|
||||||
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}`;
|
||||||
@@ -119,8 +110,7 @@ const createFeeFromIncident = (incident) => {
|
|||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
case incidentType.UNSCHEDULED_INCIDENT_STANDALONE:
|
||||||
spacing = ' ';
|
roomExplanation = resourceName;
|
||||||
roomExplanation = resourceName || 'Unknown';
|
|
||||||
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
dateExplanation = unlockMoment.clone().startOf('day').format('MMM DD');
|
||||||
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${unlockMoment.clone().format('HH:mm')} to ${lockMoment.clone().format('HH:mm')}]`;
|
||||||
//incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}, lock : ${lockMoment.clone().format('HH:mm')}`;
|
//incidentTimeExplanation = `unlock : ${unlockMoment.clone().format('HH:mm')}, lock : ${lockMoment.clone().format('HH:mm')}`;
|
||||||
@@ -131,18 +121,16 @@ const createFeeFromIncident = (incident) => {
|
|||||||
quantity = +timeIntervalsToCharge.toFixed(2);
|
quantity = +timeIntervalsToCharge.toFixed(2);
|
||||||
break;
|
break;
|
||||||
case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY:
|
case incidentType.BOOKING_MOVED_TO_ANOTHER_DAY:
|
||||||
spacing = ' ';
|
|
||||||
// if (oldResourceName !== newResourceName){
|
// if (oldResourceName !== newResourceName){
|
||||||
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
||||||
// }else{
|
// }else{
|
||||||
// roomExplanation = oldResourceName;
|
// roomExplanation = oldResourceName;
|
||||||
// }
|
// }
|
||||||
roomExplanation = newResourceName || 'Unknown';
|
roomExplanation = newResourceName;
|
||||||
|
|
||||||
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')} -> ${newBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
||||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
||||||
bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
additionalDateTimeExplanation = ` -> ${newBookingStartMoment.clone().format('MMM DD')} [${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
|
||||||
incidentTimeExplanation = `moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
incidentTimeExplanation = `moved on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
||||||
incidentExplanation += `, ${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
@@ -152,30 +140,26 @@ const createFeeFromIncident = (incident) => {
|
|||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.BOOKING_SHORTENED:
|
case incidentType.BOOKING_SHORTENED:
|
||||||
spacing = ' ';
|
|
||||||
// if (oldResourceName !== newResourceName){
|
// if (oldResourceName !== newResourceName){
|
||||||
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
// roomExplanation = `${oldResourceName} -> ${newResourceName}`;
|
||||||
// }else{
|
// }else{
|
||||||
// roomExplanation = oldResourceName;
|
// roomExplanation = oldResourceName;
|
||||||
// }
|
// }
|
||||||
roomExplanation = newResourceName || 'Unknown';
|
roomExplanation = newResourceName;
|
||||||
|
|
||||||
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
||||||
|
|
||||||
const originalBookingExplanation = `${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}`;
|
|
||||||
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
dateExplanation = `${newBookingStartMoment.clone().format('MMM DD')}`;
|
||||||
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${newBookingStartMoment.clone().format('HH:mm')} to ${newBookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
incidentTimeExplanation = `reservation shortened from [${originalBookingExplanation}] on [${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}]`;
|
incidentTimeExplanation = `shortened on : ${incidentTimestampMoment.clone().format('MMM DD, HH:mm')}`;
|
||||||
incidentExplanation = `${incidentTimeExplanation}`;
|
incidentExplanation += `, ${incidentTimeExplanation}`;
|
||||||
|
|
||||||
date = newBookingStartMoment.clone().utc(UI_TIMEZONE).startOf('day').format();
|
date = incidentTimestampMoment.clone().startOf('day').format();
|
||||||
|
|
||||||
price = +totalChargeFee.toFixed(2);
|
price = +totalChargeFee.toFixed(2);
|
||||||
quantity = 1.00;
|
quantity = 1.00;
|
||||||
break;
|
break;
|
||||||
case incidentType.BOOKING_CANCELED_LATE:
|
case incidentType.BOOKING_CANCELED_LATE:
|
||||||
spacing = ' ';
|
roomExplanation = oldResourceName;
|
||||||
roomExplanation = oldResourceName || 'Unknown';
|
|
||||||
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
// dateExplanation = `${oldBookingStartMoment.clone().format('ddd, MMM DD')}`;
|
||||||
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
dateExplanation = `${oldBookingStartMoment.clone().format('MMM DD')}`;
|
||||||
bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`;
|
bookingTimeExplanation = `[${oldBookingStartMoment.clone().format('HH:mm')} to ${oldBookingEndMoment.clone().format('HH:mm')}]`;
|
||||||
@@ -189,7 +173,7 @@ const createFeeFromIncident = (incident) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedName = `${officeSlug}, ${dateExplanation} ${bookingTimeExplanation}${additionalDateTimeExplanation}${spacing}${roomExplanation}, ${incidentExplanation}`;
|
const formattedName = `${dateExplanation} ${bookingTimeExplanation} ${roomExplanation}, ${officeName}, ${incidentExplanation}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: formattedName,
|
name: formattedName,
|
||||||
@@ -218,14 +202,14 @@ const createFeeFromBooking = (booking, resourceMappings) => {
|
|||||||
const endMoment = moment.tz(end, DEFAULT_DATE_FORMAT, timezone);
|
const endMoment = moment.tz(end, DEFAULT_DATE_FORMAT, timezone);
|
||||||
const reservationLength = endMoment.diff(startMoment, 'hours', true);
|
const reservationLength = endMoment.diff(startMoment, 'hours', true);
|
||||||
|
|
||||||
const officeSlug = officesMap[officeId].officeSlug || 'Unknown';
|
const officeName = officesMap[officeId].officeName || 'Unknown';
|
||||||
const resourceName = resourcesMap[resourceId].resourceName || 'Unknown';
|
const resourceName = resourcesMap[resourceId].resourceName || 'Unknown';
|
||||||
|
|
||||||
const formattedDate = startMoment.clone().startOf('day').format('MMM DD');
|
const formattedDate = startMoment.clone().startOf('day').format('MMM DD');
|
||||||
const formattedStartTime = startMoment.format('HH:mm');
|
const formattedStartTime = startMoment.format('HH:mm');
|
||||||
const formattedEndTime = endMoment.format('HH:mm');
|
const formattedEndTime = endMoment.format('HH:mm');
|
||||||
|
|
||||||
const formattedName = `${officeSlug}, ${formattedDate} [${formattedStartTime} to ${formattedEndTime}] ${resourceName}`;
|
const formattedName = `${formattedDate} [${formattedStartTime} to ${formattedEndTime}] ${resourceName}, ${officeName}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: formattedName,
|
name: formattedName,
|
||||||
@@ -244,9 +228,9 @@ const createNegativeFeeForDiscount = (memberData, dateRange) => {
|
|||||||
const { totalBookedHours, totalChargedHours, totalBookingChargedFee } = bookingData;
|
const { totalBookedHours, totalChargedHours, totalBookingChargedFee } = bookingData;
|
||||||
const { memberId, officeId } = member;
|
const { memberId, officeId } = member;
|
||||||
|
|
||||||
let dateForDiscount = moment.utc().subtract(1, 'month').startOf('month').toISOString();
|
let endDate = moment.utc().endOf('day').toISOString();
|
||||||
if (dateRange.startDate){
|
if (dateRange.endDate){
|
||||||
dateForDiscount = moment.utc(dateRange.startDate, DEFAULT_DATE_FORMAT).startOf('month').toISOString();
|
endDate = moment.utc(dateRange.endDate, DEFAULT_DATE_FORMAT).endOf('day').toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
let membershipFeeForDiscount = 0;
|
let membershipFeeForDiscount = 0;
|
||||||
@@ -285,7 +269,7 @@ const createNegativeFeeForDiscount = (memberData, dateRange) => {
|
|||||||
name: formattedName,
|
name: formattedName,
|
||||||
price: -discount.toFixed(2),
|
price: -discount.toFixed(2),
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
date: dateForDiscount,
|
date: endDate,
|
||||||
member: memberId,
|
member: memberId,
|
||||||
team: null,
|
team: null,
|
||||||
office: officeId,
|
office: officeId,
|
||||||
@@ -346,7 +330,7 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
|
|||||||
allIncidents.forEach((incident) => {
|
allIncidents.forEach((incident) => {
|
||||||
const feeFromIncident = createFeeFromIncident(incident);
|
const feeFromIncident = createFeeFromIncident(incident);
|
||||||
if (feeFromIncident){
|
if (feeFromIncident){
|
||||||
allFees.push(feeFromIncident);
|
allFees.push(createFeeFromIncident(incident));
|
||||||
}
|
}
|
||||||
|
|
||||||
const incidentsValuableForDiscountCalculation = [
|
const incidentsValuableForDiscountCalculation = [
|
||||||
@@ -480,7 +464,7 @@ const getMembersFeesForDateRange = (dateRange, memberIds) => {
|
|||||||
fee.team = memberIdTeamMappings[member] || null;
|
fee.team = memberIdTeamMappings[member] || null;
|
||||||
if (teamId){
|
if (teamId){
|
||||||
//if member is part of the company, add name to the fee description/name
|
//if member is part of the company, add name to the fee description/name
|
||||||
fee.name = `${memberName}, ${fee.name}`;
|
fee.name += `, ${memberName}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const Op = require('sequelize').Op;
|
|||||||
|
|
||||||
const workbookCreator = require('excel4node');
|
const workbookCreator = require('excel4node');
|
||||||
|
|
||||||
|
const { checkBookingChanges } = require('./checkBookingChange');
|
||||||
const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors } = require('../../constants/constants');
|
const { incidentType, UI_TIMEZONE, DEFAULT_DATE_FORMAT, integrationServiceErrors } = require('../../constants/constants');
|
||||||
|
|
||||||
const { getAllBookingsForMembersInDateRange } = require('./bookings');
|
const { getAllBookingsForMembersInDateRange } = require('./bookings');
|
||||||
@@ -17,9 +18,7 @@ const { getChargedCanceledReservations } = require('../integration/bookingChange
|
|||||||
const getUnlockedIncidents = (startDate, endDate, memberIds) => {
|
const getUnlockedIncidents = (startDate, endDate, memberIds) => {
|
||||||
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'unlockTimestamp', 'incidentLevel', 'incidentLevelPrice'];
|
const attributes = ['id', 'reservationId', 'memberId', 'resourceId', 'bookingStart', 'bookingEnd', 'unlockTimestamp', 'incidentLevel', 'incidentLevelPrice'];
|
||||||
|
|
||||||
const filters = {
|
const filters = {};
|
||||||
deleted: false
|
|
||||||
};
|
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
const bookingStartCondition = {
|
const bookingStartCondition = {
|
||||||
@@ -77,9 +76,7 @@ const getUnscheduledIncidents = (startDate, endDate, memberIds) => {
|
|||||||
'totalChargeFee'
|
'totalChargeFee'
|
||||||
];
|
];
|
||||||
|
|
||||||
const filters = {
|
const filters = {};
|
||||||
deleted: false
|
|
||||||
};
|
|
||||||
|
|
||||||
if (startDate && endDate) {
|
if (startDate && endDate) {
|
||||||
const bookingStartCondition = {
|
const bookingStartCondition = {
|
||||||
@@ -221,29 +218,18 @@ const getAllIncidents = (dateRange, memberIds) => {
|
|||||||
unlockedIncidents.forEach((unlockedIncident) => {
|
unlockedIncidents.forEach((unlockedIncident) => {
|
||||||
const incidentTypeNumber = unlockedIncident.reservationId ?
|
const incidentTypeNumber = unlockedIncident.reservationId ?
|
||||||
incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION : incidentType.UNLOCKED_INCIDENT_STANDALONE;
|
incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION : incidentType.UNLOCKED_INCIDENT_STANDALONE;
|
||||||
|
|
||||||
const resourceObject = resourcesMap[unlockedIncident.resourceId];
|
|
||||||
const officeObject = resourceObject ? officesMap[resourceObject.officeId] : null;
|
|
||||||
|
|
||||||
const memberName = membersMap[unlockedIncident.memberId] ? membersMap[unlockedIncident.memberId].name : 'Unknown member';
|
|
||||||
const resourceName = resourceObject ? resourceObject.resourceName : 'Unknown room';
|
|
||||||
const officeId = resourceObject ? resourceObject.officeId : '';
|
|
||||||
const officeName = officeObject ? officeObject.officeName : 'Unknown office';
|
|
||||||
const officeSlug = officeObject ? officeObject.officeSlug : '-';
|
|
||||||
|
|
||||||
allIncidents.push({
|
allIncidents.push({
|
||||||
incidentId: unlockedIncident.id,
|
incidentId: unlockedIncident.id,
|
||||||
memberId: unlockedIncident.memberId,
|
memberId: unlockedIncident.memberId,
|
||||||
memberName,
|
memberName: membersMap[unlockedIncident.memberId].name,
|
||||||
resourceName,
|
resourceName: resourcesMap[unlockedIncident.resourceId].resourceName,
|
||||||
officeId,
|
officeId: resourcesMap[unlockedIncident.resourceId].officeId,
|
||||||
officeName,
|
officeName: officesMap[resourcesMap[unlockedIncident.resourceId].officeId].officeName,
|
||||||
officeSlug,
|
bookingStart: formatTime(unlockedIncident.bookingStart),
|
||||||
bookingStart: formatTime(unlockedIncident.bookingStart) || '-',
|
bookingEnd: formatTime(unlockedIncident.bookingEnd),
|
||||||
bookingEnd: formatTime(unlockedIncident.bookingEnd) || '-',
|
|
||||||
bookingStartRaw: unlockedIncident.bookingStart,
|
bookingStartRaw: unlockedIncident.bookingStart,
|
||||||
bookingEndRaw: unlockedIncident.bookingEnd,
|
bookingEndRaw: unlockedIncident.bookingEnd,
|
||||||
unlockTimestamp: formatTime(unlockedIncident.unlockTimestamp) || '-',
|
unlockTimestamp: formatTime(unlockedIncident.unlockTimestamp),
|
||||||
unlockTimestampRaw: unlockedIncident.unlockTimestamp,
|
unlockTimestampRaw: unlockedIncident.unlockTimestamp,
|
||||||
incidentType: incidentTypeNumber,
|
incidentType: incidentTypeNumber,
|
||||||
incidentLevel: unlockedIncident.incidentLevel,
|
incidentLevel: unlockedIncident.incidentLevel,
|
||||||
@@ -262,30 +248,19 @@ const getAllIncidents = (dateRange, memberIds) => {
|
|||||||
}else{
|
}else{
|
||||||
incidentTypeNumber = incidentType.UNSCHEDULED_INCIDENT_STANDALONE;
|
incidentTypeNumber = incidentType.UNSCHEDULED_INCIDENT_STANDALONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resourceObject = resourcesMap[unscheduledIncident.resourceId];
|
|
||||||
const officeObject = resourceObject ? officesMap[resourceObject.officeId] : null;
|
|
||||||
|
|
||||||
const memberName = membersMap[unscheduledIncident.memberId] ? membersMap[unscheduledIncident.memberId].name : 'Unknown member';
|
|
||||||
const resourceName = resourceObject ? resourceObject.resourceName : 'Unknown room';
|
|
||||||
const officeId = resourceObject ? resourceObject.officeId : '';
|
|
||||||
const officeName = officeObject ? officeObject.officeName : 'Unknown office';
|
|
||||||
const officeSlug = officeObject ? officeObject.officeSlug : '-';
|
|
||||||
|
|
||||||
allIncidents.push({
|
allIncidents.push({
|
||||||
incidentId: unscheduledIncident.id,
|
incidentId: unscheduledIncident.id,
|
||||||
memberId: unscheduledIncident.memberId,
|
memberId: unscheduledIncident.memberId,
|
||||||
memberName,
|
memberName: membersMap[unscheduledIncident.memberId].name,
|
||||||
resourceName,
|
resourceName: resourcesMap[unscheduledIncident.resourceId].resourceName,
|
||||||
officeId,
|
officeId: resourcesMap[unscheduledIncident.resourceId].officeId,
|
||||||
officeName,
|
officeName: officesMap[resourcesMap[unscheduledIncident.resourceId].officeId].officeName,
|
||||||
officeSlug,
|
bookingStart: formatTime(unscheduledIncident.bookingStart),
|
||||||
bookingStart: formatTime(unscheduledIncident.bookingStart) || '-',
|
bookingEnd: formatTime(unscheduledIncident.bookingEnd),
|
||||||
bookingEnd: formatTime(unscheduledIncident.bookingEnd) || '-',
|
|
||||||
bookingStartRaw: unscheduledIncident.bookingStart,
|
bookingStartRaw: unscheduledIncident.bookingStart,
|
||||||
bookingEndRaw: unscheduledIncident.bookingEnd,
|
bookingEndRaw: unscheduledIncident.bookingEnd,
|
||||||
unlockTimestamp: formatTime(unscheduledIncident.unlockTimestamp) || '-',
|
unlockTimestamp: formatTime(unscheduledIncident.unlockTimestamp),
|
||||||
lockTimestamp: formatTime(unscheduledIncident.lockTimestamp) || '-',
|
lockTimestamp: formatTime(unscheduledIncident.lockTimestamp),
|
||||||
unlockTimestampRaw: unscheduledIncident.unlockTimestamp,
|
unlockTimestampRaw: unscheduledIncident.unlockTimestamp,
|
||||||
lockTimestampRaw: unscheduledIncident.lockTimestamp,
|
lockTimestampRaw: unscheduledIncident.lockTimestamp,
|
||||||
incidentType: incidentTypeNumber,
|
incidentType: incidentTypeNumber,
|
||||||
@@ -310,14 +285,13 @@ const getAllIncidents = (dateRange, memberIds) => {
|
|||||||
deleted,
|
deleted,
|
||||||
createdAt,
|
createdAt,
|
||||||
} = bookingChangeIncident;
|
} = bookingChangeIncident;
|
||||||
const memberName = membersMap[memberId] ? membersMap[memberId].name : 'Unknown member';
|
const memberName = membersMap[memberId].name;
|
||||||
const oldResource = resourcesMap[oldResourceId];
|
const oldResource = resourcesMap[oldResourceId];
|
||||||
const newResource = newResourceId ? resourcesMap[newResourceId] : null;
|
const newResource = newResourceId ? resourcesMap[newResourceId] : null;
|
||||||
const oldResourceName = oldResource ? oldResource.resourceName : 'Unknown room';
|
const oldResourceName = oldResource.resourceName;
|
||||||
const newResourceName = newResource ? newResource.resourceName : null;
|
const newResourceName = newResource ? newResource.resourceName : null;
|
||||||
const officeId = oldResource ? oldResource.officeId : '';
|
const officeId = oldResource.officeId;
|
||||||
const officeName = officesMap[officeId] ? officesMap[officeId].officeName : 'Unknown office';
|
const officeName = officesMap[officeId].officeName;
|
||||||
const officeSlug = officesMap[officeId] ? officesMap[officeId].officeSlug : '-';
|
|
||||||
allIncidents.push({
|
allIncidents.push({
|
||||||
incidentId: id,
|
incidentId: id,
|
||||||
memberId,
|
memberId,
|
||||||
@@ -326,11 +300,10 @@ const getAllIncidents = (dateRange, memberIds) => {
|
|||||||
newResourceName,
|
newResourceName,
|
||||||
officeId,
|
officeId,
|
||||||
officeName,
|
officeName,
|
||||||
officeSlug,
|
oldBookingStart: formatTime(oldBookingStart),
|
||||||
oldBookingStart: formatTime(oldBookingStart) || '-',
|
oldBookingEnd: formatTime(oldBookingEnd),
|
||||||
oldBookingEnd: formatTime(oldBookingEnd) || '-',
|
newBookingStart: formatTime(newBookingStart),
|
||||||
newBookingStart: formatTime(newBookingStart) || '-',
|
newBookingEnd: formatTime(newBookingEnd),
|
||||||
newBookingEnd: formatTime(newBookingEnd) || '-',
|
|
||||||
oldBookingStartRaw: oldBookingStart,
|
oldBookingStartRaw: oldBookingStart,
|
||||||
oldBookingEndRaw: oldBookingEnd,
|
oldBookingEndRaw: oldBookingEnd,
|
||||||
newBookingStartRaw: newBookingStart,
|
newBookingStartRaw: newBookingStart,
|
||||||
@@ -338,7 +311,7 @@ const getAllIncidents = (dateRange, memberIds) => {
|
|||||||
incidentType,
|
incidentType,
|
||||||
totalChargeFee: chargeFee,
|
totalChargeFee: chargeFee,
|
||||||
deleted,
|
deleted,
|
||||||
incidentTimestamp: formatTime(createdAt) || '-',
|
incidentTimestamp: formatTime(createdAt),
|
||||||
incidentTimestampRaw: createdAt,
|
incidentTimestampRaw: createdAt,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -359,12 +332,12 @@ const getMemberPracticeSummaryReport = (year) => {
|
|||||||
endDate,
|
endDate,
|
||||||
};
|
};
|
||||||
|
|
||||||
const asyncJobs = [getAllBookingsForMembersInDateRange(dateRange), fetchAllMembers()];
|
const asyncJobs = [checkBookingChanges(), getAllBookingsForMembersInDateRange(dateRange), fetchAllMembers()];
|
||||||
|
|
||||||
Promise.all(asyncJobs)
|
Promise.all(asyncJobs)
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
const allBookings = results[0];
|
const allBookings = results[1];
|
||||||
const allMembers = results[1];
|
const allMembers = results[2];
|
||||||
|
|
||||||
const membersMap = {};
|
const membersMap = {};
|
||||||
|
|
||||||
@@ -413,7 +386,6 @@ const getMemberPracticeSummaryReport = (year) => {
|
|||||||
|
|
||||||
getChargedCanceledReservations(reservationIdsForAdditionalData)
|
getChargedCanceledReservations(reservationIdsForAdditionalData)
|
||||||
.then((incidents) => {
|
.then((incidents) => {
|
||||||
console.log('Charged canceled reservations ...');
|
|
||||||
incidents.forEach((incident) => {
|
incidents.forEach((incident) => {
|
||||||
const {memberId, oldBookingStart, oldBookingEnd} = incident.get();
|
const {memberId, oldBookingStart, oldBookingEnd} = incident.get();
|
||||||
|
|
||||||
@@ -531,29 +503,15 @@ const getMemberPracticeSummaryReport = (year) => {
|
|||||||
const inactiveMemberIdsList = [];
|
const inactiveMemberIdsList = [];
|
||||||
|
|
||||||
memberIdsListFromReportMap.forEach((memberId) => {
|
memberIdsListFromReportMap.forEach((memberId) => {
|
||||||
if (memberId){
|
if (membersMap[memberId].active){
|
||||||
if (membersMap[memberId] && membersMap[memberId].active){
|
activeMemberIdsList.push(memberId);
|
||||||
activeMemberIdsList.push(memberId);
|
|
||||||
}else{
|
|
||||||
console.log('[Get Member Practice Summary Report] Unknown member ');
|
|
||||||
console.log('\tmemberId : ', memberId);
|
|
||||||
console.log('\tmembersMap[memberId] : ', membersMap[memberId]);
|
|
||||||
inactiveMemberIdsList.push(memberId);
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
console.log('[Get Member Practice Summary Report] memberId is wrong : ', memberId);
|
inactiveMemberIdsList.push(memberId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const sortMemberIdsListByName = (memberId1, memberId2) => {
|
const sortMemberIdsListByName = (memberId1, memberId2) => {
|
||||||
const name1 = membersMap[memberId1] ? membersMap[memberId1].name || 'Unknown member' : null;
|
if (membersMap[memberId1].name > membersMap[memberId2].name){
|
||||||
const name2 = membersMap[memberId2] ? membersMap[memberId2].name || 'Unknown member' : null;
|
|
||||||
|
|
||||||
if (!name1 || !name2){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name1 > name2){
|
|
||||||
return 1;
|
return 1;
|
||||||
}else{
|
}else{
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const moment = require('moment-timezone');
|
|||||||
const Op = require('sequelize').Op;
|
const Op = require('sequelize').Op;
|
||||||
|
|
||||||
const { API } = require('../../helpers/api');
|
const { API } = require('../../helpers/api');
|
||||||
const { officeRnDAPIErrors, MAX_BACK_TO_BACK_DIFFERENCE, UI_TIMEZONE } = require('../../constants/constants');
|
const { officeRnDAPIErrors, MAX_BACK_TO_BACK_DIFFERENCE } = require('../../constants/constants');
|
||||||
|
|
||||||
const fetchAllBookings = () => {
|
const fetchAllBookings = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -14,136 +14,24 @@ const fetchAllBookings = () => {
|
|||||||
const cleanedBookingReservations = [];
|
const cleanedBookingReservations = [];
|
||||||
const bookingData = result && result.data ? result.data : [];
|
const bookingData = result && result.data ? result.data : [];
|
||||||
|
|
||||||
const bookingsToCreate = [];
|
bookingData.forEach((fullBookingEntry) => {
|
||||||
const bookingIdsToRemove = [];
|
const fees = fullBookingEntry && fullBookingEntry.fees ? fullBookingEntry.fees : [];
|
||||||
|
const firstFee = fees.length > 0 && fees[0].fee ? fees[0].fee : undefined;
|
||||||
|
const hourlyRate = firstFee && firstFee.price ? firstFee.price : 0;
|
||||||
|
|
||||||
bookingData.forEach(fullBookingEntry => {
|
cleanedBookingReservations.push({
|
||||||
if (!fullBookingEntry){
|
reservationId: fullBookingEntry['_id'],
|
||||||
return;
|
memberId: fullBookingEntry.member,
|
||||||
}
|
officeId: fullBookingEntry.office,
|
||||||
const fees = fullBookingEntry.fees ? fullBookingEntry.fees : [];
|
resourceId: fullBookingEntry.resourceId,
|
||||||
const canceled = fullBookingEntry.canceled ? fullBookingEntry.canceled : false;
|
start: fullBookingEntry.start.dateTime,
|
||||||
const recurringReservation = fullBookingEntry.recurrence && fullBookingEntry.recurrence.rrule ?
|
end: fullBookingEntry.end.dateTime,
|
||||||
fullBookingEntry.recurrence.rrule : null;
|
timezone: fullBookingEntry.timezone,
|
||||||
const tentative = fullBookingEntry.tentative ? fullBookingEntry.tentative : false;
|
canceled: fullBookingEntry.canceled || false,
|
||||||
const free = fullBookingEntry.free ? fullBookingEntry.free : false;
|
hourlyRate,
|
||||||
|
|
||||||
//Special case, canceled recurring reservation
|
|
||||||
//It has empty fees array (fees.length = 0) and no "canceled" field
|
|
||||||
//Normally, canceled reservation has canceled field
|
|
||||||
//Also, it has rrule !== null
|
|
||||||
//If it is tentative, it will have tentative = true, skip those (do not delete)
|
|
||||||
//If it is free, it will have free = true, skip those (do not delete)
|
|
||||||
if (fees.length === 0 && !canceled && recurringReservation && !tentative && !free){
|
|
||||||
bookingIdsToRemove.push(fullBookingEntry['_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fees.length > 1){
|
|
||||||
// Recurring booking, let's create new booking
|
|
||||||
const member = fullBookingEntry.member ? fullBookingEntry.member : null;
|
|
||||||
const office = fullBookingEntry.office ? fullBookingEntry.office : null;
|
|
||||||
const resourceId = fullBookingEntry.resourceId ? fullBookingEntry.resourceId : null;
|
|
||||||
const team = fullBookingEntry.team ? fullBookingEntry.team : null;
|
|
||||||
const organization = fullBookingEntry.organization ? fullBookingEntry.organization : null;
|
|
||||||
const plan = fullBookingEntry.plan ? fullBookingEntry.plan : null;
|
|
||||||
const timezone = fullBookingEntry.timezone ? fullBookingEntry.timezone : UI_TIMEZONE;
|
|
||||||
const source = 'admin';
|
|
||||||
|
|
||||||
const startMoment = fullBookingEntry && fullBookingEntry.start && fullBookingEntry.start.dateTime ?
|
|
||||||
moment.utc(fullBookingEntry.start.dateTime) : null;
|
|
||||||
const endMoment = fullBookingEntry && fullBookingEntry.end && fullBookingEntry.end.dateTime ?
|
|
||||||
moment.utc(fullBookingEntry.end.dateTime) : null;
|
|
||||||
|
|
||||||
fees.forEach(fee => {
|
|
||||||
const dateMoment = fee.date ? moment.utc(fee.date) : null;
|
|
||||||
|
|
||||||
if (startMoment && endMoment && dateMoment){
|
|
||||||
const yearPart = dateMoment.year();
|
|
||||||
const monthPart = dateMoment.month();
|
|
||||||
const dayPart = dateMoment.date();
|
|
||||||
|
|
||||||
const newStartMoment = startMoment.clone().tz(fullBookingEntry.timezone).year(yearPart).month(monthPart).date(dayPart);
|
|
||||||
const newEndMoment = endMoment.clone().tz(fullBookingEntry.timezone).year(yearPart).month(monthPart).date(dayPart);
|
|
||||||
|
|
||||||
bookingsToCreate.push({
|
|
||||||
start: {
|
|
||||||
dateTime: newStartMoment.toISOString()
|
|
||||||
},
|
|
||||||
end: {
|
|
||||||
dateTime: newEndMoment.toISOString()
|
|
||||||
},
|
|
||||||
team,
|
|
||||||
member,
|
|
||||||
resourceId,
|
|
||||||
office,
|
|
||||||
source,
|
|
||||||
timezone,
|
|
||||||
organization,
|
|
||||||
plan
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
bookingIdsToRemove.push(fullBookingEntry['_id']);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Here we now have possible bookings to create and then load again "check Booking changes"
|
|
||||||
|
|
||||||
if (bookingIdsToRemove.length > 0){
|
|
||||||
//First delete, wait until operation is done, than create bookings (to avoid conflicting date/time)
|
|
||||||
API.delete('bookings/?silent', { data: bookingIdsToRemove })
|
|
||||||
.then(() => {
|
|
||||||
//Now, insert new bookings
|
|
||||||
API.post('bookings/?silent', bookingsToCreate)
|
|
||||||
.then(() => {
|
|
||||||
//And fetch again all bookings
|
|
||||||
resolve(fetchAllBookings());
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(officeRnDAPIErrors.FAILED_TO_CREATE_BOOKINGS);
|
|
||||||
console.log('Details : ', error);
|
|
||||||
reject(officeRnDAPIErrors.FAILED_TO_CREATE_BOOKINGS);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(officeRnDAPIErrors.FAILED_TO_DELETE_BOOKINGS);
|
|
||||||
console.log('Details : ', error);
|
|
||||||
reject(officeRnDAPIErrors.FAILED_TO_DELETE_BOOKINGS);
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
bookingData.forEach((fullBookingEntry) => {
|
|
||||||
const fees = fullBookingEntry && fullBookingEntry.fees ? fullBookingEntry.fees : [];
|
|
||||||
const firstFee = fees.length > 0 && fees[0].fee ? fees[0].fee : undefined;
|
|
||||||
const hourlyRate = firstFee && firstFee.price ? firstFee.price : 0;
|
|
||||||
const free = fullBookingEntry.free ? fullBookingEntry.free : false;
|
|
||||||
const tentative = fullBookingEntry.tentative ? fullBookingEntry.tentative : false;
|
|
||||||
|
|
||||||
const startMoment = fullBookingEntry && fullBookingEntry.start && fullBookingEntry.start.dateTime ?
|
|
||||||
moment.utc(fullBookingEntry.start.dateTime) : null;
|
|
||||||
const endMoment = fullBookingEntry && fullBookingEntry.end && fullBookingEntry.end.dateTime ?
|
|
||||||
moment.utc(fullBookingEntry.end.dateTime) : null;
|
|
||||||
|
|
||||||
// console.log('\r\n\r\nStart : ', startMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', startMoment.toISOString(),']');
|
|
||||||
// console.log('End : ', endMoment.clone().tz(fullBookingEntry.timezone).format('DD.MM. HH:mm'), '[', endMoment.toISOString(), ']');
|
|
||||||
// console.log('Fees : ');
|
|
||||||
|
|
||||||
if (startMoment && endMoment && !free && !tentative){
|
|
||||||
cleanedBookingReservations.push({
|
|
||||||
reservationId: fullBookingEntry['_id'],
|
|
||||||
memberId: fullBookingEntry.member,
|
|
||||||
officeId: fullBookingEntry.office,
|
|
||||||
resourceId: fullBookingEntry.resourceId,
|
|
||||||
start: startMoment.toISOString(),
|
|
||||||
end: endMoment.toISOString(),
|
|
||||||
timezone: fullBookingEntry.timezone,
|
|
||||||
canceled: fullBookingEntry.canceled || false,
|
|
||||||
hourlyRate,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
resolve(cleanedBookingReservations);
|
});
|
||||||
}
|
resolve(cleanedBookingReservations);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(officeRnDAPIErrors.FAILED_TO_FETCH_BOOKINGS);
|
console.log(officeRnDAPIErrors.FAILED_TO_FETCH_BOOKINGS);
|
||||||
@@ -261,32 +149,6 @@ const getFirstReservationInBlock = (reservation) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLastReservationInBlock = async (reservation) => {
|
|
||||||
const { resourceId, memberId, end } = reservation;
|
|
||||||
|
|
||||||
const toTimestamp = moment.utc(end).add(MAX_BACK_TO_BACK_DIFFERENCE).toISOString();
|
|
||||||
const fromTimestamp = end;
|
|
||||||
|
|
||||||
const filters = {
|
|
||||||
resourceId,
|
|
||||||
memberId,
|
|
||||||
start: {
|
|
||||||
[Op.and]: [
|
|
||||||
{[Op.gte]: fromTimestamp},
|
|
||||||
{[Op.lte]: toTimestamp}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const nextReservation = await db.bookingReservation.findOne({where: filters});
|
|
||||||
if (!nextReservation) {
|
|
||||||
return reservation;
|
|
||||||
} else {
|
|
||||||
return getLastReservationInBlock(nextReservation);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
const writeBookingReservation = (bookingReservation) => {
|
const writeBookingReservation = (bookingReservation) => {
|
||||||
const { reservationId, memberId, officeId, resourceId, start, end, timezone, canceled, hourlyRate } = bookingReservation;
|
const { reservationId, memberId, officeId, resourceId, start, end, timezone, canceled, hourlyRate } = bookingReservation;
|
||||||
const bookingReservationForDB = {
|
const bookingReservationForDB = {
|
||||||
@@ -331,15 +193,7 @@ const bulkWriteReservationsWithChangesTracking = (reservations, resourcesMap) =>
|
|||||||
if (parseFloat(instance.previous('hourlyRate') > 0)) {
|
if (parseFloat(instance.previous('hourlyRate') > 0)) {
|
||||||
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
||||||
}else{
|
}else{
|
||||||
//Determine if we should apply weekend price or work day price
|
const hourlyRate = resourceId ? resourcesMap[resourceId].price : 0;
|
||||||
const newStartWeekDay = moment.utc(instance.start).isoWeekday();
|
|
||||||
const isWeekend = newStartWeekDay > 5; //6 - Saturday, 7 - Sunday
|
|
||||||
let hourlyRate;
|
|
||||||
if (isWeekend){
|
|
||||||
hourlyRate = resourceId ? resourcesMap[resourceId].price.weekendPrice : 0;
|
|
||||||
}else{
|
|
||||||
hourlyRate = resourceId ? resourcesMap[resourceId].price.price : 0;
|
|
||||||
}
|
|
||||||
instance.setDataValue('hourlyRate', hourlyRate);
|
instance.setDataValue('hourlyRate', hourlyRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,6 +266,5 @@ module.exports = {
|
|||||||
getFirstNextBooking,
|
getFirstNextBooking,
|
||||||
getFirstPreviousBooking,
|
getFirstPreviousBooking,
|
||||||
getFirstReservationInBlock,
|
getFirstReservationInBlock,
|
||||||
getLastReservationInBlock,
|
|
||||||
bulkWriteReservationsWithChangesTracking,
|
bulkWriteReservationsWithChangesTracking,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,14 @@
|
|||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
|
|
||||||
const { API } = require('../../helpers/api');
|
const { API } = require('../../helpers/api');
|
||||||
const { officeRnDAPIErrors, DEFAULT_DATE_FORMAT, UNPAID_FEE_STATUS, CUSTOM_FEES_PREFIXES } = require('../../constants/constants');
|
const {
|
||||||
|
officeRnDAPIErrors,
|
||||||
|
DEFAULT_DATE_FORMAT,
|
||||||
|
UNPAID_FEE_STATUS,
|
||||||
|
CUSTOM_FEES_PREFIXES,
|
||||||
|
MAX_FEES_TO_DELETE,
|
||||||
|
FEES_DELETE_DELAY,
|
||||||
|
} = require('../../constants/constants');
|
||||||
|
|
||||||
const deleteFeesFromORD = (dateRange, memberIds) => {
|
const deleteFeesFromORD = (dateRange, memberIds) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -22,14 +29,9 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
|
|||||||
const fetchedFees = feesResponse.data ? feesResponse.data : [];
|
const fetchedFees = feesResponse.data ? feesResponse.data : [];
|
||||||
const fetchedPlans = plansResponse.data ? plansResponse.data : [];
|
const fetchedPlans = plansResponse.data ? plansResponse.data : [];
|
||||||
|
|
||||||
const planIsRateMap = {};
|
|
||||||
|
|
||||||
const manualFeeNames = [];
|
const manualFeeNames = [];
|
||||||
fetchedPlans.forEach((plan) => {
|
fetchedPlans.forEach((plan) => {
|
||||||
const { name, _id, isRate } = plan;
|
const { name } = plan;
|
||||||
|
|
||||||
planIsRateMap[_id] = !!isRate;
|
|
||||||
|
|
||||||
if (name && name.length > 0){
|
if (name && name.length > 0){
|
||||||
manualFeeNames.push(name);
|
manualFeeNames.push(name);
|
||||||
}
|
}
|
||||||
@@ -45,24 +47,18 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
|
|||||||
const feeIdsToRemove = [];
|
const feeIdsToRemove = [];
|
||||||
|
|
||||||
fetchedFees.forEach((fee) => {
|
fetchedFees.forEach((fee) => {
|
||||||
const { member, date, invoice, name, plan } = fee;
|
const { member, date, invoice, name } = fee;
|
||||||
const { status } = invoice;
|
const { status } = invoice;
|
||||||
const feeId = fee['_id'];
|
const feeId = fee['_id'];
|
||||||
const feePlanIsRate = plan ? planIsRateMap[plan] : null;
|
|
||||||
|
|
||||||
const isDateInDateRange = startDate.isSameOrBefore(date) && endDate.isSameOrAfter(date);
|
const isDateInDateRange = startDate.isSameOrBefore(date) && endDate.isSameOrAfter(date);
|
||||||
let manuallyAddedFee = false;
|
let manuallyAddedFee = false;
|
||||||
|
if (manualFeeNames.indexOf(name) === -1){
|
||||||
if (plan && !feePlanIsRate){
|
if (name && name[0] && CUSTOM_FEES_PREFIXES.indexOf(name[0]) !== -1){
|
||||||
manuallyAddedFee = true;
|
|
||||||
}else{
|
|
||||||
if (manualFeeNames.indexOf(name) === -1){
|
|
||||||
if (name && name[0] && CUSTOM_FEES_PREFIXES.indexOf(name[0]) !== -1){
|
|
||||||
manuallyAddedFee = true;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
manuallyAddedFee = true;
|
manuallyAddedFee = true;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
manuallyAddedFee = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberFeesShouldBeDeleted = filterByMemberIds ? memberIdsMap[member] : true;
|
const memberFeesShouldBeDeleted = filterByMemberIds ? memberIdsMap[member] : true;
|
||||||
@@ -74,14 +70,28 @@ const deleteFeesFromORD = (dateRange, memberIds) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
API.delete('fees/?silent', { data: feeIdsToRemove })
|
const asyncDeleteCalls = [];
|
||||||
|
|
||||||
|
let i,j;
|
||||||
|
for (i=0, j=feeIdsToRemove; i<j; i+= MAX_FEES_TO_DELETE){
|
||||||
|
const feesSubset = feeIdsToRemove.slice(i, i+MAX_FEES_TO_DELETE);
|
||||||
|
const deleteFeesPromise = API.delete('fees', { data: feesSubset }).then(() => resolve(true)).catch((error) => {
|
||||||
|
console.log('[Delete Fees From ORD] Error deleting fees from ORD : ', error);
|
||||||
|
reject(officeRnDAPIErrors.FAILED_TO_DELETE_FEES);
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncDeleteCalls.push(deleteFeesPromise);
|
||||||
|
//sleep for FEES_DELETE_DELAY ms
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all(asyncDeleteCalls)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(feesToSkip);
|
resolve(feesToSkip);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('[Delete Fees From ORD] Error deleting fees from ORD : ', error);
|
reject(error);
|
||||||
reject(officeRnDAPIErrors.FAILED_TO_DELETE_FEES);
|
})
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("[Delete Fees From ORD] Error fetching fees and plans from ORD : ", error);
|
console.log("[Delete Fees From ORD] Error fetching fees and plans from ORD : ", error);
|
||||||
|
|||||||
@@ -9,17 +9,9 @@ const fetchRates = () => {
|
|||||||
const rates = result.data || [];
|
const rates = result.data || [];
|
||||||
const cleanedRates = [];
|
const cleanedRates = [];
|
||||||
rates.forEach(rate => {
|
rates.forEach(rate => {
|
||||||
const additionalRates = rate.rates;
|
|
||||||
let weekendRate = rate.price; //fallback price
|
|
||||||
additionalRates.forEach(additionalRate => {
|
|
||||||
if (additionalRate.isWeekendRate){
|
|
||||||
weekendRate = additionalRate.price;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cleanedRates.push({
|
cleanedRates.push({
|
||||||
rateId: rate['_id'],
|
rateId: rate['_id'],
|
||||||
price: rate.price,
|
price: rate.price,
|
||||||
weekendPrice: weekendRate
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
resolve(cleanedRates);
|
resolve(cleanedRates);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ const fetchOffices = () => {
|
|||||||
cleanedOffices.push({
|
cleanedOffices.push({
|
||||||
officeId: office['_id'],
|
officeId: office['_id'],
|
||||||
officeName: office.name,
|
officeName: office.name,
|
||||||
officeSlug: office.description,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
resolve(cleanedOffices);
|
resolve(cleanedOffices);
|
||||||
|
|||||||
Reference in New Issue
Block a user