@dhyasama/totem-models 9.19.1 → 9.20.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.
package/lib/Account.js CHANGED
@@ -230,6 +230,18 @@ module.exports = function(mongoose, config) {
230
230
 
231
231
  };
232
232
 
233
+ Account.statics.listAdminAccounts = function (options, cb) {
234
+
235
+ const self = this;
236
+
237
+ if (!cb) { throw new Error('cb is required'); }
238
+
239
+ self
240
+ .find({ 'active': true, 'role': 'admin' })
241
+ .exec(cb);
242
+
243
+ };
244
+
233
245
  Account.statics.listAllAccounts = function (options, cb) {
234
246
 
235
247
  // This is only for worker
package/lib/Financials.js CHANGED
@@ -56,7 +56,17 @@ module.exports = function(mongoose, config) {
56
56
  second: { type: Number, default: 0 }
57
57
  }
58
58
  },
59
- review: { type: Boolean, default: false }
59
+ review: { type: Boolean, default: false },
60
+
61
+ // For reminding customer about upcoming collections
62
+ // Don't store recipients, just query admins at time of sending or check postmark post-facto
63
+ // todo - scheduled worker process to add and update items in this list
64
+ adminReminders: [{
65
+ sendOn: { type: Date },
66
+ sent: { type: Boolean, default: false },
67
+ postmarkMessageId: { type: String, trim: true },
68
+ period: { type: String, enum: [null, 'month', 'quarter', 'year'] }
69
+ }]
60
70
  },
61
71
 
62
72
  snapshots: [{
@@ -293,6 +303,16 @@ module.exports = function(mongoose, config) {
293
303
  // Statics operate on the entire collection
294
304
  //////////////////////////////////////////////////////
295
305
 
306
+ Financials.statics.getAll = function getAll(options, cb) {
307
+
308
+ const self = this;
309
+
310
+ const query = self.find({});
311
+
312
+ query.exec(cb);
313
+
314
+ };
315
+
296
316
  Financials.statics.getByOrg = function getByOrg(customerId, orgId, cb) {
297
317
 
298
318
  var self = this;
@@ -365,6 +385,20 @@ module.exports = function(mongoose, config) {
365
385
 
366
386
  };
367
387
 
388
+ Financials.statics.getUpcomingRecurring = function getUpcomingRecurring(options, cb) {
389
+
390
+ const self = this;
391
+ const now = new Date();
392
+
393
+ const query = self.find({
394
+ 'recurring.adminReminders.sendOn': { $lte: now },
395
+ 'recurring.adminReminders.sent': false
396
+ });
397
+
398
+ query.exec(cb);
399
+
400
+ };
401
+
368
402
  Financials.statics.getCompanyInitialToSend = function getCompanyInitialToSend(cb) {
369
403
 
370
404
  var self = this;
@@ -750,7 +784,7 @@ module.exports = function(mongoose, config) {
750
784
  const self = this;
751
785
 
752
786
  const query = self.find({
753
- 'snapshots.status': { $nin: ['Completed', 'Archived'] },
787
+ 'snapshots.status': { $nin: ['Completed', 'Archived', 'Overdue'] },
754
788
  'snapshots.dueOn': { $lte: new Date() }
755
789
  });
756
790
 
@@ -758,6 +792,14 @@ module.exports = function(mongoose, config) {
758
792
 
759
793
  };
760
794
 
795
+ Financials.statics.markAsOverdue = function markAsOverdue(financials, cb) {
796
+
797
+ if (!financials) { return cb(new Error('financials is required'), null); }
798
+
799
+ financials.save(cb);
800
+
801
+ };
802
+
761
803
  Financials.statics.removeCustomerFinancials = function removeCustomerFinancials(customerId, cb) {
762
804
 
763
805
  // this is only used to wipe out financials created by the google sheet import process
@@ -803,7 +845,7 @@ module.exports = function(mongoose, config) {
803
845
  // Post-remove: fired on every document after it's deleted
804
846
  ///////////////////////////////////////////////////////////////////////////////////////
805
847
 
806
- var updateStatus = function updateStatus(self) {
848
+ const updateStatus = function updateStatus(self) {
807
849
 
808
850
  _.each(self.snapshots, function(snapshot) {
809
851
 
@@ -847,7 +889,8 @@ module.exports = function(mongoose, config) {
847
889
 
848
890
  Financials.pre('save', function(next) {
849
891
 
850
- var self = this;
892
+ const self = this;
893
+
851
894
  updateStatus(self);
852
895
 
853
896
  return next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.19.1",
3
+ "version": "9.20.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",