Merge pull request #24629 from deepeshgarg007/loan_dashboard

feat: Loans Dashboard
This commit is contained in:
Deepesh Garg 2021-02-23 11:22:32 +05:30 committed by GitHub
commit 8f8d9744f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 614 additions and 5 deletions

View File

@ -0,0 +1,29 @@
{
"based_on": "disbursement_date",
"chart_name": "Loan Disbursements",
"chart_type": "Sum",
"creation": "2021-02-06 18:40:36.148470",
"docstatus": 0,
"doctype": "Dashboard Chart",
"document_type": "Loan Disbursement",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Disbursement\",\"docstatus\",\"=\",\"1\",false]]",
"group_by_type": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"modified": "2021-02-06 18:40:49.308663",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Disbursements",
"number_of_groups": 0,
"owner": "Administrator",
"source": "",
"time_interval": "Daily",
"timeseries": 1,
"timespan": "Last Month",
"type": "Line",
"use_report_chart": 0,
"value_based_on": "disbursed_amount",
"y_axis": []
}

View File

@ -0,0 +1,31 @@
{
"based_on": "posting_date",
"chart_name": "Loan Interest Accrual",
"chart_type": "Sum",
"color": "#39E4A5",
"creation": "2021-02-18 20:07:04.843876",
"docstatus": 0,
"doctype": "Dashboard Chart",
"document_type": "Loan Interest Accrual",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Interest Accrual\",\"docstatus\",\"=\",\"1\",false]]",
"group_by_type": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"last_synced_on": "2021-02-21 21:01:26.022634",
"modified": "2021-02-21 21:01:44.930712",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Interest Accrual",
"number_of_groups": 0,
"owner": "Administrator",
"source": "",
"time_interval": "Monthly",
"timeseries": 1,
"timespan": "Last Year",
"type": "Line",
"use_report_chart": 0,
"value_based_on": "interest_amount",
"y_axis": []
}

View File

@ -0,0 +1,31 @@
{
"based_on": "creation",
"chart_name": "New Loans",
"chart_type": "Count",
"color": "#449CF0",
"creation": "2021-02-06 16:59:27.509170",
"docstatus": 0,
"doctype": "Dashboard Chart",
"document_type": "Loan",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan\",\"docstatus\",\"=\",\"1\",false]]",
"group_by_type": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"last_synced_on": "2021-02-21 20:55:33.515025",
"modified": "2021-02-21 21:00:33.900821",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "New Loans",
"number_of_groups": 0,
"owner": "Administrator",
"source": "",
"time_interval": "Daily",
"timeseries": 1,
"timespan": "Last Month",
"type": "Bar",
"use_report_chart": 0,
"value_based_on": "",
"y_axis": []
}

View File

@ -0,0 +1,31 @@
{
"based_on": "",
"chart_name": "Top 10 Pledged Loan Securities",
"chart_type": "Custom",
"color": "#EC864B",
"creation": "2021-02-06 22:02:46.284479",
"docstatus": 0,
"doctype": "Dashboard Chart",
"document_type": "",
"dynamic_filters_json": "[]",
"filters_json": "[]",
"group_by_type": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"last_synced_on": "2021-02-21 21:00:57.043034",
"modified": "2021-02-21 21:01:10.048623",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Top 10 Pledged Loan Securities",
"number_of_groups": 0,
"owner": "Administrator",
"source": "Top 10 Pledged Loan Securities",
"time_interval": "Yearly",
"timeseries": 0,
"timespan": "Last Year",
"type": "Bar",
"use_report_chart": 0,
"value_based_on": "",
"y_axis": []
}

View File

@ -0,0 +1,14 @@
frappe.provide('frappe.dashboards.chart_sources');
frappe.dashboards.chart_sources["Top 10 Pledged Loan Securities"] = {
method: "erpnext.loan_management.dashboard_chart_source.top_10_pledged_loan_securities.top_10_pledged_loan_securities.get_data",
filters: [
{
fieldname: "company",
label: __("Company"),
fieldtype: "Link",
options: "Company",
default: frappe.defaults.get_user_default("Company")
}
]
};

View File

@ -0,0 +1,13 @@
{
"creation": "2021-02-06 22:01:01.332628",
"docstatus": 0,
"doctype": "Dashboard Chart Source",
"idx": 0,
"modified": "2021-02-06 22:01:01.332628",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Top 10 Pledged Loan Securities",
"owner": "Administrator",
"source_name": "Top 10 Pledged Loan Securities ",
"timeseries": 0
}

View File

@ -0,0 +1,76 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils.dashboard import cache_source
from erpnext.loan_management.report.applicant_wise_loan_security_exposure.applicant_wise_loan_security_exposure \
import get_loan_security_details
from six import iteritems
@frappe.whitelist()
@cache_source
def get_data(chart_name = None, chart = None, no_cache = None, filters = None, from_date = None,
to_date = None, timespan = None, time_interval = None, heatmap_year = None):
if chart_name:
chart = frappe.get_doc('Dashboard Chart', chart_name)
else:
chart = frappe._dict(frappe.parse_json(chart))
filters = {}
current_pledges = {}
if filters:
filters = frappe.parse_json(filters)[0]
conditions = ""
labels = []
values = []
if filters.get('company'):
conditions = "AND company = %(company)s"
loan_security_details = get_loan_security_details()
unpledges = frappe._dict(frappe.db.sql("""
SELECT u.loan_security, sum(u.qty) as qty
FROM `tabLoan Security Unpledge` up, `tabUnpledge` u
WHERE u.parent = up.name
AND up.status = 'Approved'
{conditions}
GROUP BY u.loan_security
""".format(conditions=conditions), filters, as_list=1))
pledges = frappe._dict(frappe.db.sql("""
SELECT p.loan_security, sum(p.qty) as qty
FROM `tabLoan Security Pledge` lp, `tabPledge`p
WHERE p.parent = lp.name
AND lp.status = 'Pledged'
{conditions}
GROUP BY p.loan_security
""".format(conditions=conditions), filters, as_list=1))
for security, qty in iteritems(pledges):
current_pledges.setdefault(security, qty)
current_pledges[security] -= unpledges.get(security, 0.0)
sorted_pledges = dict(sorted(current_pledges.items(), key=lambda item: item[1], reverse=True))
count = 0
for security, qty in iteritems(sorted_pledges):
values.append(qty * loan_security_details.get(security, {}).get('latest_price', 0))
labels.append(security)
count +=1
## Just need top 10 securities
if count == 10:
break
return {
'labels': labels,
'datasets': [{
'name': 'Top 10 Securities',
'chartType': 'bar',
'values': values
}]
}

View File

@ -348,3 +348,13 @@ def validate_employee_currency_with_company_currency(applicant, company):
if employee_currency != company_currency:
frappe.throw(_("Loan cannot be repayed from salary for Employee {0} because salary is processed in currency {1}")
.format(applicant, employee_currency))
@frappe.whitelist()
def get_shortfall_applicants():
loans = frappe.get_all('Loan Security Shortfall', {'status': 'Pending'}, pluck='loan')
applicants = set(frappe.get_all('Loan', {'name': ('in', loans)}, pluck='name'))
return {
"value": len(applicants),
"fieldtype": "Int"
}

View File

@ -0,0 +1,70 @@
{
"cards": [
{
"card": "New Loans"
},
{
"card": "Active Loans"
},
{
"card": "Closed Loans"
},
{
"card": "Total Disbursed"
},
{
"card": "Open Loan Applications"
},
{
"card": "New Loan Applications"
},
{
"card": "Total Sanctioned Amount"
},
{
"card": "Active Securities"
},
{
"card": "Applicants With Unpaid Shortfall"
},
{
"card": "Total Shortfall Amount"
},
{
"card": "Total Repayment"
},
{
"card": "Total Write Off"
}
],
"charts": [
{
"chart": "New Loans",
"width": "Half"
},
{
"chart": "Loan Disbursements",
"width": "Half"
},
{
"chart": "Top 10 Pledged Loan Securities",
"width": "Half"
},
{
"chart": "Loan Interest Accrual",
"width": "Half"
}
],
"creation": "2021-02-06 16:52:43.484752",
"dashboard_name": "Loan Dashboard",
"docstatus": 0,
"doctype": "Dashboard",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"modified": "2021-02-21 20:53:47.531699",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Dashboard",
"owner": "Administrator"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "",
"creation": "2021-02-06 17:10:26.132493",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan\",\"docstatus\",\"=\",\"1\",false],[\"Loan\",\"status\",\"in\",[\"Disbursed\",\"Partially Disbursed\",null],false]]",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Active Loans",
"modified": "2021-02-06 17:29:20.304087",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Active Loans",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"type": "Document Type"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "",
"creation": "2021-02-06 19:07:21.344199",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Security",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Security\",\"disabled\",\"=\",0,false]]",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Active Securities",
"modified": "2021-02-06 19:07:26.671516",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Active Securities",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -0,0 +1,21 @@
{
"creation": "2021-02-07 18:55:12.632616",
"docstatus": 0,
"doctype": "Number Card",
"filters_json": "null",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Applicants With Unpaid Shortfall",
"method": "erpnext.loan_management.doctype.loan.loan.get_shortfall_applicants",
"modified": "2021-02-07 21:46:27.369795",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Applicants With Unpaid Shortfall",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Custom"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "",
"creation": "2021-02-21 19:51:49.261813",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan\",\"docstatus\",\"=\",\"1\",false],[\"Loan\",\"status\",\"=\",\"Closed\",false]]",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Closed Loans",
"modified": "2021-02-21 19:51:54.087903",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Closed Loans",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -0,0 +1,21 @@
{
"creation": "2021-02-07 21:57:14.758007",
"docstatus": 0,
"doctype": "Number Card",
"filters_json": "null",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Last Interest Accrual",
"method": "erpnext.loan_management.doctype.loan.loan.get_last_accrual_date",
"modified": "2021-02-07 21:59:47.525197",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Last Interest Accrual",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Custom"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "",
"creation": "2021-02-06 17:59:10.051269",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Application",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Application\",\"docstatus\",\"=\",\"1\",false],[\"Loan Application\",\"creation\",\"Timespan\",\"today\",false]]",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "New Loan Applications",
"modified": "2021-02-06 17:59:21.880979",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "New Loan Applications",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "",
"creation": "2021-02-06 17:56:34.624031",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan\",\"docstatus\",\"=\",\"1\",false],[\"Loan\",\"creation\",\"Timespan\",\"today\",false]]",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "New Loans",
"modified": "2021-02-06 17:58:20.209166",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "New Loans",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "",
"creation": "2021-02-06 17:23:32.509899",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Application",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Application\",\"docstatus\",\"=\",\"1\",false],[\"Loan Application\",\"status\",\"=\",\"Open\",false]]",
"function": "Count",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Open Loan Applications",
"modified": "2021-02-06 17:29:09.761011",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Open Loan Applications",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"type": "Document Type"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "disbursed_amount",
"creation": "2021-02-06 16:52:19.505462",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Disbursement",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Disbursement\",\"docstatus\",\"=\",\"1\",false]]",
"function": "Sum",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Total Disbursed Amount",
"modified": "2021-02-06 17:29:38.453870",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Total Disbursed",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"type": "Document Type"
}

View File

@ -0,0 +1,24 @@
{
"aggregate_function_based_on": "amount_paid",
"color": "#29CD42",
"creation": "2021-02-21 19:27:45.989222",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Repayment",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Repayment\",\"docstatus\",\"=\",\"1\",false]]",
"function": "Sum",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Total Repayment",
"modified": "2021-02-21 19:34:59.656546",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Total Repayment",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "loan_amount",
"creation": "2021-02-06 17:05:04.704162",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan\",\"docstatus\",\"=\",\"1\",false],[\"Loan\",\"status\",\"=\",\"Sanctioned\",false]]",
"function": "Sum",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Total Sanctioned Amount",
"modified": "2021-02-06 17:29:29.930557",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Total Sanctioned Amount",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Monthly",
"type": "Document Type"
}

View File

@ -0,0 +1,23 @@
{
"aggregate_function_based_on": "shortfall_amount",
"creation": "2021-02-09 08:07:20.096995",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Security Shortfall",
"dynamic_filters_json": "[]",
"filters_json": "[]",
"function": "Sum",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Total Unpaid Shortfall Amount",
"modified": "2021-02-09 08:09:00.355547",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Total Shortfall Amount",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -0,0 +1,24 @@
{
"aggregate_function_based_on": "write_off_amount",
"color": "#CB2929",
"creation": "2021-02-21 19:48:29.004429",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Loan Write Off",
"dynamic_filters_json": "[]",
"filters_json": "[[\"Loan Write Off\",\"docstatus\",\"=\",\"1\",false]]",
"function": "Sum",
"idx": 0,
"is_public": 0,
"is_standard": 1,
"label": "Total Write Off",
"modified": "2021-02-21 19:48:58.604159",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Total Write Off",
"owner": "Administrator",
"report_function": "Sum",
"show_percentage_stats": 1,
"stats_time_interval": "Daily",
"type": "Document Type"
}

View File

@ -36,7 +36,7 @@ def get_columns(filters):
def get_data(filters):
data = []
loan_security_details = get_loan_security_details(filters)
loan_security_details = get_loan_security_details()
pledge_values, total_value_map, applicant_type_map = get_applicant_wise_total_loan_security_qty(filters,
loan_security_details)
@ -64,7 +64,7 @@ def get_data(filters):
return data
def get_loan_security_details(filters):
def get_loan_security_details():
security_detail_map = {}
loan_security_price_map = {}
lsp_validity_map = {}

View File

@ -171,7 +171,7 @@ def get_loan_wise_pledges(filters):
return current_pledges
def get_loan_wise_security_value(filters, current_pledges):
loan_security_details = get_loan_security_details(filters)
loan_security_details = get_loan_security_details()
loan_wise_security_value = {}
for key in current_pledges:

View File

@ -35,7 +35,7 @@ def get_columns(filters):
def get_data(filters):
data = []
loan_security_details = get_loan_security_details(filters)
loan_security_details = get_loan_security_details()
current_pledges, total_portfolio_value = get_company_wise_loan_security_details(filters, loan_security_details)
currency = erpnext.get_company_currency(filters.get('company'))

View File

@ -10,6 +10,7 @@
"hide_custom": 0,
"icon": "loan",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"label": "Loan Management",
"links": [
@ -219,7 +220,7 @@
"type": "Link"
}
],
"modified": "2021-01-12 11:27:56.079724",
"modified": "2021-02-18 17:31:53.586508",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Management",
@ -239,6 +240,12 @@
"label": "Loan",
"link_to": "Loan",
"type": "DocType"
},
{
"doc_view": "",
"label": "Dashboard",
"link_to": "Loan Dashboard",
"type": "Dashboard"
}
]
}