Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am creating a Payroll entity in which I have to manipulate different field values based on another field value (see below).

I have the following fields and I want to calculate the bottom four field values from the value of the basic salary field. Is there any function/hook available for this or do I have to write my own custom function?

  1. basic salary field
  2. da salary(daily allowance)
  3. ta salary(travel allowance)
  4. epf salary(Employee provident fund)
  5. save_salary(Save salary)
share|improve this question
Hi there. Could you explain this a little further: " i want to manipulate all the field values from the basic salary field"? What exactly are you trying to do with the other 4 fields? Are you just trying to calculate the values of the other four based on what is filled in for the 1st value in a particular node of that type? – Boriana Mar 14 at 14:49
Yes exactly i wanna do this but i am searching for any contributed module so that i can write my own operations on the different field as per my requirement. – Satyabrata sahoo Mar 15 at 5:56

1 Answer

up vote 1 down vote accepted

My suggestion, now that I understand you're trying to calculate certain values' amounts based on the amount of a different field, would be to use the Rules module.

Then you can accomplish what you need without writing a custom module. Rules are sometimes a little clunky to create, but the module is really reliable - I use rules for all sorts of things, and once you set it up, it works beautifully.

Here are (roughly) the steps you'd need to take to create a rule that modifies a certain field based on another one. Adjust as you need to, so it suits your particular needs.

  1. After enabling the module, go to /admin/config/workflow/rules to add a new rule
  2. Set the 'Event' that triggers the rule to be something like 'After updating existing content'. That will trigger this re-calculation any time the node is updated
  3. Next you'll see that the rule also has 'Conditions' and 'Actions'. Set the 'Condition' for your rule to be 'Content is of type' and select the content type you want to apply this rule to from the given list.

    enter image description here

  4. Finally, let's go onto the actions. You'll have to do two steps for each of the fields you're modifying 1) First calculate the value from the base_salary field (and store in temporary variable -- that's how it works) and 2) set the appropriate field with the value of this temporary variable. Here are the 'Action' options that correspond to these

    enter image description here

  5. When you're calculating the value for one of the fields, the interface has, by default, a field to select from the top, an operator, and then a text field into which you can enter a number. If you would rather add/multiply/etc two fields, just change the bottom one to a data selection option with the following button

    enter image description here

  6. If your calculation is more complicated than simply adding/subracting/etc two values, just keep selecting the 'Calculate' value action and keep working on the number with multiple chain operations until you're ready and then add the 'Set a data value' at the end.

Hope this helps! I can't do an entire tutorial on using Rules here, as it's a complicated module, but the above should get you started and point you in the right direction. :0)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.