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