{"action":"created","comment":{"url":"https://api.github.com/repos/civicrm/civihr/pulls/comments/135763370","pull_request_review_id":59210308,"id":135763370,"diff_hunk":"@@ -314,6 +316,21 @@ define([\n     }\n \n     /**\n+     * Initialize the original opening balance when in edit mode. This allows\n+     * to display the opening balance before the request was created. The\n+     * formula is absence type reminder + balance change (balance change is a\n+     * negative number so it needs to be subtracted).\n+     */\n+    function initOriginalOpeningBalance () {\n+      if (vm.isMode('edit')) {","path":"uk.co.compucorp.civicrm.hrleaveandabsences/js/angular/src/leave-absences/shared/components/leave-request-popup-details-tab.component.js","position":26,"original_position":26,"commit_id":"523f31385924eb3c647cddefca96062ec9d5efcb","original_commit_id":"523f31385924eb3c647cddefca96062ec9d5efcb","user":{"login":"deb1990","id":5058867,"avatar_url":"https://avatars1.githubusercontent.com/u/5058867?v=4","gravatar_id":"","url":"https://api.github.com/users/deb1990","html_url":"https://github.com/deb1990","followers_url":"https://api.github.com/users/deb1990/followers","following_url":"https://api.github.com/users/deb1990/following{/other_user}","gists_url":"https://api.github.com/users/deb1990/gists{/gist_id}","starred_url":"https://api.github.com/users/deb1990/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deb1990/subscriptions","organizations_url":"https://api.github.com/users/deb1990/orgs","repos_url":"https://api.github.com/users/deb1990/repos","events_url":"https://api.github.com/users/deb1990/events{/privacy}","received_events_url":"https://api.github.com/users/deb1990/received_events","type":"User","site_admin":false},"body":"Original Opening Balance, should be saved for approved requests in edit mode only, right? Then you are not checking if it is approved request only.","created_at":"2017-08-29T11:30:43Z","updated_at":"2017-08-29T11:36:23Z","html_url":"https://github.com/civicrm/civihr/pull/2099#discussion_r135763370","pull_request_url":"https://api.github.com/repos/civicrm/civihr/pulls/2099","_links":{"self":{"href":"https://api.github.com/repos/civicrm/civihr/pulls/comments/135763370"},"html":{"href":"https://github.com/civicrm/civihr/pull/2099#discussion_r135763370"},"pull_request":{"href":"https://api.github.com/repos/civicrm/civihr/pulls/2099"}}},"pull_request":{"url":"https://api.github.com/repos/civicrm/civihr/pulls/2099","id":138071529,"html_url":"https://github.com/civicrm/civihr/pull/2099","diff_url":"https://github.com/civicrm/civihr/pull/2099.diff","patch_url":"https://github.com/civicrm/civihr/pull/2099.patch","issue_url":"https://api.github.com/repos/civicrm/civihr/issues/2099","number":2099,"state":"open","locked":false,"title":"PCHR 2471: Fix opening balance for open requests","user":{"login":"reneolivo","id":1642119,"avatar_url":"https://avatars1.githubusercontent.com/u/1642119?v=4","gravatar_id":"","url":"https://api.github.com/users/reneolivo","html_url":"https://github.com/reneolivo","followers_url":"https://api.github.com/users/reneolivo/followers","following_url":"https://api.github.com/users/reneolivo/following{/other_user}","gists_url":"https://api.github.com/users/reneolivo/gists{/gist_id}","starred_url":"https://api.github.com/users/reneolivo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reneolivo/subscriptions","organizations_url":"https://api.github.com/users/reneolivo/orgs","repos_url":"https://api.github.com/users/reneolivo/repos","events_url":"https://api.github.com/users/reneolivo/events{/privacy}","received_events_url":"https://api.github.com/users/reneolivo/received_events","type":"User","site_admin":false},"body":"## Overview\r\nWhen trying to edit an open leave request, it will display the opening balance as the remaining balance - the leave request change which leads to wrong closing balances. Example:\r\n\r\n1. The original Opening Balance was 10.\r\n2. The Balance Change was 2.\r\n3. The new Balance is 8 after the request is saved.\r\n4. When editing the request the Opening Balance will be 8 and the Closing Balance is 6. The correct values should be 10 and 8 respectively.\r\n\r\nThis PR fixes this issue as well as refactoring component initialization on test file.\r\n\r\n## Before\r\n![anim](https://user-images.githubusercontent.com/1642119/29818031-ef75ea24-8c66-11e7-8172-67ff88cc813e.gif)\r\nBalance is 9, opening balance is 9, change is 6, closing balance is 3.\r\n\r\n\r\n## After\r\n![anim](https://user-images.githubusercontent.com/1642119/29817475-983b5d68-8c64-11e7-8f04-6e5a783d2970.gif)\r\nBalance is 9, opening balance is 15, change is 6, and closing balance is 9.\r\n\r\n\r\n## Technical Details\r\nOnly when editing, an original opening balance object is created:\r\n```js\r\noriginalOpeningBalance = {\r\n   absenceTypeId: vm.request.type_id,\r\n   value: vm.selectedAbsenceType.remainder - vm.request.balance_change\r\n};\r\n```\r\nSince balance_change is negative, the value will hold the original balance before the request was created. Using the previous example this would be 9 - -6 = 9 + 6 = 15.\r\n\r\nWhen calculating the new opening and closing balances, if the selected absence types is the original one, it will use the original balance:\r\n```js\r\nif (originalOpeningBalance &&\r\noriginalOpeningBalance.absenceTypeId === vm.selectedAbsenceType.id) {\r\n   vm.balance.opening = originalOpeningBalance.value;\r\n} else {\r\n   vm.balance.opening = vm.selectedAbsenceType.remainder;\r\n}\r\n```\r\n\r\n## Comments\r\nComponents initialization for this test was refactored. Instead of calling `compileComponent` with 6 arguments, now you call it by passing 1 object argument. The benefits of this approach are two:\r\n\r\n1. No need to remember the order of the parameters as long as you remember the names.\r\n2. Defaults were set in place to ease the component initialization.\r\n\r\n---\r\n\r\n- [x] Tests Pass\r\n","created_at":"2017-08-29T01:20:49Z","updated_at":"2017-08-29T11:36:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c2e1e63fd4caa656ee9ec8912419e99689d1f353","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/civicrm/civihr/pulls/2099/commits","review_comments_url":"https://api.github.com/repos/civicrm/civihr/pulls/2099/comments","review_comment_url":"https://api.github.com/repos/civicrm/civihr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/civicrm/civihr/issues/2099/comments","statuses_url":"https://api.github.com/repos/civicrm/civihr/statuses/523f31385924eb3c647cddefca96062ec9d5efcb","head":{"label":"civicrm:PCHR-2471-fix-opening-balance-for-open-requests","ref":"PCHR-2471-fix-opening-balance-for-open-requests","sha":"523f31385924eb3c647cddefca96062ec9d5efcb","user":{"login":"civicrm","id":136373,"avatar_url":"https://avatars2.githubusercontent.com/u/136373?v=4","gravatar_id":"","url":"https://api.github.com/users/civicrm","html_url":"https://github.com/civicrm","followers_url":"https://api.github.com/users/civicrm/followers","following_url":"https://api.github.com/users/civicrm/following{/other_user}","gists_url":"https://api.github.com/users/civicrm/gists{/gist_id}","starred_url":"https://api.github.com/users/civicrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/civicrm/subscriptions","organizations_url":"https://api.github.com/users/civicrm/orgs","repos_url":"https://api.github.com/users/civicrm/repos","events_url":"https://api.github.com/users/civicrm/events{/privacy}","received_events_url":"https://api.github.com/users/civicrm/received_events","type":"Organization","site_admin":false},"repo":{"id":10086903,"name":"civihr","full_name":"civicrm/civihr","owner":{"login":"civicrm","id":136373,"avatar_url":"https://avatars2.githubusercontent.com/u/136373?v=4","gravatar_id":"","url":"https://api.github.com/users/civicrm","html_url":"https://github.com/civicrm","followers_url":"https://api.github.com/users/civicrm/followers","following_url":"https://api.github.com/users/civicrm/following{/other_user}","gists_url":"https://api.github.com/users/civicrm/gists{/gist_id}","starred_url":"https://api.github.com/users/civicrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/civicrm/subscriptions","organizations_url":"https://api.github.com/users/civicrm/orgs","repos_url":"https://api.github.com/users/civicrm/repos","events_url":"https://api.github.com/users/civicrm/events{/privacy}","received_events_url":"https://api.github.com/users/civicrm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/civicrm/civihr","description":"CiviHR","fork":false,"url":"https://api.github.com/repos/civicrm/civihr","forks_url":"https://api.github.com/repos/civicrm/civihr/forks","keys_url":"https://api.github.com/repos/civicrm/civihr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/civicrm/civihr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/civicrm/civihr/teams","hooks_url":"https://api.github.com/repos/civicrm/civihr/hooks","issue_events_url":"https://api.github.com/repos/civicrm/civihr/issues/events{/number}","events_url":"https://api.github.com/repos/civicrm/civihr/events","assignees_url":"https://api.github.com/repos/civicrm/civihr/assignees{/user}","branches_url":"https://api.github.com/repos/civicrm/civihr/branches{/branch}","tags_url":"https://api.github.com/repos/civicrm/civihr/tags","blobs_url":"https://api.github.com/repos/civicrm/civihr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/civicrm/civihr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/civicrm/civihr/git/refs{/sha}","trees_url":"https://api.github.com/repos/civicrm/civihr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/civicrm/civihr/statuses/{sha}","languages_url":"https://api.github.com/repos/civicrm/civihr/languages","stargazers_url":"https://api.github.com/repos/civicrm/civihr/stargazers","contributors_url":"https://api.github.com/repos/civicrm/civihr/contributors","subscribers_url":"https://api.github.com/repos/civicrm/civihr/subscribers","subscription_url":"https://api.github.com/repos/civicrm/civihr/subscription","commits_url":"https://api.github.com/repos/civicrm/civihr/commits{/sha}","git_commits_url":"https://api.github.com/repos/civicrm/civihr/git/commits{/sha}","comments_url":"https://api.github.com/repos/civicrm/civihr/comments{/number}","issue_comment_url":"https://api.github.com/repos/civicrm/civihr/issues/comments{/number}","contents_url":"https://api.github.com/repos/civicrm/civihr/contents/{+path}","compare_url":"https://api.github.com/repos/civicrm/civihr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/civicrm/civihr/merges","archive_url":"https://api.github.com/repos/civicrm/civihr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/civicrm/civihr/downloads","issues_url":"https://api.github.com/repos/civicrm/civihr/issues{/number}","pulls_url":"https://api.github.com/repos/civicrm/civihr/pulls{/number}","milestones_url":"https://api.github.com/repos/civicrm/civihr/milestones{/number}","notifications_url":"https://api.github.com/repos/civicrm/civihr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/civicrm/civihr/labels{/name}","releases_url":"https://api.github.com/repos/civicrm/civihr/releases{/id}","deployments_url":"https://api.github.com/repos/civicrm/civihr/deployments","created_at":"2013-05-15T20:06:06Z","updated_at":"2017-07-24T09:17:58Z","pushed_at":"2017-08-29T11:19:36Z","git_url":"git://github.com/civicrm/civihr.git","ssh_url":"git@github.com:civicrm/civihr.git","clone_url":"https://github.com/civicrm/civihr.git","svn_url":"https://github.com/civicrm/civihr","homepage":null,"size":51361,"stargazers_count":17,"watchers_count":17,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":16,"forks":34,"open_issues":16,"watchers":17,"default_branch":"staging"}},"base":{"label":"civicrm:la-milestone-3","ref":"la-milestone-3","sha":"c342fee1ee3d126acd8546209b92c12b33ede3fa","user":{"login":"civicrm","id":136373,"avatar_url":"https://avatars2.githubusercontent.com/u/136373?v=4","gravatar_id":"","url":"https://api.github.com/users/civicrm","html_url":"https://github.com/civicrm","followers_url":"https://api.github.com/users/civicrm/followers","following_url":"https://api.github.com/users/civicrm/following{/other_user}","gists_url":"https://api.github.com/users/civicrm/gists{/gist_id}","starred_url":"https://api.github.com/users/civicrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/civicrm/subscriptions","organizations_url":"https://api.github.com/users/civicrm/orgs","repos_url":"https://api.github.com/users/civicrm/repos","events_url":"https://api.github.com/users/civicrm/events{/privacy}","received_events_url":"https://api.github.com/users/civicrm/received_events","type":"Organization","site_admin":false},"repo":{"id":10086903,"name":"civihr","full_name":"civicrm/civihr","owner":{"login":"civicrm","id":136373,"avatar_url":"https://avatars2.githubusercontent.com/u/136373?v=4","gravatar_id":"","url":"https://api.github.com/users/civicrm","html_url":"https://github.com/civicrm","followers_url":"https://api.github.com/users/civicrm/followers","following_url":"https://api.github.com/users/civicrm/following{/other_user}","gists_url":"https://api.github.com/users/civicrm/gists{/gist_id}","starred_url":"https://api.github.com/users/civicrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/civicrm/subscriptions","organizations_url":"https://api.github.com/users/civicrm/orgs","repos_url":"https://api.github.com/users/civicrm/repos","events_url":"https://api.github.com/users/civicrm/events{/privacy}","received_events_url":"https://api.github.com/users/civicrm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/civicrm/civihr","description":"CiviHR","fork":false,"url":"https://api.github.com/repos/civicrm/civihr","forks_url":"https://api.github.com/repos/civicrm/civihr/forks","keys_url":"https://api.github.com/repos/civicrm/civihr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/civicrm/civihr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/civicrm/civihr/teams","hooks_url":"https://api.github.com/repos/civicrm/civihr/hooks","issue_events_url":"https://api.github.com/repos/civicrm/civihr/issues/events{/number}","events_url":"https://api.github.com/repos/civicrm/civihr/events","assignees_url":"https://api.github.com/repos/civicrm/civihr/assignees{/user}","branches_url":"https://api.github.com/repos/civicrm/civihr/branches{/branch}","tags_url":"https://api.github.com/repos/civicrm/civihr/tags","blobs_url":"https://api.github.com/repos/civicrm/civihr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/civicrm/civihr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/civicrm/civihr/git/refs{/sha}","trees_url":"https://api.github.com/repos/civicrm/civihr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/civicrm/civihr/statuses/{sha}","languages_url":"https://api.github.com/repos/civicrm/civihr/languages","stargazers_url":"https://api.github.com/repos/civicrm/civihr/stargazers","contributors_url":"https://api.github.com/repos/civicrm/civihr/contributors","subscribers_url":"https://api.github.com/repos/civicrm/civihr/subscribers","subscription_url":"https://api.github.com/repos/civicrm/civihr/subscription","commits_url":"https://api.github.com/repos/civicrm/civihr/commits{/sha}","git_commits_url":"https://api.github.com/repos/civicrm/civihr/git/commits{/sha}","comments_url":"https://api.github.com/repos/civicrm/civihr/comments{/number}","issue_comment_url":"https://api.github.com/repos/civicrm/civihr/issues/comments{/number}","contents_url":"https://api.github.com/repos/civicrm/civihr/contents/{+path}","compare_url":"https://api.github.com/repos/civicrm/civihr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/civicrm/civihr/merges","archive_url":"https://api.github.com/repos/civicrm/civihr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/civicrm/civihr/downloads","issues_url":"https://api.github.com/repos/civicrm/civihr/issues{/number}","pulls_url":"https://api.github.com/repos/civicrm/civihr/pulls{/number}","milestones_url":"https://api.github.com/repos/civicrm/civihr/milestones{/number}","notifications_url":"https://api.github.com/repos/civicrm/civihr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/civicrm/civihr/labels{/name}","releases_url":"https://api.github.com/repos/civicrm/civihr/releases{/id}","deployments_url":"https://api.github.com/repos/civicrm/civihr/deployments","created_at":"2013-05-15T20:06:06Z","updated_at":"2017-07-24T09:17:58Z","pushed_at":"2017-08-29T11:19:36Z","git_url":"git://github.com/civicrm/civihr.git","ssh_url":"git@github.com:civicrm/civihr.git","clone_url":"https://github.com/civicrm/civihr.git","svn_url":"https://github.com/civicrm/civihr","homepage":null,"size":51361,"stargazers_count":17,"watchers_count":17,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":16,"forks":34,"open_issues":16,"watchers":17,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/civicrm/civihr/pulls/2099"},"html":{"href":"https://github.com/civicrm/civihr/pull/2099"},"issue":{"href":"https://api.github.com/repos/civicrm/civihr/issues/2099"},"comments":{"href":"https://api.github.com/repos/civicrm/civihr/issues/2099/comments"},"review_comments":{"href":"https://api.github.com/repos/civicrm/civihr/pulls/2099/comments"},"review_comment":{"href":"https://api.github.com/repos/civicrm/civihr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/civicrm/civihr/pulls/2099/commits"},"statuses":{"href":"https://api.github.com/repos/civicrm/civihr/statuses/523f31385924eb3c647cddefca96062ec9d5efcb"}}}}
{"actor":{"display_login":"deb1990"}}