[cleanup] Maintenance Schedule, Maintenance Visit
diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py
index d63d336..d1552f94 100644
--- a/buying/doctype/supplier/supplier.py
+++ b/buying/doctype/supplier/supplier.py
@@ -196,7 +196,7 @@
 
 @webnotes.whitelist()
 def get_dashboard_info(supplier):
-	if not webnotes.has_permission("Supplier", supplier):
+	if not webnotes.has_permission("Supplier", "read", supplier):
 		webnotes.msgprint("No Permission", raise_exception=True)
 	
 	out = {}
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index 83c10a5..2820fb3 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -177,7 +177,7 @@
 
 @webnotes.whitelist()
 def get_dashboard_info(customer):
-	if not webnotes.has_permission("Customer", customer):
+	if not webnotes.has_permission("Customer", "read", customer):
 		webnotes.msgprint("No Permission", raise_exception=True)
 	
 	out = {}
diff --git a/setup/doctype/sales_person/sales_person.py b/setup/doctype/sales_person/sales_person.py
index ea21cd0..2fe08fa 100644
--- a/setup/doctype/sales_person/sales_person.py
+++ b/setup/doctype/sales_person/sales_person.py
@@ -32,4 +32,13 @@
 		for d in getlist(self.doclist, 'target_details'):
 			if not flt(d.target_qty) and not flt(d.target_amount):
 				webnotes.msgprint("Either target qty or target amount is mandatory.")
-				raise Exception
\ No newline at end of file
+				raise Exception
+	
+	def get_email_id(self):
+		profile = webnotes.conn.get_value("Employee", self.doc.employee, "user_id")
+		if not profile:
+			webnotes.msgprint("User ID (Profile) no set for Employee %s" % self.doc.employee, 
+				raise_exception=True)
+		else:
+			return webnotes.conn.get_value("Profile", profile, "email") or profile
+		
\ No newline at end of file
diff --git a/setup/doctype/sales_person/sales_person.txt b/setup/doctype/sales_person/sales_person.txt
index 44a246d..56c6397 100644
--- a/setup/doctype/sales_person/sales_person.txt
+++ b/setup/doctype/sales_person/sales_person.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:24", 
   "docstatus": 0, 
-  "modified": "2013-07-05 14:54:33", 
+  "modified": "2013-07-10 12:51:58", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -44,12 +44,10 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "trash_reason", 
-  "fieldtype": "Small Text", 
-  "label": "Trash Reason", 
-  "oldfieldname": "trash_reason", 
-  "oldfieldtype": "Small Text", 
-  "read_only": 1
+  "fieldname": "name_and_employee_id", 
+  "fieldtype": "Section Break", 
+  "label": "Name and Employee ID", 
+  "options": "icon-user"
  }, 
  {
   "doctype": "DocField", 
@@ -93,7 +91,8 @@
   "fieldname": "employee", 
   "fieldtype": "Link", 
   "label": "Employee", 
-  "options": "Employee"
+  "options": "Employee", 
+  "reqd": 1
  }, 
  {
   "doctype": "DocField", 
@@ -138,7 +137,8 @@
   "fieldname": "target_details_section_break", 
   "fieldtype": "Section Break", 
   "label": "Sales Person Targets", 
-  "oldfieldtype": "Section Break"
+  "oldfieldtype": "Section Break", 
+  "options": "icon-bullseye"
  }, 
  {
   "doctype": "DocField", 
diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.js b/support/doctype/maintenance_schedule/maintenance_schedule.js
index ec75289..6e43cb1 100644
--- a/support/doctype/maintenance_schedule/maintenance_schedule.js
+++ b/support/doctype/maintenance_schedule/maintenance_schedule.js
@@ -17,6 +17,30 @@
 wn.provide("erpnext.support");
 // TODO commonify this code
 erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({
+	refresh: function() {
+		if (this.frm.doc.docstatus===0) {
+			cur_frm.add_custom_button(wn._('From Sales Order'), 
+				function() {
+					wn.model.map_current_doc({
+						method: "selling.doctype.sales_order.sales_order.make_maintenance_schedule",
+						source_doctype: "Sales Order",
+						get_query_filters: {
+							docstatus: 1,
+							order_type: cur_frm.doc.order_type,
+							customer: cur_frm.doc.customer || undefined,
+							company: cur_frm.doc.company
+						}
+					})
+				});
+		} else if (this.frm.doc.docstatus===1) {
+			cur_frm.add_custom_button(wn._("Make Maintenance Visit"), function() {
+				wn.model.open_mapped_doc({
+					method: "support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
+					source_name: cur_frm.doc.name
+				})
+			})
+		}
+	},
 	customer: function() {
 		var me = this;
 		if(this.frm.doc.customer) {
@@ -27,23 +51,8 @@
 					if(!r.exc) me.frm.refresh_fields();
 				}
 			});
-			
-			// TODO shift this to depends_on
-			unhide_field(['customer_address', 'contact_person', 'customer_name',
-				'address_display', 'contact_display', 'contact_mobile', 'contact_email', 
-				'territory', 'customer_group']);
-			
-		}
+		}		
 	}, 
-	
-	get_items: function() {
-		wn.model.map_current_doc({
-			method: "selling.doctype.sales_order.sales_order.make_maintenance_schedule",
-			source_name: cur_frm.doc.quotation_no,
-		});
-		unhide_field(['customer_address', 'contact_person', 'customer_name', 'address_display', 
-			'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']);
-	}
 });
 
 $.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm}));
@@ -82,15 +91,6 @@
   }
 }
 
-cur_frm.fields_dict['sales_order_no'].get_query = function(doc) {
-  doc = locals[this.doctype][this.docname];
-  var cond = '';
-  if(doc.customer) {
-    cond = '`tabSales Order`.customer = "'+doc.customer+'" AND';
-  }
-  return repl('SELECT DISTINCT `tabSales Order`.name FROM `tabSales Order`, `tabSales Order Item`, `tabItem` WHERE `tabSales Order`.company = "%(company)s" AND `tabSales Order`.docstatus = 1 AND `tabSales Order Item`.parent = `tabSales Order`.name AND `tabSales Order Item`.item_code = `tabItem`.name AND `tabItem`.is_service_item = "Yes" AND %(cond)s `tabSales Order`.name LIKE "%s" ORDER BY `tabSales Order`.name DESC LIMIT 50', {company:doc.company, cond:cond});
-}
-
 cur_frm.cscript.periodicity = function(doc, cdt, cdn){
   var d = locals[cdt][cdn];
   if(d.start_date && d.end_date){
diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py
index ee7f45a..0e2d1f9 100644
--- a/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -77,8 +77,8 @@
 				self.update_amc_date(d.serial_no, d.end_date)
 
 			if d.incharge_name not in email_map:
-				e = sql("select email_id, name from `tabSales Person` where name='%s' " %(d.incharge_name),as_dict=1)[0]
-				email_map[d.incharge_name] = (e['email_id'])
+				email_map[d.incharge_name] = webnotes.bean("Sales Person", 
+					d.incharge_name).run_method("get_email_id")
 
 			scheduled_date =sql("select scheduled_date from `tabMaintenance Schedule Detail` \
 				where incharge_name='%s' and item_code='%s' and parent='%s' " %(d.incharge_name, \
@@ -312,6 +312,9 @@
 def make_maintenance_visit(source_name, target_doclist=None):
 	from webnotes.model.mapper import get_mapped_doclist
 	
+	def update_status(source, target, parent):
+		target.maintenance_type = "Scheduled"
+	
 	doclist = get_mapped_doclist("Maintenance Schedule", source_name, {
 		"Maintenance Schedule": {
 			"doctype": "Maintenance Visit", 
@@ -320,13 +323,15 @@
 			},
 			"validation": {
 				"docstatus": ["=", 1]
-			}
+			},
+			"postprocess": update_status
 		}, 
 		"Maintenance Schedule Item": {
 			"doctype": "Maintenance Visit Purpose", 
 			"field_map": {
 				"parent": "prevdoc_docname", 
-				"parenttype": "prevdoc_doctype"
+				"parenttype": "prevdoc_doctype",
+				"incharge_name": "service_person"
 			}
 		}
 	}, target_doclist)
diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.txt b/support/doctype/maintenance_schedule/maintenance_schedule.txt
index fc95ec6..0491946 100644
--- a/support/doctype/maintenance_schedule/maintenance_schedule.txt
+++ b/support/doctype/maintenance_schedule/maintenance_schedule.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:30", 
   "docstatus": 0, 
-  "modified": "2013-07-07 12:18:51", 
+  "modified": "2013-07-10 12:18:19", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -24,13 +24,19 @@
   "permlevel": 0
  }, 
  {
+  "amend": 1, 
+  "cancel": 1, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Maintenance Schedule", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
+  "permlevel": 0, 
   "read": 1, 
-  "report": 1
+  "report": 1, 
+  "submit": 1, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -42,7 +48,7 @@
   "fieldtype": "Section Break", 
   "label": "Customer Details", 
   "oldfieldtype": "Section Break", 
-  "options": "Simple"
+  "options": "icon-user"
  }, 
  {
   "doctype": "DocField", 
@@ -97,6 +103,7 @@
   "doctype": "DocField", 
   "fieldname": "address_display", 
   "fieldtype": "Small Text", 
+  "hidden": 1, 
   "label": "Address", 
   "read_only": 1
  }, 
@@ -104,20 +111,23 @@
   "doctype": "DocField", 
   "fieldname": "contact_display", 
   "fieldtype": "Small Text", 
+  "hidden": 1, 
   "label": "Contact", 
   "read_only": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "contact_mobile", 
-  "fieldtype": "Text", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
   "label": "Mobile No", 
   "read_only": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "contact_email", 
-  "fieldtype": "Text", 
+  "fieldtype": "Data", 
+  "hidden": 1, 
   "label": "Contact Email", 
   "print_hide": 1, 
   "read_only": 1
@@ -202,26 +212,7 @@
   "fieldtype": "Section Break", 
   "label": "Items", 
   "oldfieldtype": "Section Break", 
-  "options": "Simple"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "sales_order_no", 
-  "fieldtype": "Link", 
-  "in_filter": 1, 
-  "label": "Sales Order No", 
-  "oldfieldname": "sales_order_no", 
-  "oldfieldtype": "Link", 
-  "options": "Sales Order", 
-  "search_index": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "get_items", 
-  "fieldtype": "Button", 
-  "label": "Get Items", 
-  "oldfieldtype": "Button", 
-  "report_hide": 1
+  "options": "icon-shopping-cart"
  }, 
  {
   "doctype": "DocField", 
@@ -238,7 +229,7 @@
   "fieldtype": "Section Break", 
   "label": "Schedule", 
   "oldfieldtype": "Section Break", 
-  "options": "Simple"
+  "options": "icon-time"
  }, 
  {
   "doctype": "DocField", 
@@ -258,41 +249,11 @@
   "read_only": 1
  }, 
  {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "role": "System Manager", 
-  "submit": 1, 
-  "write": 1
+  "role": "System Manager"
  }, 
  {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
   "doctype": "DocPerm", 
-  "permlevel": 1, 
-  "role": "System Manager", 
-  "submit": 0
- }, 
- {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "role": "Maintenance Manager", 
-  "submit": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "permlevel": 1, 
-  "role": "Maintenance Manager", 
-  "submit": 0
+  "role": "Maintenance Manager"
  }
 ]
\ No newline at end of file
diff --git a/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt b/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt
index 3a95b2c..5c0fe3c 100644
--- a/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt
+++ b/support/doctype/maintenance_schedule_item/maintenance_schedule_item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-02-22 01:28:05", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:24", 
+  "modified": "2013-07-10 12:45:10", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -59,6 +59,12 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "schedule_details", 
+  "fieldtype": "Section Break", 
+  "label": "Schedule Details"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "start_date", 
   "fieldtype": "Date", 
   "in_filter": 1, 
@@ -102,7 +108,7 @@
   "fieldname": "incharge_name", 
   "fieldtype": "Link", 
   "in_filter": 1, 
-  "label": "Incharge Name", 
+  "label": "Sales Person Incharge", 
   "oldfieldname": "incharge_name", 
   "oldfieldtype": "Link", 
   "options": "Sales Person", 
@@ -111,6 +117,12 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "reference", 
+  "fieldtype": "Section Break", 
+  "label": "Reference"
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "serial_no", 
   "fieldtype": "Small Text", 
   "label": "Serial No", 
diff --git a/support/doctype/maintenance_visit/maintenance_visit.js b/support/doctype/maintenance_visit/maintenance_visit.js
index 6c282c0..50cc797 100644
--- a/support/doctype/maintenance_visit/maintenance_visit.js
+++ b/support/doctype/maintenance_visit/maintenance_visit.js
@@ -17,6 +17,49 @@
 wn.provide("erpnext.support");
 // TODO commonify this code
 erpnext.support.MaintenanceVisit = wn.ui.form.Controller.extend({
+	refresh: function() {
+		if (this.frm.doc.docstatus===0) {
+			cur_frm.add_custom_button(wn._('From Maintenance Schedule'), 
+				function() {
+					wn.model.map_current_doc({
+						method: "support.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit",
+						source_doctype: "Maintenance Schedule",
+						get_query_filters: {
+							docstatus: 1,
+							customer: cur_frm.doc.customer || undefined,
+							company: cur_frm.doc.company
+						}
+					})
+				});
+			cur_frm.add_custom_button(wn._('From Customer Issue'), 
+				function() {
+					wn.model.map_current_doc({
+						method: "support.doctype.customer_issue.customer_issue.make_maintenance_visit",
+						source_doctype: "Customer Issue",
+						get_query_filters: {
+							docstatus: 1,
+							status: ["in", "Open, Work in Progress"],
+							customer: cur_frm.doc.customer || undefined,
+							company: cur_frm.doc.company
+						}
+					})
+				});
+			cur_frm.add_custom_button(wn._('From Sales Order'), 
+				function() {
+					wn.model.map_current_doc({
+						method: "selling.doctype.sales_order.sales_order.make_maintenance_visit",
+						source_doctype: "Sales Order",
+						get_query_filters: {
+							docstatus: 1,
+							order_type: cur_frm.doc.order_type,
+							customer: cur_frm.doc.customer || undefined,
+							company: cur_frm.doc.company
+						}
+					})
+				});
+		}
+		cur_frm.cscript.hide_contact_info();			
+	},
 	customer: function() {
 		var me = this;
 		if(this.frm.doc.customer) {
@@ -29,29 +72,9 @@
 			});
 			
 			// TODO shift this to depends_on
-			hide_contact_info(this.frm.doc);			
+			cur_frm.cscript.hide_contact_info();			
 		}
 	}, 
-	
-	get_items: function() {
-		if(cur_frm.doc.sales_order_no) {
-			wn.model.map_current_doc({
-				method: "selling.doctype.sales_order.sales_order.make_maintenance_visit",
-				source_name: cur_frm.doc.quotation_no,
-			});
-		} else if (cur_frm.doc.customer_issue_no) {
-			wn.model.map_current_doc({
-				method: "support.doctype.customer_issue.customer_issue.make_maintenance_visit",
-				source_name: cur_frm.doc.quotation_no,
-			});
-		} else if (cur_frm.doc.maintenance_schedule) {
-			wn.model.map_current_doc({
-				method: "support.doctype.maintenance_schedule.maintenance_schedule\
-					.make_maintenance_visit",
-				source_name: cur_frm.doc.quotation_no,
-			});
-		}	
-	}
 });
 
 $.extend(cur_frm.cscript, new erpnext.support.MaintenanceVisit({frm: cur_frm}));
@@ -59,17 +82,11 @@
 cur_frm.cscript.onload = function(doc, dt, dn) {
 	if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
 	if(doc.__islocal) set_multiple(dt,dn,{mntc_date:get_today()});
-	hide_contact_info(doc);
+	cur_frm.cscript.hide_contact_info();			
 }
 
-var hide_contact_info = function(doc) {
-	if(doc.customer) $(cur_frm.fields_dict.contact_info_section.row.wrapper).toggle(true);
-	else $(cur_frm.fields_dict.contact_info_section.row.wrapper).toggle(false);
-	
-}
-
-cur_frm.cscript.refresh = function(doc) {
-	hide_contact_info(doc);
+cur_frm.cscript.hide_contact_info = function() {
+	cur_frm.toggle_display("contact_info_section", cur_frm.doc.customer ? true : false);
 }
 
 cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {		
@@ -84,14 +101,6 @@
 	return 'SELECT name,CONCAT(first_name," ",ifnull(last_name,"")) As FullName,department,designation FROM tabContact WHERE customer = "'+ doc.customer +'" AND docstatus != 2 AND name LIKE "%s" ORDER BY name ASC LIMIT 50';
 }
 
-cur_frm.cscript.get_items = function(doc, dt, dn) {
-	var callback = function(r,rt) { 
-		hide_contact_info(doc);
-		cur_frm.refresh();
-	}
-	get_server_fields('fetch_items','','',doc, dt, dn,1,callback);
-}
-
 cur_frm.fields_dict['maintenance_visit_details'].grid.get_field('item_code').get_query = function(doc, cdt, cdn) {
 	return 'SELECT tabItem.name,tabItem.item_name,tabItem.description FROM tabItem WHERE tabItem.is_service_item="Yes" AND tabItem.docstatus != 2 AND tabItem.%(key)s LIKE "%s" LIMIT 50';
 }
@@ -104,36 +113,4 @@
 	}
 }
 
-cur_frm.fields_dict['sales_order_no'].get_query = function(doc) {
-	doc = locals[this.doctype][this.docname];
-	var cond = '';
-	if(doc.customer) {
-		cond = '`tabSales Order`.customer = "'+doc.customer+'" AND';
-	}
-	return repl('SELECT DISTINCT `tabSales Order`.name FROM `tabSales Order`, `tabSales Order Item`, `tabItem` WHERE `tabSales Order`.company = "%(company)s" AND `tabSales Order`.docstatus = 1 AND `tabSales Order Item`.parent = `tabSales Order`.name AND `tabSales Order Item`.item_code = `tabItem`.name AND `tabItem`.is_service_item = "Yes" AND %(cond)s `tabSales Order`.name LIKE "%s" ORDER BY `tabSales Order`.name DESC LIMIT 50', {company:doc.company, cond:cond});
-}
-
-cur_frm.fields_dict['customer_issue_no'].get_query = function(doc) {
-	doc = locals[this.doctype][this.docname];
-	var cond = '';
-	if(doc.customer) {
-		cond = '`tabCustomer Issue`.customer = "'+doc.customer+'" AND';
-	}
-	return repl('SELECT `tabCustomer Issue`.name FROM `tabCustomer Issue` WHERE `tabCustomer Issue`.company = "%(company)s" AND %(cond)s `tabCustomer Issue`.docstatus = 1 AND (`tabCustomer Issue`.status = "Open" OR `tabCustomer Issue`.status = "Work In Progress") AND `tabCustomer Issue`.name LIKE "%s" ORDER BY `tabCustomer Issue`.name DESC LIMIT 50', {company:doc.company, cond:cond});
-}
-
-cur_frm.fields_dict['maintenance_schedule'].get_query = function(doc) {
-	doc = locals[this.doctype][this.docname];
-	var cond = '';
-	if(doc.customer) {
-		cond = '`tabMaintenance Schedule`.customer = "'+doc.customer+'" AND';
-	}
-	return repl('SELECT `tabMaintenance Schedule`.name FROM `tabMaintenance Schedule` WHERE `tabMaintenance Schedule`.company = "%(company)s" AND %(cond)s `tabMaintenance Schedule`.docstatus = 1 AND `tabMaintenance Schedule`.name LIKE "%s" ORDER BY `tabMaintenance Schedule`.name DESC LIMIT 50', {company:doc.company, cond:cond});
-}
-
-//get query select Territory
-cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
-	return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s"	ORDER BY	`tabTerritory`.`name` ASC LIMIT 50';
-}
-
 cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
\ No newline at end of file
diff --git a/support/doctype/maintenance_visit/maintenance_visit.txt b/support/doctype/maintenance_visit/maintenance_visit.txt
index c57787e..478d9ac 100644
--- a/support/doctype/maintenance_visit/maintenance_visit.txt
+++ b/support/doctype/maintenance_visit/maintenance_visit.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:31", 
   "docstatus": 0, 
-  "modified": "2013-07-07 12:08:12", 
+  "modified": "2013-07-10 12:26:15", 
   "modified_by": "Administrator", 
   "owner": "ashwini@webnotestech.com"
  }, 
@@ -24,13 +24,19 @@
   "permlevel": 0
  }, 
  {
+  "amend": 1, 
+  "cancel": 1, 
+  "create": 1, 
   "doctype": "DocPerm", 
   "name": "__common__", 
   "parent": "Maintenance Visit", 
   "parentfield": "permissions", 
   "parenttype": "DocType", 
+  "permlevel": 0, 
   "read": 1, 
-  "report": 1
+  "report": 1, 
+  "submit": 1, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -42,7 +48,7 @@
   "fieldtype": "Section Break", 
   "label": "Customer Details", 
   "oldfieldtype": "Section Break", 
-  "options": "Simple"
+  "options": "icon-user"
  }, 
  {
   "doctype": "DocField", 
@@ -137,7 +143,7 @@
   "fieldtype": "Section Break", 
   "label": "Maintenance Details", 
   "oldfieldtype": "Section Break", 
-  "options": "Simple"
+  "options": "icon-wrench"
  }, 
  {
   "doctype": "DocField", 
@@ -151,6 +157,11 @@
   "reqd": 1
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "column_break_14", 
+  "fieldtype": "Column Break"
+ }, 
+ {
   "default": "Unscheduled", 
   "doctype": "DocField", 
   "fieldname": "maintenance_type", 
@@ -166,56 +177,10 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "column_break2", 
-  "fieldtype": "Column Break", 
-  "oldfieldtype": "Column Break", 
-  "width": "50%"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "sales_order_no", 
-  "fieldtype": "Link", 
-  "in_filter": 1, 
-  "label": "Sales Order No", 
-  "oldfieldname": "sales_order_no", 
-  "oldfieldtype": "Link", 
-  "options": "Sales Order", 
-  "search_index": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "customer_issue_no", 
-  "fieldtype": "Link", 
-  "in_filter": 1, 
-  "label": "Customer Issue No", 
-  "oldfieldname": "customer_issue_no", 
-  "oldfieldtype": "Link", 
-  "options": "Customer Issue", 
-  "search_index": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "maintenance_schedule", 
-  "fieldtype": "Link", 
-  "in_filter": 1, 
-  "label": "Maintenance Schedule", 
-  "options": "Maintenance Schedule"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "get_items", 
-  "fieldtype": "Button", 
-  "label": "Get Items", 
-  "oldfieldtype": "Button", 
-  "print_hide": 1, 
-  "report_hide": 1
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "section_break0", 
   "fieldtype": "Section Break", 
   "oldfieldtype": "Section Break", 
-  "options": "Simple"
+  "options": "icon-wrench"
  }, 
  {
   "doctype": "DocField", 
@@ -231,7 +196,8 @@
   "fieldname": "more_info", 
   "fieldtype": "Section Break", 
   "label": "More Info", 
-  "oldfieldtype": "Section Break"
+  "oldfieldtype": "Section Break", 
+  "options": "icon-file-text"
  }, 
  {
   "doctype": "DocField", 
@@ -301,7 +267,8 @@
   "doctype": "DocField", 
   "fieldname": "contact_info_section", 
   "fieldtype": "Section Break", 
-  "label": "Contact Info"
+  "label": "Contact Info", 
+  "options": "icon-bullhorn"
  }, 
  {
   "doctype": "DocField", 
@@ -341,60 +308,15 @@
   "print_hide": 1
  }, 
  {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "role": "System Manager", 
-  "submit": 1, 
-  "write": 1
+  "role": "System Manager"
  }, 
  {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
   "doctype": "DocPerm", 
-  "permlevel": 1, 
-  "role": "System Manager", 
-  "submit": 0
+  "role": "Maintenance Manager"
  }, 
  {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
   "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "role": "Maintenance Manager", 
-  "submit": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "permlevel": 1, 
-  "role": "Maintenance Manager", 
-  "submit": 0
- }, 
- {
-  "amend": 1, 
-  "cancel": 1, 
-  "create": 1, 
-  "doctype": "DocPerm", 
-  "permlevel": 0, 
-  "role": "Maintenance User", 
-  "submit": 1, 
-  "write": 1
- }, 
- {
-  "amend": 0, 
-  "cancel": 0, 
-  "create": 0, 
-  "doctype": "DocPerm", 
-  "permlevel": 1, 
-  "role": "Maintenance User", 
-  "submit": 0
+  "role": "Maintenance User"
  }
 ]
\ No newline at end of file
diff --git a/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.txt b/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.txt
index 694f871..4f4af9a 100644
--- a/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.txt
+++ b/support/doctype/maintenance_visit_purpose/maintenance_visit_purpose.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-02-22 01:28:06", 
   "docstatus": 0, 
-  "modified": "2013-03-07 07:03:24", 
+  "modified": "2013-07-10 12:58:21", 
   "modified_by": "Administrator", 
   "owner": "ashwini@webnotestech.com"
  }, 
@@ -27,36 +27,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "description", 
-  "fieldtype": "Small Text", 
-  "label": "Description", 
-  "oldfieldname": "description", 
-  "oldfieldtype": "Small Text", 
-  "print_width": "300px", 
-  "reqd": 1, 
-  "width": "300px"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "service_person", 
-  "fieldtype": "Link", 
-  "label": "Service Person", 
-  "oldfieldname": "service_person", 
-  "oldfieldtype": "Link", 
-  "options": "Sales Person", 
-  "reqd": 1
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "work_done", 
-  "fieldtype": "Small Text", 
-  "label": "Work Done", 
-  "oldfieldname": "work_done", 
-  "oldfieldtype": "Small Text", 
-  "reqd": 1
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "item_code", 
   "fieldtype": "Link", 
   "label": "Item Code", 
@@ -83,6 +53,42 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "description", 
+  "fieldtype": "Small Text", 
+  "label": "Description", 
+  "oldfieldname": "description", 
+  "oldfieldtype": "Small Text", 
+  "print_width": "300px", 
+  "reqd": 1, 
+  "width": "300px"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "work_details", 
+  "fieldtype": "Section Break", 
+  "label": "Work Details"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "service_person", 
+  "fieldtype": "Link", 
+  "label": "Sales Person", 
+  "oldfieldname": "service_person", 
+  "oldfieldtype": "Link", 
+  "options": "Sales Person", 
+  "reqd": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "work_done", 
+  "fieldtype": "Small Text", 
+  "label": "Work Done", 
+  "oldfieldname": "work_done", 
+  "oldfieldtype": "Small Text", 
+  "reqd": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "prevdoc_docname", 
   "fieldtype": "Data", 
   "hidden": 0,