Skip to content

Commit

Permalink
fix sorting estimate groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-mange committed Feb 5, 2020
1 parent ace586f commit a1abf88
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions app/templates/includes/estimates-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,9 @@ let estimatesMixin = {
// wipe and rebuild
this.estimates = [];

// attempt to create a "due date+time" using the ExpirationDate and a custom time field
_.forEach(json.estimates, (estimate) => {
let due_time = moment(this.getCustomField(estimate, 'Expiration Time'), 'h:mma');
if (due_time.isValid()) {
estimate.ExpirationDate = moment(estimate.ExpirationDate).hour(due_time.hours()).minute(due_time.minutes()).format();
}
});

// group by statuses
let statusGroups = _.groupBy(json.estimates, 'TxnStatus');

// sort estimates by due date
_.forEach(statusGroups, (group) => {
group.sort((a, b) => {
return new Date(a.ExpirationDate) - new Date(b.ExpirationDate);
});
});

// distinguish in-shop vs not-in-shop "Pending" estimates
statusGroups['Pending-In'] = [];
statusGroups['Pending-Out'] = [];
Expand All @@ -111,6 +96,24 @@ let estimatesMixin = {
// remove since we're splitting it out into two groups
delete statusGroups['Pending'];

//
// sort each group's estimates by due date
//

// attempt to create a "due date+time" using the ExpirationDate and a custom time field
_.forEach(json.estimates, (estimate) => {
let due_time = moment(this.getCustomField(estimate, 'Expiration Time'), 'h:mma');
if (due_time.isValid()) {
estimate.ExpirationDate = moment(estimate.ExpirationDate).hour(due_time.hours()).minute(due_time.minutes()).format();
}
});
// sort each group
_.forEach(statusGroups, (group) => {
group.sort((a, b) => {
return new Date(a.ExpirationDate) - new Date(b.ExpirationDate);
});
});

// build by status order preference
_.forEach(['Accepted', 'Pending-In', 'Pending-Out', 'Closed'], (status) => {
if (_.has(statusGroups, status)) {
Expand Down

0 comments on commit a1abf88

Please sign in to comment.