Advertisement
ihris

litlfred

Mar 4th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.64 KB | None | 0 0
  1. class iHRIS_Intervention_A1_management extends iHRIS_Intervention {
  2.  
  3.     /**                                                                                                                                                                                                                                                                
  4.      * Get the field names that are yearly inputs                                                                                                                                                                                                                      
  5.      * @returns array of string                                                                                                                                                                                                                                        
  6.      */
  7.     public function yearlyInputs() {
  8.         return array('manager_time','support_staff_time','other_staff_time');
  9.     }
  10.  
  11.     /**                                                                                                                                                                                                                                                                
  12.      * Get the cost of the salaries for the indicated year                                                                                                                                                                                                            
  13.      * @return total cost for salaries                                                                                                                                                                                                                                
  14.      */
  15.     public function costSalaries($start_year,$year_offset,$salary,$time) {
  16.         $year = $start_year + $year_offset;
  17.         $sal_cost = 0;
  18.  
  19.         if (!array_key_exists($salary,$this->fields) || ! $this->fields[$salary] instanceof I2CE_FormField_INT) {
  20.             I2CE::raiseError("Field $salary is not an INT");
  21.             return 0;
  22.         }
  23.         if (!array_key_exists($time,$this->fields) || ! $this->fields[$time] instanceof I2CE_FormField_ASSOC_INT) {
  24.             I2CE::raiseError("Field $time is not an ASSOC_INT");
  25.             return 0;
  26.         }
  27.         $time = 0;
  28.         if (array_key_exists($time,$this->fields) && $this->fields[$time] instanceof I2CE_FormField_ASSOC_INT && $this->fields[$time]->keyIsSet($year)) {
  29.             $time =  max(0,$this->fields[$time]->getValueOfKey($year));
  30.         }
  31.         return  (($this->inflateCosts($year_offset,max(0,$this->fields[$salary]->getValue())))*12*(( $time /100)));
  32.     }
  33.     /**                                                                                                                                                                                                                                                                
  34.      * Get the cost for the indicated year                                                                                                                                                                                                                            
  35.      * @param int $start_year                                                                                                                                                                                                                                          
  36.      * @param int $year                                                                                                                                                                                                                                                
  37.      */
  38.     protected function _getCostByYear($start_year,$year_offset) {
  39.         $cost = 0;
  40.         foreach ( array('supplies','communications','other') as $cost) {
  41.             $costField = $this->getField($cost);
  42.             if (!array_key_exists($cost,$this->fields) || ! $this->fields[$cost] instanceof I2CE_FormField_INT) {
  43.                 I2CE::raiseError("Field $cost is not an INT");
  44.                 continue;
  45.             }
  46.             $cost += $this->inflateCosts($year_offset,max(0,$this->fields[$cost]->getValue()));
  47.         }
  48.  
  49.         $salaries_cost = 0;
  50.         $salaries = array ('manager_time'=>'manager_salary','support_staff_time'=>'support_staff_salary','other_staff_time'=>'other_staff_salary');
  51.         foreach ($salaries as $time=>$salary) {
  52.             $salaries_cost += $this->costSalary($start_year,$year_offset,$salary,$time);
  53.         }
  54.         return  $salaries_cost + $cost;
  55.     }
  56.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement