def METHOD_NAME(date_range, company, field, limit=None):
	if field == "outstanding_amount":
		filters = [["docstatus", "=", "1"], ["company", "=", company]]
		if date_range:
			date_range = frappe.parse_json(date_range)
			filters.append(["posting_date", ">=", "between", [date_range[0], date_range[1]]])
		return frappe.db.get_all(
			"Sales Invoice",
			fields=["customer as name", "sum(outstanding_amount) as value"],
			filters=filters,
			group_by="customer",
			order_by="value desc",
			limit=limit,
		)
	else:
		if field == "total_sales_amount":
			select_field = "sum(so_item.base_net_amount)"
		elif field == "total_qty_sold":
			select_field = "sum(so_item.stock_qty)"
		date_condition = get_date_condition(date_range, "so.transaction_date")
		return frappe.db.sql(
			"""
			select so.customer as name, {0} as value
			FROM `tabSales Order` as so JOIN `tabSales Order Item` as so_item
				ON so.name = so_item.parent
			where so.docstatus = 1 {1} and so.company = %s
			group by so.customer
			order by value DESC
			limit %s
		""".format(
				select_field, date_condition
			),
			(company, cint(limit)),
			as_dict=1,
		)