DROP PROCEDURE sp_get_stock_requisition;

CREATE PROCEDURE sp_get_stock_requisition(a_item_id int, a_stock_date date)
BEGIN
	DECLARE	v_bal_date DATE;
	DECLARE	v_quantity DECIMAL(12, 2);
	DECLARE	v_prev_quantity DECIMAL(12, 2);
	DECLARE	v_issue_qty	DECIMAL(12, 2);

	SELECT 	Max(stock_date)
	INTO	v_bal_date
	FROM	stock_item_requisition
	WHERE	item_id = v_item_id
	AND		stock_date <= a_stock_date;

	SELECT	req_qty, issue_qty, tot_quantity
	WHERE	stock_date = v_bal_date;

END;