the terms of an agreement does not change, so you can build the logic in your script. make sure that you conform all the contracts to a single rule like days after end of month (of invoice). so you have a table that links to your invoices (i assume by unique companyID) and hold the number of daysEOM:
CONTRACTS:
CompanyID, daysEOM
left join this to your invoices, then create a calculated field:
=date(monthend(InvoiceDate) + daysEOM)
in reality contracts have start and end dates and if that is true, its a more complicated logic. however, if the invoice references a contract then that may be your link instead of companyID. that said the solution suggested is wil change based on what data i s available and how the contract is linked.