I am getting into computed field and have 3 working fields at the moment. But what I am contemplating here is way over my abilities. So I really could use some advice on this.

In D6.14 I have a content type that is used to submit retailprices on goods bought in retailchains. this type has the fields:
- Chain/storename
- MultiGroup: Items (unlimited no.)
- Item
- Quantity
- Unit

With this content type goods are submitted to Drupal (they all have item, quantity, and unit). There is one submission pr. week pr. retail-chain. And these submissions hold many goods/items.

Now to get to the fun stuff I have another content type: shoppinglist.

The content type shoppinglist is comprised of the following fields:
- MultiGroup: Items
- Item (text)
- Quantity (Decimal)
- Unit (text)
- Shoppingtotal (Computed)
- Saved from most expensive (Computed)

I need the following functionality:
- When a user submits a shoppinglist
- Shoppinglisttotal, and 'Saved from most expensive' should both be calculated from among all the submitted retailchains (but only the ones that have the relevant items)
- Then I will present the user with a list of the retail chains that meet the relevant items in their submitted prices for the week.
- Showing for each shop the shoppingtotal and the amount the user save from bying there in contrast to the most expensive shop.

Here is an example of what I have in mind:

Chain Shoppingtotal Saved compared to most exp.
* [chain1] 543,83 89,34
* [chain2] 567,34 76,23
* [chain3] 573,87 54,76
* [chain4] 589,65 34,87
* [chain5] 603,78 12,98
* [chain6] 614,65 -

I hope you get my drift. Don't go through the math on the above numbers. They are just an example - not a calculation.

In other words there are several business logic things going on in these 2 computed fields.

- 1. Shoppinglisttotal, should ONLY be calculated IF all items are listed from the retail-chain with a price in the DB.
- 1B. Even better, I would love to be able to include also the shops that missed say up to 20% of the items and then compare those numbers, with a list of where the last items could be had for the least amount (another attachment view to present this)
I think I might be able to reuse some of the this snippet: for the testing if all fields are filled out: http://drupal.org/node/366665

- 2. the 'Saved from most expensive' is more simple and I should be able to nail that without too much trouble. It should sort all the shoppinglisttotals and subtract the 'Shoppinglisttotal for all the cheaper ones from the most expensive one and present the delta price. To make this work there must be a way of discerning the different shoppinglisttotals from eachother pr. week. This means that [chain1] shoppinglisttotal and [chain2] shoppinglisttotal should be distinguished from eachother. How is this possible? Could I use tokens or should i use NIDs? I have never done anything this complicated before. But I know that it is possible using CCK (incl. MultiGoups, Computed field) and Views.

So the complicated Computed field i think is the Shoppinglist total described above in 1. However also the elaborate use of tokens for this to come together is pretty much eluding me... Please help.

Any thoughts on how I could nail this in PHP in a computed field. As well as some of the logics in a view to make things userfriendly in Views2.

All and any thoughts are more than welcome. I am not able to do this without your help.

Thanks a lot

Morten E.

Comments

excaliburst’s picture

In the above text the indents are removed so I clarify my Multigroups here:

Content Type: Pricereporting:
- Chain/storename
- MultiGroup: Items (unlimited no.)
-- Item
-- Quantity
-- Unit

Content type: shoppinglist.
The content type shoppinglist is comprised of the following fields:
- MultiGroup: Items
-- Item (text)
-- Quantity (Decimal)
-- Unit (text)
- Shoppingtotal (Computed)
- Saved from most expensive (Computed)

Thanks

Morten

mmjvb’s picture

Status: Active » Closed (outdated)