Hello,
I don't know how to realize this :

An integer or decimal text field where it should be able to add and substract amounts, and keep track of when what was changed.
I would need to show a final number to some users, and the history of how we got to that number to others
example:

sum = 5

full history =
+1 13/12/29
+3 14/01/01
-2 14/02/20
+3 14/03/30

Any ideas how this could be done ?
cheers
agnez

Comments

alinouman’s picture

Hi, you could do that with field collection and some custom code.
1- add field_sum as field collection in a node.And in that entity add an integer in field and a date field.
2-add following code in custom module

function modulename_node_view($node, $view_mode = 'full', $langcode = NULL){
    $ids=$node->content['field_sum']['#items'];
    foreach($ids as $id){
        $val[]=$id['value'];
    }
    $fic=entity_load('field_collection_item',$val);
    $result=0;
    foreach($fic as $f){
        $result+=$f->field_value['und']['0']['value'];
    }
    $node->content['sum']=array('#markup'=>'SUM is '.$result);
    
}

3- Images viewing node http://i.imgur.com/lRz3xGi.png
4-images adding node http://i.imgur.com/pSj9nKz.png
5- You could see the sum.
I hope it helps you. if any question i will be glad to help you. thanks.

agnez’s picture

Hey alinouman,
thanks a lot for your replie !
It looks really promising, but is not yet working for me.

SUM is staying on 0 and I get this error message:
Undefined property: FieldCollectionItemEntity::$field_value in mymodule_node_view()
and it points me on this line of your code :
$result+=$f->field_value['und']['0']['value'];

Would you know what blocks?
Cheers
agnez