[enhance] show customer, supplier billing and outstanding, fixes #6078
diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js
index 74eecc2..b176e00 100644
--- a/erpnext/buying/doctype/supplier/supplier.js
+++ b/erpnext/buying/doctype/supplier/supplier.js
@@ -30,6 +30,7 @@
unhide_field(['address_html','contact_html']);
erpnext.utils.render_address_and_contact(frm);
+ // custom buttons
frm.add_custom_button(__('Accounting Ledger'), function() {
frappe.set_route('query-report', 'General Ledger',
{party_type:'Supplier', party:frm.doc.name});
@@ -37,6 +38,9 @@
frm.add_custom_button(__('Accounts Payable'), function() {
frappe.set_route('query-report', 'Accounts Payable', {supplier:frm.doc.name});
});
+
+ // indicators
+ erpnext.utils.set_party_dashboard_indicators(frm);
}
},
});
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index a4ee326..3677ee2 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -18,6 +18,26 @@
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self, "supplier")
+ 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
+
+ self.set_onload('dashboard_info', info)
def autoname(self):
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 7330889..6c8898d 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -108,6 +108,17 @@
}
},
+ set_party_dashboard_indicators: function(frm) {
+ if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
+ var info = frm.doc.__onload.dashboard_info;
+ frm.dashboard.add_indicator(__('Annual Billing: {0}',
+ [format_currency(info.billing_this_year, frm.doc.default_currency)]), 'blue');
+ frm.dashboard.add_indicator(__('Total Unpaid: {0}',
+ [format_currency(info.total_unpaid, frm.doc.default_currency)]),
+ info.total_unpaid ? 'orange' : 'green');
+ }
+ },
+
copy_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname) {
var d = locals[dt][dn];
if(d[fieldname]){
diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js
index 0ffe161..ea88e8b 100644
--- a/erpnext/selling/doctype/customer/customer.js
+++ b/erpnext/selling/doctype/customer/customer.js
@@ -37,13 +37,19 @@
if(!frm.doc.__islocal) {
erpnext.utils.render_address_and_contact(frm);
+ // custom buttons
frm.add_custom_button(__('Accounting Ledger'), function() {
frappe.set_route('query-report', 'General Ledger',
{party_type:'Customer', party:frm.doc.name});
});
+
frm.add_custom_button(__('Accounts Receivable'), function() {
frappe.set_route('query-report', 'Accounts Receivable', {customer:frm.doc.name});
});
+
+ // indicator
+ erpnext.utils.set_party_dashboard_indicators(frm);
+
} else {
erpnext.utils.clear_address_and_contact(frm);
}
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index bccc228..82dbba7 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -20,6 +20,26 @@
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self, "customer")
+ 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)
+ 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["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
+
+ self.set_onload('dashboard_info', info)
+
def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name')