@dhyasama/totem-models 9.19.2 → 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 +12 -0
- package/lib/Financials.js +38 -3
- 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,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;
|
|
@@ -811,7 +845,7 @@ module.exports = function(mongoose, config) {
|
|
|
811
845
|
// Post-remove: fired on every document after it's deleted
|
|
812
846
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
813
847
|
|
|
814
|
-
|
|
848
|
+
const updateStatus = function updateStatus(self) {
|
|
815
849
|
|
|
816
850
|
_.each(self.snapshots, function(snapshot) {
|
|
817
851
|
|
|
@@ -855,7 +889,8 @@ module.exports = function(mongoose, config) {
|
|
|
855
889
|
|
|
856
890
|
Financials.pre('save', function(next) {
|
|
857
891
|
|
|
858
|
-
|
|
892
|
+
const self = this;
|
|
893
|
+
|
|
859
894
|
updateStatus(self);
|
|
860
895
|
|
|
861
896
|
return next();
|