Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
index e773a95..14a53c4 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
@@ -33,7 +33,7 @@
 			'load_default_accounts','',
 			function(r,rt) {
 				refresh_field('entries');
-				refresh_field('debit_to');
+				cur_frm.cscript.customer(doc,dt,dn);
 			}
 		);
 	}
diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py
index f26374a..dba08fe 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.py
@@ -139,7 +139,6 @@
 			Loads default accounts from items, customer when called from mapper
 		"""
 		self.get_income_account('entries')
-		self.doc.debit_to = self.get_customer_account()
 		
 	def get_income_account(self,doctype):		
 		for d in getlist(self.doclist, doctype):			
diff --git a/erpnext/home/doctype/widget_control/widget_control.py b/erpnext/home/doctype/widget_control/widget_control.py
index fa41cc9..d6bb9d1 100644
--- a/erpnext/home/doctype/widget_control/widget_control.py
+++ b/erpnext/home/doctype/widget_control/widget_control.py
@@ -27,11 +27,6 @@
       cmt.comment_date = nowdate()
       cmt.comment_time = time.strftime('%H:%M')
       cmt.save(1)
-      
-      try:
-        get_obj('Feed Control').upate_comment_in_feed(args['comment_doctype'], args['comment_docname'])
-      except:
-        pass
 	      
     else:
       raise Exception
@@ -39,7 +34,3 @@
   def remove_comment(self, args):
     args = json.loads(args)
     sql("delete from `tabComment Widget Record` where name=%s",args['id'])
-
-    try:
-      get_obj('Feed Control').upate_comment_in_feed(args['dt'], args['dn'])
-    except: pass
diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py
index 01ff32d..ba602cf 100644
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -46,7 +46,7 @@
   # check if salary structure exists
   #========================================================================================================
   def check_sal_structure(self, nm):
-    ret_sal_struct=sql("select name from `tabSalary Structure` where employee='%s' and is_active = 'Yes'"%nm)
+    ret_sal_struct=sql("select name from `tabSalary Structure` where employee='%s' and is_active = 'Yes' and docstatus!= 2"%nm)
     return ret_sal_struct and ret_sal_struct[0][0] or ''
 
   #========================================================================================================
diff --git a/erpnext/hr/doctype/it_checklist/it_checklist.py b/erpnext/hr/doctype/it_checklist/it_checklist.py
index abed301..182e171 100644
--- a/erpnext/hr/doctype/it_checklist/it_checklist.py
+++ b/erpnext/hr/doctype/it_checklist/it_checklist.py
@@ -411,9 +411,3 @@
     new_tot_income = cint(self.doc.tax_tot_income) + cint(self.doc.edu_cess) - (cint(ret_income_tax[0][0]) or 0)
     
     self.doc.tax_per_month = new_tot_income/cint(self.doc.rem_months)
-
-  # on update
-  def on_update(self):
-    obj = get_obj('Feed Control', 'Feed Control')
-   
-    obj.make_feed(self.doc)
\ No newline at end of file
diff --git a/erpnext/patches/patch.py b/erpnext/patches/patch.py
index e930c2e..f78736b 100644
--- a/erpnext/patches/patch.py
+++ b/erpnext/patches/patch.py
@@ -1,7 +1,7 @@
 # REMEMBER to update this
 # ========================
 
-last_patch = 366
+last_patch = 367
 
 #-------------------------------------------
 
@@ -346,3 +346,6 @@
 			bobj = get_obj('Bin',b[0])
 			prev_sle = bobj.get_prev_sle(posting_date = '2011-09-15', posting_time = '01:00')
 			bobj.update_item_valuation(posting_date = '2011-09-15', posting_time = '01:00', prev_sle = prev_sle)
+	elif patch_no == 367:
+		sql("update tabDocPerm set amend = 0 where parent = 'Salary Structure'")
+		sql("update tabDocPerm set cancel = 1 where parent = 'Company' and role = 'System Manager'")
diff --git a/erpnext/selling/doctype/enquiry/enquiry.py b/erpnext/selling/doctype/enquiry/enquiry.py
index 1259702..773bedf 100644
--- a/erpnext/selling/doctype/enquiry/enquiry.py
+++ b/erpnext/selling/doctype/enquiry/enquiry.py
@@ -115,26 +115,17 @@
       ch = addchild(ev, 'event_individuals', 'Event User', 0)
       ch.person = d
       ch.save(1)
-    
-    #user_list = ['Sales Manager', 'Sales User']
-    #for d in user_list:
-    #  ch = addchild(ev, 'event_individuals', 'Event User', 0)
-    #  ch.person = d
-    #  ch.save()
+
 
   #--------------Validation For Last Contact Date-----------------
   # ====================================================================================================================
   def set_last_contact_date(self):
-    #if not self.doc.contact_date_ref:
-      #self.doc.contact_date_ref=self.doc.contact_date
-      #self.doc.last_contact_date=self.doc.contact_date_ref
     if self.doc.contact_date_ref and self.doc.contact_date_ref != self.doc.contact_date:
       if getdate(self.doc.contact_date_ref) < getdate(self.doc.contact_date):
         self.doc.last_contact_date=self.doc.contact_date_ref
       else:
         msgprint("Contact Date Cannot be before Last Contact Date")
         raise Exception
-      #set(self.doc, 'contact_date_ref',self.doc.contact_date)
   
   # check if item present in item table
   # ====================================================================================================================
@@ -171,8 +162,6 @@
       raise Exception
     else:
       set(self.doc, 'status', 'Cancelled')
-
-    get_obj('Feed Control').make_feed(self.doc, 'cancelled')
     
   # declare as enquiry lost
   #---------------------------
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index a2e333d..45b4973 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -200,24 +200,20 @@
 		if not cc:
 			self.create_default_cost_center()
 
-	# Trash accounts and cost centers for this company
-	# ---------------------------------------------------
-	#def on_trash1(self):
-	#	acc = sql("select name from tabAccount where company = '%s' and docstatus != 2 order by lft desc, rgt desc limit 2" % self.doc.name, debug=1)
-	#	for each in acc:
-	#		get_obj('Account', each[0]).on_trash()
-			
-	#	cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus != 2" % self.doc.name)
-	#	for each in cc:
-	#		get_obj('Cost Center', each[0]).on_trash()
-		
-	#	msgprint("Company trashed. All the accounts and cost centers related to this company also trashed. You can restore it anytime from Setup -> Manage Trash")
-		
+	# 
+	# ---------------------------------------------------	
 	def on_trash(self):
-		rec = sql("SELECT sum(ab.opening), sum(ab.balance), sum(ab.debit), sum(ab.credit) FROM `tabAccount Balance` ab, `tabAccount` a WHERE ab.account = a.name and a.company = %s", self.doc.name)
-		if rec[0][0] == 0 and rec[0][1] == 0 and rec[0][2] == 0 and rec[0][3] == 0:
+		"""
+			Trash accounts and cost centers for this company if no gl entry exists
+		"""
+		rec = sql("SELECT name from `tabGL Entry` where ifnull(is_cancelled, 'No') = 'No' and company = %s", self.doc.name)
+		if not rec:
+			# delete gl entry
+			sql("delete from `tabGL Entry` where company = %s", self.doc.name)
+
 			#delete tabAccount Balance
 			sql("delete ab.* from `tabAccount Balance` ab, `tabAccount` a where ab.account = a.name and a.company = %s", self.doc.name)
+
 			#delete tabAccount
 			sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name)
 			
@@ -232,18 +228,6 @@
 			#update value as blank for tabSingles Manage Account
 			sql("update `tabSingles` set value = '' where doctype='Manage Account' and field = 'default_company' and value = %s", self.doc.name)
 
-	# Restore accounts and cost centers for this company
-	# ---------------------------------------------------
-	def on_restore(self):
-		acc = sql("select name from tabAccount where company = '%s' and docstatus = 2" % self.doc.name)
-		for each in acc:
-			get_obj('Account', each[0]).on_restore()
-			
-		cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus = 2" % self.doc.name)
-		for each in cc:
-			get_obj('Cost Center', each[0]).on_restore()
-		
-		msgprint("Company restored. All the accounts and cost centers related to this company also restored.")
 		
 	# on rename
 	# ---------