t('Reportes'),
'page callback' => 'reporte_sipes_views_page',
'access callback' => true,
'type' => MENU_CALLBACK,
);
$items['reportes_sipes_views_csv'] = array(
'title' => t('Reportes'),
'page callback' => 'reporte_sipes_views_page_csv',
'access callback' => true,
'type' => MENU_CALLBACK,
);
return $items;
} // function reportes_sipp_menu
/**
* Implementation of hook_views_api().
*/
function reportes_sipes_views_views_api() {
return array(
'api' => '2.0',
'path' => drupal_get_path('module', 'reportes_sipp') . '/views',
);
}
/**
* Genera el reporte
*/
function reporte_sipes_views_page() {
if (!user_access('admin planificador')) return false;
$author = variable_get('site_name', '');
module_load_include('module', 'libraries', 'libraries');
$path = libraries_get_path('tcpdf');
if (($path) && (file_exists($path . '/config/lang/spa.php'))) {
require_once($path . '/config/lang/spa.php');
}
else {
drupal_set_message(t('TCPDF library not found!'), 'error');
return FALSE;
}
if (($path) && (file_exists($path . '/tcpdf.php'))) {
require_once($path . '/tcpdf.php');
}
else {
drupal_set_message(t('TCPDF library not found!'), 'error');
return FALSE;
}
// create new PDF documentsite_slogan
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
ob_clean();
// set document information
$pdf->SetCreator($author);
$pdf->SetAuthor($author);
// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(10, 17, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
//$pdf->SetFont('dejavusans', '', 8);
$pdf->SetFont('times', '', 8);
// add a page
//$pdf->AddPage();
if ($pdf) {
$title = t('Reporte Anual POAN @year', array('@year' => $year));
$pdf->SetTitle($title);
$pdf->SetSubject($title);
}
//$view_id = 'reporte_poan_anual';
$view_id = 'reporte_poan_anual1';
$view = views_get_view($view_id);
$display_id = 'block_1';
// $display_id = 'default';
$view->set_display($display_id);
$view->override_path = $_GET['q'];
$view->pre_execute();
$view->execute();
$view->post_execute();
// $output = $view->render();
$year = variable_get('proyectos_operativos_anho_creacion', 0);
$header = '
';
$header .= '';
$header .= '' . t('Cod.') . ' | ';
$header .= '' . t('Nombre del Proyecto.') . ' | ';
$header .= '' . t('Objetivo Específico del Proyecto') . ' | ';
$header .= '' . t('Ejecutor') . ' | ';
$header .= '' . t('Localización') . ' | ';
$header .= '' . t('Resultados esperados del Proyecto @year', array('@year' => $year)) . ' | ';
$header .= '' . t('Asignación Presupuestaria @year (En bolívares)', array('@year' => $year)) . ' | ';
$header .= '
';
$header .= '';
$header .= '' . t('Bien o Servicio') . ' | ';
$header .= '' . t('Cantidad/Meta') . ' | ';
$header .= '' . t('Fuente') . ' | ';
$header .= '' . t('Monto') . ' | ';
$header .= '' . t('Total') . ' | ';
$header .= '
';
$plan_nombre = t('PLAN OPERATIVO ANUAL NACIONAL @anho (POAN @anho)', array('@anho' => $year));
$begin = '';
$nid = 0;
foreach ($view->result as $key => $values) {
if (!in_array($values->nid, $nids)) {
$output = '';
if ($values->node_ente_planificador_hierarchical_nid != $nid) {
$objetivo = implode('
', $values->views_php_18[0]);
$output .= $begin . '' . $plan_nombre . '
';
$output .= t('ORGANISMO RESPONSABLE: @ente', array('@ente' => $values->node_ente_planificador_hierarchical_title)) . '
';
$output .= '' . t('OBJETIVO HISTORICO:') . '
' . $objetivo . '
';
$output .= $header;
$begin = '
';
}
$output .= '';
//field codigo
$output .= '' . $values->node_title . ' | ';
$output .= '' . $values->node_data_field_proyecto_poan_field_proyecto_titulo_value . ' | ';
$output .= '' . $values->node_data_field_proyecto_poan_field_proyecto_og_value . ' | ';
$output .= '' . $values->node_node_data_field_proyecto_ente_title . ' | ';
$output .= '' . implode('
', $values->views_php_6) . ' | ';
$output .= '' . $values->node_data_field_proyecto_poan_field_proyecto_descripcion_bie . ' | ';
$term = taxonomy_get_term($values->node_data_field_proyecto_poan_field_proyecto_unidadm_value);
$output .= '' . $values->views_php_17 . ' ' . $term->name . ' | ';
$output .= '' . implode('
', $values->views_php_10['fuentes']) . ' | ';
$output .= '' . implode('
', $values->views_php_10['valores']) . ' | ';
$output .= '' . $values->views_php_10['total'] . ' | ';
$output .= '
';
$output .= $begin;
$pdf->AddPage('L', 'Legal');
$pdf->writeHTML($output, true, false, true, false, '');
$pdf->lastPage();
}
$nids[] = $values->nid;
}
if ($pdf) {
header('Content-type: text/plain');
$name = 'reporte_anual_poan_' . $year . '.pdf';
header('Content-Disposition: attachment; filename="' . $name . '"');
print $pdf->Output($name, 'I');
}
return $output;
}
/**
* Genera el reporte CSV
*/
function reporte_sipes_views_page_csv() {
if (!user_access('admin planificador')) return false;
$content = '';
$view_id = 'reporte_poan_anual1';
$view = views_get_view($view_id);
$display_id = 'block_1';
$view->set_display($display_id);
$view->override_path = $_GET['q'];
$view->pre_execute();
$view->execute();
$year = variable_get('proyectos_operativos_anho_creacion', 0);
// $output = $view->render();
$header = '"' . t('Cod.') . '"' ."\t";
$header .= '"' . t('Nombre del Proyecto') . '"' ."\t";
$header .= '"' . t('Objetivo Específico del Proyecto') . '"' ."\t";
$header .= '"' . t('Ejecutor') . '"' ."\t";
$header .= '"' . t('Localización') . '"' ."\t";
$header .= '"' . t('Resultado de las Acciones Especificas del Proyecto @year', array('@year' => $year)) . '"' ."\t";
$header .="\t";
$header .= '"' . t('Asignación Presupuestaria @year (En Millones de Bolivares)', array('@year' => $year)) . '"' ."\t";
$header .="\t";
$header .="\t";
$header.= "\n";
$header .="\t";
$header .="\t";
$header .="\t";
$header .="\t";
$header .="\t";
$header .= '"' . t('Bien o Servicio') . '"' ."\t";
$header .= '"' . t('Cantidad/Meta') . '"' ."\t";
$header .= '"' . t('Fuente') . '"' ."\t";
$header .= '"' . t('Monto') . '"' ."\t";
$header .= '"' . t('Total') . '"' ."\t";
$html = '';
$nid = 0;
$output = '';
$nids = array();
$year = variable_get('proyectos_operativos_anho_creacion', 0);
foreach ($view->result as $key => $values) {
if (!in_array($values->nid, $nids)) {
$content = '';
if ($values->node_ente_planificador_hierarchical_nid != $nid) {
$node = node_load($values->node_ente_planificador_hierarchical_nid);
$nid = $node->nid;
$header_organismo = '"'. t('PLAN OPERATIVO ANUAL NACIONAL @anho (POAN @anho)', array('@anho' => $year)) . '"' . "\n";
$header_organismo .= '"'. t('ORGANISMO RESPONSABLE: @ente', array('@ente' => $node->title)) . '"' . "\n";
$obj = "\n" . implode("\n", $values->views_php_18[0]);
$header_organismo .= '"'. t('OBJETIVO HISTORICO: @obj', array('@obj' => $obj)) . '"' . "\n";
$output .= $header_organismo . $header . "\n";
}
$content = '"' . trim($values->node_title) . '"' . "\t";
$content .= '"' . trim($values->node_data_field_proyecto_poan_field_proyecto_titulo_value) . '"' . "\t";
$content .= '"' . trim($values->node_data_field_proyecto_poan_field_proyecto_og_value) . '"' . "\t";
$content .= '"' . trim($values->node_node_data_field_proyecto_ente_title) . '"' . "\t";
$content .= '"' . implode("\n", $values->views_php_6) . '"' . "\t";
$content .= '"' . trim(str_replace('"', '', $values->node_data_field_proyecto_poan_field_proyecto_descripcion_bie)) . '"' . "\t";
$output .= $content;
$term = taxonomy_get_term($values->node_data_field_proyecto_poan_field_proyecto_unidadm_value);
$content = '"' . $values->views_php_17 . ' ' . check_plain($term->name) . '"' . "\t";
$content .= '"' . implode("\n", $values->views_php_10['fuentes']) . '"' . "\t";
$content .= '"' . implode("\n", $values->views_php_10['valores']) . '"' . "\t";
$content .= '"' . $values->views_php_10['total'] .'"';
$output .= $content . "\n";
}
$nids[] = $values->nid;
}
$Name = 'SIPES-Reporte-POAN-' . $year . '.csv';
header('Expires: 0');
header('Cache-control: private');
header('Content-Type: application/x-octet-stream'); // Archivo de Excel
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Description: File Transfer');
header('Last-Modified: '.date('D, d M Y H:i:s'));
header('Content-Disposition: attachment; filename="'.$Name.'"');
header("Content-Transfer-Encoding: binary");
print $output;
}