DTP Base provides a scalable and secure Node.js application development harness ready for production service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
828 B

'use strict';
/* globals db */
const clients = db.clients.find();
while (clients.hasNext()) {
let timeWorked = 0, billable = 0;
const client = clients.next();
const sessions = db.tasksessions.find({ client: client._id });
while (sessions.hasNext()) {
const session = sessions.next();
timeWorked += session.duration;
billable += session.hourlyRate * (session.duration / 3600);
}
/*
* Fix some JavaScript goofiness with numbers (round correctly to 2nd decimal
* digit).
*/
billable = Math.round((billable + Number.EPSILON) * 100) / 100;
print(`client: ${client._id}:${client.name} time:${timeWorked} bill:${billable}`);
db.clients.updateOne(
{ _id: client._id },
{
$set: {
weeklyTotals: {
timeWorked,
billable,
},
},
},
);
}