Пример #1
0
def get_data(filters):
    data = []
    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"))

    for security, value in current_pledges.items():
        if value.get("qty"):
            row = {}
            current_value = flt(
                value.get("qty", 0) *
                loan_security_details.get(security, {}).get("latest_price", 0))
            valid_upto = loan_security_details.get(security,
                                                   {}).get("valid_upto")

            row.update(loan_security_details.get(security))
            row.update({
                "total_qty":
                value.get("qty"),
                "current_value":
                current_value,
                "price_valid_upto":
                valid_upto,
                "portfolio_percent":
                flt(current_value * 100 / total_portfolio_value, 2),
                "pledged_applicant_count":
                value.get("applicant_count"),
                "currency":
                currency,
            })

            data.append(row)

    return data
Пример #2
0
def get_data(filters):
    data = []
    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'))

    for security, value in iteritems(current_pledges):
        if value.get('qty'):
            row = {}
            current_value = flt(
                value.get('qty', 0) *
                loan_security_details.get(security, {}).get('latest_price', 0))
            valid_upto = loan_security_details.get(security,
                                                   {}).get('valid_upto')

            row.update(loan_security_details.get(security))
            row.update({
                'total_qty':
                value.get('qty'),
                'current_value':
                current_value,
                'price_valid_upto':
                valid_upto,
                'portfolio_percent':
                flt(current_value * 100 / total_portfolio_value, 2),
                'pledged_applicant_count':
                value.get('applicant_count'),
                'currency':
                currency
            })

            data.append(row)

    return data
def get_loan_wise_security_value(filters, current_pledges):
	loan_security_details = get_loan_security_details()
	loan_wise_security_value = {}

	for key in current_pledges:
		qty = current_pledges.get(key)
		loan_wise_security_value.setdefault(key[0], 0.0)
		loan_wise_security_value[key[0]] += \
			flt(qty * loan_security_details.get(key[1], {}).get('latest_price', 0))

	return loan_wise_security_value
Пример #4
0
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}],
	}