source: sipes/0.3-modules/reportes_sipp/includes/reporte_configurado_reporte.pages.inc @ 92213c1

stableversion-3.0
Last change on this file since 92213c1 was 303fae2, checked in by José Gregorio Puentes <jpuentes@…>, 9 años ago

se agregaron los modulos

  • Propiedad mode establecida a 100755
File size: 16.1 KB
Línea 
1<?php
2  /**
3  * Sistema Integral de Planificación y Presupuesto (SIPP)
4  * @file reportes_sipp.module
5  * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP)
6  * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  * @author Cenditel Merida - Ing. Diego Uzcátegui (diego.uzc [at] gmail [dot] com)
23  * @date 2013-05-01 // (a&#241;o-mes-dia)
24  * @version 0.1 // (0.1)
25  *
26  */
27
28/*
29 * Pagina que muestra el reporte de matriz de procesos
30 * Implementado por: Ing. Diego Uzcátegui,
31 * Inicio de codificación: 25-04-13
32 */
33
34function reporte_configurado_reporte_page(){
35 
36  drupal_set_title(t('Reporte Configurado'));
37 
38  $output = '<br>';
39 
40  $output .= drupal_get_form('consulta_reporte_configurado_reporte_form');
41 
42  $output .= '<br><br>';
43 
44  //****************************************************************************
45 
46  $anno_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_rconfig']) && isset($_SESSION['datos_para_generar_reporte_rconfig']['anho']) ? $_SESSION['datos_para_generar_reporte_rconfig']['anho'] : date('Y');
47  if($anno_seleccionado_para_reporte > 0){
48    $anho_selecc = $anno_seleccionado_para_reporte;
49  }else{
50    $anho_selecc = 'Todos';
51  }
52 
53  $sub_opciones_campo = array(t('Unidad Ejecutora'), t('Sector del Proyecto'),t('Directriz PNDES'), t('Estratégia MCTI'), t('Estatus del Proyecto'), t('Situación Presupuestaria'),);
54  $campo_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_rconfig']) && isset($_SESSION['datos_para_generar_reporte_rconfig']['campo']) ? $_SESSION['datos_para_generar_reporte_rconfig']['campo'] : 0;
55  $campo_selec = $sub_opciones_campo[$campo_seleccionado_para_reporte];
56 
57  $sub_opciones_tipografico = array(t('Columna'), t('Barra'),t('Circulo'),);
58  $tipografico_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_rconfig']) && isset($_SESSION['datos_para_generar_reporte_rconfig']['tipografico']) ? $_SESSION['datos_para_generar_reporte_rconfig']['tipografico'] : 0;
59  $tipografico_selec = $sub_opciones_tipografico[$tipografico_seleccionado_para_reporte];
60   
61  $header = array();
62 
63  $rows1 = array();
64 
65  $row1 = array();
66  $row1[] = array('data' => 'Año', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
67  $row1[] = array('data' => $anho_selecc, 'bgcolor' => 'FCFCFC',);
68  $rows1[] = $row1;
69 
70  $row1 = array();
71  $row1[] = array('data' => 'Campo de Agrupación', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
72  $row1[] = array('data' => $campo_selec, 'bgcolor' => 'FCFCFC',);
73  $rows1[] = $row1;
74 
75  $row1 = array();
76  $row1[] = array('data' => 'Tipo de Gráfico', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
77  $row1[] = array('data' => $tipografico_selec, 'bgcolor' => 'FCFCFC',);
78  $rows1[] = $row1;
79
80  $output .= theme('table', $header, $rows1);
81  $output .= '<br><br>';
82   
83 
84  $header = array();
85  $header[] = array('data' => $campo_selec);
86  $header[] = array('data' => t('Cantidad de proyectos'));
87
88  $sql1 = "SELECT";
89  $sql_campos = " COUNT(*) AS cant";
90  $sql_tablas = " FROM {proyectos_operativos} po, {node} n, {content_type_proyectos_operativos} ctpo, {workflow_node} AS wn";
91  $sql_condiciones = " WHERE po.nid = n.nid AND n.vid = ctpo.vid AND wn.nid = n.nid AND wn.sid = %d";
92  $sql_agrupacion = "";//GROUP BY cn.field_sc_mes_value
93  $inputs[] = variable_get('proyectos_operativos_state_aprobado', NULL);//proyectos aprobados
94 
95  if($anno_seleccionado_para_reporte > 0){
96    $sql_condiciones .= " AND po.year = %d";
97    $inputs[] = $anno_seleccionado_para_reporte;
98  }
99 
100  if($campo_selec == t('Unidad Ejecutora')){
101    $sql_campos .= ", ctpo.field_proyecto_ente_nid AS nombrecampocol";
102    $sql_agrupacion = " GROUP BY ctpo.field_proyecto_ente_nid";
103   
104  }elseif($campo_selec == t('Sector del Proyecto')){
105    $sql_campos .= ", ctpo.field_proyecto_sector_value AS nombrecampocol";
106    $sql_agrupacion = " GROUP BY ctpo.field_proyecto_sector_value";
107   
108  }elseif($campo_selec == t('Directriz PNDES')){
109    $sql_campos .= ", ctpo.field_proyecto_pndes_value AS nombrecampocol";
110    $sql_agrupacion = " GROUP BY ctpo.field_proyecto_pndes_value";
111       
112  }elseif($campo_selec == t('Estratégia MCTI')){
113    $sql_campos .= ", ctpo.field_proyecto_mcti_value AS nombrecampocol";
114    $sql_agrupacion = " GROUP BY ctpo.field_proyecto_mcti_value";
115   
116  }elseif($campo_selec == t('Estatus del Proyecto')){
117    $sql_campos .= ", ctpo.field_proyecto_status_value AS nombrecampocol";
118    $sql_agrupacion = " GROUP BY ctpo.field_proyecto_status_value";
119   
120  }elseif($campo_selec == t('Situación Presupuestaria')){
121    $sql_campos .= ", ctpo.field_proyecto_situacion_p_value AS nombrecampocol";
122    $sql_agrupacion = " GROUP BY ctpo.field_proyecto_situacion_p_value";
123  }
124 
125  $sql1 .= $sql_campos.$sql_tablas.$sql_condiciones.$sql_agrupacion;
126 
127  $queryResult1 =  db_query ( $sql1, $inputs);
128  $tablas = array();
129  $rows = array();
130  $datos_grafica = array();
131  while ($resultado_consult_tabla = db_fetch_array ( $queryResult1 ) ){
132   
133    if($campo_selec == t('Unidad Ejecutora')){
134      $nodo_ente = node_load($resultado_consult_tabla['nombrecampocol']);
135      $nombre_campo_valor = $nodo_ente->title;
136     
137    }elseif(($campo_selec == t('Sector del Proyecto')) || ($campo_selec == t('Directriz PNDES'))||($campo_selec == t('Estratégia MCTI'))){
138      $term = taxonomy_get_term($resultado_consult_tabla['nombrecampocol']);
139      $nombre_campo_valor = $term->name;
140   
141    }else{//if(($campo_selec == t('Estatus del Proyecto'))||($campo_selec == t('Situación Presupuestaria')))
142      $nombre_campo_valor = $resultado_consult_tabla['nombrecampocol'];
143    }
144   
145    $row = array();
146    $row[] = array('data' => $nombre_campo_valor,);
147    $row[] = array('data' => $resultado_consult_tabla['cant']);
148   
149    //copiar para datos graficas
150    $dato_graf = array(
151      'nombre_opcion' => $nombre_campo_valor,
152      'cantidad' => $resultado_consult_tabla['cant'],
153    );
154    $datos_grafica[] = $dato_graf;
155   
156    $rows[] = $row;
157  }
158 
159  $tablas[]= theme('table', $header, $rows);
160 
161  //generación de grafica
162  $output .= generar_grafica_relacionada($datos_grafica, $campo_selec, $tipografico_selec);
163       
164  if (count($tablas)) {
165    $output .= implode('', $tablas);
166  }
167
168  $output .='<br><br>';
169
170  return $output;
171 
172}
173
174
175
176//***********************************************************
177
178function generar_grafica_relacionada($datos_grafica, $campo_selec, $tipografico_selec) {
179  $page_content = '';
180 
181  $path = libraries_get_path('Highcharts-3.0.1');
182 
183  if($tipografico_selec == t('Columna')){
184    $options = grafica_basica_columnas_opciones($datos_grafica, $campo_selec);
185  }elseif($tipografico_selec == t('Barra')){
186    $options = grafica_basica_barras_opciones($datos_grafica, $campo_selec);
187  }elseif($tipografico_selec == t('Circulo')){
188    $options = grafica_basica_circulo_opciones($datos_grafica, $campo_selec);
189  }
190 
191  if (is_object($options)) {
192    // Render the chart options object, and retrieve the chart id.
193    highcharts_render($options);
194    // Define required and optional chart container attributes.
195    $attributes = array(
196      // Required chart id passed by reference.
197      'id' => $options->chart->renderTo,
198      // Optionally add styles or any other valid attribute.
199      'style' => 'height: 400px;width: 800px;'
200    );
201       
202    $page_content .= theme_highcharts_chart($options->chart->renderTo);
203    $page_content .= theme('highcharts_chart', $attributes);
204  }
205 
206  $path_biblioteca_Highcharts = libraries_get_path('Highcharts-3.0.1');
207  drupal_add_js($path_biblioteca_Highcharts . '/js/modules/exporting.js');
208
209  return $page_content;
210}
211
212
213/**
214 * Column-basic highcharts options object.
215 *
216 * @see highcharts_render()
217 */
218function grafica_basica_columnas_opciones($datos_grafica, $campo_selec) {
219  $options = new stdClass();
220
221  // Chart.
222  $options->chart = (object)array(
223    'renderTo' => 'container',
224    'plotBackgroundColor' => NULL,
225    'plotBorderWidth' => NULL,
226    'plotShadow' => FALSE,
227  );
228
229  $options->chart->type = 'column';
230 
231  // Title.
232  $options->title->text = 'Distribución de Proyectos Operativos según <b>'.$campo_selec.'</b>';
233  $options->subtitle->text = 'Reporte Configurado SIPP';
234 
235  $categorias_xAxis = array();
236  $categorias_xAxis[] = $campo_selec;
237  $options->xAxis->categories = $categorias_xAxis;
238 
239  $options->yAxis->title->text = 'Cantidad de Proyectos';
240  $options->yAxis->allowDecimals = FALSE;
241
242  // Tooltip.
243  // Normally formatter is a function callback. For now we'll make it a string.
244  // @todo whenever this is user defined (views config, etc) be sure to sanitize
245  // this string before passing to highcharts_render().
246  $options->tooltip->formatter = "function() {return '<b>'+ this.series.name +'</b>: '+ this.point.y +' proyecto(s)';}";
247 
248  // Plot options.
249  $options->plotOptions->column = (object)array(
250    'allowPointSelect' => TRUE,
251    'cursor' => 'pointer',
252    'dataLabels' => array(
253      'enabled' => FALSE,
254    ),
255    'showInLegend' => TRUE,
256  );
257 
258  // Series.
259  $options->series = array();
260 
261  foreach($datos_grafica as $valor_opc_i){
262    $series = new StdClass();
263    $series->name = $valor_opc_i['nombre_opcion'];
264    $series->data = array();
265    $series->data[] = array($valor_opc_i['cantidad']*1.0);
266    $options->series[] = $series;
267  }
268
269  // Diable credits.
270  $options->credits->enabled = FALSE;
271
272  return $options;
273}
274
275
276/**
277 * Bar-basic highcharts options object.
278 *
279 * @see highcharts_render()
280 */
281function grafica_basica_barras_opciones($datos_grafica, $campo_selec) {
282  $options = new stdClass();
283
284  // Chart.
285  $options->chart = (object)array(
286    'renderTo' => 'container',
287    'plotBackgroundColor' => NULL,
288    'plotBorderWidth' => NULL,
289    'plotShadow' => FALSE,
290  );
291
292  $options->chart->type = 'bar';
293 
294  // Title.
295  $options->title->text = 'Distribución de Proyectos Operativos según <b>'.$campo_selec.'</b>';
296  $options->subtitle->text = 'Reporte Configurado SIPP';
297 
298  $categorias_xAxis = array();
299  $categorias_xAxis[] = $campo_selec;
300  $options->xAxis->categories = $categorias_xAxis;
301 
302  $options->yAxis->title->text = 'Cantidad de Proyectos';
303  $options->yAxis->allowDecimals = FALSE;
304
305  // Tooltip.
306  // Normally formatter is a function callback. For now we'll make it a string.
307  // @todo whenever this is user defined (views config, etc) be sure to sanitize
308  // this string before passing to highcharts_render().
309  $options->tooltip->formatter = "function() {return '<b>'+ this.series.name +'</b>: '+ this.point.y +' proyecto(s)';}";
310 
311  // Plot options.
312  $options->plotOptions->bar = (object)array(
313    'allowPointSelect' => TRUE,
314    'cursor' => 'pointer',
315    'dataLabels' => array(
316      'enabled' => FALSE,
317    ),
318    'showInLegend' => TRUE,
319  );
320 
321  // Series.
322  $options->series = array();
323
324  foreach($datos_grafica as $valor_opc_i){
325    $series = new StdClass();
326    $series->name = $valor_opc_i['nombre_opcion'];
327    $series->data = array();
328    $series->data[] = array($valor_opc_i['cantidad']*1.0);
329    $options->series[] = $series;
330  }
331
332  // Diable credits.
333  $options->credits->enabled = FALSE;
334
335  return $options;
336}
337
338
339/**
340 * Pie-basic highcharts options object.
341 *
342 * @see highcharts_render()
343 */
344function grafica_basica_circulo_opciones($datos_grafica, $campo_selec) {
345  $options = new stdClass();
346
347  // Chart.
348  $options->chart = (object)array(
349    'renderTo' => 'container',
350    'plotBackgroundColor' => NULL,
351    'plotBorderWidth' => NULL,
352    'plotShadow' => FALSE,
353  );
354
355  // Title.
356  $options->title->text = 'Distribución de Proyectos Operativos según <b>'.$campo_selec.'</b>';
357  $options->subtitle->text = 'Reporte Configurado SIPP';
358
359  // Tooltip.
360  // Normally formatter is a function callback. For now we'll make it a string.
361  // @todo whenever this is user defined (views config, etc) be sure to sanitize
362  // this string before passing to highcharts_render().
363  $options->tooltip->formatter = "function() {return '<b>'+ this.point.name +'</b>: '+ this.point.y + ' proyecto(s), ' + this.percentage.toFixed(2) +' %';}";
364
365  // Plot options.
366  $options->plotOptions->pie = (object)array(
367    'allowPointSelect' => TRUE,
368    'cursor' => 'pointer',
369    'dataLabels' => array(
370      'enabled' => FALSE,
371    ),
372    'showInLegend' => TRUE,
373  );
374
375  // Series.
376  $options->series = array();
377  $series = new StdClass();
378  $series->type = 'pie';
379  $series->name = $campo_selec;
380 
381  $series->data = array();
382  foreach($datos_grafica as $valor_opc_i){
383    $series->data[] = array($valor_opc_i['nombre_opcion'], $valor_opc_i['cantidad']*1.0);
384  }
385  $options->series[] = $series;
386
387  // Diable credits.
388  $options->credits->enabled = FALSE;
389
390  return $options;
391}
392
393//***********************************************************
394
395
396/**
397 * Implementation of consulta_matriz_de_procesos_reporte_form().
398 * Formulario de busqueda de proyecto.
399 */
400function consulta_reporte_configurado_reporte_form($form_state) {
401  $form = array();
402 
403  //años disponibles
404  $anno_actual = date("Y");
405  for($i = $anno_actual - 10; $i <= $anno_actual; $i++) {
406    $annos[$i] = $i;
407  }
408  $annos[0] = 'Todos';
409  $anno_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_rconfig']) && isset($_SESSION['datos_para_generar_reporte_rconfig']['anho']) ? $_SESSION['datos_para_generar_reporte_rconfig']['anho'] : date('Y');
410  $form['anno_seleccionado_para_reporte'] = array(
411    '#title' => t('Consultar para el año'),
412    '#type' => 'select',
413    '#default_value' => $anno_seleccionado_para_reporte,
414    '#options' => $annos,
415  );
416
417  $sub_opciones_campo = array(t('Unidad Ejecutora'), t('Sector del Proyecto'),t('Directriz PNDES'), t('Estratégia MCTI'), t('Estatus del Proyecto'), t('Situación Presupuestaria'),);
418  $campo_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_rconfig']) && isset($_SESSION['datos_para_generar_reporte_rconfig']['campo']) ? $_SESSION['datos_para_generar_reporte_rconfig']['campo'] : 0;
419  $form['campo_seleccionado_para_reporte'] = array(
420    '#title' => t('Campo de agrupación'),
421    '#type' => 'select',
422    '#default_value' => $campo_seleccionado_para_reporte,
423    '#options' => $sub_opciones_campo,
424  );
425 
426  $sub_opciones_tipografico = array(t('Columna'), t('Barra'),t('Circulo'),);
427  $tipografico_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_rconfig']) && isset($_SESSION['datos_para_generar_reporte_rconfig']['tipografico']) ? $_SESSION['datos_para_generar_reporte_rconfig']['tipografico'] : 0;
428  $form['tipografico_seleccionado_para_reporte'] = array(
429    '#title' => t('Tipo de Gráfico'),
430    '#type' => 'select',
431    '#default_value' => $tipografico_seleccionado_para_reporte,
432    '#options' => $sub_opciones_tipografico,
433  );
434       
435  //boton de enviar consulta
436  $form['buttons'] = array(
437    '#prefix' => '<div class="container-inline">',
438    '#suffix' => '</div>',
439  );
440  $form['buttons']['submit'] = array(
441    '#type' => 'submit',
442    '#value' => t('Consultar'),
443  );
444  return $form;
445}
446
447/**
448 * Implementation of consulta_matriz_de_procesos_reporte_form_submit().
449 * cambia el filtro de busqueda de proyectos.
450 */
451function consulta_reporte_configurado_reporte_form_submit($form, &$form_state) {
452  $_SESSION['datos_para_generar_reporte_rconfig'] = array();
453
454  $_SESSION['datos_para_generar_reporte_rconfig']['anho'] = $form_state['values']['anno_seleccionado_para_reporte'];
455  $_SESSION['datos_para_generar_reporte_rconfig']['campo'] = $form_state['values']['campo_seleccionado_para_reporte'];
456  $_SESSION['datos_para_generar_reporte_rconfig']['tipografico'] = $form_state['values']['tipografico_seleccionado_para_reporte'];
457
458}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.