source: sipes/0.3-modules/reportes_sipes_views/reportes_sipes_views.module @ 22f13f7

stable
Last change on this file since 22f13f7 was 22f13f7, checked in by jpuentes <jpuentes@…>, 7 años ago

se modifico el path del hook menu reporte csv

  • Propiedad mode establecida a 100755
File size: 11.8 KB
Línea 
1<?php
2  /**
3  * Sistema Integral de Planificación y Presupuesto (SIPP)
4  * @file reportes_sipes_views.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-04-25 // (a&#241;o-mes-dia)
24  * @version 0.1 // (0.1)
25  *
26  */
27
28/*
29 * Implementation of hook_menu()
30 */
31function reportes_sipes_views_menu() {
32  $items = array();
33 
34  $items['reportes_sipes_views'] = array(
35    'title' => t('Reportes'),
36    'page callback' => 'reporte_sipes_views_page',
37    'access callback' => true,
38    'type' => MENU_CALLBACK,
39  );
40  $items['reportes_sipes_views_csv'] = array(
41    'title' => t('Reportes'),
42    'page callback' => 'reporte_sipes_views_page_csv',
43    'access callback' => true,
44    'type' => MENU_CALLBACK,
45  );
46
47 
48  return $items;
49} // function reportes_sipp_menu
50
51
52/**
53 * Implementation of hook_views_api().
54 */
55function reportes_sipes_views_views_api() {
56  return array(
57    'api' => '2.0',
58    'path' => drupal_get_path('module', 'reportes_sipp') . '/views',
59  );
60}
61
62/**
63 * Genera el reporte
64 */
65function reporte_sipes_views_page() {
66  if (!user_access('admin planificador')) return false;
67
68  $author = variable_get('site_name', '');
69  module_load_include('module', 'libraries', 'libraries');
70  $path = libraries_get_path('tcpdf');
71
72  if (($path) && (file_exists($path . '/config/lang/spa.php'))) {
73    require_once($path . '/config/lang/spa.php');
74  }
75  else {
76    drupal_set_message(t('TCPDF library not found!'), 'error');
77    return FALSE;
78  }
79
80  if (($path) && (file_exists($path . '/tcpdf.php'))) {
81    require_once($path . '/tcpdf.php');
82  }
83  else {
84    drupal_set_message(t('TCPDF library not found!'), 'error');
85    return FALSE;
86  }
87
88  // create new PDF documentsite_slogan
89  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
90  ob_clean();
91  // set document information
92  $pdf->SetCreator($author);
93  $pdf->SetAuthor($author);
94  // set default header data
95  //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
96  // set header and footer fonts
97  $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
98  $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
99  // set default monospaced font
100  $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
101  //set margins
102  $pdf->SetMargins(10, 17, 10);
103  $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
104  $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
105  //set auto page breaks
106  $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
107  //set image scale factor
108  $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
109  //set some language-dependent strings
110  $pdf->setLanguageArray($l);
111  // ---------------------------------------------------------
112  // set font
113  //$pdf->SetFont('dejavusans', '', 8);
114  $pdf->SetFont('times', '', 8);
115  // add a page
116  //$pdf->AddPage();
117
118  if ($pdf) {
119    $title = t('Reporte Anual POAN @year', array('@year' => $year));
120    $pdf->SetTitle($title);
121    $pdf->SetSubject($title);
122  }
123
124  //$view_id = 'reporte_poan_anual';
125  $view_id = 'reporte_poan_anual1';
126  $view = views_get_view($view_id);
127  $display_id = 'block_1';
128//  $display_id = 'default';
129
130  $view->set_display($display_id);
131  $view->override_path = $_GET['q'];
132  $view->pre_execute();
133  $view->execute();
134  $view->post_execute();
135  // $output = $view->render();
136
137
138
139  $year = variable_get('proyectos_operativos_anho_creacion', 0);
140  $header = '<table border="1" cellpadding="4" style="text-align: justify">';
141  $header .= '<tr>';
142  $header .= '<th rowspan = "2" style="width: 5%; text-align: center">' . t('Cod.') . '</th>';
143  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Nombre del Proyecto.') . '</th>';
144  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Objetivo Específico del Proyecto') . '</th>';
145  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Ejecutor') . '</th>';
146  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Localización') . '</th>';
147  $header .= '<th colspan = "2" style="width: 20%; text-align: center">' . t('Resultados esperados del Proyecto @year', array('@year' => $year)) . '</th>';
148  $header .= '<th colspan = "3" style="width: 35%; text-align: center">' . t('Asignación Presupuestaria @year (En bolívares)', array('@year' => $year)) . '</th>';
149  $header .= '</tr>';
150  $header .= '<tr>';
151  $header .= '<th style="text-align: center">' . t('Bien o Servicio') . '</th>';
152  $header .= '<th style="text-align: center">' . t('Cantidad/Meta') . '</th>';
153  $header .= '<th style="text-align: center">' . t('Fuente') . '</th>';
154  $header .= '<th style="text-align: center">' . t('Monto') . '</th>';
155  $header .= '<th style="text-align: center">' . t('Total') . '</th>';
156  $header .= '</tr>';
157  $plan_nombre = t('<strong style="font-size: 50px;">PLAN OPERATIVO ANUAL NACIONAL @anho (POAN @anho)</strong>', array('@anho' => $year));
158  $begin = '';
159  $nid = 0;
160  foreach ($view->result as $key => $values) {
161    if (!in_array($values->nid, $nids)) {
162      $output = '';
163      if ($values->node_ente_planificador_hierarchical_nid != $nid) {
164        $objetivo = implode('<br>', $values->views_php_18[0]);
165        $output .= $begin . '<p></p><p>' . $plan_nombre . '<br>';
166        $output .= t('<strong style="font-size: 50px; ">ORGANISMO RESPONSABLE</strong>: <span style="font-size: 50px">@ente</span>', array('@ente' => $values->node_ente_planificador_hierarchical_title)) . '</p>';
167        $output .= '<p><strong style="font-size: 50px">' . t('OBJETIVO HISTORICO:') . '</strong><br><span style="font-size: 50px;">' . $objetivo . '</span></p>';
168        $output .= $header;
169        $begin = '</table><br>';
170      }
171
172      $output .= '<tr>';
173      //field codigo
174      $output .= '<td>' . $values->node_title . '</td>';
175      $output .= '<td>' . $values->node_data_field_proyecto_poan_field_proyecto_titulo_value . '</td>';
176      $output .= '<td>' . $values->node_data_field_proyecto_poan_field_proyecto_og_value . '</td>';
177      $output .= '<td>' . $values->node_node_data_field_proyecto_ente_title . '</td>';
178      $output .= '<td>' . implode('<hr><br>', $values->views_php_6) . '</td>';
179      $output .= '<td>' . $values->node_data_field_proyecto_poan_field_proyecto_descripcion_bie . '</td>';
180
181      $term = taxonomy_get_term($values->node_data_field_proyecto_poan_field_proyecto_unidadm_value);
182      $output .= '<td>' . $values->views_php_17 . ' ' . $term->name . '</td>';
183
184      $output .= '<td>' . implode('<hr><br>', $values->views_php_10['fuentes']) . '</td>';
185      $output .= '<td>' . implode('<hr><br>', $values->views_php_10['valores']) . '</td>';
186      $output .= '<td align="center">' . $values->views_php_10['total'] . '</td>';
187      $output .= '</tr>';
188      $output .= $begin;
189
190      $pdf->AddPage('L', 'Legal');
191      $pdf->writeHTML($output, true, false, true, false, '');
192      $pdf->lastPage();
193    }
194    $nids[] = $values->nid;
195  }
196
197  if ($pdf) {
198    header('Content-type: text/plain');
199    $name = 'reporte_anual_poan_' . $year . '.pdf';
200    header('Content-Disposition: attachment; filename="' . $name . '"');
201    print $pdf->Output($name, 'I');
202  }
203
204  return $output;
205}
206
207/**
208 * Genera el reporte CSV
209 */
210function reporte_sipes_views_page_csv() {
211  if (!user_access('admin planificador')) return false;
212
213  $content = '';
214  $view_id = 'reporte_poan_anual1';
215  $view = views_get_view($view_id);
216  $display_id = 'block_1';
217  $view->set_display($display_id);
218  $view->override_path = $_GET['q'];
219  $view->pre_execute();
220  $view->execute();
221  $year = variable_get('proyectos_operativos_anho_creacion', 0);
222  // $output = $view->render();
223  $header = '"' . t('Cod.') . '"'  ."\t";
224  $header .= '"' . t('Nombre del Proyecto') . '"'  ."\t";
225  $header .= '"' . t('Objetivo Específico del Proyecto') . '"'  ."\t";
226  $header .= '"' . t('Ejecutor') . '"'  ."\t";
227  $header .= '"' . t('Localización') . '"' ."\t";
228  $header .= '"' . t('Resultado de las Acciones Especificas del Proyecto @year', array('@year' => $year)) . '"' ."\t";
229  $header .="\t";
230  $header .=  '"' . t('Asignación Presupuestaria @year (En Millones de Bolivares)', array('@year' => $year)) . '"' ."\t";
231  $header .="\t";
232  $header .="\t";
233  $header.= "\n";
234
235  $header .="\t";
236  $header .="\t";
237  $header .="\t";
238  $header .="\t";
239  $header .="\t";
240  $header .= '"' . t('Bien o Servicio') . '"' ."\t";
241  $header .= '"' . t('Cantidad/Meta') . '"' ."\t";
242  $header .= '"' . t('Fuente') . '"' ."\t";
243  $header .= '"' . t('Monto') . '"' ."\t";
244  $header .= '"' . t('Total') . '"' ."\t";
245  $html = '';
246  $nid = 0;
247  $output = '';
248  $nids = array();
249  $year = variable_get('proyectos_operativos_anho_creacion', 0);
250
251  foreach ($view->result as $key => $values) {
252    if (!in_array($values->nid, $nids)) {
253      $content = '';
254      if ($values->node_ente_planificador_hierarchical_nid != $nid) {
255        $node = node_load($values->node_ente_planificador_hierarchical_nid);
256        $nid = $node->nid;
257
258        $header_organismo = '"'.  t('PLAN OPERATIVO ANUAL NACIONAL @anho (POAN @anho)', array('@anho' => $year)) . '"' . "\n";
259
260        $header_organismo .= '"'. t('ORGANISMO RESPONSABLE: @ente', array('@ente' => $node->title)) . '"' . "\n";
261        $obj = "\n" . implode("\n", $values->views_php_18[0]);
262        $header_organismo .= '"'. t('OBJETIVO HISTORICO: @obj', array('@obj' => $obj)) . '"' . "\n";
263        $output .= $header_organismo . $header . "\n";
264      }
265      $content = '"' . trim($values->node_title) . '"' . "\t";
266      $content .= '"' . trim($values->node_data_field_proyecto_poan_field_proyecto_titulo_value) . '"' . "\t";
267      $content .= '"' . trim($values->node_data_field_proyecto_poan_field_proyecto_og_value) . '"' . "\t";
268      $content .= '"' . trim($values->node_node_data_field_proyecto_ente_title) . '"' . "\t";
269
270      $content .= '"' . implode("\n", $values->views_php_6) . '"' . "\t";
271
272      $content .= '"' . trim(str_replace('"', '', $values->node_data_field_proyecto_poan_field_proyecto_descripcion_bie)) . '"' . "\t";
273
274      $output .= $content;
275
276      $term = taxonomy_get_term($values->node_data_field_proyecto_poan_field_proyecto_unidadm_value);
277
278      $content = '"' . $values->views_php_17 . ' ' . check_plain($term->name) . '"' . "\t";
279      $content .= '"' . implode("\n", $values->views_php_10['fuentes']) . '"' . "\t";
280      $content .= '"' . implode("\n", $values->views_php_10['valores']) . '"' . "\t";
281      $content .= '"' . $values->views_php_10['total'] .'"';
282      $output .= $content . "\n";
283
284
285    }
286    $nids[] = $values->nid;
287  }
288  $Name = 'SIPES-Reporte-POAN-' . $year . '.csv';
289  header('Expires: 0');
290  header('Cache-control: private');
291  header('Content-Type: application/x-octet-stream'); // Archivo de Excel
292  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
293  header('Content-Description: File Transfer');
294  header('Last-Modified: '.date('D, d M Y H:i:s'));
295  header('Content-Disposition: attachment; filename="'.$Name.'"');
296  header("Content-Transfer-Encoding: binary");
297  print $output;
298}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.