Improve finding of company_id [MJ-934]

Change how company_id is found:
- If buid is 0 and a domain is present, search by domain
- Else, filter companies by buid and take the first

All tests pass.