Making WordPress.org

Changeset 4899


Ignore:
Timestamp:
02/10/2017 01:26:17 AM (8 years ago)
Author:
coreymckrill
Message:

Budget Tool: Correctly calculate Cost Per Person Per Day

The formula wasn't taking into account the number of days the event lasted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/budget-tool.js

    r3857 r4899  
    100100
    101101        render: function() {
    102             var data = {
    103                 'income': 0,
    104                 'expenses': 0,
    105                 'variance': 0,
    106                 'variance_raw': 0,
    107                 'per_person': 0
    108             };
     102            var attendees = wcb.table.collection.findWhere({type: 'meta', name: 'attendees'}),
     103                days      = wcb.table.collection.findWhere({type: 'meta', name: 'days'}),
     104                data = {
     105                    'income': 0,
     106                    'expenses': 0,
     107                    'variance': 0,
     108                    'variance_raw': 0,
     109                    'per_person': 0
     110                };
    109111
    110112            _.each(wcb.table.collection.where({type: 'income'}), function(item) {
     
    118120            data['variance'] = data['income'] - data['expenses'];
    119121            data['variance_raw'] = data['variance'];
    120             var attendees = wcb.table.collection.findWhere({type: 'meta', name: 'attendees'});
    121             data['per_person'] = attendees ? data['expenses'] / attendees.get('value') : 0;
     122            data['per_person'] = (attendees && days) ? data['expenses'] / attendees.get('value') / days.get('value'): 0;
    122123
    123124            data = _.mapObject(data, function(v, k) {
Note: See TracChangeset for help on using the changeset viewer.