Merge pull request #6973 from RobertSchouten/bankrecon

[fix] layout for bank reconciliation
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js
index 85d3187..f1ccd9f 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.js
@@ -46,6 +46,12 @@
 			callback: function(r, rt) {
 				frm.refresh_field("payment_entries");
 				frm.refresh_fields();
+
+				$(frm.fields_dict.payment_entries.wrapper).find("[data-fieldname=amount]").each(function(i,v){
+					if (i !=0){
+						$(v).addClass("text-right")
+					}
+				})
 			}
 		});
 	}
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
index a56170d..abc6eba 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import flt, getdate, nowdate
+from frappe.utils import flt, getdate, nowdate, fmt_money
 from frappe import msgprint, _
 from frappe.model.document import Document
 
@@ -26,8 +26,8 @@
 			select 
 				"Journal Entry" as payment_document, t1.name as payment_entry, 
 				t1.cheque_no as cheque_number, t1.cheque_date, 
-				abs(t2.debit_in_account_currency - t2.credit_in_account_currency) as amount, 
-				t1.posting_date, t2.against_account, t1.clearance_date
+				t2.debit_in_account_currency as debit, t2.credit_in_account_currency as credit, 
+				t1.posting_date, t2.against_account, t1.clearance_date, t2.account_currency 
 			from
 				`tabJournal Entry` t1, `tabJournal Entry Account` t2
 			where
@@ -36,21 +36,23 @@
 				and ifnull(t1.is_opening, 'No') = 'No' {0}
 			order by t1.posting_date ASC, t1.name DESC
 		""".format(condition), (self.bank_account, self.from_date, self.to_date), as_dict=1)
-				
+
 		payment_entries = frappe.db.sql("""
 			select 
 				"Payment Entry" as payment_document, name as payment_entry, 
 				reference_no as cheque_number, reference_date as cheque_date, 
-				if(paid_from=%s, paid_amount, received_amount) as amount, 
-				posting_date, party as against_account, clearance_date
+				if(paid_from=%(account)s, paid_amount, "") as credit, 
+				if(paid_from=%(account)s, "", received_amount) as debit, 
+				posting_date, ifnull(party,if(paid_from=%(account)s,paid_to,paid_from)) as against_account, clearance_date,
+				if(paid_to=%(account)s, paid_to_account_currency, paid_from_account_currency) as account_currency
 			from `tabPayment Entry`
 			where
-				(paid_from=%s or paid_to=%s) and docstatus=1
-				and posting_date >= %s and posting_date <= %s {0}
+				(paid_from=%(account)s or paid_to=%(account)s) and docstatus=1
+				and posting_date >= %(from)s and posting_date <= %(to)s {0}
 			order by 
 				posting_date ASC, name DESC
 		""".format(condition), 
-		(self.bank_account, self.bank_account, self.bank_account, self.from_date, self.to_date), as_dict=1)
+		        {"account":self.bank_account, "from":self.from_date, "to":self.to_date}, as_dict=1)
 		
 		entries = sorted(list(payment_entries)+list(journal_entries), 
 			key=lambda k: k['posting_date'] or getdate(nowdate()))
@@ -60,6 +62,11 @@
 
 		for d in entries:
 			row = self.append('payment_entries', {})
+
+			d.amount = fmt_money(d.debit if d.debit else d.credit, 2, d.account_currency) + " " + (_("Dr") if d.debit else _("Cr"))
+			d.pop("credit")
+			d.pop("debit")
+			d.pop("account_currency")
 			row.update(d)
 			self.total_amount += flt(d.amount)
 
diff --git a/erpnext/accounts/doctype/bank_reconciliation_detail/bank_reconciliation_detail.json b/erpnext/accounts/doctype/bank_reconciliation_detail/bank_reconciliation_detail.json
index 0f30fee..2e4af26 100644
--- a/erpnext/accounts/doctype/bank_reconciliation_detail/bank_reconciliation_detail.json
+++ b/erpnext/accounts/doctype/bank_reconciliation_detail/bank_reconciliation_detail.json
@@ -40,14 +40,14 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 0, 
+   "columns": 1, 
    "fieldname": "payment_entry", 
    "fieldtype": "Dynamic Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "label": "Payment Entry", 
    "length": 0, 
    "no_copy": 0, 
@@ -69,7 +69,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 3, 
+   "columns": 2, 
    "fieldname": "against_account", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -99,7 +99,7 @@
    "collapsible": 0, 
    "columns": 2, 
    "fieldname": "amount", 
-   "fieldtype": "Currency", 
+   "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -110,7 +110,7 @@
    "no_copy": 0, 
    "oldfieldname": "debit", 
    "oldfieldtype": "Currency", 
-   "options": "account_currency", 
+   "options": "", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
@@ -151,7 +151,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 0, 
+   "columns": 2, 
    "fieldname": "posting_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -178,7 +178,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 3, 
+   "columns": 1, 
    "fieldname": "cheque_number", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -267,7 +267,7 @@
  "istable": 1, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-08-26 01:51:36.123941", 
+ "modified": "2016-11-17 11:39:00.308624", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Bank Reconciliation Detail",