Skip to content

Instantly share code, notes, and snippets.

@joelhooks
Created November 17, 2013 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelhooks/7507859 to your computer and use it in GitHub Desktop.
Save joelhooks/7507859 to your computer and use it in GitHub Desktop.
$scope.subscriptions = _.map(_.sortBy(_.filter(subscriptions, function(sub) {
return sub.transactions && sub.transactions.length;
}), function(sub) {
return _.last(sub.transactions).created_at;
}), function(sub) {
var last_transaction = _.last(sub.transactions),
totals = _.reduce(sub.transactions, function (memo, t) {
return memo + t.amount/100.0;
}, 0);
return {
email: sub.user.email,
last_transaction_date: last_transaction.created_at,
last_transaction_amount: last_transaction.amount/100.0,
total_transactions: sub.transactions.length,
transactions_total: totals,
will_cancel: sub.willCancelAfterPeriod
};
}).reverse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment