Skip to main content
added 28 characters in body
Source Link

The help offered in the previous two answers (if ordered by oldest date) solved the problem of creating a sum of a column in a views table, but didn't allow me to add a computed field of my own based on data from the view. For example, take two summed fields, subtract one from the other and put the result into a custom field. Views' custom field would be the way to do this as it allows you to use php snippets to build the field value, although again I am not sure it would allow you access to other custom fields in the view (just the view results).

The help offered in the previous two answers solved the problem of creating a sum of a column in a views table, but didn't allow me to add a computed field of my own based on data from the view. For example, take two summed fields, subtract one from the other and put the result into a custom field. Views' custom field would be the way to do this as it allows you to use php snippets to build the field value, although again I am not sure it would allow you access to other custom fields in the view (just the view results).

The help offered in the previous two answers (if ordered by oldest date) solved the problem of creating a sum of a column in a views table, but didn't allow me to add a computed field of my own based on data from the view. For example, take two summed fields, subtract one from the other and put the result into a custom field. Views' custom field would be the way to do this as it allows you to use php snippets to build the field value, although again I am not sure it would allow you access to other custom fields in the view (just the view results).

Source Link

It seems that views is not a good way to go when trying to build reports that require more than one query of the database. Problems I found were:

-- 1) I could not bring in all payment nodes to the view using a property node id and then call in all charge nodes for the same property. The query returned the same information into the view multiple times, once for each payment and once for each charge. I wanted separate tables and then I wanted to make total fields from the data in each table. It seems a solution to this is to use hook_views_pre_execute() to edit the query to create a union query as described here but this was honestly mostly over my head!

-- 2) I could not calculate fields base on a value from a field in the property node and add them to the view (the service charge I talk about in the question).

The help offered in the previous two answers solved the problem of creating a sum of a column in a views table, but didn't allow me to add a computed field of my own based on data from the view. For example, take two summed fields, subtract one from the other and put the result into a custom field. Views' custom field would be the way to do this as it allows you to use php snippets to build the field value, although again I am not sure it would allow you access to other custom fields in the view (just the view results).

Furthermore, I would then have to format the results by a call to some template hook function (sorry, I haven't figure out which one yet!).

So instead my solution was to use hook_menu() to add a path to create my own report

  $items['property_account_summary'] = array(
    'title' => 'Property account summary',
    'page callback' => 'MYmodule_property_account_summary_view',
    'page arguments' => array(1),
    'access callback' => 'user_access',
    'access arguments' => array('List Charge by Prop'),

and in MYmodule_property_account_summary_view it was pretty straight forward to construct the two queries I needed to collect the payment and charge nodes I needed. For example, for payments (where $prop_nid contains the node id of the property node I am working from:

  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
     ->entityCondition('bundle', 'payment');
  $query->fieldCondition('field_payment_property', 'target_id', $prop_nid, '=');
  $result = $query->execute();
  $node_list = $result['node'];

and for charges:

  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
     ->entityCondition('bundle', 'charge');
  $query->fieldCondition('field_charge_property_id', 'target_id', $prop_nid, '=');
  $result = $query->execute();
  $node_list = $result['node'];

and from there build the html and add the totals.

Payment and charge summary Now I just need to format the values and add links to the term values in the Type column.

It just seems like a lot less work than trying to force views into doing what I needed. I must reiterate that this is my first attempt at using views (other than the straight forward grab and show data) and maybe I missed something amongst the views hooks that would have made my life a lot easier. But for now, I will use a solution within my module.