Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team Expense Reports #29

Open
bradley-holt opened this issue Jul 29, 2016 · 2 comments
Open

Team Expense Reports #29

bradley-holt opened this issue Jul 29, 2016 · 2 comments

Comments

@bradley-holt
Copy link

Allow people in a team (see #28) to view the aggregate and individual results for their team, by year and by quarter, for the following data:

  • Total expenses (both travel and non-travel)
  • Total travel expenses
  • Total non-travel expenses
  • Individual entries which contribute to the above (read only)

Note that we also want to allow team members to see team aggregate and individual results for other data as well, but that is not in scope for this feature request.

@bradley-holt
Copy link
Author

A temporary work around for this could be to provide an option to export a user's expense data to a CSV. These CSV files could then be manually aggregated.

@glynnbird
Copy link
Contributor

I created a view that outputs CSVs using a list function the structure is this:

{
  "_id": "_design/finance",
  "views": {
    "MYVIEW": {
      "map": "YOUR MAP CODE HERE"
    }
  },
  "language": "javascript",
  "lists": {
    "csv": "function (head, req) {\n  var row;\n  start({\n    headers: {  'Content-Type': 'text/csv'  },\n  });\n  var first = true;\n  while(row = getRow()) {\n    var doc = row.value;\n    if (first) {\n      send(Object.keys(doc).join(',') + '\\n');\n      first = false;\n    }\n    var line = '';\n    for(var i in doc) {\n      // comma separator\n      if (line.length > 0) {\n        line += ',';\n      }\n      \n      // output the value, ensuring values that themselves\n      // contain commas are enclosed in double quotes\n      var val = doc[i];\n      if (typeof val == 'string' && val.indexOf(',') >  -1) {\n        line += '\"' + val.replace(/\"/g,'\"\"') + '\"';\n      } else {\n        line += val;\n      }\n    }\n    line += '\\n';\n    send(line);\n  }\n}"
  }
}

You can add your view code in there too an example map function could be:

function(doc) {
  if (doc.collection === 'event') {
     var obj = {
        title: doc.title,
        userDisplayName: doc.userDisplayName
     };
     emit(doc.dtstart, obj);
  }

which emits a sub-set of the document in date order.

If you access the view with a URL of this form:

https://YOURURL/advocated2/_design/finance/_list/csv/MYVIEW

then you get a CSV file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants