';
$output .= drupal_get_form('consulta_matriz_de_procesos_reporte_trimestral_form');
$output .= '
';
//****************************************************************************
$trimestre_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['trimestre']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['trimestre'] : 0;
$trimestres_disponibles = array(t('1er Trimestre'), t('2do Trimestre'), t('3er Trimestre'), t('4to Trimestre'));
$trimestre_selecc = isset($trimestres_disponibles[$trimestre_seleccionado_para_reporte])? $trimestres_disponibles[$trimestre_seleccionado_para_reporte] : 'Todos';
$ente_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['ente']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['ente'] : 0;
if($ente_seleccionado_para_reporte > 0){
$nodo_ente = node_load($ente_seleccionado_para_reporte);
$ente_selecc = l($nodo_ente->title, 'node/' . $nodo_ente->nid);
}else{
$ente_selecc = 'Todos';
}
$anno_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['anho']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['anho'] : date('Y');
if($anno_seleccionado_para_reporte > 0){
$anho_selecc = $anno_seleccionado_para_reporte;
}else{
$anho_selecc = 'Todos';
}
$header = array();
$rows1 = array();
$row1 = array();
$row1[] = array('data' => 'Año', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row1[] = array('data' => $anho_selecc, 'bgcolor' => 'FCFCFC',);
$rows1[] = $row1;
$row1 = array();
$row1[] = array('data' => 'Trimestre(es)', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row1[] = array('data' => $trimestre_selecc, 'bgcolor' => 'FCFCFC',);
$rows1[] = $row1;
$row1 = array();
$row1[] = array('data' => 'Ente Planificador', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row1[] = array('data' => $ente_selecc, 'bgcolor' => 'FCFCFC',);
$rows1[] = $row1;
$output .= theme('table', $header, $rows1);
$output .= '
';
//****************************************************************************
$inputs = array();
$sql = '';
$header = array();
$row_header = array();
$header[] = array('data' => t('Año'));
$row_header[] = array('data' => '', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$header[] = array('data' => t('Ente.'));
$row_header[] = array('data' => '', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab = 2;
$header[] = array('data' => t('Datos del Proyecto'), 'colspan' => 3, );
$row_header[] = array('data' => 'Nombre', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row_header[] = array('data' => 'Código', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row_header[] = array('data' => 'Directríz PNDES', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab += 3;
$row_header[] = array('data' => 'Unidad de Medida', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab += 1;
//colocar cabceras correspondientes avance fisico y financiero para el proyecto en el mes actual
if($trimestre_seleccionado_para_reporte == 4){//todos los meses
$header[] = array('data' => t('Meta Física hasta ahora'), 'colspan' => 2,);
$row_header[] = array('data' => t('Cantidad'), 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$header[] = array('data' => t('Presupuesto del año') );
$row_header[] = array('data' => '', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$header[] = array('data' => t('Beneficiarios hasta ahora') );
$row_header[] = array('data' => '', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab = $cab + 3;
foreach($trimestres_disponibles as $trimestre_i){
$header[] = array('data' => $trimestre_i, 'colspan' => 2, );
$row_header[] = array('data' => '% Avance Físico', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row_header[] = array('data' => '% Ejecución Financiera', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab = $cab + 2;
}
}else{
//solo un trimestre
$header[] = array('data' => t('Meta Física en el trimestre') , 'colspan' => 2,);
$row_header[] = array('data' => t('Cantidad'), 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$header[] = array('data' => t('Presupuesto del año').'
' );
$row_header[] = array('data' => '', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$header[] = array('data' => t('Beneficiarios en el trimestre') );
$row_header[] = array('data' => '', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab = $cab + 3;
$header[] = array('data' => $trimestres_disponibles[$trimestre_seleccionado_para_reporte], 'colspan' => 2, );
$row_header[] = array('data' => '% Avance Físico', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$row_header[] = array('data' => '% Ejecución Financiera', 'bgcolor' => 'E6E6E6', 'style' => 'font-weight: bold;');
$cab = $cab + 2;
}
//proyectos operativos con estado aprobado
$sql1 = "SELECT n.nid, n.title, po.year, po.ente, wn.sid FROM {proyectos_operativos} po, {node} n, {workflow_node} AS wn WHERE po.nid = n.nid AND wn.nid = n.nid AND wn.sid = %d ";
$inputs[] = variable_get('proyectos_operativos_state_aprobado', NULL);
//verificar filtro de ente planificador
$ente_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['ente']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['ente'] : 0;
if($ente_seleccionado_para_reporte > 0){
$sql1 .= "AND po.ente = %d ";
$inputs[] = $ente_seleccionado_para_reporte;
}
//verificar filtro de anho
$anno_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['anho']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['anho'] : date('Y');
if($anno_seleccionado_para_reporte > 0){
$sql1 .= "AND po.year = %d ";
$inputs[] = $anno_seleccionado_para_reporte;
}
$queryResult1 = db_query ( $sql1, $inputs);
$rows = array();
$rows[] = $row_header;
while ($proyectos = db_fetch_array ( $queryResult1 ) ){
$row = array();
$row[] = array('data' => $proyectos['year'],);
//cargar nodo para mostrar otros datos
$ente_planificador = node_load($proyectos['ente']);
$row[] = array('data' => l($ente_planificador->title, 'node/' . $proyectos['ente']),);
$row[] = array('data' => l($proyectos['title'], 'proyectosop/' . $proyectos['nid']),);
//cargar nodo para mostrar otros datos
$nodo_proyecto = node_load($proyectos['nid']);
$row[] = array('data' => $nodo_proyecto->field_proyecto_codigo[0]['value'] );
$term = taxonomy_get_term($nodo_proyecto->field_proyecto_pndes[0]['value']);
$row[] = array('data' => $term->name );
$term = taxonomy_get_term($nodo_proyecto->field_proyecto_unidadm[0]['value']);
$row[] = array('data' => $term->name );
//calcular avance fisico y financiero para el proyecto en el trimestre actual
if($trimestre_seleccionado_para_reporte == 4){
//calcular cantidad de meta fisica y de beneficiarios
module_load_include('inc', 'reportes_sipp' , 'includes/matriz_de_procesos_reporte_mensual.pages');
$datos_mf_benef_monto = _calcular_cantmf_beneficiarios_montoref_total($nodo_proyecto);
$row[] = array('data' => $datos_mf_benef_monto['cant_ejecut_metafisica'] );
$row[] = array('data' => $datos_mf_benef_monto['monto_total_proyecto'] );
$row[] = array('data' => $datos_mf_benef_monto['cant_beneficiarios_mes'] );
//calcular todos los trimestres
foreach($trimestres_disponibles as $id => $trimestre_i){
$porcentajes_avance = _calcular_porcentaje_avance_para_trimestre($nodo_proyecto, $id);
$porczonacritica_mf = $porcentajes_avance['avance_fisico'] != 'N/A' ? number_format($porcentajes_avance['avance_fisico'], 2, '.', ',').'%' : 'N/A';
$row[] = array('data' => $porczonacritica_mf );
$porczonacritica_financiera = $porcentajes_avance['ejecucion_financiera'] != 'N/A' ? number_format($porcentajes_avance['ejecucion_financiera'], 2, '.', ',').'%' : 'N/A';
$row[] = array('data' => $porczonacritica_financiera );
}
}else{
//calcular trimestre actual
$porcentajes_avance = _calcular_porcentaje_avance_para_trimestre($nodo_proyecto, $trimestre_seleccionado_para_reporte);
$row[] = array('data' => $porcentajes_avance['valores_particulares']['mf_ejecutado_trimestre'] );
//calcular cantidad de meta fisica y de beneficiarios
$datos_mf_benef_monto = _calcular_cantmf_beneficiarios_montoref_para_trimestre($nodo_proyecto, $trimestre_seleccionado_para_reporte);
$row[] = array('data' => $datos_mf_benef_monto['monto_total_proyecto'] );
$row[] = array('data' => $datos_mf_benef_monto['cant_beneficiarios_mes'] );
$porczonacritica_mf = $porcentajes_avance['avance_fisico'] != 'N/A' ? number_format($porcentajes_avance['avance_fisico'], 2, '.', ',').'%' : 'N/A';
$row[] = array('data' => $porczonacritica_mf );
$porczonacritica_financiera = $porcentajes_avance['ejecucion_financiera'] != 'N/A' ? number_format($porcentajes_avance['ejecucion_financiera'], 2, '.', ',').'%' : 'N/A';
$row[] = array('data' => $porczonacritica_financiera );
}
$rows[] = $row;
}
if (!(count($rows)>1)) {
$row[] = array('data' => t('No hay resultados para la consulta actual'), 'colspan' => $cab);
$rows[] = $row;
}
$output .= theme('table', $header, $rows);
return $output;
}
/**
* Implementation of consulta_matriz_de_procesos_reporte_trimestral_form().
* Formulario de busqueda de proyecto.
*/
function consulta_matriz_de_procesos_reporte_trimestral_form($form_state) {
$form = array();
//entes planificadores
$entes = array();
$result = db_query('SELECT e.nid, n.title FROM {ente_planificador} AS e INNER JOIN {node} AS n ON n.nid = e.nid WHERE n.status = 1 AND e.tipo = 2 ');
while($ente = db_fetch_object($result)) {
$entes[$ente->nid] = $ente->title;
}
$entes[0] = 'Todos';
$ente_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['ente']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['ente'] : 0;
$form['ente_seleccionado_para_reporte'] = array(
'#title' => t('Ente Planificador'),
'#type' => 'select',
'#default_value' => $ente_seleccionado_para_reporte,
'#options' => $entes,
);
//años disponibles
$anno_actual = date("Y");
for($i = $anno_actual - 10; $i <= $anno_actual; $i++) {
$annos[$i] = $i;
}
$annos[0] = 'Todos';
$anno_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['anho']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['anho'] : date('Y');
$form['anno_seleccionado_para_reporte'] = array(
'#title' => t('Consultar para el año'),
'#type' => 'select',
'#default_value' => $anno_seleccionado_para_reporte,
'#options' => $annos,
);
//tipo de periodo
$tipo_periodo = t('Trimestral');
//subopciones de periodo
$sub_opciones = array(t('1er Trimestre'), t('2do Trimestre'), t('3er Trimestre'), t('4to Trimestre'), t('Todos'));
$trimestre_seleccionado_para_reporte = isset($_SESSION['datos_para_generar_reporte_mp_trimestral']) && isset($_SESSION['datos_para_generar_reporte_mp_trimestral']['trimestre']) ? $_SESSION['datos_para_generar_reporte_mp_trimestral']['trimestre'] : 0;
$form['trimestre_seleccionado_para_reporte'] = array(
'#title' => t('Trimestre(s)'),
'#type' => 'select',
'#default_value' => $trimestre_seleccionado_para_reporte,
'#options' => $sub_opciones,
);
//boton de enviar consulta
$form['buttons'] = array(
'#prefix' => '