I have a Drupal 7 website that tracks values associated with "Content Type A". I have another content type, "Content Type B", which is a part that is associated with Content Type A. Any A item may have one or more B items associated with it:
A-101 (B-201 B-202 B-203)
Each B item has a field that shows its total number of available uses (its limit, if you will). This is a static integer field. Each A item has a field that shows "aggregated uses" of that item, based on a third content type: "Content Type A-Usage". The "aggregated uses" field in A uses Views and aggregation to add up the A-Usage items referenced/linked to that A item.
I need to take that aggregated A-Usage value and subtract it from the "B-available uses/limit" value, and then display that result in a view or a CCK field.
So let's say A-101 has an aggregated usage of "100", and B-201 has a limit of 500 uses. I need to display the remaining uses for B-201 (400, in this case) in a view or CCK field.
One step further, I also need to take into account the remaining uses for B-201, B-202, and B-203, and pluck the lowest value from those remaining uses and display it in a view/CCK field. Let's say B-201 has 400 remaining uses, B-202 has 350 remaining uses, and B-203 has 100 remaining uses. The view/field in question would simply display "100", as that is the lowest remaining value of those B items.
I'm hoping someone can point me in the right direction, or provide some type of php snippet or guidance to help me accomplish these tasks. Views would be my method of choice, as much of the site's pages are already compiled using Views.