@dhyasama/totem-models 9.15.0 → 9.16.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.
Files changed (2) hide show
  1. package/lib/Financials.js +26 -37
  2. package/package.json +1 -1
package/lib/Financials.js CHANGED
@@ -775,63 +775,52 @@ module.exports = function(mongoose, config) {
775
775
  // Post-remove: fired on every document after it's deleted
776
776
  ///////////////////////////////////////////////////////////////////////////////////////
777
777
 
778
- Financials.pre('save', function(next) {
779
-
780
- var self = this;
778
+ var updateStatus = function updateStatus(self) {
781
779
 
782
780
  _.each(self.snapshots, function(snapshot) {
783
781
 
784
782
  if(!snapshot) return;
785
783
 
786
- var isManagedServices = snapshot.managedServices;
784
+ var needsReview = snapshot.managedServices || snapshot.review;
787
785
  var isSubmitted = snapshot.submittedOn;
788
786
  var isReviewed = snapshot.reviewedOn;
789
787
  var isRejected = snapshot.rejection;
788
+ var isArchived = snapshot.archivedOn;
789
+ var isOverdue = moment(snapshot.dueOn).isBefore(new Date());
790
+ var isOpened = snapshot.action == 'Opened' || snapshot.action == 'Clicked';
791
+ var isDelivered = snapshot.action == 'Delivered';
792
+
793
+ if(!snapshot.uuid) snapshot.status = 'Completed'; // no uuid means the snapshot was created from the google sheet and should always be completed
794
+ else if(needsReview && isReviewed) snapshot.status = 'Completed';
795
+ else if(!needsReview && isSubmitted) snapshot.status = 'Completed';
796
+ else if(needsReview && isSubmitted && !isReviewed) snapshot.status = 'In Review';
797
+ else if(isArchived) snapshot.status = 'Archived';
798
+ else if(isOverdue) snapshot.status = 'Overdue';
799
+ else if(isDelivered && isOpened) snapshot.status = 'Opened';
800
+ else snapshot.status = 'Delivered';
790
801
 
791
- // no uuid means the data was captured from the google sheet
792
- if((!snapshot.uuid) || (!isManagedServices && isSubmitted) || (isManagedServices && isReviewed)) {
793
- snapshot.status = 'Completed';
794
- snapshot.action = null;
795
- }
796
-
797
- else if(snapshot.notifications.company && snapshot.notifications.company.initial && snapshot.notifications.company.initial.sendOn) {
802
+ });
798
803
 
799
- var latestReminder = _.max(snapshot.notifications.company.reminders, function(r) { return new Date(r.sendOn); });
804
+ };
800
805
 
801
- var isScheduled = snapshot.notifications.company.initial.sendOn && moment().isBefore(moment(snapshot.notifications.company.initial.sendOn));
802
- var isOverdue = latestReminder.sendOn && moment().subtract(14, 'd').isAfter(moment(latestReminder.sendOn));
806
+ Financials.pre('init', function(next) {
803
807
 
804
- if(isScheduled) {
805
- snapshot.status = 'Scheduled';
806
- snapshot.action = null;
807
- }
808
-
809
- else if(isOverdue) {
810
- snapshot.status = 'Overdue';
811
- snapshot.action = null;
812
- }
808
+ var self = this;
809
+ updateStatus(self);
813
810
 
814
- else {
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
- }
811
+ return next();
821
812
 
822
- }
813
+ });
823
814
 
824
- else {
825
- snapshot.status = 'Not Scheduled';
826
- snapshot.action = null;
827
- }
815
+ Financials.pre('save', function(next) {
828
816
 
829
- });
817
+ var self = this;
818
+ updateStatus(self);
830
819
 
831
820
  return next();
832
821
 
833
822
  });
834
-
823
+
835
824
  ///////////////////////////////////////////////////////////////////////////////////////
836
825
  // CONFIG
837
826
  ///////////////////////////////////////////////////////////////////////////////////////
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "9.15.0",
3
+ "version": "9.16.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",