Merge branch 'latest' of github.com:webnotes/erpnext into latest

Conflicts:
	version.num
diff --git a/css/all-web.css b/css/all-web.css
index 1780c8a..13ea802 100644
--- a/css/all-web.css
+++ b/css/all-web.css
@@ -1092,14 +1092,14 @@
 	margin: auto;
 }
 
-.web-head-section {
-	margin-bottom: 20px
-}
-
 .web-content input[type="text"], .web-content input[type="password"], .web-content select {
 	min-width: 180px;
 }
 
+.web-head-section {
+	margin-bottom: 20px
+}
+
 .web-main-section {
 	width: 65%;
 	float: left;
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 6c8003a..4cfd64d 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -202,7 +202,6 @@
 		self.update_nsm_model()		
 		# Add curret year balance
 		self.set_year_balance()
-		
 
 	# Check user role for approval process
 	# ==================================================================
@@ -232,7 +231,7 @@
 	# ==================================================================
 	def check_balance_before_trash(self):
 		if self.check_gle_exists():
-			msgprint("Account with existing transaction can not be trashed", raise_exception=1)
+			msgprint("Account with existing transaction (Sales Invoice / Purchase Invoice / Journal Voucher) can not be trashed", raise_exception=1)
 		if self.check_if_child_exists():
 			msgprint("Child account exists for this account. You can not trash this account.", raise_exception=1)
 
@@ -247,11 +246,15 @@
 	# ==================================================================
 	def on_trash(self): 
 		# Check balance before trash
-		self.check_balance_before_trash()		
+		self.check_balance_before_trash()
+		
 		# rebuild tree
 		set(self.doc,'old_parent', '')
 		self.update_nsm_model()
 
+		# delete all cancelled gl entry of this account
+		sql("delete from `tabGL Entry` where account = %s and ifnull(is_cancelled, 'No') = 'Yes'", self.doc.name)
+
 		#delete Account Balance
 		sql("delete from `tabAccount Balance` where account = %s", self.doc.name)
 
@@ -260,6 +263,8 @@
 	def on_restore(self):
 		# rebuild tree
 		self.update_nsm_model()
+		# intiate balances
+		self.set_year_balance()
 	
 	# on rename
 	# ---------
diff --git a/erpnext/setup/page/import_data/import_data.html b/erpnext/setup/page/import_data/import_data.html
index d227c2c..5f9556b 100644
--- a/erpnext/setup/page/import_data/import_data.html
+++ b/erpnext/setup/page/import_data/import_data.html
@@ -10,7 +10,7 @@
 <h3 style="background-color: #EEF; padding: 2px;">Step 1. Download Template</h3>
 <select id="import_template" style="margin: 10px;"> <option>Select Master...</option> </select>
 
-<div style="margin: 10px; margin-top: 0px;"><input name="overwrite" type="checkbox"/> Over-write records with same name?</div>
+<div style="margin: 10px; margin-top: 0px;"><input name="overwrite" type="checkbox"/> Do you want to over-write records? <br><span style='color:orange'>Warning: Over-writing the data of child tables, will delete all old data. For more info see below</span></div>
 <div id="child_tab_lst"></div>
 <h3 style="background-color: #EEF; padding: 2px;">Step 2. Upload and Import</h3>
 <table style="width: 480px;" border="0" cellspacing="10px">
@@ -33,23 +33,31 @@
 </table>
 </form>
 <div style="background-color: #FFE; padding: 13px; margin: 17px;">
-<h3>Data Import Guide</h3>
-<ol>
-<li>Get the template of the DocType for which you want to import in CSV (Comma seperated values) format.</li>
-<li>Fill in the data in the template. You can remove columns that are not relevant</li>
-<li>Save the template in CSV format</li>
-<li>Select the saved CSV file, identify the date format if any</li>
-<li>Click on "Import"</li>
-</ol></div>
+	<h3>Data Import Guide</h3>
+	<ol>
+		<li>Get the template of the DocType for which you want to import in CSV (Comma seperated values) format.</li>
+		<li>Fill in the data in the template. You can remove columns that are not relevant</li>
+		<li>Save the template in CSV format</li>
+		<li>Select the saved CSV file, identify the date format if any</li>
+		<li>Click on "Import"</li>
+	</ol>
+	<h4>Over-writing Guide</h4>
+	<ol>
+		<li>To over-write data, click on "Do you want to over-write records?" and then download template</li>
+		<li>To over-write parent table data, mention existing ID in "Name" column</li>
+		<li>Over-writing of child table data will delete all previous data of child table and re-import. so before over-writing child tables, export all data from system, modify them and then re-import</li>
+		<li>Over-write checkbox will be checked while importing</li>
+	</ol>
+</div>
 </td>
 <td style="border: 1px solid #AAA; padding: 4px;">
 <h3>Import Log:</h3>
 <div id="import_result_area">
-<iframe name="ImportIFrame" style="border: 0px; height: 500px; width: 100%"></iframe>
+<iframe name="ImportIFrame" style="border: 0px; height: 620px; width: 100%"></iframe>
 </div>
 </td>
 </tr>
 </tbody>
 </table>
 </div>
-</div>
\ No newline at end of file
+</div>
diff --git a/erpnext/website/css/website.css b/erpnext/website/css/website.css
index 6c89130..9fd7f12 100644
--- a/erpnext/website/css/website.css
+++ b/erpnext/website/css/website.css
@@ -39,14 +39,14 @@
 	margin: auto;
 }
 
-.web-head-section {
-	margin-bottom: 20px
-}
-
 .web-content input[type="text"], .web-content input[type="password"], .web-content select {
 	min-width: 180px;
 }
 
+.web-head-section {
+	margin-bottom: 20px
+}
+
 .web-main-section {
 	width: 65%;
 	float: left;
diff --git a/erpnext/website/doctype/website_settings/website_settings.js b/erpnext/website/doctype/website_settings/website_settings.js
new file mode 100644
index 0000000..9aaba62
--- /dev/null
+++ b/erpnext/website/doctype/website_settings/website_settings.js
@@ -0,0 +1,28 @@
+// update parent select
+
+$.extend(cur_frm.cscript, {
+	
+	onload_post_render: function(doc) {
+		// get labels of parent items
+		var get_parent_options = function(table_field) {
+			var items = getchildren('Top Bar Item', doc.name, table_field);
+			var main_items = [''];
+			for(var i in items) {
+				var d = items[i];
+				if(!d.parent_label) {
+					main_items.push(d.label);
+				}
+			}
+			return main_items.join('\n');
+		}
+		
+		// bind function to refresh fields
+		// when "Parent Label" is select, it 
+		// should automatically update
+		// options
+		$(cur_frm.fields_dict['top_bar_items'].grid.get_field('parent_label').wrapper)
+			.bind('refresh', function() {
+				this.fieldobj.refresh_options(get_parent_options('top_bar_items'));
+			});
+	}
+});
\ No newline at end of file
diff --git a/index.cgi b/index.cgi
index d618250..686ce05 100755
--- a/index.cgi
+++ b/index.cgi
@@ -24,7 +24,7 @@
 		webnotes.http_request = webnotes.auth.HTTPRequest()
 	except webnotes.AuthenticationError, e:
 		pass
-	except webnotes.defs.IllegalDomainException, e:
+	except webnotes.UnknownDomainError, e:
 		print "Location: " + (webnotes.defs.redirect_404)
 
 def respond():
diff --git a/js/all-app.js b/js/all-app.js
index d0628d2..0c8cad7 100644
--- a/js/all-app.js
+++ b/js/all-app.js
Binary files differ
diff --git a/js/all-web.js b/js/all-web.js
index 70dcb75..33348c5 100644
--- a/js/all-web.js
+++ b/js/all-web.js
@@ -142,13 +142,14 @@
 /*
  *	lib/js/core.js
  */
+if(!console){var console={log:function(txt){errprint(txt);}}}
 wn.versions.check();$(document).bind('ready',function(){var base=window.location.href.split('#')[0];$.each($('a[softlink!="false"]'),function(i,v){if(v.href.substr(0,base.length)==base){var path=(v.href.substr(base.length));if(path.substr(0,1)!='#'){v.href=base+'#'+path;}}});if(!wn.settings.no_history&&window.location.hash){wn.page.set(window.location.hash.substr(1));}});
 /*
  *	lib/js/legacy/globals.js
  */
 wn.provide('wn.widgets.form');wn.provide('wn.widgets.report');wn.provide('wn.utils');wn.provide('wn.model');wn.provide('wn.profile');wn.provide('wn.session');wn.provide('_f');wn.provide('_p');wn.provide('_r');wn.provide('_c');wn.provide('_e');wn.provide('_startup_data')
 wn.settings.no_history=1;var NEWLINE='\n';var login_file='';var version='v170';var profile=null;var session={};var is_testing=false;var user=null;var user_defaults=null;var user_roles=null;var user_fullname=null;var user_email=null;var user_img={};var home_page=null;var hide_autosuggest=null;var page_body=null;var pscript={};var selector=null;var top_index=91;var _f={};var _p={};var _e={};var _r={};var FILTER_SEP='\1';var _c={};var widget_files={'_f.FrmContainer':'form.compressed.js','_c.CalendarPopup':'widgets/form/date_picker.js','_r.ReportContainer':'report.compressed.js','_p.PrintQuery':'widgets/print_query.js','Calendar':'widgets/calendar.js','Recommendation':'widgets/recommend.js','RatingWidget':'widgets/rating.js'}
-var frms={};var cur_frm=null;var pscript={};var validated=true;var validation_message='';var tinymce_loaded=null;var cur_autosug=null;if(!console){var console={log:function(txt){errprint(txt);}}}
+var frms={};var cur_frm=null;var pscript={};var validated=true;var validation_message='';var tinymce_loaded=null;var cur_autosug=null;
 /*
  *	lib/js/legacy/utils/datatype.js
  */
@@ -721,9 +722,9 @@
 /*
  *	lib/js/legacy/webpage/page_header.js
  */
-var def_ph_style={wrapper:{marginBottom:'16px',backgroundColor:'#EEE'},main_heading:{},sub_heading:{marginBottom:'8px',color:'#555',display:'none'},separator:{borderTop:'3px solid #444'},toolbar_area:{padding:'3px 0px',display:'none',borderBottom:'1px solid #AAA'}}
+var def_ph_style={wrapper:{marginBottom:'16px',backgroundColor:'#EEE'},main_heading:{},sub_heading:{marginBottom:'8px',color:'#555',display:'none'},separator:{borderTop:'3px solid #777'},toolbar_area:{padding:'3px 0px',display:'none',borderBottom:'1px solid #AAA'}}
 function PageHeader(parent,main_text,sub_text){this.wrapper=$a(parent,'div','page_header');this.t1=make_table($a(this.wrapper,'div','',def_ph_style.wrapper.backgroundColor),1,2,'100%',[null,'100px'],{padding:'2px'});$y(this.t1,{borderCollapse:'collapse'})
-this.lhs=$td(this.t1,0,0);this.main_head=$a(this.lhs,'h1','',def_ph_style.main_heading);this.sub_head=$a(this.lhs,'h4','',def_ph_style.sub_heading);this.separator=$a(this.wrapper,'div','',def_ph_style.separator);this.toolbar_area=$a(this.wrapper,'div','',def_ph_style.toolbar_area);this.padding_area=$a(this.wrapper,'div','',{padding:'3px'});$y($td(this.t1,0,1),{textAlign:'right',padding:'3px'});this.close_btn=$a($td(this.t1,0,1),'span','close',{},'&#215;');this.close_btn.onclick=function(){nav_obj.show_last_open();};if(main_text)this.main_head.innerHTML=main_text;if(sub_text)this.sub_head.innerHTML=sub_text;this.buttons={};this.buttons2={};}
+this.lhs=$td(this.t1,0,0);this.main_head=$a(this.lhs,'h1','',def_ph_style.main_heading);this.sub_head=$a(this.lhs,'h4','',def_ph_style.sub_heading);this.separator=$a(this.wrapper,'div','',def_ph_style.separator);this.toolbar_area=$a(this.wrapper,'div','',def_ph_style.toolbar_area);this.padding_area=$a(this.wrapper,'div','',{padding:'3px'});$y($td(this.t1,0,1),{textAlign:'right',padding:'3px'});this.close_btn=$a($td(this.t1,0,1),'span','close',{},'&times;');this.close_btn.onclick=function(){nav_obj.show_last_open();};if(main_text)this.main_head.innerHTML=main_text;if(sub_text)this.sub_head.innerHTML=sub_text;this.buttons={};this.buttons2={};}
 PageHeader.prototype.add_button=function(label,fn,bold,icon,green){var tb=this.toolbar_area;if(this.buttons[label])return;var btn=$btn(tb,label,fn,{marginRight:'4px'},(green?'primary':''));if(bold)$y(btn,{fontWeight:'bold'});this.buttons[label]=btn;$ds(this.toolbar_area);return btn;}
 PageHeader.prototype.clear_toolbar=function(){this.toolbar_area.innerHTML='';this.buttons={};}
 PageHeader.prototype.make_buttonset=function(){$(this.toolbar_area).buttonset();}
diff --git a/version.num b/version.num
index 8f7277e..6aedc8e 100644
--- a/version.num
+++ b/version.num
@@ -1 +1 @@
-571
\ No newline at end of file
+571