Annual billing amount in party dashboard based on grand total
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index f0c29bc..d54b5b9 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -7,10 +7,13 @@
 import datetime
 from frappe import _, msgprint, scrub
 from frappe.defaults import get_user_permissions
-from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, add_years, get_timestamp
+from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, \
+	add_years, get_timestamp, nowdate
 from frappe.geo.doctype.address.address import get_address_display, get_default_address
 from frappe.email.doctype.contact.contact import get_contact_details, get_default_contact
 from erpnext.exceptions import PartyFrozen, InvalidCurrency, PartyDisabled, InvalidAccountCurrency
+from erpnext.accounts.utils import get_fiscal_year
+from erpnext import get_default_currency
 
 class DuplicatePartyAccountError(frappe.ValidationError): pass
 
@@ -359,4 +362,34 @@
 		timestamp = get_timestamp(date)
 		out.update({ timestamp: count })
 
-	return out
\ No newline at end of file
+	return out
+	
+def get_dashboard_info(party_type, party):
+	current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True)
+	party_account_currency = get_party_account_currency(party_type, party, frappe.db.get_default("company"))
+	company_default_currency = get_default_currency()
+		
+	if party_account_currency==company_default_currency:
+		total_field = "base_grand_total"
+	else:
+		total_field = "grand_total"
+		
+	doctype = "Sales Invoice" if party_type=="Customer" else "Purchase Invoice"
+	
+	billing_this_year = frappe.db.sql("""
+		select sum({0})
+		from `tab{1}`
+		where {2}=%s and docstatus=1 and posting_date between %s and %s
+	""".format(total_field, doctype, party_type.lower()), 
+	(party, current_fiscal_year.year_start_date, current_fiscal_year.year_end_date))
+
+	total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
+		from `tab{0}`
+		where {1}=%s and docstatus = 1""".format(doctype, party_type.lower()), party)
+
+	info = {}
+	info["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
+	info["currency"] = party_account_currency
+	info["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
+	
+	return info
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index 704e828..3b6ae62 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -6,11 +6,9 @@
 import frappe.defaults
 from frappe import msgprint, _
 from frappe.model.naming import make_autoname
-from frappe.geo.address_and_contact import (load_address_and_contact,
-	delete_contact_and_address)
-
+from frappe.geo.address_and_contact import load_address_and_contact, delete_contact_and_address
 from erpnext.utilities.transaction_base import TransactionBase
-from erpnext.accounts.party import validate_party_accounts, get_timeline_data # keep this
+from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
 
 class Supplier(TransactionBase):
 	def get_feed(self):
@@ -22,22 +20,7 @@
 		self.load_dashboard_info()
 
 	def load_dashboard_info(self):
-		billing_this_year = frappe.db.sql("""
-			select sum(credit_in_account_currency) - sum(debit_in_account_currency)
-			from `tabGL Entry`
-			where voucher_type='Purchase Invoice' and party_type = 'Supplier'
-				and party=%s and fiscal_year = %s""",
-			(self.name, frappe.db.get_default("fiscal_year")))
-
-		total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
-			from `tabPurchase Invoice`
-			where supplier=%s and docstatus = 1""", self.name)
-
-
-		info = {}
-		info["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
-		info["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
-
+		info = get_dashboard_info(self.doctype, self.name)
 		self.set_onload('dashboard_info', info)
 
 	def autoname(self):
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index e4101af..c0b3b84 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -10,8 +10,7 @@
 from frappe.desk.reportview import build_match_conditions
 from erpnext.utilities.transaction_base import TransactionBase
 from frappe.geo.address_and_contact import load_address_and_contact, delete_contact_and_address
-from erpnext.accounts.party import validate_party_accounts, get_timeline_data # keep this
-from erpnext import get_default_currency
+from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
 
 class Customer(TransactionBase):
 	def get_feed(self):
@@ -23,25 +22,9 @@
 		self.load_dashboard_info()
 
 	def load_dashboard_info(self):
-		billing_this_year = frappe.db.sql("""
-			select sum(debit_in_account_currency) - sum(credit_in_account_currency), account_currency
-			from `tabGL Entry`
-			where voucher_type='Sales Invoice' and party_type = 'Customer'
-				and party=%s and fiscal_year = %s""",
-			(self.name, frappe.db.get_default("fiscal_year")))
-
-		total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
-			from `tabSales Invoice`
-			where customer=%s and docstatus = 1""", self.name)
-
-		info = {}
-		info["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
-		info["currency"] = billing_this_year[0][1] if billing_this_year else get_default_currency()
-		info["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
-
+		info = get_dashboard_info(self.doctype, self.name)
 		self.set_onload('dashboard_info', info)
 
-
 	def autoname(self):
 		cust_master_name = frappe.defaults.get_global_default('cust_master_name')
 		if cust_master_name == 'Customer Name':