Custom function to check multiple orders

Custom function to check multiple orders

I have a module "Orders" containings orders of companies. The field 'Status' indicated whether this order is active or not. The field 'Enddate' indicates when this order will expire. I have a workflow, which is triggered 45 days before the enddate. This workflow automatically creates a task. However, I don't want this task to be created if there is another order in the Orders module for this specific company with the status 'Concept' and a start date later than today. 

The company field is a look up field

Could someone help me with the custom function for this workflow?