-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- CREATE OR REPLACE FUNCTION public.search_inventory (search text)
-- 	RETURNS SETOF inventory
-- 	LANGUAGE plpgsql
-- 	STABLE
-- 	AS $function$
-- BEGIN
-- 	IF search = '' THEN
-- 		RETURN query
-- 		SELECT
-- 			*
-- 		FROM
-- 			inventory;
-- 	ELSE
-- 		RETURN query
-- 		SELECT
-- 			*
-- 		FROM
-- 			inventory i,
-- 			billlines bl,
-- 			bills b,
-- 			vendors v
-- 		WHERE
-- 			i.billlineid = bl.id
-- 			AND bl.billid = b.id
-- 			AND b.vendorid = v.id
-- 			AND i.line_desc ILIKE '%' || search || '%'
-- 			OR b.invoice_number ILIKE '%' || search || '%'
-- 			OR v.name ILIKE '%' || search || '%'
-- 		ORDER BY
-- 			i.line_desc ILIKE '%' || search || '%'
-- 			OR NULL,
-- 			b.invoice_number ILIKE '%' || search || '%'
-- 			OR NULL,
-- 			v.name ILIKE '%' || search || '%'
-- 			OR NULL;
-- 	END IF;
-- END
-- $function$;
