@dhyasama/totem-models 11.112.0 → 11.114.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/Financials.js +34 -27
- package/package.json +1 -1
package/lib/Financials.js
CHANGED
|
@@ -61,7 +61,7 @@ module.exports = function(mongoose, config) {
|
|
|
61
61
|
month: { type: Number, default: 12 },
|
|
62
62
|
day: { type: Number, default: 31 },
|
|
63
63
|
},
|
|
64
|
-
|
|
64
|
+
approval: { type: Boolean, default: false },
|
|
65
65
|
|
|
66
66
|
// For reminding customer about upcoming collections
|
|
67
67
|
// Don't store recipients, just query admins at time of sending or check postmark post-facto
|
|
@@ -78,9 +78,9 @@ module.exports = function(mongoose, config) {
|
|
|
78
78
|
|
|
79
79
|
currency: { type: String, default: 'USD' },
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
approval:{ type: Boolean, default: false },
|
|
82
82
|
|
|
83
|
-
status: { type: String, enum: ['Created', 'Scheduled', 'Delivered', 'Opened', '
|
|
83
|
+
status: { type: String, enum: ['Created', 'Scheduled', 'Delivered', 'Opened', 'Delayed', 'Unapproved', 'Completed', 'Archived'] },
|
|
84
84
|
|
|
85
85
|
year: { type: Number, default: 0 },
|
|
86
86
|
period: { type: String, enum: ['FY', 'H1', 'H2', 'Q1', 'Q2', 'Q3', 'Q4', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] },
|
|
@@ -88,6 +88,8 @@ module.exports = function(mongoose, config) {
|
|
|
88
88
|
form: [{
|
|
89
89
|
name: { type: String, trim: true },
|
|
90
90
|
type: { type: String, enum: [null, 'header', 'block', 'document', 'metric', 'question'] },
|
|
91
|
+
budget: { type: Number },
|
|
92
|
+
forecast: { type: Number },
|
|
91
93
|
required: { type: Boolean, default: false }
|
|
92
94
|
}],
|
|
93
95
|
|
|
@@ -95,19 +97,36 @@ module.exports = function(mongoose, config) {
|
|
|
95
97
|
_id: false,
|
|
96
98
|
name: { type: String, trim: true },
|
|
97
99
|
document: { type: Schema.ObjectId, ref: 'Document' },
|
|
100
|
+
verified: { type: Boolean, default: false },
|
|
98
101
|
}],
|
|
99
102
|
|
|
100
103
|
metrics: [{
|
|
101
104
|
_id: false,
|
|
102
105
|
name: { type: String, trim: true },
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
scenario: { type: String, enum: ['actual', 'budget', 'forecast'] },
|
|
107
|
+
value: { type: Number },
|
|
108
|
+
breakdown: { type: Schema.Types.Mixed },
|
|
109
|
+
source: {
|
|
110
|
+
_id: false,
|
|
111
|
+
model: {
|
|
112
|
+
type: String,
|
|
113
|
+
enum: ['Document', 'Meeting', 'Message', 'Note'],
|
|
114
|
+
required: true,
|
|
115
|
+
},
|
|
116
|
+
ref: {
|
|
117
|
+
type: Schema.Types.ObjectId,
|
|
118
|
+
required: true,
|
|
119
|
+
refPath: 'metrics.source.model',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
verified: { type: Boolean, default: false },
|
|
105
123
|
}],
|
|
106
124
|
|
|
107
125
|
questions: [{
|
|
108
126
|
_id: false,
|
|
109
127
|
prompt: { type: String, trim: true },
|
|
110
128
|
response: { type: String, trim: true },
|
|
129
|
+
verified: { type: Boolean, default: false },
|
|
111
130
|
}],
|
|
112
131
|
|
|
113
132
|
dueOn: { type: Date, index: false },
|
|
@@ -203,11 +222,7 @@ module.exports = function(mongoose, config) {
|
|
|
203
222
|
|
|
204
223
|
}
|
|
205
224
|
|
|
206
|
-
}]
|
|
207
|
-
|
|
208
|
-
projections: [
|
|
209
|
-
|
|
210
|
-
]
|
|
225
|
+
}]
|
|
211
226
|
|
|
212
227
|
});
|
|
213
228
|
|
|
@@ -927,14 +942,14 @@ module.exports = function(mongoose, config) {
|
|
|
927
942
|
|
|
928
943
|
};
|
|
929
944
|
|
|
930
|
-
Financials.statics.
|
|
945
|
+
Financials.statics.getOverdue = function getOverdue(cb) {
|
|
931
946
|
|
|
932
947
|
const self = this;
|
|
933
948
|
|
|
934
949
|
const query = self.find({
|
|
935
950
|
'snapshots': {
|
|
936
951
|
$elemMatch: {
|
|
937
|
-
'status': { $nin: ['Completed', 'Archived', '
|
|
952
|
+
'status': { $nin: ['Completed', 'Archived', 'Delayed'] },
|
|
938
953
|
'dueOn': { $lte: new Date() }
|
|
939
954
|
}
|
|
940
955
|
}
|
|
@@ -944,14 +959,6 @@ module.exports = function(mongoose, config) {
|
|
|
944
959
|
|
|
945
960
|
};
|
|
946
961
|
|
|
947
|
-
Financials.statics.markAsOverdue = function markAsOverdue(financials, cb) {
|
|
948
|
-
|
|
949
|
-
if (!financials) { return cb(new Error('financials is required'), null); }
|
|
950
|
-
|
|
951
|
-
financials.save(cb);
|
|
952
|
-
|
|
953
|
-
};
|
|
954
|
-
|
|
955
962
|
Financials.statics.updateProperty = function updateProperty(id, key, value, cb) {
|
|
956
963
|
|
|
957
964
|
const self = this;
|
|
@@ -1000,12 +1007,12 @@ module.exports = function(mongoose, config) {
|
|
|
1000
1007
|
|
|
1001
1008
|
if (!snapshot) return;
|
|
1002
1009
|
|
|
1003
|
-
var
|
|
1010
|
+
var needsApproval = snapshot.approval;
|
|
1004
1011
|
var isSubmitted = snapshot.submittedOn;
|
|
1005
1012
|
var isApproved = snapshot.approvedOn;
|
|
1006
1013
|
var isRejected = snapshot.rejectedOn && snapshot.rejection;
|
|
1007
1014
|
var isArchived = snapshot.archivedOn;
|
|
1008
|
-
var
|
|
1015
|
+
var isDelayed = snapshot.dueOn ? moment(new Date()).isAfter(moment(snapshot.dueOn)) : false;
|
|
1009
1016
|
|
|
1010
1017
|
var isOpened = false;
|
|
1011
1018
|
var isDelivered = false;
|
|
@@ -1017,12 +1024,12 @@ module.exports = function(mongoose, config) {
|
|
|
1017
1024
|
}
|
|
1018
1025
|
|
|
1019
1026
|
if(!snapshot.uuid) snapshot.status = 'Completed'; // no uuid means the snapshot was created from the google sheet and should always be completed
|
|
1020
|
-
else if(
|
|
1021
|
-
else if(!
|
|
1027
|
+
else if(needsApproval && isApproved) snapshot.status = 'Completed';
|
|
1028
|
+
else if(!needsApproval && isSubmitted) snapshot.status = 'Completed';
|
|
1022
1029
|
else if(isArchived) snapshot.status = 'Archived';
|
|
1023
|
-
else if(
|
|
1024
|
-
else if(
|
|
1025
|
-
else if(
|
|
1030
|
+
else if(needsApproval && isSubmitted && !isRejected) snapshot.status = 'Unapproved';
|
|
1031
|
+
else if(needsApproval && isSubmitted && isRejected) snapshot.status = 'Opened';
|
|
1032
|
+
else if(isDelayed) snapshot.status = 'Delayed';
|
|
1026
1033
|
else if(isDelivered && isOpened) snapshot.status = 'Opened';
|
|
1027
1034
|
else if(isDelivered) snapshot.status = 'Delivered';
|
|
1028
1035
|
else if(isScheduled) snapshot.status = 'Scheduled'; // when a snapshot is scheduled, but not yet sent (checks every 5 minutes)
|