From 3a10e56eeb8345b211670f4ab42b6f570deef512 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 6 Jan 2020 22:33:26 +0100 Subject: [PATCH 1/8] wait for door lock charges calculation --- routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index e35c18d..bd3c65e 100644 --- a/routes/index.js +++ b/routes/index.js @@ -44,6 +44,6 @@ router.get('/integration/report/practiceSummary/:year', getPracticeSummaryReport // temporary route, manually trigger door lock charge calculations -router.get('/calculate', (req, res) => { calculateDoorLockCharges(); res.send();}); +router.get('/calculate', (req, res) => { calculateDoorLockCharges().then(() => res.send('Done')).catch((err) => res.send('Error \r\n', err));}); module.exports = router; -- 2.47.3 From c78a0e4138caecbbddd53af151184307b333d71a Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Wed, 8 Jan 2020 19:09:35 +0100 Subject: [PATCH 2/8] allow fees edit; track changes; focus last changed input field --- .../components/SingleIncidentsTable.js | 108 ++++++++++++++++-- .../components/style.css | 5 + 2 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 client/src/components/MemberIncidentsTables/components/style.css diff --git a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js index c4c2221..b4f1cb6 100644 --- a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js +++ b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Loader, Button } from 'semantic-ui-react'; import 'react-table/react-table.css'; +import './style.css'; import { NavLink } from 'react-router-dom'; import SelectTable from "../../SelectTable"; @@ -12,7 +13,8 @@ import { incidentDescriptions, incidentLevelDescriptions, UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION, UNLOCKED_INCIDENT_STANDALONE, UNSCHEDULED_INCIDENT_AFTER_RESERVATION, - UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE + UNSCHEDULED_INCIDENT_BEFORE_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE, BOOKING_CANCELED_LATE, BOOKING_MOVED_TO_ANOTHER_DAY, + BOOKING_SHORTENED } from '../../../constants/enums'; import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants'; import { deleteIncidents } from "../../../store/actions"; @@ -21,7 +23,11 @@ class SingleIncidentsTable extends Component { state = { selectedUnlockedIncidentIds: [], selectedUnscheduledIncidentIds: [], - selectedBookingChangeIncidentIds: [] + selectedBookingChangeIncidentIds: [], + changedUnlockedIncidentIds: {}, + changedUnscheduledIncidentIds: {}, + changedBookingChangeIncidentIds: {}, + inputIdToFocus: null, }; onSelectChange = (selectedIncidents) => { @@ -94,12 +100,33 @@ class SingleIncidentsTable extends Component { const { selectedUnlockedIncidentIds, selectedUnscheduledIncidentIds, - selectedBookingChangeIncidentIds + selectedBookingChangeIncidentIds, + changedUnlockedIncidentIds, + changedUnscheduledIncidentIds, + changedBookingChangeIncidentIds, + inputIdToFocus } = this.state; + const changedIncidentsProxy = { + [UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION]: changedUnlockedIncidentIds, + [UNLOCKED_INCIDENT_STANDALONE]: changedUnlockedIncidentIds, + [UNSCHEDULED_INCIDENT_BEFORE_RESERVATION]: changedUnscheduledIncidentIds, + [UNSCHEDULED_INCIDENT_AFTER_RESERVATION]: changedUnscheduledIncidentIds, + [UNSCHEDULED_INCIDENT_STANDALONE]: changedUnscheduledIncidentIds, + [BOOKING_SHORTENED]: changedBookingChangeIncidentIds, + [BOOKING_MOVED_TO_ANOTHER_DAY]: changedBookingChangeIncidentIds, + [BOOKING_CANCELED_LATE]: changedBookingChangeIncidentIds + }; + 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}`; @@ -122,6 +149,44 @@ class SingleIncidentsTable extends Component { 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)) && 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]; @@ -143,6 +208,10 @@ class SingleIncidentsTable extends Component { 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': @@ -198,8 +267,18 @@ class SingleIncidentsTable extends Component { } break; case 'totalChargeFee': - const totalFee = (props.row['_original'].incidentPrice || props.value) || 0; + clickablePrice = true; + let totalFee = 0; + const changedFee = changedIncidentsProxy[props.row['_original'].incidentType][props.row['_original'].incidentId]; + if (changedFee || (changedFee === 0)){ + totalFee = changedFee; + priceFontColor = 'red'; + }else{ + totalFee = (props.row['_original'].incidentPrice || props.value) || 0; + } const totalFeeFormatted = parseFloat(totalFee).toFixed(2); + priceAsNumber = totalFee; + priceInputID = `${props.row['_original'].incidentType || ''}-${props.row['_original'].incidentId || ''}`; cellValue = `$ ${totalFeeFormatted}`; columnContentsAlignment = columnAlignments.right; break; @@ -217,10 +296,22 @@ class SingleIncidentsTable extends Component { cellValue = props.value; } - if (openMemberSummaryOnMemberClick && urlValue){ - return {cellValue} + if (clickablePrice){ + return

$ +

}else{ - return
{cellValue}
+ if (openMemberSummaryOnMemberClick && urlValue){ + return {cellValue} + }else{ + return
{cellValue}
+ } } } }); @@ -235,6 +326,9 @@ class SingleIncidentsTable extends Component { { } + { + + }

{ !loading && incidents && diff --git a/client/src/components/MemberIncidentsTables/components/style.css b/client/src/components/MemberIncidentsTables/components/style.css new file mode 100644 index 0000000..4ee6e76 --- /dev/null +++ b/client/src/components/MemberIncidentsTables/components/style.css @@ -0,0 +1,5 @@ +::placeholder{ + color: black; + opacity: 1; +} + -- 2.47.3 From ff8a836fed8ea5d9bad443f832f8bc5f10968ec6 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 9 Jan 2020 01:29:06 +0100 Subject: [PATCH 3/8] add action for sending update data to backend --- .../components/SingleIncidentsTable.js | 25 ++++++++++++++++--- .../src/store/actions/integrationActions.js | 15 +++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js index b4f1cb6..1324972 100644 --- a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js +++ b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js @@ -17,7 +17,7 @@ import { BOOKING_SHORTENED } from '../../../constants/enums'; import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants'; -import { deleteIncidents } from "../../../store/actions"; +import { deleteIncidents, updateIncidentFees } from "../../../store/actions"; class SingleIncidentsTable extends Component { state = { @@ -88,6 +88,24 @@ class SingleIncidentsTable extends Component { }); }; + updateChangedFees = () => { + const { dateRange, updateIncidentsById, memberId } = this.props; + const { changedUnlockedIncidentIds, changedUnscheduledIncidentIds, changedBookingChangeIncidentIds } = this.state; + + const incidentFeesToUpdate = { + unlockedIncidentFees: changedUnlockedIncidentIds, + unscheduledIncidentFees: changedUnscheduledIncidentIds, + bookingChangeIncidentFees: changedBookingChangeIncidentIds + }; + + updateIncidentsById(dateRange, incidentFeesToUpdate, memberId); + this.setState({ + changedUnlockedIncidentIds: {}, + changedUnscheduledIncidentIds: {}, + changedBookingChangeIncidentIds: {} + }); + }; + render(){ const { loading, @@ -327,7 +345,7 @@ class SingleIncidentsTable extends Component { } { - + }

{ @@ -346,7 +364,8 @@ class SingleIncidentsTable extends Component { } const mapDispatchToProps = (dispatch) => ({ - deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId}) + deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId}), + updateIncidentsById: (dateRange, updatedIncidentsData, memberId) => updateIncidentFees(dispatch, {dateRange, updatedIncidentsData, memberId}) }); export default connect(null, mapDispatchToProps)(SingleIncidentsTable); diff --git a/client/src/store/actions/integrationActions.js b/client/src/store/actions/integrationActions.js index f285e29..f5320cb 100644 --- a/client/src/store/actions/integrationActions.js +++ b/client/src/store/actions/integrationActions.js @@ -103,6 +103,21 @@ export const deleteIncidents = (dispatch, deleteData) => { }); }; +export const updateIncidentFees = (dispatch, updateData) => { + const pendingAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_PENDING : FETCH_INCIDENTS_PENDING; + const successAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_SUCCESS : FETCH_INCIDENTS_SUCCESS; + const failedAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_FAILED : FETCH_INCIDENTS_FAILED; + + dispatch({type: pendingAction}); + API.patch(`/integration/fees`, updateData) + .then(response => { + dispatch({type: successAction, payload: response.data}); + }) + .catch(error => { + dispatch({type: failedAction, payload: error.response}); + }); +}; + export const fetchMembersList = (dispatch) => { dispatch({type: FETCH_MEMBERS_PENDING}); API.get('officeRnD/membersList') -- 2.47.3 From 1a21e91796916dbef5ac225be210e0dec6e02efe Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 9 Jan 2020 01:33:19 +0100 Subject: [PATCH 4/8] implement backend methods to update incident fees --- controllers/integration.js | 65 ++++++++++++++++++-- routes/index.js | 4 +- services/integration/bookingChangeCharges.js | 19 +++++- services/integration/doorLockCharges.js | 40 +++++++++++- 4 files changed, 120 insertions(+), 8 deletions(-) diff --git a/controllers/integration.js b/controllers/integration.js index e9c2d8b..2c538aa 100644 --- a/controllers/integration.js +++ b/controllers/integration.js @@ -2,15 +2,25 @@ const moment = require('moment-timezone'); -const { getMappingsFromDatabase, fetchOffices, fetchResources, saveNewMappingToDatabase, deleteMappingById, updateMappingById } = require('../services/officeRnD/resources'); +const { + getMappingsFromDatabase, + fetchOffices, + fetchResources, + saveNewMappingToDatabase, + deleteMappingById, + updateMappingById } = require('../services/officeRnD/resources'); const { getAllIncidents, getMemberPracticeSummaryReport } = require('../services/integration/reports'); const { getMembersFeesForDateRange } = require('../services/integration/invoiceIntegration'); const { deleteFeesFromORD, addFeesToORD } = require('../services/officeRnD/fees'); const { reformatMembershipsName } = require('../services/officeRnD/memberships'); const { checkBookingChanges } = require('../services/integration/checkBookingChange'); const { checkIfProcessing } = require('../services/integration/processingStatus'); -const { deleteUnlockedIncidentsById, deleteUnscheduledIncidentsById } = require('../services/integration/doorLockCharges'); -const { deleteBookingChangeIncidentsById } = require('../services/integration/bookingChangeCharges'); +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'); @@ -177,7 +187,7 @@ const addFees = (req, res) => { } }; -const deleteFees= (req, res) => { +const deleteFees = (req, res) => { const deleteData = req.body; const dateRange = deleteData.dateRange ? deleteData.dateRange : null; const incidents = deleteData.incidentsToDelete ? deleteData.incidentsToDelete : null; @@ -220,6 +230,50 @@ const deleteFees= (req, res) => { } }; +const updateFees = (req, res) => { + const updateData = req.body; + console.log(updateData); + 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) => { checkIfProcessing() .then((processing) => { @@ -272,5 +326,6 @@ module.exports = { addFees, checkProcessingStatus, getPracticeSummaryReport, - deleteFees + deleteFees, + updateFees }; diff --git a/routes/index.js b/routes/index.js index bd3c65e..699bcde 100644 --- a/routes/index.js +++ b/routes/index.js @@ -13,7 +13,8 @@ const { addFees, checkProcessingStatus, getPracticeSummaryReport, - deleteFees + deleteFees, + updateFees } = require('../controllers/integration'); const { calculateDoorLockCharges } = require('../services/integration/doorLockCharges'); @@ -36,6 +37,7 @@ router.get('/officeRnD/membersList', fetchMembersList); router.post('/integration/addFees', addFees); router.delete('/integration/fees', deleteFees); +router.patch('/integration/fees', updateFees); router.get('/integration/processing', checkProcessingStatus); diff --git a/services/integration/bookingChangeCharges.js b/services/integration/bookingChangeCharges.js index 1f6f2ba..9d760bd 100644 --- a/services/integration/bookingChangeCharges.js +++ b/services/integration/bookingChangeCharges.js @@ -283,6 +283,22 @@ const deleteBookingChangeIncidentsById = (incidentIds) => { return db.bookingChangeIncident.update({deleted: true},{where: filters}); }; +const updateBookingChangeIncidentsById = (incidentFees) => { + const incidentIds = Object.keys(incidentFees); + + const asyncUpdateActions = []; + + incidentIds.forEach((incidentId) => { + const newFeeCharge = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null; + + if (newFeeCharge || (newFeeCharge === 0)){ + asyncUpdateActions.push(db.bookingChangeIncident.update({chargeFee: newFeeCharge}, {where: {id: incidentId}})); + } + }); + + return Promise.all(asyncUpdateActions); +}; + module.exports = { getChargedCanceledReservations, getIncidentsFromChanges, @@ -290,5 +306,6 @@ module.exports = { getShorteningIncidentsForReservationId, getReservationsIncidentsForRemoval, deleteBookingChangeIncidents, - deleteBookingChangeIncidentsById + deleteBookingChangeIncidentsById, + updateBookingChangeIncidentsById }; diff --git a/services/integration/doorLockCharges.js b/services/integration/doorLockCharges.js index d331a37..a506b27 100644 --- a/services/integration/doorLockCharges.js +++ b/services/integration/doorLockCharges.js @@ -80,6 +80,26 @@ const deleteUnscheduledIncidentsById = (incidentIds) => { return db.unscheduledIncident.update({deleted: true},{where: filters}); }; +const updateUnscheduledIncidentsById = (incidentFees) => { + const incidentIds = Object.keys(incidentFees); + + const asyncUpdateActions = []; + + incidentIds.forEach((incidentId) => { + const newFeeCharge = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null; + + 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 asyncJobs = []; incidents.forEach((incident) => { @@ -124,6 +144,22 @@ const deleteUnlockedIncidentsById = (incidentIds) => { return db.unlockedIncident.update({deleted: true},{where: filters}); }; +const updateUnlockedIncidentsById = (incidentFees) => { + const incidentIds = Object.keys(incidentFees); + + const asyncUpdateActions = []; + + incidentIds.forEach((incidentId) => { + const newFeeCharge = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null; + + if (newFeeCharge || (newFeeCharge === 0)){ + asyncUpdateActions.push(db.unlockedIncident.update({incidentLevelPrice: newFeeCharge}, {where: {id: incidentId}})); + } + }); + + return Promise.all(asyncUpdateActions); +}; + const setUnlockedIncidentsLevel = (incidents) => { return new Promise ((resolve, reject) => { const sortingFunction = (incidentA, incidentB) => { @@ -850,5 +886,7 @@ const calculateDoorLockCharges = () => { module.exports = { calculateDoorLockCharges, deleteUnlockedIncidentsById, - deleteUnscheduledIncidentsById + deleteUnscheduledIncidentsById, + updateUnlockedIncidentsById, + updateUnscheduledIncidentsById }; -- 2.47.3 From aafd046063cfd8c1b4418d2915548abd03c668b4 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 9 Jan 2020 02:26:35 +0100 Subject: [PATCH 5/8] show rounded decimals for default values; handle zero as normal input --- .../components/SingleIncidentsTable.js | 6 +++--- services/integration/bookingChangeCharges.js | 2 +- services/integration/doorLockCharges.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js index 1324972..d15dee2 100644 --- a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js +++ b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js @@ -292,12 +292,12 @@ class SingleIncidentsTable extends Component { totalFee = changedFee; priceFontColor = 'red'; }else{ - totalFee = (props.row['_original'].incidentPrice || props.value) || 0; + totalFee = parseFloat((props.row['_original'].incidentPrice || props.value) || 0).toFixed(2); } - const totalFeeFormatted = parseFloat(totalFee).toFixed(2); + // const totalFeeFormatted = parseFloat(totalFee).toFixed(2); priceAsNumber = totalFee; priceInputID = `${props.row['_original'].incidentType || ''}-${props.row['_original'].incidentId || ''}`; - cellValue = `$ ${totalFeeFormatted}`; + // cellValue = `$ ${totalFeeFormatted}`; columnContentsAlignment = columnAlignments.right; break; case 'oldReservation': diff --git a/services/integration/bookingChangeCharges.js b/services/integration/bookingChangeCharges.js index 9d760bd..93e5361 100644 --- a/services/integration/bookingChangeCharges.js +++ b/services/integration/bookingChangeCharges.js @@ -289,7 +289,7 @@ const updateBookingChangeIncidentsById = (incidentFees) => { const asyncUpdateActions = []; incidentIds.forEach((incidentId) => { - const newFeeCharge = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null; + const newFeeCharge = parseFloat(incidentFees[incidentId]); if (newFeeCharge || (newFeeCharge === 0)){ asyncUpdateActions.push(db.bookingChangeIncident.update({chargeFee: newFeeCharge}, {where: {id: incidentId}})); diff --git a/services/integration/doorLockCharges.js b/services/integration/doorLockCharges.js index a506b27..b18d95c 100644 --- a/services/integration/doorLockCharges.js +++ b/services/integration/doorLockCharges.js @@ -86,7 +86,7 @@ const updateUnscheduledIncidentsById = (incidentFees) => { const asyncUpdateActions = []; incidentIds.forEach((incidentId) => { - const newFeeCharge = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null; + const newFeeCharge = parseFloat(incidentFees[incidentId]); if (newFeeCharge || (newFeeCharge === 0)){ asyncUpdateActions.push(db.unscheduledIncident.update({ @@ -150,7 +150,7 @@ const updateUnlockedIncidentsById = (incidentFees) => { const asyncUpdateActions = []; incidentIds.forEach((incidentId) => { - const newFeeCharge = incidentFees[incidentId] ? parseFloat(incidentFees[incidentId]) : null; + const newFeeCharge = parseFloat(incidentFees[incidentId]); if (newFeeCharge || (newFeeCharge === 0)){ asyncUpdateActions.push(db.unlockedIncident.update({incidentLevelPrice: newFeeCharge}, {where: {id: incidentId}})); -- 2.47.3 From a5bec0f7f3b79a98c0dc952be7fe6fee742198f6 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 9 Jan 2020 02:30:22 +0100 Subject: [PATCH 6/8] remove logs on update request --- controllers/integration.js | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/integration.js b/controllers/integration.js index 2c538aa..83c7016 100644 --- a/controllers/integration.js +++ b/controllers/integration.js @@ -232,7 +232,6 @@ const deleteFees = (req, res) => { const updateFees = (req, res) => { const updateData = req.body; - console.log(updateData); const dateRange = updateData.dateRange ? updateData.dateRange : null; const incidents = updateData.updatedIncidentsData ? updateData.updatedIncidentsData : null; const memberId = updateData.memberId ? updateData.memberId : null; -- 2.47.3 From e03bf7609ef0cd1d0a5dbd81336a2f25c7d0956a Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 9 Jan 2020 03:41:16 +0100 Subject: [PATCH 7/8] fix paging bug --- .../components/SingleIncidentsTable.js | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js index d15dee2..f109c51 100644 --- a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js +++ b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js @@ -125,17 +125,6 @@ class SingleIncidentsTable extends Component { inputIdToFocus } = this.state; - const changedIncidentsProxy = { - [UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION]: changedUnlockedIncidentIds, - [UNLOCKED_INCIDENT_STANDALONE]: changedUnlockedIncidentIds, - [UNSCHEDULED_INCIDENT_BEFORE_RESERVATION]: changedUnscheduledIncidentIds, - [UNSCHEDULED_INCIDENT_AFTER_RESERVATION]: changedUnscheduledIncidentIds, - [UNSCHEDULED_INCIDENT_STANDALONE]: changedUnscheduledIncidentIds, - [BOOKING_SHORTENED]: changedBookingChangeIncidentIds, - [BOOKING_MOVED_TO_ANOTHER_DAY]: changedBookingChangeIncidentIds, - [BOOKING_CANCELED_LATE]: changedBookingChangeIncidentIds - }; - const totalSelected = selectedUnlockedIncidentIds.length + selectedUnscheduledIncidentIds.length + selectedBookingChangeIncidentIds.length; const numberOfSelectedText = totalSelected > 0 ? ` (${totalSelected})` : ''; @@ -175,7 +164,7 @@ class SingleIncidentsTable extends Component { const incidentType = parseInt(incidentData[0]) || null; const incidentID = parseInt(incidentData[1]) || null; - if ((newValueFloat || (newValueFloat === 0)) && incidentType && incidentID){ + if ((newValueFloat || (newValueFloat === 0) || (isNaN(newValueFloat))) && incidentType && incidentID){ const changedUnlockedIncidentIdsCopy = Object.assign({}, changedUnlockedIncidentIds); const changedUnscheduledIncidentIdsCopy = Object.assign({}, changedUnscheduledIncidentIds); const changedBookingChangeIncidentIdsCopy = Object.assign({}, changedBookingChangeIncidentIds); @@ -287,11 +276,36 @@ class SingleIncidentsTable extends Component { case 'totalChargeFee': clickablePrice = true; let totalFee = 0; - const changedFee = changedIncidentsProxy[props.row['_original'].incidentType][props.row['_original'].incidentId]; - if (changedFee || (changedFee === 0)){ - totalFee = changedFee; - priceFontColor = 'red'; + + 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); @@ -320,7 +334,7 @@ class SingleIncidentsTable extends Component { style={{ color: priceFontColor }} type={'number'} onChange={priceChangeHandler} - defaultValue={priceAsNumber} + value={priceAsNumber} autoFocus={priceInputID === inputIdToFocus} />

-- 2.47.3 From cf0b2793ece5f90fa42a15fdaa7b566b7f41a62d Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Thu, 9 Jan 2020 03:47:17 +0100 Subject: [PATCH 8/8] remove obsolete stylesheet file --- .../MemberIncidentsTables/components/SingleIncidentsTable.js | 1 - .../components/MemberIncidentsTables/components/style.css | 5 ----- 2 files changed, 6 deletions(-) delete mode 100644 client/src/components/MemberIncidentsTables/components/style.css diff --git a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js index f109c51..26d83a9 100644 --- a/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js +++ b/client/src/components/MemberIncidentsTables/components/SingleIncidentsTable.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Loader, Button } from 'semantic-ui-react'; import 'react-table/react-table.css'; -import './style.css'; import { NavLink } from 'react-router-dom'; import SelectTable from "../../SelectTable"; diff --git a/client/src/components/MemberIncidentsTables/components/style.css b/client/src/components/MemberIncidentsTables/components/style.css deleted file mode 100644 index 4ee6e76..0000000 --- a/client/src/components/MemberIncidentsTables/components/style.css +++ /dev/null @@ -1,5 +0,0 @@ -::placeholder{ - color: black; - opacity: 1; -} - -- 2.47.3