{"action":"created","comment":{"url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/comments/65655219","id":65655219,"diff_hunk":"@@ -5,16 +5,85 @@\n use Illuminate\\Http\\Request;\n use App\\Http\\Requests;\n use App\\Http\\Controllers\\Controller;\n+use App\\Models\\Backend\\Order;\n+use DB;\n \n class DashboardController extends Controller\n {\n     /**\n      * Index admmin\n      *\n+     * @param string $condition this is of group by\n+     *\n+     * @return view index of admin\n+     */\n+    public function index($condition = 'DAYNAME')\n+    {\n+        // create array save data report\n+        $data = array();\n+\n+        // check condition group by.\n+        // only group by with condition = DAYNAME or MONTHNAME of created_at\n+        // if condition != DAYNAME or MONTHNAME then group by with DAYNAME\n+        if ($condition == 'DAYNAME' or $condition == 'MONTHNAME') {\n+            $data['order']   = $this->getReportOrder($condition);\n+            $data['user']    = $this->getReportUser($condition);\n+            $data['product'] = $this->getReportProduct($condition);\n+        } else {\n+            $data['order']   = $this->getReportOrder('DAYNAME');\n+            $data['user']    = $this->getReportUser('DAYNAME');\n+            $data['product'] = $this->getReportProduct('DAYNAME');\n+        }\n+        \n+        return view('backend.dashboard.index', compact('data'));\n+    }\n+\n+    /**\n+     * Get report order with condition\n+     *\n+     * @param string $con is condition of group by (DAYNAME or MONTHNAME)\n+     *\n+     * @return view index of admin\n+     */\n+    private function getReportOrder($con)\n+    {\n+        return Order::selectRaw(\"$con(created_at) as $con, sum(total_price) as total\")\n+                    ->groupBy(DB::raw(\"$con(created_at)\"))\n+                    ->get()->toArray();\n+    }\n+\n+    /**\n+     * Get report user with condition\n+     *\n+     * @param string $con is condition of group by (DAYNAME or MONTHNAME)\n+     *\n+     * @return view index of admin\n+     */\n+    private function getReportUser($con)\n+    {\n+        return DB::table('orders')\n+            ->selectRaw(\"name, sum(total_price) as total, $con(orders.created_at) as date\")\n+            ->join('users', 'orders.user_id', '=', 'users.id')\n+            ->groupBy(DB::raw(\"$con(orders.created_at)\"), 'orders.user_id')\n+            ->orderBy(DB::raw(\"sum(total_price)\"), 'desc')\n+            ->take(3)->get();","path":"app/Http/Controllers/Backend/DashboardController.php","position":65,"original_position":65,"commit_id":"3c53b17070295c8bb2ac5ae3e9bac471aecadcf6","original_commit_id":"3c53b17070295c8bb2ac5ae3e9bac471aecadcf6","user":{"login":"at-tuanpn","id":18674807,"avatar_url":"https://avatars.githubusercontent.com/u/18674807?v=3","gravatar_id":"","url":"https://api.github.com/users/at-tuanpn","html_url":"https://github.com/at-tuanpn","followers_url":"https://api.github.com/users/at-tuanpn/followers","following_url":"https://api.github.com/users/at-tuanpn/following{/other_user}","gists_url":"https://api.github.com/users/at-tuanpn/gists{/gist_id}","starred_url":"https://api.github.com/users/at-tuanpn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/at-tuanpn/subscriptions","organizations_url":"https://api.github.com/users/at-tuanpn/orgs","repos_url":"https://api.github.com/users/at-tuanpn/repos","events_url":"https://api.github.com/users/at-tuanpn/events{/privacy}","received_events_url":"https://api.github.com/users/at-tuanpn/received_events","type":"User","site_admin":false},"body":"take(3) means:\r\nI want get top 3 user with most orders.","created_at":"2016-06-03T04:24:11Z","updated_at":"2016-06-03T04:24:11Z","html_url":"https://github.com/AT-PHPIntership/phone-ec/pull/101#discussion_r65655219","pull_request_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101","_links":{"self":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/comments/65655219"},"html":{"href":"https://github.com/AT-PHPIntership/phone-ec/pull/101#discussion_r65655219"},"pull_request":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101"}}},"pull_request":{"url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101","id":72447352,"html_url":"https://github.com/AT-PHPIntership/phone-ec/pull/101","diff_url":"https://github.com/AT-PHPIntership/phone-ec/pull/101.diff","patch_url":"https://github.com/AT-PHPIntership/phone-ec/pull/101.patch","issue_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/101","number":101,"state":"open","locked":false,"title":"Function Report","user":{"login":"at-tuanpn","id":18674807,"avatar_url":"https://avatars.githubusercontent.com/u/18674807?v=3","gravatar_id":"","url":"https://api.github.com/users/at-tuanpn","html_url":"https://github.com/at-tuanpn","followers_url":"https://api.github.com/users/at-tuanpn/followers","following_url":"https://api.github.com/users/at-tuanpn/following{/other_user}","gists_url":"https://api.github.com/users/at-tuanpn/gists{/gist_id}","starred_url":"https://api.github.com/users/at-tuanpn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/at-tuanpn/subscriptions","organizations_url":"https://api.github.com/users/at-tuanpn/orgs","repos_url":"https://api.github.com/users/at-tuanpn/repos","events_url":"https://api.github.com/users/at-tuanpn/events{/privacy}","received_events_url":"https://api.github.com/users/at-tuanpn/received_events","type":"User","site_admin":false},"body":"I finished function report with order.\r\n@at-dungnh Please review for me.","created_at":"2016-06-03T02:56:26Z","updated_at":"2016-06-03T04:24:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c0b4c330e3853a0bca99f7e72e86d8efac2e705e","assignee":{"login":"at-dungnh","id":12025853,"avatar_url":"https://avatars.githubusercontent.com/u/12025853?v=3","gravatar_id":"","url":"https://api.github.com/users/at-dungnh","html_url":"https://github.com/at-dungnh","followers_url":"https://api.github.com/users/at-dungnh/followers","following_url":"https://api.github.com/users/at-dungnh/following{/other_user}","gists_url":"https://api.github.com/users/at-dungnh/gists{/gist_id}","starred_url":"https://api.github.com/users/at-dungnh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/at-dungnh/subscriptions","organizations_url":"https://api.github.com/users/at-dungnh/orgs","repos_url":"https://api.github.com/users/at-dungnh/repos","events_url":"https://api.github.com/users/at-dungnh/events{/privacy}","received_events_url":"https://api.github.com/users/at-dungnh/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101/commits","review_comments_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101/comments","review_comment_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/101/comments","statuses_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/statuses/3c53b17070295c8bb2ac5ae3e9bac471aecadcf6","head":{"label":"AT-PHPIntership:Report","ref":"Report","sha":"3c53b17070295c8bb2ac5ae3e9bac471aecadcf6","user":{"login":"AT-PHPIntership","id":17865237,"avatar_url":"https://avatars.githubusercontent.com/u/17865237?v=3","gravatar_id":"","url":"https://api.github.com/users/AT-PHPIntership","html_url":"https://github.com/AT-PHPIntership","followers_url":"https://api.github.com/users/AT-PHPIntership/followers","following_url":"https://api.github.com/users/AT-PHPIntership/following{/other_user}","gists_url":"https://api.github.com/users/AT-PHPIntership/gists{/gist_id}","starred_url":"https://api.github.com/users/AT-PHPIntership/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AT-PHPIntership/subscriptions","organizations_url":"https://api.github.com/users/AT-PHPIntership/orgs","repos_url":"https://api.github.com/users/AT-PHPIntership/repos","events_url":"https://api.github.com/users/AT-PHPIntership/events{/privacy}","received_events_url":"https://api.github.com/users/AT-PHPIntership/received_events","type":"Organization","site_admin":false},"repo":{"id":56130148,"name":"phone-ec","full_name":"AT-PHPIntership/phone-ec","owner":{"login":"AT-PHPIntership","id":17865237,"avatar_url":"https://avatars.githubusercontent.com/u/17865237?v=3","gravatar_id":"","url":"https://api.github.com/users/AT-PHPIntership","html_url":"https://github.com/AT-PHPIntership","followers_url":"https://api.github.com/users/AT-PHPIntership/followers","following_url":"https://api.github.com/users/AT-PHPIntership/following{/other_user}","gists_url":"https://api.github.com/users/AT-PHPIntership/gists{/gist_id}","starred_url":"https://api.github.com/users/AT-PHPIntership/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AT-PHPIntership/subscriptions","organizations_url":"https://api.github.com/users/AT-PHPIntership/orgs","repos_url":"https://api.github.com/users/AT-PHPIntership/repos","events_url":"https://api.github.com/users/AT-PHPIntership/events{/privacy}","received_events_url":"https://api.github.com/users/AT-PHPIntership/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AT-PHPIntership/phone-ec","description":"Simple EC site","fork":false,"url":"https://api.github.com/repos/AT-PHPIntership/phone-ec","forks_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/forks","keys_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/teams","hooks_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/hooks","issue_events_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/events{/number}","events_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/events","assignees_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/assignees{/user}","branches_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/branches{/branch}","tags_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/tags","blobs_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/refs{/sha}","trees_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/statuses/{sha}","languages_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/languages","stargazers_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/stargazers","contributors_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/contributors","subscribers_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/subscribers","subscription_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/subscription","commits_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/commits{/sha}","git_commits_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/commits{/sha}","comments_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/comments{/number}","issue_comment_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/comments{/number}","contents_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/contents/{+path}","compare_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/merges","archive_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/downloads","issues_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues{/number}","pulls_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls{/number}","milestones_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/milestones{/number}","notifications_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/labels{/name}","releases_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/releases{/id}","deployments_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/deployments","created_at":"2016-04-13T07:23:00Z","updated_at":"2016-05-23T02:34:08Z","pushed_at":"2016-06-03T03:04:15Z","git_url":"git://github.com/AT-PHPIntership/phone-ec.git","ssh_url":"git@github.com:AT-PHPIntership/phone-ec.git","clone_url":"https://github.com/AT-PHPIntership/phone-ec.git","svn_url":"https://github.com/AT-PHPIntership/phone-ec","homepage":"","size":4368,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":53,"forks":0,"open_issues":53,"watchers":0,"default_branch":"master"}},"base":{"label":"AT-PHPIntership:master","ref":"master","sha":"fc7b81070f72bfb3611d255bd3d78f89638753b4","user":{"login":"AT-PHPIntership","id":17865237,"avatar_url":"https://avatars.githubusercontent.com/u/17865237?v=3","gravatar_id":"","url":"https://api.github.com/users/AT-PHPIntership","html_url":"https://github.com/AT-PHPIntership","followers_url":"https://api.github.com/users/AT-PHPIntership/followers","following_url":"https://api.github.com/users/AT-PHPIntership/following{/other_user}","gists_url":"https://api.github.com/users/AT-PHPIntership/gists{/gist_id}","starred_url":"https://api.github.com/users/AT-PHPIntership/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AT-PHPIntership/subscriptions","organizations_url":"https://api.github.com/users/AT-PHPIntership/orgs","repos_url":"https://api.github.com/users/AT-PHPIntership/repos","events_url":"https://api.github.com/users/AT-PHPIntership/events{/privacy}","received_events_url":"https://api.github.com/users/AT-PHPIntership/received_events","type":"Organization","site_admin":false},"repo":{"id":56130148,"name":"phone-ec","full_name":"AT-PHPIntership/phone-ec","owner":{"login":"AT-PHPIntership","id":17865237,"avatar_url":"https://avatars.githubusercontent.com/u/17865237?v=3","gravatar_id":"","url":"https://api.github.com/users/AT-PHPIntership","html_url":"https://github.com/AT-PHPIntership","followers_url":"https://api.github.com/users/AT-PHPIntership/followers","following_url":"https://api.github.com/users/AT-PHPIntership/following{/other_user}","gists_url":"https://api.github.com/users/AT-PHPIntership/gists{/gist_id}","starred_url":"https://api.github.com/users/AT-PHPIntership/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AT-PHPIntership/subscriptions","organizations_url":"https://api.github.com/users/AT-PHPIntership/orgs","repos_url":"https://api.github.com/users/AT-PHPIntership/repos","events_url":"https://api.github.com/users/AT-PHPIntership/events{/privacy}","received_events_url":"https://api.github.com/users/AT-PHPIntership/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AT-PHPIntership/phone-ec","description":"Simple EC site","fork":false,"url":"https://api.github.com/repos/AT-PHPIntership/phone-ec","forks_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/forks","keys_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/teams","hooks_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/hooks","issue_events_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/events{/number}","events_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/events","assignees_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/assignees{/user}","branches_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/branches{/branch}","tags_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/tags","blobs_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/refs{/sha}","trees_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/statuses/{sha}","languages_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/languages","stargazers_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/stargazers","contributors_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/contributors","subscribers_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/subscribers","subscription_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/subscription","commits_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/commits{/sha}","git_commits_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/git/commits{/sha}","comments_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/comments{/number}","issue_comment_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/comments{/number}","contents_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/contents/{+path}","compare_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/merges","archive_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/downloads","issues_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues{/number}","pulls_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls{/number}","milestones_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/milestones{/number}","notifications_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/labels{/name}","releases_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/releases{/id}","deployments_url":"https://api.github.com/repos/AT-PHPIntership/phone-ec/deployments","created_at":"2016-04-13T07:23:00Z","updated_at":"2016-05-23T02:34:08Z","pushed_at":"2016-06-03T03:04:15Z","git_url":"git://github.com/AT-PHPIntership/phone-ec.git","ssh_url":"git@github.com:AT-PHPIntership/phone-ec.git","clone_url":"https://github.com/AT-PHPIntership/phone-ec.git","svn_url":"https://github.com/AT-PHPIntership/phone-ec","homepage":"","size":4368,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":53,"forks":0,"open_issues":53,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101"},"html":{"href":"https://github.com/AT-PHPIntership/phone-ec/pull/101"},"issue":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/101"},"comments":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/issues/101/comments"},"review_comments":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101/comments"},"review_comment":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/pulls/101/commits"},"statuses":{"href":"https://api.github.com/repos/AT-PHPIntership/phone-ec/statuses/3c53b17070295c8bb2ac5ae3e9bac471aecadcf6"}}}}
{"actor":{"display_login":"at-tuanpn"}}