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ño-mes-dia) |
---|
24 | * @version 0.1 // (0.1) |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | function calcular_datos_para_aem_reporte_page($anno_seleccionado_para_reporte = 0, $area_seleccionada_para_reporte = 0, $tipografico_selec){//areas_estrategicas_del_ministerio |
---|
29 | |
---|
30 | $anho_selecc = $anno_seleccionado_para_reporte; |
---|
31 | $area_selecc = ($area_seleccionada_para_reporte > 0) ? taxonomy_get_term($area_seleccionada_para_reporte)->name : 'Todas'; |
---|
32 | |
---|
33 | $anho_min_historico = $anno_seleccionado_para_reporte; |
---|
34 | |
---|
35 | module_load_include('inc', 'reportes_sipp' , 'includes/matriz_de_procesos_reporte_trimestral.pages'); |
---|
36 | |
---|
37 | $datos_grafica = array(); |
---|
38 | $datos_historico = array(); |
---|
39 | |
---|
40 | //proyectos operativos con estado aprobado |
---|
41 | $sql1 = "SELECT"; |
---|
42 | $sql_campos = " COUNT(*) AS total, ctpo.field_proyecto_mcti_value, ctpo.field_proyecto_unidadm_value";//, po.year"; |
---|
43 | $sql_tablas = " FROM {proyectos_operativos} po, {node} n, {workflow_node} AS wn, {content_type_proyectos_operativos} AS ctpo"; |
---|
44 | $sql_condiciones = " WHERE po.nid = n.nid AND wn.nid = n.nid AND wn.sid = %d AND n.nid = ctpo.nid AND n.vid = ctpo.vid"; |
---|
45 | $sql_agrupacion = "";//GROUP BY campo |
---|
46 | $sql_ordenacion = ""; |
---|
47 | |
---|
48 | $inputs = array(); |
---|
49 | $inputs[] = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
50 | |
---|
51 | if($area_selecc != 'Todas'){ |
---|
52 | //filtrar por estrategia MCTI |
---|
53 | $inputs[] = $area_seleccionada_para_reporte; |
---|
54 | $sql_condiciones .= " AND ctpo.field_proyecto_mcti_value = %d"; |
---|
55 | } |
---|
56 | |
---|
57 | $inputs[] = $anno_seleccionado_para_reporte; |
---|
58 | $sql_condiciones .= " AND po.year = %d"; |
---|
59 | |
---|
60 | $sql_agrupacion = " GROUP BY ctpo.field_proyecto_mcti_value, ctpo.field_proyecto_unidadm_value";//, po.year";//agrupando de derecha a izquierda |
---|
61 | $sql_ordenacion = " ORDER BY ctpo.field_proyecto_mcti_value, ctpo.field_proyecto_unidadm_value";//, po.year"; |
---|
62 | |
---|
63 | $sql1 .= $sql_campos.$sql_tablas.$sql_condiciones.$sql_agrupacion.$sql_ordenacion; |
---|
64 | |
---|
65 | $queryResult1 = db_query ( $sql1, $inputs); |
---|
66 | while ($proyectos = db_fetch_array ( $queryResult1 ) ){ |
---|
67 | $nombre_estrategia_mcti = taxonomy_get_term($proyectos['field_proyecto_mcti_value'])->name; |
---|
68 | $nombre_unidad_medida = taxonomy_get_term($proyectos['field_proyecto_unidadm_value'])->name; |
---|
69 | |
---|
70 | //calcular cantidades producidas en trimestres |
---|
71 | $sql2 = "SELECT"; |
---|
72 | $sql_campos_2 = " n.nid"; |
---|
73 | $sql_tablas_2 = $sql_tablas; |
---|
74 | $sql_condiciones_2 = $sql_condiciones; |
---|
75 | |
---|
76 | $inputs_2 = array(); |
---|
77 | |
---|
78 | if($area_selecc == 'Todas'){//incluir filtro particular area |
---|
79 | $sql_condiciones_2 .= " AND ctpo.field_proyecto_mcti_value = %d"; |
---|
80 | $inputs_2[] = $proyectos['field_proyecto_mcti_value']; |
---|
81 | } |
---|
82 | $sql_condiciones_2 .= " AND ctpo.field_proyecto_unidadm_value = %d"; |
---|
83 | $inputs_2[] = $proyectos['field_proyecto_unidadm_value']; |
---|
84 | |
---|
85 | $sql2 .= $sql_campos_2.$sql_tablas_2.$sql_condiciones_2;//consulta especializada a proyectos de un grupo |
---|
86 | $entradas = array_merge($inputs, $inputs_2);//agregar segundo grupo de entradas |
---|
87 | |
---|
88 | //inicializar cantidades en trimestres |
---|
89 | $cant_ejecutado_trim = array(); |
---|
90 | $cant_ejecutado_trim[0] = 0; |
---|
91 | $cant_ejecutado_trim[1] = 0; |
---|
92 | $cant_ejecutado_trim[2] = 0; |
---|
93 | $cant_ejecutado_trim[3] = 0; |
---|
94 | |
---|
95 | //consular cantidad de ejecutado de meta fisica en trimestres |
---|
96 | $queryResult_2 = db_query ( $sql2, $entradas);//consultar los proyectos en determinado grupo |
---|
97 | while ($proyectos_en_area_estrat = db_fetch_array ( $queryResult_2 ) ){ |
---|
98 | $nodo_proyecto = node_load($proyectos_en_area_estrat['nid']); |
---|
99 | //calcular todos los trimestres |
---|
100 | for($i=0; $i<4; $i++){ |
---|
101 | $porcentajes_avance = _calcular_porcentaje_avance_para_trimestre($nodo_proyecto, $i); |
---|
102 | $cant_ejecutado_trim[$i] += $porcentajes_avance['valores_particulares']['mf_ejecutado_trimestre']; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | $total_area_y_unidad_medida = 0; |
---|
107 | for($i=0; $i<4; $i++){ |
---|
108 | $total_area_y_unidad_medida += $cant_ejecutado_trim[$i]; |
---|
109 | } |
---|
110 | |
---|
111 | //copiar para datos graficas |
---|
112 | $dato_graf = array( |
---|
113 | 'id_aem' => $proyectos['field_proyecto_mcti_value'], |
---|
114 | 'id_unidadmedida' => $proyectos['field_proyecto_unidadm_value'], |
---|
115 | 'nombre_opcion_politica' => $nombre_estrategia_mcti, |
---|
116 | 'nombre_opcion_unidadmedida' => $nombre_unidad_medida, |
---|
117 | 'cant_proyectos' => $proyectos['total'], |
---|
118 | 'anho_actual' => $anno_seleccionado_para_reporte, |
---|
119 | 'cantidad_trimestres' => $cant_ejecutado_trim, |
---|
120 | ); |
---|
121 | $datos_grafica[] = $dato_graf; |
---|
122 | |
---|
123 | //****************************************************************************** |
---|
124 | //consultar datos para grafico de historicos |
---|
125 | $datos_historico_i = calcular_datos_historico_para_aem_reporte_page($proyectos['field_proyecto_mcti_value'], $proyectos['field_proyecto_unidadm_value'], $anno_seleccionado_para_reporte, $total_area_y_unidad_medida); |
---|
126 | if($datos_historico_i['anho_nim'] < $anho_min_historico){ |
---|
127 | $anho_min_historico = $datos_historico_i['anho_nim']; |
---|
128 | } |
---|
129 | $datos_historico[] = $datos_historico_i['cantidad_por_anho']; |
---|
130 | //****************************************************************************** |
---|
131 | |
---|
132 | } |
---|
133 | |
---|
134 | $valor_de_retorno = array( |
---|
135 | 'datos_anho_actual' => $datos_grafica, |
---|
136 | 'datos_historico' => $datos_historico, |
---|
137 | 'anho_min_historico' => $anho_min_historico, |
---|
138 | 'param' => array('anho' => $anno_seleccionado_para_reporte, 'area' => $area_selecc, 'tgraf' => $tipografico_selec,), |
---|
139 | ); |
---|
140 | |
---|
141 | return $valor_de_retorno; |
---|
142 | |
---|
143 | } |
---|
144 | //******************************************************* |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | function calcular_datos_historico_para_aem_reporte_page($id_aem = 0, $id_unidadmedida = 0, $anho_actual=0, $cant_anho_actual=0){//areas_estrategicas_del_ministerio |
---|
149 | |
---|
150 | $cantidad_por_anhos = array(); |
---|
151 | $cantidad_por_anhos[$anho_actual] = $cant_anho_actual; |
---|
152 | $anho_min = $anho_actual - 4; |
---|
153 | |
---|
154 | //proyectos operativos con estado aprobado |
---|
155 | $sql1 = "SELECT"; |
---|
156 | $sql_campos = " po.year AS anho, COUNT(*) AS total, SUM(sp.ejecutadometafisica) AS cantidad_prod"; |
---|
157 | $sql_tablas = " FROM {proyectos_operativos} po, {node} n, {workflow_node} AS wn, {content_type_proyectos_operativos} AS ctpo"; |
---|
158 | $sql_tablas .= ", {seguimiento_proyecto} AS sp"; |
---|
159 | $sql_condiciones = " WHERE po.nid = n.nid AND wn.nid = n.nid AND wn.sid = %d AND n.nid = ctpo.nid AND n.vid = ctpo.vid"; |
---|
160 | $sql_condiciones .= " AND ctpo.field_proyecto_mcti_value = %d AND ctpo.field_proyecto_unidadm_value = %d AND po.year != %d";// estrategia mcti y unidad de medida |
---|
161 | $sql_condiciones .= " AND n.nid = sp.nid AND sp.estado = %d";//seguimiento de proyecto aprobado |
---|
162 | $sql_agrupacion = " GROUP BY po.year"; |
---|
163 | $sql_ordenacion = " ORDER BY po.year"; |
---|
164 | |
---|
165 | $sql1 .= $sql_campos . $sql_tablas . $sql_condiciones . $sql_agrupacion . $sql_ordenacion; |
---|
166 | |
---|
167 | $inputs = array(); |
---|
168 | $inputs[] = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
169 | $inputs[] = $id_aem; |
---|
170 | $inputs[] = $id_unidadmedida; |
---|
171 | $inputs[] = $anho_actual; |
---|
172 | $inputs[] = variable_get('acciones_centralizadas_state_aprobado', NULL); |
---|
173 | |
---|
174 | $queryResult_2 = db_query ( $sql1, $inputs); |
---|
175 | while ($proyectos_en_area_estrat = db_fetch_array ( $queryResult_2 ) ){ |
---|
176 | $cantidad_por_anhos[ $proyectos_en_area_estrat['anho'] ] = $proyectos_en_area_estrat['cantidad_prod']; |
---|
177 | if($proyectos_en_area_estrat['anho'] < $anho_min){ |
---|
178 | $anho_min = $proyectos_en_area_estrat['anho']; |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | $valor_regresado = array( |
---|
183 | 'anho_nim' => $anho_min, |
---|
184 | 'cantidad_por_anho' => $cantidad_por_anhos, |
---|
185 | ); |
---|
186 | |
---|
187 | return $valor_regresado; |
---|
188 | |
---|
189 | } |
---|
190 | //******************************************************* |
---|
191 | |
---|
192 | function generar_tabla_produccion_trimestres($datos_anho_actual=array(), $param = array()){//areas_estrategicas_del_ministerio |
---|
193 | |
---|
194 | $anno_seleccionado_para_reporte = $param['anho']; |
---|
195 | |
---|
196 | $header = array(); |
---|
197 | $header[] = array('data' => t('Cantidad de Proyectos')); |
---|
198 | $header[] = array('data' => t('Ãrea Estratégica')); |
---|
199 | $header[] = array('data' => t('Unidad de Medida')); |
---|
200 | $header[] = array('data' => t('Producción <br> 1er Trimestre')); |
---|
201 | $header[] = array('data' => t('Producción <br> 2do Trimestre')); |
---|
202 | $header[] = array('data' => t('Producción <br> 3er Trimestre')); |
---|
203 | $header[] = array('data' => t('Producción <br> 4to Trimestre')); |
---|
204 | $header[] = array('data' => t('Total')); |
---|
205 | |
---|
206 | $rows = array(); |
---|
207 | foreach($datos_anho_actual as $datos_area_udm_i){//area - unidad de medida |
---|
208 | $row = array(); |
---|
209 | $row[] = array('data' => $datos_area_udm_i['cant_proyectos'],); |
---|
210 | $row[] = array('data' => $datos_area_udm_i['nombre_opcion_politica'],); |
---|
211 | $row[] = array('data' => $datos_area_udm_i['nombre_opcion_unidadmedida'],); |
---|
212 | |
---|
213 | $total_area_y_unidad_medida = 0; |
---|
214 | for($i=0; $i<4; $i++){ |
---|
215 | $row[] = array('data' => $datos_area_udm_i['cantidad_trimestres'][$i],); |
---|
216 | $total_area_y_unidad_medida += $datos_area_udm_i['cantidad_trimestres'][$i]; |
---|
217 | } |
---|
218 | $row[] = array('data' => $total_area_y_unidad_medida,); |
---|
219 | |
---|
220 | $rows[] = $row; |
---|
221 | } |
---|
222 | |
---|
223 | if (!(count($rows)>0)) { |
---|
224 | $row[] = array('data' => t('No hay resultados para el reporte actual'), 'colspan' => 8); |
---|
225 | $rows[] = $row; |
---|
226 | } |
---|
227 | |
---|
228 | //generación tabla |
---|
229 | $output .= "<h4>Gestión en el año: ".$anno_seleccionado_para_reporte."</h4>"; |
---|
230 | $tabla_trimestres = theme('table', $header, $rows); |
---|
231 | $output .= $tabla_trimestres; |
---|
232 | |
---|
233 | return $output; |
---|
234 | |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | //************************************************************************************************************************** |
---|
239 | function generar_grafica_producciontrimestres($datos_grafica=array(), $param = array()) { |
---|
240 | |
---|
241 | $area_selecc = $param['area']; |
---|
242 | $tipografico_selec = $param['tgraf']; |
---|
243 | $anho_selecc = $param['anho']; |
---|
244 | |
---|
245 | $page_content = ''; |
---|
246 | |
---|
247 | $path = libraries_get_path('Highcharts-3.0.1'); |
---|
248 | |
---|
249 | if($tipografico_selec == t('Columnas')){ |
---|
250 | $options = grafica_basica_variascolumnas_opciones($datos_grafica, $area_selecc, $anho_selecc); |
---|
251 | }elseif($tipografico_selec == t('Lineas')){ |
---|
252 | $options = grafica_basica_variaslineas_opciones($datos_grafica, $area_selecc, $anho_selecc); |
---|
253 | } |
---|
254 | |
---|
255 | if (is_object($options)) { |
---|
256 | // Render the chart options object, and retrieve the chart id. |
---|
257 | highcharts_render($options); |
---|
258 | // Define required and optional chart container attributes. |
---|
259 | $attributes = array( |
---|
260 | // Required chart id passed by reference. |
---|
261 | 'id' => $options->chart->renderTo, |
---|
262 | // Optionally add styles or any other valid attribute. |
---|
263 | 'style' => 'height: 400px;width: 800px;' |
---|
264 | ); |
---|
265 | |
---|
266 | $page_content .= theme_highcharts_chart($options->chart->renderTo); |
---|
267 | $page_content .= theme('highcharts_chart', $attributes); |
---|
268 | } |
---|
269 | |
---|
270 | $path_biblioteca_Highcharts = libraries_get_path('Highcharts-3.0.1'); |
---|
271 | drupal_add_js($path_biblioteca_Highcharts . '/js/modules/exporting.js'); |
---|
272 | |
---|
273 | return $page_content; |
---|
274 | } |
---|
275 | |
---|
276 | |
---|
277 | /** |
---|
278 | * Column-basic highcharts options object. |
---|
279 | * |
---|
280 | * @see highcharts_render() |
---|
281 | */ |
---|
282 | function grafica_basica_variascolumnas_opciones($datos_grafica, $area_selecc, $anho_selecc) { |
---|
283 | $options = new stdClass(); |
---|
284 | |
---|
285 | // Chart. |
---|
286 | $options->chart = (object)array( |
---|
287 | 'renderTo' => 'container', |
---|
288 | 'plotBackgroundColor' => NULL, |
---|
289 | 'plotBorderWidth' => NULL, |
---|
290 | 'plotShadow' => FALSE, |
---|
291 | ); |
---|
292 | |
---|
293 | $options->chart->type = 'column'; |
---|
294 | |
---|
295 | // Title. |
---|
296 | $options->title->text = '<b>Gestión en el año '.$anho_selecc.' en <i>'.$area_selecc.'</i></b>'; |
---|
297 | $options->subtitle->text = 'Ãreas Estratégicas del Ministerio SIPP'; |
---|
298 | |
---|
299 | $categorias_xAxis = array(); |
---|
300 | $categorias_xAxis[] = '1er Trimestre'; |
---|
301 | $categorias_xAxis[] = '2do Trimestre'; |
---|
302 | $categorias_xAxis[] = '3er Trimestre'; |
---|
303 | $categorias_xAxis[] = '4to Trimestre'; |
---|
304 | $options->xAxis->categories = $categorias_xAxis; |
---|
305 | |
---|
306 | $options->yAxis->title->text = 'Producción Trimestral'; |
---|
307 | $options->yAxis->allowDecimals = FALSE; |
---|
308 | |
---|
309 | // Tooltip. |
---|
310 | // Normally formatter is a function callback. For now we'll make it a string. |
---|
311 | // @todo whenever this is user defined (views config, etc) be sure to sanitize |
---|
312 | // this string before passing to highcharts_render(). |
---|
313 | $options->tooltip->formatter = "function() {return 'Producción en trimestre: <b>'+ this.point.y + ' ' + this.series.name + '</b>';}"; |
---|
314 | //$options->tooltip->formatter = "function() {return '<b>'+ this.series.name +'</b>: '+ this.point.y +' proyecto(s)';}"; |
---|
315 | |
---|
316 | // Plot options. |
---|
317 | $options->plotOptions->column = (object)array( |
---|
318 | 'allowPointSelect' => TRUE, |
---|
319 | 'cursor' => 'pointer', |
---|
320 | 'dataLabels' => array( |
---|
321 | 'enabled' => FALSE, |
---|
322 | ), |
---|
323 | 'showInLegend' => TRUE, |
---|
324 | ); |
---|
325 | |
---|
326 | // Series. |
---|
327 | $options->series = array(); |
---|
328 | |
---|
329 | foreach($datos_grafica as $valor_opc_i){ |
---|
330 | $series = new StdClass(); |
---|
331 | if($area_selecc == 'Todas'){ |
---|
332 | $series->name = $valor_opc_i['nombre_opcion_unidadmedida'].'<br>'.$valor_opc_i['nombre_opcion_politica']; |
---|
333 | }else{ |
---|
334 | $series->name = $valor_opc_i['nombre_opcion_unidadmedida']; |
---|
335 | } |
---|
336 | $series->data = array(); |
---|
337 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][0]*1.0); |
---|
338 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][1]*1.0); |
---|
339 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][2]*1.0); |
---|
340 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][3]*1.0); |
---|
341 | $options->series[] = $series; |
---|
342 | } |
---|
343 | |
---|
344 | // Diable credits. |
---|
345 | $options->credits->enabled = FALSE; |
---|
346 | |
---|
347 | return $options; |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | /** |
---|
352 | * Column-basic highcharts options object. |
---|
353 | * |
---|
354 | * @see highcharts_render() |
---|
355 | */ |
---|
356 | function grafica_basica_variaslineas_opciones($datos_grafica, $area_selecc, $anho_selecc) { |
---|
357 | $options = new stdClass(); |
---|
358 | |
---|
359 | // Chart. |
---|
360 | $options->chart = (object)array( |
---|
361 | 'renderTo' => 'container', |
---|
362 | 'plotBackgroundColor' => NULL, |
---|
363 | 'plotBorderWidth' => NULL, |
---|
364 | 'plotShadow' => FALSE, |
---|
365 | ); |
---|
366 | |
---|
367 | $options->chart->type = 'line'; |
---|
368 | |
---|
369 | // Title. |
---|
370 | $options->title->text = 'Producción del año '.$anho_selecc.' en <b>'.$area_selecc.'</b>'; |
---|
371 | $options->subtitle->text = 'Ãreas Estratégicas del Ministerio SIPP'; |
---|
372 | |
---|
373 | $categorias_xAxis = array(); |
---|
374 | $categorias_xAxis[] = '1er Trimestre'; |
---|
375 | $categorias_xAxis[] = '2do Trimestre'; |
---|
376 | $categorias_xAxis[] = '3er Trimestre'; |
---|
377 | $categorias_xAxis[] = '4to Trimestre'; |
---|
378 | $options->xAxis->categories = $categorias_xAxis; |
---|
379 | |
---|
380 | $options->yAxis->title->text = 'Producción'; |
---|
381 | $options->yAxis->allowDecimals = FALSE; |
---|
382 | $options->yAxis->min = 0; |
---|
383 | |
---|
384 | // Tooltip. |
---|
385 | // Normally formatter is a function callback. For now we'll make it a string. |
---|
386 | // @todo whenever this is user defined (views config, etc) be sure to sanitize |
---|
387 | // this string before passing to highcharts_render(). |
---|
388 | $options->tooltip->formatter = "function() {return 'Producción en trimestre: <b>'+ this.point.y + ' ' + this.series.name + '</b>';}"; |
---|
389 | |
---|
390 | // Plot options. |
---|
391 | $options->plotOptions->column = (object)array( |
---|
392 | 'allowPointSelect' => TRUE, |
---|
393 | 'cursor' => 'pointer', |
---|
394 | 'dataLabels' => array( |
---|
395 | 'enabled' => FALSE, |
---|
396 | ), |
---|
397 | 'showInLegend' => TRUE, |
---|
398 | ); |
---|
399 | |
---|
400 | // Series. |
---|
401 | $options->series = array(); |
---|
402 | |
---|
403 | foreach($datos_grafica as $valor_opc_i){ |
---|
404 | $series = new StdClass(); |
---|
405 | if($area_selecc == 'Todas'){ |
---|
406 | $series->name = $valor_opc_i['nombre_opcion_unidadmedida'].'<br>'.$valor_opc_i['nombre_opcion_politica']; |
---|
407 | }else{ |
---|
408 | $series->name = $valor_opc_i['nombre_opcion_unidadmedida']; |
---|
409 | } |
---|
410 | $series->data = array(); |
---|
411 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][0]*1.0); |
---|
412 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][1]*1.0); |
---|
413 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][2]*1.0); |
---|
414 | $series->data[] = array($valor_opc_i['cantidad_trimestres'][3]*1.0); |
---|
415 | $options->series[] = $series; |
---|
416 | } |
---|
417 | |
---|
418 | // Diable credits. |
---|
419 | $options->credits->enabled = FALSE; |
---|
420 | |
---|
421 | return $options; |
---|
422 | } |
---|
423 | |
---|
424 | //************************************************************************************************************************* |
---|
425 | |
---|
426 | |
---|
427 | function generar_grafica_historicos($datos_cargados) { |
---|
428 | |
---|
429 | $page_content = ''; |
---|
430 | |
---|
431 | $path = libraries_get_path('Highcharts-3.0.1'); |
---|
432 | |
---|
433 | $options = grafica_basica_variascolumnas_opciones_historico($datos_cargados); |
---|
434 | |
---|
435 | if (is_object($options)) { |
---|
436 | // Render the chart options object, and retrieve the chart id. |
---|
437 | highcharts_render($options); |
---|
438 | // Define required and optional chart container attributes. |
---|
439 | $attributes = array( |
---|
440 | // Required chart id passed by reference. |
---|
441 | 'id' => $options->chart->renderTo, |
---|
442 | // Optionally add styles or any other valid attribute. |
---|
443 | 'style' => 'height: 400px;width: 800px;' |
---|
444 | ); |
---|
445 | |
---|
446 | $page_content .= theme_highcharts_chart($options->chart->renderTo); |
---|
447 | $page_content .= theme('highcharts_chart', $attributes); |
---|
448 | } |
---|
449 | |
---|
450 | $path_biblioteca_Highcharts = libraries_get_path('Highcharts-3.0.1'); |
---|
451 | drupal_add_js($path_biblioteca_Highcharts . '/js/modules/exporting.js'); |
---|
452 | |
---|
453 | return $page_content; |
---|
454 | } |
---|
455 | |
---|
456 | |
---|
457 | /** |
---|
458 | * Column-basic highcharts options object. |
---|
459 | * |
---|
460 | * @see highcharts_render() |
---|
461 | */ |
---|
462 | function grafica_basica_variascolumnas_opciones_historico($datos_cargados) { |
---|
463 | $options = new stdClass(); |
---|
464 | |
---|
465 | // Chart. |
---|
466 | $options->chart = (object)array( |
---|
467 | 'renderTo' => 'container', |
---|
468 | 'plotBackgroundColor' => NULL, |
---|
469 | 'plotBorderWidth' => NULL, |
---|
470 | 'plotShadow' => FALSE, |
---|
471 | ); |
---|
472 | |
---|
473 | $options->chart->type = 'column'; |
---|
474 | |
---|
475 | // Title. |
---|
476 | $area_selecc = $datos_cargados['param']['area']; |
---|
477 | $options->title->text = '<b>Historico de la Gestión en <i>'.$area_selecc.'</i></b>'; |
---|
478 | $options->subtitle->text = 'Ãreas Estratégicas del Ministerio SIPP'; |
---|
479 | |
---|
480 | $categorias_xAxis = array(); |
---|
481 | for($it_anho = $datos_cargados['anho_min_historico']; $it_anho <= $datos_cargados['param']['anho']; $it_anho++){ |
---|
482 | $categorias_xAxis[] = $it_anho; |
---|
483 | } |
---|
484 | |
---|
485 | $options->xAxis->categories = $categorias_xAxis; |
---|
486 | |
---|
487 | $options->yAxis->title->text = 'Producción Anual'; |
---|
488 | $options->yAxis->allowDecimals = FALSE; |
---|
489 | |
---|
490 | // Tooltip. |
---|
491 | // Normally formatter is a function callback. For now we'll make it a string. |
---|
492 | // @todo whenever this is user defined (views config, etc) be sure to sanitize |
---|
493 | // this string before passing to highcharts_render(). |
---|
494 | $options->tooltip->formatter = "function() {return 'Producción en trimestre: <b>'+ this.point.y + ' ' + this.series.name + '</b>';}"; |
---|
495 | |
---|
496 | // Plot options. |
---|
497 | $options->plotOptions->column = (object)array( |
---|
498 | 'allowPointSelect' => TRUE, |
---|
499 | 'cursor' => 'pointer', |
---|
500 | 'dataLabels' => array( |
---|
501 | 'enabled' => FALSE, |
---|
502 | ), |
---|
503 | 'showInLegend' => TRUE, |
---|
504 | ); |
---|
505 | |
---|
506 | // Series. |
---|
507 | $options->series = array(); |
---|
508 | |
---|
509 | foreach($datos_cargados['datos_anho_actual'] AS $id => $areas_unidadmedida){ |
---|
510 | $series = new StdClass(); |
---|
511 | if($area_selecc == 'Todas'){ |
---|
512 | $series->name = $areas_unidadmedida['nombre_opcion_unidadmedida'].'<br>'.$areas_unidadmedida['nombre_opcion_politica']; |
---|
513 | }else{ |
---|
514 | $series->name = $areas_unidadmedida['nombre_opcion_unidadmedida']; |
---|
515 | } |
---|
516 | $series->data = array(); |
---|
517 | |
---|
518 | for($it_anho = $datos_cargados['anho_min_historico']; $it_anho <= $datos_cargados['param']['anho']; $it_anho++){ |
---|
519 | $cantidad_producida = isset($datos_cargados['datos_historico'][$id][$it_anho])? $datos_cargados['datos_historico'][$id][$it_anho] : 0; |
---|
520 | $series->data[] = array($cantidad_producida*1.0); |
---|
521 | } |
---|
522 | $options->series[] = $series; |
---|
523 | |
---|
524 | } |
---|
525 | |
---|
526 | // Diable credits. |
---|
527 | $options->credits->enabled = FALSE; |
---|
528 | |
---|
529 | return $options; |
---|
530 | } |
---|