How to get values from all linked records frome the same module?

How to get values from all linked records frome the same module?

Hello, 

I have created a custom module "Subscriptions" and different records from the module are linked to one subscription.

I want to check the values of the field "Payment status" of all linked invoices (module "Invoices") and synchronize it to the field with the name "Subscription status" (module "Subscriptions"): 
  1. If all invoices have payment status "Paid" the subscription status of this subscription should be "Active". 
  2. If one or more invoices have payment status "Unpaid" or "Cancelled" the subscription status of this subscription sbould be "Inactive". 

Is this possible? Is there something like a code snippet for a function?

Thanks for help, 
M.