Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js
index 93e6bff..868e59a 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js
+++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.js
@@ -17,6 +17,19 @@
 // Booking Entry Id
 // --------------------
 
+cur_frm.cscript.onload_post_render = function(doc) {
+	$(cur_frm.get_field("reconcile").input).addClass("btn-info");
+}
+
+cur_frm.cscript.refresh = function(doc) {
+	cur_frm.set_intro("");
+	if(!doc.voucher_no) {
+		cur_frm.set_intro("Select the Invoice against which you want to allocate payments.");
+	} else {
+		cur_frm.set_intro("Set allocated amount against each Payment Entry and click 'Allocate'.");
+	}
+}
+
 cur_frm.fields_dict.voucher_no.get_query = function(doc) {
 	if (!doc.account) msgprint("Please select Account first");
 	else {
diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
index 81b94a2..e72d23e 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
+++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.py
@@ -107,7 +107,6 @@
 			ch.total_amt = flt(d.get('total_amt'))
 			ch.against_account = d.get('against_account')
 			ch.remarks = d.get('remark')
-			ch.amt_to_be_reconciled = flt(ch.amt_due)
 			ch.voucher_detail_no = d.get('voucher_detail_no')
 			
 	#--------------------------------------------------
@@ -128,7 +127,7 @@
 		
 		lst = []
 		for d in getlist(self.doclist, 'ir_payment_details'):
-			if d.selected and flt(d.amt_to_be_reconciled) > 0:
+			if flt(d.amt_to_be_reconciled) > 0:
 				args = {
 					'voucher_no' : d.voucher_no,
 					'voucher_detail_no' : d.voucher_detail_no, 
@@ -146,6 +145,6 @@
 
 		if lst:
 			get_obj('GL Control').reconcile_against_document(lst)
-			msgprint("Successfully reconciled.")
+			msgprint("Successfully allocated.")
 		else:
-			msgprint("No payment entries selected.", raise_exception=1)
+			msgprint("No amount allocated.", raise_exception=1)
diff --git a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.txt b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.txt
index 4ae813a..91d2613 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.txt
+++ b/accounts/doctype/payment_to_invoice_matching_tool/payment_to_invoice_matching_tool.txt
@@ -2,21 +2,17 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-03-27 14:35:42", 
+  "creation": "2012-07-03 13:30:46", 
   "modified_by": "Administrator", 
-  "modified": "2012-03-27 14:35:42"
+  "modified": "2012-12-31 10:34:43"
  }, 
  {
-  "section_style": "Simple", 
-  "module": "Accounts", 
-  "doctype": "DocType", 
   "issingle": 1, 
-  "document_type": "Other", 
   "name": "__common__", 
-  "colour": "White:FFF", 
-  "_last_update": "1316509358", 
-  "show_in_menu": 1, 
-  "version": 37
+  "doctype": "DocType", 
+  "module": "Accounts", 
+  "document_type": "Other", 
+  "hide_toolbar": 1
  }, 
  {
   "name": "__common__", 
@@ -38,6 +34,148 @@
   "doctype": "DocType"
  }, 
  {
+  "doctype": "DocField", 
+  "label": "Account", 
+  "options": "Account", 
+  "fieldname": "account", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Voucher Type", 
+  "options": "Sales Invoice\nPurchase Invoice\nJournal Voucher", 
+  "fieldname": "voucher_type", 
+  "fieldtype": "Select", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Voucher No", 
+  "options": "[Select]", 
+  "fieldname": "voucher_no", 
+  "fieldtype": "Link", 
+  "reqd": 1, 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Pull Payment Entries", 
+  "options": "get_payment_entries", 
+  "fieldname": "pull_payment_entries", 
+  "fieldtype": "Button", 
+  "permlevel": 0
+ }, 
+ {
+  "print_width": "50%", 
+  "doctype": "DocField", 
+  "width": "50%", 
+  "fieldname": "column_break1", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Total Amount", 
+  "fieldname": "total_amount", 
+  "fieldtype": "Currency", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Outstanding Amount", 
+  "fieldname": "pending_amt_to_reconcile", 
+  "fieldtype": "Currency", 
+  "permlevel": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Payment Entries", 
+  "fieldname": "payment_entries", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "description": "Update allocated amount in the above table and then click \"Allocate\" button", 
+  "doctype": "DocField", 
+  "label": "Payment Entries", 
+  "options": "Payment to Invoice Matching Tool Detail", 
+  "fieldname": "ir_payment_details", 
+  "fieldtype": "Table", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Allocate", 
+  "options": "reconcile", 
+  "fieldname": "reconcile", 
+  "fieldtype": "Button", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "options": "Simple", 
+  "fieldname": "section_break0", 
+  "fieldtype": "Section Break", 
+  "permlevel": 0
+ }, 
+ {
+  "print_width": "50%", 
+  "doctype": "DocField", 
+  "label": "Filter By Date", 
+  "width": "50%", 
+  "fieldname": "column_break2", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "From Date", 
+  "fieldname": "from_date", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "To Date", 
+  "fieldname": "to_date", 
+  "fieldtype": "Date", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Help HTML", 
+  "options": "Click \"Pull Payment Entries\" to refresh the table with filters.", 
+  "fieldname": "help_html", 
+  "fieldtype": "HTML", 
+  "permlevel": 0
+ }, 
+ {
+  "print_width": "50%", 
+  "doctype": "DocField", 
+  "label": "Filter By Amount", 
+  "width": "50%", 
+  "fieldname": "column_break3", 
+  "fieldtype": "Column Break", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Amount >=", 
+  "fieldname": "amt_greater_than", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "label": "Amount <=", 
+  "fieldname": "amt_less_than", 
+  "fieldtype": "Data", 
+  "permlevel": 0
+ }, 
+ {
   "create": 1, 
   "doctype": "DocPerm", 
   "write": 1, 
@@ -59,159 +197,8 @@
   "permlevel": 0
  }, 
  {
+  "doctype": "DocPerm", 
   "role": "All", 
-  "permlevel": 1, 
-  "doctype": "DocPerm"
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "width": "50%", 
-  "fieldname": "column_break0", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "options": "Account", 
-  "fieldname": "account", 
-  "fieldtype": "Link", 
-  "label": "Account", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "options": "Sales Invoice\nPurchase Invoice\nJournal Voucher", 
-  "fieldname": "voucher_type", 
-  "fieldtype": "Select", 
-  "label": "Voucher Type", 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Voucher No", 
-  "trigger": "Client", 
-  "fieldname": "voucher_no", 
-  "fieldtype": "Link", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "width": "50%", 
-  "fieldname": "column_break1", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Total Amount", 
-  "fieldname": "total_amount", 
-  "fieldtype": "Currency", 
   "permlevel": 1
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Pending Amt To Reconcile", 
-  "fieldname": "pending_amt_to_reconcile", 
-  "fieldtype": "Currency", 
-  "permlevel": 1
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Payment Entries", 
-  "fieldname": "payment_entries", 
-  "fieldtype": "Section Break", 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "<div class = 'field_description'>Filter payment entries based on date:</div>", 
-  "width": "50%", 
-  "fieldname": "column_break2", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "From Date", 
-  "fieldname": "from_date", 
-  "fieldtype": "Date", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "To Date", 
-  "fieldname": "to_date", 
-  "fieldtype": "Date", 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "<div class = 'field_description'>Filter payment entries based on amount:</div>", 
-  "width": "50%", 
-  "fieldname": "column_break3", 
-  "fieldtype": "Column Break", 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Amount >=", 
-  "fieldname": "amt_greater_than", 
-  "fieldtype": "Data", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Amount <=", 
-  "fieldname": "amt_less_than", 
-  "fieldtype": "Data", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "permlevel": 0, 
-  "fieldname": "section_break0", 
-  "fieldtype": "Section Break", 
-  "options": "Simple"
- }, 
- {
-  "doctype": "DocField", 
-  "options": "get_payment_entries", 
-  "fieldname": "pull_payment_entries", 
-  "fieldtype": "Button", 
-  "label": "Pull Payment Entries", 
-  "permlevel": 0
- }, 
- {
-  "doctype": "DocField", 
-  "options": "Payment to Invoice Matching Tool Detail", 
-  "fieldname": "ir_payment_details", 
-  "fieldtype": "Table", 
-  "label": "Payment Entries", 
-  "permlevel": 0
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Reconcile HTML", 
-  "permlevel": 0, 
-  "fieldname": "reconcile_html", 
-  "fieldtype": "HTML", 
-  "options": "<div class='field_description'>Select Payment Voucher and Amount to Reconcile in the above table and then click Reconcile button</div>"
- }, 
- {
-  "colour": "White:FFF", 
-  "doctype": "DocField", 
-  "label": "Reconcile", 
-  "permlevel": 0, 
-  "trigger": "Client", 
-  "fieldname": "reconcile", 
-  "fieldtype": "Button", 
-  "options": "reconcile"
  }
 ]
\ No newline at end of file
diff --git a/accounts/doctype/payment_to_invoice_matching_tool_detail/payment_to_invoice_matching_tool_detail.txt b/accounts/doctype/payment_to_invoice_matching_tool_detail/payment_to_invoice_matching_tool_detail.txt
index ab7e6bb..81bc59e 100644
--- a/accounts/doctype/payment_to_invoice_matching_tool_detail/payment_to_invoice_matching_tool_detail.txt
+++ b/accounts/doctype/payment_to_invoice_matching_tool_detail/payment_to_invoice_matching_tool_detail.txt
@@ -2,19 +2,15 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-03-27 14:35:43", 
+  "creation": "2012-07-03 13:30:47", 
   "modified_by": "Administrator", 
-  "modified": "2012-03-27 14:35:43"
+  "modified": "2012-12-31 10:24:49"
  }, 
  {
-  "section_style": "Simple", 
   "istable": 1, 
   "name": "__common__", 
-  "colour": "White:FFF", 
-  "module": "Accounts", 
   "doctype": "DocType", 
-  "version": 14, 
-  "show_in_menu": 0
+  "module": "Accounts"
  }, 
  {
   "name": "__common__", 
@@ -28,15 +24,7 @@
   "doctype": "DocType"
  }, 
  {
-  "doctype": "DocField", 
-  "label": "Select", 
-  "width": "60px", 
-  "fieldname": "selected", 
-  "fieldtype": "Check", 
-  "reqd": 1, 
-  "permlevel": 0
- }, 
- {
+  "print_width": "140px", 
   "permlevel": 1, 
   "doctype": "DocField", 
   "label": "Voucher No", 
@@ -48,14 +36,14 @@
  }, 
  {
   "doctype": "DocField", 
-  "label": "Amt Due", 
+  "label": "Unmatched Amount", 
   "fieldname": "amt_due", 
   "fieldtype": "Currency", 
   "permlevel": 1
  }, 
  {
   "doctype": "DocField", 
-  "label": "Amt to be reconciled", 
+  "label": "Allocated Amount", 
   "fieldname": "amt_to_be_reconciled", 
   "fieldtype": "Currency", 
   "reqd": 1, 
@@ -70,7 +58,7 @@
  }, 
  {
   "doctype": "DocField", 
-  "label": "Total Amt", 
+  "label": "Total Amount", 
   "fieldname": "total_amt", 
   "fieldtype": "Currency", 
   "permlevel": 1
@@ -83,6 +71,7 @@
   "permlevel": 1
  }, 
  {
+  "print_width": "200px", 
   "doctype": "DocField", 
   "label": "Remarks", 
   "width": "200px", 
@@ -96,7 +85,6 @@
   "label": "Voucher Detail No", 
   "fieldname": "voucher_detail_no", 
   "fieldtype": "Data", 
-  "no_column": 0, 
   "reqd": 0, 
   "hidden": 1, 
   "permlevel": 1
diff --git a/hr/doctype/expense_claim/expense_claim.py b/hr/doctype/expense_claim/expense_claim.py
index 2ba53aa..3906550 100644
--- a/hr/doctype/expense_claim/expense_claim.py
+++ b/hr/doctype/expense_claim/expense_claim.py
@@ -34,7 +34,7 @@
 		# 	webnotes.msgprint("""Self Approval is not allowed.""", raise_exception=1)
 
 		import utilities
-		utilities.validate_status(self.doc.status, ["Draft", "Approved", "Rejected"])
+		utilities.validate_status(self.doc.approval_status, ["Draft", "Approved", "Rejected"])
 
 		self.validate_fiscal_year()
 		self.validate_exp_details()
diff --git a/setup/doctype/permission_control/permission_control.py b/setup/doctype/permission_control/permission_control.py
index cb0575d..4fbd1dd 100644
--- a/setup/doctype/permission_control/permission_control.py
+++ b/setup/doctype/permission_control/permission_control.py
@@ -81,7 +81,12 @@
 	# get default values
 	# ------------------
 	def get_defaults(self, arg):
-		match_key, with_profiles = arg.split('~~~')
+		if isinstance(arg, basestring):
+			import json
+			arg = json.loads(arg)
+
+		match_key = arg["match"]
+		with_profiles = arg["profiles"]
 		
 		pl = ol = []
 	
@@ -89,7 +94,9 @@
 		dl = [a for a in sql("select parent, ifnull(parenttype,'') as parenttype, ifnull(defvalue,'') as defvalue from tabDefaultValue where defkey=%s order by parenttype desc, parent asc", match_key, as_dict=1)]
 
 		# options
-		tn = sql("select options from tabDocField where fieldname=%s and fieldtype='Link' and docstatus=0 limit 1", match_key)[0][0]
+		tn = webnotes.get_doctype(arg["doctype"]).get_options(match_key)
+
+		# tn = sql("select options from tabDocField where fieldname=%s and fieldtype='Link' and docstatus=0 limit 1", match_key)[0][0]
 		ol = [''] + [a[0] for a in sql("select name from `tab%s` where ifnull(docstatus,0)=0" % tn)]
 
 		# roles
diff --git a/setup/page/permission_engine/permission_engine.js b/setup/page/permission_engine/permission_engine.js
index 5f5630c..6edde4c 100644
--- a/setup/page/permission_engine/permission_engine.js
+++ b/setup/page/permission_engine/permission_engine.js
@@ -287,7 +287,11 @@
 		me.render_match_dialog(r, details);
 	}
 	// load the rules
-	$c_obj('Permission Control','get_defaults', details.match + '~~~' + (this.profiles ? 'No' : 'Yes'), callback); 
+	$c_obj('Permission Control','get_defaults', {
+			match: details.match,
+			profiles: this.profiles ? "No" : "Yes",
+			doctype: sel_val(me.type_select)
+		}, callback);
 }
 
 // --------------------------------------------
diff --git a/stock/page/stock_balance/stock_balance.js b/stock/page/stock_balance/stock_balance.js
index 485909c..b25d150 100644
--- a/stock/page/stock_balance/stock_balance.js
+++ b/stock/page/stock_balance/stock_balance.js
@@ -110,8 +110,8 @@
 					item.opening += diff;
 				} else if(posting_datetime <= to_date) {
 					var ignore_inflow_outflow = this.is_default("warehouse")
-						&& item.voucher_type=="Stock Entry" 
-						&& this.stock_entry_map[item.voucher_no].purpose=="Material Transfer";
+						&& sl.voucher_type=="Stock Entry" 
+						&& this.stock_entry_map[sl.voucher_no].purpose=="Material Transfer";
 					
 					if(!ignore_inflow_outflow) {
 						if(diff < 0) {
diff --git a/website/utils.py b/website/utils.py
index ec33103..674d752 100644
--- a/website/utils.py
+++ b/website/utils.py
@@ -263,7 +263,8 @@
 		webnotes.cache().delete_keys("page:")
 	
 def delete_page_cache(page_name):
-	webnotes.cache().delete_value("page:" + page_name)
+	if page_name:
+		webnotes.cache().delete_value("page:" + page_name)
 	
 def url_for_website(url):
 	if url and not url.lower().startswith("http"):