@dhyasama/totem-models 7.50.0 → 7.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/Financials.js +46 -3
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -231,6 +231,49 @@ module.exports = function(mongoose, config) {
231
231
 
232
232
  };
233
233
 
234
+ Financials.statics.getUUIDsToSend = function getUUIDsToSend(cb) {
235
+
236
+ var self = this;
237
+ var now = new Date();
238
+
239
+ var query = self.find({
240
+ 'snapshots': {
241
+ $elemMatch: {
242
+ 'notifications.company.sendTo': { $gt: [] },
243
+ 'notifications.company.sendOn.sendOn': { $lte: now },
244
+ 'notifications.company.sendOn.sentOn': null
245
+ }
246
+ }
247
+ });
248
+
249
+ query.exec(function(err, result) {
250
+
251
+ if (err) { return cb(err, null); }
252
+
253
+ var snapshots = _.pluck(result || [], 'snapshots');
254
+
255
+ snapshots = _.flatten(snapshots);
256
+
257
+ snapshots = _.filter(snapshots, function(snapshot) {
258
+
259
+ var sendOnsLessThanNow = _.filter(snapshot.notifications.company.sendOn, function(sendOn) {
260
+ return sendOn.sendOn < now;
261
+ });
262
+
263
+ var hasRecipients = snapshot.notifications.company.sendTo.length > 0;
264
+ var hasSendOnLessThanNow = !_.isEmpty(sendOnsLessThanNow);
265
+ var hasSendOnNotSent = _.some(sendOnsLessThanNow, function(s) { return s.sentOn ? false : true; });
266
+
267
+ return hasRecipients && hasSendOnLessThanNow && hasSendOnNotSent;
268
+
269
+ });
270
+
271
+ return cb(null, _.pluck(snapshots, 'uuid'));
272
+
273
+ });
274
+
275
+ };
276
+
234
277
  Financials.statics.getForCustomer = function getForCustomer(customerId, cb) {
235
278
 
236
279
  var self = this;
@@ -363,7 +406,7 @@ module.exports = function(mongoose, config) {
363
406
  var isRejected = !_.isEmpty(snapshot.rejection);
364
407
 
365
408
  // no uuid means the data was captured from the google sheet
366
- if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (managedServices && isReviewed)) {
409
+ if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (isManagedServices && isReviewed)) {
367
410
  snapshot.status = 'Completed';
368
411
  snapshot.action = null;
369
412
  }
@@ -389,8 +432,8 @@ module.exports = function(mongoose, config) {
389
432
 
390
433
  else {
391
434
  snapshot.status = 'In Progress';
392
- if(managedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
393
- else if(managedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
435
+ if(isManagedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
436
+ else if(isManagedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
394
437
  else if(latestSentOn.status) snapshot.action = latestSentOn.status;
395
438
  }
396
439
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "7.50.0",
3
+ "version": "7.51.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",