public function getListTableRowOperations(&$row)
 {
     $progress = R3EcoGisGlobalPlainHelper::getActionStatus($row['gpr_id']);
     if ($progress['energy_perc'] != '') {
         $row['progress_energy'] = sprintf('%.1f', $progress['energy_perc']);
     }
     if ($progress['emission_perc'] != '') {
         $row['progress_emission'] = sprintf('%.1f', $progress['emission_perc']);
     }
     $id = $row['gpr_id'];
     $baseURL = 'edit.php?on=' . $this->baseName;
     $objName = strToUpper($this->baseName);
     $links = array();
     foreach (array('show', 'mod', 'del') as $act) {
         if ($this->auth->hasPerm(strToUpper($act), $objName)) {
             switch ($act) {
                 case 'show':
                     $links['SHOW'] = $this->simpleTable->AddLinkCell(_('Visualizza'), "javascript:showObject('{$id}')", "", "{$this->imagePath}ico_{$act}.gif");
                     break;
                 case 'mod':
                     $links['MOD'] = $this->simpleTable->AddLinkCell(_('Modifica'), "javascript:modObject('{$id}')", "", "{$this->imagePath}ico_{$act}.gif");
                     break;
                 case 'del':
                     if (!$row['gpr_imported_row']) {
                         $links['DEL'] = $this->simpleTable->AddLinkCell(_('Cancella'), "javascript:askDelGlobalPlainRowFromGauge('{$id}')", "", "{$this->imagePath}ico_{$act}.gif");
                     } else {
                         $links['DEL'] = $this->simpleTable->AddLinkCell('', '', '', "../images/ico_spacer.gif");
                     }
                     break;
             }
         }
     }
     return $links;
 }
 /**
  *
  * @param <type> $ge_id
  * @param <type> $kind
  * @param <type> $divider Return the table data
  */
 private static function getDataMunicipality($do_id, $gp_id)
 {
     $lang = R3Locale::getLanguageID();
     $db = ezcDbInstance::get();
     $auth = R3AuthInstance::get();
     $calculateCategorySum = $auth->getConfigValue('APPLICATION', 'CALCULATE_GLOBAL_PLAIN_TOTALS', 'T') == 'T';
     $other = _('Altro');
     $sql = "SELECT gc1.gc_id,gc1.gc_parent_id,gc1.do_id,\r\n                       gc2.gc_code AS gc_code_main,gc2.gc_name_{$lang} AS gc_name_main,gc2.gc_order AS gc_order_main,\r\n                       gc1.gc_code, gc1.gc_name_{$lang} AS gc_name, gc1.gc_order,\r\n                       gps_id,gps.gp_id AS pg_id_sum,gps_expected_energy_saving,gps_expected_renewable_energy_production,gps_expected_co2_reduction,\r\n                       BOOL2TEXT(gc1.gc_has_extradata) AS gc_has_extradata, gpr_id,\r\n                       CASE WHEN gc_extradata_{$lang} IS NULL THEN gc1.gc_name_{$lang} ELSE gc1.gc_name_{$lang} || ' - ' || gc_extradata_{$lang} END AS gc_fullname,\r\n                       gpr.gpa_id, gpa.gpa_code, \r\n                       \r\n                       CASE WHEN gpr.gpa_extradata_{$lang} IS NULL THEN gpa_name_{$lang}\r\n                       ELSE CASE WHEN UPPER(gpa_name_{$lang})=UPPER('{$other}') THEN gpr.gpa_extradata_{$lang}\r\n                           ELSE gpa_name_{$lang} || ' - ' || gpr.gpa_extradata_{$lang}\r\n                           END \r\n                       END AS gpa_name,\r\n                       gpr_descr_{$lang} AS gpr_descr, gpr_responsible_department_{$lang} AS gpr_responsible_department,\r\n                       gpr_start_date, gpr_end_date, gpr_estimated_cost, gpr_expected_energy_saving, gpr_expected_renewable_energy_production,\r\n                       gpr_expected_co2_reduction, gpr_imported_row, gpr_gauge_type\r\n                FROM ecogis.global_category gc1\r\n                INNER JOIN ecogis.global_category gc2 ON gc1.gc_parent_id=gc2.gc_id\r\n                LEFT JOIN ecogis.global_plain_row gpr ON gc1.gc_id=gpr.gc_id AND gpr.gp_id={$gp_id}\r\n                LEFT JOIN ecogis.global_plain_action gpa ON gpa.gpa_id=gpr.gpa_id\r\n                LEFT JOIN ecogis.global_plain_sum gps ON gc2.gc_id=gps.gc_id and gps.gp_id={$gp_id}\r\n                WHERE (gc1.do_id IS NULL OR gc1.do_id={$do_id}) AND gc1.gc_global_plain IS TRUE AND gc2.gc_global_plain IS TRUE AND\r\n                      gc1.gc_visible IS TRUE and gc2.gc_visible IS TRUE\r\n                ORDER BY gc_order_main, gc_name_main, gc_order, gc_name, gc_fullname, gpr_order, gpa_name, gpr_id";
     $result = array();
     $sumData = array();
     // Serve per somme di categoria e totali
     foreach ($db->query($sql, PDO::FETCH_ASSOC) as $row) {
         $progress = R3EcoGisGlobalPlainHelper::getActionStatus($row['gpr_id']);
         // Dati per somma totali categoria (e totalone)
         if (!isset($sumData[$row['gc_parent_id']])) {
             $sumData[$row['gc_parent_id']] = array('energy_tot' => null, 'emission_tot' => null);
         }
         if ($progress['energy_tot'] != '') {
             $sumData[$row['gc_parent_id']]['energy_tot'] += $progress['energy_tot'];
         }
         if ($progress['emission_tot'] != '') {
             $sumData[$row['gc_parent_id']]['emission_tot'] += $progress['emission_tot'];
         }
         if (!isset($result['data'][$row['gc_parent_id']]['rowspan'])) {
             $result['data'][$row['gc_parent_id']]['rowspan'] = 0;
         }
         if (!isset($result['data'][$row['gc_parent_id']]['sum'])) {
             $result['data'][$row['gc_parent_id']]['sum'] = array('expected_energy_saving' => null, 'expected_renewable_energy_production' => null, 'expected_co2_reduction' => null, 'progress_energy' => null, 'progress_emission' => null);
         }
         $result['data'][$row['gc_parent_id']]['rowspan']++;
         $result['data'][$row['gc_parent_id']]['gc_id'] = $row['gc_id'];
         $result['data'][$row['gc_parent_id']]['gc_parent_id'] = $row['gc_parent_id'];
         $result['data'][$row['gc_parent_id']]['code'] = $row['gc_code_main'];
         $result['data'][$row['gc_parent_id']]['name'] = $row['gc_name_main'];
         if ($calculateCategorySum) {
             // Sum data (ignoring database entry) - New configuration
             if ($row['gpr_expected_energy_saving'] !== null) {
                 $result['data'][$row['gc_parent_id']]['sum']['expected_energy_saving'] += $row['gpr_expected_energy_saving'];
             }
             if ($row['gpr_expected_renewable_energy_production'] !== null) {
                 $result['data'][$row['gc_parent_id']]['sum']['expected_renewable_energy_production'] += $row['gpr_expected_renewable_energy_production'];
             }
             if ($row['gpr_expected_co2_reduction'] !== null) {
                 $result['data'][$row['gc_parent_id']]['sum']['expected_co2_reduction'] += $row['gpr_expected_co2_reduction'];
             }
         } else {
             // Use database entry for sum category data (table ecogis.global_plain_sum) - Old configuration. SHould be switched to automatic calculation
             $result['data'][$row['gc_parent_id']]['sum']['expected_energy_saving'] = $row['gps_expected_energy_saving'];
             $result['data'][$row['gc_parent_id']]['sum']['expected_renewable_energy_production'] = $row['gps_expected_renewable_energy_production'];
             $result['data'][$row['gc_parent_id']]['sum']['expected_co2_reduction'] = $row['gps_expected_co2_reduction'];
         }
         $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['name'] = $row['gc_name'];
         $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['code'] = $row['gc_code'];
         $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['has_extradata'] = $row['gc_has_extradata'];
         $result['data'][$row['gc_parent_id']]['categories'][$row['gc_id']]['data'][$row['gpr_id']] = array('code' => $row['gpa_code'], 'imported_row' => $row['gpr_imported_row'], 'gauge_type' => $row['gpr_gauge_type'], 'progress_energy' => round($progress['energy_perc'], 1), 'progress_emission' => round($progress['emission_perc'], 1), 'name' => $row['gpa_name'], 'fullname' => $row['gc_fullname'], 'descr' => $row['gpr_descr'], 'responsible_department' => $row['gpr_responsible_department'], 'start_date' => $row['gpr_start_date'], 'end_date' => $row['gpr_end_date'], 'estimated_cost' => $row['gpr_estimated_cost'], 'expected_energy_saving' => $row['gpr_expected_energy_saving'], 'expected_renewable_energy_production' => $row['gpr_expected_renewable_energy_production'], 'expected_co2_reduction' => $row['gpr_expected_co2_reduction']);
     }
     $sum = array('expected_energy_saving' => null, 'expected_renewable_energy_production' => null, 'expected_co2_reduction' => null, 'progress_energy' => null, 'progress_emission' => null);
     $energyTot = null;
     $emisisonTot = null;
     foreach ($result['data'] as $row) {
         if ($row['sum']['expected_energy_saving'] != '') {
             $sum['expected_energy_saving'] += $row['sum']['expected_energy_saving'];
         }
         if ($row['sum']['expected_renewable_energy_production'] != '') {
             $sum['expected_renewable_energy_production'] += $row['sum']['expected_renewable_energy_production'];
         }
         if ($row['sum']['expected_co2_reduction'] != '') {
             $sum['expected_co2_reduction'] += $row['sum']['expected_co2_reduction'];
         }
         // Imposto Percentuali completamento
         if ($row['sum']['expected_energy_saving'] + $row['sum']['expected_renewable_energy_production'] != 0) {
             $energyTot += $sumData[$row['gc_parent_id']]['energy_tot'];
             $result['data'][$row['gc_parent_id']]['sum']['progress_energy'] = round($sumData[$row['gc_parent_id']]['energy_tot'] / ($row['sum']['expected_energy_saving'] + $row['sum']['expected_renewable_energy_production']) * 100, 1);
         }
         if ($row['sum']['expected_co2_reduction'] != 0) {
             $emisisonTot += $sumData[$row['gc_parent_id']]['emission_tot'];
             $result['data'][$row['gc_parent_id']]['sum']['progress_emission'] = round($sumData[$row['gc_parent_id']]['emission_tot'] / $row['sum']['expected_co2_reduction'] * 100, 1);
         }
     }
     if ($sum['expected_energy_saving'] + $sum['expected_renewable_energy_production'] != 0) {
         $sum['progress_energy'] = round($energyTot / ($sum['expected_energy_saving'] + $sum['expected_renewable_energy_production']) * 100, 1);
     }
     if ($sum['expected_co2_reduction'] != 0) {
         $sum['progress_emission'] = round($emisisonTot / $sum['expected_co2_reduction'] * 100, 1);
     }
     $result['sum'] = $sum;
     return $result;
 }
Exemple #3
0
 public function getGlobalCategory($request)
 {
     R3EcoGisHelper::includeHelperClass('obj.global_plain_row.php');
     return array('status' => R3_AJAX_NO_ERROR, 'data' => R3EcoGisHelper::forceJSonArray(R3EcoGisGlobalPlainHelper::getCategoriesListByParentId($_SESSION['do_id'], (int) $request['parent_id'], array('allow_empty' => true))));
 }
 public function getGlobalAction($request)
 {
     return array('status' => R3_AJAX_NO_ERROR, 'data' => R3EcoGisHelper::forceJSonArray(R3EcoGisGlobalPlainHelper::getPlainActionList($_SESSION['do_id'], $request['gc_id'], array('allow_empty' => true))));
 }