NaN bug fix
This commit is contained in:
@@ -118,7 +118,7 @@ const SingleIncidentsTable = props => {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'totalChargeFee':
|
case 'totalChargeFee':
|
||||||
const totalFee = props.value ? props.value : props.row['_original'].incidentPrice;
|
const totalFee = (props.row['_original'].incidentPrice || props.value) || 0;
|
||||||
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
const totalFeeFormatted = parseFloat(totalFee).toFixed(2);
|
||||||
cellValue = `$ ${totalFeeFormatted}`;
|
cellValue = `$ ${totalFeeFormatted}`;
|
||||||
columnContentsAlignment = columnAlignments.right;
|
columnContentsAlignment = columnAlignments.right;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
|
||||||
|
const { fetchResources } = require('../officeRnD/resources');
|
||||||
|
const { fetchRates } = require('../officeRnD/rates');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getIncidentsFromChanges,
|
getIncidentsFromChanges,
|
||||||
@@ -12,9 +14,27 @@ const { bulkWriteChanges } = require('./bookingChangeLog');
|
|||||||
|
|
||||||
const checkBookingChanges = () => {
|
const checkBookingChanges = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetchAllBookings()
|
const asyncFetchActions = [fetchAllBookings(), fetchResources(), fetchRates()];
|
||||||
.then((reservations) => {
|
Promise.all(asyncFetchActions)
|
||||||
bulkWriteReservationsWithChangesTracking(reservations)
|
.then((asyncData) => {
|
||||||
|
const reservations = asyncData[0];
|
||||||
|
const resources = asyncData[1];
|
||||||
|
const rates = asyncData[2];
|
||||||
|
|
||||||
|
const ratesMap = {};
|
||||||
|
rates.forEach(rate => {
|
||||||
|
const { rateId, price } = rate;
|
||||||
|
ratesMap[rateId] = price;
|
||||||
|
});
|
||||||
|
|
||||||
|
const resourcesMap = {};
|
||||||
|
resources.forEach(resource => {
|
||||||
|
const { resourceId, rate } = resource;
|
||||||
|
resource.price = ratesMap[rate] || 0;
|
||||||
|
resourcesMap[resourceId] = resource;
|
||||||
|
});
|
||||||
|
|
||||||
|
bulkWriteReservationsWithChangesTracking(reservations, resourcesMap)
|
||||||
.then((changes) => {
|
.then((changes) => {
|
||||||
bulkWriteChanges(changes)
|
bulkWriteChanges(changes)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -57,7 +77,7 @@ const checkBookingChanges = () => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log('Error fetching bookings from ORD ', error);
|
console.log('Error fetching bookings, resources and rates from ORD ', error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ const writeBookingReservation = (bookingReservation) => {
|
|||||||
return db.bookingReservation.findOrCreate({where: {...bookingReservationForDB}, defaults: {...bookingReservationForDB}});
|
return db.bookingReservation.findOrCreate({where: {...bookingReservationForDB}, defaults: {...bookingReservationForDB}});
|
||||||
};
|
};
|
||||||
|
|
||||||
const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
const bulkWriteReservationsWithChangesTracking = (reservations, resourcesMap) => {
|
||||||
return new Promise ((resolve, reject) => {
|
return new Promise ((resolve, reject) => {
|
||||||
const changes = [];
|
const changes = [];
|
||||||
const asyncJobs = [];
|
const asyncJobs = [];
|
||||||
@@ -184,8 +184,18 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (instance.hourlyRate === 0 && parseFloat(instance.previous('hourlyRate')) > 0){
|
const previousResourceId = instance.previous('resourceId');
|
||||||
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
const currentResourceId = instance.resourceId;
|
||||||
|
|
||||||
|
const resourceId = currentResourceId ? currentResourceId : previousResourceId;
|
||||||
|
|
||||||
|
if (instance.hourlyRate === 0 || isNaN(instance.hourlyRate)){
|
||||||
|
if (parseFloat(instance.previous('hourlyRate') > 0)) {
|
||||||
|
instance.setDataValue('hourlyRate', instance.previous('hourlyRate'));
|
||||||
|
}else{
|
||||||
|
const hourlyRate = resourceId ? resourcesMap[resourceId].price : 0;
|
||||||
|
instance.setDataValue('hourlyRate', hourlyRate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (realChange){
|
if (realChange){
|
||||||
|
|||||||
26
services/officeRnD/rates.js
Normal file
26
services/officeRnD/rates.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
const { API } = require('../../helpers/api');
|
||||||
|
|
||||||
|
const fetchRates = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
API.get('/rates')
|
||||||
|
.then((result) => {
|
||||||
|
const rates = result.data || [];
|
||||||
|
const cleanedRates = [];
|
||||||
|
rates.forEach(rate => {
|
||||||
|
cleanedRates.push({
|
||||||
|
rateId: rate['_id'],
|
||||||
|
price: rate.price,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
resolve(cleanedRates);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
fetchRates
|
||||||
|
};
|
||||||
@@ -35,6 +35,7 @@ const fetchResources = () => {
|
|||||||
resourceId: resource['_id'],
|
resourceId: resource['_id'],
|
||||||
resourceName: resource.name,
|
resourceName: resource.name,
|
||||||
officeId: resource.office,
|
officeId: resource.office,
|
||||||
|
rate: resource.rate,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
resolve(cleanedResources);
|
resolve(cleanedResources);
|
||||||
|
|||||||
Reference in New Issue
Block a user