This is really complex and might take a while to transform into set based code. I wouldn't expect much help and even less without DDL and sample data.
Basically, you're inserting in a table based on different conditions. Using the WHERE clause you could get it done without a cursor. There's a Stored Procedure that expects scalar values, you need to change that code as well or you'll end up with a forced loop to execute it.