blob: 3d304927dae33538d2bae8d54b9945d2d77c6424 [file] [log] [blame]
Rushabh Mehta95e4e142012-09-13 19:40:56 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Anand Doshi82042f12012-04-06 17:54:17 +053017import webnotes
18
19def get_unread_messages():
20 "returns unread (docstatus-0 messages for a user)"
21 return webnotes.conn.sql("""\
22 SELECT name, comment
23 FROM `tabComment`
24 WHERE comment_doctype IN ('My Company', 'Message')
25 AND comment_docname = %s
26 AND ifnull(docstatus,0)=0
27 """, webnotes.user.name, as_list=1)
28
29def get_open_support_tickets():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053030 """Returns a count of open support tickets"""
Anand Doshi82042f12012-04-06 17:54:17 +053031 from webnotes.utils import cint
32 open_support_tickets = webnotes.conn.sql("""\
33 SELECT COUNT(*) FROM `tabSupport Ticket`
34 WHERE status = 'Open'""")
35 return open_support_tickets and cint(open_support_tickets[0][0]) or 0
36
Rushabh Mehta07c94ce2012-06-04 12:57:23 +053037def get_open_tasks():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053038 """Returns a count of open tasks"""
Rushabh Mehta07c94ce2012-06-04 12:57:23 +053039 from webnotes.utils import cint
40 return webnotes.conn.sql("""\
41 SELECT COUNT(*) FROM `tabTask`
42 WHERE status = 'Open'""")[0][0]
43
Anand Doshi82042f12012-04-06 17:54:17 +053044def get_things_todo():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053045 """Returns a count of incomplete todos"""
Anand Doshi82042f12012-04-06 17:54:17 +053046 from webnotes.utils import cint
47 incomplete_todos = webnotes.conn.sql("""\
48 SELECT COUNT(*) FROM `tabToDo`
49 WHERE IFNULL(checked, 0) = 0
50 AND owner = %s""", webnotes.session.get('user'))
51 return incomplete_todos and cint(incomplete_todos[0][0]) or 0
52
53def get_todays_events():
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053054 """Returns a count of todays events in calendar"""
Anand Doshi82042f12012-04-06 17:54:17 +053055 from webnotes.utils import nowdate, cint
56 todays_events = webnotes.conn.sql("""\
57 SELECT COUNT(*) FROM `tabEvent`
58 WHERE owner = %s
59 AND event_type != 'Cancel'
60 AND event_date = %s""", (
61 webnotes.session.get('user'), nowdate()))
62 return todays_events and cint(todays_events[0][0]) or 0
63
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053064def get_unanswered_questions():
65 return len(filter(lambda d: d[0]==0,
66 webnotes.conn.sql("""select (select count(*) from tabAnswer
67 where tabAnswer.question = tabQuestion.name) as answers from tabQuestion""")))
68
Anand Doshi82042f12012-04-06 17:54:17 +053069@webnotes.whitelist()
70def get_global_status_messages(arg=None):
71 return {
72 'unread_messages': get_unread_messages(),
73 'open_support_tickets': get_open_support_tickets(),
74 'things_todo': get_things_todo(),
75 'todays_events': get_todays_events(),
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053076 'open_tasks': get_open_tasks(),
77 'unanswered_questions': get_unanswered_questions()
Anand Doshi82042f12012-04-06 17:54:17 +053078 }