/**
  * Save the data from the file to the database
  *
  * @param array  $data The values to save
  *
  * @return  boolean false on failure
  *
  **/
 protected function saveObject(&$db, $data, $type)
 {
     if ($type == 'health_data') {
         // first we check if the data is already set
         $id = $this->getHealthDataId($db, $data->causerisk, $data->year, $data->country);
     }
     // if new then insert data
     if ($type == 'health_data' && !$id && $this->canCreate) {
         // build some extra data
         $data->created_by = $this->user->id;
         $data->created = $this->dateSql;
         $data->version = 1;
         $data->published = 1;
         $data->access = 1;
         $done = $db->insertObject('#__costbenefitprojection_' . $type, $data);
         if ($done) {
             $aId = $db->insertid();
             // make sure the access of asset is set
             return CostbenefitprojectionHelper::setAsset($aId, $type);
         }
     } elseif ($this->canEdit) {
         // build some extra data
         if ($type == 'health_data' && $id > 0) {
             $data->id = $id;
         }
         if ($data->id > 0) {
             $version = CostbenefitprojectionHelper::getVar($type, $data->id, 'id', 'version');
             $data->version = $version + 1;
             $data->modified_by = $this->user->id;
             $data->modified = $this->dateSql;
             return $db->updateObject('#__costbenefitprojection_' . $type, $data, 'id');
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 public function getClusterData($idName, $cluster)
 {
     // we first build the json object from the cluster ids, then pass it to the builder
     $oject = '';
     $oject_table = '';
     if (CostbenefitprojectionHelper::isJson($cluster) && CostbenefitprojectionHelper::checkString($idName)) {
         $array = json_decode($cluster, true);
         // get te set intervention data
         $interventions = array();
         if (CostbenefitprojectionHelper::checkArray($array)) {
             foreach ($array as $intervention) {
                 $interventions[$intervention] = CostbenefitprojectionHelper::getVar('intervention', $intervention, 'id', 'intervention');
             }
         }
         // sort the data
         $bucket = array();
         if (CostbenefitprojectionHelper::checkArray($interventions)) {
             foreach ($interventions as $inter => $set) {
                 if (CostbenefitprojectionHelper::isJson($set)) {
                     $set = json_decode($set, true);
                     if (CostbenefitprojectionHelper::checkArray($set)) {
                         foreach ($set as $option => $values) {
                             foreach ($values as $nr => $value) {
                                 $bucket[$inter][$nr][$option] = $value;
                             }
                         }
                     }
                 }
             }
         }
         // combine the data
         $combine = array();
         if (CostbenefitprojectionHelper::checkArray($bucket)) {
             foreach ($bucket as $pool) {
                 if (CostbenefitprojectionHelper::checkArray($pool)) {
                     foreach ($pool as $headers) {
                         if (CostbenefitprojectionHelper::checkArray($headers)) {
                             // check if this cause is already targeted
                             if (isset($combine[$headers['causerisk']])) {
                                 // combine
                                 $temp = $combine[$headers['causerisk']];
                                 $temp['cpe'] = $this->combineValues($temp['cpe'], $headers['cpe']);
                                 $temp['mbr'] = $this->combineValues($temp['mbr'], $headers['mbr']);
                                 $temp['mtr'] = $this->combineValues($temp['mtr'], $headers['mtr']);
                                 // update the data
                                 $combine[$headers['causerisk']] = $temp;
                             } else {
                                 // set for first time
                                 $combine[$headers['causerisk']] = array('cpe' => $headers['cpe'], 'mbr' => $headers['mbr'], 'mtr' => $headers['mtr']);
                             }
                         }
                     }
                 }
             }
         }
         // setup the object
         if (CostbenefitprojectionHelper::checkArray($combine)) {
             $oject = array();
             foreach ($combine as $causerisk => $vals) {
                 if (CostbenefitprojectionHelper::checkArray($vals)) {
                     $oject['causerisk'][] = $causerisk;
                     foreach ($vals as $header => $v) {
                         // set placeholder
                         $oject[$header][] = $v;
                     }
                 }
             }
             // done at last
             $oject = json_encode($oject);
         }
     }
     // return the table and values
     return array('table' => $this->getInterventionBuildTable($idName, $oject, 'ja'), 'values' => $oject);
 }
Ejemplo n.º 3
0
 /**
  * Set the interventions related to this Company.
  *
  * @return array
  *
  */
 protected function setInterventions()
 {
     // now set the result set
     if (CostbenefitprojectionHelper::checkArray($this->company->causesrisks) && isset($this->company->interventions) && CostbenefitprojectionHelper::checkArray($this->company->interventions)) {
         $i = 0;
         foreach ($this->company->interventions as $mainkey => $item) {
             // make sure duration is set
             if (!isset($item->duration) || !is_numeric($item->duration) || 1 > $item->duration) {
                 $item->duration = 1;
             }
             $this->interventions[$i]["id"] = $item->id;
             $this->interventions[$i]["name"] = $item->name;
             $this->interventions[$i]["description"] = $item->description;
             $this->interventions[$i]["duration"] = $item->duration;
             $this->interventions[$i]["coverage"] = $item->coverage;
             $this->interventions[$i]["type"] = $item->type;
             $this->interventions[$i]['found'] = array();
             $this->interventions[$i]['not_found'] = array();
             // set totals
             $this->interventions[$i]['totals']['cost_per_employee'] = 0;
             $this->interventions[$i]['totals']['costmoney_per_employee'] = 0;
             $this->interventions[$i]['totals']['cost_of_problem_scaled'] = 0;
             $this->interventions[$i]['totals']['cost_of_problem_unscaled'] = 0;
             $this->interventions[$i]['totals']['costmoney_of_problem_scaled'] = 0;
             $this->interventions[$i]['totals']['costmoney_of_problem_unscaled'] = 0;
             $this->interventions[$i]['totals']['contribution_to_cost_scaled'] = 0;
             $this->interventions[$i]['totals']['contribution_to_cost_unscaled'] = 0;
             $this->interventions[$i]['totals']['cost'] = 0;
             $this->interventions[$i]['totals']['costmoney'] = 0;
             $this->interventions[$i]['totals']['benefit_scaled'] = 0;
             $this->interventions[$i]['totals']['benefit_unscaled'] = 0;
             $this->interventions[$i]['totals']['benefitmoney_scaled'] = 0;
             $this->interventions[$i]['totals']['benefitmoney_unscaled'] = 0;
             $this->interventions[$i]['totals']['net_benefit_scaled'] = 0;
             $this->interventions[$i]['totals']['net_benefit_unscaled'] = 0;
             $this->interventions[$i]['totals']['net_benefitmoney_scaled'] = 0;
             $this->interventions[$i]['totals']['net_benefitmoney_unscaled'] = 0;
             // now load the cause/risk that are linked to this user
             $a = 0;
             // set values
             foreach ($item->data as $key => $value) {
                 if (in_array($value['id'], $this->company->causesrisks)) {
                     // set array of causes/risk ids
                     $this->interventions[$i]['found'][$value['id']] = $this->items[$value['id']]->details->name;
                     // set local cause/risk values
                     $this->interventions[$i]['items'][$a] = $value;
                     $this->interventions[$i]['items'][$a]['name'] = $this->items[$value['id']]->details->name;
                     $this->interventions[$i]['items'][$a]['cost_of_problem_unscaled'] = $this->items[$value['id']]->subtotal_cost_unscaled * $item->duration;
                     $this->interventions[$i]['items'][$a]['cost_of_problem_scaled'] = $this->items[$value['id']]->subtotal_cost_scaled * $item->duration;
                     $this->interventions[$i]['items'][$a]['costmoney_of_problem_unscaled'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['cost_of_problem_unscaled']);
                     $this->interventions[$i]['items'][$a]['costmoney_of_problem_scaled'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['cost_of_problem_scaled']);
                     $this->interventions[$i]['items'][$a]['cost'] = $this->interventions[$i]["coverage"] / 100 * $value['cpe'] * ($this->company->males + $this->company->females);
                     // turn into money
                     $this->interventions[$i]['items'][$a]['costmoney'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['cost']);
                     $this->interventions[$i]['items'][$a]['benefit_unscaled'] = $this->interventions[$i]["coverage"] / 100 * ($value['mbr'] / 100) * ($this->items[$value['id']]->subtotal_cost_morbidity_unscaled + $this->items[$value['id']]->subtotal_cost_presenteeism_unscaled) + $value['mtr'] / 100 * $this->items[$value['id']]->subtotal_cost_mortality_unscaled * $item->duration;
                     $this->interventions[$i]['items'][$a]['benefit_scaled'] = $this->interventions[$i]["coverage"] / 100 * ($value['mbr'] / 100) * ($this->items[$value['id']]->subtotal_cost_morbidity_scaled + $this->items[$value['id']]->subtotal_cost_presenteeism_scaled) + $value['mtr'] / 100 * $this->items[$value['id']]->subtotal_cost_mortality_scaled * $item->duration;
                     // turn into money
                     $this->interventions[$i]['items'][$a]['benefitmoney_unscaled'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['benefit_unscaled']);
                     $this->interventions[$i]['items'][$a]['benefitmoney_scaled'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['benefit_scaled']);
                     $this->interventions[$i]['items'][$a]['net_benefit_unscaled'] = $this->interventions[$i]['items'][$a]['benefit_unscaled'] - $this->interventions[$i]['items'][$a]['cost'];
                     $this->interventions[$i]['items'][$a]['net_benefit_scaled'] = $this->interventions[$i]['items'][$a]['benefit_scaled'] - $this->interventions[$i]['items'][$a]['cost'];
                     // turn into money
                     $this->interventions[$i]['items'][$a]['net_benefitmoney_unscaled'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['net_benefit_unscaled']);
                     $this->interventions[$i]['items'][$a]['net_benefitmoney_scaled'] = $this->makeMoney((double) $this->interventions[$i]['items'][$a]['net_benefit_scaled']);
                     // set ratio
                     $this->interventions[$i]['items'][$a]['benefit_ratio_unscaled'] = $this->interventions[$i]['items'][$a]['benefit_unscaled'] / $this->interventions[$i]['items'][$a]['cost'];
                     $this->interventions[$i]['items'][$a]['benefit_ratio_scaled'] = $this->interventions[$i]['items'][$a]['benefit_scaled'] / $this->interventions[$i]['items'][$a]['cost'];
                     $this->interventions[$i]['items'][$a]['costmoney_per_employee'] = $this->makeMoney((double) $value['cpe']);
                     // set totals
                     $this->interventions[$i]['totals']['cost'] = $this->interventions[$i]['totals']['cost'] + $this->interventions[$i]['items'][$a]['cost'];
                     $this->interventions[$i]['totals']['benefit_scaled'] = $this->interventions[$i]['totals']['benefit_scaled'] + $this->interventions[$i]['items'][$a]['benefit_scaled'];
                     $this->interventions[$i]['totals']['benefit_unscaled'] = $this->interventions[$i]['totals']['benefit_unscaled'] + $this->interventions[$i]['items'][$a]['benefit_unscaled'];
                     $this->interventions[$i]['totals']['net_benefit_scaled'] = $this->interventions[$i]['totals']['net_benefit_scaled'] + $this->interventions[$i]['items'][$a]['net_benefit_scaled'];
                     $this->interventions[$i]['totals']['net_benefit_unscaled'] = $this->interventions[$i]['totals']['net_benefit_unscaled'] + $this->interventions[$i]['items'][$a]['net_benefit_unscaled'];
                     $this->interventions[$i]['totals']['cost_per_employee'] = $this->interventions[$i]['totals']['cost_per_employee'] + $value['cpe'];
                     $this->interventions[$i]['totals']['cost_of_problem_scaled'] = $this->interventions[$i]['totals']['cost_of_problem_scaled'] + $this->interventions[$i]['items'][$a]['cost_of_problem_scaled'];
                     $this->interventions[$i]['totals']['cost_of_problem_unscaled'] = $this->interventions[$i]['totals']['cost_of_problem_unscaled'] + $this->interventions[$i]['items'][$a]['cost_of_problem_unscaled'];
                 } else {
                     $this->interventions[$i]['not_found'][$value['id']] = CostbenefitprojectionHelper::getVar('causerisk', $value['id'], 'id', 'name');
                 }
                 $a++;
             }
             // contribution_to_cost
             $a = 0;
             foreach ($item->data as $key => $value) {
                 if (in_array($value['id'], $this->company->causesrisks)) {
                     $this->interventions[$i]['items'][$a]['contribution_to_cost_unscaled'] = $this->interventions[$i]['items'][$a]['cost_of_problem_unscaled'] / $this->interventions[$i]['totals']['cost_of_problem_unscaled'] * 100;
                     $this->interventions[$i]['items'][$a]['contribution_to_cost_scaled'] = $this->interventions[$i]['items'][$a]['cost_of_problem_scaled'] / $this->interventions[$i]['totals']['cost_of_problem_scaled'] * 100;
                     // set totals
                     $this->interventions[$i]['totals']['contribution_to_cost_scaled'] = $this->interventions[$i]['totals']['contribution_to_cost_scaled'] + $this->interventions[$i]['items'][$a]['contribution_to_cost_scaled'];
                     $this->interventions[$i]['totals']['contribution_to_cost_unscaled'] = $this->interventions[$i]['totals']['contribution_to_cost_unscaled'] + $this->interventions[$i]['items'][$a]['contribution_to_cost_unscaled'];
                 }
                 $a++;
             }
             // set total money
             $this->interventions[$i]['totals']['costmoney_per_employee'] = $this->makeMoney((double) $this->interventions[$i]['totals']['cost_per_employee']);
             $this->interventions[$i]['totals']['costmoney_of_problem_scaled'] = $this->makeMoney((double) $this->interventions[$i]['totals']['cost_of_problem_scaled']);
             $this->interventions[$i]['totals']['costmoney_of_problem_unscaled'] = $this->makeMoney((double) $this->interventions[$i]['totals']['cost_of_problem_unscaled']);
             $this->interventions[$i]['totals']['costmoney'] = $this->makeMoney((double) $this->interventions[$i]['totals']['cost']);
             $this->interventions[$i]['totals']['benefitmoney_scaled'] = $this->makeMoney((double) $this->interventions[$i]['totals']['benefit_scaled']);
             $this->interventions[$i]['totals']['benefitmoney_unscaled'] = $this->makeMoney((double) $this->interventions[$i]['totals']['benefit_unscaled']);
             $this->interventions[$i]['totals']['net_benefitmoney_scaled'] = $this->makeMoney((double) $this->interventions[$i]['totals']['net_benefit_scaled']);
             $this->interventions[$i]['totals']['net_benefitmoney_unscaled'] = $this->makeMoney((double) $this->interventions[$i]['totals']['net_benefit_unscaled']);
             if (isset($this->interventions[$i]['items'])) {
                 $this->interventions[$i]['nr_found'] = sizeof($this->interventions[$i]['items']);
             } else {
                 $this->interventions[$i]['nr_found'] = 0;
             }
             if (isset($this->interventions[$i]['not_found'])) {
                 $this->interventions[$i]['nr_not_found'] = sizeof($this->interventions[$i]['not_found']);
             } else {
                 $this->interventions[$i]['nr_not_found'] = 0;
             }
             $i++;
         }
         return true;
     }
     $this->interventions = false;
 }
Ejemplo n.º 4
0
function setIntervention($item)
{
    if (CostbenefitprojectionHelper::isJson($item->intervention)) {
        $bucket = array();
        $bucketsmall = array();
        $interventions = json_decode($item->intervention);
        foreach ($interventions as $name => $values) {
            if (CostbenefitprojectionHelper::checkArray($values)) {
                foreach ($values as $pointer => $value) {
                    if (!isset($bucket[$pointer])) {
                        $bucket[$pointer] = '';
                        $bucketsmall[$pointer] = '';
                    }
                    switch ($name) {
                        case 'causerisk':
                            $causeName = CostbenefitprojectionHelper::getVar('causerisk', $value, 'id', 'name');
                            $bucket[$pointer] .= '<td>' . $causeName . "</td>";
                            $bucketsmall[$pointer] .= $causeName . ': ';
                            break;
                        case 'cpe':
                            $bucket[$pointer] .= '<td class="uk-text-center"><span class="uk-badge uk-badge-notification uk-badge-success">' . $value . '</span></td>';
                            $bucketsmall[$pointer] .= '<span class="uk-badge uk-badge-success">' . $name . ' ' . $value . '</span> ';
                            break;
                        case 'mbr':
                            $bucket[$pointer] .= '<td class="uk-text-center"><span class="uk-badge uk-badge-notification uk-badge-success">' . $value . '</span></td>';
                            $bucketsmall[$pointer] .= '<span class="uk-badge uk-badge-success">' . $name . ' ' . $value . '</span> ';
                            break;
                        case 'mtr':
                            $bucket[$pointer] .= '<td class="uk-text-center"><span class="uk-badge uk-badge-notification uk-badge-success">' . $value . '</span></td>';
                            $bucketsmall[$pointer] .= '<span class="uk-badge uk-badge-success">' . $name . ' ' . $value . '</span>';
                            break;
                    }
                }
            }
        }
    }
    return '<td><table class="uk-table  uk-table-hover uk-table-striped uk-table-condensed uk-hidden-small"><thead><tr><th>' . JText::_('COM_COSTBENEFITPROJECTION_CAUSERISK') . '</th><th>' . JText::_('COM_COSTBENEFITPROJECTION_COST_PER_EMPLOYEE') . '</th><th>' . JText::_('COM_COSTBENEFITPROJECTION_MORBIDITY_REDUCTION') . '</th><th>' . JText::_('COM_COSTBENEFITPROJECTION_MORTALITY_REDUCTION') . '</th></tr></thead><tbody><tr>' . implode('</tr><tr>', $bucket) . '</tr></tbody></table><div class="uk-visible-small">' . implode('<br />', $bucketsmall) . '</div></td>';
}