blob: c990207fe912a7049cb219e7e00edee4ea1aa71f [file] [log] [blame]
Anand Doshi486f9df2012-07-19 13:40:31 +05301from __future__ import unicode_literals
Anand Doshi82042f12012-04-06 17:54:17 +05302import webnotes
3
4def get_unread_messages():
5 "returns unread (docstatus-0 messages for a user)"
6 return webnotes.conn.sql("""\
7 SELECT name, comment
8 FROM `tabComment`
9 WHERE comment_doctype IN ('My Company', 'Message')
10 AND comment_docname = %s
11 AND ifnull(docstatus,0)=0
12 """, webnotes.user.name, as_list=1)
13
14def get_open_support_tickets():
15 """
16 Returns a count of open support tickets
17 """
18 from webnotes.utils import cint
19 open_support_tickets = webnotes.conn.sql("""\
20 SELECT COUNT(*) FROM `tabSupport Ticket`
21 WHERE status = 'Open'""")
22 return open_support_tickets and cint(open_support_tickets[0][0]) or 0
23
Rushabh Mehta07c94ce2012-06-04 12:57:23 +053024def get_open_tasks():
25 """
26 Returns a count of open tasks
27 """
28 from webnotes.utils import cint
29 return webnotes.conn.sql("""\
30 SELECT COUNT(*) FROM `tabTask`
31 WHERE status = 'Open'""")[0][0]
32
Anand Doshi82042f12012-04-06 17:54:17 +053033def get_things_todo():
34 """
35 Returns a count of incomplete todos
36 """
37 from webnotes.utils import cint
38 incomplete_todos = webnotes.conn.sql("""\
39 SELECT COUNT(*) FROM `tabToDo`
40 WHERE IFNULL(checked, 0) = 0
41 AND owner = %s""", webnotes.session.get('user'))
42 return incomplete_todos and cint(incomplete_todos[0][0]) or 0
43
44def get_todays_events():
45 """
46 Returns a count of todays events in calendar
47 """
48 from webnotes.utils import nowdate, cint
49 todays_events = webnotes.conn.sql("""\
50 SELECT COUNT(*) FROM `tabEvent`
51 WHERE owner = %s
52 AND event_type != 'Cancel'
53 AND event_date = %s""", (
54 webnotes.session.get('user'), nowdate()))
55 return todays_events and cint(todays_events[0][0]) or 0
56
57@webnotes.whitelist()
58def get_global_status_messages(arg=None):
59 return {
60 'unread_messages': get_unread_messages(),
61 'open_support_tickets': get_open_support_tickets(),
62 'things_todo': get_things_todo(),
63 'todays_events': get_todays_events(),
Rushabh Mehta07c94ce2012-06-04 12:57:23 +053064 'open_tasks': get_open_tasks()
Anand Doshi82042f12012-04-06 17:54:17 +053065 }