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