Need help with a function script that adds active brands to accounts

Need help with a function script that adds active brands to accounts

Hi there,

we are selling brands' collections to our accounts. We need to be able to easily see, which account is an active customer of which brand. 

The function would have to read the "Brand Name" (field) from "Deals" (Module) that are related to "Account" and writes them in to the field "Active Brand(s)" in the "Accounts" module.

Another complexity: if the account has not ordered the brand for > 300 days, it should become "inactive"

Hope someone can help with this!
thanks!!!