[communication] [minor]
diff --git a/hr/doctype/job_applicant/job_applicant.js b/hr/doctype/job_applicant/job_applicant.js
index 9aff605..f82da11 100644
--- a/hr/doctype/job_applicant/job_applicant.js
+++ b/hr/doctype/job_applicant/job_applicant.js
@@ -16,7 +16,7 @@
 	},
 	make_listing: function(doc) {
 		cur_frm.communication_view = new wn.views.CommunicationList({
-			list: wn.model.get("Communication", {"job_applicant": doc.name}),
+			list: wn.model.get("Communication", {"parent": doc.name, "parenttype": "Job Applicant"}),
 			parent: cur_frm.fields_dict['thread_html'].wrapper,
 			doc: doc,
 			recipients: doc.email_id
diff --git a/patches/september_2013/p01_update_communication.py b/patches/september_2013/p01_update_communication.py
index c3bd61b..d840c80 100644
--- a/patches/september_2013/p01_update_communication.py
+++ b/patches/september_2013/p01_update_communication.py
@@ -7,4 +7,9 @@
 			set parenttype=%s, parentfield='communications', 
 			parent=`%s` 
 			where ifnull(`%s`, '')!=''""" % ("%s", fieldname, fieldname), doctype)
+			
+		webnotes.reload_doc("core", "doctype", "communication")
+			
+		webnotes.conn.sql("""update tabCommunication set communication_date = creation where 
+			ifnull(communication_date, '')='' """)
 	
\ No newline at end of file
diff --git a/selling/doctype/lead/lead.js b/selling/doctype/lead/lead.js
index 4088739..3bc357c 100644
--- a/selling/doctype/lead/lead.js
+++ b/selling/doctype/lead/lead.js
@@ -36,7 +36,90 @@
 		
 		this.frm.dashboard.reset(doc);
 		if(!doc.__islocal) {
-			if(doc.status=="Converted") {
+			if(doc.status=="Converted") {// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+// License: GNU General Public License v3. See license.txt
+
+cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
+	return{	query:"controllers.queries.customer_query" } }
+
+wn.provide("erpnext.support");
+// TODO commonify this code
+erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({
+	customer: function() {
+		var me = this;
+		if(this.frm.doc.customer) {
+			return this.frm.call({
+				doc: this.frm.doc,
+				method: "set_customer_defaults",
+			});			
+		}
+	}
+});
+
+$.extend(cur_frm.cscript, new erpnext.support.CustomerIssue({frm: cur_frm}));
+
+$.extend(cur_frm.cscript, {
+	onload: function(doc, dt, dn) {
+		if(in_list(user_roles,'System Manager')) {
+			cur_frm.footer.help_area.innerHTML = '<p><a href="#Form/Email Settings/Email Settings">Email Settings</a><br>\
+				<span class="help">Integrate incoming support emails to Support Ticket</span></p>';
+		}
+	},
+	
+	refresh: function(doc) {
+		erpnext.hide_naming_series();
+		cur_frm.cscript.make_listing(doc);
+		if(!doc.__islocal) {
+			if(cur_frm.fields_dict.status.get_status()=="Write") {
+				if(doc.status!='Closed') cur_frm.add_custom_button('Close Ticket', cur_frm.cscript['Close Ticket']);
+				if(doc.status=='Closed') cur_frm.add_custom_button('Re-Open Ticket', cur_frm.cscript['Re-Open Ticket']);
+			}
+			
+			cur_frm.toggle_enable(["subject", "raised_by"], false);
+			cur_frm.toggle_display("description", false);
+		}
+		refresh_field('status');
+	},
+	
+	make_listing: function(doc) {
+		var wrapper = cur_frm.fields_dict['thread_html'].wrapper;
+		
+		var comm_list = wn.model.get("Communication", {"parent": doc.name, "parenttype":"Lead"})
+							
+		cur_frm.communication_view = new wn.views.CommunicationList({
+			list: comm_list,
+			parent: wrapper,
+			doc: doc,
+			recipients: doc.raised_by
+		})
+
+	},
+		
+	'Close Ticket': function() {
+		cur_frm.cscript.set_status("Closed");
+	},
+	
+	'Re-Open Ticket': function() {
+		cur_frm.cscript.set_status("Open");
+	},
+
+	set_status: function(status) {
+		return wn.call({
+			method:"support.doctype.support_ticket.support_ticket.set_status",
+			args: {
+				name: cur_frm.doc.name,
+				status: status
+			},
+			callback: function(r) {
+				if(!r.exc) cur_frm.reload_doc();
+			}
+		})
+		
+	}
+	
+})
+
+
 				this.frm.dashboard.set_headline_alert(wn._("Converted"), "alert-success", "icon-ok-sign");
 			} else {
 				this.frm.dashboard.set_headline_alert(wn._(doc.status), "alert-info", "icon-exclamation-sign");
diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js
index 2c1f332..78c3ce5 100644
--- a/support/doctype/support_ticket/support_ticket.js
+++ b/support/doctype/support_ticket/support_ticket.js
@@ -46,16 +46,12 @@
 	make_listing: function(doc) {
 		var wrapper = cur_frm.fields_dict['thread_html'].wrapper;
 		
-		var comm_list = wn.model.get("Communication", {"support_ticket": doc.name})
-
-		var sortfn = function (a, b) { return (b.creation > a.creation) ? 1 : -1; }
-		comm_list = comm_list.sort(sortfn);
+		var comm_list = wn.model.get("Communication", {"parent": doc.name, "parenttype":"Support Ticket"})
 		
-		if(!comm_list.length || (comm_list[comm_list.length - 1].sender != doc.raised_by)) {
+		if(!comm_list.length) {
 			comm_list.push({
 				"sender": doc.raised_by,
-				"creation": doc.creation,
-				"modified": doc.creation,
+				"communication_date": doc.creation,
 				"content": doc.description});
 		}