@dhyasama/totem-models 9.15.0 → 9.17.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 +33 -37
- package/package.json +1 -1
package/lib/Financials.js
CHANGED
|
@@ -70,6 +70,8 @@ module.exports = function(mongoose, config) {
|
|
|
70
70
|
// Not Scheduled to be removed
|
|
71
71
|
// Scheduled to be removed
|
|
72
72
|
status: { type: String, enum: ['Delivered', 'Opened', 'Overdue', 'In Review', 'Completed', 'Archived', 'In Progress', 'Not Scheduled', 'Scheduled'] },
|
|
73
|
+
|
|
74
|
+
// to be removed
|
|
73
75
|
action: { type: String },
|
|
74
76
|
|
|
75
77
|
year: { type: Number, default: 0 },
|
|
@@ -775,63 +777,57 @@ module.exports = function(mongoose, config) {
|
|
|
775
777
|
// Post-remove: fired on every document after it's deleted
|
|
776
778
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
777
779
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
var self = this;
|
|
780
|
+
var updateStatus = function updateStatus(self) {
|
|
781
781
|
|
|
782
782
|
_.each(self.snapshots, function(snapshot) {
|
|
783
783
|
|
|
784
784
|
if(!snapshot) return;
|
|
785
785
|
|
|
786
|
-
var
|
|
786
|
+
var needsReview = snapshot.managedServices || snapshot.review;
|
|
787
787
|
var isSubmitted = snapshot.submittedOn;
|
|
788
788
|
var isReviewed = snapshot.reviewedOn;
|
|
789
789
|
var isRejected = snapshot.rejection;
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (isManagedServices && isReviewed)) {
|
|
793
|
-
snapshot.status = 'Completed';
|
|
794
|
-
snapshot.action = null;
|
|
795
|
-
}
|
|
790
|
+
var isArchived = snapshot.archivedOn;
|
|
791
|
+
var isOverdue = moment(new Date()).isAfter(moment(snapshot.dueOn));
|
|
796
792
|
|
|
797
|
-
|
|
793
|
+
var isOpened = false;
|
|
794
|
+
var isDelivered = false;
|
|
795
|
+
if(snapshot.notifications && snapshot.notifications.company && snapshot.notifications.company.initial) {
|
|
796
|
+
isOpened = snapshot.notifications.company.initial.status && snapshot.notifications.company.initial.status == 'Opened' || snapshot.notifications.company.initial.status == 'Clicked';
|
|
797
|
+
isDelivered = snapshot.notifications.company.initial.sentOn;
|
|
798
|
+
}
|
|
798
799
|
|
|
799
|
-
|
|
800
|
+
if(!snapshot.uuid) snapshot.status = 'Completed'; // no uuid means the snapshot was created from the google sheet and should always be completed
|
|
801
|
+
else if(needsReview && isReviewed) snapshot.status = 'Completed';
|
|
802
|
+
else if(!needsReview && isSubmitted) snapshot.status = 'Completed';
|
|
803
|
+
else if(isArchived) snapshot.status = 'Archived';
|
|
804
|
+
else if(needsReview && isSubmitted && !isReviewed) snapshot.status = 'In Review';
|
|
805
|
+
else if(isOverdue) snapshot.status = 'Overdue';
|
|
806
|
+
else if(isDelivered && isOpened) snapshot.status = 'Opened';
|
|
807
|
+
else if(isDelivered) snapshot.status = 'Delivered';
|
|
800
808
|
|
|
801
|
-
|
|
802
|
-
var isOverdue = latestReminder.sendOn && moment().subtract(14, 'd').isAfter(moment(latestReminder.sendOn));
|
|
809
|
+
});
|
|
803
810
|
|
|
804
|
-
|
|
805
|
-
snapshot.status = 'Scheduled';
|
|
806
|
-
snapshot.action = null;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
else if(isOverdue) {
|
|
810
|
-
snapshot.status = 'Overdue';
|
|
811
|
-
snapshot.action = null;
|
|
812
|
-
}
|
|
811
|
+
};
|
|
813
812
|
|
|
814
|
-
|
|
815
|
-
snapshot.status = 'In Progress';
|
|
816
|
-
if(isManagedServices && isSubmitted && !isRejected) snapshot.action = 'Review';
|
|
817
|
-
else if(isManagedServices && isSubmitted && isRejected) snapshot.action = 'Rejected';
|
|
818
|
-
else if(latestReminder.sentOn) snapshot.action = latestReminder.status;
|
|
819
|
-
else snapshot.action = snapshot.notifications.company.initial.status;
|
|
820
|
-
}
|
|
813
|
+
Financials.pre('init', function(next) {
|
|
821
814
|
|
|
822
|
-
|
|
815
|
+
var self = this;
|
|
816
|
+
updateStatus(self);
|
|
823
817
|
|
|
824
|
-
|
|
825
|
-
snapshot.status = 'Not Scheduled';
|
|
826
|
-
snapshot.action = null;
|
|
827
|
-
}
|
|
818
|
+
return next();
|
|
828
819
|
|
|
829
|
-
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
Financials.pre('save', function(next) {
|
|
823
|
+
|
|
824
|
+
var self = this;
|
|
825
|
+
updateStatus(self);
|
|
830
826
|
|
|
831
827
|
return next();
|
|
832
828
|
|
|
833
829
|
});
|
|
834
|
-
|
|
830
|
+
|
|
835
831
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
836
832
|
// CONFIG
|
|
837
833
|
///////////////////////////////////////////////////////////////////////////////////////
|