source: sipes/0.3-modules/reportes_sipes_views/reportes_sipes_views.module @ 9b13782

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

se oculto el paginador y los border superiores e inferiores

  • Propiedad mode establecida a 100755
File size: 11.9 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  // remove default header/footer
119  $pdf->setPrintHeader(false);
120  $pdf->setPrintFooter(false);
121
122  if ($pdf) {
123    $title = t('Reporte Anual POAN @year', array('@year' => $year));
124    $pdf->SetTitle($title);
125    $pdf->SetSubject($title);
126  }
127
128  //$view_id = 'reporte_poan_anual';
129  $view_id = 'reporte_poan_anual1';
130  $view = views_get_view($view_id);
131  $display_id = 'block_1';
132//  $display_id = 'default';
133
134  $view->set_display($display_id);
135  $view->override_path = $_GET['q'];
136  $view->pre_execute();
137  $view->execute();
138  $view->post_execute();
139  // $output = $view->render();
140
141
142
143  $year = variable_get('proyectos_operativos_anho_creacion', 0);
144  $header = '<table border="1" cellpadding="4" style="text-align: justify">';
145  $header .= '<tr>';
146  $header .= '<th rowspan = "2" style="width: 5%; text-align: center">' . t('Cod.') . '</th>';
147  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Nombre del Proyecto.') . '</th>';
148  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Objetivo Específico del Proyecto') . '</th>';
149  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Ejecutor') . '</th>';
150  $header .= '<th rowspan = "2" style="width: 10%; text-align: center">' . t('Localización') . '</th>';
151  $header .= '<th colspan = "2" style="width: 20%; text-align: center">' . t('Resultados esperados del Proyecto @year', array('@year' => $year)) . '</th>';
152  $header .= '<th colspan = "3" style="width: 35%; text-align: center">' . t('Asignación Presupuestaria @year (En bolívares)', array('@year' => $year)) . '</th>';
153  $header .= '</tr>';
154  $header .= '<tr>';
155  $header .= '<th style="text-align: center">' . t('Bien o Servicio') . '</th>';
156  $header .= '<th style="text-align: center">' . t('Cantidad/Meta') . '</th>';
157  $header .= '<th style="text-align: center">' . t('Fuente') . '</th>';
158  $header .= '<th style="text-align: center">' . t('Monto') . '</th>';
159  $header .= '<th style="text-align: center">' . t('Total') . '</th>';
160  $header .= '</tr>';
161  $plan_nombre = t('<strong style="font-size: 50px;">PLAN OPERATIVO ANUAL NACIONAL @anho (POAN @anho)</strong>', array('@anho' => $year));
162  $begin = '';
163  $nid = 0;
164  foreach ($view->result as $key => $values) {
165    if (!in_array($values->nid, $nids)) {
166      $output = '';
167      if ($values->node_ente_planificador_hierarchical_nid != $nid) {
168        $objetivo = implode('<br>', $values->views_php_18[0]);
169        $output .= $begin . '<p></p><p>' . $plan_nombre . '<br>';
170        $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>';
171        $output .= '<p><strong style="font-size: 50px">' . t('OBJETIVO HISTORICO:') . '</strong><br><span style="font-size: 50px;">' . $objetivo . '</span></p>';
172        $output .= $header;
173        $begin = '</table><br>';
174      }
175
176      $output .= '<tr>';
177      //field codigo
178      $output .= '<td>' . $values->node_title . '</td>';
179      $output .= '<td>' . $values->node_data_field_proyecto_poan_field_proyecto_titulo_value . '</td>';
180      $output .= '<td>' . $values->node_data_field_proyecto_poan_field_proyecto_og_value . '</td>';
181      $output .= '<td>' . $values->node_node_data_field_proyecto_ente_title . '</td>';
182      $output .= '<td>' . implode('<hr><br>', $values->views_php_6) . '</td>';
183      $output .= '<td>' . $values->node_data_field_proyecto_poan_field_proyecto_descripcion_bie . '</td>';
184
185      $term = taxonomy_get_term($values->node_data_field_proyecto_poan_field_proyecto_unidadm_value);
186      $output .= '<td>' . $values->views_php_17 . ' ' . $term->name . '</td>';
187
188      $output .= '<td>' . implode('<hr><br>', $values->views_php_10['fuentes']) . '</td>';
189      $output .= '<td>' . implode('<hr><br>', $values->views_php_10['valores']) . '</td>';
190      $output .= '<td align="center">' . $values->views_php_10['total'] . '</td>';
191      $output .= '</tr>';
192      $output .= $begin;
193
194      $pdf->AddPage('L', 'Legal');
195      $pdf->writeHTML($output, true, false, true, false, '');
196      $pdf->lastPage();
197    }
198    $nids[] = $values->nid;
199  }
200
201  if ($pdf) {
202    header('Content-type: text/plain');
203    $name = 'reporte_anual_poan_' . $year . '.pdf';
204    header('Content-Disposition: attachment; filename="' . $name . '"');
205    print $pdf->Output($name, 'I');
206  }
207
208  return $output;
209}
210
211/**
212 * Genera el reporte CSV
213 */
214function reporte_sipes_views_page_csv() {
215  if (!user_access('admin planificador')) return false;
216
217  $content = '';
218  $view_id = 'reporte_poan_anual1';
219  $view = views_get_view($view_id);
220  $display_id = 'block_1';
221  $view->set_display($display_id);
222  $view->override_path = $_GET['q'];
223  $view->pre_execute();
224  $view->execute();
225  $year = variable_get('proyectos_operativos_anho_creacion', 0);
226  // $output = $view->render();
227  $header = '"' . t('Cod.') . '"'  ."\t";
228  $header .= '"' . t('Nombre del Proyecto') . '"'  ."\t";
229  $header .= '"' . t('Objetivo Específico del Proyecto') . '"'  ."\t";
230  $header .= '"' . t('Ejecutor') . '"'  ."\t";
231  $header .= '"' . t('Localización') . '"' ."\t";
232  $header .= '"' . t('Resultado de las Acciones Especificas del Proyecto @year', array('@year' => $year)) . '"' ."\t";
233  $header .="\t";
234  $header .=  '"' . t('Asignación Presupuestaria @year (En Millones de Bolivares)', array('@year' => $year)) . '"' ."\t";
235  $header .="\t";
236  $header .="\t";
237  $header.= "\n";
238
239  $header .="\t";
240  $header .="\t";
241  $header .="\t";
242  $header .="\t";
243  $header .="\t";
244  $header .= '"' . t('Bien o Servicio') . '"' ."\t";
245  $header .= '"' . t('Cantidad/Meta') . '"' ."\t";
246  $header .= '"' . t('Fuente') . '"' ."\t";
247  $header .= '"' . t('Monto') . '"' ."\t";
248  $header .= '"' . t('Total') . '"' ."\t";
249  $html = '';
250  $nid = 0;
251  $output = '';
252  $nids = array();
253  $year = variable_get('proyectos_operativos_anho_creacion', 0);
254
255  foreach ($view->result as $key => $values) {
256    if (!in_array($values->nid, $nids)) {
257      $content = '';
258      if ($values->node_ente_planificador_hierarchical_nid != $nid) {
259        $node = node_load($values->node_ente_planificador_hierarchical_nid);
260        $nid = $node->nid;
261
262        $header_organismo = '"'.  t('PLAN OPERATIVO ANUAL NACIONAL @anho (POAN @anho)', array('@anho' => $year)) . '"' . "\n";
263
264        $header_organismo .= '"'. t('ORGANISMO RESPONSABLE: @ente', array('@ente' => $node->title)) . '"' . "\n";
265        $obj = "\n" . implode("\n", $values->views_php_18[0]);
266        $header_organismo .= '"'. t('OBJETIVO HISTORICO: @obj', array('@obj' => $obj)) . '"' . "\n";
267        $output .= $header_organismo . $header . "\n";
268      }
269      $content = '"' . trim($values->node_title) . '"' . "\t";
270      $content .= '"' . trim($values->node_data_field_proyecto_poan_field_proyecto_titulo_value) . '"' . "\t";
271      $content .= '"' . trim($values->node_data_field_proyecto_poan_field_proyecto_og_value) . '"' . "\t";
272      $content .= '"' . trim($values->node_node_data_field_proyecto_ente_title) . '"' . "\t";
273
274      $content .= '"' . implode("\n", $values->views_php_6) . '"' . "\t";
275
276      $content .= '"' . trim(str_replace('"', '', $values->node_data_field_proyecto_poan_field_proyecto_descripcion_bie)) . '"' . "\t";
277
278      $output .= $content;
279
280      $term = taxonomy_get_term($values->node_data_field_proyecto_poan_field_proyecto_unidadm_value);
281
282      $content = '"' . $values->views_php_17 . ' ' . check_plain($term->name) . '"' . "\t";
283      $content .= '"' . implode("\n", $values->views_php_10['fuentes']) . '"' . "\t";
284      $content .= '"' . implode("\n", $values->views_php_10['valores']) . '"' . "\t";
285      $content .= '"' . $values->views_php_10['total'] .'"';
286      $output .= $content . "\n";
287
288
289    }
290    $nids[] = $values->nid;
291  }
292  $Name = 'SIPES-Reporte-POAN-' . $year . '.csv';
293  header('Expires: 0');
294  header('Cache-control: private');
295  header('Content-Type: application/x-octet-stream'); // Archivo de Excel
296  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
297  header('Content-Description: File Transfer');
298  header('Last-Modified: '.date('D, d M Y H:i:s'));
299  header('Content-Disposition: attachment; filename="'.$Name.'"');
300  header("Content-Transfer-Encoding: binary");
301  print $output;
302}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.