To resolve the "two lines" issue, you could add the criteria Main Line = Yes. Or, if you actually need both those lines for reporting, but only want to return one line in your final output, perhaps summarizing them by grouping the results by Document Number. I'd wait to summarize until you have pinned down the record data you want, though.
On the second piece... that sounds like it might be achievable using a CASE statement in a Formula (Text) field.