t('Reformular los proyectos Operativos'),
'description' => t('Permite reformular los proyectos Operativos'),
'message' => 'Se podrá registrar y/o modificar la reformulación de los proyectos Operativos desde %fecha hasta la fecha %fecha1',
'message_expire' => 'Registrar y/o modificar la reformulación de los proyectos Operativos no se encuentra disponible, se podra realizar desde %fecha hasta la fecha %fecha1)',
'weight' => 4,
'proceso' => 'proyectos_operativos',
);
}
}
/*
* Implementation of acciones_centralizadas_status_planificacion_acciones_centralizadas()
*/
function proyectos_reformulacion_status_planificacion_proyectos_operativos($ente_planificador, $tipo = 2) {
$datos_proyectos_reformulacion_status = array();
//si existe al menos una reformulacion en estado aprobado la reformulacion se puede considerar terminado
$reformular = FALSE;
$year = variable_get('proyectos_operativos_anho_creacion', 0);
$estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);;
$result = db_query('SELECT COUNT(re.id_ref) AS cantidad FROM {proyectos_reformular} AS re INNER JOIN {users} AS u ON u.uid = re.uid INNER JOIN {proyectos_operativos} AS po ON po.nid = re.nid WHERE re.nid = %d AND estado <> %d AND po.year = %d', $ente_planificador, $estado_naprobado, $year);
$reformular = db_fetch_object($result);
$reformular = $reformular->cantidad;
$datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['value'] = ($reformular) ? 1 : 0;
$datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['title'] = t('Reformulaciones para el año @year', array('@year' => $year));
$datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['link'] = 'proyectos_operativos';
$datos_acciones_centralizadas_status['proyectos_operativos_reformular']['mylink'] = 'proyectos_operativos';
$datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['weight'] = -9;
return $datos_proyectos_reformulacion_status;
}
/*
* Implementation of hook_nodeapi()
*/
function proyectos_reformulacion_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'view':
if ($node->type == 'proyectos_operativos') {
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
//se obtiene la reformulacion
$variaciones = _proyectos_reformula_all_partidas_load($node);
$varia = isset($variaciones['total']) ? $variaciones['total'] : 0;
//se obtiene el monto anual del proyecto
$min = $node->field_proyecto_monto_anual[0]['value'] + $varia;
$node->content['proyectos_operativos_monto_anual_reformulado'] = array(
'#value' => '
' . t('Monto Total del Proyecto para el año en curso') . ':
' . number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '
',
'#weight' => 100,
);
//se obtiene el monto total del proyecto
$min = $node->field_proyecto_total[0]['value'] + $varia;
$node->content['proyectos_operativos_monto_total_reformulado'] = array(
'#value' => '' . t('Monto Total del Proyecto') . ':
' . number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '
',
'#weight' => 100,
);
$unidad_medida = isset($variaciones['unidad']) ? $variaciones['unidad'] : $node->field_proyecto_unidadm[0]['tid'];
if ($unidad_medida) {
$unidad_medida_term = taxonomy_get_term($unidad_medida);
$unidad_nombre = t('No seleccionado');
// If this term's vocabulary supports localization.
if ($unidad_medida_term && module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($unidad_medida_term->vid) == I18N_TAXONOMY_LOCALIZE) {
$unidad_medida_term->name = tt("taxonomy:term:$unidad_medida_term->tid:name", $unidad_medida_term->name);
}
if ($unidad_medida_term) {
$unidad_nombre = $unidad_medida_term->name;
}
}
$node->content['proyectos_operativos_unidad_medida_reformulado'] = array(
'#value' => '' . t('Unidad de Medida') . ':
' . $unidad_nombre . '
',
'#weight' => 100,
);
//meta fisica del proyecto
$output = '' . t('Meta Física del proyecto') . ' ';
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
$header = array();
$rows = array();
$row = array();
$total = 0;
$total1 = 0;
foreach($ftypes as $id_field => $texto) {
$header[] = array('data' => $texto);
$varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0;
$min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia;
$valor = isset($reformula['field_proyecto_meta_fisica'][0][$id_field])? $reformula['field_proyecto_meta_fisica'][0][$id_field] : 0;
$total += $min;
$total1 += $valor;
$row[] = array('data' => $min, );
}
$row[] = array('data' => $total, );
$rows[] = $row;
$header[] = array('data' => t('TOTAL'));
$output .= theme('table', $header, $rows);
$output .= ' ';
$node->content['proyectos_operativos_meta_fisica_reformulado'] = array(
'#value' => $output,
'#weight' => 100,
);
}
elseif ($node->type == 'accion_especifica') {
$term_id = isset($node->variaciones) && isset($node->variaciones['field_accion_esp_metaf_'. $node->nid][0]['unidad']) ? $node->variaciones['field_accion_esp_metaf_'. $node->nid][0]['unidad'] : $node->field_accion_esp_unidadm[0]['value'];
$term = taxonomy_get_term($term_id);
//se agrega la unidad de medida reformulada
$node->content['proyectos_operativos_unidad_medida_reformulado'] = array(
'#value' => '' . t('Unidad de Medida') . ':
' . $term->name . '
',
'#weight' => 100,
);
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
$proyecto = node_load($node->field_accion_esp_proyecto[0]['nid']);
$variaciones = _proyectos_reformula_all_partidas_load($proyecto);
$output = '' . t('Meta Física de las Acción Específica') . ' ';
$header = array();
$rows = array();
$row = array();
foreach($ftypes as $id_field => $texto) {
$header[] = array('data' => $texto);
$varia = isset($variaciones['field_accion_esp_metaf_' . $node->nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $node->nid][0][$id_field] : 0;
$min = $node->field_accion_esp_metaf[0][$id_field] + $varia;
$total += $min;
$row[] = array('data' => number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
$header[] = array('data' => t('TOTAL'));
$rows[] = $row;
$output .= theme('table', $header, $rows);
$output .= ' ';
$node->content['accion_especifica_meta_fisica_reformulado'] = array(
'#value' => $output,
'#weight' => 100,
);
$field = content_fields('field_accion_esp_programacion', 'accion_especifica');
$tree = taxonomy_get_tree($field['vid']);
$vtid = $field['vtid'];
$partidas = array();
if ($tree) {
foreach ($tree as $term) {
if (isset($vtid[$term->tid])) {
if ($term && module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
$term->name = tt("taxonomy:term:$term->tid:name", $unidad_medida_term->name);
}
$partidas[$term->tid] = $term->name;
}
}
}
$partidas_nodo = array();
foreach ($node->field_accion_esp_programacion as $partida) {
if(!empty($partida['tid'])) {
$partidas_nodo[$partida['tid']] = $partida;
}
}
$output = '';
$output .= '' . t('Distribución por partidas Presupuestarias') . ' ';
$header = array();
$header[] = array('data' => t('Partidas'));
foreach($ftypes as $id_field => $texto) {
$header[] = array('data' => $texto);
}
$header[] = array('data' => t('TOTAL'));
$rows = array();
$rowsF = array();
$totales = array();
$totalT = 0;
$plant = array();
$sumaplan = 0;
$sumaplanm = array();
foreach($partidas as $tid => $grupo) {
$total = 0;
$total1 = 0;
$row = array();
$row[] = array('data' => $grupo);
foreach($ftypes as $id_field => $texto) {
$varia = isset($variaciones['field_accion_esp_programacion_' . $node->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $node->nid][$tid][$id_field] : 0;
$min = $partidas_nodo[$tid][$id_field] + $varia;
if (!isset($plant[$tid])) {
$plant[$tid] = 0;
}
$totalT += $min;
$plant[$tid] += $min;
$total += $min;
$sumaplan += $min;
if (!isset($sumaplanm[$id_field])) {
$sumaplanm[$id_field] = 0;
}
$sumaplanm[$id_field] += $min;
$row[] = array('data' => number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($plant[$tid], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
if ($plant[$tid] > 0) {
$rows[] = $row;
}
}
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ' ', 'align' => 'right');
foreach($ftypes as $id_field => $texto) {
$row[] = array('data' => number_format($sumaplanm[$id_field], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($totalT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$output .= theme('table', $header, $rows);
$output .= ' ';
$node->content['accion_especifica_partidas_reformulado'] = array(
'#value' => $output,
'#weight' => 101,
);
$output = '';
//financiamiento
$arreglo_financiamiento = array();
$accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4);
for($i = 0; $i < $accion_especifica_number_fields; $i++) {
$arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : '';
$arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array());
}
/*
$arreglo = array();
$titles = array(
'ordinarios' => t('Recursos Ordinarios'),
'propios' => t('Recursos Propios'),
'transferencias' => t('Donaciones'),
'otros' => t('Otros'),
);
$titles_field = array(
'field_accion_esp_transferencias' => t('Recursos Ordinarios'),
'field_accion_esp_creditosa' => t('Recursos Propios'),
'transferencias' => t('Donaciones'),
'otros' => t('Otros'),
);
$arreglo['ordinarios'] = array(
'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
'field_accion_esp_mcti' => 'field_accion_esp_mcti',
);
$arreglo['propios'] = array(
'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
'field_accion_esp_activos' => 'field_accion_esp_activos',
'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
);
$arreglo['transferencias'] = array(
'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
);
$arreglo['otros'] = array(
'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
'field_accion_esp_misionc' => 'field_accion_esp_misionc',
'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
'field_accion_esp_fonden' => 'field_accion_esp_fonden',
'field_accion_esp_locti' => 'field_accion_esp_locti',
'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
);
*/
$rows = array();
$row = array();
$row1 = array();
$sumalT = 0;
foreach($arreglo_financiamiento as $id_items => $titulo) {
$sumal = 0;
$output1 = '' . $titulo . ' ';
foreach($arreglo_financiamiento_fields[$id_items] as $id1) {
if ($id1) {
$field = content_fields($id1, 'accion_especifica');
$varia = isset($variaciones[$id1 . '_' . $node->nid][0]['value']) ? $variaciones[$id1 . '_' . $node->nid][0]['value'] : 0;
$min = $node->{$id1}[0]['value'] + $varia;
if (!isset($sumafinm[$id_items])) {
$sumafinm[$id_items] = 0;
}
$sumafinm[$id_items] += $min;
$sumatotalf += $min;
$field = content_fields($id1, 'accion_especifica');
$sumal += $min;
$sumalT += $min;
$output1 .= '' . $field['widget']['label'] . ':
' . '
' . number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '
' . '
';
}
}
$output1 .= ' ';
$row[] = array('data' => $output1, );
$row1[] = array('data' => number_format($sumal, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
}
$rows[] = $row;
$rows[] = $row1;
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ': ', 'colspan' => 3, 'align' => 'right');
$row[] = array('data' => number_format($sumalT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$output .= '' . t('Distribución por fuentes de Financiamiento') . ' ' . theme('table', array(), $rows) . ' ';
$node->content['accion_especifica_fuentesfinanc_reformulado'] = array(
'#value' => $output,
'#weight' => 102,
);
}
break;
case 'delete':
if ($node->type = 'proyectos_operativos') {
db_query('DELETE FROM {proyectos_reformula} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {proyectos_reformular} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {proyectos_reformular_state} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {proyectos_reformula_fuente} WHERE nid = %d', $node->nid);
}
break;
case 'load':
if ($node->type == 'accion_especifica') {
$proyecto = node_load($node->field_accion_esp_proyecto[0]['nid']);
$variaciones = _proyectos_reformula_all_partidas_load($proyecto);
$node->proyecto_asignado = $proyecto;
$node->variaciones = $proyecto->variaciones;
}
elseif ($node->type == 'proyectos_operativos'){
$variaciones = _proyectos_reformula_all_partidas_load($node);
$node->variaciones = $variaciones;
}
break;
}
}
/*
* Implementation of hook_proyecto_obtiene_links_alter()
*/
function proyectos_reformulacion_proyecto_obtiene_links_alter(&$links, $proyecto, $acceso = FALSE) {
$node_accion = node_load($proyecto->nid);
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
if($node_accion->_workflow == $estado_aprobado){
$links[] = array(
'data' => l(t('Reformulaciones'), 'proyectosop/' . $proyecto->nid . '/reformular'),
'class' => 'proyectos-operativos-reformulaciones',
);
}
}
/*
* hook_form_alter()
*/
function proyectos_reformulacion_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'proyectos_operativos_proyecto_genera_campos_form') {
if (!isset($_SESSION['proyectos_operativos_mostrar_campos'][$form['#node']->nid]) || !count($_SESSION['proyectos_operativos_mostrar_campos'][$form['#node']->nid])) {
//REFORMULACION DEL PROYECTO
$arreglo['proyectos_reformulacion']['reformulacion'] = array(
'proyectos_operativos_monto_anual_reformulado' => t('Monto Total del Proyecto para el año en curso (Reformulado)'),
'proyectos_operativos_monto_total_reformulado' => t('Monto Total del Proyecto (Reformulado)'),
'proyectos_operativos_unidad_medida_reformulado' => t('Unidad de Medida (Reformulado)'),
'proyectos_operativos_meta_fisica_reformulado' => t('Meta Física del proyecto (Reformulado)'),
);
$form['proyectos_reformulacion'] = array(
'#type' => 'fieldset',
'#title' => t('Reformulación del Proyecto'),
'#weight' => 1,
);
//Clasificación Sectorial
$form['proyectos_reformulacion']['reformulacion'] = array(
'#type' => 'checkboxes',
'#options' => $arreglo['proyectos_reformulacion']['reformulacion'],
'#default_value' => array(),
'#title' => t('Reformulación del Proyecto'),
'#multiple' => TRUE,
);
$form['#title_combos']['reformulacion']['title'] = t('Reformulación del Proyecto');
}
}
$states = array();
if ($form_id == 'proyectos_operativos_admin_settings') {
if (module_exists('workflow')) {
$wid = workflow_get_workflow_for_type('proyectos_operativos');
if ($wid){
$states = workflow_get_states($wid);
$rids = user_roles();
$rids['-1'] = t('author');
if (count($states)) {
foreach ($states as $sid => $state) {
$form['workflow']['proyectos_operativos_state_r_' . $sid] = array(
'#type' => 'checkboxes',
'#options' => $rids,
'#default_value' => variable_get('proyectos_operativos_state_r_' . $sid, array()),
'#title' => t('Roles que pueden editar las reformulaciones de los Proyectos Operativos'),
'#multiple' => TRUE,
'#prefix' => '' . t('State: @state', array('@state' => $state)) . ' ',
'#suffix' => "
",
);
}
}
}
}
}
if (count($states)) {
$form['workflow']['proyectos_operativos_state_reformulacion'] = array(
'#title' => t('Seleccione el estado de inicio cuando se añada una reformulación'),
'#type' => 'select',
'#default_value' => variable_get('proyectos_operativos_state_reformulacion', 0),
'#options' => $states,
'#weight' => -6,
);
}
}
/**
* Menu access control callback. Determine access to reformula tab.
*/
function _proyectos_reformulacion_reformula_node_tab_access($node = NULL) {
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
return ($node->type == 'proyectos_operativos' && $node->_workflow == $estado_aprobado);
}
/**
* Menu access control callback. Determine access to reformulacion tab.
*/
function _proyectos_reformulacion_reformula_node_add_tab_access($node = NULL) {
global $user;
$year = variable_get('proyectos_operativos_anho_creacion', 0);
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
if ($node->type != 'proyectos_operativos' || $node->anhoproyectos_operativos != $year) {
return FALSE;
}
if ($estado_aprobado && $node->_workflow != $estado_aprobado) {
return FALSE;
}
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
$current_time = time();
$tipo_plan = 'proyectos_operativos_reformular';
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo);
$fecha = FALSE;
$ente = usuario_tiene_ente($user->uid);
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if ($fecha) {
if ($ente->nid == $ente_planificador->nid) {
$fecha = TRUE;
}
elseif (!user_access('admin planificador')) {
return FALSE;
}
}
if (!$fecha) {
return FALSE;
}
$roles_allow = variable_get('proyectos_operativos_state_r_1', array());
$estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);
$result = db_query("SELECT count(ar.id_ref) AS cantidad FROM {proyectos_operativos} AS ac INNER JOIN {proyectos_reformular} AS ar ON ar.nid = ac.nid WHERE (ar.estado <> %d AND ar.estado <> %d) AND ac.ente = %d AND ac.year = %d and ac.nid = %d", $estado_aprobado, $estado_naprobado, $node->field_proyecto_ente[0]['nid'], $year, $node->nid);
$proyecto = db_fetch_array($result);
$roles = array_keys($user->roles);
if (count($roles)) {
foreach($roles as $rol) {
if($roles_allow[$rol]) {
return TRUE && !$proyecto['cantidad'];
}
}
}
return ($proyecto && !$proyecto['cantidad'] && $user->uid == 1);
}
/**
* Menu access control callback. Determine access to editar reformulacion tab.
*/
function _proyectos_reformulacion_reformula_node_edit_tab_access($node = NULL, $reformulacion) {
global $user;
$year = variable_get('proyectos_operativos_anho_creacion', 0);
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
if ($node->type != 'proyectos_operativos' || $node->anhoproyectos_operativos != $year) {
return FALSE;
}
if ($estado_aprobado && $node->_workflow != $estado_aprobado) {
return FALSE;
}
if ($estado_aprobado && $reformulacion->estado == $estado_aprobado) {
return FALSE;
}
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
$current_time = time();
$tipo_plan = 'proyectos_operativos_reformular';
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo);
$fecha = FALSE;
$ente = usuario_tiene_ente($user->uid);
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if ($fecha) {
if ($ente->nid == $ente_planificador->nid) {
$fecha = TRUE;
}
elseif (!user_access('admin planificador')) {
return FALSE;
}
}
if (!$fecha) {
return FALSE;
}
$roles_allow = variable_get('proyectos_operativos_state_r_' . $reformulacion->estado, array());
if ($user->uid == 1 || ($user->uid == $reformulacion->uid && $roles_allow[-1])) {
return TRUE;
}
$roles = array_keys($user->roles);
if (count($roles)) {
foreach($roles as $rol) {
if($roles_allow[$rol]) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Implementation of proyectos_reformulacion_menu_reformulacion_load().
* Menu loader callback. Load a mes.
*/
function proyectosop_menu_reformulacion_load($id_ref = 0, $node = 0) {
$reformula = FALSE;
$nodo = $node ? $node->nid : arg(1);
if ($id_ref && is_numeric($nodo)) {
$result = db_query("SELECT * FROM {proyectos_reformular} WHERE nid = %d AND id_ref = %d", $nodo, $id_ref);
$reformula = db_fetch_object($result);
}
return $reformula;
}
/**
* Implementation of accionesp_menu_r_load().
* Devuelve la accion especifica.
*/
function accionesp_menu_r_load($nid) {
$ae = FALSE;
if ($nid && arg(1) && is_numeric(arg(1))) {
$ae = node_load($nid);
if ($ae->type != 'accion_especifica' || $ae->field_accion_esp_proyecto[0]['nid'] != arg(1)) {
return FALSE;
}
}
return $ae;
}
/*
* Implementation of proyectos_reformulacion_wk_menu_load()
*/
function proyectos_reformulacion_wk_menu_load($state = 0) {
$states = _proyectos_operativos_reformulacion_obtiene_estados();
if (isset($states['states'][$state])) {
return $state;
}
return FALSE;
}
/**
* Menu access control callback. Determine access to wk tab.
*/
function _proyectos_reformulacion_reformula_wk_node_tab_access($node = NULL, $reformulacion, $state = 0) {
global $user;
$id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$suma_r_ae = total_reformulado_ae($node, $reformula);
if ($suma_r_ae != $reformulacion_load->variacion) {
return FALSE;
}
$year = variable_get('proyectos_operativos_anho_creacion', 0);
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
if ($node->type != 'proyectos_operativos' || $node->anhoproyectos_operativos != $year) {
return FALSE;
}
if ($estado_aprobado && $node->_workflow != $estado_aprobado) {
return FALSE;
}
$ente = usuario_tiene_ente($user->uid);
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) {
return FALSE;
}
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
$estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);
if ($reformulacion->estado == $estado_naprobado || $reformulacion->estado == $estado_aprobado) {
return FALSE;
}
$states = _proyectos_operativos_reformulacion_obtiene_estados();
$first_state = 0;
if ($states['wid']) {
$first_state = _workflow_creation_state($states['wid']);
}
$roles = array_keys($user->roles);
if ($user->uid == 1) {
// Superuser is special.
$roles_transition = 'ALL';
}
else {
$roles_transition = $roles;
if ($user->uid == $reformulacion->uid && $reformulacion->uid > 0) {
$roles_transition += array('author' => 'author');
}
}
$transitions = array();
if ($states['wid']) {
$transitions = workflow_allowable_transitions($reformulacion->estado, 'to', $roles_transition);
}
if ($first_state && $reformulacion->estado == $first_state) {
unset($transitions[$reformulacion->estado]);
}
if (isset($transitions[$state])) {
return TRUE;
}
return FALSE;
}
/*
* Implementation of proyectos_reformulacion_reformula_wk_tab_page_form()
*/
function proyectos_reformulacion_reformula_wk_tab_page_form($form_state, $node, $reformulacion_load = 0, $state = 0) {
$estados = _proyectos_operativos_reformulacion_obtiene_estados();
$form = array();
$form['#node'] = $node;
$form['#nuevo_estado'] = $state;
$form['#estados'] = $estados['states'];
$form['#reformulacion'] = $reformulacion_load;
$form['comentario'] = array(
'#title' => t('Comentario'),
'#type' => 'textarea',
'#default_value' => '',
);
$message = t('Esta seguro de cambiar la reformulación al estado %nombre_estado?', array('%nombre_estado' => $estados['states'][$state]));
$caption = ''. t('This action cannot be undone.') .'
';
$return_path = 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/view';
return confirm_form($form, $message, $return_path, $caption, t('Cambiar'));
return $form;
}
/**
* Implementation of proyectos_reformulacion_reformula_wk_tab_page_form_submit().
* Process funcion delete confirm form.
*/
function proyectos_reformulacion_reformula_wk_tab_page_form_submit($form, &$form_state) {
global $user;
$nuevo_estado = $form['#datos_institucionales_funcion'];
db_query('UPDATE {proyectos_reformular} SET estado = %d, estado_ant = %d WHERE nid = %d AND id_ref = %d', $form['#nuevo_estado'], $form['#reformulacion']->estado, $form['#node']->nid, $form['#reformulacion']->id_ref);
db_query("INSERT INTO {proyectos_reformular_state} (nid, estado, estado_ant, comentario, date, id_ref, uid) VALUES (%d, %d, %d, '%s', %d, %d, %d)", $form['#node']->nid, $form['#nuevo_estado'], $form['#reformulacion']->estado, check_plain($form_state['values']['comentario']), time(), $form['#reformulacion']->id_ref, $user->uid);
drupal_set_message(t('La reformulación fue cambiada al estado @nombre_estado', array('@nombre_estado' => $form['#estados'][$form['#nuevo_estado']])));
$form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#reformulacion']->id_ref . '/view';
}
/*
* Implementation of hook_menu()
*/
function proyectos_reformulacion_menu() {
$items = array();
$items['proyectosop/%proyectosop/reformular'] = array(
'title' => 'Reformular',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_node_tab_access',
'access arguments' => array(1),
'page callback' => '_proyectos_reformulacion_reformula_list_page',
'page arguments' => array(1),
'weight' => 2,
);
$items['proyectosop/%proyectosop/reformular/list'] = array(
'title' => 'Reformulaciones',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10
);
$items['proyectosop/%proyectosop/reformular/add'] = array(
'title' => 'Agregar Reformulación',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_node_add_tab_access',
'access arguments' => array(1),
'page callback' => 'drupal_get_form',
'page arguments' => array('proyectos_reformulacion_reformula_tab_page_form', 1),
'weight' => 2,
);
$items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/view'] = array(
'title' => 'Ver reformulación',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_node_tab_access',
'access arguments' => array(1),
'page callback' => '_proyectos_reformulacion_reformula_tab_page_ver',
'page arguments' => array(1, 3),
'weight' => 2,
);
$items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/edit'] = array(
'title' => 'Editar',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_node_edit_tab_access',
'access arguments' => array(1, 3),
'page callback' => 'drupal_get_form',
'page arguments' => array('proyectos_reformulacion_reformula_tab_page_form', 1, 3),
'weight' => 3,
);
$items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/ae/%accionesp_menu_r'] = array(
'title' => 'Acciones Especificas',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_node_tab_access',
'access arguments' => array(1),
'page callback' => '_proyectos_reformulacion_reformula_tab_page_ver_ae',
'page arguments' => array(1, 3, 5),
'weight' => 2,
);
$items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/ae/%accionesp_menu_r/edit'] = array(
'title' => 'Editar AEs',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_node_edit_tab_access',
'access arguments' => array(1, 3),
'page callback' => 'drupal_get_form',
'page arguments' => array('proyectos_reformulacion_reformula_tab_page_ae_form', 1, 3, 5),
'weight' => 3,
);
$items['proyectosop/%node/reformular/%proyectosop_menu_reformulacion/workflow/%proyectos_reformulacion_wk_menu'] = array(
'title' => 'Workflow',
'type' => MENU_LOCAL_TASK,
'access callback' => '_proyectos_reformulacion_reformula_wk_node_tab_access',
'access arguments' => array(1, 3, 5),
'page callback' => 'drupal_get_form',
'page arguments' => array('proyectos_reformulacion_reformula_wk_tab_page_form', 1, 3, 5),
'weight' => 3,
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function proyectos_reformulacion_theme() {
return array(
'proyectos_reformulacion_reformula_tab_page_form' => array(
'arguments' => array('form' => NULL),
),
'proyectos_reformulacion_reformula_tab_page_ae_form' => array(
'arguments' => array('form' => NULL),
),
);
}
/*
* Implementation of proyectos_reformulacion_reformula_tab_page_form()
*/
function proyectos_reformulacion_reformula_tab_page_form($form_state, $node, $reformulacion_load = 0) {
$title = $reformulacion_load ? t('Modificar Reformulación') : t('Agregar Reformulación al Proyecto');
drupal_set_title($title);
$id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
$field = content_fields('field_proyecto_unidadm', 'proyectos_operativos');
$unidad_ant = $node->field_proyecto_unidadm[0]['value'];
$text_unidad = t('N/A');
$tree = taxonomy_get_tree($field['vid']);
$options = array();
if ($tree) {
foreach ($tree as $term) {
if ($term->tid == $unidad_ant) {
$text_unidad = $term->name;
}
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$options[] = $choice;
}
}
$field = content_fields('field_accion_esp_unidadm', 'accion_especifica');
$unidadesm = array();
$tree = taxonomy_get_tree($field['vid']);
if ($tree) {
foreach ($tree as $term) {
$unidadesm[$term->tid] = $term->name;
}
}
$form['field_proyecto_unidadm_ant'] = array(
'#title' => t('Unidad de Medida Actual'),
'#type' => 'textfield',
'#value' => $text_unidad,
'#attributes' => array('class' => 'campo-bloqueado '),
);
$valor_medida = $reformula['unidad'] ? $reformula['unidad'] : $node->field_proyecto_unidadm[0]['value'];
$form['field_proyecto_unidadm'] = array(
'#title' => t('Unidad de Medida Nueva'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $valor_medida,
);
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
$grupos = array();
if ($node->field_proyecto_accion_esp[0]['nid']) {
foreach($node->field_proyecto_accion_esp as $ae) {
$grupos[$ae['nid']] = node_load($ae['nid']);
$array[$ae['nid']] = node_load($ae['nid']);
}
}
$varia = isset($variaciones['total']) ? $variaciones['total'] : 0;
$min = $node->field_proyecto_monto_anual[0]['value'] + $varia;
$form['#monto_reformulado'] = $min;
$valor = isset($reformulacion_load->variacion)? $reformulacion_load->variacion : 0;
$suma_variacion['primero'] = $min;
$total_accion = $min;
$idformuj = 'variacion';
$id_field = 'primero';
$fecha = array();
$fecha['dia'] = $reformula['fecha_onapre'] ? date('j', $reformula['fecha_onapre']) : date('j');
$fecha['mes'] = $reformula['fecha_onapre'] ? date('n', $reformula['fecha_onapre']) : date('m');
$fecha['year'] = $reformula['fecha_onapre'] ? date('Y', $reformula['fecha_onapre']) : date('Y');
$form['fecha_onapre'] = array(
'#type' => 'date',
'#title' => t('Fecha de Aprobación'),
'#default_value' => array('day' => $fecha['dia'], 'month' => $fecha['mes'], 'year' => $fecha['year']),
'#required' => TRUE,
);
$valor_justificacion = isset($reformula['justificacion'])? $reformula['justificacion'] : '';
$form['justificacion'] = array(
'#title' => t('Justificación'),
'#type' => 'textarea',
'#default_value' => $valor_justificacion,
);
$form['variacion'] = array(
'#type' => 'textfield',
'#title' => t('Variación Presupuestaria'),
'#default_value' => $valor,
'#size' => 30,
'#suffix' => '' . t('Estimado Usuario: El monto a ingresar debe comenzar con el signo mas "+" o con el signo menos "-".') . '
',
'#attributes' => array('class' => $clase . ' field-variacion number', 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref2('" . 'field-variacion' . "', 'variacion', '" . $id_field . "');"),
);
$form['variaciont'] = array(
'#type' => 'textfield',
'#title' => t('Monto Total Reformulación'),
'#default_value' => $min + $valor,
'#size' => 30,
'#attributes' => array('class' => 'campo-bloqueado field-variacion-total number1'),
);
$form['#state_creation'] = -1;
//get first state
if (module_exists('workflow')) {
$estados = _proyectos_operativos_reformulacion_obtiene_estados();
$estado_inicial = variable_get('proyectos_operativos_state_reformulacion', 0);
if ($estados['wid']) {
if ($estado_inicial && $estados['states'][$estado_inicial]) {
$form['#state_creation'] = $estado_inicial;
}
else {
$form['#state_creation'] = _workflow_creation_state($estados['wid']);
}
}
}
$form['#node'] = $node;
$form['#ftypes'] = $ftypes;
$form['#grupos'] = $grupos;
$form['#unidadesm'] = $unidadesm;
$form['#variaciones'] = $variaciones;
$form['#reformula'] = $reformula;
$form['#id_ref'] = $id_ref;
$form['#total_accion'] = $total_accion;
$mes_inicio = 0;
$mes_fin = 12;
if (!variable_get('proyectos_operativos_reformulacion_meses', TRUE)) {
$f_aux = explode(' ', $node->field_proyecto_fecha_i[0]['value']);
$f_aux = explode('-', $f_aux[0]);
$mes_inicio = (int) $f_aux[1];
$f_aux = explode(' ', $node->field_proyecto_fecha_f[0]['value']);
$f_aux = explode('-', $f_aux[0]);
$mes_fin = (int) $f_aux[1];
}
$form['#mes'] = variable_get('accion_especifica_de_proyecto_seguimiento_anho_seguimiento', 0) == $node->anhoproyectos_operativos ? variable_get('accion_especifica_de_proyecto_seguimiento_mes_seguimiento', 0) - 1 : 0;
$proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion');
$proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js');
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
$form['#format_number'] = array('format_number' => $format_number);
drupal_add_js($form['#format_number'], 'setting');
$i = 1;
$sumafisica = 0;
$sumaT = 0;
$sumaTv = 0;
$sumaplanm = array();
foreach($ftypes as $id_field => $texto) {
$clase = '';
if ($form['#mes'] >= $i) {
$clase .= 'campo-bloqueado ';
}
elseif($mes_inicio > $i) {
$clase .= 'campo-bloqueado ';
}
elseif($mes_fin < $i) {
$clase .= 'campo-bloqueado ';
}
$varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0;
$min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia;
$total_accion += $min;
$valor = isset($reformula['field_proyecto_meta_fisica'][0][$id_field])? $reformula['field_proyecto_meta_fisica'][0][$id_field] : 0;
$sumafisica += $valor;
$sumaT += $min + $valor;
$idformuj = str_replace('_', '-', 'field_proyecto_meta_fisica_' . $id_field);
if (!isset($sumaplanm[$id_field])) {
$sumaplanm[$id_field] = 0;
}
$sumaTv += $min;
$sumaplanm[$id_field] = $min;
$form['field_proyecto_meta_fisica_' . $id_field] = array(
'#type' => 'textfield',
'#default_value' => $valor,
'#size' => 15,
'#attributes' => array('class' => $clase . ' field-proyecto-meta-fisica-r subtotal-' . $id_field . ' number', 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref('" . 'field-proyecto-meta-fisica-r' . "');prsumaref2('" . 'subtotal-' . $id_field . "', 'sumaplan', '" . $id_field . "'); prsumaref('subtotales')"),
);
$form['field_proyecto_meta_fisica_to_' . $id_field] = array(
'#type' => 'textfield',
'#default_value' => $min + $valor,
'#size' => 15,
'#attributes' => array('class' => 'campo-bloqueado subtotales subtotal-' . $id_field . '-total number1'),
);
$i++;
}
$form['field_proyecto_meta_fisica_total'] = array(
'#type' => 'textfield',
'#default_value' => $sumafisica,
'#size' => 15,
'#attributes' => array('class' => 'campo-bloqueado field-proyecto-meta-fisica-r-total number1'),
);
$form['field_proyecto_meta_fisica_totalt'] = array(
'#type' => 'textfield',
'#default_value' => $sumaT,
'#size' => 15,
'#attributes' => array('class' => 'campo-bloqueado subtotales-total number1'),
);
$sumaacciones = 0;
$sumaaccionm = array();
$sumaaccionv = 0;
foreach($grupos as $nid => $ae) {
$i = 1;
$sumaP = 0;
$valor_unidad = $reformula['field_accion_esp_metaf_' . $nid][0]['unidad'] ? $reformula['field_accion_esp_metaf_' . $nid][0]['unidad'] : $ae->field_accion_esp_unidadm[0]['value'];
$form[$nid . '_field_accion_esp_metaf_unidadm'] = array(
'#title' => t('Unidad de Medida Nueva'),
'#type' => 'select',
'#options' => $options,
'#default_value' => $valor_unidad,
);
foreach($ftypes as $id_field => $texto) {
$clase = '';
if ($form['#mes'] >= $i) {
$clase = 'campo-bloqueado ';
}
elseif($mes_inicio > $i) {
$clase .= 'campo-bloqueado ';
}
elseif($mes_fin < $i) {
$clase .= 'campo-bloqueado ';
}
$idformuj = str_replace('_', '-', $nid . '_field_accion_esp_metaf_' . $id_field);
$varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0;
$min = $ae->field_accion_esp_metaf[0][$id_field] + $varia;
$total_accion += $min;
$valor = isset($reformula['field_accion_esp_metaf_' . $nid][0][$id_field])? $reformula['field_accion_esp_metaf_' . $nid][0][$id_field] : 0;
$sumaacciones += $min + $valor;
$sumaP += $valor;
if (!isset($sumaaccionm[$id_field])) {
$sumaaccionm[$id_field] = 0;
}
$sumaaccionv += $min;
$sumaaccionm[$id_field] += $min;
$form[$nid . '_field_accion_esp_metaf_' . $id_field] = array(
'#type' => 'textfield',
'#default_value' => $valor,
'#size' => 15,
'#attributes' => array('class' => $clase . ' ' . $nid . '-field-accion-esp-metaf subtotal1-' . $id_field . ' number', 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref('" . $nid . '-field-accion-esp-metaf' . "');prsumaref2('" . 'subtotal1-' . $id_field . "', 'sumaaccion', '" . $id_field . "'); prsumaref('subtotales1');sumatotalAE('" . $idformuj . "'," . $min . ");"),
);
$i++;
}
$form[$nid . '_field_accion_esp_metaf_t'] = array(
'#type' => 'textfield',
'#default_value' => $sumaP,
'#size' => 15,
'#attributes' => array('class' => 'campo-bloqueado ' . $nid . '-field-accion-esp-metaf-total number1'),
);
}
foreach($ftypes as $id_field => $texto) {
$form['field_accion_esp_metaft_' . $id_field] = array(
'#type' => 'textfield',
'#default_value' => $sumaaccionm[$id_field],
'#size' => 15,
'#attributes' => array('class' => 'campo-bloqueado subtotales1 subtotal1-' . $id_field . '-total number1'),
);
}
$form['field_accion_esp_metaftt'] = array(
'#type' => 'textfield',
'#default_value' => $sumaacciones,
'#size' => 15,
'#attributes' => array('class' => 'campo-bloqueado subtotales1-total number1'),
);
$jse = array(
'sumatotal' => $sumaTv,
'sumaplan' => $sumaplanm,
'sumaacciones' => $sumaaccionv,
'sumaaccion' => $sumaaccionm,
'variacion' => $suma_variacion,
);
$form['#jse'] = $jse;
drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting');
$form['buttons'] = array(
'#prefix' => '',
'#suffix' => '
',
);
$form['buttons']['registrar'] = array(
'#type' => 'submit',
'#default_value' => t('Guardar'),
'#weight' => 100,
);
$form['buttons']['cancelar'] = array(
'#type' => 'submit',
'#default_value' => t('Cancelar'),
'#weight' => 101,
);
return $form;
}
/*
* Implementation of proyectos_reformulacion_reformula_tab_page_ae_form_validate()
*/
function proyectos_reformulacion_reformula_tab_page_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancelar')) {
return;
}
$proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
$proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion');
drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js');
drupal_add_js($form['#format_number'], 'setting');
drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting');
$start = $form_state['values']['variacion'];
$value = preg_replace('@[^-0-9]@', '', $start);
if ($start != $value) {
form_set_error('variacion', t('Solo números enteros son permitidos en la variación presupuestaria.'));
}
$ftypes = $form['#ftypes'];
foreach($ftypes as $id_field => $texto) {
$start = $form_state['values']['field_proyecto_meta_fisica_' . $id_field];
$value = preg_replace('@[^-0-9]@', '', $start);
if ($start != $value) {
form_set_error('field_proyecto_meta_fisica_' . $id_field, t('Solo números enteros son permitidos en la meta física.'));
}
if ($form_state['values']['field_proyecto_meta_fisica_' . $id_field] + $form['#jse']['sumaplan'][$id_field] < 0) {
form_set_error('field_proyecto_meta_fisica_' . $id_field, t('El valor para reformular de la meta física no puede ser menor que cero'));
}
}
foreach($form['#grupos'] as $nid => $grupo) {
foreach($ftypes as $id_field => $texto) {
$start = $form_state['values'][$nid . '_field_accion_esp_metaf_' . $id_field];
$value = preg_replace('@[^-0-9]@', '', $start);
if ($start != $value) {
form_set_error($nid . '_field_accion_esp_metaf_' . $id_field, t('Solo números enteros son permitidos en la meta física de las AEs.'));
}
}
}
}
/*
* Implementation of proyectos_reformulacion_reformula_tab_page_form_submit()
*/
function proyectos_reformulacion_reformula_tab_page_form_submit($form, &$form_state) {
global $user;
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancelar')) {
drupal_set_message(t('La reformulación ha sido cancelada.'));
if ($form['#id_ref']) {
$form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#id_ref'] . '/view';
}
else {
$form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular';
}
return;
}
$fecha_onapre = mktime(0, 0, 0, $form_state['values']['fecha_onapre']['month'], $form_state['values']['fecha_onapre']['day'], $form_state['values']['fecha_onapre']['year']);
$ftypes = $form['#ftypes'];
$id_ref = $form['#id_ref'];
$campos = array();
$justificacion = check_plain($form_state['values']['justificacion']);
$campos[] = "field_name = 'field_proyecto_meta_fisica'";
foreach($form['#grupos'] as $nid => $grupo) {
$campos[] = "'field_accion_esp_metaf_" . $nid . "'";
}
db_query("DELETE FROM {proyectos_reformula} WHERE nid = %d AND id_ref = %d AND ae = 0", $form['#node']->nid, $id_ref);
if(!$id_ref) {
db_query("INSERT INTO {proyectos_reformular} (uid, nid, estado, date, estado_ant, monto, variacion, unidad, fecha_onapre, justificacion) VALUES (%d, %d, %d, %d, 0, %f, 0, %d, %d, '%s')", $user->uid, $form['#node']->nid, $form['#state_creation'], time(), $form['#total_accion'], $form['#node']->field_proyecto_unidadm[0]['value'], $fecha_onapre, $justificacion);
$id_ref = db_last_insert_id('proyectos_reformular', 'id_ref');
}
$field = array();
$field[] = $id_ref;
$field[] = 'field_proyecto_meta_fisica';
$field[] = 0;
$field[] = $form['#node']->nid;
foreach($ftypes as $id_field => $texto) {
$field[] = $form_state['values']['field_proyecto_meta_fisica_' . $id_field];
}
db_query("INSERT INTO {proyectos_reformula} (id_ref, field_name, partida, nid, value, value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10, value_11, ae) VALUES (%d, '%s', %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 0)", $field);
foreach($form['#grupos'] as $nid => $grupo) {
$field = array();
$field[] = $id_ref;
$field[] = 'field_accion_esp_metaf_' . $nid;
$field[] = 0;
$field[] = $form['#node']->nid;
foreach($ftypes as $id_field => $texto) {
$field[] = $form_state['values'][$nid . '_field_accion_esp_metaf_' . $id_field];
}
$field[] = $form_state['values'][$nid . '_field_accion_esp_metaf_unidadm'];
db_query("INSERT INTO {proyectos_reformula} (id_ref, field_name, partida, nid, value, value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10, value_11, ae, unidad) VALUES (%d, '%s', %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 0, %d)", $field);
}
drupal_set_message(t('La reformulación fue modificada'));
db_query("UPDATE {proyectos_reformular} SET variacion = %d, unidad = %d, fecha_onapre = %d, justificacion = '%s' WHERE nid = %d AND id_ref = %d", $form_state['values']['variacion'], $form_state['values']['field_proyecto_unidadm'], $fecha_onapre, $justificacion, $form['#node']->nid, $id_ref);
$form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $id_ref . '/view';
}
/*
* Implementation of _proyectos_reformulacion_load()
*/
function _proyectos_reformulacion_load($node, $id_ref = 0) {
$reformula_load = proyectosop_menu_reformulacion_load($id_ref, $node);
$reformula = array();
$inputs = array();
$sql = "SELECT * FROM {proyectos_reformula} WHERE nid = %d";
$sql1 = "SELECT * FROM {proyectos_reformula_fuente} WHERE nid = %d";
$inputs[] = $node->nid;
if ($reformula_load) {
$reformula['total'] = $reformula_load->variacion;
$reformula['unidad'] = $reformula_load->unidad;
$reformula['fecha_onapre'] = $reformula_load->fecha_onapre;
$reformula['justificacion'] = $reformula_load->justificacion;
$reformula['estado'] = $reformula_load->estado;
$sql .= ' AND id_ref = %d';
$sql1 .= ' AND id_ref = %d';
$inputs[] = $id_ref;
$result = db_query($sql, $inputs);
while($partida = db_fetch_array($result)) {
$reformula[$partida['field_name']][$partida['partida']] = $partida;
}
$result = db_query($sql1, $inputs);
while($partida = db_fetch_array($result)) {
$reformula[$partida['field_name']][0] = $partida;
}
}
return $reformula;
}
/*
* Implementation of _proyectos_reformula_all_load()
*/
function _proyectos_reformula_all_load($node, $id_ref = 0) {
$reformulaciones = array();
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
$result = db_query("SELECT * FROM {proyectos_reformular} WHERE nid = %d AND estado = %d ORDER BY id_ref DESC", $node->nid, $estado_aprobado);
while($reformula = db_fetch_array($result)) {
$reformulaciones[$reformula['id_ref']] = $reformula;
}
return $reformulaciones;
}
/*
* Implementation of _proyectos_reformulacion_reformula_all_partidas_load()
*/
function _proyectos_reformula_all_partidas_load($node, $id_ref = 0) {
$variaciones = array();
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
'unidad' => t('Unidad'),
);
$load_reformulaciones = array();
$reformulaciones = _proyectos_reformula_all_load($node, $id_ref);
if ($id_ref) {
foreach($reformulaciones as $id => $value) {
if ($id < $id_ref) {
$load_reformulaciones[$id] = $values;
}
}
}
else {
$load_reformulaciones = $reformulaciones;
}
$current_id = 0;
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
if(count($load_reformulaciones)) {
foreach($load_reformulaciones as $id => $value) {
$nueva_variacion = _proyectos_reformulacion_load($node, $id);
if ($estado_aprobado == $nueva_variacion['estado'] && !$current_id) {
$current_id = $id;
}
elseif($estado_aprobado == $nueva_variacion['estado'] && $current_id && $id > $current_id) {
$current_id = $id;
}
if(count($nueva_variacion)) {
foreach($nueva_variacion as $id_campo => $campo) {
if ($id_campo != 'total' && $id_campo != 'unidad') {
if(is_array($campo) && count($campo)) {
foreach($campo as $id_partida => $partida) {
if (!isset($variaciones[$id_campo][$id_partida]['partida'])) {
$variaciones[$id_campo][$id_partida]['partida'] = $partida['partida'];
}
foreach($ftypes as $idc => $valor) {
if (!isset($variaciones[$id_campo][$id_partida][$idc])) {
$variaciones[$id_campo][$id_partida][$idc] = 0;
}
if ($idc == 'unidad') {
if ($current_id == $id) {
$variaciones[$id_campo][$id_partida][$idc] = $partida[$idc];
}
}
else {
$variaciones[$id_campo][$id_partida][$idc] += $partida[$idc];
}
}
}
}
}
else {
if ($id_campo == 'total') {
if (!isset($variaciones['total'])) {
$variaciones['total'] = 0;
}
$variaciones['total'] += $campo;
}
else {
$variaciones['unidad'] = $campo;
}
}
}
}
}
}
return $variaciones;
}
/*
* Implementation of theme_proyectos_reformulacion_reformula_tab_page_form()
*/
function theme_proyectos_reformulacion_reformula_tab_page_form($form) {
$node = $form['#node'];
$variaciones = $form['#variaciones'];
$reformula = $form['#reformula'];
$planificado = t('planificado');
$total_AE_text = t('Total AE');
$variacion = t('variación');
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
$output = '';
$output .= '' . t('Monto Total del Proyecto') . ' ';
$rows = array();
$row = array();
$row[] = array('data' => drupal_render($form['fecha_onapre']));
$row[] = array('data' => drupal_render($form['justificacion']));
$rows[] = $row;
$row = array();
$row[] = array('data' => '' . t('Monto Total del Proyecto para el año en curso: %monto', array('%monto' => number_format($form['#monto_reformulado'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']))) . ' ', 'colspan' => 2, 'align' => center);
$rows[] = $row;
$row = array();
$row[] = array('data' => drupal_render($form['variacion']), );
$row[] = array('data' => drupal_render($form['variaciont']), );
$rows[] = $row;
$output .= theme('table', array(), $rows) . ' ';
$output .= '' . t('Distribución de la Meta Física') . ' ';
$output .= '' . t('Meta Física del Proyecto') . ' ';
$output .= drupal_render($form['field_proyecto_unidadm_ant']);
$output .= drupal_render($form['field_proyecto_unidadm']);
$header = array();
$header[] = array('data' => t('Meta Física del Proyecto'));
$rows = array();
$row = array();
$row1 = array();
$row2 = array();
$row[] = array('data' => $planificado, );
$row1[] = array('data' => $variacion, );
$row2[] = array('data' => '' . t('TOTAL') . ' ', );
$min_planificado = 0;
foreach($form['#ftypes'] as $id_field => $texto) {
$header[] = array('data' => $texto);
$varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0;
$min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia;
$min_planificado += $min;
$row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_' . $id_field]), );
$row2[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_to_' . $id_field]), );
}
$row[] = array('data' => number_format($min_planificado, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_total']), );
$row2[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_totalt']), );
$rows[] = $row;
$rows[] = $row1;
$rows[] = $row2;
$header[] = array('data' => t('TOTAL'));
$output .= theme('table', $header, $rows);
$output .= '' . t('Estimado Usuario: El monto a ingresar debe comenzar con el signo mas "+" o con el signo menos "-".') . '
';
$output .= ' ';
$output .= '' . t('Meta Física de las Acciones Específicas') . ' ';
$header = array();
$header[] = array('data' => t('Meta Física de las AEs'));
$header[] = array('data' => t('Unidad de Medida'));
$header[] = array('data' => t('% de la AEs'),);
$header[] = array('data' => '-',);
foreach($form['#ftypes'] as $id_field => $texto) {
$header[] = array('data' => $texto);
}
$header[] = array('data' => t('TOTAL'));
$rows = array();
$rowsF = array();
$i = 0;
$rowF = array();
$rowF[] = array('data' => '' . t('Número') . ' ', 'align' => center,);
$rowF[] = array('data' => '' . t('Nombre') . ' ', 'align' => center,);
$rowsF[] = $rowF;
foreach($form['#grupos'] as $nid => $grupo) {
$i++;
$row = array();
$rowF = array();
$row1 = array();
$row2 = array();
$rowF[] = array('data' => t('AE %numero', array('%numero' => $i)));
$rowF[] = array('data' => $grupo->titulo_asignado);
$rowsF[] = $rowF;
$row[] = array('data' => t('AE %numero', array('%numero' => $i)), 'rowspan' => 3);
$row[] = array('data' => $form['#unidadesm'][$grupo->field_accion_esp_unidadm[0]['value']] . drupal_render($form[$nid . '_field_accion_esp_metaf_unidadm']), 'rowspan' => 3);
$row[] = array('data' => $grupo->field_accion_esp_ponderacion[0]['value'], 'rowspan' => 3);
$row[] = array('data' => $planificado, );
$row1[] = array('data' => $variacion, );
$row2[] = array('data' => $total_AE_text, );
$min_planificado = 0;
$total_AE = 0;
$min_partida = 0;
foreach($form['#ftypes'] as $id_field => $texto) {
$varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0;
$min = $grupo->field_accion_esp_metaf[0][$id_field] + $varia;
$min_partida += $min;
}
foreach($form['#ftypes'] as $id_field => $texto) {
$idformuj = str_replace('_', '-', $nid . '_field_accion_esp_metaf_' . $id_field);
$varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0;
$min = $grupo->field_accion_esp_metaf[0][$id_field] + $varia;
$min_planificado += $min;
$total_AE += $min + $form[$nid . '_field_accion_esp_metaf_' . $id_field]['#value'];
$form[$nid . '_field_accion_esp_metaf_' . $id_field]['#attributes']['onchange'] .= "sumatotalAE('" . $nid . '-field-accion-esp-metaf-t' . "', " . $min_partida . ");";
$row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => drupal_render($form[$nid . '_field_accion_esp_metaf_' . $id_field]), );
$row2[] = array('data' => '' . number_format($min + $form[$nid . '_field_accion_esp_metaf_' . $id_field]['#value'], 0, $format_number['dec_point'], $format_number['thousands_sep']) . '
', );
}
$row[] = array('data' => number_format($min_planificado, 0, ',', '.'), );
$row1[] = array('data' => drupal_render($form[$nid . '_field_accion_esp_metaf_t']), );
$row2[] = array('data' => '' . number_format($total_AE, 0, $format_number['dec_point'], $format_number['thousands_sep']) . '
', );
$rows[] = $row;
$rows[] = $row1;
$rows[] = $row2;
}
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ' ', 'colspan' => 4, 'align' => 'right');
foreach($form['#ftypes'] as $id_field => $texto) {
$row[] = array('data' => drupal_render($form['field_accion_esp_metaft_' . $id_field]), );
}
$row[] = array('data' => drupal_render($form['field_accion_esp_metaftt']), );
$rows[] = $row;
$output .= theme('table', $header, $rows);
$output .= '' . t('Estimado Usuario: El monto a ingresar debe comenzar con el signo mas "+" o con el signo menos "-".') . '
';
$header = array();
$header[] = array('data' => t('Detalles de las Acciones Específicas'), 'colspan' => 2, 'align' => center);
$output .= theme('table', $header, $rowsF);
$output .= ' ';
$output .= ' ';
$output .= '' . drupal_render($form) .'
';
return $output;
}
/**
* Implementation of _proyectos_operativos_reformula_obtiene_estados().
* Obtiene los estados del tipo de contenido proyecto.
*/
function _proyectos_operativos_reformulacion_obtiene_estados() {
$estados = array();
$wid = 0;
if (module_exists('workflow')) {
$wid = workflow_get_workflow_for_type('proyectos_operativos');
if ($wid){
$estados = workflow_get_states($wid);
}
}
return array(
'wid' => $wid,
'states' => $estados,
);
}
/*
* Implementation of _proyectos_reformulacion_reformula_list_page()
*/
function _proyectos_reformulacion_reformula_list_page($node) {
drupal_set_title(t('Reformulaciones del Proyecto'));
$output = '';
$output .= _proyectos_reformulacion_reformula_obtiene_list_page($node, TRUE);
return $output;
}
/*
* Implementation of _proyectos_reformulacion_reformula_obtiene_list_page()
*/
function _proyectos_reformulacion_reformula_obtiene_list_page($node, $muestra = TRUE) {
global $user;
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
$current_time = time();
$add_reformular = _proyectos_reformulacion_reformula_node_add_tab_access($node);
$tipo_plan = 'proyectos_operativos_reformular';
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo);
$fecha = FALSE;
$ente = usuario_tiene_ente($user->uid);
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
if ($muestra) {
muestra_mensaje($tipo_plan, $ente_planificador->tipo);
}
}
else {
if ($ente->nid == $ente_planificador->nid) {
$fecha = TRUE;
if ($muestra) {
muestra_mensaje($tipo_plan, $ente_planificador->tipo, 0);
}
}
elseif (!user_access('admin planificador')) {
$fecha = FALSE;
}
}
$enlaces_estados = TRUE;
if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) {
$enlaces_estados = FALSE;
}
$states = _proyectos_operativos_reformulacion_obtiene_estados();
$first_state = 0;
if ($states['wid']) {
$first_state = _workflow_creation_state($states['wid']);
}
$estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);
$result = db_query('SELECT re.*, u.name, u.uid FROM {proyectos_reformular} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND estado <> %d ORDER BY id_ref DESC', $node->nid, $estado_naprobado);
$header = array();
$header[] = array('data' => t('Fecha'));
$header[] = array('data' => t('Estado Actual'));
$header[] = array('data' => t('Estado Anterior'));
$header[] = array('data' => t('Fecha de Aprobación'));
$header[] = array('data' => t('Monto (Bs)'));
$header[] = array('data' => t('Variación (Bs)'));
$header[] = array('data' => t('Total monto (Bs)'));
$header[] = array('data' => t('Usuario'));
$header[] = array('data' => t('Acción'));
$rows = array();
$i = 1;
$roles = array_keys($user->roles);
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
$editar = ($node->_workflow == $estado_aprobado);
while($reformular = db_fetch_object($result)) {
if ($user->uid == 1) {
// Superuser is special.
$roles_transition = 'ALL';
}
else {
$roles_transition = $roles;
if ($user->uid == $reformular->uid && $reformular->uid > 0) {
$roles_transition += array('author' => 'author');
}
}
$transitions = array();
if ($states['wid']) {
$transitions = workflow_allowable_transitions($reformular->estado, 'to', $roles_transition);
}
unset($transitions[$reformular->estado]);
$acciones = array();
$row = array();
$row[] = array('data' => format_date($reformular->date),);
$estado = isset($states['states'][$reformular->estado]) ? $states['states'][$reformular->estado] : 'N/A';
$row[] = array('data' => $estado,);
$estado = isset($states['states'][$reformular->estado_ant]) ? $states['states'][$reformular->estado_ant] : 'N/A';
$row[] = array('data' => $estado,);
$row[] = array('data' => date( 'd/m/Y', $reformular->fecha_onapre),);
$row[] = array('data' => number_format($reformular->monto, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),);
$row[] = array('data' => number_format($reformular->variacion, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),);
$total = $reformular->monto + $reformular->variacion;
$row[] = array('data' => number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),);
$row[] = array('data' => l($reformular->name, 'user/' . $reformular->uid),);
//display options
if ($editar) {
$acciones[] = l(t('Ver'), 'proyectosop/' . $node->nid . '/reformular/' . $reformular->id_ref . '/view');
}
if ($add_reformular) {
$acciones[] = l(t('Agregar nueva reformulación'), 'proyectosop/' . $node->nid . '/reformular/add');
}
if ($editar && $fecha && $reformular->estado != $estado_naprobado && $reformular->estado != $estado_aprobado && $reformular->id_ref) {
$acciones[] = l(t('Modificar'), 'proyectosop/' . $node->nid . '/reformular/' . $reformular->id_ref . '/edit');
}
if ($enlaces_estados && count($transitions) && $reformular->estado != $estado_aprobado) {
foreach($transitions as $id => $transition) {
$acciones[] = l(t('Enviar a @state', array('@state' => $transition)), 'proyectosop/' . $node->nid . '/reformular/' . $reformular->id_ref . '/workflow/' . $id);
}
}
$row[] = array('data' => theme('item_list', $acciones),);
$rows[] = $row;
$i++;
}
if (!count($rows)) {
$row[] = array('data' => 'No existen reformulaciones para este proyecto', 'colspan' => 9);
$rows[] = $row;
}
$output = '';
if ($node->field_acciones_ente[0]['nid']) {
$output = '' . t('Datos de la Acción Centralizada') . ' ';
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
$output .= '' . t('Ente') . ':
' . l($ente_planificador->title, 'proyectosop/' . $ente_planificador->nid) . '
';
$output .= '' . t('Año') . ':
' . $node->anhoproyectos_operativos . '
';
$output .= '' . t('Autor') . ':
' . l($node->name, 'user/' . $node->uid) . '
';
$output .= '' . t('Fecha de creación') . ':
' . format_date($node->created) . '
';
$output .= '' . t('Fecha de la última actualización') . ':
' . format_date($node->changed) . '
';
if (module_exists('workflow')) {
$states = _proyectos_operativos_reformulacion_obtiene_estados();
$first_state = _workflow_creation_state($states['wid']);
$estado = $node->_workflow == $first_state ? t('Ingresado') : $states['states'][$node->_workflow];
$output .= '' . t('Estado del proyecto') . ':
' . $estado . '
';
}
$output .= ' ';
}
$output .= '' . t('Reformulaciones del proyecto') . ' ';
$output .= theme('table', $header, $rows) . ' ';
return $output;
}
/*
* Implementation of total_reformulado_ae()
* Obtiene el monto total de las partidas de las acciones especificas
*/
function total_reformulado_ae($node, $reformula, $exclude = array()) {
$ae_l = array();
$suma_r_ae = 0;
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
if ($node->field_proyecto_accion_esp[0]['nid']) {
foreach($node->field_proyecto_accion_esp as $ae) {
$ae_l[$ae['nid']] = $ae['nid'];
if (!isset($exclude[$ae['nid']])) {
if (array_key_exists('field_accion_esp_programacion_' . $ae['nid'], $reformula)) {
foreach($reformula['field_accion_esp_programacion_' . $ae['nid']] as $montos_accion) {
foreach ($ftypes as $clave => $valor) {
$suma_r_ae += $montos_accion[$clave];
}
}
}
}
}
}
return $suma_r_ae;
}
/*
* Implementation of _proyectos_reformulacion_reformula_tab_page_ver()
*/
function _proyectos_reformulacion_reformula_tab_page_ver($node, $reformulacion_load = 0, $show_variacion = TRUE, $muestra = TRUE) {
drupal_set_title(t('Consultar Reformulación'));
global $user;
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
$current_time = time();
$add_reformular = _proyectos_reformulacion_reformula_node_add_tab_access($node);
$tipo_plan = 'proyectos_operativos_reformular';
$mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo);
$fecha = FALSE;
$ente = usuario_tiene_ente($user->uid);
if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) {
$fecha = TRUE;
}
if (!$fecha) {
if ($muestra) {
muestra_mensaje($tipo_plan, $ente_planificador->tipo);
}
}
else {
if ($ente->nid == $ente_planificador->nid) {
$fecha = TRUE;
if ($muestra) {
muestra_mensaje($tipo_plan, $ente_planificador->tipo, 0);
}
}
elseif (!user_access('admin planificador')) {
$fecha = FALSE;
}
}
$enlaces_estados = TRUE;
if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) {
$enlaces_estados = FALSE;
}
$estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL);
$editar = ($node->_workflow == $estado_aprobado);
$id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
//obtiene el total de las variaciones de las acciones especificas
$ae_l = array();
$suma_r_ae = total_reformulado_ae($node, $reformula);
$field = content_fields('field_proyecto_unidadm', 'proyectos_operativos');
$unidad_ant = $node->field_proyecto_unidadm[0]['value'];
$text_unidad = t('N/A');
$tree = taxonomy_get_tree($field['vid']);
$planificado = t('planificado');
$variacion = t('variación');
$options = array();
if ($tree) {
foreach ($tree as $term) {
if ($term->tid == $unidad_ant) {
$text_unidad = $term->name;
}
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$options[] = $choice;
}
}
$field = content_fields('field_accion_esp_unidadm', 'accion_especifica');
$unidadesm = array();
$tree = taxonomy_get_tree($field['vid']);
if ($tree) {
foreach ($tree as $term) {
$unidadesm[$term->tid] = $term->name;
}
}
$grupos = array();
if ($node->field_proyecto_accion_esp[0]['nid']) {
foreach($node->field_proyecto_accion_esp as $ae) {
$grupos[$ae['nid']] = node_load($ae['nid']);
}
}
$varia = isset($variaciones['total']) ? $variaciones['total'] : 0;
$min = $node->field_proyecto_monto_anual[0]['value'] + $varia;
$valor = isset($reformula['total'])? $reformula['total'] : 0;
$total_accion = $min;
if (module_exists('workflow')) {
$estados = _proyectos_operativos_reformulacion_obtiene_estados();
}
$mes = 2;
$planificado = t('planificado');
$variacion = t('variación');
$subtotal = t('Total AE');
$output = '';
if ($suma_r_ae != $reformula['total']) {
$output .= '' . t('El monto de la variación del proyecto (%monto_total_proyecto) es diferente al total de las variaciones de las Acciones Específicas (%monto_total_ae)', array('%monto_total_proyecto' => number_format($reformula['total'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '%monto_total_ae' => number_format($suma_r_ae, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']))) . '
';
}
$output .= '' . t('Resumen del Proyecto') . ' ';
$output .= '' . t('Código Único del Proyecto') . ':
' . $node->field_proyecto_codigo[0]['value'] . '
';
$output .= '' . t('Nombre del Proyecto') . ':
' . $node->titulo_asignado . '
';
$output .= '' . t('Organismo') . ':
' . $ente_planificador->title . '
';
$output .= ' ';
$output .= '' . t('Datos de la Reformulación') . ' ';
$states = array();
if (module_exists('workflow')) {
$states = _proyectos_operativos_reformulacion_obtiene_estados();
$header = array();
$header[] = array('data' => t('Fecha'),);
$header[] = array('data' => t('Estado'),);
$header[] = array('data' => t('Estado anterior'),);
$header[] = array('data' => t('Comentario'),);
$header[] = array('data' => t('Usuario'),);
$rows = array();
$result = db_query('SELECT re.*, u.name, u.uid FROM {proyectos_reformular_state} re INNER JOIN {users} u ON u.uid = re.uid WHERE nid = %d AND id_ref = %d ORDER BY date DESC', $node->nid, $id_ref);
while($history = db_fetch_object($result)) {
$row = array();
$row[] = array('data' => format_date($history->date),);
$row[] = array('data' => $states['states'][$history->estado],);
$row[] = array('data' => $states['states'][$history->estado_ant],);
$row[] = array('data' => $history->comentario,);
$row[] = array('data' => l($history->name, 'user/' . $history->uid),);
$rows[] = $row;
}
if (count($rows)) {
$output .= '' . t('Historial') . ':
' . theme('table', $header, $rows) . '
';
}
else {
$output .= '' . t('Historial') . ':
' . t('No existe historial para esta reformulación') . '
';
}
}
$output .= ' ';
$output .= '' . t('Monto Total del Proyecto') . ' ';
$rows = array();
$row = array();
$row[] = array('data' => t('Fecha de Aprobación: %fecha_onapre', array('%fecha_onapre' => date( 'd/m/Y', $reformula['fecha_onapre']))), 'align' => 'left');
$row[] = array('data' => t('Justificación: %justificacion', array('%justificacion' => $reformula['justificacion'])), 'align' => 'left');
$rows[] = $row;
$row = array();
$row[] = array('data' => '' . t('Monto Total del Proyecto para el año en curso: %monto', array('%monto' => number_format($total_accion, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']))) . ' ', 'colspan' => 2, 'align' => center);
$rows[] = $row;
$row = array();
$signo = '';
if ($reformulacion_load->variacion > 0) {
$signo = '+';
}
$row[] = array('data' => t('Variación Presupuestaria: %variacion', array('%variacion' => $signo . number_format($reformulacion_load->variacion, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']))), );
$row[] = array('data' => t('Monto Total Reformulación: %totalreformulacion', array('%totalreformulacion' => number_format($reformulacion_load->variacion + $total_accion, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']))), );
$rows[] = $row;
$output .= theme('table', array(), $rows) . ' ';
$output .= '' . t('Distribución de la Meta Física') . ' ';
$output .= '' . t('Meta Física del Proyecto') . ' ';
$output .= '' . t('Unidad de Medida Anterior') . ':
' . $unidadesm[$node->field_proyecto_unidadm[0]['value']] . '
';
$output .= '' . t('Unidad de Medida Nueva') . ':
' . $unidadesm[$reformulacion_load->unidad] . '
';
$header = array();
$header[] = array('data' => t('Meta Física del Proyecto'));
$rows = array();
$row = array();
$row1 = array();
$row2 = array();
$row[] = array('data' => $planificado, );
$row1[] = array('data' => $variacion, );
$row2[] = array('data' => '' . t('TOTAL') . ' ', );
$total = 0;
$total1 = 0;
foreach($ftypes as $id_field => $texto) {
$header[] = array('data' => $texto);
$varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0;
$min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia;
$valor = isset($reformula['field_proyecto_meta_fisica'][0][$id_field])? $reformula['field_proyecto_meta_fisica'][0][$id_field] : 0;
$signo = '';
if ($valor > 0) {
$signo = '+';
}
$total += $min;
$total1 += $valor;
$row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => $signo . number_format($valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row2[] = array('data' => number_format($min + $valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($total, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => number_format($total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row2[] = array('data' => number_format($total + $total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$rows[] = $row1;
$rows[] = $row2;
$header[] = array('data' => t('TOTAL'));
$output .= theme('table', $header, $rows);
$output .= ' ';
$output .= '' . t('Meta Física de las Acciones Específicas') . ' ';
$header = array();
$header[] = array('data' => t('Meta Física de las AEs'));
$header[] = array('data' => t('Unidad de Medida'));
$header[] = array('data' => t('% de la AEs'),);
$header[] = array('data' => '-',);
foreach($ftypes as $id_field => $texto) {
$header[] = array('data' => $texto);
}
$header[] = array('data' => t('TOTAL'));
$rows = array();
$rowsF = array();
$i = 0;
$rowF = array();
$rowF[] = array('data' => '' . t('Número') . ' ', 'align' => center,);
$rowF[] = array('data' => '' . t('Nombre') . ' ', 'align' => center,);
$rowF[] = array('data' => '' . t('Acción') . ' ', 'align' => center,);
$rowsF[] = $rowF;
$totalA = array();
$totalT;
foreach($grupos as $nid => $grupo) {
$i++;
$row = array();
$rowF = array();
$row1 = array();
$row2 = array();
$rowF[] = array('data' => t('AE %numero', array('%numero' => $i)));
$rowF[] = array('data' => $grupo->titulo_asignado);
$links = array();
$links[] = l(t('Ver reformulación'), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/ae/' . $grupo->nid);
if (_proyectos_reformulacion_reformula_node_edit_tab_access($node, $reformulacion_load)) {
$links[] = l(t('Reformular'), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/ae/' . $grupo->nid . '/edit');
}
$rowF[] = array('data' => theme('item_list', $links),);
$rowsF[] = $rowF;
$row[] = array('data' => t('AE %numero', array('%numero' => $i)), 'rowspan' => 3);
$row[] = array('data' => t('Unidad de Medida Anterior: %umedida', array('%umedida' => $unidadesm[$grupo->field_accion_esp_unidadm[0]['value']])) . ' '. t('Unidad de Medida Nueva: %umedida', array('%umedida' => $unidadesm[$reformula['field_accion_esp_metaf_' . $nid][0]['unidad']])), 'rowspan' => 3);
$row[] = array('data' => $grupo->field_accion_esp_ponderacion[0]['value'], 'rowspan' => 3);
$row[] = array('data' => $planificado, );
$row1[] = array('data' => $variacion, );
$row2[] = array('data' => $subtotal);
$total = 0;
$total1 = 0;
foreach($ftypes as $id_field => $texto) {
$varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0;
$min = $grupo->field_accion_esp_metaf[0][$id_field] + $varia;
$valor = isset($reformula['field_accion_esp_metaf_' . $nid][0][$id_field])? $reformula['field_accion_esp_metaf_' . $nid][0][$id_field] : 0;
$signo = '';
if ($valor > 0) {
$signo = '+';
}
$total += $min;
$total1 += $valor;
if (!isset($totalA[$id_field])) {
$totalA[$id_field] = 0;
}
$totalA[$id_field] += $min + $valor;
$totalT += $min + $valor;
$row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => $signo . number_format($valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row2[] = array('data' => number_format($min + $valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($total, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => number_format($total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row2[] = array('data' => number_format($total + $total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$rows[] = $row1;
$rows[] = $row2;
}
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ' ', 'colspan' => 4, 'align' => 'right');
foreach($ftypes as $id_field => $texto) {
$row[] = array('data' => number_format($totalA[$id_field], 0, $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($totalT, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$output .= theme('table', $header, $rows);
$header = array();
$header[] = array('data' => t('Detalles de las Acciones Específicas'), 'colspan' => 3, 'align' => center);
$output .= theme('table', $header, $rowsF);
$output .= ' ';
$output .= ' ';
if ($show_variacion) {
$links = array();
if ($editar) {
$links[] = l(t('Reformulaciones'), 'proyectosop/' . $node->nid . '/reformular');
}
if ($add_reformular) {
$links[] = l(t('Agregar nueva reformulación'), 'proyectosop/' . $node->nid . '/reformular/add');
}
if (isset($states['wid'])) {
$estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);
if (_proyectos_reformulacion_reformula_node_edit_tab_access($node, $reformulacion_load) && $editar && $fecha && $reformulacion_load->estado != $estado_naprobado && $reformulacion_load->estado != $estado_aprobado && $reformulacion_load->id_ref) {
$links[] = l(t('Modificar'), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/edit');
}
$first_state = 0;
if ($states['wid']) {
$first_state = _workflow_creation_state($states['wid']);
}
if ($user->uid == 1) {
// Superuser is special.
$roles = 'ALL';
}
else {
$roles = array_keys($user->roles);
$roles_transition = $roles;
if ($user->uid == $reformulacion_load->uid && $reformulacion_load->uid > 0) {
$roles += array('author' => 'author');
}
}
$transitions = array();
if ($states['wid']) {
$transitions = workflow_allowable_transitions($reformulacion_load->estado, 'to', $roles);
}
unset($transitions[$reformulacion_load->estado]);
if ($suma_r_ae == $reformula['total'] && $enlaces_estados && count($transitions) && $estado_aprobado != $reformulacion_load->estado) {
foreach($transitions as $id => $transition) {
$links[] = l(t('Enviar a @state', array('@state' => $transition)), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/workflow/' . $id);
}
}
}
$output .= '' . t('Acciones') . ':
' . implode(' | ', $links) . '
';
}
return $output;
}
/*
* Implementation of proyectos_reformulacion_reformula_tab_page_ae_form()
* Formulario para reformular las acciones especificas
*/
function proyectos_reformulacion_reformula_tab_page_ae_form($form_state, $node, $reformulacion_load = 0, $ae = 0) {
drupal_set_title(t('Reformular A.E.'));
$form = array();
$proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
$proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion');
drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js');
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
$partidas_nodo = array();
foreach ($ae->field_accion_esp_programacion as $partida) {
if(!empty($partida['tid'])) {
$partidas_nodo[$partida['tid']] = $partida;
}
}
$id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
$field = content_fields('field_accion_esp_programacion', 'accion_especifica');
$tree = taxonomy_get_tree($field['vid']);
$vtid = $field['vtid'];
$partidas = array();
if ($tree) {
foreach ($tree as $term) {
if (isset($vtid[$term->tid])) {
$partidas[$term->tid] = $term->name;
}
}
}
//$form['#mes'] = variable_get('accion_especifica_de_proyecto_seguimiento_mes_seguimiento', 0);
$form['#mes'] = variable_get('accion_especifica_de_proyecto_seguimiento_anho_seguimiento', 0) == $node->anhoproyectos_operativos ? variable_get('accion_especifica_de_proyecto_seguimiento_mes_seguimiento', 0) - 1 : 0;
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
$form['#format_number'] = array('format_number' => $format_number);
drupal_add_js($form['#format_number'], 'setting');
$totales = array();
$totalT = 0;
$plant = array();
$sumaplan = 0;
$sumaplanm = array();
foreach($partidas as $tid => $term) {
$total = 0;
$total1 = 0;
$i = 1;
foreach($ftypes as $id_field => $texto) {
$varia = isset($variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0;
$min = $partidas_nodo[$tid][$id_field] + $varia;
$valor = isset($reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field])? $reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0;
$total1 += $valor;
$totalT += $min + $valor;
if (!isset($plant[$tid])) {
$plant[$tid] = 0;
}
$plant[$tid] += $min;
$sumaplan += $min;
if (!isset($totales[$id_field])) {
$totales[$id_field] = 0;
}
if (!isset($sumaplanm[$id_field])) {
$sumaplanm[$id_field] = 0;
}
$sumaplanm[$id_field] += $min;
$totales[$id_field] += $min + $valor;
$idformu = $ae->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field;
$idformuj = str_replace('_', '-', $idformu);
$clase = '';
if ($form['#mes'] >= $i) {
$clase = 'campo-bloqueado ';
}
$form[$idformu] = array(
'#type' => 'textfield',
'#default_value' => $valor,
'#size' => 15,
'#attributes' => array('class' => $clase . 'field-accion-esp-programacion-r-' . $tid . ' subtotal-' . $id_field . ' number', 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref('" . 'field-accion-esp-programacion-r-' . $tid . "');prsumaref2('" . 'subtotal-' . $id_field . "', 'sumaplan', '" . $id_field . "'); prsumaref('subtotales')", 'valor' => $min, 'indice' => $i - 1, 'taxonomia' => $tid, 'nodo' => $ae->nid),
);
$i++;
}
$form[$ae->nid . '_field_accion_esp_programacion_' . $tid . '_t'] = array(
'#type' => 'textfield',
'#default_value' => $total1,
'#size' => 15,
'#attributes' => array('class' => 'number1 campo-bloqueado field-accion-esp-programacion-r-' . $tid . '-total'),
);
}
foreach($ftypes as $id_field => $texto) {
$form[$ae->nid . '_field_accion_esp_programacion_t_' . $id_field] = array(
'#type' => 'textfield',
'#default_value' => $totales[$id_field],
'#size' => 15,
'#attributes' => array('class' => 'number1 campo-bloqueado subtotales subtotal-' . $id_field . '-total'),
);
}
$form[$ae->nid . '_field_accion_esp_programacion_t'] = array(
'#type' => 'textfield',
'#default_value' => $totalT,
'#size' => 15,
'#attributes' => array('class' => 'number1 campo-bloqueado subtotales-total'),
);
//financiamiento
$arreglo_financiamiento = array();
$accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4);
for($i = 0; $i < $accion_especifica_number_fields; $i++) {
$arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : '';
$arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array());
}
$form['#plant'] = $plant;
$form['#partidas_nodo'] = $partidas_nodo;
$form['#arreglo'] = $arreglo_financiamiento_fields;
$form['#ftypes'] = $ftypes;
$form['#partidas'] = $partidas;
$form['#node'] = $node;
$form['#variaciones'] = $variaciones;
$form['#reformula'] = $reformula;
$form['#id_ref'] = $id_ref;
$form['#ae'] = $ae;
$form['#reformula_load'] = $reformulacion_load;
$suma_r_ae = total_reformulado_ae($node, $reformula, array($ae->nid => 1));
$monto_asignar = $form['#reformula_load']->variacion - $suma_r_ae;
$form['#monto_asignar'] = $monto_asignar;
$total = 0;
$sumafinm = array();
$sumatotalf = 0;
foreach($arreglo_financiamiento as $id_items => $titulo) {
$form[$id_items] = array(
'#type' => 'fieldset',
'#title' => $titulo,
);
$total1 = 0;
foreach($arreglo_financiamiento_fields[$id_items] as $id1) {
if ($id1) {
$id_items1 = str_replace('_', '-', $id_items);
$varia = isset($variaciones[$id1 . '_' . $ae->nid][0]['value']) ? $variaciones[$id1 . '_' . $ae->nid][0]['value'] : 0;
$min = $ae->{$id1}[0]['value'] + $varia;
if (!isset($sumafinm[$id_items1])) {
$sumafinm[$id_items1] = 0;
}
$valor = isset($reformula[$id1 . '_' . $ae->nid][0]['value'])? $reformula[$id1 . '_' . $ae->nid][0]['value'] : 0;
$sumafinm[$id_items1] += $min;
$sumatotalf += $min;
$field = content_fields($id1, 'accion_especifica');
$total1 += $valor;
$total += $valor;
$idformuj = str_replace('_', '-', $id1);
$form[$id_items][$id1] = array(
'#type' => 'textfield',
'#default_value' => $valor,
'#size' => 20,
'#prefix' =>'' . $field['widget']['label'] . ': ' . t('Planificado') . ': ' . number_format($min, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
' . t('Variación') . ':
',
'#attributes' => array('class' => 'number subtotalff-' . $id_items1, 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref2('" . 'subtotalff-' . $id_items1 . "', 'financia', '" . $id_items1 . "'); prsumaref('subtotalesf')"),
);
}
}
$form['totalf_' . $id_items] = array(
'#type' => 'textfield',
'#default_value' => $sumafinm[$id_items1],
'#size' => 20,
'#attributes' => array('class' => 'number1 campo-bloqueado subtotalesf subtotalff-' . $id_items1 . '-total'),
);
}
$form['total_financiamiento'] = array(
'#type' => 'textfield',
'#default_value' => $sumatotalf,
'#size' => 20,
'#attributes' => array('class' => 'number1 campo-bloqueado subtotalesf-total'),
);
$jse = array(
'sumatotal' => $sumaplan,
'sumaplan' => $sumaplanm,
'financia' => $sumafinm,
'sumatotalf' => $sumatotalf,
);
$form['#jse'] = $jse;
drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting');
$form['buttons'] = array(
'#prefix' => '',
'#suffix' => '
',
);
$form['buttons']['registrar'] = array(
'#type' => 'submit',
'#default_value' => t('Guardar'),
'#weight' => 100,
);
$form['buttons']['cancelar'] = array(
'#type' => 'submit',
'#default_value' => t('Cancelar'),
'#weight' => 101,
);
return $form;
}
/*
* Implementation of proyectos_reformulacion_reformula_tab_page_ae_form_validate()
*/
function proyectos_reformulacion_reformula_tab_page_ae_form_validate($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancelar')) {
return;
}
$proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
$proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion');
drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js');
//drupal_add_js($form['#format_number'], 'setting');
//drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting');
//se obtienen la suma de la meta fisica
$mf = $form['#jse']['sumatotal'];
foreach($form['#partidas'] as $tid => $grupo) {
foreach($form['#ftypes'] as $id_field => $texto) {
$varia = isset($form['#variaciones']['field_accion_esp_programacion_' . $form['#ae']->nid][$tid][$id_field]) ? $form['#variaciones']['field_accion_esp_programacion_' . $form['#ae']->nid][$tid][$id_field] : 0;
$min = $form['#partidas_nodo'][$tid][$id_field] + $varia;
$start = $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field];
$value = preg_replace('@[^-0-9]@', '', $start);
if ($start != $value) {
form_set_error($form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field, t('Solo números enteros son permitidos en la reformulación de la partida #nombre.', array('#nombre' => $form['#partidas'][$tid])));
}
if ($form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field] + $min < 0) {
form_set_error($form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field, t('El valor para reformular de la partida #nombre no puede ser menor que cero', array('#nombre' => $form['#partidas'][$tid])));
}
$mf += $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field];
}
}
$finan = $form['#jse']['sumatotalf'];
//se obtiene la suma del financiamiento
foreach($form['#arreglo'] as $id => $arreglo1) {
foreach($arreglo1 as $id1) {
$varia = isset($form['#variaciones'][$id1 . '_' . $form['#ae']->nid][0]['value']) ? $form['#variaciones'][$id1 . '_' . $form['#ae']->nid][0]['value'] : 0;
$min = $form['#ae']->{$id1}[0]['value'] + $varia;
$start = $form_state['values'][$id1];
$value = preg_replace('@[^-0-9]@', '', $start);
if ($start != $value) {
form_set_error($id1, t('Solo números enteros son permitidos en la fuente de financiamiento #nombre.', array('#nombre' => $form[$id1]['#title'])));
}
if ($form_state['values'][$id1] + $min < 0) {
form_set_error($id1, t('El valor para reformular de la fuente de financiamiento #nombre no puede ser menor que cero', array('#nombre' => $form[$id1]['#title'])));
}
$finan += $form_state['values'][$id1];
}
}
if ($mf != $finan) {
form_set_error($form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field, t('La suma de la Programación Financiera (#valor) debe ser igual a las Fuentes de Financiamiento (#valor1)', array('#valor' => $mf, '#valor1' => $finan)));
}
}
/*
* Implementation of proyectos_reformulacion_reformula_tab_page_ae_form_validate()
*/
function proyectos_reformulacion_reformula_tab_page_ae_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op == t('Cancelar')) {
drupal_set_message(t('La reformulación ha sido cancelada.'));
$form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#id_ref']. '/ae/' . $form['#ae']->nid;
return;
}
db_query("DELETE FROM {proyectos_reformula} WHERE nid = %d AND id_ref = %d AND ae = %d", $form['#node']->nid, $form['#id_ref'], $form['#ae']->nid);
db_query("DELETE FROM {proyectos_reformula_fuente} WHERE nid = %d AND id_ref = %d AND ae = %d", $form['#node']->nid, $form['#id_ref'], $form['#ae']->nid);
foreach($form['#partidas'] as $tid => $grupo) {
$suma = 0;
$field = array();
$field[] = $form['#id_ref'];
$field[] = 'field_accion_esp_programacion_' . $form['#ae']->nid;
$field[] = $tid;
$field[] = $form['#node']->nid;
foreach($form['#ftypes'] as $id_field => $texto) {
$suma += $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field];
$field[] = $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field];
}
if ($suma) {
$field[] = $form['#ae']->nid;
db_query("INSERT INTO {proyectos_reformula} (id_ref, field_name, partida, nid, value, value_1, value_2, value_3, value_4, value_5, value_6, value_7, value_8, value_9, value_10, value_11, ae) VALUES (%d, '%s', %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %d)", $field);
}
}
foreach($form['#arreglo'] as $id => $arreglo1) {
foreach($arreglo1 as $id1) {
if ($form_state['values'][$id1]) {
$field = array();
$field[] = $form['#id_ref'];
$field[] = $id1 . '_' . $form['#ae']->nid;
$field[] = $form['#node']->nid;
$field[] = $form['#ae']->nid;
$field[] = $form_state['values'][$id1];
db_query("INSERT INTO {proyectos_reformula_fuente} (id_ref, field_name, nid, ae, value) VALUES (%d, '%s', %d, %d, %f)", $field);
}
}
}
drupal_set_message(t('Se modifico la formulación de la acción específica @nombre', array('@nombre' => $form['#ae']->titulo_asignado)));
$form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#id_ref'] . '/ae/' . $form['#ae']->nid;
}
/*
* Implementation of theme_proyectos_reformulacion_reformula_tab_page_form()
*/
function theme_proyectos_reformulacion_reformula_tab_page_ae_form($form) {
$planificado = t('planificado');
$variacion = t('variación');
$totalAEtexto = t('Total AE');
$output = '';
if ($form['#monto_asignar'] != 0) {
$output .= '' . t('Usted puede asignar hasta %monto_total_ae para la variación de esta Acción Específica', array('%monto_total_ae' => number_format($form['#monto_asignar'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))) . '
';
}
else {
$output .= '' . t('Ya el monto del proyecto ha sido asignado a otras Acciones Específicas') . '
';
}
$output .= '' . t('Resumen Financiero de las Acciones') . ' ';
$header = array();
$header[] = array('data' => t('Partidas'), 'colspan' => 2);
foreach($form['#ftypes'] as $id_field => $texto) {
$header[] = array('data' => $texto);
}
$header[] = array('data' => t('TOTAL'));
$rows = array();
$rowsF = array();
$i = 0;
foreach($form['#partidas'] as $tid => $grupo) {
$i++;
$row = array();
$row1 = array();
$row2 = array();
$row[] = array('data' => $grupo, 'rowspan' => 3);
$row[] = array('data' => $planificado, );
$row1[] = array('data' => $variacion, );
$row2[] = array('data' => $totalAEtexto, );
$totales_partida = 0;
foreach($form['#ftypes'] as $id_field => $texto) {
$varia = isset($form['#variaciones']['field_accion_esp_programacion_' . $form['#ae']->nid][$tid][$id_field]) ? $form['#variaciones']['field_accion_esp_programacion_' . $form['#ae']->nid][$tid][$id_field] : 0;
$min = $form['#partidas_nodo'][$tid][$id_field] + $varia;
$totales_partida += $min;
}
foreach($form['#ftypes'] as $id_field => $texto) {
$idformu = $form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field;
$idformuj = str_replace('_', '-', $idformu);
$varia = isset($form['#variaciones']['field_accion_esp_programacion_' . $form['#ae']->nid][$tid][$id_field]) ? $form['#variaciones']['field_accion_esp_programacion_' . $form['#ae']->nid][$tid][$id_field] : 0;
$min = $form['#partidas_nodo'][$tid][$id_field] + $varia;
$form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]['#attributes']['onchange'] .= ";sumatotalAE('" . $idformuj . "'," . $min . ")";
$form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]['#attributes']['onchange'] .= ";sumatotalAE('" . $form['#ae']->nid . '-field-accion-esp-programacion-' . $tid . '-t' . "'," . $totales_partida . ");";
$form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]['#attributes']['total_partida'] = $totales_partida;
$row[] = array('data' => number_format($min, 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), );
$row1[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]), );
$row2[] = array('data' => '' . number_format($min, 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
', );
}
$row[] = array('data' => number_format($form['#plant'][$tid], 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), );
$row1[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_t']), );
$row2[] = array('data' => '' . number_format($form['#plant'][$tid], 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '
', );
$rows[] = $row;
$rows[] = $row1;
$rows[] = $row2;
}
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ' ', 'colspan' => 2, 'align' => 'right');
foreach($form['#ftypes'] as $id_field => $texto) {
$row[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_t_' . $id_field]), );
}
$row[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_t']), );
$rows[] = $row;
$output .= theme('table', $header, $rows);
$output .= ' ';
$rows = array();
$row = array();
$row1 = array();
foreach($form['#arreglo'] as $id => $arreglo1) {
$row[] = array('data' => drupal_render($form[$id]), );
$row1[] = array('data' => drupal_render($form['totalf_' . $id]), );
}
$rows[] = $row;
$rows[] = $row1;
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ': ', 'colspan' => 3, 'align' => 'right');
$row[] = array('data' => drupal_render($form['total_financiamiento']), );
$rows[] = $row;
$output .= '' . t('Distribución por fuentes de Financiamiento') . ' ' . theme('table', array(), $rows) . ' ';
$output .= '' . drupal_render($form) .'
';
return $output;
}
/*
* Implementation of _proyectos_reformulacion_reformula_tab_page_ver_ae()
*/
function _proyectos_reformulacion_reformula_tab_page_ver_ae($node, $reformulacion_load = 0, $ae = 0) {
drupal_set_title(t('Consultar Reformulación de A.E.'));
$planificado = t('planificado');
$format_number = array(
'decimals' => variable_get('proyectos_operativos_number_decimals', 0),
'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','),
'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'),
);
$variacion = t('variación');
$subtotal = t('Total AE');
$ftypes = array(
'value' => t('January'),
'value_1' => t('February'),
'value_2' => t('March'),
'value_3' => t('April'),
'value_4' => t('May'),
'value_5' => t('June'),
'value_6' => t('July'),
'value_7' => t('August'),
'value_8' => t('September'),
'value_9' => t('Octuber'),
'value_10' => t('November'),
'value_11' => t('December'),
);
$partidas_nodo = array();
foreach ($ae->field_accion_esp_programacion as $partida) {
if(!empty($partida['tid'])) {
$partidas_nodo[$partida['tid']] = $partida;
}
}
$id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0;
$reformula = _proyectos_reformulacion_load($node, $id_ref);
$variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref);
$field = content_fields('field_accion_esp_programacion', 'accion_especifica');
$tree = taxonomy_get_tree($field['vid']);
$vtid = $field['vtid'];
$partidas = array();
$suma_r_ae = total_reformulado_ae($node, $reformula);
if ($tree) {
foreach ($tree as $term) {
if (isset($vtid[$term->tid])) {
$partidas[$term->tid] = $term->name;
}
}
}
//financiamiento
$arreglo_financiamiento = array();
$accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4);
for($i = 0; $i < $accion_especifica_number_fields; $i++) {
$arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : '';
$arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array());
}
/*
$arreglo = array();
$titles = array(
'ordinarios' => t('Recursos Ordinarios'),
'propios' => t('Recursos Propios'),
'transferencias' => t('Donaciones'),
'otros' => t('Otros'),
);
$titles_field = array(
'field_accion_esp_transferencias' => t('Recursos Ordinarios'),
'field_accion_esp_creditosa' => t('Recursos Propios'),
'transferencias' => t('Donaciones'),
'otros' => t('Otros'),
);
$arreglo['ordinarios'] = array(
'field_accion_esp_transferencias' => 'field_accion_esp_transferencias',
'field_accion_esp_creditosa' => 'field_accion_esp_creditosa',
'field_accion_esp_mcti' => 'field_accion_esp_mcti',
);
$arreglo['propios'] = array(
'field_accion_esp_venta_act' => 'field_accion_esp_venta_act',
'field_accion_esp_activos' => 'field_accion_esp_activos',
'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja',
'field_accion_esp_ventapro' => 'field_accion_esp_ventapro',
);
$arreglo['transferencias'] = array(
'field_accion_esp_donaciones' => 'field_accion_esp_donaciones',
);
$arreglo['otros'] = array(
'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion',
'field_accion_esp_misionc' => 'field_accion_esp_misionc',
'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona',
'field_accion_esp_fonacit' => 'field_accion_esp_fonacit',
'field_accion_esp_fonden' => 'field_accion_esp_fonden',
'field_accion_esp_locti' => 'field_accion_esp_locti',
'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi',
'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie',
'field_accion_esp_infocentro' => 'field_accion_esp_infocentro',
'field_accion_esp_fidetel' => 'field_accion_esp_fidetel',
);
*/
$output = '';
$ente_planificador = node_load($node->field_proyecto_ente[0]['nid']);
if ($suma_r_ae != $reformula['total']) {
$output .= '' . t('El monto de la variación del proyecto (%monto_total_proyecto) es diferente al total de las variaciones de las Acciones Específicas (%monto_total_ae)', array('%monto_total_proyecto' => number_format($reformula['total'], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), '%monto_total_ae' => number_format($suma_r_ae, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']))) . '
';
}
$output .= '' . t('Resumen del Proyecto') . ' ';
$output .= '' . t('Código Único del Proyecto') . ':
' . $node->field_proyecto_codigo[0]['value'] . '
';
$output .= '' . t('Nombre del Proyecto') . ':
' . $node->titulo_asignado . '
';
$output .= '' . t('Organismo') . ':
' . $ente_planificador->title . '
';
$output .= ' ';
$output .= '' . t('Resumen Financiero de las Acciones') . ' ';
$header = array();
$header[] = array('data' => t('Partidas'), 'colspan' => 2);
foreach($ftypes as $id_field => $texto) {
$header[] = array('data' => $texto);
}
$header[] = array('data' => t('TOTAL'));
$rows = array();
$rowsF = array();
$i = 0;
$totales = array();
$totalT = 0;
$plant = array();
$sumaplan = 0;
$sumaplanm = array();
foreach($partidas as $tid => $grupo) {
$i++;
$total = 0;
$total1 = 0;
$row = array();
$row1 = array();
$row2 = array();
$row[] = array('data' => $grupo, 'rowspan' => 3);
$row[] = array('data' => $planificado, );
$row1[] = array('data' => $variacion, );
$row2[] = array('data' => $subtotal, );
foreach($ftypes as $id_field => $texto) {
$varia = isset($variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0;
$min = $partidas_nodo[$tid][$id_field] + $varia;
$valor = isset($reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field])? $reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0;
$signo = '';
if ($valor > 0) {
$signo = '+';
}
$total1 += $valor;
$totalT += $min + $valor;
if (!isset($plant[$tid])) {
$plant[$tid] = 0;
}
$plant[$tid] += $min;
$sumaplan += $min;
if (!isset($totales[$id_field])) {
$totales[$id_field] = 0;
}
if (!isset($sumaplanm[$id_field])) {
$sumaplanm[$id_field] = 0;
}
$sumaplanm[$id_field] += $min;
$totales[$id_field] += $min + $valor;
$idformu = $ae->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field;
$idformuj = str_replace('_', '-', $idformu);
$row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => $signo . number_format($valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row2[] = array('data' => number_format($min + $valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($plant[$tid], 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row1[] = array('data' => number_format($total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$row2[] = array('data' => number_format($plant[$tid] + $total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$rows[] = $row1;
$rows[] = $row2;
}
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ' ', 'colspan' => 2, 'align' => 'right');
foreach($ftypes as $id_field => $texto) {
$row[] = array('data' => number_format($totales[$id_field], 0, $format_number['dec_point'], $format_number['thousands_sep']), );
}
$row[] = array('data' => number_format($totalT, 0, $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$output .= theme('table', $header, $rows);
$output .= ' ';
$rows = array();
$row = array();
$row1 = array();
$sumalT = 0;
foreach($arreglo_financiamiento as $id_items => $titulo) {
$sumal = 0;
$output1 = '';
foreach($arreglo_financiamiento_fields[$id_items] as $id1) {
if ($id1) {
$field = content_fields($id1, 'accion_especifica');
$varia = isset($variaciones[$id1 . '_' . $ae->nid][0]['value']) ? $variaciones[$id1 . '_' . $ae->nid][0]['value'] : 0;
$min = $ae->{$id1}[0]['value'] + $varia;
if (!isset($sumafinm[$id_items])) {
$sumafinm[$id_items] = 0;
}
$sumafinm[$id_items] += $min;
$sumatotalf += $min;
$field = content_fields($id1, 'accion_especifica');
$valor = isset($reformula[$id1 . '_' . $ae->nid][0]['value'])? $reformula[$id1 . '_' . $ae->nid][0]['value'] : 0;
$total1 += $valor;
$total += $valor;
$sumal += $min + $valor;
$sumalT += $min + $valor;
$idformuj = str_replace('_', '-', $id1);
$signo = '';
if ($valor > 0) {
$signo = '+';
}
$output1 .= '' . $field['widget']['label'] . ':
' . '
' . t('Planificado') . ': ' . number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']) . '
' . t('Variación') . ': ' . $signo . number_format($valor, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '
' . '
';
}
}
$row[] = array('data' => $output1, );
$row1[] = array('data' => number_format($sumal, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
}
$rows[] = $row;
$rows[] = $row1;
$row = array();
$row[] = array('data' => '' . t('TOTAL') . ': ', 'colspan' => 3, 'align' => 'right');
$row[] = array('data' => number_format($sumalT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), );
$rows[] = $row;
$output .= '' . t('Distribución por fuentes de Financiamiento') . ' ' . theme('table', array(), $rows) . ' ';
return $output;
}