text: # Copyright (c) 2013, Dirk van der Laarse and contributors
  # For license information, please see license.txt
  
  from __future__ import unicode_literals
  import frappe
  from frappe import _
  
  def execute(filters=None):
  	if not filters: filters = {}
  
  	columns = get_columns()
  
  	data = get_process_flow_steps(filters)
  
  	return columns, data
  
  def get_columns():
  	"""return columns"""
  	columns = [
  	{
  	    "fieldname": "department",
  	    "label": _("Department"),
  	    "fieldtype": "Link",
  	    "options": "Department",
  	    "width": 200
  	},
  	{
  	    "fieldname": "Sequence",
  	    "label": _("Sequence"),
  	    "fieldtype": "Data",
  	    "options": "",
  	    "width": 20
  	},
  	{
  	    "fieldname": "workstation",
  	    "label": _("Workstation"),
  	    "fieldtype": "Link",
  	    "options": "Workstation",
  	    "width": 100
  	},
  	{
  	    "fieldname": "step",
  	    "label": _("Step"),
  	    "fieldtype": "Link",
  	    "options": "Step",
  	    "width": 100
  	},
  	{
  	    "fieldname": "description",
  	    "label": _("Description"),
  	    "fieldtype": "",
  	    "options": "",
  	    "width": 400
  	}]
  
  	return columns
  
  def get_process_flow_steps(filters):
  
  	company = filters.get("company")
  	product_line_process_flow = filters.get("product_line_process_flow")
  
  	return frappe.db.sql("""
  			SELECT
  				t_ws.department,
  				CONCAT(t_plpfw.idx,'.',t_wsstep.idx) AS sequence,
  				t_ws.name AS workstation,
  				t_wsstep.step,
  				t_step.description
  			FROM `tabWorkstation Step` t_wsstep
  				INNER JOIN `tabStep` t_step ON t_step.name = t_wsstep.step
  				INNER JOIN `tabWorkstation` t_ws ON t_ws.name = t_wsstep.parent
  				INNER JOIN `tabProduct Line Process Flow Workstation` t_plpfw ON t_plpfw.workstation = t_ws.name
  				WHERE t_plpfw.parent = '{product_line_process_flow}'
  				ORDER BY t_plpfw.idx, t_wsstep.idx""".format(
  				product_line_process_flow=product_line_process_flow
  			)
  	)
  
  @frappe.whitelist()
  def get_product_line_process_flows(doctype, txt, searchfield, start, page_len, filters):
  	company = filters.get('company')
  	if company:
  		return frappe.db.sql("""SELECT name, title FROM `tabProduct Line Process Flow` t_plpf WHERE company = '{company}'""".format(company=company))
  