I'm a new beginner drupal user, and I don't have enough capabilities around drupal or php code, but I like to know to use computed field to compute water usage by customer and it's price.

The final target I want to create a views to display table below for one customer, (similar table for other customer)

To describe the situation please see table below by 5 measurements

(this list are field in sequence)
A = Date of Measurement (input field)
B = Measurement Value (input field)
C = Previous Meter Number (computed field)
D = Last Meter Number (Computed field)
E = Water Usage (Computed field)
F = Water Usage This Month (Computed field)
G = Total Usage (Computed field)

A	         |  B |  C	 | D 	 | E	 | F	 | G	
2010-01-29 |	10 |	10 |	10 |	0 |	0 | 0
2010-01-30 |	16 |	10 |	16 |	6 |	6 | 6
2010-02-01 |	19 |	16 |	19 |	3 |	3 | 9
2010-02-02 |	22 |	19 |	22 |	3 |	6 | 15
2010-02-03 |	24 |	22 |	24 |	2 |	8 | 23

Condition for this problem is

  • For 1'st record each costomer : Previous Meter Number and Last Meter Number = Measurement Value
  • 2nd record each costomer : Previous Meter Number = Last Meter Number (at previous input )
    Last Meter Number = Measurement Value
  • Water Usage : Last Meter Number - Previous Meter Number and
  • Water Usage This Month = Water Usage This Month + Water Usage (every new month reset to zero value
  • Total Usage = Total Usage + Water Usage This Month every year reset to zero value

I Have create a content type to provide this needs as in attachment, but I I'm too stupid to understand how to create compute code, but I don't give up tring hard, and finally this is my compute code.

My Questions

  • Do I have to create compute code for each computed field ? or I can create only 0ne compute code at last field to provide all computed field
  • I have to try to create compute code for 'Previous Meter Number' field like this
     $node_field[0]['value'] = $node->field_wm_measurement_value[0]['value'];
    

    This compute code only correct for 1'st input data, or for 2nd input data I have to create condition

    if .. then ...else,
    How if situation is not input data but edit data? can I use the same compute code or I have to create other contions, How to create it ???

  • same compute code for 'Last Meter Number' field like this
     $node_field[0]['value'] = $node->field_wm_measurement_value[0]['value'];
    
  • For Water Usage field, I create this one,
    $node_field[0]['value'] = $node->field_wm_last_meter_number[0]['value']- $node->field_wm_previous_meter_number[0]['value'];
    
  • For Water Usage This Month field, I create this one, how to reset value to zero at 1'st input data every month ?
    $node_field[0]['value'] = $node->field_wm_water_usage_this_month[0]['value']+ $node->field_wm_water_usage[0]['value'];
    
  • For Total Usage field (need reset every year)
    $node_field[0]['value'] = $node->field_wm_water_total_usage[0]['value']+ $node->field_wm_water_usage_this_month[0]['value'];

Please help me to solve this problem, and sorry for my bad English,

Comments

mmjvb’s picture

Status: Active » Closed (outdated)