{"action":"created","comment":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments/41129773","id":41129773,"diff_hunk":"@@ -0,0 +1,125 @@\n+/* Budget controller */\n+'use strict';\n+\n+var csv    = require('fast-csv'),\n+\tfs     = require('fs'),\n+\tq      = require('q');\n+\n+var config = require('../config/environment/server'),\n+\tdb     = require('../lib/db');\n+\t\n+var uploadDir = config.uploadFolder;\n+\n+module.exports = {\n+\tupdate : updateBudget,\n+\tupload : uploadedFile\n+};\n+\n+function uploadedFile(req, res, next) {\n+\t/*\n+\t\t* Objectif : handling the uploaded file and generate an array (csvArray) from the file\n+\t*/\n+\tvar csvArray = [];\n+\tvar file = req.files.file;\n+\tvar fiscal_year_id = req.body.fiscal_year_id;\n+\tvar period = JSON.parse(req.body.period);\n+\n+\tif (file && file.path && file.name) {\n+\t\tvar fileName = uploadDir + file.name.replace(/ /g, '_');\n+\n+\t\t// File name can be more readable\n+\t\tfs.rename(file.path, fileName, function (err) {\n+\t\t\tif (err) { throw err; }\n+\t\t\tfs.stat(fileName, function (err, stat) {\n+\t\t\t\tif (err) { throw err; }\n+\t\t\t\tcsv.fromPath(fileName, {headers: true})\n+\t\t\t\t.on('data', function (data) {\n+\t\t\t\t\tcsvArray.push(data);\n+\t\t\t\t})\n+\t\t\t\t.on('end', function () {\n+\t\t\t\t\tcreateBudget(csvArray, fiscal_year_id, period);\n+\t\t\t\t\tres.status(200).send('uploaded');\n+\t\t\t\t});\n+\t\t\t});\n+\t\t});\n+\t} \n+}\n+\n+function createBudget(csvArray, fiscal_year_id, period) {\n+\n+\t/*\n+\t\t* Objectif : create a new budget via params given\n+\t\t* Params : \n+\t\t*\t- csvArray : an array of the budget csv file\n+\t\t* - fiscal_year_id : the fiscal year id\n+\t\t* - period : the period\n+\t*/\n+\n+\tif (csvArray.length) {\n+\n+\t\tif (period.period_number === 0) {\n+\t\t\t// Budget for the fiscal year\n+\t\t\tvar queryPeriods = 'SELECT period.id, period.period_number FROM period WHERE period.fiscal_year_id = ? ';\n+\t\t\tdb.exec(queryPeriods, [fiscal_year_id])","path":"server/controllers/budget.js","position":63,"original_position":63,"commit_id":"7572720d53a8cfe5a3325a5ff1a6bb583fb2637f","original_commit_id":"7572720d53a8cfe5a3325a5ff1a6bb583fb2637f","user":{"login":"jniles","id":896472,"avatar_url":"https://avatars.githubusercontent.com/u/896472?v=3","gravatar_id":"","url":"https://api.github.com/users/jniles","html_url":"https://github.com/jniles","followers_url":"https://api.github.com/users/jniles/followers","following_url":"https://api.github.com/users/jniles/following{/other_user}","gists_url":"https://api.github.com/users/jniles/gists{/gist_id}","starred_url":"https://api.github.com/users/jniles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jniles/subscriptions","organizations_url":"https://api.github.com/users/jniles/orgs","repos_url":"https://api.github.com/users/jniles/repos","events_url":"https://api.github.com/users/jniles/events{/privacy}","received_events_url":"https://api.github.com/users/jniles/received_events","type":"User","site_admin":false},"body":"Where is the `catch()` statement for promise?  Is there any chance that an error could occur?","created_at":"2015-10-05T10:34:16Z","updated_at":"2015-10-05T10:34:16Z","html_url":"https://github.com/IMA-WorldHealth/bhima/pull/776#discussion_r41129773","pull_request_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776","_links":{"self":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments/41129773"},"html":{"href":"https://github.com/IMA-WorldHealth/bhima/pull/776#discussion_r41129773"},"pull_request":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776"}}},"pull_request":{"url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776","id":46398480,"html_url":"https://github.com/IMA-WorldHealth/bhima/pull/776","diff_url":"https://github.com/IMA-WorldHealth/bhima/pull/776.diff","patch_url":"https://github.com/IMA-WorldHealth/bhima/pull/776.patch","issue_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/776","number":776,"state":"open","locked":false,"title":"Budget importation via csv","user":{"login":"mbayopanda","id":5445251,"avatar_url":"https://avatars.githubusercontent.com/u/5445251?v=3","gravatar_id":"","url":"https://api.github.com/users/mbayopanda","html_url":"https://github.com/mbayopanda","followers_url":"https://api.github.com/users/mbayopanda/followers","following_url":"https://api.github.com/users/mbayopanda/following{/other_user}","gists_url":"https://api.github.com/users/mbayopanda/gists{/gist_id}","starred_url":"https://api.github.com/users/mbayopanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbayopanda/subscriptions","organizations_url":"https://api.github.com/users/mbayopanda/orgs","repos_url":"https://api.github.com/users/mbayopanda/repos","events_url":"https://api.github.com/users/mbayopanda/events{/privacy}","received_events_url":"https://api.github.com/users/mbayopanda/received_events","type":"User","site_admin":false},"body":"In this PR : \r\n- We use : \r\n  - npm modules : \"fast-csv\", \"connect-multiparty\" \r\n  - angular module : \"ng-file-upload\"\r\n\r\nThe main task in this PR is to import budget from csv file, and make the imported budget the new budget of the enterprise.\r\n\r\nWe have to : \r\n- make \"npm install\" for installing 'fast-csv' and 'connect-multiparty'\r\n- make \"bower install\" for installing 'ng-file-upload'\r\n\r\nIn this PR, i fixed some codes in budget analysis : \r\n- The label of the csv file generated\r\n- The ui of budget analysis for harmony with \"budget management\"","created_at":"2015-09-30T13:03:32Z","updated_at":"2015-10-05T10:34:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1933647de5cc6049742b7bd9bfb14482dd280d49","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776/commits","review_comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776/comments","review_comment_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments{/number}","comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/776/comments","statuses_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/statuses/7572720d53a8cfe5a3325a5ff1a6bb583fb2637f","head":{"label":"mbayopanda:features/budget_creation","ref":"features/budget_creation","sha":"7572720d53a8cfe5a3325a5ff1a6bb583fb2637f","user":{"login":"mbayopanda","id":5445251,"avatar_url":"https://avatars.githubusercontent.com/u/5445251?v=3","gravatar_id":"","url":"https://api.github.com/users/mbayopanda","html_url":"https://github.com/mbayopanda","followers_url":"https://api.github.com/users/mbayopanda/followers","following_url":"https://api.github.com/users/mbayopanda/following{/other_user}","gists_url":"https://api.github.com/users/mbayopanda/gists{/gist_id}","starred_url":"https://api.github.com/users/mbayopanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbayopanda/subscriptions","organizations_url":"https://api.github.com/users/mbayopanda/orgs","repos_url":"https://api.github.com/users/mbayopanda/repos","events_url":"https://api.github.com/users/mbayopanda/events{/privacy}","received_events_url":"https://api.github.com/users/mbayopanda/received_events","type":"User","site_admin":false},"repo":{"id":22832403,"name":"bhima","full_name":"mbayopanda/bhima","owner":{"login":"mbayopanda","id":5445251,"avatar_url":"https://avatars.githubusercontent.com/u/5445251?v=3","gravatar_id":"","url":"https://api.github.com/users/mbayopanda","html_url":"https://github.com/mbayopanda","followers_url":"https://api.github.com/users/mbayopanda/followers","following_url":"https://api.github.com/users/mbayopanda/following{/other_user}","gists_url":"https://api.github.com/users/mbayopanda/gists{/gist_id}","starred_url":"https://api.github.com/users/mbayopanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbayopanda/subscriptions","organizations_url":"https://api.github.com/users/mbayopanda/orgs","repos_url":"https://api.github.com/users/mbayopanda/repos","events_url":"https://api.github.com/users/mbayopanda/events{/privacy}","received_events_url":"https://api.github.com/users/mbayopanda/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mbayopanda/bhima","description":"Continuation of the Bika HIS project with an Angular core.","fork":true,"url":"https://api.github.com/repos/mbayopanda/bhima","forks_url":"https://api.github.com/repos/mbayopanda/bhima/forks","keys_url":"https://api.github.com/repos/mbayopanda/bhima/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mbayopanda/bhima/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mbayopanda/bhima/teams","hooks_url":"https://api.github.com/repos/mbayopanda/bhima/hooks","issue_events_url":"https://api.github.com/repos/mbayopanda/bhima/issues/events{/number}","events_url":"https://api.github.com/repos/mbayopanda/bhima/events","assignees_url":"https://api.github.com/repos/mbayopanda/bhima/assignees{/user}","branches_url":"https://api.github.com/repos/mbayopanda/bhima/branches{/branch}","tags_url":"https://api.github.com/repos/mbayopanda/bhima/tags","blobs_url":"https://api.github.com/repos/mbayopanda/bhima/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mbayopanda/bhima/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mbayopanda/bhima/git/refs{/sha}","trees_url":"https://api.github.com/repos/mbayopanda/bhima/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mbayopanda/bhima/statuses/{sha}","languages_url":"https://api.github.com/repos/mbayopanda/bhima/languages","stargazers_url":"https://api.github.com/repos/mbayopanda/bhima/stargazers","contributors_url":"https://api.github.com/repos/mbayopanda/bhima/contributors","subscribers_url":"https://api.github.com/repos/mbayopanda/bhima/subscribers","subscription_url":"https://api.github.com/repos/mbayopanda/bhima/subscription","commits_url":"https://api.github.com/repos/mbayopanda/bhima/commits{/sha}","git_commits_url":"https://api.github.com/repos/mbayopanda/bhima/git/commits{/sha}","comments_url":"https://api.github.com/repos/mbayopanda/bhima/comments{/number}","issue_comment_url":"https://api.github.com/repos/mbayopanda/bhima/issues/comments{/number}","contents_url":"https://api.github.com/repos/mbayopanda/bhima/contents/{+path}","compare_url":"https://api.github.com/repos/mbayopanda/bhima/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mbayopanda/bhima/merges","archive_url":"https://api.github.com/repos/mbayopanda/bhima/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mbayopanda/bhima/downloads","issues_url":"https://api.github.com/repos/mbayopanda/bhima/issues{/number}","pulls_url":"https://api.github.com/repos/mbayopanda/bhima/pulls{/number}","milestones_url":"https://api.github.com/repos/mbayopanda/bhima/milestones{/number}","notifications_url":"https://api.github.com/repos/mbayopanda/bhima/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mbayopanda/bhima/labels{/name}","releases_url":"https://api.github.com/repos/mbayopanda/bhima/releases{/id}","created_at":"2014-08-11T08:40:29Z","updated_at":"2015-03-26T15:23:36Z","pushed_at":"2015-10-05T09:36:57Z","git_url":"git://github.com/mbayopanda/bhima.git","ssh_url":"git@github.com:mbayopanda/bhima.git","clone_url":"https://github.com/mbayopanda/bhima.git","svn_url":"https://github.com/mbayopanda/bhima","homepage":null,"size":101121,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"IMA-WorldHealth:development","ref":"development","sha":"96818952ebd5621d2b16ae3cb8b047c5586b5d4e","user":{"login":"IMA-WorldHealth","id":5330583,"avatar_url":"https://avatars.githubusercontent.com/u/5330583?v=3","gravatar_id":"","url":"https://api.github.com/users/IMA-WorldHealth","html_url":"https://github.com/IMA-WorldHealth","followers_url":"https://api.github.com/users/IMA-WorldHealth/followers","following_url":"https://api.github.com/users/IMA-WorldHealth/following{/other_user}","gists_url":"https://api.github.com/users/IMA-WorldHealth/gists{/gist_id}","starred_url":"https://api.github.com/users/IMA-WorldHealth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IMA-WorldHealth/subscriptions","organizations_url":"https://api.github.com/users/IMA-WorldHealth/orgs","repos_url":"https://api.github.com/users/IMA-WorldHealth/repos","events_url":"https://api.github.com/users/IMA-WorldHealth/events{/privacy}","received_events_url":"https://api.github.com/users/IMA-WorldHealth/received_events","type":"Organization","site_admin":false},"repo":{"id":15043926,"name":"bhima","full_name":"IMA-WorldHealth/bhima","owner":{"login":"IMA-WorldHealth","id":5330583,"avatar_url":"https://avatars.githubusercontent.com/u/5330583?v=3","gravatar_id":"","url":"https://api.github.com/users/IMA-WorldHealth","html_url":"https://github.com/IMA-WorldHealth","followers_url":"https://api.github.com/users/IMA-WorldHealth/followers","following_url":"https://api.github.com/users/IMA-WorldHealth/following{/other_user}","gists_url":"https://api.github.com/users/IMA-WorldHealth/gists{/gist_id}","starred_url":"https://api.github.com/users/IMA-WorldHealth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IMA-WorldHealth/subscriptions","organizations_url":"https://api.github.com/users/IMA-WorldHealth/orgs","repos_url":"https://api.github.com/users/IMA-WorldHealth/repos","events_url":"https://api.github.com/users/IMA-WorldHealth/events{/privacy}","received_events_url":"https://api.github.com/users/IMA-WorldHealth/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IMA-WorldHealth/bhima","description":"A hospital information system for developing countries.","fork":false,"url":"https://api.github.com/repos/IMA-WorldHealth/bhima","forks_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/forks","keys_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/teams","hooks_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/hooks","issue_events_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/events{/number}","events_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/events","assignees_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/assignees{/user}","branches_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/branches{/branch}","tags_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/tags","blobs_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/refs{/sha}","trees_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/statuses/{sha}","languages_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/languages","stargazers_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/stargazers","contributors_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/contributors","subscribers_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/subscribers","subscription_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/subscription","commits_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/commits{/sha}","git_commits_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/git/commits{/sha}","comments_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/comments{/number}","issue_comment_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/comments{/number}","contents_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/contents/{+path}","compare_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/merges","archive_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/downloads","issues_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues{/number}","pulls_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls{/number}","milestones_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/milestones{/number}","notifications_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/labels{/name}","releases_url":"https://api.github.com/repos/IMA-WorldHealth/bhima/releases{/id}","created_at":"2013-12-09T10:07:16Z","updated_at":"2015-08-26T12:16:26Z","pushed_at":"2015-10-05T10:12:12Z","git_url":"git://github.com/IMA-WorldHealth/bhima.git","ssh_url":"git@github.com:IMA-WorldHealth/bhima.git","clone_url":"https://github.com/IMA-WorldHealth/bhima.git","svn_url":"https://github.com/IMA-WorldHealth/bhima","homepage":"","size":104405,"stargazers_count":6,"watchers_count":6,"language":"Groff","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":82,"forks":10,"open_issues":82,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776"},"html":{"href":"https://github.com/IMA-WorldHealth/bhima/pull/776"},"issue":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/776"},"comments":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/issues/776/comments"},"review_comments":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776/comments"},"review_comment":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/pulls/776/commits"},"statuses":{"href":"https://api.github.com/repos/IMA-WorldHealth/bhima/statuses/7572720d53a8cfe5a3325a5ff1a6bb583fb2637f"}}}}