@dhyasama/totem-models 7.36.0 → 7.37.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/Fund.js +18 -3
- package/lib/LimitedPartner.js +77 -62
- package/package.json +1 -1
package/lib/Fund.js
CHANGED
|
@@ -8,7 +8,6 @@ module.exports = function(mongoose, config) {
|
|
|
8
8
|
var env = process.env.NODE_ENV || 'development';
|
|
9
9
|
|
|
10
10
|
var Fund = new Schema({
|
|
11
|
-
|
|
12
11
|
name: { type: String, required: true, unique: true },
|
|
13
12
|
slug: { type: String, required: true, unique: true },
|
|
14
13
|
shortName: { type: String, required: true },
|
|
@@ -17,8 +16,12 @@ module.exports = function(mongoose, config) {
|
|
|
17
16
|
hexColorCode: { type: String, required: true, default: '#cccccc' },
|
|
18
17
|
closeDate: { type: Date },
|
|
19
18
|
amount: { type: Number },
|
|
20
|
-
crunchbase: { uuid: { type: String, default: '', unique: true } }
|
|
21
|
-
|
|
19
|
+
crunchbase: { uuid: { type: String, default: '', unique: true } },
|
|
20
|
+
transactions: [{
|
|
21
|
+
type: { type: String, enum: ['fees', 'expenses', 'carry'] },
|
|
22
|
+
amount: { type: Number, default: 0 },
|
|
23
|
+
date: { type: Date, default: null },
|
|
24
|
+
}],
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
/************* BASIC FIELDS **********************/
|
|
@@ -169,6 +172,18 @@ module.exports = function(mongoose, config) {
|
|
|
169
172
|
|
|
170
173
|
};
|
|
171
174
|
|
|
175
|
+
Fund.statics.removeTransactions = function removeTransactions(cb) {
|
|
176
|
+
|
|
177
|
+
var self = this;
|
|
178
|
+
|
|
179
|
+
var query = self.update(
|
|
180
|
+
{ $set: { transactions: [] } },
|
|
181
|
+
{ multi : true }
|
|
182
|
+
);
|
|
183
|
+
query.exec(cb);
|
|
184
|
+
|
|
185
|
+
};
|
|
186
|
+
|
|
172
187
|
Fund.post('remove', function(doc) {
|
|
173
188
|
// Debt.debts.internal.fund
|
|
174
189
|
// Document.fundInvolved
|
package/lib/LimitedPartner.js
CHANGED
|
@@ -45,10 +45,11 @@ module.exports = function(mongoose, config) {
|
|
|
45
45
|
quarterlyAccountStatement: { type: String, default: '' }
|
|
46
46
|
},
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
transactions: [{
|
|
49
49
|
fund: {type: Schema.ObjectId, ref: 'Fund'},
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
type: { type: String, enum: ['commitment', 'contribution', 'distribution'] },
|
|
51
|
+
amount: { type: Number, default: 0 },
|
|
52
|
+
date: { type: Date, default: null },
|
|
52
53
|
}],
|
|
53
54
|
|
|
54
55
|
contact: {
|
|
@@ -194,9 +195,56 @@ module.exports = function(mongoose, config) {
|
|
|
194
195
|
|
|
195
196
|
/////////////////////
|
|
196
197
|
|
|
197
|
-
LimitedPartner.virtual('
|
|
198
|
+
LimitedPartner.virtual('totalCommitment').get(function () {
|
|
198
199
|
var self = this;
|
|
199
|
-
return _.reduce(self.
|
|
200
|
+
return _.reduce(self.transactions, function(memo, transaction) {
|
|
201
|
+
return memo + ((transaction.type == 'commitment' && transaction.amount > 0) ? transaction.amount : 0);
|
|
202
|
+
}, 0);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
LimitedPartner.virtual('totalContribution').get(function () {
|
|
206
|
+
var self = this;
|
|
207
|
+
return _.reduce(self.transactions, function(memo, transaction) {
|
|
208
|
+
return memo + ((transaction.type == 'contribution' && transaction.amount > 0) ? transaction.amount : 0);
|
|
209
|
+
}, 0);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
LimitedPartner.virtual('totalDistribution').get(function () {
|
|
213
|
+
var self = this;
|
|
214
|
+
return _.reduce(self.transactions, function(memo, transaction) {
|
|
215
|
+
return memo + ((transaction.type == 'distribution' && transaction.amount > 0) ? transaction.amount : 0);
|
|
216
|
+
}, 0);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
LimitedPartner.virtual('fundsInvested').get(function () {
|
|
220
|
+
|
|
221
|
+
var self = this;
|
|
222
|
+
var fundsInvested = [];
|
|
223
|
+
|
|
224
|
+
_.each(self.transactions, function(transaction) {
|
|
225
|
+
|
|
226
|
+
var fundMatch = _.find(fundsInvested, function(fund) { return fund._id == transaction.fund._id; });
|
|
227
|
+
|
|
228
|
+
if(!fundMatch) {
|
|
229
|
+
fundsInvested.push({
|
|
230
|
+
_id: transaction.fund._id,
|
|
231
|
+
name: transaction.fund.name,
|
|
232
|
+
shortName: transaction.fund.shortName,
|
|
233
|
+
abbreviation: transaction.fund.abbreviation,
|
|
234
|
+
commitment: 0,
|
|
235
|
+
contribution: 0,
|
|
236
|
+
distribution: 0
|
|
237
|
+
});
|
|
238
|
+
fundMatch = _.last(fundsInvested);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// and increment the transaction type by the transaction amount
|
|
242
|
+
fundMatch[transaction.type] += transaction.amount;
|
|
243
|
+
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
return fundsInvested;
|
|
247
|
+
|
|
200
248
|
});
|
|
201
249
|
|
|
202
250
|
LimitedPartner.virtual('email.primary').get(function () {
|
|
@@ -308,40 +356,7 @@ module.exports = function(mongoose, config) {
|
|
|
308
356
|
});
|
|
309
357
|
|
|
310
358
|
};
|
|
311
|
-
|
|
312
|
-
LimitedPartner.methods.fundPercentCalled = function(fundId) {
|
|
313
|
-
|
|
314
|
-
if (!fundId) return 0;
|
|
315
|
-
|
|
316
|
-
var match = _.find(this.fundsInvested, function(inv) {
|
|
317
|
-
return inv.fund == fundId || inv.fund.id == fundId;
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
if (!match) return 0;
|
|
321
|
-
|
|
322
|
-
return (match.called / match.committed) * 100;
|
|
323
|
-
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
LimitedPartner.methods.listActiveFunds = function(cb) {
|
|
327
|
-
|
|
328
|
-
var lp = this;
|
|
329
|
-
var funds = [];
|
|
330
|
-
|
|
331
|
-
lp.populate('fundsInvested.fund', function(err) {
|
|
332
|
-
|
|
333
|
-
if (err) return cb(err, null);
|
|
334
|
-
|
|
335
|
-
_.each(lp.fundsInvested, function(investment) {
|
|
336
|
-
if (investment.committed > 0) { funds.push(investment); }
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
return cb(null, funds);
|
|
340
|
-
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
};
|
|
344
|
-
|
|
359
|
+
|
|
345
360
|
LimitedPartner.methods.docSlugs = function() {
|
|
346
361
|
|
|
347
362
|
var slugs = this.documentSlugs;
|
|
@@ -371,7 +386,7 @@ module.exports = function(mongoose, config) {
|
|
|
371
386
|
var self = this;
|
|
372
387
|
var query;
|
|
373
388
|
var getLp = function() {
|
|
374
|
-
query.populate('
|
|
389
|
+
query.populate('transactions.fund');
|
|
375
390
|
query.populate('people');
|
|
376
391
|
query.populate('notes');
|
|
377
392
|
query.deepPopulate([
|
|
@@ -397,7 +412,7 @@ module.exports = function(mongoose, config) {
|
|
|
397
412
|
getLp();
|
|
398
413
|
}
|
|
399
414
|
else {
|
|
400
|
-
query = self.findOne({ '_id': id, '
|
|
415
|
+
query = self.findOne({ '_id': id, 'transactions.fund': { $in : self.customerFunds }}, self.getReadFilterKeys(role));
|
|
401
416
|
getLp();
|
|
402
417
|
}
|
|
403
418
|
|
|
@@ -409,7 +424,7 @@ module.exports = function(mongoose, config) {
|
|
|
409
424
|
var query;
|
|
410
425
|
|
|
411
426
|
var getLps = function(q) {
|
|
412
|
-
q.populate('
|
|
427
|
+
q.populate('transactions.fund')
|
|
413
428
|
q.populate('people', 'name')
|
|
414
429
|
q.exec(function (err, lps) {
|
|
415
430
|
if (err) return cb(err, null);
|
|
@@ -423,7 +438,7 @@ module.exports = function(mongoose, config) {
|
|
|
423
438
|
getLps(query);
|
|
424
439
|
}
|
|
425
440
|
else {
|
|
426
|
-
query = self.find({'people': personId, '
|
|
441
|
+
query = self.find({'people': personId, 'transactions.fund': { $in : self.customerFunds }}, self.getReadFilterKeys(role));
|
|
427
442
|
getLps(query);
|
|
428
443
|
}
|
|
429
444
|
|
|
@@ -435,7 +450,7 @@ module.exports = function(mongoose, config) {
|
|
|
435
450
|
var query;
|
|
436
451
|
|
|
437
452
|
var getLps = function() {
|
|
438
|
-
query.populate('
|
|
453
|
+
query.populate('transactions.fund');
|
|
439
454
|
query.exec(cb);
|
|
440
455
|
};
|
|
441
456
|
|
|
@@ -444,7 +459,7 @@ module.exports = function(mongoose, config) {
|
|
|
444
459
|
getLps();
|
|
445
460
|
}
|
|
446
461
|
else {
|
|
447
|
-
query = self.find({'name': lpName, '
|
|
462
|
+
query = self.find({'name': lpName, 'transactions.fund': { $in : self.customerFunds }}, self.getReadFilterKeys(role));
|
|
448
463
|
getLps();
|
|
449
464
|
}
|
|
450
465
|
|
|
@@ -563,7 +578,7 @@ module.exports = function(mongoose, config) {
|
|
|
563
578
|
var query;
|
|
564
579
|
|
|
565
580
|
var getLps = function(q) {
|
|
566
|
-
q.populate('
|
|
581
|
+
q.populate('transactions.fund')
|
|
567
582
|
q.exec(function (err, lps) {
|
|
568
583
|
if (err) return cb(err, null);
|
|
569
584
|
lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
|
|
@@ -576,7 +591,7 @@ module.exports = function(mongoose, config) {
|
|
|
576
591
|
getLps(query);
|
|
577
592
|
}
|
|
578
593
|
else {
|
|
579
|
-
query = self.find({ '
|
|
594
|
+
query = self.find({ 'transactions.fund': { $in : self.customerFunds }}, self.getReadFilterKeys(role));
|
|
580
595
|
getLps(query);
|
|
581
596
|
}
|
|
582
597
|
|
|
@@ -591,7 +606,7 @@ module.exports = function(mongoose, config) {
|
|
|
591
606
|
var query;
|
|
592
607
|
|
|
593
608
|
var getLps = function(q) {
|
|
594
|
-
q.populate('
|
|
609
|
+
q.populate('transactions.fund')
|
|
595
610
|
q.exec(function (err, lps) {
|
|
596
611
|
if (err) return cb(err, null);
|
|
597
612
|
lps = _.sortBy(lps, function(lp) { return lp.name ? lp.name.toLowerCase() : ''; });
|
|
@@ -599,7 +614,7 @@ module.exports = function(mongoose, config) {
|
|
|
599
614
|
});
|
|
600
615
|
};
|
|
601
616
|
|
|
602
|
-
query = self.find({ '
|
|
617
|
+
query = self.find({ 'transactions.fund': { $in : fundIds }}, self.getReadFilterKeys(role));
|
|
603
618
|
getLps(query);
|
|
604
619
|
|
|
605
620
|
};
|
|
@@ -610,7 +625,7 @@ module.exports = function(mongoose, config) {
|
|
|
610
625
|
|
|
611
626
|
this
|
|
612
627
|
.find({'status.verified': false}, this.getReadFilterKeys(role))
|
|
613
|
-
.populate('
|
|
628
|
+
.populate('transactions.fund')
|
|
614
629
|
.exec(function (err, lps) {
|
|
615
630
|
cb(err, _.sortBy(lps, function(lp) { return lp.name; }));
|
|
616
631
|
});
|
|
@@ -623,7 +638,7 @@ module.exports = function(mongoose, config) {
|
|
|
623
638
|
|
|
624
639
|
this
|
|
625
640
|
.find({'flagged.resolved': false, 'flagged.text': { $ne: '' }}, this.getReadFilterKeys(role))
|
|
626
|
-
.populate('
|
|
641
|
+
.populate('transactions.fund')
|
|
627
642
|
.exec(function (err, lps) {
|
|
628
643
|
cb(err, _.sortBy(lps, function(lp) { return lp.name; }));
|
|
629
644
|
});
|
|
@@ -638,8 +653,8 @@ module.exports = function(mongoose, config) {
|
|
|
638
653
|
var self = this;
|
|
639
654
|
|
|
640
655
|
self
|
|
641
|
-
.find({ '
|
|
642
|
-
.populate('
|
|
656
|
+
.find({ 'transactions.fund': fundId }, self.getReadFilterKeys(role))
|
|
657
|
+
.populate('transactions.fund')
|
|
643
658
|
.exec(function(err, lps) {
|
|
644
659
|
|
|
645
660
|
if (err) return cb(err, null);
|
|
@@ -680,7 +695,7 @@ module.exports = function(mongoose, config) {
|
|
|
680
695
|
var self = this;
|
|
681
696
|
var query;
|
|
682
697
|
var getLps = function() {
|
|
683
|
-
query.populate('
|
|
698
|
+
query.populate('transactions.fund');
|
|
684
699
|
query.exec(function (err, lps) {
|
|
685
700
|
|
|
686
701
|
if (err) return cb(err, null);
|
|
@@ -700,7 +715,7 @@ module.exports = function(mongoose, config) {
|
|
|
700
715
|
getLps();
|
|
701
716
|
}
|
|
702
717
|
else {
|
|
703
|
-
query = self.find({ 'name': new RegExp(terms, "i"), '
|
|
718
|
+
query = self.find({ 'name': new RegExp(terms, "i"), 'transactions.fund': { $in : self.customerFunds }}, self.getReadFilterKeys(role));
|
|
704
719
|
|
|
705
720
|
getLps();
|
|
706
721
|
}
|
|
@@ -713,13 +728,13 @@ module.exports = function(mongoose, config) {
|
|
|
713
728
|
return self.customerFunds;
|
|
714
729
|
};
|
|
715
730
|
|
|
716
|
-
LimitedPartner.statics.
|
|
731
|
+
LimitedPartner.statics.removeCustomerTransactions = function removeCustomerTransactions(customerId, cb) {
|
|
717
732
|
|
|
718
733
|
var self = this;
|
|
719
734
|
|
|
720
735
|
var query = self.update(
|
|
721
736
|
{ 'customer': customerId },
|
|
722
|
-
{ $set: {
|
|
737
|
+
{ $set: { transactions: [] } },
|
|
723
738
|
{ multi : true }
|
|
724
739
|
);
|
|
725
740
|
query.exec(cb);
|
|
@@ -929,14 +944,14 @@ module.exports = function(mongoose, config) {
|
|
|
929
944
|
|
|
930
945
|
LimitedPartner.plugin(filter, {
|
|
931
946
|
"readFilter": {
|
|
932
|
-
"admin": ["name", "shortName", "start", "people", "documentSlugs", "
|
|
933
|
-
"lp-full": ["name", "shortName", "start", "people", "documentSlugs", "
|
|
947
|
+
"admin": ["name", "shortName", "start", "people", "documentSlugs", "transactions", "contact", "distributions", "k1", "entered", "status", "flagged", "flags", "notes"],
|
|
948
|
+
"lp-full": ["name", "shortName", "start", "people", "documentSlugs", "transactions", "contact", "distributions", "k1", "entered", "status", "flagged", "flags", "notes"],
|
|
934
949
|
"lp-names": ["name", "shortName", "flagged", "flags"],
|
|
935
950
|
"none": []
|
|
936
951
|
},
|
|
937
952
|
"writeFilter": {
|
|
938
|
-
"admin": ["name", "shortName", "start", "people", "documentSlugs", "
|
|
939
|
-
"lp-full": ["name", "shortName", "start", "people", "documentSlugs", "
|
|
953
|
+
"admin": ["name", "shortName", "start", "people", "documentSlugs", "transactions", "contact", "distributions", "k1", "entered", "status", "flagged", "flags", "notes"],
|
|
954
|
+
"lp-full": ["name", "shortName", "start", "people", "documentSlugs", "transactions", "contact", "distributions", "k1", "entered", "status", "flagged", "flags", "notes"],
|
|
940
955
|
"lp-names": ["flagged", "flags"],
|
|
941
956
|
"none": []
|
|
942
957
|
},
|
|
@@ -957,4 +972,4 @@ module.exports = function(mongoose, config) {
|
|
|
957
972
|
|
|
958
973
|
mongoose.model('LimitedPartner', LimitedPartner);
|
|
959
974
|
|
|
960
|
-
};
|
|
975
|
+
};
|