[Enhancement] Added allocate payment amount checkbox in Payment Entry
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 695a721..6ce8bf0 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -511,6 +511,18 @@
 		});
 	},
 
+	allocate_payment_amount: function(frm) {
+		if(frm.doc.payment_type == 'Internal Transfer'){
+			return
+		}
+
+		if(frm.doc.references.length == 0){
+			frm.events.get_outstanding_documents(frm);
+		}
+
+		frm.events.allocate_party_amount_against_ref_docs(frm, 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;
@@ -552,22 +564,24 @@
 		}
 
 		$.each(frm.doc.references || [], function(i, row) {
-			row.allocated_amount = 0
+			row.allocated_amount = 0 //If allocate payment amount checkbox is unchecked, set zero to allocate amount
+			if(frm.doc.allocate_payment_amount){
+				if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
+					if(row.outstanding_amount >= allocated_positive_outstanding)
+							row.allocated_amount = allocated_positive_outstanding;
+					else row.allocated_amount = row.outstanding_amount;
 
-			if(row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
-				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_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));
+					allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
+				}
 			}
 		})
+
 		frm.refresh_fields()
 		frm.events.set_total_allocated_amount(frm);
 	},
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json
index 2057d07..6018571 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.json
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json
@@ -777,6 +777,34 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "default": "1", 
+   "depends_on": "eval:in_list(['Pay', 'Receive'], doc.payment_type)", 
+   "fieldname": "allocate_payment_amount", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Allocate Payment Amount", 
+   "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": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "", 
    "fieldname": "references", 
    "fieldtype": "Table", 
@@ -1426,7 +1454,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-09-05 11:06:18.183458", 
+ "modified": "2016-09-28 18:20:47.625383", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Entry", 
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 179a321..7b9bf16 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -669,6 +669,7 @@
 	pe.paid_to_account_currency = party_account_currency if payment_type=="Pay" else bank.account_currency
 	pe.paid_amount = paid_amount
 	pe.received_amount = received_amount
+	pe.allocate_payment_amount = 1
 	
 	pe.append("references", {
 		"reference_doctype": dt,