{"action":"created","comment":{"url":"https://api.github.com/repos/stxnext/lunch-app/pulls/comments/24004384","id":24004384,"diff_hunk":"@@ -421,3 +449,335 @@ def company_summary_month_view(year, month):\n         orders_koziol_cost=orders_koziol_cost,\n         pub_date=pub_date,\n     )\n+\n+\n+@app.route('/finance/<int:year>/<int:month>/<int:did_pay>', methods=[\n+    'GET',\n+    'POST',\n+    ])\n+@login.login_required\n+@user_is_admin\n+def finance(year, month, did_pay):\n+    \"\"\"\n+    Renders finance page.\n+    did_pay = 0 - no filter\n+    did_pay = 1 - filter only paid\n+    did_pay = 2 - filter only unpaid\n+    \"\"\"\n+    month_begin = datetime.datetime(\n+        year=year,\n+        month=month,\n+        day=1,\n+        hour=0,\n+        minute=0,\n+        second=1\n+    )\n+    day = monthrange(year, month)[1]\n+    month_end = datetime.datetime(\n+        year=year,\n+        month=month,\n+        day=day,\n+        hour=23,\n+        minute=59,\n+        second=59\n+    )\n+    users = User.query.all()\n+    orders = Order.query.filter(\n+        and_(\n+            Order.date >= month_begin,\n+            Order.date <= month_end,\n+        )\n+    ).all()\n+    finance_data = {}\n+    for user in users:\n+        finance_data[user.username] = {\n+            'username': user.username,\n+            'number_of_orders': 0,\n+            'month_cost': 0,\n+            'did_user_pay': False,\n+        }\n+        for order in orders:\n+            if user.username == order.user_name:\n+                finance_data[user.username]['number_of_orders'] += 1\n+                finance_data[user.username]['month_cost'] += order.cost\n+        finance_query = Finance.query.filter(\n+            and_(\n+                Finance.month == month,\n+                Finance.year == year,\n+                Finance.user_name == user.username,\n+            )\n+        ).first()\n+        if finance_query and finance_query.did_user_pay:\n+            finance_data[user.username]['did_user_pay'] = True\n+        if finance_data[user.username]['month_cost'] == 0:\n+            del finance_data[user.username]\n+        elif did_pay == 2 and finance_data[user.username]['did_user_pay']:\n+            del finance_data[user.username]\n+        elif did_pay == 1 and not finance_data[user.username]['did_user_pay']:\n+            del finance_data[user.username]\n+\n+    pub_date = {'year': year, 'month': month_name[month]}\n+\n+    finance_record = Finance()\n+\n+    if request.method == 'POST':\n+        for row in finance_data.values():\n+            finance_record.did_user_pay = request.form.get(\n+                'did_user_pay_'+row['username'],\n+                'off',\n+            ) == 'on'\n+            finance_record.month = month\n+            finance_record.year = year\n+            finance_record.user_name = row['username']\n+            finance_querry = Finance.query.filter(\n+                and_(\n+                    Finance.month == month,\n+                    Finance.year == year,\n+                    Finance.user_name == row['username'],\n+                )\n+            ).first()\n+            if finance_querry:\n+                finance_querry.did_user_pay = finance_record.did_user_pay\n+                db.session.commit()\n+            else:\n+                db.session.add(finance_record)\n+                db.session.commit()\n+            flash('Finances changes submitted successfully')\n+        return redirect(url_for(\n+            'finance',\n+            year=year,\n+            month=month,\n+            did_pay=did_pay,\n+        ))\n+    p_year, p_month = previous_month(year, month)\n+    n_year, n_month = next_month(year, month)\n+    links = {\n+        'previous_month':\n+            url_for('finance', year=p_year, month=p_month, did_pay=did_pay),\n+        'next_month':\n+            url_for('finance', year=n_year, month=n_month, did_pay=did_pay),\n+    }\n+    return render_template(\n+        'finance.html',\n+        finance_data=finance_data,\n+        pub_date=pub_date,\n+        links=links,\n+    )\n+\n+\n+@app.route('/finance_mail_text', methods=['GET', 'POST'])\n+@login.login_required\n+@user_is_admin\n+def finance_mail_text():\n+    \"\"\"\n+    Renders mail all page.\n+    \"\"\"\n+    try:\n+        mail_data = MailText.query.first()\n+    except OperationalError:\n+        mail_data = None\n+    form = MailTextForm(formdata=request.form, obj=mail_data)\n+\n+    if request.method == 'POST' and form.validate():\n+        # import pdb; pdb.set_trace()\n+        if mail_data is None:\n+            texts = MailText()\n+            form.populate_obj(texts)\n+            db.session.add(texts)\n+        else:\n+            form.populate_obj(mail_data)\n+            db.session.commit()\n+        flash('Messages text updated')\n+        return redirect('finance_mail_text')\n+\n+    return render_template(\n+        'finance_mail_text.html',\n+        form=form,\n+    )\n+\n+\n+@app.route('/finance_mail_all', methods=['GET', 'POST'])\n+@login.login_required\n+@user_is_admin\n+def finance_mail_all():\n+    \"\"\"\n+    Renders mail all page.\n+    \"\"\"\n+    this_month = datetime.date.today()\n+    month_begin = datetime.datetime(\n+        year=this_month.year,\n+        month=this_month.month,\n+        day=1,\n+        hour=0,\n+        minute=0,\n+        second=1\n+    )\n+    day = monthrange(this_month.year, this_month.month)[1]\n+    month_end = datetime.datetime(\n+        year=this_month.year,\n+        month=this_month.month,\n+        day=day,\n+        hour=23,\n+        minute=59,\n+        second=59\n+    )\n+    users = User.query.all()\n+    orders = Order.query.filter(\n+        and_(\n+            Order.date >= month_begin,\n+            Order.date <= month_end,\n+        )\n+    ).all()\n+    finance_data = {}\n+    for user in users:\n+        finance_data[user.username] = {\n+            'username': user.username,\n+            'number_of_orders': 0,\n+            'month_cost': 0,\n+            'did_user_pay': DidUserPayForm(formdata=request.form),\n+        }\n+        for order in orders:\n+            if user.username == order.user_name:\n+                finance_data[user.username]['number_of_orders'] += 1\n+                finance_data[user.username]['month_cost'] += order.cost\n+        finance_query = Finance.query.filter(\n+            and_(\n+                Finance.month == this_month.month,\n+                Finance.year == this_month.year,\n+                Finance.user_name == user.username,\n+            )\n+        ).first()\n+        if finance_query and finance_query.did_user_pay:\n+            finance_data[user.username]['did_user_pay'] = DidUserPayForm(\n+                formdata=request.form, obj=finance_query)\n+        if finance_data[user.username]['month_cost'] == 0:\n+            del finance_data[user.username]\n+\n+    if request.method == 'POST':\n+        message_text = MailText.query.first()\n+        for record in finance_data.values():\n+            msg = Message(\n+                'Lunch {} / {} summary'.format(month_name[this_month.month],\n+                                               this_month.year),\n+                recipients=[record['username']],\n+            )\n+            msg.body = \"In {} you ordered {} meals for {} PLN.\\n {}\".format(\n+                month_name[this_month.month],\n+                record['number_of_orders'],\n+                record['month_cost'],\n+                message_text.monthly_pay_summary,\n+                )\n+            mail.send(msg)\n+            flash('Mail send')\n+        return redirect('finance_mail_all')\n+\n+    return render_template('finance_mail_all.html', finance_data=finance_data)\n+\n+\n+@app.route('/payment_remind/<string:username>/<int:slack>', methods=[\n+    'GET',\n+    'POST',\n+    ])\n+@login.login_required\n+@user_is_admin\n+def payment_remind(username, slack=0):\n+    \"\"\"\n+    Renders mail all page.","path":"src/lunch_app/views.py","position":374,"original_position":374,"commit_id":"087d68e9bc86e99ae761e17e5555c9539aeb1db2","original_commit_id":"087d68e9bc86e99ae761e17e5555c9539aeb1db2","user":{"login":"sargo","id":155872,"avatar_url":"https://avatars.githubusercontent.com/u/155872?v=3","gravatar_id":"","url":"https://api.github.com/users/sargo","html_url":"https://github.com/sargo","followers_url":"https://api.github.com/users/sargo/followers","following_url":"https://api.github.com/users/sargo/following{/other_user}","gists_url":"https://api.github.com/users/sargo/gists{/gist_id}","starred_url":"https://api.github.com/users/sargo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sargo/subscriptions","organizations_url":"https://api.github.com/users/sargo/orgs","repos_url":"https://api.github.com/users/sargo/repos","events_url":"https://api.github.com/users/sargo/events{/privacy}","received_events_url":"https://api.github.com/users/sargo/received_events","type":"User","site_admin":false},"body":"to nic nie renderuje ale wysyła maile i robi redirect","created_at":"2015-02-03T13:56:36Z","updated_at":"2015-02-03T13:56:36Z","html_url":"https://github.com/stxnext/lunch-app/pull/9#discussion_r24004384","pull_request_url":"https://api.github.com/repos/stxnext/lunch-app/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/stxnext/lunch-app/pulls/comments/24004384"},"html":{"href":"https://github.com/stxnext/lunch-app/pull/9#discussion_r24004384"},"pull_request":{"href":"https://api.github.com/repos/stxnext/lunch-app/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/stxnext/lunch-app/pulls/9","id":28483599,"html_url":"https://github.com/stxnext/lunch-app/pull/9","diff_url":"https://github.com/stxnext/lunch-app/pull/9.diff","patch_url":"https://github.com/stxnext/lunch-app/pull/9.patch","issue_url":"https://api.github.com/repos/stxnext/lunch-app/issues/9","number":9,"state":"open","locked":false,"title":"10 12 13 14 tasks","user":{"login":"pdyba","id":9288974,"avatar_url":"https://avatars.githubusercontent.com/u/9288974?v=3","gravatar_id":"","url":"https://api.github.com/users/pdyba","html_url":"https://github.com/pdyba","followers_url":"https://api.github.com/users/pdyba/followers","following_url":"https://api.github.com/users/pdyba/following{/other_user}","gists_url":"https://api.github.com/users/pdyba/gists{/gist_id}","starred_url":"https://api.github.com/users/pdyba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdyba/subscriptions","organizations_url":"https://api.github.com/users/pdyba/orgs","repos_url":"https://api.github.com/users/pdyba/repos","events_url":"https://api.github.com/users/pdyba/events{/privacy}","received_events_url":"https://api.github.com/users/pdyba/received_events","type":"User","site_admin":false},"body":"details of what is in review:\r\nhttps://trello.com/b/R79eJecq/lunch-app","created_at":"2015-02-02T16:55:18Z","updated_at":"2015-02-03T13:56:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e5343ac0a6b731ca8c41bc6d6ddc2e64353fd2f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stxnext/lunch-app/pulls/9/commits","review_comments_url":"https://api.github.com/repos/stxnext/lunch-app/pulls/9/comments","review_comment_url":"https://api.github.com/repos/stxnext/lunch-app/pulls/comments/{number}","comments_url":"https://api.github.com/repos/stxnext/lunch-app/issues/9/comments","statuses_url":"https://api.github.com/repos/stxnext/lunch-app/statuses/087d68e9bc86e99ae761e17e5555c9539aeb1db2","head":{"label":"pdyba:10_12_13_14_tasks","ref":"10_12_13_14_tasks","sha":"087d68e9bc86e99ae761e17e5555c9539aeb1db2","user":{"login":"pdyba","id":9288974,"avatar_url":"https://avatars.githubusercontent.com/u/9288974?v=3","gravatar_id":"","url":"https://api.github.com/users/pdyba","html_url":"https://github.com/pdyba","followers_url":"https://api.github.com/users/pdyba/followers","following_url":"https://api.github.com/users/pdyba/following{/other_user}","gists_url":"https://api.github.com/users/pdyba/gists{/gist_id}","starred_url":"https://api.github.com/users/pdyba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdyba/subscriptions","organizations_url":"https://api.github.com/users/pdyba/orgs","repos_url":"https://api.github.com/users/pdyba/repos","events_url":"https://api.github.com/users/pdyba/events{/privacy}","received_events_url":"https://api.github.com/users/pdyba/received_events","type":"User","site_admin":false},"repo":{"id":29301538,"name":"lunch-app","full_name":"pdyba/lunch-app","owner":{"login":"pdyba","id":9288974,"avatar_url":"https://avatars.githubusercontent.com/u/9288974?v=3","gravatar_id":"","url":"https://api.github.com/users/pdyba","html_url":"https://github.com/pdyba","followers_url":"https://api.github.com/users/pdyba/followers","following_url":"https://api.github.com/users/pdyba/following{/other_user}","gists_url":"https://api.github.com/users/pdyba/gists{/gist_id}","starred_url":"https://api.github.com/users/pdyba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdyba/subscriptions","organizations_url":"https://api.github.com/users/pdyba/orgs","repos_url":"https://api.github.com/users/pdyba/repos","events_url":"https://api.github.com/users/pdyba/events{/privacy}","received_events_url":"https://api.github.com/users/pdyba/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pdyba/lunch-app","description":"Aplikacja do zamawiania lunchy","fork":true,"url":"https://api.github.com/repos/pdyba/lunch-app","forks_url":"https://api.github.com/repos/pdyba/lunch-app/forks","keys_url":"https://api.github.com/repos/pdyba/lunch-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pdyba/lunch-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pdyba/lunch-app/teams","hooks_url":"https://api.github.com/repos/pdyba/lunch-app/hooks","issue_events_url":"https://api.github.com/repos/pdyba/lunch-app/issues/events{/number}","events_url":"https://api.github.com/repos/pdyba/lunch-app/events","assignees_url":"https://api.github.com/repos/pdyba/lunch-app/assignees{/user}","branches_url":"https://api.github.com/repos/pdyba/lunch-app/branches{/branch}","tags_url":"https://api.github.com/repos/pdyba/lunch-app/tags","blobs_url":"https://api.github.com/repos/pdyba/lunch-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pdyba/lunch-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pdyba/lunch-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/pdyba/lunch-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pdyba/lunch-app/statuses/{sha}","languages_url":"https://api.github.com/repos/pdyba/lunch-app/languages","stargazers_url":"https://api.github.com/repos/pdyba/lunch-app/stargazers","contributors_url":"https://api.github.com/repos/pdyba/lunch-app/contributors","subscribers_url":"https://api.github.com/repos/pdyba/lunch-app/subscribers","subscription_url":"https://api.github.com/repos/pdyba/lunch-app/subscription","commits_url":"https://api.github.com/repos/pdyba/lunch-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/pdyba/lunch-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/pdyba/lunch-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/pdyba/lunch-app/issues/comments/{number}","contents_url":"https://api.github.com/repos/pdyba/lunch-app/contents/{+path}","compare_url":"https://api.github.com/repos/pdyba/lunch-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pdyba/lunch-app/merges","archive_url":"https://api.github.com/repos/pdyba/lunch-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pdyba/lunch-app/downloads","issues_url":"https://api.github.com/repos/pdyba/lunch-app/issues{/number}","pulls_url":"https://api.github.com/repos/pdyba/lunch-app/pulls{/number}","milestones_url":"https://api.github.com/repos/pdyba/lunch-app/milestones{/number}","notifications_url":"https://api.github.com/repos/pdyba/lunch-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pdyba/lunch-app/labels{/name}","releases_url":"https://api.github.com/repos/pdyba/lunch-app/releases{/id}","created_at":"2015-01-15T14:40:36Z","updated_at":"2015-02-02T13:33:05Z","pushed_at":"2015-02-03T12:42:36Z","git_url":"git://github.com/pdyba/lunch-app.git","ssh_url":"git@github.com:pdyba/lunch-app.git","clone_url":"https://github.com/pdyba/lunch-app.git","svn_url":"https://github.com/pdyba/lunch-app","homepage":null,"size":581,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"master"}},"base":{"label":"stxnext:master","ref":"master","sha":"aa133dc9f0d1bed6cb6dac3ab17275bba2a9a0d2","user":{"login":"stxnext","id":1661949,"avatar_url":"https://avatars.githubusercontent.com/u/1661949?v=3","gravatar_id":"","url":"https://api.github.com/users/stxnext","html_url":"https://github.com/stxnext","followers_url":"https://api.github.com/users/stxnext/followers","following_url":"https://api.github.com/users/stxnext/following{/other_user}","gists_url":"https://api.github.com/users/stxnext/gists{/gist_id}","starred_url":"https://api.github.com/users/stxnext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stxnext/subscriptions","organizations_url":"https://api.github.com/users/stxnext/orgs","repos_url":"https://api.github.com/users/stxnext/repos","events_url":"https://api.github.com/users/stxnext/events{/privacy}","received_events_url":"https://api.github.com/users/stxnext/received_events","type":"Organization","site_admin":false},"repo":{"id":29291687,"name":"lunch-app","full_name":"stxnext/lunch-app","owner":{"login":"stxnext","id":1661949,"avatar_url":"https://avatars.githubusercontent.com/u/1661949?v=3","gravatar_id":"","url":"https://api.github.com/users/stxnext","html_url":"https://github.com/stxnext","followers_url":"https://api.github.com/users/stxnext/followers","following_url":"https://api.github.com/users/stxnext/following{/other_user}","gists_url":"https://api.github.com/users/stxnext/gists{/gist_id}","starred_url":"https://api.github.com/users/stxnext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stxnext/subscriptions","organizations_url":"https://api.github.com/users/stxnext/orgs","repos_url":"https://api.github.com/users/stxnext/repos","events_url":"https://api.github.com/users/stxnext/events{/privacy}","received_events_url":"https://api.github.com/users/stxnext/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stxnext/lunch-app","description":"Aplikacja do zamawiania lunchy","fork":false,"url":"https://api.github.com/repos/stxnext/lunch-app","forks_url":"https://api.github.com/repos/stxnext/lunch-app/forks","keys_url":"https://api.github.com/repos/stxnext/lunch-app/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stxnext/lunch-app/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stxnext/lunch-app/teams","hooks_url":"https://api.github.com/repos/stxnext/lunch-app/hooks","issue_events_url":"https://api.github.com/repos/stxnext/lunch-app/issues/events{/number}","events_url":"https://api.github.com/repos/stxnext/lunch-app/events","assignees_url":"https://api.github.com/repos/stxnext/lunch-app/assignees{/user}","branches_url":"https://api.github.com/repos/stxnext/lunch-app/branches{/branch}","tags_url":"https://api.github.com/repos/stxnext/lunch-app/tags","blobs_url":"https://api.github.com/repos/stxnext/lunch-app/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stxnext/lunch-app/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stxnext/lunch-app/git/refs{/sha}","trees_url":"https://api.github.com/repos/stxnext/lunch-app/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stxnext/lunch-app/statuses/{sha}","languages_url":"https://api.github.com/repos/stxnext/lunch-app/languages","stargazers_url":"https://api.github.com/repos/stxnext/lunch-app/stargazers","contributors_url":"https://api.github.com/repos/stxnext/lunch-app/contributors","subscribers_url":"https://api.github.com/repos/stxnext/lunch-app/subscribers","subscription_url":"https://api.github.com/repos/stxnext/lunch-app/subscription","commits_url":"https://api.github.com/repos/stxnext/lunch-app/commits{/sha}","git_commits_url":"https://api.github.com/repos/stxnext/lunch-app/git/commits{/sha}","comments_url":"https://api.github.com/repos/stxnext/lunch-app/comments{/number}","issue_comment_url":"https://api.github.com/repos/stxnext/lunch-app/issues/comments/{number}","contents_url":"https://api.github.com/repos/stxnext/lunch-app/contents/{+path}","compare_url":"https://api.github.com/repos/stxnext/lunch-app/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stxnext/lunch-app/merges","archive_url":"https://api.github.com/repos/stxnext/lunch-app/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stxnext/lunch-app/downloads","issues_url":"https://api.github.com/repos/stxnext/lunch-app/issues{/number}","pulls_url":"https://api.github.com/repos/stxnext/lunch-app/pulls{/number}","milestones_url":"https://api.github.com/repos/stxnext/lunch-app/milestones{/number}","notifications_url":"https://api.github.com/repos/stxnext/lunch-app/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stxnext/lunch-app/labels{/name}","releases_url":"https://api.github.com/repos/stxnext/lunch-app/releases{/id}","created_at":"2015-01-15T10:09:20Z","updated_at":"2015-02-02T07:50:49Z","pushed_at":"2015-02-02T07:50:49Z","git_url":"git://github.com/stxnext/lunch-app.git","ssh_url":"git@github.com:stxnext/lunch-app.git","clone_url":"https://github.com/stxnext/lunch-app.git","svn_url":"https://github.com/stxnext/lunch-app","homepage":null,"size":533,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stxnext/lunch-app/pulls/9"},"html":{"href":"https://github.com/stxnext/lunch-app/pull/9"},"issue":{"href":"https://api.github.com/repos/stxnext/lunch-app/issues/9"},"comments":{"href":"https://api.github.com/repos/stxnext/lunch-app/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/stxnext/lunch-app/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/stxnext/lunch-app/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/stxnext/lunch-app/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/stxnext/lunch-app/statuses/087d68e9bc86e99ae761e17e5555c9539aeb1db2"}}}}