def METHOD_NAME(filters, items):
	if not items:
		return []
	sle = frappe.qb.DocType("Stock Ledger Entry")
	sle2 = frappe.qb.DocType("Stock Ledger Entry")
	query = (
		frappe.qb.from_(sle)
		.force_index("posting_sort_index")
		.left_join(sle2)
		.on(
			(sle.item_code == sle2.item_code)
			& (sle.warehouse == sle2.warehouse)
			& (sle.posting_date < sle2.posting_date)
			& (sle.posting_time < sle2.posting_time)
			& (sle.name < sle2.name)
		)
		.select(sle.item_code, sle.warehouse, sle.qty_after_transaction, sle.company)
		.where((sle2.name.isnull()) & (sle.docstatus < 2) & (sle.item_code.isin(items)))
	)
	if date := filters.get("date"):
		query = query.where(sle.posting_date <= date)
	else:
		frappe.throw(_("'Date' is required"))
	if filters.get("warehouse"):
		warehouse_details = frappe.db.get_value(
			"Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1
		)
		if warehouse_details:
			wh = frappe.qb.DocType("Warehouse")
			query = query.where(
				ExistsCriterion(
					frappe.qb.from_(wh)
					.select(wh.name)
					.where((wh.lft >= warehouse_details.lft) & (wh.rgt <= warehouse_details.rgt))
				)
			)
	return query.run(as_dict=True)