@dhyasama/totem-models 9.19.2 → 9.21.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 +12 -0
- package/lib/Financials.js +40 -57
- package/package.json +1 -1
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,23 +56,26 @@ 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: [{
|
|
63
73
|
|
|
64
74
|
uuid: { type: String },
|
|
65
75
|
|
|
66
|
-
managedServices: { type: Boolean, default: false }, // to be transformed into review
|
|
67
76
|
review: { type: Boolean, default: false },
|
|
68
77
|
|
|
69
|
-
|
|
70
|
-
// Not Scheduled -> Completed
|
|
71
|
-
// Scheduled to be removed
|
|
72
|
-
status: { type: String, enum: ['Delivered', 'Opened', 'Overdue', 'In Review', 'Completed', 'Archived', 'In Progress', 'Not Scheduled', 'Scheduled'] },
|
|
73
|
-
|
|
74
|
-
// to be removed
|
|
75
|
-
action: { type: String },
|
|
78
|
+
status: { type: String, enum: ['Delivered', 'Opened', 'Overdue', 'In Review', 'Completed', 'Archived'] },
|
|
76
79
|
|
|
77
80
|
year: { type: Number, default: 0 },
|
|
78
81
|
period: { type: String, enum: ['Annual', 'Q1', 'Q2', 'Q3', 'Q4', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] },
|
|
@@ -293,6 +296,16 @@ module.exports = function(mongoose, config) {
|
|
|
293
296
|
// Statics operate on the entire collection
|
|
294
297
|
//////////////////////////////////////////////////////
|
|
295
298
|
|
|
299
|
+
Financials.statics.getAll = function getAll(options, cb) {
|
|
300
|
+
|
|
301
|
+
const self = this;
|
|
302
|
+
|
|
303
|
+
const query = self.find({});
|
|
304
|
+
|
|
305
|
+
query.exec(cb);
|
|
306
|
+
|
|
307
|
+
};
|
|
308
|
+
|
|
296
309
|
Financials.statics.getByOrg = function getByOrg(customerId, orgId, cb) {
|
|
297
310
|
|
|
298
311
|
var self = this;
|
|
@@ -365,6 +378,20 @@ module.exports = function(mongoose, config) {
|
|
|
365
378
|
|
|
366
379
|
};
|
|
367
380
|
|
|
381
|
+
Financials.statics.getUpcomingRecurring = function getUpcomingRecurring(options, cb) {
|
|
382
|
+
|
|
383
|
+
const self = this;
|
|
384
|
+
const now = new Date();
|
|
385
|
+
|
|
386
|
+
const query = self.find({
|
|
387
|
+
'recurring.adminReminders.sendOn': { $lte: now },
|
|
388
|
+
'recurring.adminReminders.sent': false
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
query.exec(cb);
|
|
392
|
+
|
|
393
|
+
};
|
|
394
|
+
|
|
368
395
|
Financials.statics.getCompanyInitialToSend = function getCompanyInitialToSend(cb) {
|
|
369
396
|
|
|
370
397
|
var self = this;
|
|
@@ -700,51 +727,6 @@ module.exports = function(mongoose, config) {
|
|
|
700
727
|
|
|
701
728
|
};
|
|
702
729
|
|
|
703
|
-
Financials.statics.getManagedServicesForReview = function getManagedServicesForReview(customerId, cb) {
|
|
704
|
-
|
|
705
|
-
var self = this;
|
|
706
|
-
|
|
707
|
-
var query = self.find({
|
|
708
|
-
'customer': customerId,
|
|
709
|
-
'snapshots': {
|
|
710
|
-
$elemMatch: {
|
|
711
|
-
'managedServices': true,
|
|
712
|
-
'submittedOn': { $ne: null },
|
|
713
|
-
'reviewedOn': null
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
query.populate('organization', 'name');
|
|
719
|
-
|
|
720
|
-
query.exec(function(err, results) {
|
|
721
|
-
|
|
722
|
-
var snapshots = [];
|
|
723
|
-
|
|
724
|
-
_.each(results, function(result) {
|
|
725
|
-
_.each(result.snapshots, function(snapshot) {
|
|
726
|
-
|
|
727
|
-
var isManagedServices = snapshot.managedServices;
|
|
728
|
-
var isSubmitted = snapshot.submittedOn;
|
|
729
|
-
var isNotReviewed = !snapshot.reviewedOn;
|
|
730
|
-
|
|
731
|
-
if(isManagedServices && isSubmitted && isNotReviewed) {
|
|
732
|
-
snapshots.push({
|
|
733
|
-
organization: result.organization.name,
|
|
734
|
-
snapshot: snapshot
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
});
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
if (err) { return cb(err, null); }
|
|
742
|
-
return cb(null, snapshots);
|
|
743
|
-
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
};
|
|
747
|
-
|
|
748
730
|
Financials.statics.getPassivelyOverdue = function getPassivelyOverdue(cb) {
|
|
749
731
|
|
|
750
732
|
const self = this;
|
|
@@ -811,13 +793,13 @@ module.exports = function(mongoose, config) {
|
|
|
811
793
|
// Post-remove: fired on every document after it's deleted
|
|
812
794
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
813
795
|
|
|
814
|
-
|
|
796
|
+
const updateStatus = function updateStatus(self) {
|
|
815
797
|
|
|
816
798
|
_.each(self.snapshots, function(snapshot) {
|
|
817
799
|
|
|
818
800
|
if(!snapshot) return;
|
|
819
801
|
|
|
820
|
-
var needsReview = snapshot.
|
|
802
|
+
var needsReview = snapshot.review;
|
|
821
803
|
var isSubmitted = snapshot.submittedOn;
|
|
822
804
|
var isReviewed = snapshot.reviewedOn;
|
|
823
805
|
var isRejected = snapshot.rejection;
|
|
@@ -855,7 +837,8 @@ module.exports = function(mongoose, config) {
|
|
|
855
837
|
|
|
856
838
|
Financials.pre('save', function(next) {
|
|
857
839
|
|
|
858
|
-
|
|
840
|
+
const self = this;
|
|
841
|
+
|
|
859
842
|
updateStatus(self);
|
|
860
843
|
|
|
861
844
|
return next();
|