Merge pull request #6550 from rohitwaghchaure/make_payment_using_journal_entry

[Enhancement] Option to make payment via Journal Entry
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
index a02e591..c5b3e5b 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
@@ -15,6 +15,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "default": "1", 
    "description": "If enabled, the system will post accounting entries for inventory automatically.", 
    "fieldname": "auto_accounting_for_stock", 
@@ -41,6 +42,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Accounting entry frozen up to this date, nobody can do / modify entry except role specified below.", 
    "fieldname": "acc_frozen_upto", 
    "fieldtype": "Date", 
@@ -66,6 +68,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Users with this role are allowed to set frozen accounts and create / modify accounting entries against frozen accounts", 
    "fieldname": "frozen_accounts_modifier", 
    "fieldtype": "Link", 
@@ -92,6 +95,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -116,6 +120,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "description": "Role that is allowed to submit transactions that exceed credit limits set.", 
    "fieldname": "credit_controller", 
    "fieldtype": "Link", 
@@ -142,6 +147,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "check_supplier_invoice_uniqueness", 
    "fieldtype": "Check", 
    "hidden": 0, 
@@ -162,6 +168,32 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "make_payment_via_journal_entry", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Make Payment via Journal Entry", 
+   "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
   }
  ], 
  "hide_heading": 0, 
@@ -175,8 +207,8 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-07-14 14:32:06.056888", 
- "modified_by": "Administrator", 
+ "modified": "2016-10-05 16:13:10.978208", 
+ "modified_by": "rohitw1991@gmail.com", 
  "module": "Accounts", 
  "name": "Accounts Settings", 
  "owner": "Administrator", 
@@ -191,6 +223,7 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index e245875..3d2f16b 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -26,6 +26,9 @@
 
 		return self.__company_currency
 
+	def onload(self):
+		self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value('Accounts Settings', 'make_payment_via_journal_entry')
+
 	def validate(self):
 		if self.get("_action") and self._action != "update_after_submit":
 			self.set_missing_values(for_validate=True)
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index b9b94f5..3f4d12d 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -23,6 +23,7 @@
 			self.grand_total)
 
 	def onload(self):
+		super(SellingController, self).onload()
 		if self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice"):
 			for item in self.get("items"):
 				item.update(get_bin_details(item.item_code,
diff --git a/erpnext/docs/assets/img/accounts/account-settings.png b/erpnext/docs/assets/img/accounts/account-settings.png
index 943aa3d..dfe2abe 100644
--- a/erpnext/docs/assets/img/accounts/account-settings.png
+++ b/erpnext/docs/assets/img/accounts/account-settings.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/journal-entry.png b/erpnext/docs/assets/img/accounts/journal-entry.png
index d4a4e21..c6a2a64 100644
--- a/erpnext/docs/assets/img/accounts/journal-entry.png
+++ b/erpnext/docs/assets/img/accounts/journal-entry.png
Binary files differ
diff --git a/erpnext/docs/user/manual/en/accounts/index.txt b/erpnext/docs/user/manual/en/accounts/index.txt
index d7c405a..6ba9337 100644
--- a/erpnext/docs/user/manual/en/accounts/index.txt
+++ b/erpnext/docs/user/manual/en/accounts/index.txt
@@ -3,6 +3,7 @@
 sales-invoice
 point-of-sale-pos-invoice
 purchase-invoice
+payments
 journal-entry
 payment-entry
 multi-currency-accounting
diff --git a/erpnext/docs/user/manual/en/accounts/payments.md b/erpnext/docs/user/manual/en/accounts/payments.md
new file mode 100644
index 0000000..7e5aab3
--- /dev/null
+++ b/erpnext/docs/user/manual/en/accounts/payments.md
@@ -0,0 +1,48 @@
+Payment can be made against following transactions.
+
+  1. Sales Invoice.
+  2. Purchase Invoice.
+  3. Sales Order (Advance Payment)
+  4. Purchase Order (Advance Payment)
+  
+In ERPNext, there is two options through which user can capture the payment
+
+  1. Payment Entry(Default).
+  2. Journal Entry.
+  
+## Payment Entry
+
+####Step 1: Make Payment
+
+On submitting a document against which Payment Entry can be made, you will find Make Payment button.
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/payment-entry-1.png">
+
+####Step 2: Payment Entry
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/payment-entry-9.png">
+
+For more details about payment entry [check here.](https://frappe.github.io/erpnext/user/manual/en/accounts/payment-entry)
+
+## Journal Entry
+
+To make paymant using journal entry, check below steps
+
+####Step 1: Activate Payment via Journal Entry
+
+Goto Accounts Settings > checked Make Payment via Journal Entry
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/account-settings.png">
+
+####Step 2: Make Payment
+
+On submitting a document against which Journal Entry can be made, you will find Make Payment button.
+
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/payment-entry-1.png">
+
+####Step 3: Journal Entry
+
+Save and submit the journal entry to record the payament against the invoice
+<img class="screenshot" alt="Making Payment" src="{{docs_base_url}}/assets/img/accounts/journal-entry.png">
+
+For more details about journal entry [check here.](https://frappe.github.io/erpnext/user/manual/en/accounts/journal-entry)
\ No newline at end of file
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 92161e1..7ac9031 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -989,7 +989,7 @@
 
 	make_payment_entry: function() {
 		return frappe.call({
-			method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry",
+			method: cur_frm.cscript.get_method_for_payment(),
 			args: {
 				"dt": cur_frm.doc.doctype,
 				"dn": cur_frm.doc.name
@@ -1000,5 +1000,18 @@
 				// cur_frm.refresh_fields()
 			}
 		});
+	},
+
+	get_method_for_payment: function(){
+		method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry"
+		if(cur_frm.doc.__onload && cur_frm.doc.__onload.make_payment_via_journal_entry){
+			if(in_list(['Sales Invoice', 'Purchase Invoice'],  cur_frm.doc.doctype)){
+				method = "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_invoice"
+			}else {
+				method= "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_order"
+			}
+		}
+
+		return method
 	}
 });
\ No newline at end of file