blob: fdd0b52c900015d1f78ddd1e1f8e8a665c03ee28 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +05304# For license information, please see license.txt
5
6from __future__ import unicode_literals
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05307import frappe
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +05308
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05309@frappe.whitelist()
Rushabh Mehtab21eb9a2013-02-28 18:42:46 +053010def get_time_log_list(doctype, txt, searchfield, start, page_len, filters):
Anand Doshie9baaa62014-02-26 12:35:33 +053011 return frappe.db.get_values("Time Log", filters, ["name", "activity_type", "owner"])
Anand Doshi9e1d1202013-05-09 19:34:34 +053012
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053013@frappe.whitelist()
Anand Doshi9e1d1202013-05-09 19:34:34 +053014def query_task(doctype, txt, searchfield, start, page_len, filters):
Rushabh Mehtac0bb4532014-09-09 16:15:35 +053015 from frappe.desk.reportview import build_match_conditions
Anand Doshi0d504492013-05-13 15:15:20 +053016
Anand Doshi9e1d1202013-05-09 19:34:34 +053017 search_string = "%%%s%%" % txt
18 order_by_string = "%s%%" % txt
Anand Doshi0d504492013-05-13 15:15:20 +053019 match_conditions = build_match_conditions("Task")
20 match_conditions = ("and" + match_conditions) if match_conditions else ""
21
Anand Doshie9baaa62014-02-26 12:35:33 +053022 return frappe.db.sql("""select name, subject from `tabTask`
Anand Doshi0d504492013-05-13 15:15:20 +053023 where (`%s` like %s or `subject` like %s) %s
Anand Doshi9e1d1202013-05-09 19:34:34 +053024 order by
25 case when `subject` like %s then 0 else 1 end,
26 case when `%s` like %s then 0 else 1 end,
27 `%s`,
28 subject
29 limit %s, %s""" %
Anand Doshi0d504492013-05-13 15:15:20 +053030 (searchfield, "%s", "%s", match_conditions, "%s",
31 searchfield, "%s", searchfield, "%s", "%s"),
Anand Doshi9e1d1202013-05-09 19:34:34 +053032 (search_string, search_string, order_by_string, order_by_string, start, page_len))