CREATE OR REPLACE PROCEDURE public.sp_changefunddeposited(var_storeid int8, var_movementdate varchar, var_filename varchar)
	LANGUAGE plpgsql
AS $$	

BEGIN  
execute 'DROP TABLE IF EXISTS ' || var_filename;
	execute 'CREATE TEMP TABLE ' || var_filename || ' AS
			SELECT s.businessday
					,s."timestamp" AS "Time of Entry"
					,s.actualamount AS "Amount Received"
					,e.firstname + '' '' + e.lastname AS "Authorised By"
			FROM safemovement s
				INNER JOIN employee e ON e.employeeid = s.authorizedbyuserid		
			WHERE movementtype = ''Banking'' 
					AND s.businessday = ''' || var_movementdate || ''' 
					AND s.storeid = ' || var_storeid || '
					AND s.deletedbyid  IS NULL
			ORDER BY 1 DESC';
	END;
$$;