[cleanup] payment entry form view
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 230d728..ba76bdc 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -8,7 +8,7 @@
 			if (!frm.doc.paid_to) frm.set_value("paid_to_account_currency", null);
 		}
 	},
-	
+
 	setup: function(frm) {
 		frm.get_field('references').grid.editable_fields = [
 			{fieldname: 'reference_doctype', columns: 2},
@@ -16,11 +16,11 @@
 			{fieldname: 'outstanding_amount', columns: 3},
 			{fieldname: 'allocated_amount', columns: 3}
 		];
-		
+
 		var party_account_type = frm.doc.party_type=="Customer" ? "Receivable" : "Payable";
-				
+
 		frm.set_query("paid_from", function() {
-			var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ? 
+			var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ?
 				["Bank", "Cash"] : party_account_type;
 
 			return {
@@ -31,11 +31,11 @@
 				}
 			}
 		});
-		
+
 		frm.set_query("paid_to", function() {
-			var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ? 
+			var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ?
 	 			["Bank", "Cash"] : party_account_type;
-			
+
 			return {
 				filters: {
 					"account_type": ["in", account_types],
@@ -44,7 +44,7 @@
 				}
 			}
 		});
-		
+
 		frm.set_query("account", "deductions", function() {
 			return {
 				filters: {
@@ -53,7 +53,7 @@
 				}
 			}
 		});
-		
+
 		frm.set_query("cost_center", "deductions", function() {
 			return {
 				filters: {
@@ -62,7 +62,7 @@
 				}
 			}
 		});
-		
+
 		frm.set_query("reference_doctype", "references", function() {
 			if (frm.doc.party_type=="Customer") {
 				var doctypes = ["Sales Order", "Sales Invoice", "Journal Entry"];
@@ -71,60 +71,61 @@
 			} else {
 				var doctypes = ["Journal Entry"];
 			}
-			
+
 			return {
 				filters: { "name": ["in", doctypes] }
 			};
 		});
 	},
-	
+
 	refresh: function(frm) {
+		erpnext.hide_company();
 		frm.events.hide_unhide_fields(frm);
 		frm.events.set_dynamic_labels(frm);
 		frm.events.show_general_ledger(frm);
 	},
-	
+
 	hide_unhide_fields: function(frm) {
 		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
-		
-		frm.toggle_display("source_exchange_rate", 
+
+		frm.toggle_display("source_exchange_rate",
 			(frm.doc.paid_amount && frm.doc.paid_from_account_currency != company_currency));
-			
-		frm.toggle_display("target_exchange_rate", (frm.doc.received_amount && 
+
+		frm.toggle_display("target_exchange_rate", (frm.doc.received_amount &&
 			frm.doc.paid_to_account_currency != company_currency &&
 			frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency));
-			
+
 			frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency);
-			
-		frm.toggle_display("base_received_amount", (frm.doc.paid_to_account_currency != company_currency && 
+
+		frm.toggle_display("base_received_amount", (frm.doc.paid_to_account_currency != company_currency &&
 			frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency));
-				
-		frm.toggle_display("received_amount", 
+
+		frm.toggle_display("received_amount",
 			frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)
-				
-		frm.toggle_display(["base_total_allocated_amount"], 
+
+		frm.toggle_display(["base_total_allocated_amount"],
 			(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.base_total_allocated_amount &&
-			((frm.doc.payment_type=="Receive" && frm.doc.paid_from_account_currency != company_currency) || 
+			((frm.doc.payment_type=="Receive" && frm.doc.paid_from_account_currency != company_currency) ||
 			(frm.doc.payment_type=="Pay" && frm.doc.paid_to_account_currency != company_currency))));
-			
-		var party_amount = frm.doc.payment_type=="Receive" ? 
+
+		var party_amount = frm.doc.payment_type=="Receive" ?
 			frm.doc.paid_amount : frm.doc.received_amount;
-					
+
 		frm.toggle_display("write_off_difference_amount", (frm.doc.difference_amount && frm.doc.party &&
-			(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) && 
+			(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) &&
 			(frm.doc.total_allocated_amount > party_amount)));
-		
-		frm.toggle_display("set_exchange_gain_loss", 
-			(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.difference_amount && 
-				(frm.doc.paid_from_account_currency != company_currency || 
+
+		frm.toggle_display("set_exchange_gain_loss",
+			(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.difference_amount &&
+				(frm.doc.paid_from_account_currency != company_currency ||
 					frm.doc.paid_to_account_currency != company_currency)));
-			
+
 		frm.refresh_fields();
 	},
-	
+
 	set_dynamic_labels: function(frm) {
 		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
-		
+
 		var field_label_map = {};
 		var grid_field_label_map = {};
 
@@ -135,7 +136,7 @@
 				if(docfield) {
 					var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
 					if(parentfield) {
-						grid_field_label_map[doctype + "-" + fname] = 
+						grid_field_label_map[doctype + "-" + fname] =
 							label.trim() + " (" + __(currency) + ")";
 					} else {
 						field_label_map[fname] = label.trim() + " (" + currency + ")";
@@ -143,42 +144,42 @@
 				}
 			});
 		}
-		
-		setup_field_label_map(["base_paid_amount", "base_received_amount", "base_total_allocated_amount", 
+
+		setup_field_label_map(["base_paid_amount", "base_received_amount", "base_total_allocated_amount",
 			"difference_amount"], company_currency);
-		
+
 		setup_field_label_map(["paid_amount"], frm.doc.paid_from_account_currency);
 		setup_field_label_map(["received_amount"], frm.doc.paid_to_account_currency);
-		
-		var party_account_currency = frm.doc.payment_type=="Receive" ? 
+
+		var party_account_currency = frm.doc.payment_type=="Receive" ?
 			frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency;
 
 		setup_field_label_map(["total_allocated_amount", "unallocated_amount"], party_account_currency);
-		
+
 		$.each(field_label_map, function(fname, label) {
 			me.frm.fields_dict[fname].set_label(label);
 		});
-		
-		setup_field_label_map(["total_amount", "outstanding_amount", "allocated_amount"], 
+
+		setup_field_label_map(["total_amount", "outstanding_amount", "allocated_amount"],
 			party_account_currency, "references");
-			
+
 		setup_field_label_map(["amount"], company_currency, "deductions");
-		
+
 		$.each(grid_field_label_map, function(fname, label) {
 			fname = fname.split("-");
 			var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
 			if(df) df.label = label;
 		});
-		
-		cur_frm.set_df_property("source_exchange_rate", "description", 
+
+		cur_frm.set_df_property("source_exchange_rate", "description",
 			("1 " + frm.doc.paid_from_account_currency + " = [?] " + company_currency));
-		
-		cur_frm.set_df_property("target_exchange_rate", "description", 
+
+		cur_frm.set_df_property("target_exchange_rate", "description",
 			("1 " + frm.doc.paid_to_account_currency + " = [?] " + company_currency));
-			
+
 		frm.refresh_fields();
 	},
-	
+
 	show_general_ledger: function(frm) {
 		if(frm.doc.docstatus==1) {
 			frm.add_custom_button(__('Ledger'), function() {
@@ -193,27 +194,27 @@
 			}, "icon-table");
 		}
 	},
-	
+
 	payment_type: function(frm) {
 		if(frm.doc.payment_type == "Internal Transfer") {
-			$.each(["party", "party_balance", "paid_from", "paid_to", 
+			$.each(["party", "party_balance", "paid_from", "paid_to",
 				"references", "total_allocated_amount"], function(i, field) {
 					frm.set_value(field, null);
 			})
 		} else {
 			if(!frm.doc.party)
 				frm.set_value("party_type", frm.doc.payment_type=="Receive" ? "Customer" : "Supplier");
-			else 
+			else
 				frm.events.party(frm);
-			
+
 			if(frm.doc.mode_of_payment)
 				frm.events.mode_of_payment(frm);
 		}
 	},
-	
+
 	party_type: function(frm) {
 		if(frm.doc.party) {
-			$.each(["party", "party_balance", "paid_from", "paid_to", 
+			$.each(["party", "party_balance", "paid_from", "paid_to",
 				"paid_from_account_currency", "paid_from_account_balance",
 				"paid_to_account_currency", "paid_to_account_balance",
 				"references", "total_allocated_amount"], function(i, field) {
@@ -221,17 +222,17 @@
 			})
 		}
 	},
-		
+
 	party: function(frm) {
 		if(frm.doc.payment_type && frm.doc.party_type && frm.doc.party) {
 			frm.set_party_account_based_on_party = true;
-			
+
 			return frappe.call({
 				method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_party_details",
 				args: {
 					company: frm.doc.company,
 					party_type: frm.doc.party_type,
-					party: frm.doc.party, 
+					party: frm.doc.party,
 					date: frm.doc.posting_date
 				},
 				callback: function(r, rt) {
@@ -255,7 +256,7 @@
 			});
 		}
 	},
-		
+
 	mode_of_payment: function(frm) {
 		return  frappe.call({
 			method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
@@ -271,28 +272,28 @@
 			}
 		});
 	},
-	
+
 	paid_from: function(frm) {
 		if(frm.set_party_account_based_on_party) return;
-		
-		frm.events.set_account_currency_and_balance(frm, frm.doc.paid_from, 
+
+		frm.events.set_account_currency_and_balance(frm, frm.doc.paid_from,
 			"paid_from_account_currency", "paid_from_account_balance", function(frm) {
 				if(frm.doc.payment_type == "Receive") frm.events.get_outstanding_documents(frm);
 			}
 		);
-	},	
-	
+	},
+
 	paid_to: function(frm) {
 		if(frm.set_party_account_based_on_party) return;
-		
-		frm.events.set_account_currency_and_balance(frm, frm.doc.paid_to, 
+
+		frm.events.set_account_currency_and_balance(frm, frm.doc.paid_to,
 			"paid_to_account_currency", "paid_to_account_balance", function(frm) {
 				if(frm.doc.payment_type == "Pay") frm.events.get_outstanding_documents(frm);
 			}
 		);
 	},
-	
-	set_account_currency_and_balance: function(frm, account, currency_field, 
+
+	set_account_currency_and_balance: function(frm, account, currency_field,
 			balance_field, callback_function) {
 		frappe.call({
 			method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_account_details",
@@ -304,33 +305,33 @@
 				if(r.message) {
 					frm.set_value(currency_field, r.message['account_currency']);
 					frm.set_value(balance_field, r.message['account_balance']);
-					
+
 					if(frm.doc.payment_type=="Receive" && currency_field=="paid_to_account_currency") {
-						frm.toggle_reqd(["reference_no", "reference_date"], 
+						frm.toggle_reqd(["reference_no", "reference_date"],
 							(r.message['account_type'] == "Bank" ? 1 : 0));
 						if(!frm.doc.received_amount && frm.doc.paid_amount)
 							frm.events.paid_amount(frm);
-					} else if(frm.doc.payment_type=="Pay" && currency_field=="paid_from_account_currency") { 
-						frm.toggle_reqd(["reference_no", "reference_date"], 
+					} else if(frm.doc.payment_type=="Pay" && currency_field=="paid_from_account_currency") {
+						frm.toggle_reqd(["reference_no", "reference_date"],
 							(r.message['account_type'] == "Bank" ? 1 : 0));
-							
+
 						if(!frm.doc.paid_amount && frm.doc.received_amount)
 							frm.events.received_amount(frm);
 					}
-					
+
 					if(callback_function) callback_function(frm);
-						
+
 					frm.events.hide_unhide_fields(frm);
 					frm.events.set_dynamic_labels(frm);
 				}
 			}
 		});
 	},
-	
+
 	paid_from_account_currency: function(frm) {
 		if(!frm.doc.paid_from_account_currency) return;
 		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
-		
+
 		if (frm.doc.paid_from_account_currency == company_currency) {
 			frm.set_value("source_exchange_rate", 1);
 		} else if (frm.doc.paid_from){
@@ -345,20 +346,20 @@
 					}
 				})
 			} else {
-				frm.events.set_current_exchange_rate(frm, "source_exchange_rate", 
+				frm.events.set_current_exchange_rate(frm, "source_exchange_rate",
 					frm.doc.paid_from_account_currency, company_currency);
 			}
 		}
 	},
-	
+
 	paid_to_account_currency: function(frm) {
 		if(!frm.doc.paid_to_account_currency) return;
 		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
-		
-		frm.events.set_current_exchange_rate(frm, "target_exchange_rate", 
+
+		frm.events.set_current_exchange_rate(frm, "target_exchange_rate",
 			frm.doc.paid_to_account_currency, company_currency);
 	},
-	
+
 	set_current_exchange_rate: function(frm, exchange_rate_field, from_currency, to_currency) {
 		frappe.call({
 			method: "erpnext.setup.utils.get_exchange_rate",
@@ -371,24 +372,24 @@
 			}
 		})
 	},
-	
+
 	source_exchange_rate: function(frm) {
 		if (frm.doc.paid_amount) {
 			frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
 		}
 	},
-	
+
 	target_exchange_rate: function(frm) {
 		if (frm.doc.received_amount) {
-			frm.set_value("base_received_amount", 
+			frm.set_value("base_received_amount",
 				flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate));
 		}
 	},
-	
+
 	paid_amount: function(frm) {
 		frm.set_value("base_paid_amount", flt(frm.doc.paid_amount) * flt(frm.doc.source_exchange_rate));
-		
-		if(!frm.set_paid_amount_based_on_received_amount && 
+
+		if(!frm.set_paid_amount_based_on_received_amount &&
 				(frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency)) {
 			frm.set_value("received_amount", frm.doc.paid_amount);
 			frm.set_value("target_exchange_rate", frm.doc.source_exchange_rate);
@@ -398,33 +399,33 @@
 			frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount);
 		else
 			frm.events.set_difference_amount(frm);
-		
+
 		frm.set_paid_amount_based_on_received_amount = false;
 	},
-	
+
 	received_amount: function(frm) {
 		frm.set_paid_amount_based_on_received_amount = true;
-		
+
 		if(!frm.doc.paid_amount && frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency) {
 			frm.set_value("paid_amount", frm.doc.received_amount);
 			frm.set_value("source_exchange_rate", frm.doc.target_exchange_rate);
 			frm.set_value("base_paid_amount", frm.doc.base_received_amount);
 		}
-		
-		frm.set_value("base_received_amount", 
+
+		frm.set_value("base_received_amount",
 			flt(frm.doc.received_amount) * flt(frm.doc.target_exchange_rate));
-			
+
 		if(frm.doc.payment_type == "Pay")
 			frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.received_amount);
 		else
 			frm.events.set_difference_amount(frm);
 	},
-	
+
 	get_outstanding_documents: function(frm) {
 		frm.clear_table("references");
-		
+
 		if(!frm.doc.party) return;
-		
+
 		frm.events.check_mandatory_to_fetch(frm);
 		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
 
@@ -443,7 +444,7 @@
 				if(r.message) {
 					var total_positive_outstanding = 0;
 					var total_negative_outstanding = 0;
-					
+
 					$.each(r.message, function(i, d) {
 						var c = frm.add_child("references");
 						c.reference_doctype = d.voucher_type;
@@ -456,8 +457,8 @@
 							else
 								total_negative_outstanding += Math.abs(flt(d.outstanding_amount));
 						}
-							
-						var party_account_currency = frm.doc.payment_type=="Receive" ? 
+
+						var party_account_currency = frm.doc.payment_type=="Receive" ?
 							frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency;
 
 						if(party_account_currency != company_currency) {
@@ -469,51 +470,51 @@
 							c.due_date = d.due_date;
 						}
 					});
-					
-					if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || 
+
+					if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
 						(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier")) {
 							if(total_positive_outstanding > total_negative_outstanding)
-								frm.set_value("paid_amount", 
+								frm.set_value("paid_amount",
 									total_positive_outstanding - total_negative_outstanding);
-					} else if (total_negative_outstanding && 
+					} else if (total_negative_outstanding &&
 							(total_positive_outstanding < total_negative_outstanding)) {
-						frm.set_value("received_amount", 
+						frm.set_value("received_amount",
 							total_negative_outstanding - total_positive_outstanding);
 					}
 				}
-				
+
 				frm.events.allocate_party_amount_against_ref_docs(frm,
 					(frm.doc.payment_type=="Receive" ? frm.doc.paid_amount : frm.doc.received_amount));
 			}
 		});
 	},
-	
+
 	allocate_party_amount_against_ref_docs: function(frm, paid_amount) {
 		var total_positive_outstanding_including_order = 0;
 		var total_negative_outstanding = 0;
-		
+
 		$.each(frm.doc.references || [], function(i, row) {
 			if(flt(row.outstanding_amount) > 0)
 				total_positive_outstanding_including_order += flt(row.outstanding_amount);
 			else
 				total_negative_outstanding += Math.abs(flt(row.outstanding_amount));
 		})
-		
+
 		var allocated_negative_outstanding = 0;
-		if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || 
+		if((frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") ||
 				(frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier")) {
 			if(total_positive_outstanding_including_order > paid_amount) {
 				var remaining_outstanding = total_positive_outstanding_including_order - paid_amount;
-				allocated_negative_outstanding = total_negative_outstanding < remaining_outstanding ? 
+				allocated_negative_outstanding = total_negative_outstanding < remaining_outstanding ?
 					total_negative_outstanding : remaining_outstanding;
 			}
-		
+
 			var allocated_positive_outstanding =  paid_amount + allocated_negative_outstanding;
 		} else {
 			if(paid_amount > total_negative_outstanding) {
 				if(total_negative_outstanding == 0) {
-					frappe.msgprint(__("Cannot {0} {1} {2} without any negative outstanding invoice", 
-						[frm.doc.payment_type, 
+					frappe.msgprint(__("Cannot {0} {1} {2} without any negative outstanding invoice",
+						[frm.doc.payment_type,
 							(frm.doc.party_type=="Customer" ? "to" : "from"), frm.doc.party_type]));
 					return false
 				} else {
@@ -522,66 +523,66 @@
 				}
 			} else {
 				allocated_positive_outstanding = total_negative_outstanding - paid_amount;
-				allocated_negative_outstanding = paid_amount + 
-					(total_positive_outstanding_including_order < allocated_positive_outstanding ? 
+				allocated_negative_outstanding = paid_amount +
+					(total_positive_outstanding_including_order < allocated_positive_outstanding ?
 						total_positive_outstanding_including_order : allocated_positive_outstanding)
 			}
 		}
-		
+
 		$.each(frm.doc.references || [], function(i, row) {
 			row.allocated_amount = 0
-			
+
 			if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
-				if(row.outstanding_amount >= allocated_positive_outstanding) 
+				if(row.outstanding_amount >= allocated_positive_outstanding)
 						row.allocated_amount = allocated_positive_outstanding;
 				else row.allocated_amount = row.outstanding_amount;
-				
+
 				allocated_positive_outstanding -= flt(row.allocated_amount);
 			} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
 				if(Math.abs(row.outstanding_amount) >= allocated_negative_outstanding)
 					row.allocated_amount = -1*allocated_negative_outstanding;
 				else row.allocated_amount = row.outstanding_amount;
-				
+
 				allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
 			}
 		})
 		frm.refresh_fields()
 		frm.events.set_total_allocated_amount(frm);
 	},
-	
+
 	set_total_allocated_amount: function(frm) {
 		var total_allocated_amount = base_total_allocated_amount = 0.0;
 		$.each(frm.doc.references || [], function(i, row) {
 			if (row.allocated_amount) {
 				total_allocated_amount += flt(row.allocated_amount);
-				base_total_allocated_amount += flt(flt(row.allocated_amount)*flt(row.exchange_rate), 
+				base_total_allocated_amount += flt(flt(row.allocated_amount)*flt(row.exchange_rate),
 					precision("base_paid_amount"));
 			}
 		});
 		frm.set_value("total_allocated_amount", Math.abs(total_allocated_amount));
 		frm.set_value("base_total_allocated_amount", Math.abs(base_total_allocated_amount));
-					
+
 		frm.events.set_difference_amount(frm);
 	},
-	
+
 	set_difference_amount: function(frm) {
 		var unallocated_amount = 0;
 		if(frm.doc.party) {
-			var party_amount = frm.doc.payment_type=="Receive" ? 
+			var party_amount = frm.doc.payment_type=="Receive" ?
 				frm.doc.paid_amount : frm.doc.received_amount;
-		
+
 			if(frm.doc.total_allocated_amount < party_amount)
 				unallocated_amount = party_amount - frm.doc.total_allocated_amount;
-		}	
-		
+		}
+
 		frm.set_value("unallocated_amount", unallocated_amount);
-		
+
 		var difference_amount = 0;
-		var base_unallocated_amount = flt(frm.doc.unallocated_amount) *	
+		var base_unallocated_amount = flt(frm.doc.unallocated_amount) *
 			(frm.doc.payment_type=="Receive" ? frm.doc.source_exchange_rate : frm.doc.target_exchange_rate);
-			
+
 		var base_party_amount = flt(frm.doc.base_total_allocated_amount) + base_unallocated_amount;
-		
+
 		if(frm.doc.payment_type == "Receive") {
 			difference_amount = base_party_amount - flt(frm.doc.base_received_amount);
 		} else if (frm.doc.payment_type == "Pay") {
@@ -589,26 +590,26 @@
 		} else {
 			difference_amount = flt(frm.doc.base_paid_amount) - flt(frm.doc.base_received_amount);
 		}
-		
+
 		$.each(frm.doc.deductions || [], function(i, d) {
 			if(d.amount) difference_amount -= flt(d.amount);
 		})
-		
+
 		frm.set_value("difference_amount", difference_amount);
-		
+
 		frm.events.hide_unhide_fields(frm);
 	},
-	
+
 	check_mandatory_to_fetch: function(frm) {
 		$.each(["Company", "Party Type", "Party", "payment_type"], function(i, field) {
 			if(!frm.doc[frappe.model.scrub(field)]) {
 				frappe.msgprint(__("Please select {0} first", [field]));
 				return false;
 			}
-				
+
 		});
 	},
-		
+
 	validate_reference_document: function(frm, row) {
 		var _validate = function(i, row) {
 			if (!row.reference_doctype) {
@@ -622,7 +623,7 @@
 					return false;
 				}
 
-			if(frm.doc.party_type=="Supplier" && !in_list(["Purchase Order", 
+			if(frm.doc.party_type=="Supplier" && !in_list(["Purchase Order",
 				"Purchase Invoice", "Journal Entry"], row.reference_doctype)) {
 					frappe.model.set_value(row.doctype, row.name, "against_voucher_type", null);
 					frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Purchase Order, Purchase Invoice or Journal Entry", [row.idx]));
@@ -636,15 +637,15 @@
 			$.each(frm.doc.vouchers || [], _validate);
 		}
 	},
-	
+
 	write_off_difference_amount: function(frm) {
-		frm.events.set_deductions_entry(frm, "write_off_account");	
+		frm.events.set_deductions_entry(frm, "write_off_account");
 	},
 
 	set_exchange_gain_loss: function(frm) {
 		frm.events.set_deductions_entry(frm, "exchange_gain_loss_account");
 	},
-	
+
 	set_deductions_entry: function(frm, account) {
 		if(frm.doc.difference_amount) {
 			frappe.call({
@@ -654,9 +655,9 @@
 				},
 				callback: function(r, rt) {
 					if(r.message) {
-						var write_off_row = $.map(frm.doc["deductions"] || [], function(t) { 
+						var write_off_row = $.map(frm.doc["deductions"] || [], function(t) {
 							return t.account==r.message[account] ? t : null; });
-						
+
 						if (!write_off_row.length) {
 							var row = frm.add_child("deductions");
 							row.account = r.message[account];
@@ -664,10 +665,10 @@
 						} else {
 							var row = write_off_row[0];
 						}
-						
+
 						row.amount = flt(row.amount) + flt(frm.doc.difference_amount);
 						refresh_field("deductions");
-						
+
 						frm.events.set_difference_amount(frm);
 					}
 				}
@@ -682,7 +683,7 @@
 		var row = locals[cdt][cdn];
 		frm.events.validate_reference_document(frm, row);
 	},
-	
+
 	reference_name: function(frm, cdt, cdn) {
 		var row = locals[cdt][cdn];
 		return frappe.call({
@@ -690,9 +691,9 @@
 			args: {
 				reference_doctype: row.reference_doctype,
 				reference_name: row.reference_name,
-				party_account_currency: frm.doc.payment_type=="Receive" ? 
+				party_account_currency: frm.doc.payment_type=="Receive" ?
 					frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency
-			}, 
+			},
 			callback: function(r, rt) {
 				if(r.message) {
 					$.each(r.message, function(field, value) {
@@ -703,11 +704,11 @@
 			}
 		})
 	},
-	
+
 	allocated_amount: function(frm) {
 		frm.events.set_total_allocated_amount(frm);
 	},
-	
+
 	references_remove: function(frm) {
 		frm.events.set_total_allocated_amount(frm);
 	}
@@ -717,7 +718,7 @@
 	amount: function(frm) {
 		frm.events.set_difference_amount(frm);
 	},
-	
+
 	deductions_remove: function(frm) {
 		frm.events.set_difference_amount(frm);
 	}
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json
index d816eb8..5f14c2f 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.json
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json
@@ -9,9 +9,35 @@
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "", 
+ "editable_grid": 0, 
  "fields": [
   {
    "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "type_of_payment", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Type of Payment", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
    "fieldname": "naming_series", 
@@ -66,6 +92,60 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", 
+   "fieldname": "party_type", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Party Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Customer\nSupplier", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type", 
+   "fieldname": "party", 
+   "fieldtype": "Dynamic Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Party", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "party_type", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
    "fieldname": "column_break_5", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -167,16 +247,15 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
-   "collapsible": 0, 
-   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", 
-   "fieldname": "party_section", 
+   "collapsible": 1, 
+   "fieldname": "payment_accounts_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "", 
+   "label": "Accounts", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -194,84 +273,6 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", 
-   "fieldname": "party_type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Party Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Customer\nSupplier", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "column_break_10", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type", 
-   "fieldname": "party", 
-   "fieldtype": "Dynamic Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Party", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "party_type", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
    "depends_on": "party", 
    "fieldname": "party_balance", 
    "fieldtype": "Currency", 
@@ -296,31 +297,6 @@
   }, 
   {
    "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "payment_accounts_section", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
    "depends_on": "eval:(in_list([\"Internal Transfer\", \"Pay\"], doc.payment_type) || doc.party)", 
@@ -518,7 +494,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "", 
+   "label": "Amount", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -729,7 +705,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Reference Documents", 
+   "label": "Reference", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -782,6 +758,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "label": "Writeoff", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -1040,7 +1017,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Transaction References", 
+   "label": "Transaction ID", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -1372,7 +1349,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-07-04 15:00:53.731584", 
+ "modified": "2016-07-11 06:25:00.248907", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Entry", 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 107fbc0..9624967 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -10,6 +10,10 @@
 		erpnext.queries.setup_queries(frm, "Warehouse", function() {
 			return erpnext.queries.warehouse(frm.doc);
 		});
+
+		frm.set_indicator_formatter('item_code',
+			function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" })
+
 	}
 });
 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py b/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py
index 4f1f576..0812790 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order_dashboard.py
@@ -5,7 +5,7 @@
 	'fieldname': 'purchase_order',
 	'transactions': [
 		{
-			'label': _('Related Documents'),
+			'label': _('Related'),
 			'items': ['Purchase Receipt', 'Purchase Invoice', 'Stock Entry']
 		},
 	]
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py
index 395e357..4bb4d76 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation_dashboard.py
@@ -5,7 +5,7 @@
 	'fieldname': 'request_for_quotation',
 	'transactions': [
 		{
-			'label': _('Related Documents'),
+			'label': _('Related'),
 			'items': ['Supplier Quotation']
 		},
 	]
diff --git a/erpnext/crm/doctype/opportunity/opportunity_dashboard.py b/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
index 6442d35..08d5657 100644
--- a/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
+++ b/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
@@ -4,7 +4,7 @@
 	'fieldname': 'prevdoc_docname',
 	'transactions': [
 		{
-			'label': _('Related Documents'),
+			'label': _('Related'),
 			'items': ['Quotation']
 		},
 	]
diff --git a/erpnext/demo/setup_data.py b/erpnext/demo/setup_data.py
index 137a073..eb80254 100644
--- a/erpnext/demo/setup_data.py
+++ b/erpnext/demo/setup_data.py
@@ -147,6 +147,7 @@
 	for i in items:
 		item = frappe.new_doc('Item')
 		item.update(i)
+		item.min_order_qty = random.randint(10, 30)
 		item.default_warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1)[0].name
 		item.insert()
 
diff --git a/erpnext/demo/user/stock.py b/erpnext/demo/user/stock.py
index 8266d7e..d2a7254 100644
--- a/erpnext/demo/user/stock.py
+++ b/erpnext/demo/user/stock.py
@@ -29,11 +29,8 @@
 
 			pr.posting_date = frappe.flags.current_date
 			pr.insert()
-			try:
-				pr.submit()
-				frappe.db.commit()
-			except (NegativeStockError):
-				frappe.db.rollback()
+			pr.submit()
+			frappe.db.commit()
 
 def make_delivery_note():
 	# make purchase requests
diff --git a/erpnext/public/js/utils/document_flow.js b/erpnext/public/js/utils/document_flow.js
index d453c68..0bc0b44 100644
--- a/erpnext/public/js/utils/document_flow.js
+++ b/erpnext/public/js/utils/document_flow.js
@@ -14,8 +14,8 @@
 			"Purchase Invoice", "Payment Entry"]
 	},
 	"Buying": {
-		"Purchase Order": ["Supplier Quotation", "Purchase Order", "Purchase Receipt",
-			"Purchase Invoice", "Payment Entry"],
+		// "Purchase Order": ["Supplier Quotation", "Purchase Order", "Purchase Receipt",
+		// 	"Purchase Invoice", "Payment Entry"],
 		"Supplier Quotation": ["Supplier Quotation", "Purchase Order", "Purchase Receipt",
 			"Purchase Invoice", "Payment Entry"]
 	},
diff --git a/erpnext/stock/doctype/item_reorder/item_reorder.json b/erpnext/stock/doctype/item_reorder/item_reorder.json
index 2bb7209..4c98c3f 100644
--- a/erpnext/stock/doctype/item_reorder/item_reorder.json
+++ b/erpnext/stock/doctype/item_reorder/item_reorder.json
@@ -21,8 +21,8 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Warehouse Group", 
+   "in_list_view": 1, 
+   "label": "Check in (group)", 
    "length": 0, 
    "no_copy": 0, 
    "options": "Warehouse", 
@@ -48,7 +48,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Warehouse", 
+   "label": "Request for", 
    "length": 0, 
    "no_copy": 0, 
    "options": "Warehouse", 
@@ -146,7 +146,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-11 03:19:14.851011", 
+ "modified": "2016-07-11 03:59:06.870780", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item Reorder", 
diff --git a/erpnext/stock/doctype/material_request/material_request_dashboard.py b/erpnext/stock/doctype/material_request/material_request_dashboard.py
index 7ed1040..da6790d 100644
--- a/erpnext/stock/doctype/material_request/material_request_dashboard.py
+++ b/erpnext/stock/doctype/material_request/material_request_dashboard.py
@@ -5,7 +5,7 @@
 	'fieldname': 'material_request',
 	'transactions': [
 		{
-			'label': _('Related Documents'),
+			'label': _('Related'),
 			'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order']
 		},
 	]