[303fae2] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
| 4 | * @file proyectos_reformulacion.module |
---|
| 5 | * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
| 6 | * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or modify |
---|
| 9 | * it under the terms of the GNU General Public License as published by |
---|
| 10 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | * (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 21 | * |
---|
| 22 | * @author Cenditel Merida - Msc. Juan Vizcarrondo |
---|
| 23 | * @date 2013-04-11 // (año-mes-dia) |
---|
| 24 | * @version 0.1 // (0.1) |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * Implementation of hook_ente_procesos_alter() |
---|
| 30 | */ |
---|
| 31 | function proyectos_reformulacion_ente_procesos_alter(&$procesos, $type) { |
---|
| 32 | if ($type != 'status') { |
---|
| 33 | $procesos['proyectos_operativos_reformular'] = array( |
---|
| 34 | 'title' => t('Reformular los proyectos Operativos'), |
---|
| 35 | 'description' => t('Permite reformular los proyectos Operativos'), |
---|
| 36 | 'message' => 'Se podrá registrar y/o modificar la reformulación de los proyectos Operativos desde %fecha hasta la fecha %fecha1', |
---|
| 37 | '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)', |
---|
| 38 | 'weight' => 4, |
---|
| 39 | 'proceso' => 'proyectos_operativos', |
---|
| 40 | ); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /* |
---|
| 45 | * Implementation of acciones_centralizadas_status_planificacion_acciones_centralizadas() |
---|
| 46 | */ |
---|
| 47 | function proyectos_reformulacion_status_planificacion_proyectos_operativos($ente_planificador, $tipo = 2) { |
---|
| 48 | $datos_proyectos_reformulacion_status = array(); |
---|
| 49 | //si existe al menos una reformulacion en estado aprobado la reformulacion se puede considerar terminado |
---|
| 50 | $reformular = FALSE; |
---|
| 51 | $year = variable_get('proyectos_operativos_anho_creacion', 0); |
---|
| 52 | $estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL);; |
---|
| 53 | $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); |
---|
| 54 | $reformular = db_fetch_object($result); |
---|
| 55 | $reformular = $reformular->cantidad; |
---|
| 56 | $datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['value'] = ($reformular) ? 1 : 0; |
---|
| 57 | $datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['title'] = t('Reformulaciones para el año @year', array('@year' => $year)); |
---|
| 58 | $datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['link'] = 'proyectos_operativos'; |
---|
| 59 | $datos_acciones_centralizadas_status['proyectos_operativos_reformular']['mylink'] = 'proyectos_operativos'; |
---|
| 60 | $datos_proyectos_reformulacion_status['proyectos_operativos_reformular']['weight'] = -9; |
---|
| 61 | return $datos_proyectos_reformulacion_status; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /* |
---|
| 65 | * Implementation of hook_nodeapi() |
---|
| 66 | */ |
---|
| 67 | function proyectos_reformulacion_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
---|
| 68 | switch ($op) { |
---|
| 69 | case 'view': |
---|
| 70 | if ($node->type == 'proyectos_operativos') { |
---|
| 71 | $format_number = array( |
---|
| 72 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 73 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 74 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 75 | ); |
---|
| 76 | //se obtiene la reformulacion |
---|
| 77 | $variaciones = _proyectos_reformula_all_partidas_load($node); |
---|
| 78 | $varia = isset($variaciones['total']) ? $variaciones['total'] : 0; |
---|
| 79 | //se obtiene el monto anual del proyecto |
---|
| 80 | $min = $node->field_proyecto_monto_anual[0]['value'] + $varia; |
---|
| 81 | $node->content['proyectos_operativos_monto_anual_reformulado'] = array( |
---|
| 82 | '#value' => '<div class="field"><div class="field-label">' . t('Monto Total del Proyecto para el año en curso') . ':</div>' . number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '</div>', |
---|
| 83 | '#weight' => 100, |
---|
| 84 | ); |
---|
| 85 | //se obtiene el monto total del proyecto |
---|
| 86 | $min = $node->field_proyecto_total[0]['value'] + $varia; |
---|
| 87 | $node->content['proyectos_operativos_monto_total_reformulado'] = array( |
---|
| 88 | '#value' => '<div class="field"><div class="field-label">' . t('Monto Total del Proyecto') . ':</div>' . number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '</div>', |
---|
| 89 | '#weight' => 100, |
---|
| 90 | ); |
---|
| 91 | $unidad_medida = isset($variaciones['unidad']) ? $variaciones['unidad'] : $node->field_proyecto_unidadm[0]['tid']; |
---|
| 92 | if ($unidad_medida) { |
---|
| 93 | $unidad_medida_term = taxonomy_get_term($unidad_medida); |
---|
| 94 | $unidad_nombre = t('No seleccionado'); |
---|
| 95 | // If this term's vocabulary supports localization. |
---|
| 96 | if ($unidad_medida_term && module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($unidad_medida_term->vid) == I18N_TAXONOMY_LOCALIZE) { |
---|
| 97 | $unidad_medida_term->name = tt("taxonomy:term:$unidad_medida_term->tid:name", $unidad_medida_term->name); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | if ($unidad_medida_term) { |
---|
| 101 | $unidad_nombre = $unidad_medida_term->name; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | $node->content['proyectos_operativos_unidad_medida_reformulado'] = array( |
---|
| 105 | '#value' => '<div class="field"><div class="field-label">' . t('Unidad de Medida') . ':</div>' . $unidad_nombre . '</div>', |
---|
| 106 | '#weight' => 100, |
---|
| 107 | ); |
---|
| 108 | //meta fisica del proyecto |
---|
| 109 | $output = '<fieldset><legend>' . t('Meta FÃsica del proyecto') . '</legend>'; |
---|
| 110 | $ftypes = array( |
---|
| 111 | 'value' => t('January'), |
---|
| 112 | 'value_1' => t('February'), |
---|
| 113 | 'value_2' => t('March'), |
---|
| 114 | 'value_3' => t('April'), |
---|
| 115 | 'value_4' => t('May'), |
---|
| 116 | 'value_5' => t('June'), |
---|
| 117 | 'value_6' => t('July'), |
---|
| 118 | 'value_7' => t('August'), |
---|
| 119 | 'value_8' => t('September'), |
---|
| 120 | 'value_9' => t('Octuber'), |
---|
| 121 | 'value_10' => t('November'), |
---|
| 122 | 'value_11' => t('December'), |
---|
| 123 | ); |
---|
| 124 | $header = array(); |
---|
| 125 | $rows = array(); |
---|
| 126 | $row = array(); |
---|
| 127 | $total = 0; |
---|
| 128 | $total1 = 0; |
---|
| 129 | foreach($ftypes as $id_field => $texto) { |
---|
| 130 | $header[] = array('data' => $texto); |
---|
| 131 | $varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 132 | $min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia; |
---|
| 133 | $valor = isset($reformula['field_proyecto_meta_fisica'][0][$id_field])? $reformula['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 134 | $total += $min; |
---|
| 135 | $total1 += $valor; |
---|
| 136 | $row[] = array('data' => $min, ); |
---|
| 137 | } |
---|
| 138 | $row[] = array('data' => $total, ); |
---|
| 139 | $rows[] = $row; |
---|
| 140 | $header[] = array('data' => t('TOTAL')); |
---|
| 141 | $output .= theme('table', $header, $rows); |
---|
| 142 | $output .= '</fieldset>'; |
---|
| 143 | $node->content['proyectos_operativos_meta_fisica_reformulado'] = array( |
---|
| 144 | '#value' => $output, |
---|
| 145 | '#weight' => 100, |
---|
| 146 | ); |
---|
| 147 | } |
---|
| 148 | elseif ($node->type == 'accion_especifica') { |
---|
| 149 | $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']; |
---|
| 150 | $term = taxonomy_get_term($term_id); |
---|
| 151 | //se agrega la unidad de medida reformulada |
---|
| 152 | $node->content['proyectos_operativos_unidad_medida_reformulado'] = array( |
---|
| 153 | '#value' => '<div class="field"><div class="field-label">' . t('Unidad de Medida') . ':</div>' . $term->name . '</div>', |
---|
| 154 | '#weight' => 100, |
---|
| 155 | ); |
---|
| 156 | $format_number = array( |
---|
| 157 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 158 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 159 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 160 | ); |
---|
| 161 | $ftypes = array( |
---|
| 162 | 'value' => t('January'), |
---|
| 163 | 'value_1' => t('February'), |
---|
| 164 | 'value_2' => t('March'), |
---|
| 165 | 'value_3' => t('April'), |
---|
| 166 | 'value_4' => t('May'), |
---|
| 167 | 'value_5' => t('June'), |
---|
| 168 | 'value_6' => t('July'), |
---|
| 169 | 'value_7' => t('August'), |
---|
| 170 | 'value_8' => t('September'), |
---|
| 171 | 'value_9' => t('Octuber'), |
---|
| 172 | 'value_10' => t('November'), |
---|
| 173 | 'value_11' => t('December'), |
---|
| 174 | ); |
---|
| 175 | $proyecto = node_load($node->field_accion_esp_proyecto[0]['nid']); |
---|
| 176 | $variaciones = _proyectos_reformula_all_partidas_load($proyecto); |
---|
| 177 | $output = '<fieldset><legend>' . t('Meta FÃsica de las Acción EspecÃfica') . '</legend>'; |
---|
| 178 | $header = array(); |
---|
| 179 | $rows = array(); |
---|
| 180 | $row = array(); |
---|
| 181 | foreach($ftypes as $id_field => $texto) { |
---|
| 182 | $header[] = array('data' => $texto); |
---|
| 183 | $varia = isset($variaciones['field_accion_esp_metaf_' . $node->nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $node->nid][0][$id_field] : 0; |
---|
| 184 | $min = $node->field_accion_esp_metaf[0][$id_field] + $varia; |
---|
| 185 | $total += $min; |
---|
| 186 | $row[] = array('data' => number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 187 | } |
---|
| 188 | $row[] = array('data' => number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 189 | $header[] = array('data' => t('TOTAL')); |
---|
| 190 | $rows[] = $row; |
---|
| 191 | $output .= theme('table', $header, $rows); |
---|
| 192 | $output .= '</fieldset>'; |
---|
| 193 | $node->content['accion_especifica_meta_fisica_reformulado'] = array( |
---|
| 194 | '#value' => $output, |
---|
| 195 | '#weight' => 100, |
---|
| 196 | ); |
---|
| 197 | $field = content_fields('field_accion_esp_programacion', 'accion_especifica'); |
---|
| 198 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 199 | $vtid = $field['vtid']; |
---|
| 200 | $partidas = array(); |
---|
| 201 | if ($tree) { |
---|
| 202 | foreach ($tree as $term) { |
---|
| 203 | if (isset($vtid[$term->tid])) { |
---|
| 204 | if ($term && module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { |
---|
| 205 | $term->name = tt("taxonomy:term:$term->tid:name", $unidad_medida_term->name); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | $partidas[$term->tid] = $term->name; |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | $partidas_nodo = array(); |
---|
| 213 | foreach ($node->field_accion_esp_programacion as $partida) { |
---|
| 214 | if(!empty($partida['tid'])) { |
---|
| 215 | $partidas_nodo[$partida['tid']] = $partida; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | $output = ''; |
---|
| 219 | $output .= '<fieldset><legend>' . t('Distribución por partidas Presupuestarias') . '</legend>'; |
---|
| 220 | $header = array(); |
---|
| 221 | $header[] = array('data' => t('Partidas')); |
---|
| 222 | foreach($ftypes as $id_field => $texto) { |
---|
| 223 | $header[] = array('data' => $texto); |
---|
| 224 | } |
---|
| 225 | $header[] = array('data' => t('TOTAL')); |
---|
| 226 | $rows = array(); |
---|
| 227 | $rowsF = array(); |
---|
| 228 | $totales = array(); |
---|
| 229 | $totalT = 0; |
---|
| 230 | $plant = array(); |
---|
| 231 | $sumaplan = 0; |
---|
| 232 | $sumaplanm = array(); |
---|
| 233 | |
---|
| 234 | foreach($partidas as $tid => $grupo) { |
---|
| 235 | $total = 0; |
---|
| 236 | $total1 = 0; |
---|
| 237 | $row = array(); |
---|
| 238 | $row[] = array('data' => $grupo); |
---|
| 239 | foreach($ftypes as $id_field => $texto) { |
---|
| 240 | $varia = isset($variaciones['field_accion_esp_programacion_' . $node->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $node->nid][$tid][$id_field] : 0; |
---|
| 241 | $min = $partidas_nodo[$tid][$id_field] + $varia; |
---|
| 242 | if (!isset($plant[$tid])) { |
---|
| 243 | $plant[$tid] = 0; |
---|
| 244 | } |
---|
| 245 | $totalT += $min; |
---|
| 246 | $plant[$tid] += $min; |
---|
| 247 | $total += $min; |
---|
| 248 | $sumaplan += $min; |
---|
| 249 | if (!isset($sumaplanm[$id_field])) { |
---|
| 250 | $sumaplanm[$id_field] = 0; |
---|
| 251 | } |
---|
| 252 | $sumaplanm[$id_field] += $min; |
---|
| 253 | $row[] = array('data' => number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 254 | } |
---|
| 255 | $row[] = array('data' => number_format($plant[$tid], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 256 | if ($plant[$tid] > 0) { |
---|
| 257 | $rows[] = $row; |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | $row = array(); |
---|
| 261 | $row[] = array('data' => '<b>' . t('TOTAL') . '</b>', 'align' => 'right'); |
---|
| 262 | foreach($ftypes as $id_field => $texto) { |
---|
| 263 | $row[] = array('data' => number_format($sumaplanm[$id_field], $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 264 | } |
---|
| 265 | $row[] = array('data' => number_format($totalT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 266 | $rows[] = $row; |
---|
| 267 | $output .= theme('table', $header, $rows); |
---|
| 268 | $output .= '</fieldset>'; |
---|
| 269 | $node->content['accion_especifica_partidas_reformulado'] = array( |
---|
| 270 | '#value' => $output, |
---|
| 271 | '#weight' => 101, |
---|
| 272 | ); |
---|
| 273 | $output = ''; |
---|
| 274 | |
---|
| 275 | //financiamiento |
---|
| 276 | $arreglo_financiamiento = array(); |
---|
| 277 | $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4); |
---|
| 278 | for($i = 0; $i < $accion_especifica_number_fields; $i++) { |
---|
| 279 | $arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : ''; |
---|
| 280 | $arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array()); |
---|
| 281 | } |
---|
| 282 | /* |
---|
| 283 | |
---|
| 284 | $arreglo = array(); |
---|
| 285 | $titles = array( |
---|
| 286 | 'ordinarios' => t('Recursos Ordinarios'), |
---|
| 287 | 'propios' => t('Recursos Propios'), |
---|
| 288 | 'transferencias' => t('Donaciones'), |
---|
| 289 | 'otros' => t('Otros'), |
---|
| 290 | ); |
---|
| 291 | $titles_field = array( |
---|
| 292 | 'field_accion_esp_transferencias' => t('Recursos Ordinarios'), |
---|
| 293 | 'field_accion_esp_creditosa' => t('Recursos Propios'), |
---|
| 294 | 'transferencias' => t('Donaciones'), |
---|
| 295 | 'otros' => t('Otros'), |
---|
| 296 | ); |
---|
| 297 | $arreglo['ordinarios'] = array( |
---|
| 298 | 'field_accion_esp_transferencias' => 'field_accion_esp_transferencias', |
---|
| 299 | 'field_accion_esp_creditosa' => 'field_accion_esp_creditosa', |
---|
| 300 | 'field_accion_esp_mcti' => 'field_accion_esp_mcti', |
---|
| 301 | ); |
---|
| 302 | $arreglo['propios'] = array( |
---|
| 303 | 'field_accion_esp_venta_act' => 'field_accion_esp_venta_act', |
---|
| 304 | 'field_accion_esp_activos' => 'field_accion_esp_activos', |
---|
| 305 | 'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja', |
---|
| 306 | 'field_accion_esp_ventapro' => 'field_accion_esp_ventapro', |
---|
| 307 | ); |
---|
| 308 | $arreglo['transferencias'] = array( |
---|
| 309 | 'field_accion_esp_donaciones' => 'field_accion_esp_donaciones', |
---|
| 310 | ); |
---|
| 311 | $arreglo['otros'] = array( |
---|
| 312 | 'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion', |
---|
| 313 | 'field_accion_esp_misionc' => 'field_accion_esp_misionc', |
---|
| 314 | 'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona', |
---|
| 315 | 'field_accion_esp_fonacit' => 'field_accion_esp_fonacit', |
---|
| 316 | 'field_accion_esp_fonden' => 'field_accion_esp_fonden', |
---|
| 317 | 'field_accion_esp_locti' => 'field_accion_esp_locti', |
---|
| 318 | 'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi', |
---|
| 319 | 'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie', |
---|
| 320 | 'field_accion_esp_infocentro' => 'field_accion_esp_infocentro', |
---|
| 321 | 'field_accion_esp_fidetel' => 'field_accion_esp_fidetel', |
---|
| 322 | ); |
---|
| 323 | */ |
---|
| 324 | $rows = array(); |
---|
| 325 | $row = array(); |
---|
| 326 | $row1 = array(); |
---|
| 327 | $sumalT = 0; |
---|
| 328 | foreach($arreglo_financiamiento as $id_items => $titulo) { |
---|
| 329 | $sumal = 0; |
---|
| 330 | $output1 = '<fieldset><legend>' . $titulo . '</legend>'; |
---|
| 331 | foreach($arreglo_financiamiento_fields[$id_items] as $id1) { |
---|
| 332 | if ($id1) { |
---|
| 333 | $field = content_fields($id1, 'accion_especifica'); |
---|
| 334 | $varia = isset($variaciones[$id1 . '_' . $node->nid][0]['value']) ? $variaciones[$id1 . '_' . $node->nid][0]['value'] : 0; |
---|
| 335 | $min = $node->{$id1}[0]['value'] + $varia; |
---|
| 336 | if (!isset($sumafinm[$id_items])) { |
---|
| 337 | $sumafinm[$id_items] = 0; |
---|
| 338 | } |
---|
| 339 | $sumafinm[$id_items] += $min; |
---|
| 340 | $sumatotalf += $min; |
---|
| 341 | $field = content_fields($id1, 'accion_especifica'); |
---|
| 342 | $sumal += $min; |
---|
| 343 | $sumalT += $min; |
---|
| 344 | $output1 .= '<div class="field"><div class="field-label">' . $field['widget']['label'] . ':</div>' . '<div class="field-label-planificado">' . number_format($min, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '</div>' . '</div>'; |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | $output1 .= '</fieldset>'; |
---|
| 348 | $row[] = array('data' => $output1, ); |
---|
| 349 | $row1[] = array('data' => number_format($sumal, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 350 | } |
---|
| 351 | $rows[] = $row; |
---|
| 352 | $rows[] = $row1; |
---|
| 353 | $row = array(); |
---|
| 354 | $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => 3, 'align' => 'right'); |
---|
| 355 | $row[] = array('data' => number_format($sumalT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 356 | $rows[] = $row; |
---|
| 357 | $output .= '<fieldset><legend>' . t('Distribución por fuentes de Financiamiento') . '</legend>' . theme('table', array(), $rows) . '</fieldset>'; |
---|
| 358 | $node->content['accion_especifica_fuentesfinanc_reformulado'] = array( |
---|
| 359 | '#value' => $output, |
---|
| 360 | '#weight' => 102, |
---|
| 361 | ); |
---|
| 362 | } |
---|
| 363 | break; |
---|
| 364 | case 'delete': |
---|
| 365 | if ($node->type = 'proyectos_operativos') { |
---|
| 366 | db_query('DELETE FROM {proyectos_reformula} WHERE nid = %d', $node->nid); |
---|
| 367 | db_query('DELETE FROM {proyectos_reformular} WHERE nid = %d', $node->nid); |
---|
| 368 | db_query('DELETE FROM {proyectos_reformular_state} WHERE nid = %d', $node->nid); |
---|
| 369 | db_query('DELETE FROM {proyectos_reformula_fuente} WHERE nid = %d', $node->nid); |
---|
| 370 | } |
---|
| 371 | break; |
---|
| 372 | case 'load': |
---|
| 373 | if ($node->type == 'accion_especifica') { |
---|
| 374 | $proyecto = node_load($node->field_accion_esp_proyecto[0]['nid']); |
---|
| 375 | $variaciones = _proyectos_reformula_all_partidas_load($proyecto); |
---|
| 376 | $node->proyecto_asignado = $proyecto; |
---|
| 377 | $node->variaciones = $proyecto->variaciones; |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | } |
---|
| 381 | elseif ($node->type == 'proyectos_operativos'){ |
---|
| 382 | $variaciones = _proyectos_reformula_all_partidas_load($node); |
---|
| 383 | $node->variaciones = $variaciones; |
---|
| 384 | |
---|
| 385 | } |
---|
| 386 | break; |
---|
| 387 | } |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | /* |
---|
| 392 | * Implementation of hook_proyecto_obtiene_links_alter() |
---|
| 393 | */ |
---|
| 394 | function proyectos_reformulacion_proyecto_obtiene_links_alter(&$links, $proyecto, $acceso = FALSE) { |
---|
| 395 | $node_accion = node_load($proyecto->nid); |
---|
| 396 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 397 | if($node_accion->_workflow == $estado_aprobado){ |
---|
| 398 | $links[] = array( |
---|
| 399 | 'data' => l(t('Reformulaciones'), 'proyectosop/' . $proyecto->nid . '/reformular'), |
---|
| 400 | 'class' => 'proyectos-operativos-reformulaciones', |
---|
| 401 | ); |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | /* |
---|
| 406 | * hook_form_alter() |
---|
| 407 | */ |
---|
| 408 | function proyectos_reformulacion_form_alter(&$form, $form_state, $form_id) { |
---|
| 409 | if ($form_id == 'proyectos_operativos_proyecto_genera_campos_form') { |
---|
| 410 | if (!isset($_SESSION['proyectos_operativos_mostrar_campos'][$form['#node']->nid]) || !count($_SESSION['proyectos_operativos_mostrar_campos'][$form['#node']->nid])) { |
---|
| 411 | //REFORMULACION DEL PROYECTO |
---|
| 412 | $arreglo['proyectos_reformulacion']['reformulacion'] = array( |
---|
| 413 | 'proyectos_operativos_monto_anual_reformulado' => t('Monto Total del Proyecto para el año en curso (Reformulado)'), |
---|
| 414 | 'proyectos_operativos_monto_total_reformulado' => t('Monto Total del Proyecto (Reformulado)'), |
---|
| 415 | 'proyectos_operativos_unidad_medida_reformulado' => t('Unidad de Medida (Reformulado)'), |
---|
| 416 | 'proyectos_operativos_meta_fisica_reformulado' => t('Meta FÃsica del proyecto (Reformulado)'), |
---|
| 417 | ); |
---|
| 418 | $form['proyectos_reformulacion'] = array( |
---|
| 419 | '#type' => 'fieldset', |
---|
| 420 | '#title' => t('Reformulación del Proyecto'), |
---|
| 421 | '#weight' => 1, |
---|
| 422 | ); |
---|
| 423 | //Clasificación Sectorial |
---|
| 424 | $form['proyectos_reformulacion']['reformulacion'] = array( |
---|
| 425 | '#type' => 'checkboxes', |
---|
| 426 | '#options' => $arreglo['proyectos_reformulacion']['reformulacion'], |
---|
| 427 | '#default_value' => array(), |
---|
| 428 | '#title' => t('Reformulación del Proyecto'), |
---|
| 429 | '#multiple' => TRUE, |
---|
| 430 | ); |
---|
| 431 | $form['#title_combos']['reformulacion']['title'] = t('Reformulación del Proyecto'); |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | $states = array(); |
---|
| 435 | if ($form_id == 'proyectos_operativos_admin_settings') { |
---|
| 436 | if (module_exists('workflow')) { |
---|
| 437 | $wid = workflow_get_workflow_for_type('proyectos_operativos'); |
---|
| 438 | if ($wid){ |
---|
| 439 | $states = workflow_get_states($wid); |
---|
| 440 | $rids = user_roles(); |
---|
| 441 | $rids['-1'] = t('author'); |
---|
| 442 | if (count($states)) { |
---|
| 443 | foreach ($states as $sid => $state) { |
---|
| 444 | $form['workflow']['proyectos_operativos_state_r_' . $sid] = array( |
---|
| 445 | '#type' => 'checkboxes', |
---|
| 446 | '#options' => $rids, |
---|
| 447 | '#default_value' => variable_get('proyectos_operativos_state_r_' . $sid, array()), |
---|
| 448 | '#title' => t('Roles que pueden editar las reformulaciones de los Proyectos Operativos'), |
---|
| 449 | '#multiple' => TRUE, |
---|
| 450 | '#prefix' => '<table width="100%" style="border: 0;"><tbody style="border: 0;"><tr><th colspan="3">' . t('State: @state', array('@state' => $state)) . '</th></tr><tr><td>', |
---|
| 451 | '#suffix' => "</td></tr></tbody></table>", |
---|
| 452 | ); |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | if (count($states)) { |
---|
| 459 | $form['workflow']['proyectos_operativos_state_reformulacion'] = array( |
---|
| 460 | '#title' => t('Seleccione el estado de inicio cuando se añada una reformulación'), |
---|
| 461 | '#type' => 'select', |
---|
| 462 | '#default_value' => variable_get('proyectos_operativos_state_reformulacion', 0), |
---|
| 463 | '#options' => $states, |
---|
| 464 | '#weight' => -6, |
---|
| 465 | ); |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | /** |
---|
| 471 | * Menu access control callback. Determine access to reformula tab. |
---|
| 472 | */ |
---|
| 473 | function _proyectos_reformulacion_reformula_node_tab_access($node = NULL) { |
---|
| 474 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 475 | return ($node->type == 'proyectos_operativos' && $node->_workflow == $estado_aprobado); |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | /** |
---|
| 479 | * Menu access control callback. Determine access to reformulacion tab. |
---|
| 480 | */ |
---|
| 481 | function _proyectos_reformulacion_reformula_node_add_tab_access($node = NULL) { |
---|
| 482 | global $user; |
---|
| 483 | $year = variable_get('proyectos_operativos_anho_creacion', 0); |
---|
| 484 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 485 | if ($node->type != 'proyectos_operativos' || $node->anhoproyectos_operativos != $year) { |
---|
| 486 | return FALSE; |
---|
| 487 | } |
---|
| 488 | if ($estado_aprobado && $node->_workflow != $estado_aprobado) { |
---|
| 489 | return FALSE; |
---|
| 490 | } |
---|
| 491 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 492 | $current_time = time(); |
---|
| 493 | $tipo_plan = 'proyectos_operativos_reformular'; |
---|
| 494 | $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo); |
---|
| 495 | $fecha = FALSE; |
---|
| 496 | $ente = usuario_tiene_ente($user->uid); |
---|
| 497 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
| 498 | $fecha = TRUE; |
---|
| 499 | } |
---|
| 500 | if ($fecha) { |
---|
| 501 | if ($ente->nid == $ente_planificador->nid) { |
---|
| 502 | $fecha = TRUE; |
---|
| 503 | } |
---|
| 504 | elseif (!user_access('admin planificador')) { |
---|
| 505 | return FALSE; |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | if (!$fecha) { |
---|
| 509 | return FALSE; |
---|
| 510 | } |
---|
| 511 | $roles_allow = variable_get('proyectos_operativos_state_r_1', array()); |
---|
| 512 | $estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL); |
---|
| 513 | $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); |
---|
| 514 | $proyecto = db_fetch_array($result); |
---|
| 515 | $roles = array_keys($user->roles); |
---|
| 516 | if (count($roles)) { |
---|
| 517 | foreach($roles as $rol) { |
---|
| 518 | if($roles_allow[$rol]) { |
---|
| 519 | return TRUE && !$proyecto['cantidad']; |
---|
| 520 | } |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | return ($proyecto && !$proyecto['cantidad'] && $user->uid == 1); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | /** |
---|
| 527 | * Menu access control callback. Determine access to editar reformulacion tab. |
---|
| 528 | */ |
---|
| 529 | function _proyectos_reformulacion_reformula_node_edit_tab_access($node = NULL, $reformulacion) { |
---|
| 530 | global $user; |
---|
| 531 | $year = variable_get('proyectos_operativos_anho_creacion', 0); |
---|
| 532 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 533 | if ($node->type != 'proyectos_operativos' || $node->anhoproyectos_operativos != $year) { |
---|
| 534 | return FALSE; |
---|
| 535 | } |
---|
| 536 | if ($estado_aprobado && $node->_workflow != $estado_aprobado) { |
---|
| 537 | return FALSE; |
---|
| 538 | } |
---|
| 539 | if ($estado_aprobado && $reformulacion->estado == $estado_aprobado) { |
---|
| 540 | return FALSE; |
---|
| 541 | } |
---|
| 542 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 543 | $current_time = time(); |
---|
| 544 | $tipo_plan = 'proyectos_operativos_reformular'; |
---|
| 545 | $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo); |
---|
| 546 | $fecha = FALSE; |
---|
| 547 | $ente = usuario_tiene_ente($user->uid); |
---|
| 548 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
| 549 | $fecha = TRUE; |
---|
| 550 | } |
---|
| 551 | if ($fecha) { |
---|
| 552 | if ($ente->nid == $ente_planificador->nid) { |
---|
| 553 | $fecha = TRUE; |
---|
| 554 | } |
---|
| 555 | elseif (!user_access('admin planificador')) { |
---|
| 556 | return FALSE; |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | if (!$fecha) { |
---|
| 560 | return FALSE; |
---|
| 561 | } |
---|
| 562 | $roles_allow = variable_get('proyectos_operativos_state_r_' . $reformulacion->estado, array()); |
---|
| 563 | if ($user->uid == 1 || ($user->uid == $reformulacion->uid && $roles_allow[-1])) { |
---|
| 564 | return TRUE; |
---|
| 565 | } |
---|
| 566 | $roles = array_keys($user->roles); |
---|
| 567 | if (count($roles)) { |
---|
| 568 | foreach($roles as $rol) { |
---|
| 569 | if($roles_allow[$rol]) { |
---|
| 570 | return TRUE; |
---|
| 571 | } |
---|
| 572 | } |
---|
| 573 | } |
---|
| 574 | return FALSE; |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | |
---|
| 578 | /** |
---|
| 579 | * Implementation of proyectos_reformulacion_menu_reformulacion_load(). |
---|
| 580 | * Menu loader callback. Load a mes. |
---|
| 581 | */ |
---|
| 582 | function proyectosop_menu_reformulacion_load($id_ref = 0, $node = 0) { |
---|
| 583 | $reformula = FALSE; |
---|
| 584 | $nodo = $node ? $node->nid : arg(1); |
---|
| 585 | if ($id_ref && is_numeric($nodo)) { |
---|
| 586 | $result = db_query("SELECT * FROM {proyectos_reformular} WHERE nid = %d AND id_ref = %d", $nodo, $id_ref); |
---|
| 587 | $reformula = db_fetch_object($result); |
---|
| 588 | } |
---|
| 589 | return $reformula; |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | /** |
---|
| 593 | * Implementation of accionesp_menu_r_load(). |
---|
| 594 | * Devuelve la accion especifica. |
---|
| 595 | */ |
---|
| 596 | function accionesp_menu_r_load($nid) { |
---|
| 597 | $ae = FALSE; |
---|
| 598 | if ($nid && arg(1) && is_numeric(arg(1))) { |
---|
| 599 | $ae = node_load($nid); |
---|
| 600 | if ($ae->type != 'accion_especifica' || $ae->field_accion_esp_proyecto[0]['nid'] != arg(1)) { |
---|
| 601 | return FALSE; |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | return $ae; |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | /* |
---|
| 608 | * Implementation of proyectos_reformulacion_wk_menu_load() |
---|
| 609 | */ |
---|
| 610 | function proyectos_reformulacion_wk_menu_load($state = 0) { |
---|
| 611 | $states = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 612 | if (isset($states['states'][$state])) { |
---|
| 613 | return $state; |
---|
| 614 | } |
---|
| 615 | return FALSE; |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | /** |
---|
| 619 | * Menu access control callback. Determine access to wk tab. |
---|
| 620 | */ |
---|
| 621 | function _proyectos_reformulacion_reformula_wk_node_tab_access($node = NULL, $reformulacion, $state = 0) { |
---|
| 622 | global $user; |
---|
| 623 | $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; |
---|
| 624 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 625 | $suma_r_ae = total_reformulado_ae($node, $reformula); |
---|
| 626 | if ($suma_r_ae != $reformulacion_load->variacion) { |
---|
| 627 | return FALSE; |
---|
| 628 | } |
---|
| 629 | $year = variable_get('proyectos_operativos_anho_creacion', 0); |
---|
| 630 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 631 | if ($node->type != 'proyectos_operativos' || $node->anhoproyectos_operativos != $year) { |
---|
| 632 | return FALSE; |
---|
| 633 | } |
---|
| 634 | if ($estado_aprobado && $node->_workflow != $estado_aprobado) { |
---|
| 635 | return FALSE; |
---|
| 636 | } |
---|
| 637 | $ente = usuario_tiene_ente($user->uid); |
---|
| 638 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 639 | if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { |
---|
| 640 | return FALSE; |
---|
| 641 | } |
---|
| 642 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 643 | $estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL); |
---|
| 644 | if ($reformulacion->estado == $estado_naprobado || $reformulacion->estado == $estado_aprobado) { |
---|
| 645 | return FALSE; |
---|
| 646 | } |
---|
| 647 | $states = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 648 | $first_state = 0; |
---|
| 649 | if ($states['wid']) { |
---|
| 650 | $first_state = _workflow_creation_state($states['wid']); |
---|
| 651 | } |
---|
| 652 | $roles = array_keys($user->roles); |
---|
| 653 | if ($user->uid == 1) { |
---|
| 654 | // Superuser is special. |
---|
| 655 | $roles_transition = 'ALL'; |
---|
| 656 | } |
---|
| 657 | else { |
---|
| 658 | $roles_transition = $roles; |
---|
| 659 | if ($user->uid == $reformulacion->uid && $reformulacion->uid > 0) { |
---|
| 660 | $roles_transition += array('author' => 'author'); |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | $transitions = array(); |
---|
| 664 | if ($states['wid']) { |
---|
| 665 | $transitions = workflow_allowable_transitions($reformulacion->estado, 'to', $roles_transition); |
---|
| 666 | } |
---|
| 667 | if ($first_state && $reformulacion->estado == $first_state) { |
---|
| 668 | unset($transitions[$reformulacion->estado]); |
---|
| 669 | } |
---|
| 670 | if (isset($transitions[$state])) { |
---|
| 671 | return TRUE; |
---|
| 672 | } |
---|
| 673 | return FALSE; |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | /* |
---|
| 677 | * Implementation of proyectos_reformulacion_reformula_wk_tab_page_form() |
---|
| 678 | */ |
---|
| 679 | function proyectos_reformulacion_reformula_wk_tab_page_form($form_state, $node, $reformulacion_load = 0, $state = 0) { |
---|
| 680 | $estados = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 681 | $form = array(); |
---|
| 682 | $form['#node'] = $node; |
---|
| 683 | $form['#nuevo_estado'] = $state; |
---|
| 684 | $form['#estados'] = $estados['states']; |
---|
| 685 | $form['#reformulacion'] = $reformulacion_load; |
---|
| 686 | $form['comentario'] = array( |
---|
| 687 | '#title' => t('Comentario'), |
---|
| 688 | '#type' => 'textarea', |
---|
| 689 | '#default_value' => '', |
---|
| 690 | ); |
---|
| 691 | $message = t('Esta seguro de cambiar la reformulación al estado %nombre_estado?', array('%nombre_estado' => $estados['states'][$state])); |
---|
| 692 | $caption = '<p>'. t('This action cannot be undone.') .'</p>'; |
---|
| 693 | $return_path = 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/view'; |
---|
| 694 | return confirm_form($form, $message, $return_path, $caption, t('Cambiar')); |
---|
| 695 | return $form; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | /** |
---|
| 699 | * Implementation of proyectos_reformulacion_reformula_wk_tab_page_form_submit(). |
---|
| 700 | * Process funcion delete confirm form. |
---|
| 701 | */ |
---|
| 702 | function proyectos_reformulacion_reformula_wk_tab_page_form_submit($form, &$form_state) { |
---|
| 703 | global $user; |
---|
| 704 | $nuevo_estado = $form['#datos_institucionales_funcion']; |
---|
| 705 | 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); |
---|
| 706 | 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); |
---|
| 707 | drupal_set_message(t('La reformulación fue cambiada al estado @nombre_estado', array('@nombre_estado' => $form['#estados'][$form['#nuevo_estado']]))); |
---|
| 708 | $form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#reformulacion']->id_ref . '/view'; |
---|
| 709 | } |
---|
| 710 | |
---|
| 711 | /* |
---|
| 712 | * Implementation of hook_menu() |
---|
| 713 | */ |
---|
| 714 | function proyectos_reformulacion_menu() { |
---|
| 715 | $items = array(); |
---|
| 716 | $items['proyectosop/%proyectosop/reformular'] = array( |
---|
| 717 | 'title' => 'Reformular', |
---|
| 718 | 'type' => MENU_LOCAL_TASK, |
---|
| 719 | 'access callback' => '_proyectos_reformulacion_reformula_node_tab_access', |
---|
| 720 | 'access arguments' => array(1), |
---|
| 721 | 'page callback' => '_proyectos_reformulacion_reformula_list_page', |
---|
| 722 | 'page arguments' => array(1), |
---|
| 723 | 'weight' => 2, |
---|
| 724 | ); |
---|
| 725 | $items['proyectosop/%proyectosop/reformular/list'] = array( |
---|
| 726 | 'title' => 'Reformulaciones', |
---|
| 727 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
---|
| 728 | 'weight' => -10 |
---|
| 729 | ); |
---|
| 730 | $items['proyectosop/%proyectosop/reformular/add'] = array( |
---|
| 731 | 'title' => 'Agregar Reformulación', |
---|
| 732 | 'type' => MENU_LOCAL_TASK, |
---|
| 733 | 'access callback' => '_proyectos_reformulacion_reformula_node_add_tab_access', |
---|
| 734 | 'access arguments' => array(1), |
---|
| 735 | 'page callback' => 'drupal_get_form', |
---|
| 736 | 'page arguments' => array('proyectos_reformulacion_reformula_tab_page_form', 1), |
---|
| 737 | 'weight' => 2, |
---|
| 738 | ); |
---|
| 739 | $items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/view'] = array( |
---|
| 740 | 'title' => 'Ver reformulación', |
---|
| 741 | 'type' => MENU_LOCAL_TASK, |
---|
| 742 | 'access callback' => '_proyectos_reformulacion_reformula_node_tab_access', |
---|
| 743 | 'access arguments' => array(1), |
---|
| 744 | 'page callback' => '_proyectos_reformulacion_reformula_tab_page_ver', |
---|
| 745 | 'page arguments' => array(1, 3), |
---|
| 746 | 'weight' => 2, |
---|
| 747 | ); |
---|
| 748 | $items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/edit'] = array( |
---|
| 749 | 'title' => 'Editar', |
---|
| 750 | 'type' => MENU_LOCAL_TASK, |
---|
| 751 | 'access callback' => '_proyectos_reformulacion_reformula_node_edit_tab_access', |
---|
| 752 | 'access arguments' => array(1, 3), |
---|
| 753 | 'page callback' => 'drupal_get_form', |
---|
| 754 | 'page arguments' => array('proyectos_reformulacion_reformula_tab_page_form', 1, 3), |
---|
| 755 | 'weight' => 3, |
---|
| 756 | ); |
---|
| 757 | $items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/ae/%accionesp_menu_r'] = array( |
---|
| 758 | 'title' => 'Acciones Especificas', |
---|
| 759 | 'type' => MENU_LOCAL_TASK, |
---|
| 760 | 'access callback' => '_proyectos_reformulacion_reformula_node_tab_access', |
---|
| 761 | 'access arguments' => array(1), |
---|
| 762 | 'page callback' => '_proyectos_reformulacion_reformula_tab_page_ver_ae', |
---|
| 763 | 'page arguments' => array(1, 3, 5), |
---|
| 764 | 'weight' => 2, |
---|
| 765 | ); |
---|
| 766 | $items['proyectosop/%proyectosop/reformular/%proyectosop_menu_reformulacion/ae/%accionesp_menu_r/edit'] = array( |
---|
| 767 | 'title' => 'Editar AEs', |
---|
| 768 | 'type' => MENU_LOCAL_TASK, |
---|
| 769 | 'access callback' => '_proyectos_reformulacion_reformula_node_edit_tab_access', |
---|
| 770 | 'access arguments' => array(1, 3), |
---|
| 771 | 'page callback' => 'drupal_get_form', |
---|
| 772 | 'page arguments' => array('proyectos_reformulacion_reformula_tab_page_ae_form', 1, 3, 5), |
---|
| 773 | 'weight' => 3, |
---|
| 774 | ); |
---|
| 775 | $items['proyectosop/%node/reformular/%proyectosop_menu_reformulacion/workflow/%proyectos_reformulacion_wk_menu'] = array( |
---|
| 776 | 'title' => 'Workflow', |
---|
| 777 | 'type' => MENU_LOCAL_TASK, |
---|
| 778 | 'access callback' => '_proyectos_reformulacion_reformula_wk_node_tab_access', |
---|
| 779 | 'access arguments' => array(1, 3, 5), |
---|
| 780 | 'page callback' => 'drupal_get_form', |
---|
| 781 | 'page arguments' => array('proyectos_reformulacion_reformula_wk_tab_page_form', 1, 3, 5), |
---|
| 782 | 'weight' => 3, |
---|
| 783 | ); |
---|
| 784 | return $items; |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | /** |
---|
| 788 | * Implementation of hook_theme(). |
---|
| 789 | */ |
---|
| 790 | function proyectos_reformulacion_theme() { |
---|
| 791 | return array( |
---|
| 792 | 'proyectos_reformulacion_reformula_tab_page_form' => array( |
---|
| 793 | 'arguments' => array('form' => NULL), |
---|
| 794 | ), |
---|
| 795 | 'proyectos_reformulacion_reformula_tab_page_ae_form' => array( |
---|
| 796 | 'arguments' => array('form' => NULL), |
---|
| 797 | ), |
---|
| 798 | ); |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | /* |
---|
| 802 | * Implementation of proyectos_reformulacion_reformula_tab_page_form() |
---|
| 803 | */ |
---|
| 804 | function proyectos_reformulacion_reformula_tab_page_form($form_state, $node, $reformulacion_load = 0) { |
---|
| 805 | $title = $reformulacion_load ? t('Modificar Reformulación') : t('Agregar Reformulación al Proyecto'); |
---|
| 806 | drupal_set_title($title); |
---|
| 807 | $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; |
---|
| 808 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 809 | $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref); |
---|
| 810 | $field = content_fields('field_proyecto_unidadm', 'proyectos_operativos'); |
---|
| 811 | $unidad_ant = $node->field_proyecto_unidadm[0]['value']; |
---|
| 812 | $text_unidad = t('N/A'); |
---|
| 813 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 814 | $options = array(); |
---|
| 815 | if ($tree) { |
---|
| 816 | foreach ($tree as $term) { |
---|
| 817 | if ($term->tid == $unidad_ant) { |
---|
| 818 | $text_unidad = $term->name; |
---|
| 819 | } |
---|
| 820 | $choice = new stdClass(); |
---|
| 821 | $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name); |
---|
| 822 | $options[] = $choice; |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | $field = content_fields('field_accion_esp_unidadm', 'accion_especifica'); |
---|
| 826 | $unidadesm = array(); |
---|
| 827 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 828 | if ($tree) { |
---|
| 829 | foreach ($tree as $term) { |
---|
| 830 | $unidadesm[$term->tid] = $term->name; |
---|
| 831 | } |
---|
| 832 | } |
---|
| 833 | $form['field_proyecto_unidadm_ant'] = array( |
---|
| 834 | '#title' => t('Unidad de Medida Actual'), |
---|
| 835 | '#type' => 'textfield', |
---|
| 836 | '#value' => $text_unidad, |
---|
| 837 | '#attributes' => array('class' => 'campo-bloqueado '), |
---|
| 838 | ); |
---|
| 839 | $valor_medida = $reformula['unidad'] ? $reformula['unidad'] : $node->field_proyecto_unidadm[0]['value']; |
---|
| 840 | $form['field_proyecto_unidadm'] = array( |
---|
| 841 | '#title' => t('Unidad de Medida Nueva'), |
---|
| 842 | '#type' => 'select', |
---|
| 843 | '#options' => $options, |
---|
| 844 | '#default_value' => $valor_medida, |
---|
| 845 | ); |
---|
| 846 | $ftypes = array( |
---|
| 847 | 'value' => t('January'), |
---|
| 848 | 'value_1' => t('February'), |
---|
| 849 | 'value_2' => t('March'), |
---|
| 850 | 'value_3' => t('April'), |
---|
| 851 | 'value_4' => t('May'), |
---|
| 852 | 'value_5' => t('June'), |
---|
| 853 | 'value_6' => t('July'), |
---|
| 854 | 'value_7' => t('August'), |
---|
| 855 | 'value_8' => t('September'), |
---|
| 856 | 'value_9' => t('Octuber'), |
---|
| 857 | 'value_10' => t('November'), |
---|
| 858 | 'value_11' => t('December'), |
---|
| 859 | ); |
---|
| 860 | $grupos = array(); |
---|
| 861 | if ($node->field_proyecto_accion_esp[0]['nid']) { |
---|
| 862 | foreach($node->field_proyecto_accion_esp as $ae) { |
---|
| 863 | $grupos[$ae['nid']] = node_load($ae['nid']); |
---|
| 864 | $array[$ae['nid']] = node_load($ae['nid']); |
---|
| 865 | } |
---|
| 866 | } |
---|
| 867 | $varia = isset($variaciones['total']) ? $variaciones['total'] : 0; |
---|
| 868 | $min = $node->field_proyecto_monto_anual[0]['value'] + $varia; |
---|
| 869 | $form['#monto_reformulado'] = $min; |
---|
| 870 | $valor = isset($reformulacion_load->variacion)? $reformulacion_load->variacion : 0; |
---|
| 871 | $suma_variacion['primero'] = $min; |
---|
| 872 | $total_accion = $min; |
---|
| 873 | $idformuj = 'variacion'; |
---|
| 874 | $id_field = 'primero'; |
---|
| 875 | $fecha = array(); |
---|
| 876 | $fecha['dia'] = $reformula['fecha_onapre'] ? date('j', $reformula['fecha_onapre']) : date('j'); |
---|
| 877 | $fecha['mes'] = $reformula['fecha_onapre'] ? date('n', $reformula['fecha_onapre']) : date('m'); |
---|
| 878 | $fecha['year'] = $reformula['fecha_onapre'] ? date('Y', $reformula['fecha_onapre']) : date('Y'); |
---|
| 879 | $form['fecha_onapre'] = array( |
---|
| 880 | '#type' => 'date', |
---|
| 881 | '#title' => t('Fecha de Aprobación'), |
---|
| 882 | '#default_value' => array('day' => $fecha['dia'], 'month' => $fecha['mes'], 'year' => $fecha['year']), |
---|
| 883 | '#required' => TRUE, |
---|
| 884 | ); |
---|
| 885 | $valor_justificacion = isset($reformula['justificacion'])? $reformula['justificacion'] : ''; |
---|
| 886 | $form['justificacion'] = array( |
---|
| 887 | '#title' => t('Justificación'), |
---|
| 888 | '#type' => 'textarea', |
---|
| 889 | '#default_value' => $valor_justificacion, |
---|
| 890 | ); |
---|
| 891 | |
---|
| 892 | $form['variacion'] = array( |
---|
| 893 | '#type' => 'textfield', |
---|
| 894 | '#title' => t('Variación Presupuestaria'), |
---|
| 895 | '#default_value' => $valor, |
---|
| 896 | '#size' => 30, |
---|
| 897 | '#suffix' => '<div class="texto-variacion">' . t('Estimado Usuario: El monto a ingresar debe comenzar con el signo mas "+" o con el signo menos "-".') . '</div>', |
---|
| 898 | '#attributes' => array('class' => $clase . ' field-variacion number', 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref2('" . 'field-variacion' . "', 'variacion', '" . $id_field . "');"), |
---|
| 899 | ); |
---|
| 900 | $form['variaciont'] = array( |
---|
| 901 | '#type' => 'textfield', |
---|
| 902 | '#title' => t('Monto Total Reformulación'), |
---|
| 903 | '#default_value' => $min + $valor, |
---|
| 904 | '#size' => 30, |
---|
| 905 | '#attributes' => array('class' => 'campo-bloqueado field-variacion-total number1'), |
---|
| 906 | ); |
---|
| 907 | $form['#state_creation'] = -1; |
---|
| 908 | //get first state |
---|
| 909 | if (module_exists('workflow')) { |
---|
| 910 | $estados = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 911 | $estado_inicial = variable_get('proyectos_operativos_state_reformulacion', 0); |
---|
| 912 | if ($estados['wid']) { |
---|
| 913 | if ($estado_inicial && $estados['states'][$estado_inicial]) { |
---|
| 914 | $form['#state_creation'] = $estado_inicial; |
---|
| 915 | } |
---|
| 916 | else { |
---|
| 917 | $form['#state_creation'] = _workflow_creation_state($estados['wid']); |
---|
| 918 | } |
---|
| 919 | } |
---|
| 920 | } |
---|
| 921 | $form['#node'] = $node; |
---|
| 922 | $form['#ftypes'] = $ftypes; |
---|
| 923 | $form['#grupos'] = $grupos; |
---|
| 924 | $form['#unidadesm'] = $unidadesm; |
---|
| 925 | $form['#variaciones'] = $variaciones; |
---|
| 926 | $form['#reformula'] = $reformula; |
---|
| 927 | $form['#id_ref'] = $id_ref; |
---|
| 928 | $form['#total_accion'] = $total_accion; |
---|
| 929 | $mes_inicio = 0; |
---|
| 930 | $mes_fin = 12; |
---|
| 931 | if (!variable_get('proyectos_operativos_reformulacion_meses', TRUE)) { |
---|
| 932 | $f_aux = explode(' ', $node->field_proyecto_fecha_i[0]['value']); |
---|
| 933 | $f_aux = explode('-', $f_aux[0]); |
---|
| 934 | $mes_inicio = (int) $f_aux[1]; |
---|
| 935 | $f_aux = explode(' ', $node->field_proyecto_fecha_f[0]['value']); |
---|
| 936 | $f_aux = explode('-', $f_aux[0]); |
---|
| 937 | $mes_fin = (int) $f_aux[1]; |
---|
| 938 | } |
---|
| 939 | $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; |
---|
| 940 | $proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion'); |
---|
| 941 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
| 942 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
| 943 | drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js'); |
---|
| 944 | $format_number = array( |
---|
| 945 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 946 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 947 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 948 | ); |
---|
| 949 | $form['#format_number'] = array('format_number' => $format_number); |
---|
| 950 | drupal_add_js($form['#format_number'], 'setting'); |
---|
| 951 | $i = 1; |
---|
| 952 | $sumafisica = 0; |
---|
| 953 | $sumaT = 0; |
---|
| 954 | $sumaTv = 0; |
---|
| 955 | $sumaplanm = array(); |
---|
| 956 | foreach($ftypes as $id_field => $texto) { |
---|
| 957 | $clase = ''; |
---|
| 958 | if ($form['#mes'] >= $i) { |
---|
| 959 | $clase .= 'campo-bloqueado '; |
---|
| 960 | } |
---|
| 961 | elseif($mes_inicio > $i) { |
---|
| 962 | $clase .= 'campo-bloqueado '; |
---|
| 963 | } |
---|
| 964 | elseif($mes_fin < $i) { |
---|
| 965 | $clase .= 'campo-bloqueado '; |
---|
| 966 | } |
---|
| 967 | $varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 968 | $min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia; |
---|
| 969 | $total_accion += $min; |
---|
| 970 | $valor = isset($reformula['field_proyecto_meta_fisica'][0][$id_field])? $reformula['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 971 | $sumafisica += $valor; |
---|
| 972 | $sumaT += $min + $valor; |
---|
| 973 | $idformuj = str_replace('_', '-', 'field_proyecto_meta_fisica_' . $id_field); |
---|
| 974 | if (!isset($sumaplanm[$id_field])) { |
---|
| 975 | $sumaplanm[$id_field] = 0; |
---|
| 976 | } |
---|
| 977 | $sumaTv += $min; |
---|
| 978 | $sumaplanm[$id_field] = $min; |
---|
| 979 | $form['field_proyecto_meta_fisica_' . $id_field] = array( |
---|
| 980 | '#type' => 'textfield', |
---|
| 981 | '#default_value' => $valor, |
---|
| 982 | '#size' => 15, |
---|
| 983 | '#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')"), |
---|
| 984 | ); |
---|
| 985 | $form['field_proyecto_meta_fisica_to_' . $id_field] = array( |
---|
| 986 | '#type' => 'textfield', |
---|
| 987 | '#default_value' => $min + $valor, |
---|
| 988 | '#size' => 15, |
---|
| 989 | '#attributes' => array('class' => 'campo-bloqueado subtotales subtotal-' . $id_field . '-total number1'), |
---|
| 990 | ); |
---|
| 991 | $i++; |
---|
| 992 | } |
---|
| 993 | $form['field_proyecto_meta_fisica_total'] = array( |
---|
| 994 | '#type' => 'textfield', |
---|
| 995 | '#default_value' => $sumafisica, |
---|
| 996 | '#size' => 15, |
---|
| 997 | '#attributes' => array('class' => 'campo-bloqueado field-proyecto-meta-fisica-r-total number1'), |
---|
| 998 | ); |
---|
| 999 | $form['field_proyecto_meta_fisica_totalt'] = array( |
---|
| 1000 | '#type' => 'textfield', |
---|
| 1001 | '#default_value' => $sumaT, |
---|
| 1002 | '#size' => 15, |
---|
| 1003 | '#attributes' => array('class' => 'campo-bloqueado subtotales-total number1'), |
---|
| 1004 | ); |
---|
| 1005 | $sumaacciones = 0; |
---|
| 1006 | $sumaaccionm = array(); |
---|
| 1007 | $sumaaccionv = 0; |
---|
| 1008 | foreach($grupos as $nid => $ae) { |
---|
| 1009 | $i = 1; |
---|
| 1010 | $sumaP = 0; |
---|
| 1011 | $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']; |
---|
| 1012 | $form[$nid . '_field_accion_esp_metaf_unidadm'] = array( |
---|
| 1013 | '#title' => t('Unidad de Medida Nueva'), |
---|
| 1014 | '#type' => 'select', |
---|
| 1015 | '#options' => $options, |
---|
| 1016 | '#default_value' => $valor_unidad, |
---|
| 1017 | ); |
---|
| 1018 | foreach($ftypes as $id_field => $texto) { |
---|
| 1019 | $clase = ''; |
---|
| 1020 | if ($form['#mes'] >= $i) { |
---|
| 1021 | $clase = 'campo-bloqueado '; |
---|
| 1022 | } |
---|
| 1023 | elseif($mes_inicio > $i) { |
---|
| 1024 | $clase .= 'campo-bloqueado '; |
---|
| 1025 | } |
---|
| 1026 | elseif($mes_fin < $i) { |
---|
| 1027 | $clase .= 'campo-bloqueado '; |
---|
| 1028 | } |
---|
| 1029 | $idformuj = str_replace('_', '-', $nid . '_field_accion_esp_metaf_' . $id_field); |
---|
| 1030 | $varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0; |
---|
| 1031 | $min = $ae->field_accion_esp_metaf[0][$id_field] + $varia; |
---|
| 1032 | $total_accion += $min; |
---|
| 1033 | $valor = isset($reformula['field_accion_esp_metaf_' . $nid][0][$id_field])? $reformula['field_accion_esp_metaf_' . $nid][0][$id_field] : 0; |
---|
| 1034 | $sumaacciones += $min + $valor; |
---|
| 1035 | $sumaP += $valor; |
---|
| 1036 | if (!isset($sumaaccionm[$id_field])) { |
---|
| 1037 | $sumaaccionm[$id_field] = 0; |
---|
| 1038 | } |
---|
| 1039 | $sumaaccionv += $min; |
---|
| 1040 | $sumaaccionm[$id_field] += $min; |
---|
| 1041 | $form[$nid . '_field_accion_esp_metaf_' . $id_field] = array( |
---|
| 1042 | '#type' => 'textfield', |
---|
| 1043 | '#default_value' => $valor, |
---|
| 1044 | '#size' => 15, |
---|
| 1045 | '#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 . ");"), |
---|
| 1046 | ); |
---|
| 1047 | $i++; |
---|
| 1048 | } |
---|
| 1049 | $form[$nid . '_field_accion_esp_metaf_t'] = array( |
---|
| 1050 | '#type' => 'textfield', |
---|
| 1051 | '#default_value' => $sumaP, |
---|
| 1052 | '#size' => 15, |
---|
| 1053 | '#attributes' => array('class' => 'campo-bloqueado ' . $nid . '-field-accion-esp-metaf-total number1'), |
---|
| 1054 | ); |
---|
| 1055 | } |
---|
| 1056 | foreach($ftypes as $id_field => $texto) { |
---|
| 1057 | $form['field_accion_esp_metaft_' . $id_field] = array( |
---|
| 1058 | '#type' => 'textfield', |
---|
| 1059 | '#default_value' => $sumaaccionm[$id_field], |
---|
| 1060 | '#size' => 15, |
---|
| 1061 | '#attributes' => array('class' => 'campo-bloqueado subtotales1 subtotal1-' . $id_field . '-total number1'), |
---|
| 1062 | ); |
---|
| 1063 | } |
---|
| 1064 | $form['field_accion_esp_metaftt'] = array( |
---|
| 1065 | '#type' => 'textfield', |
---|
| 1066 | '#default_value' => $sumaacciones, |
---|
| 1067 | '#size' => 15, |
---|
| 1068 | '#attributes' => array('class' => 'campo-bloqueado subtotales1-total number1'), |
---|
| 1069 | ); |
---|
| 1070 | $jse = array( |
---|
| 1071 | 'sumatotal' => $sumaTv, |
---|
| 1072 | 'sumaplan' => $sumaplanm, |
---|
| 1073 | 'sumaacciones' => $sumaaccionv, |
---|
| 1074 | 'sumaaccion' => $sumaaccionm, |
---|
| 1075 | 'variacion' => $suma_variacion, |
---|
| 1076 | ); |
---|
| 1077 | $form['#jse'] = $jse; |
---|
| 1078 | drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting'); |
---|
| 1079 | $form['buttons'] = array( |
---|
| 1080 | '#prefix' => '<div class="container-inline">', |
---|
| 1081 | '#suffix' => '</div>', |
---|
| 1082 | ); |
---|
| 1083 | $form['buttons']['registrar'] = array( |
---|
| 1084 | '#type' => 'submit', |
---|
| 1085 | '#default_value' => t('Guardar'), |
---|
| 1086 | '#weight' => 100, |
---|
| 1087 | ); |
---|
| 1088 | $form['buttons']['cancelar'] = array( |
---|
| 1089 | '#type' => 'submit', |
---|
| 1090 | '#default_value' => t('Cancelar'), |
---|
| 1091 | '#weight' => 101, |
---|
| 1092 | ); |
---|
| 1093 | return $form; |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | /* |
---|
| 1097 | * Implementation of proyectos_reformulacion_reformula_tab_page_ae_form_validate() |
---|
| 1098 | */ |
---|
| 1099 | function proyectos_reformulacion_reformula_tab_page_form_validate($form, &$form_state) { |
---|
| 1100 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
| 1101 | if ($op == t('Cancelar')) { |
---|
| 1102 | return; |
---|
| 1103 | } |
---|
| 1104 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
| 1105 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
| 1106 | $proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion'); |
---|
| 1107 | drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js'); |
---|
| 1108 | drupal_add_js($form['#format_number'], 'setting'); |
---|
| 1109 | drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting'); |
---|
| 1110 | $start = $form_state['values']['variacion']; |
---|
| 1111 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
| 1112 | if ($start != $value) { |
---|
| 1113 | form_set_error('variacion', t('Solo números enteros son permitidos en la variación presupuestaria.')); |
---|
| 1114 | } |
---|
| 1115 | $ftypes = $form['#ftypes']; |
---|
| 1116 | foreach($ftypes as $id_field => $texto) { |
---|
| 1117 | $start = $form_state['values']['field_proyecto_meta_fisica_' . $id_field]; |
---|
| 1118 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
| 1119 | if ($start != $value) { |
---|
| 1120 | form_set_error('field_proyecto_meta_fisica_' . $id_field, t('Solo números enteros son permitidos en la meta fÃsica.')); |
---|
| 1121 | } |
---|
| 1122 | |
---|
| 1123 | if ($form_state['values']['field_proyecto_meta_fisica_' . $id_field] + $form['#jse']['sumaplan'][$id_field] < 0) { |
---|
| 1124 | 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')); |
---|
| 1125 | } |
---|
| 1126 | } |
---|
| 1127 | foreach($form['#grupos'] as $nid => $grupo) { |
---|
| 1128 | foreach($ftypes as $id_field => $texto) { |
---|
| 1129 | $start = $form_state['values'][$nid . '_field_accion_esp_metaf_' . $id_field]; |
---|
| 1130 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
| 1131 | if ($start != $value) { |
---|
| 1132 | 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.')); |
---|
| 1133 | } |
---|
| 1134 | } |
---|
| 1135 | } |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | /* |
---|
| 1139 | * Implementation of proyectos_reformulacion_reformula_tab_page_form_submit() |
---|
| 1140 | */ |
---|
| 1141 | function proyectos_reformulacion_reformula_tab_page_form_submit($form, &$form_state) { |
---|
| 1142 | global $user; |
---|
| 1143 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
| 1144 | if ($op == t('Cancelar')) { |
---|
| 1145 | drupal_set_message(t('La reformulación ha sido cancelada.')); |
---|
| 1146 | if ($form['#id_ref']) { |
---|
| 1147 | $form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#id_ref'] . '/view'; |
---|
| 1148 | } |
---|
| 1149 | else { |
---|
| 1150 | $form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular'; |
---|
| 1151 | } |
---|
| 1152 | return; |
---|
| 1153 | } |
---|
| 1154 | $fecha_onapre = mktime(0, 0, 0, $form_state['values']['fecha_onapre']['month'], $form_state['values']['fecha_onapre']['day'], $form_state['values']['fecha_onapre']['year']); |
---|
| 1155 | $ftypes = $form['#ftypes']; |
---|
| 1156 | $id_ref = $form['#id_ref']; |
---|
| 1157 | $campos = array(); |
---|
| 1158 | $justificacion = check_plain($form_state['values']['justificacion']); |
---|
| 1159 | $campos[] = "field_name = 'field_proyecto_meta_fisica'"; |
---|
| 1160 | foreach($form['#grupos'] as $nid => $grupo) { |
---|
| 1161 | $campos[] = "'field_accion_esp_metaf_" . $nid . "'"; |
---|
| 1162 | } |
---|
| 1163 | db_query("DELETE FROM {proyectos_reformula} WHERE nid = %d AND id_ref = %d AND ae = 0", $form['#node']->nid, $id_ref); |
---|
| 1164 | if(!$id_ref) { |
---|
| 1165 | 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); |
---|
| 1166 | $id_ref = db_last_insert_id('proyectos_reformular', 'id_ref'); |
---|
| 1167 | } |
---|
| 1168 | $field = array(); |
---|
| 1169 | $field[] = $id_ref; |
---|
| 1170 | $field[] = 'field_proyecto_meta_fisica'; |
---|
| 1171 | $field[] = 0; |
---|
| 1172 | $field[] = $form['#node']->nid; |
---|
| 1173 | foreach($ftypes as $id_field => $texto) { |
---|
| 1174 | $field[] = $form_state['values']['field_proyecto_meta_fisica_' . $id_field]; |
---|
| 1175 | } |
---|
| 1176 | 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); |
---|
| 1177 | foreach($form['#grupos'] as $nid => $grupo) { |
---|
| 1178 | $field = array(); |
---|
| 1179 | $field[] = $id_ref; |
---|
| 1180 | $field[] = 'field_accion_esp_metaf_' . $nid; |
---|
| 1181 | $field[] = 0; |
---|
| 1182 | $field[] = $form['#node']->nid; |
---|
| 1183 | foreach($ftypes as $id_field => $texto) { |
---|
| 1184 | $field[] = $form_state['values'][$nid . '_field_accion_esp_metaf_' . $id_field]; |
---|
| 1185 | } |
---|
| 1186 | $field[] = $form_state['values'][$nid . '_field_accion_esp_metaf_unidadm']; |
---|
| 1187 | 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); |
---|
| 1188 | } |
---|
| 1189 | drupal_set_message(t('La reformulación fue modificada')); |
---|
| 1190 | 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); |
---|
| 1191 | $form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $id_ref . '/view'; |
---|
| 1192 | } |
---|
| 1193 | |
---|
| 1194 | /* |
---|
| 1195 | * Implementation of _proyectos_reformulacion_load() |
---|
| 1196 | */ |
---|
| 1197 | function _proyectos_reformulacion_load($node, $id_ref = 0) { |
---|
| 1198 | $reformula_load = proyectosop_menu_reformulacion_load($id_ref, $node); |
---|
| 1199 | $reformula = array(); |
---|
| 1200 | $inputs = array(); |
---|
| 1201 | $sql = "SELECT * FROM {proyectos_reformula} WHERE nid = %d"; |
---|
| 1202 | $sql1 = "SELECT * FROM {proyectos_reformula_fuente} WHERE nid = %d"; |
---|
| 1203 | $inputs[] = $node->nid; |
---|
| 1204 | if ($reformula_load) { |
---|
| 1205 | $reformula['total'] = $reformula_load->variacion; |
---|
| 1206 | $reformula['unidad'] = $reformula_load->unidad; |
---|
| 1207 | $reformula['fecha_onapre'] = $reformula_load->fecha_onapre; |
---|
| 1208 | $reformula['justificacion'] = $reformula_load->justificacion; |
---|
| 1209 | $reformula['estado'] = $reformula_load->estado; |
---|
| 1210 | $sql .= ' AND id_ref = %d'; |
---|
| 1211 | $sql1 .= ' AND id_ref = %d'; |
---|
| 1212 | $inputs[] = $id_ref; |
---|
| 1213 | $result = db_query($sql, $inputs); |
---|
| 1214 | while($partida = db_fetch_array($result)) { |
---|
| 1215 | $reformula[$partida['field_name']][$partida['partida']] = $partida; |
---|
| 1216 | } |
---|
| 1217 | $result = db_query($sql1, $inputs); |
---|
| 1218 | while($partida = db_fetch_array($result)) { |
---|
| 1219 | $reformula[$partida['field_name']][0] = $partida; |
---|
| 1220 | } |
---|
| 1221 | } |
---|
| 1222 | return $reformula; |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | /* |
---|
| 1226 | * Implementation of _proyectos_reformula_all_load() |
---|
| 1227 | */ |
---|
| 1228 | function _proyectos_reformula_all_load($node, $id_ref = 0) { |
---|
| 1229 | $reformulaciones = array(); |
---|
| 1230 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 1231 | $result = db_query("SELECT * FROM {proyectos_reformular} WHERE nid = %d AND estado = %d ORDER BY id_ref DESC", $node->nid, $estado_aprobado); |
---|
| 1232 | while($reformula = db_fetch_array($result)) { |
---|
| 1233 | $reformulaciones[$reformula['id_ref']] = $reformula; |
---|
| 1234 | } |
---|
| 1235 | return $reformulaciones; |
---|
| 1236 | } |
---|
| 1237 | |
---|
| 1238 | /* |
---|
| 1239 | * Implementation of _proyectos_reformulacion_reformula_all_partidas_load() |
---|
| 1240 | */ |
---|
| 1241 | function _proyectos_reformula_all_partidas_load($node, $id_ref = 0) { |
---|
| 1242 | $variaciones = array(); |
---|
| 1243 | $ftypes = array( |
---|
| 1244 | 'value' => t('January'), |
---|
| 1245 | 'value_1' => t('February'), |
---|
| 1246 | 'value_2' => t('March'), |
---|
| 1247 | 'value_3' => t('April'), |
---|
| 1248 | 'value_4' => t('May'), |
---|
| 1249 | 'value_5' => t('June'), |
---|
| 1250 | 'value_6' => t('July'), |
---|
| 1251 | 'value_7' => t('August'), |
---|
| 1252 | 'value_8' => t('September'), |
---|
| 1253 | 'value_9' => t('Octuber'), |
---|
| 1254 | 'value_10' => t('November'), |
---|
| 1255 | 'value_11' => t('December'), |
---|
| 1256 | 'unidad' => t('Unidad'), |
---|
| 1257 | ); |
---|
| 1258 | $load_reformulaciones = array(); |
---|
| 1259 | $reformulaciones = _proyectos_reformula_all_load($node, $id_ref); |
---|
| 1260 | if ($id_ref) { |
---|
| 1261 | foreach($reformulaciones as $id => $value) { |
---|
| 1262 | if ($id < $id_ref) { |
---|
| 1263 | $load_reformulaciones[$id] = $values; |
---|
| 1264 | } |
---|
| 1265 | } |
---|
| 1266 | } |
---|
| 1267 | else { |
---|
| 1268 | $load_reformulaciones = $reformulaciones; |
---|
| 1269 | } |
---|
| 1270 | $current_id = 0; |
---|
| 1271 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 1272 | if(count($load_reformulaciones)) { |
---|
| 1273 | foreach($load_reformulaciones as $id => $value) { |
---|
| 1274 | $nueva_variacion = _proyectos_reformulacion_load($node, $id); |
---|
| 1275 | if ($estado_aprobado == $nueva_variacion['estado'] && !$current_id) { |
---|
| 1276 | $current_id = $id; |
---|
| 1277 | } |
---|
| 1278 | elseif($estado_aprobado == $nueva_variacion['estado'] && $current_id && $id > $current_id) { |
---|
| 1279 | $current_id = $id; |
---|
| 1280 | } |
---|
| 1281 | if(count($nueva_variacion)) { |
---|
| 1282 | foreach($nueva_variacion as $id_campo => $campo) { |
---|
| 1283 | if ($id_campo != 'total' && $id_campo != 'unidad') { |
---|
| 1284 | if(is_array($campo) && count($campo)) { |
---|
| 1285 | foreach($campo as $id_partida => $partida) { |
---|
| 1286 | if (!isset($variaciones[$id_campo][$id_partida]['partida'])) { |
---|
| 1287 | $variaciones[$id_campo][$id_partida]['partida'] = $partida['partida']; |
---|
| 1288 | } |
---|
| 1289 | foreach($ftypes as $idc => $valor) { |
---|
| 1290 | if (!isset($variaciones[$id_campo][$id_partida][$idc])) { |
---|
| 1291 | $variaciones[$id_campo][$id_partida][$idc] = 0; |
---|
| 1292 | } |
---|
| 1293 | if ($idc == 'unidad') { |
---|
| 1294 | if ($current_id == $id) { |
---|
| 1295 | $variaciones[$id_campo][$id_partida][$idc] = $partida[$idc]; |
---|
| 1296 | } |
---|
| 1297 | } |
---|
| 1298 | else { |
---|
| 1299 | $variaciones[$id_campo][$id_partida][$idc] += $partida[$idc]; |
---|
| 1300 | } |
---|
| 1301 | } |
---|
| 1302 | } |
---|
| 1303 | } |
---|
| 1304 | } |
---|
| 1305 | else { |
---|
| 1306 | if ($id_campo == 'total') { |
---|
| 1307 | if (!isset($variaciones['total'])) { |
---|
| 1308 | $variaciones['total'] = 0; |
---|
| 1309 | } |
---|
| 1310 | $variaciones['total'] += $campo; |
---|
| 1311 | } |
---|
| 1312 | else { |
---|
| 1313 | $variaciones['unidad'] = $campo; |
---|
| 1314 | } |
---|
| 1315 | } |
---|
| 1316 | } |
---|
| 1317 | } |
---|
| 1318 | } |
---|
| 1319 | } |
---|
| 1320 | return $variaciones; |
---|
| 1321 | } |
---|
| 1322 | |
---|
| 1323 | /* |
---|
| 1324 | * Implementation of theme_proyectos_reformulacion_reformula_tab_page_form() |
---|
| 1325 | */ |
---|
| 1326 | function theme_proyectos_reformulacion_reformula_tab_page_form($form) { |
---|
| 1327 | $node = $form['#node']; |
---|
| 1328 | $variaciones = $form['#variaciones']; |
---|
| 1329 | $reformula = $form['#reformula']; |
---|
| 1330 | $planificado = t('planificado'); |
---|
| 1331 | $total_AE_text = t('Total AE'); |
---|
| 1332 | $variacion = t('variación'); |
---|
| 1333 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 1334 | $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref); |
---|
| 1335 | $output = ''; |
---|
| 1336 | $output .= '<fieldset><legend>' . t('Monto Total del Proyecto') . '</legend>'; |
---|
| 1337 | $rows = array(); |
---|
| 1338 | $row = array(); |
---|
| 1339 | $row[] = array('data' => drupal_render($form['fecha_onapre'])); |
---|
| 1340 | $row[] = array('data' => drupal_render($form['justificacion'])); |
---|
| 1341 | $rows[] = $row; |
---|
| 1342 | $row = array(); |
---|
| 1343 | $row[] = array('data' => '<b>' . 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']))) . '</b>', 'colspan' => 2, 'align' => center); |
---|
| 1344 | $rows[] = $row; |
---|
| 1345 | $row = array(); |
---|
| 1346 | $row[] = array('data' => drupal_render($form['variacion']), ); |
---|
| 1347 | $row[] = array('data' => drupal_render($form['variaciont']), ); |
---|
| 1348 | $rows[] = $row; |
---|
| 1349 | $output .= theme('table', array(), $rows) . '</fieldset>'; |
---|
| 1350 | $output .= '<fieldset><legend>' . t('Distribución de la Meta FÃsica') . '</legend>'; |
---|
| 1351 | $output .= '<fieldset><legend>' . t('Meta FÃsica del Proyecto') . '</legend>'; |
---|
| 1352 | $output .= drupal_render($form['field_proyecto_unidadm_ant']); |
---|
| 1353 | $output .= drupal_render($form['field_proyecto_unidadm']); |
---|
| 1354 | $header = array(); |
---|
| 1355 | $header[] = array('data' => t('Meta FÃsica del Proyecto')); |
---|
| 1356 | $rows = array(); |
---|
| 1357 | $row = array(); |
---|
| 1358 | $row1 = array(); |
---|
| 1359 | $row2 = array(); |
---|
| 1360 | $row[] = array('data' => $planificado, ); |
---|
| 1361 | $row1[] = array('data' => $variacion, ); |
---|
| 1362 | $row2[] = array('data' => '<b>' . t('TOTAL') . '</b>', ); |
---|
| 1363 | $min_planificado = 0; |
---|
| 1364 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 1365 | $header[] = array('data' => $texto); |
---|
| 1366 | $varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 1367 | $min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia; |
---|
| 1368 | $min_planificado += $min; |
---|
| 1369 | $row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1370 | $row1[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_' . $id_field]), ); |
---|
| 1371 | $row2[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_to_' . $id_field]), ); |
---|
| 1372 | } |
---|
| 1373 | $row[] = array('data' => number_format($min_planificado, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1374 | $row1[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_total']), ); |
---|
| 1375 | $row2[] = array('data' => drupal_render($form['field_proyecto_meta_fisica_totalt']), ); |
---|
| 1376 | $rows[] = $row; |
---|
| 1377 | $rows[] = $row1; |
---|
| 1378 | $rows[] = $row2; |
---|
| 1379 | $header[] = array('data' => t('TOTAL')); |
---|
| 1380 | $output .= theme('table', $header, $rows); |
---|
| 1381 | $output .= '<div class="texto-proyecto-metafisica">' . t('Estimado Usuario: El monto a ingresar debe comenzar con el signo mas "+" o con el signo menos "-".') . '</div>'; |
---|
| 1382 | $output .= '</fieldset>'; |
---|
| 1383 | $output .= '<fieldset><legend>' . t('Meta FÃsica de las Acciones EspecÃficas') . '</legend>'; |
---|
| 1384 | $header = array(); |
---|
| 1385 | $header[] = array('data' => t('Meta FÃsica de las AEs')); |
---|
| 1386 | $header[] = array('data' => t('Unidad de Medida')); |
---|
| 1387 | $header[] = array('data' => t('% de la AEs'),); |
---|
| 1388 | $header[] = array('data' => '-',); |
---|
| 1389 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 1390 | $header[] = array('data' => $texto); |
---|
| 1391 | } |
---|
| 1392 | $header[] = array('data' => t('TOTAL')); |
---|
| 1393 | $rows = array(); |
---|
| 1394 | $rowsF = array(); |
---|
| 1395 | $i = 0; |
---|
| 1396 | $rowF = array(); |
---|
| 1397 | $rowF[] = array('data' => '<b>' . t('Número') . '</b>', 'align' => center,); |
---|
| 1398 | $rowF[] = array('data' => '<b>' . t('Nombre') . '</b>', 'align' => center,); |
---|
| 1399 | $rowsF[] = $rowF; |
---|
| 1400 | foreach($form['#grupos'] as $nid => $grupo) { |
---|
| 1401 | $i++; |
---|
| 1402 | $row = array(); |
---|
| 1403 | $rowF = array(); |
---|
| 1404 | $row1 = array(); |
---|
| 1405 | $row2 = array(); |
---|
| 1406 | $rowF[] = array('data' => t('AE %numero', array('%numero' => $i))); |
---|
| 1407 | $rowF[] = array('data' => $grupo->titulo_asignado); |
---|
| 1408 | $rowsF[] = $rowF; |
---|
| 1409 | $row[] = array('data' => t('AE %numero', array('%numero' => $i)), 'rowspan' => 3); |
---|
| 1410 | $row[] = array('data' => $form['#unidadesm'][$grupo->field_accion_esp_unidadm[0]['value']] . drupal_render($form[$nid . '_field_accion_esp_metaf_unidadm']), 'rowspan' => 3); |
---|
| 1411 | $row[] = array('data' => $grupo->field_accion_esp_ponderacion[0]['value'], 'rowspan' => 3); |
---|
| 1412 | $row[] = array('data' => $planificado, ); |
---|
| 1413 | $row1[] = array('data' => $variacion, ); |
---|
| 1414 | $row2[] = array('data' => $total_AE_text, ); |
---|
| 1415 | $min_planificado = 0; |
---|
| 1416 | $total_AE = 0; |
---|
| 1417 | $min_partida = 0; |
---|
| 1418 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 1419 | $varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0; |
---|
| 1420 | $min = $grupo->field_accion_esp_metaf[0][$id_field] + $varia; |
---|
| 1421 | $min_partida += $min; |
---|
| 1422 | } |
---|
| 1423 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 1424 | $idformuj = str_replace('_', '-', $nid . '_field_accion_esp_metaf_' . $id_field); |
---|
| 1425 | $varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0; |
---|
| 1426 | $min = $grupo->field_accion_esp_metaf[0][$id_field] + $varia; |
---|
| 1427 | $min_planificado += $min; |
---|
| 1428 | $total_AE += $min + $form[$nid . '_field_accion_esp_metaf_' . $id_field]['#value']; |
---|
| 1429 | $form[$nid . '_field_accion_esp_metaf_' . $id_field]['#attributes']['onchange'] .= "sumatotalAE('" . $nid . '-field-accion-esp-metaf-t' . "', " . $min_partida . ");"; |
---|
| 1430 | $row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1431 | $row1[] = array('data' => drupal_render($form[$nid . '_field_accion_esp_metaf_' . $id_field]), ); |
---|
| 1432 | $row2[] = array('data' => '<div id ="' . $idformuj . '-texto">' . number_format($min + $form[$nid . '_field_accion_esp_metaf_' . $id_field]['#value'], 0, $format_number['dec_point'], $format_number['thousands_sep']) . '</div>', ); |
---|
| 1433 | } |
---|
| 1434 | $row[] = array('data' => number_format($min_planificado, 0, ',', '.'), ); |
---|
| 1435 | $row1[] = array('data' => drupal_render($form[$nid . '_field_accion_esp_metaf_t']), ); |
---|
| 1436 | $row2[] = array('data' => '<div id ="' . $nid . '-field-accion-esp-metaf-t-texto' . '">' . number_format($total_AE, 0, $format_number['dec_point'], $format_number['thousands_sep']) . '</div>', ); |
---|
| 1437 | $rows[] = $row; |
---|
| 1438 | $rows[] = $row1; |
---|
| 1439 | $rows[] = $row2; |
---|
| 1440 | } |
---|
| 1441 | $row = array(); |
---|
| 1442 | $row[] = array('data' => '<b>' . t('TOTAL') . '</b>', 'colspan' => 4, 'align' => 'right'); |
---|
| 1443 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 1444 | $row[] = array('data' => drupal_render($form['field_accion_esp_metaft_' . $id_field]), ); |
---|
| 1445 | } |
---|
| 1446 | $row[] = array('data' => drupal_render($form['field_accion_esp_metaftt']), ); |
---|
| 1447 | $rows[] = $row; |
---|
| 1448 | $output .= theme('table', $header, $rows); |
---|
| 1449 | $output .= '<div class="texto-proyecto-metafisica">' . t('Estimado Usuario: El monto a ingresar debe comenzar con el signo mas "+" o con el signo menos "-".') . '</div>'; |
---|
| 1450 | $header = array(); |
---|
| 1451 | $header[] = array('data' => t('Detalles de las Acciones EspecÃficas'), 'colspan' => 2, 'align' => center); |
---|
| 1452 | $output .= theme('table', $header, $rowsF); |
---|
| 1453 | $output .= '</fieldset>'; |
---|
| 1454 | $output .= '</fieldset>'; |
---|
| 1455 | $output .= '<div id="acciones-centralizadas-form-acciones">' . drupal_render($form) .'</div>'; |
---|
| 1456 | return $output; |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | /** |
---|
| 1460 | * Implementation of _proyectos_operativos_reformula_obtiene_estados(). |
---|
| 1461 | * Obtiene los estados del tipo de contenido proyecto. |
---|
| 1462 | */ |
---|
| 1463 | function _proyectos_operativos_reformulacion_obtiene_estados() { |
---|
| 1464 | $estados = array(); |
---|
| 1465 | $wid = 0; |
---|
| 1466 | if (module_exists('workflow')) { |
---|
| 1467 | $wid = workflow_get_workflow_for_type('proyectos_operativos'); |
---|
| 1468 | if ($wid){ |
---|
| 1469 | $estados = workflow_get_states($wid); |
---|
| 1470 | } |
---|
| 1471 | } |
---|
| 1472 | return array( |
---|
| 1473 | 'wid' => $wid, |
---|
| 1474 | 'states' => $estados, |
---|
| 1475 | ); |
---|
| 1476 | } |
---|
| 1477 | |
---|
| 1478 | /* |
---|
| 1479 | * Implementation of _proyectos_reformulacion_reformula_list_page() |
---|
| 1480 | */ |
---|
| 1481 | function _proyectos_reformulacion_reformula_list_page($node) { |
---|
| 1482 | drupal_set_title(t('Reformulaciones del Proyecto')); |
---|
| 1483 | $output = ''; |
---|
| 1484 | $output .= _proyectos_reformulacion_reformula_obtiene_list_page($node, TRUE); |
---|
| 1485 | return $output; |
---|
| 1486 | } |
---|
| 1487 | |
---|
| 1488 | /* |
---|
| 1489 | * Implementation of _proyectos_reformulacion_reformula_obtiene_list_page() |
---|
| 1490 | */ |
---|
| 1491 | function _proyectos_reformulacion_reformula_obtiene_list_page($node, $muestra = TRUE) { |
---|
| 1492 | global $user; |
---|
| 1493 | $format_number = array( |
---|
| 1494 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 1495 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 1496 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 1497 | ); |
---|
| 1498 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 1499 | $current_time = time(); |
---|
| 1500 | $add_reformular = _proyectos_reformulacion_reformula_node_add_tab_access($node); |
---|
| 1501 | $tipo_plan = 'proyectos_operativos_reformular'; |
---|
| 1502 | $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo); |
---|
| 1503 | $fecha = FALSE; |
---|
| 1504 | $ente = usuario_tiene_ente($user->uid); |
---|
| 1505 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
| 1506 | $fecha = TRUE; |
---|
| 1507 | } |
---|
| 1508 | if (!$fecha) { |
---|
| 1509 | if ($muestra) { |
---|
| 1510 | muestra_mensaje($tipo_plan, $ente_planificador->tipo); |
---|
| 1511 | } |
---|
| 1512 | } |
---|
| 1513 | else { |
---|
| 1514 | if ($ente->nid == $ente_planificador->nid) { |
---|
| 1515 | $fecha = TRUE; |
---|
| 1516 | if ($muestra) { |
---|
| 1517 | muestra_mensaje($tipo_plan, $ente_planificador->tipo, 0); |
---|
| 1518 | } |
---|
| 1519 | } |
---|
| 1520 | elseif (!user_access('admin planificador')) { |
---|
| 1521 | $fecha = FALSE; |
---|
| 1522 | } |
---|
| 1523 | } |
---|
| 1524 | $enlaces_estados = TRUE; |
---|
| 1525 | if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { |
---|
| 1526 | $enlaces_estados = FALSE; |
---|
| 1527 | } |
---|
| 1528 | $states = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 1529 | $first_state = 0; |
---|
| 1530 | if ($states['wid']) { |
---|
| 1531 | $first_state = _workflow_creation_state($states['wid']); |
---|
| 1532 | } |
---|
| 1533 | $estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL); |
---|
| 1534 | $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); |
---|
| 1535 | $header = array(); |
---|
| 1536 | $header[] = array('data' => t('Fecha')); |
---|
| 1537 | $header[] = array('data' => t('Estado Actual')); |
---|
| 1538 | $header[] = array('data' => t('Estado Anterior')); |
---|
| 1539 | $header[] = array('data' => t('Fecha de Aprobación')); |
---|
| 1540 | $header[] = array('data' => t('Monto (Bs)')); |
---|
| 1541 | $header[] = array('data' => t('Variación (Bs)')); |
---|
| 1542 | $header[] = array('data' => t('Total monto (Bs)')); |
---|
| 1543 | $header[] = array('data' => t('Usuario')); |
---|
| 1544 | $header[] = array('data' => t('Acción')); |
---|
| 1545 | $rows = array(); |
---|
| 1546 | $i = 1; |
---|
| 1547 | $roles = array_keys($user->roles); |
---|
| 1548 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 1549 | $editar = ($node->_workflow == $estado_aprobado); |
---|
| 1550 | while($reformular = db_fetch_object($result)) { |
---|
| 1551 | if ($user->uid == 1) { |
---|
| 1552 | // Superuser is special. |
---|
| 1553 | $roles_transition = 'ALL'; |
---|
| 1554 | } |
---|
| 1555 | else { |
---|
| 1556 | $roles_transition = $roles; |
---|
| 1557 | if ($user->uid == $reformular->uid && $reformular->uid > 0) { |
---|
| 1558 | $roles_transition += array('author' => 'author'); |
---|
| 1559 | } |
---|
| 1560 | } |
---|
| 1561 | $transitions = array(); |
---|
| 1562 | if ($states['wid']) { |
---|
| 1563 | $transitions = workflow_allowable_transitions($reformular->estado, 'to', $roles_transition); |
---|
| 1564 | } |
---|
| 1565 | unset($transitions[$reformular->estado]); |
---|
| 1566 | $acciones = array(); |
---|
| 1567 | $row = array(); |
---|
| 1568 | $row[] = array('data' => format_date($reformular->date),); |
---|
| 1569 | $estado = isset($states['states'][$reformular->estado]) ? $states['states'][$reformular->estado] : 'N/A'; |
---|
| 1570 | $row[] = array('data' => $estado,); |
---|
| 1571 | $estado = isset($states['states'][$reformular->estado_ant]) ? $states['states'][$reformular->estado_ant] : 'N/A'; |
---|
| 1572 | $row[] = array('data' => $estado,); |
---|
| 1573 | $row[] = array('data' => date( 'd/m/Y', $reformular->fecha_onapre),); |
---|
| 1574 | $row[] = array('data' => number_format($reformular->monto, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); |
---|
| 1575 | $row[] = array('data' => number_format($reformular->variacion, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); |
---|
| 1576 | $total = $reformular->monto + $reformular->variacion; |
---|
| 1577 | $row[] = array('data' => number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']),); |
---|
| 1578 | $row[] = array('data' => l($reformular->name, 'user/' . $reformular->uid),); |
---|
| 1579 | //display options |
---|
| 1580 | if ($editar) { |
---|
| 1581 | $acciones[] = l(t('Ver'), 'proyectosop/' . $node->nid . '/reformular/' . $reformular->id_ref . '/view'); |
---|
| 1582 | } |
---|
| 1583 | if ($add_reformular) { |
---|
| 1584 | $acciones[] = l(t('Agregar nueva reformulación'), 'proyectosop/' . $node->nid . '/reformular/add'); |
---|
| 1585 | } |
---|
| 1586 | if ($editar && $fecha && $reformular->estado != $estado_naprobado && $reformular->estado != $estado_aprobado && $reformular->id_ref) { |
---|
| 1587 | $acciones[] = l(t('Modificar'), 'proyectosop/' . $node->nid . '/reformular/' . $reformular->id_ref . '/edit'); |
---|
| 1588 | } |
---|
| 1589 | if ($enlaces_estados && count($transitions) && $reformular->estado != $estado_aprobado) { |
---|
| 1590 | foreach($transitions as $id => $transition) { |
---|
| 1591 | $acciones[] = l(t('Enviar a @state', array('@state' => $transition)), 'proyectosop/' . $node->nid . '/reformular/' . $reformular->id_ref . '/workflow/' . $id); |
---|
| 1592 | } |
---|
| 1593 | } |
---|
| 1594 | $row[] = array('data' => theme('item_list', $acciones),); |
---|
| 1595 | $rows[] = $row; |
---|
| 1596 | $i++; |
---|
| 1597 | } |
---|
| 1598 | if (!count($rows)) { |
---|
| 1599 | $row[] = array('data' => 'No existen reformulaciones para este proyecto', 'colspan' => 9); |
---|
| 1600 | $rows[] = $row; |
---|
| 1601 | } |
---|
| 1602 | $output = ''; |
---|
| 1603 | if ($node->field_acciones_ente[0]['nid']) { |
---|
| 1604 | $output = '<fieldset><legend>' . t('Datos de la Acción Centralizada') . '</legend>'; |
---|
| 1605 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 1606 | $output .= '<div class="field"><div class="field-label">' . t('Ente') . ':</div>' . l($ente_planificador->title, 'proyectosop/' . $ente_planificador->nid) . '</div>'; |
---|
| 1607 | $output .= '<div class="field"><div class="field-label">' . t('Año') . ':</div>' . $node->anhoproyectos_operativos . '</div>'; |
---|
| 1608 | $output .= '<div class="field"><div class="field-label">' . t('Autor') . ':</div>' . l($node->name, 'user/' . $node->uid) . '</div>'; |
---|
| 1609 | $output .= '<div class="field"><div class="field-label">' . t('Fecha de creación') . ':</div>' . format_date($node->created) . '</div>'; |
---|
| 1610 | $output .= '<div class="field"><div class="field-label">' . t('Fecha de la última actualización') . ':</div>' . format_date($node->changed) . '</div>'; |
---|
| 1611 | if (module_exists('workflow')) { |
---|
| 1612 | $states = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 1613 | $first_state = _workflow_creation_state($states['wid']); |
---|
| 1614 | $estado = $node->_workflow == $first_state ? t('Ingresado') : $states['states'][$node->_workflow]; |
---|
| 1615 | $output .= '<div class="field"><div class="field-label">' . t('Estado del proyecto') . ':</div>' . $estado . '</div>'; |
---|
| 1616 | } |
---|
| 1617 | $output .= '</fieldset>'; |
---|
| 1618 | } |
---|
| 1619 | $output .= '<fieldset><legend>' . t('Reformulaciones del proyecto') . '</legend>'; |
---|
| 1620 | $output .= theme('table', $header, $rows) . '</fieldset>'; |
---|
| 1621 | return $output; |
---|
| 1622 | } |
---|
| 1623 | |
---|
| 1624 | /* |
---|
| 1625 | * Implementation of total_reformulado_ae() |
---|
| 1626 | * Obtiene el monto total de las partidas de las acciones especificas |
---|
| 1627 | */ |
---|
| 1628 | function total_reformulado_ae($node, $reformula, $exclude = array()) { |
---|
| 1629 | $ae_l = array(); |
---|
| 1630 | $suma_r_ae = 0; |
---|
| 1631 | $ftypes = array( |
---|
| 1632 | 'value' => t('January'), |
---|
| 1633 | 'value_1' => t('February'), |
---|
| 1634 | 'value_2' => t('March'), |
---|
| 1635 | 'value_3' => t('April'), |
---|
| 1636 | 'value_4' => t('May'), |
---|
| 1637 | 'value_5' => t('June'), |
---|
| 1638 | 'value_6' => t('July'), |
---|
| 1639 | 'value_7' => t('August'), |
---|
| 1640 | 'value_8' => t('September'), |
---|
| 1641 | 'value_9' => t('Octuber'), |
---|
| 1642 | 'value_10' => t('November'), |
---|
| 1643 | 'value_11' => t('December'), |
---|
| 1644 | ); |
---|
| 1645 | if ($node->field_proyecto_accion_esp[0]['nid']) { |
---|
| 1646 | foreach($node->field_proyecto_accion_esp as $ae) { |
---|
| 1647 | $ae_l[$ae['nid']] = $ae['nid']; |
---|
| 1648 | if (!isset($exclude[$ae['nid']])) { |
---|
| 1649 | |
---|
| 1650 | if (array_key_exists('field_accion_esp_programacion_' . $ae['nid'], $reformula)) { |
---|
| 1651 | foreach($reformula['field_accion_esp_programacion_' . $ae['nid']] as $montos_accion) { |
---|
| 1652 | foreach ($ftypes as $clave => $valor) { |
---|
| 1653 | $suma_r_ae += $montos_accion[$clave]; |
---|
| 1654 | } |
---|
| 1655 | } |
---|
| 1656 | } |
---|
| 1657 | } |
---|
| 1658 | } |
---|
| 1659 | } |
---|
| 1660 | return $suma_r_ae; |
---|
| 1661 | } |
---|
| 1662 | |
---|
| 1663 | /* |
---|
| 1664 | * Implementation of _proyectos_reformulacion_reformula_tab_page_ver() |
---|
| 1665 | */ |
---|
| 1666 | function _proyectos_reformulacion_reformula_tab_page_ver($node, $reformulacion_load = 0, $show_variacion = TRUE, $muestra = TRUE) { |
---|
| 1667 | drupal_set_title(t('Consultar Reformulación')); |
---|
| 1668 | global $user; |
---|
| 1669 | $format_number = array( |
---|
| 1670 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 1671 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 1672 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 1673 | ); |
---|
| 1674 | $ftypes = array( |
---|
| 1675 | 'value' => t('January'), |
---|
| 1676 | 'value_1' => t('February'), |
---|
| 1677 | 'value_2' => t('March'), |
---|
| 1678 | 'value_3' => t('April'), |
---|
| 1679 | 'value_4' => t('May'), |
---|
| 1680 | 'value_5' => t('June'), |
---|
| 1681 | 'value_6' => t('July'), |
---|
| 1682 | 'value_7' => t('August'), |
---|
| 1683 | 'value_8' => t('September'), |
---|
| 1684 | 'value_9' => t('Octuber'), |
---|
| 1685 | 'value_10' => t('November'), |
---|
| 1686 | 'value_11' => t('December'), |
---|
| 1687 | ); |
---|
| 1688 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 1689 | $current_time = time(); |
---|
| 1690 | $add_reformular = _proyectos_reformulacion_reformula_node_add_tab_access($node); |
---|
| 1691 | $tipo_plan = 'proyectos_operativos_reformular'; |
---|
| 1692 | $mi_fecha = ente_planificador_user_acceso_proceso($tipo_plan, $ente_planificador->tipo); |
---|
| 1693 | $fecha = FALSE; |
---|
| 1694 | $ente = usuario_tiene_ente($user->uid); |
---|
| 1695 | if ($mi_fecha[1] + 86399 > $current_time && $mi_fecha[0] < $current_time) { |
---|
| 1696 | $fecha = TRUE; |
---|
| 1697 | } |
---|
| 1698 | if (!$fecha) { |
---|
| 1699 | if ($muestra) { |
---|
| 1700 | muestra_mensaje($tipo_plan, $ente_planificador->tipo); |
---|
| 1701 | } |
---|
| 1702 | } |
---|
| 1703 | else { |
---|
| 1704 | if ($ente->nid == $ente_planificador->nid) { |
---|
| 1705 | $fecha = TRUE; |
---|
| 1706 | if ($muestra) { |
---|
| 1707 | muestra_mensaje($tipo_plan, $ente_planificador->tipo, 0); |
---|
| 1708 | } |
---|
| 1709 | } |
---|
| 1710 | elseif (!user_access('admin planificador')) { |
---|
| 1711 | $fecha = FALSE; |
---|
| 1712 | } |
---|
| 1713 | } |
---|
| 1714 | $enlaces_estados = TRUE; |
---|
| 1715 | if ($ente->nid != $ente_planificador->nid && !user_access('admin planificador')) { |
---|
| 1716 | $enlaces_estados = FALSE; |
---|
| 1717 | } |
---|
| 1718 | $estado_aprobado = variable_get('proyectos_operativos_state_aprobado', NULL); |
---|
| 1719 | $editar = ($node->_workflow == $estado_aprobado); |
---|
| 1720 | $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; |
---|
| 1721 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 1722 | $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref); |
---|
| 1723 | //obtiene el total de las variaciones de las acciones especificas |
---|
| 1724 | $ae_l = array(); |
---|
| 1725 | $suma_r_ae = total_reformulado_ae($node, $reformula); |
---|
| 1726 | $field = content_fields('field_proyecto_unidadm', 'proyectos_operativos'); |
---|
| 1727 | $unidad_ant = $node->field_proyecto_unidadm[0]['value']; |
---|
| 1728 | $text_unidad = t('N/A'); |
---|
| 1729 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 1730 | $planificado = t('planificado'); |
---|
| 1731 | $variacion = t('variación'); |
---|
| 1732 | $options = array(); |
---|
| 1733 | if ($tree) { |
---|
| 1734 | foreach ($tree as $term) { |
---|
| 1735 | if ($term->tid == $unidad_ant) { |
---|
| 1736 | $text_unidad = $term->name; |
---|
| 1737 | } |
---|
| 1738 | $choice = new stdClass(); |
---|
| 1739 | $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name); |
---|
| 1740 | $options[] = $choice; |
---|
| 1741 | } |
---|
| 1742 | } |
---|
| 1743 | $field = content_fields('field_accion_esp_unidadm', 'accion_especifica'); |
---|
| 1744 | $unidadesm = array(); |
---|
| 1745 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 1746 | if ($tree) { |
---|
| 1747 | foreach ($tree as $term) { |
---|
| 1748 | $unidadesm[$term->tid] = $term->name; |
---|
| 1749 | } |
---|
| 1750 | } |
---|
| 1751 | $grupos = array(); |
---|
| 1752 | if ($node->field_proyecto_accion_esp[0]['nid']) { |
---|
| 1753 | foreach($node->field_proyecto_accion_esp as $ae) { |
---|
| 1754 | $grupos[$ae['nid']] = node_load($ae['nid']); |
---|
| 1755 | } |
---|
| 1756 | } |
---|
| 1757 | $varia = isset($variaciones['total']) ? $variaciones['total'] : 0; |
---|
| 1758 | $min = $node->field_proyecto_monto_anual[0]['value'] + $varia; |
---|
| 1759 | $valor = isset($reformula['total'])? $reformula['total'] : 0; |
---|
| 1760 | $total_accion = $min; |
---|
| 1761 | if (module_exists('workflow')) { |
---|
| 1762 | $estados = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 1763 | } |
---|
| 1764 | $mes = 2; |
---|
| 1765 | $planificado = t('planificado'); |
---|
| 1766 | $variacion = t('variación'); |
---|
| 1767 | $subtotal = t('Total AE'); |
---|
| 1768 | $output = ''; |
---|
| 1769 | if ($suma_r_ae != $reformula['total']) { |
---|
| 1770 | $output .= '<div id="mensaje_alerta"><label style ="color:red">' . 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']))) . '</label></div>'; |
---|
| 1771 | } |
---|
| 1772 | $output .= '<fieldset><legend>' . t('Resumen del Proyecto') . '</legend>'; |
---|
| 1773 | $output .= '<div class="field"><div class="field-label">' . t('Código Ãnico del Proyecto') . ':</div>' . $node->field_proyecto_codigo[0]['value'] . '</div>'; |
---|
| 1774 | $output .= '<div class="field"><div class="field-label">' . t('Nombre del Proyecto') . ':</div>' . $node->titulo_asignado . '</div>'; |
---|
| 1775 | $output .= '<div class="field"><div class="field-label">' . t('Organismo') . ':</div>' . $ente_planificador->title . '</div>'; |
---|
| 1776 | $output .= '</fieldset>'; |
---|
| 1777 | $output .= '<fieldset><legend>' . t('Datos de la Reformulación') . '</legend>'; |
---|
| 1778 | $states = array(); |
---|
| 1779 | if (module_exists('workflow')) { |
---|
| 1780 | $states = _proyectos_operativos_reformulacion_obtiene_estados(); |
---|
| 1781 | $header = array(); |
---|
| 1782 | $header[] = array('data' => t('Fecha'),); |
---|
| 1783 | $header[] = array('data' => t('Estado'),); |
---|
| 1784 | $header[] = array('data' => t('Estado anterior'),); |
---|
| 1785 | $header[] = array('data' => t('Comentario'),); |
---|
| 1786 | $header[] = array('data' => t('Usuario'),); |
---|
| 1787 | $rows = array(); |
---|
| 1788 | $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); |
---|
| 1789 | while($history = db_fetch_object($result)) { |
---|
| 1790 | $row = array(); |
---|
| 1791 | $row[] = array('data' => format_date($history->date),); |
---|
| 1792 | $row[] = array('data' => $states['states'][$history->estado],); |
---|
| 1793 | $row[] = array('data' => $states['states'][$history->estado_ant],); |
---|
| 1794 | $row[] = array('data' => $history->comentario,); |
---|
| 1795 | $row[] = array('data' => l($history->name, 'user/' . $history->uid),); |
---|
| 1796 | $rows[] = $row; |
---|
| 1797 | } |
---|
| 1798 | if (count($rows)) { |
---|
| 1799 | $output .= '<div class="field"><div class="field-label">' . t('Historial') . ':</div>' . theme('table', $header, $rows) . '</div>'; |
---|
| 1800 | } |
---|
| 1801 | else { |
---|
| 1802 | $output .= '<div class="field"><div class="field-label">' . t('Historial') . ':</div>' . t('No existe historial para esta reformulación') . '</div>'; |
---|
| 1803 | } |
---|
| 1804 | } |
---|
| 1805 | $output .= '</fieldset>'; |
---|
| 1806 | $output .= '<fieldset><legend>' . t('Monto Total del Proyecto') . '</legend>'; |
---|
| 1807 | $rows = array(); |
---|
| 1808 | $row = array(); |
---|
| 1809 | $row[] = array('data' => t('<b>Fecha de Aprobación:</b> %fecha_onapre', array('%fecha_onapre' => date( 'd/m/Y', $reformula['fecha_onapre']))), 'align' => 'left'); |
---|
| 1810 | $row[] = array('data' => t('<b>Justificación:</b> %justificacion', array('%justificacion' => $reformula['justificacion'])), 'align' => 'left'); |
---|
| 1811 | $rows[] = $row; |
---|
| 1812 | $row = array(); |
---|
| 1813 | $row[] = array('data' => '<b>' . 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']))) . '</b>', 'colspan' => 2, 'align' => center); |
---|
| 1814 | $rows[] = $row; |
---|
| 1815 | $row = array(); |
---|
| 1816 | $signo = ''; |
---|
| 1817 | if ($reformulacion_load->variacion > 0) { |
---|
| 1818 | $signo = '+'; |
---|
| 1819 | } |
---|
| 1820 | $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']))), ); |
---|
| 1821 | $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']))), ); |
---|
| 1822 | $rows[] = $row; |
---|
| 1823 | $output .= theme('table', array(), $rows) . '</fieldset>'; |
---|
| 1824 | $output .= '<fieldset><legend>' . t('Distribución de la Meta FÃsica') . '</legend>'; |
---|
| 1825 | $output .= '<fieldset><legend>' . t('Meta FÃsica del Proyecto') . '</legend>'; |
---|
| 1826 | $output .= '<div class="field"><div class="field-label">' . t('Unidad de Medida Anterior') . ':</div>' . $unidadesm[$node->field_proyecto_unidadm[0]['value']] . '</div>'; |
---|
| 1827 | $output .= '<div class="field"><div class="field-label">' . t('Unidad de Medida Nueva') . ':</div>' . $unidadesm[$reformulacion_load->unidad] . '</div>'; |
---|
| 1828 | $header = array(); |
---|
| 1829 | $header[] = array('data' => t('Meta FÃsica del Proyecto')); |
---|
| 1830 | $rows = array(); |
---|
| 1831 | $row = array(); |
---|
| 1832 | $row1 = array(); |
---|
| 1833 | $row2 = array(); |
---|
| 1834 | $row[] = array('data' => $planificado, ); |
---|
| 1835 | $row1[] = array('data' => $variacion, ); |
---|
| 1836 | $row2[] = array('data' => '<b>' . t('TOTAL') . '</b>', ); |
---|
| 1837 | $total = 0; |
---|
| 1838 | $total1 = 0; |
---|
| 1839 | foreach($ftypes as $id_field => $texto) { |
---|
| 1840 | $header[] = array('data' => $texto); |
---|
| 1841 | $varia = isset($variaciones['field_proyecto_meta_fisica'][0][$id_field]) ? $variaciones['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 1842 | $min = $node->field_proyecto_meta_fisica[0][$id_field] + $varia; |
---|
| 1843 | $valor = isset($reformula['field_proyecto_meta_fisica'][0][$id_field])? $reformula['field_proyecto_meta_fisica'][0][$id_field] : 0; |
---|
| 1844 | $signo = ''; |
---|
| 1845 | if ($valor > 0) { |
---|
| 1846 | $signo = '+'; |
---|
| 1847 | } |
---|
| 1848 | $total += $min; |
---|
| 1849 | $total1 += $valor; |
---|
| 1850 | $row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1851 | $row1[] = array('data' => $signo . number_format($valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1852 | $row2[] = array('data' => number_format($min + $valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1853 | } |
---|
| 1854 | $row[] = array('data' => number_format($total, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1855 | $row1[] = array('data' => number_format($total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1856 | $row2[] = array('data' => number_format($total + $total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1857 | $rows[] = $row; |
---|
| 1858 | $rows[] = $row1; |
---|
| 1859 | $rows[] = $row2; |
---|
| 1860 | $header[] = array('data' => t('TOTAL')); |
---|
| 1861 | $output .= theme('table', $header, $rows); |
---|
| 1862 | $output .= '</fieldset>'; |
---|
| 1863 | $output .= '<fieldset><legend>' . t('Meta FÃsica de las Acciones EspecÃficas') . '</legend>'; |
---|
| 1864 | $header = array(); |
---|
| 1865 | $header[] = array('data' => t('Meta FÃsica de las AEs')); |
---|
| 1866 | $header[] = array('data' => t('Unidad de Medida')); |
---|
| 1867 | $header[] = array('data' => t('% de la AEs'),); |
---|
| 1868 | $header[] = array('data' => '-',); |
---|
| 1869 | foreach($ftypes as $id_field => $texto) { |
---|
| 1870 | $header[] = array('data' => $texto); |
---|
| 1871 | } |
---|
| 1872 | $header[] = array('data' => t('TOTAL')); |
---|
| 1873 | $rows = array(); |
---|
| 1874 | $rowsF = array(); |
---|
| 1875 | $i = 0; |
---|
| 1876 | $rowF = array(); |
---|
| 1877 | $rowF[] = array('data' => '<b>' . t('Número') . '</b>', 'align' => center,); |
---|
| 1878 | $rowF[] = array('data' => '<b>' . t('Nombre') . '</b>', 'align' => center,); |
---|
| 1879 | $rowF[] = array('data' => '<b>' . t('Acción') . '</b>', 'align' => center,); |
---|
| 1880 | $rowsF[] = $rowF; |
---|
| 1881 | $totalA = array(); |
---|
| 1882 | $totalT; |
---|
| 1883 | foreach($grupos as $nid => $grupo) { |
---|
| 1884 | $i++; |
---|
| 1885 | $row = array(); |
---|
| 1886 | $rowF = array(); |
---|
| 1887 | $row1 = array(); |
---|
| 1888 | $row2 = array(); |
---|
| 1889 | $rowF[] = array('data' => t('AE %numero', array('%numero' => $i))); |
---|
| 1890 | $rowF[] = array('data' => $grupo->titulo_asignado); |
---|
| 1891 | $links = array(); |
---|
| 1892 | $links[] = l(t('Ver reformulación'), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/ae/' . $grupo->nid); |
---|
| 1893 | if (_proyectos_reformulacion_reformula_node_edit_tab_access($node, $reformulacion_load)) { |
---|
| 1894 | $links[] = l(t('Reformular'), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/ae/' . $grupo->nid . '/edit'); |
---|
| 1895 | } |
---|
| 1896 | $rowF[] = array('data' => theme('item_list', $links),); |
---|
| 1897 | $rowsF[] = $rowF; |
---|
| 1898 | $row[] = array('data' => t('AE %numero', array('%numero' => $i)), 'rowspan' => 3); |
---|
| 1899 | $row[] = array('data' => t('<b>Unidad de Medida Anterior:</b> %umedida', array('%umedida' => $unidadesm[$grupo->field_accion_esp_unidadm[0]['value']])) . '<br/>'. t('<b>Unidad de Medida Nueva:</b> %umedida', array('%umedida' => $unidadesm[$reformula['field_accion_esp_metaf_' . $nid][0]['unidad']])), 'rowspan' => 3); |
---|
| 1900 | $row[] = array('data' => $grupo->field_accion_esp_ponderacion[0]['value'], 'rowspan' => 3); |
---|
| 1901 | $row[] = array('data' => $planificado, ); |
---|
| 1902 | $row1[] = array('data' => $variacion, ); |
---|
| 1903 | $row2[] = array('data' => $subtotal); |
---|
| 1904 | $total = 0; |
---|
| 1905 | $total1 = 0; |
---|
| 1906 | foreach($ftypes as $id_field => $texto) { |
---|
| 1907 | $varia = isset($variaciones['field_accion_esp_metaf_' . $nid][0][$id_field]) ? $variaciones['field_accion_esp_metaf_' . $nid][0][$id_field] : 0; |
---|
| 1908 | $min = $grupo->field_accion_esp_metaf[0][$id_field] + $varia; |
---|
| 1909 | $valor = isset($reformula['field_accion_esp_metaf_' . $nid][0][$id_field])? $reformula['field_accion_esp_metaf_' . $nid][0][$id_field] : 0; |
---|
| 1910 | $signo = ''; |
---|
| 1911 | if ($valor > 0) { |
---|
| 1912 | $signo = '+'; |
---|
| 1913 | } |
---|
| 1914 | $total += $min; |
---|
| 1915 | $total1 += $valor; |
---|
| 1916 | if (!isset($totalA[$id_field])) { |
---|
| 1917 | $totalA[$id_field] = 0; |
---|
| 1918 | } |
---|
| 1919 | $totalA[$id_field] += $min + $valor; |
---|
| 1920 | $totalT += $min + $valor; |
---|
| 1921 | $row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1922 | $row1[] = array('data' => $signo . number_format($valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1923 | $row2[] = array('data' => number_format($min + $valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1924 | } |
---|
| 1925 | $row[] = array('data' => number_format($total, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1926 | $row1[] = array('data' => number_format($total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1927 | $row2[] = array('data' => number_format($total + $total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1928 | $rows[] = $row; |
---|
| 1929 | $rows[] = $row1; |
---|
| 1930 | $rows[] = $row2; |
---|
| 1931 | } |
---|
| 1932 | $row = array(); |
---|
| 1933 | $row[] = array('data' => '<b>' . t('TOTAL') . '</b>', 'colspan' => 4, 'align' => 'right'); |
---|
| 1934 | foreach($ftypes as $id_field => $texto) { |
---|
| 1935 | $row[] = array('data' => number_format($totalA[$id_field], 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1936 | } |
---|
| 1937 | $row[] = array('data' => number_format($totalT, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 1938 | $rows[] = $row; |
---|
| 1939 | $output .= theme('table', $header, $rows); |
---|
| 1940 | $header = array(); |
---|
| 1941 | $header[] = array('data' => t('Detalles de las Acciones EspecÃficas'), 'colspan' => 3, 'align' => center); |
---|
| 1942 | $output .= theme('table', $header, $rowsF); |
---|
| 1943 | $output .= '</fieldset>'; |
---|
| 1944 | $output .= '</fieldset>'; |
---|
| 1945 | if ($show_variacion) { |
---|
| 1946 | $links = array(); |
---|
| 1947 | if ($editar) { |
---|
| 1948 | $links[] = l(t('Reformulaciones'), 'proyectosop/' . $node->nid . '/reformular'); |
---|
| 1949 | } |
---|
| 1950 | if ($add_reformular) { |
---|
| 1951 | $links[] = l(t('Agregar nueva reformulación'), 'proyectosop/' . $node->nid . '/reformular/add'); |
---|
| 1952 | } |
---|
| 1953 | if (isset($states['wid'])) { |
---|
| 1954 | $estado_naprobado = variable_get('proyectos_operativos_state_naprobado', NULL); |
---|
| 1955 | 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) { |
---|
| 1956 | $links[] = l(t('Modificar'), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/edit'); |
---|
| 1957 | } |
---|
| 1958 | $first_state = 0; |
---|
| 1959 | if ($states['wid']) { |
---|
| 1960 | $first_state = _workflow_creation_state($states['wid']); |
---|
| 1961 | } |
---|
| 1962 | if ($user->uid == 1) { |
---|
| 1963 | // Superuser is special. |
---|
| 1964 | $roles = 'ALL'; |
---|
| 1965 | } |
---|
| 1966 | else { |
---|
| 1967 | $roles = array_keys($user->roles); |
---|
| 1968 | $roles_transition = $roles; |
---|
| 1969 | if ($user->uid == $reformulacion_load->uid && $reformulacion_load->uid > 0) { |
---|
| 1970 | $roles += array('author' => 'author'); |
---|
| 1971 | } |
---|
| 1972 | } |
---|
| 1973 | $transitions = array(); |
---|
| 1974 | if ($states['wid']) { |
---|
| 1975 | $transitions = workflow_allowable_transitions($reformulacion_load->estado, 'to', $roles); |
---|
| 1976 | } |
---|
| 1977 | unset($transitions[$reformulacion_load->estado]); |
---|
| 1978 | if ($suma_r_ae == $reformula['total'] && $enlaces_estados && count($transitions) && $estado_aprobado != $reformulacion_load->estado) { |
---|
| 1979 | foreach($transitions as $id => $transition) { |
---|
| 1980 | $links[] = l(t('Enviar a @state', array('@state' => $transition)), 'proyectosop/' . $node->nid . '/reformular/' . $reformulacion_load->id_ref . '/workflow/' . $id); |
---|
| 1981 | } |
---|
| 1982 | } |
---|
| 1983 | } |
---|
| 1984 | $output .= '<div class="field"><div class="field-label">' . t('Acciones') . ':</div>' . implode(' | ', $links) . '</div>'; |
---|
| 1985 | } |
---|
| 1986 | return $output; |
---|
| 1987 | } |
---|
| 1988 | |
---|
| 1989 | /* |
---|
| 1990 | * Implementation of proyectos_reformulacion_reformula_tab_page_ae_form() |
---|
| 1991 | * Formulario para reformular las acciones especificas |
---|
| 1992 | */ |
---|
| 1993 | function proyectos_reformulacion_reformula_tab_page_ae_form($form_state, $node, $reformulacion_load = 0, $ae = 0) { |
---|
| 1994 | drupal_set_title(t('Reformular A.E.')); |
---|
| 1995 | $form = array(); |
---|
| 1996 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
| 1997 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
| 1998 | $proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion'); |
---|
| 1999 | drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js'); |
---|
| 2000 | $ftypes = array( |
---|
| 2001 | 'value' => t('January'), |
---|
| 2002 | 'value_1' => t('February'), |
---|
| 2003 | 'value_2' => t('March'), |
---|
| 2004 | 'value_3' => t('April'), |
---|
| 2005 | 'value_4' => t('May'), |
---|
| 2006 | 'value_5' => t('June'), |
---|
| 2007 | 'value_6' => t('July'), |
---|
| 2008 | 'value_7' => t('August'), |
---|
| 2009 | 'value_8' => t('September'), |
---|
| 2010 | 'value_9' => t('Octuber'), |
---|
| 2011 | 'value_10' => t('November'), |
---|
| 2012 | 'value_11' => t('December'), |
---|
| 2013 | ); |
---|
| 2014 | $partidas_nodo = array(); |
---|
| 2015 | foreach ($ae->field_accion_esp_programacion as $partida) { |
---|
| 2016 | if(!empty($partida['tid'])) { |
---|
| 2017 | $partidas_nodo[$partida['tid']] = $partida; |
---|
| 2018 | } |
---|
| 2019 | } |
---|
| 2020 | $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; |
---|
| 2021 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 2022 | $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref); |
---|
| 2023 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 2024 | $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref); |
---|
| 2025 | $field = content_fields('field_accion_esp_programacion', 'accion_especifica'); |
---|
| 2026 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 2027 | $vtid = $field['vtid']; |
---|
| 2028 | $partidas = array(); |
---|
| 2029 | if ($tree) { |
---|
| 2030 | foreach ($tree as $term) { |
---|
| 2031 | if (isset($vtid[$term->tid])) { |
---|
| 2032 | $partidas[$term->tid] = $term->name; |
---|
| 2033 | } |
---|
| 2034 | } |
---|
| 2035 | } |
---|
| 2036 | //$form['#mes'] = variable_get('accion_especifica_de_proyecto_seguimiento_mes_seguimiento', 0); |
---|
| 2037 | $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; |
---|
| 2038 | $format_number = array( |
---|
| 2039 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 2040 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 2041 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 2042 | ); |
---|
| 2043 | $form['#format_number'] = array('format_number' => $format_number); |
---|
| 2044 | drupal_add_js($form['#format_number'], 'setting'); |
---|
| 2045 | $totales = array(); |
---|
| 2046 | $totalT = 0; |
---|
| 2047 | $plant = array(); |
---|
| 2048 | $sumaplan = 0; |
---|
| 2049 | $sumaplanm = array(); |
---|
| 2050 | foreach($partidas as $tid => $term) { |
---|
| 2051 | $total = 0; |
---|
| 2052 | $total1 = 0; |
---|
| 2053 | $i = 1; |
---|
| 2054 | foreach($ftypes as $id_field => $texto) { |
---|
| 2055 | $varia = isset($variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0; |
---|
| 2056 | $min = $partidas_nodo[$tid][$id_field] + $varia; |
---|
| 2057 | $valor = isset($reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field])? $reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0; |
---|
| 2058 | $total1 += $valor; |
---|
| 2059 | $totalT += $min + $valor; |
---|
| 2060 | if (!isset($plant[$tid])) { |
---|
| 2061 | $plant[$tid] = 0; |
---|
| 2062 | } |
---|
| 2063 | $plant[$tid] += $min; |
---|
| 2064 | $sumaplan += $min; |
---|
| 2065 | if (!isset($totales[$id_field])) { |
---|
| 2066 | $totales[$id_field] = 0; |
---|
| 2067 | } |
---|
| 2068 | if (!isset($sumaplanm[$id_field])) { |
---|
| 2069 | $sumaplanm[$id_field] = 0; |
---|
| 2070 | } |
---|
| 2071 | $sumaplanm[$id_field] += $min; |
---|
| 2072 | $totales[$id_field] += $min + $valor; |
---|
| 2073 | $idformu = $ae->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field; |
---|
| 2074 | $idformuj = str_replace('_', '-', $idformu); |
---|
| 2075 | $clase = ''; |
---|
| 2076 | if ($form['#mes'] >= $i) { |
---|
| 2077 | $clase = 'campo-bloqueado '; |
---|
| 2078 | } |
---|
| 2079 | $form[$idformu] = array( |
---|
| 2080 | '#type' => 'textfield', |
---|
| 2081 | '#default_value' => $valor, |
---|
| 2082 | '#size' => 15, |
---|
| 2083 | '#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), |
---|
| 2084 | ); |
---|
| 2085 | $i++; |
---|
| 2086 | } |
---|
| 2087 | $form[$ae->nid . '_field_accion_esp_programacion_' . $tid . '_t'] = array( |
---|
| 2088 | '#type' => 'textfield', |
---|
| 2089 | '#default_value' => $total1, |
---|
| 2090 | '#size' => 15, |
---|
| 2091 | '#attributes' => array('class' => 'number1 campo-bloqueado field-accion-esp-programacion-r-' . $tid . '-total'), |
---|
| 2092 | ); |
---|
| 2093 | } |
---|
| 2094 | foreach($ftypes as $id_field => $texto) { |
---|
| 2095 | $form[$ae->nid . '_field_accion_esp_programacion_t_' . $id_field] = array( |
---|
| 2096 | '#type' => 'textfield', |
---|
| 2097 | '#default_value' => $totales[$id_field], |
---|
| 2098 | '#size' => 15, |
---|
| 2099 | '#attributes' => array('class' => 'number1 campo-bloqueado subtotales subtotal-' . $id_field . '-total'), |
---|
| 2100 | ); |
---|
| 2101 | } |
---|
| 2102 | $form[$ae->nid . '_field_accion_esp_programacion_t'] = array( |
---|
| 2103 | '#type' => 'textfield', |
---|
| 2104 | '#default_value' => $totalT, |
---|
| 2105 | '#size' => 15, |
---|
| 2106 | '#attributes' => array('class' => 'number1 campo-bloqueado subtotales-total'), |
---|
| 2107 | ); |
---|
| 2108 | //financiamiento |
---|
| 2109 | $arreglo_financiamiento = array(); |
---|
| 2110 | $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4); |
---|
| 2111 | for($i = 0; $i < $accion_especifica_number_fields; $i++) { |
---|
| 2112 | $arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : ''; |
---|
| 2113 | $arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array()); |
---|
| 2114 | } |
---|
| 2115 | |
---|
| 2116 | $form['#plant'] = $plant; |
---|
| 2117 | $form['#partidas_nodo'] = $partidas_nodo; |
---|
| 2118 | $form['#arreglo'] = $arreglo_financiamiento_fields; |
---|
| 2119 | $form['#ftypes'] = $ftypes; |
---|
| 2120 | $form['#partidas'] = $partidas; |
---|
| 2121 | $form['#node'] = $node; |
---|
| 2122 | $form['#variaciones'] = $variaciones; |
---|
| 2123 | $form['#reformula'] = $reformula; |
---|
| 2124 | $form['#id_ref'] = $id_ref; |
---|
| 2125 | $form['#ae'] = $ae; |
---|
| 2126 | $form['#reformula_load'] = $reformulacion_load; |
---|
| 2127 | $suma_r_ae = total_reformulado_ae($node, $reformula, array($ae->nid => 1)); |
---|
| 2128 | $monto_asignar = $form['#reformula_load']->variacion - $suma_r_ae; |
---|
| 2129 | $form['#monto_asignar'] = $monto_asignar; |
---|
| 2130 | $total = 0; |
---|
| 2131 | $sumafinm = array(); |
---|
| 2132 | $sumatotalf = 0; |
---|
| 2133 | foreach($arreglo_financiamiento as $id_items => $titulo) { |
---|
| 2134 | $form[$id_items] = array( |
---|
| 2135 | '#type' => 'fieldset', |
---|
| 2136 | '#title' => $titulo, |
---|
| 2137 | ); |
---|
| 2138 | $total1 = 0; |
---|
| 2139 | foreach($arreglo_financiamiento_fields[$id_items] as $id1) { |
---|
| 2140 | if ($id1) { |
---|
| 2141 | $id_items1 = str_replace('_', '-', $id_items); |
---|
| 2142 | $varia = isset($variaciones[$id1 . '_' . $ae->nid][0]['value']) ? $variaciones[$id1 . '_' . $ae->nid][0]['value'] : 0; |
---|
| 2143 | $min = $ae->{$id1}[0]['value'] + $varia; |
---|
| 2144 | if (!isset($sumafinm[$id_items1])) { |
---|
| 2145 | $sumafinm[$id_items1] = 0; |
---|
| 2146 | } |
---|
| 2147 | $valor = isset($reformula[$id1 . '_' . $ae->nid][0]['value'])? $reformula[$id1 . '_' . $ae->nid][0]['value'] : 0; |
---|
| 2148 | $sumafinm[$id_items1] += $min; |
---|
| 2149 | $sumatotalf += $min; |
---|
| 2150 | $field = content_fields($id1, 'accion_especifica'); |
---|
| 2151 | $total1 += $valor; |
---|
| 2152 | $total += $valor; |
---|
| 2153 | $idformuj = str_replace('_', '-', $id1); |
---|
| 2154 | $form[$id_items][$id1] = array( |
---|
| 2155 | '#type' => 'textfield', |
---|
| 2156 | '#default_value' => $valor, |
---|
| 2157 | '#size' => 20, |
---|
| 2158 | '#prefix' =>'<label><b>' . $field['widget']['label'] . ':</b></label><div class="field-label-planificado">' . 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']) . '</div><div class="field-label-reformulado">' . t('Variación') . ':</div>', |
---|
| 2159 | '#attributes' => array('class' => 'number subtotalff-' . $id_items1, 'onchange' => "prvalminimo('" . $idformuj . "', '" . $min . "');prsumaref2('" . 'subtotalff-' . $id_items1 . "', 'financia', '" . $id_items1 . "'); prsumaref('subtotalesf')"), |
---|
| 2160 | ); |
---|
| 2161 | } |
---|
| 2162 | } |
---|
| 2163 | |
---|
| 2164 | $form['totalf_' . $id_items] = array( |
---|
| 2165 | '#type' => 'textfield', |
---|
| 2166 | '#default_value' => $sumafinm[$id_items1], |
---|
| 2167 | '#size' => 20, |
---|
| 2168 | '#attributes' => array('class' => 'number1 campo-bloqueado subtotalesf subtotalff-' . $id_items1 . '-total'), |
---|
| 2169 | ); |
---|
| 2170 | } |
---|
| 2171 | $form['total_financiamiento'] = array( |
---|
| 2172 | '#type' => 'textfield', |
---|
| 2173 | '#default_value' => $sumatotalf, |
---|
| 2174 | '#size' => 20, |
---|
| 2175 | '#attributes' => array('class' => 'number1 campo-bloqueado subtotalesf-total'), |
---|
| 2176 | ); |
---|
| 2177 | $jse = array( |
---|
| 2178 | 'sumatotal' => $sumaplan, |
---|
| 2179 | 'sumaplan' => $sumaplanm, |
---|
| 2180 | 'financia' => $sumafinm, |
---|
| 2181 | 'sumatotalf' => $sumatotalf, |
---|
| 2182 | ); |
---|
| 2183 | $form['#jse'] = $jse; |
---|
| 2184 | drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting'); |
---|
| 2185 | $form['buttons'] = array( |
---|
| 2186 | '#prefix' => '<div class="container-inline">', |
---|
| 2187 | '#suffix' => '</div>', |
---|
| 2188 | ); |
---|
| 2189 | $form['buttons']['registrar'] = array( |
---|
| 2190 | '#type' => 'submit', |
---|
| 2191 | '#default_value' => t('Guardar'), |
---|
| 2192 | '#weight' => 100, |
---|
| 2193 | ); |
---|
| 2194 | $form['buttons']['cancelar'] = array( |
---|
| 2195 | '#type' => 'submit', |
---|
| 2196 | '#default_value' => t('Cancelar'), |
---|
| 2197 | '#weight' => 101, |
---|
| 2198 | ); |
---|
| 2199 | return $form; |
---|
| 2200 | } |
---|
| 2201 | |
---|
| 2202 | /* |
---|
| 2203 | * Implementation of proyectos_reformulacion_reformula_tab_page_ae_form_validate() |
---|
| 2204 | */ |
---|
| 2205 | function proyectos_reformulacion_reformula_tab_page_ae_form_validate($form, &$form_state) { |
---|
| 2206 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
| 2207 | if ($op == t('Cancelar')) { |
---|
| 2208 | return; |
---|
| 2209 | } |
---|
| 2210 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
| 2211 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
| 2212 | $proyectos_reformulacion_path = drupal_get_path('module', 'proyectos_reformulacion'); |
---|
| 2213 | drupal_add_js($proyectos_reformulacion_path . '/js/proyectos_reformulacion.js'); |
---|
| 2214 | //drupal_add_js($form['#format_number'], 'setting'); |
---|
| 2215 | //drupal_add_js(array('proyectos_reformulacion' => array('mfisicas' => $form['#jse'])), 'setting'); |
---|
| 2216 | //se obtienen la suma de la meta fisica |
---|
| 2217 | $mf = $form['#jse']['sumatotal']; |
---|
| 2218 | foreach($form['#partidas'] as $tid => $grupo) { |
---|
| 2219 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 2220 | $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; |
---|
| 2221 | $min = $form['#partidas_nodo'][$tid][$id_field] + $varia; |
---|
| 2222 | $start = $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]; |
---|
| 2223 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
| 2224 | if ($start != $value) { |
---|
| 2225 | 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]))); |
---|
| 2226 | } |
---|
| 2227 | if ($form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field] + $min < 0) { |
---|
| 2228 | 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]))); |
---|
| 2229 | } |
---|
| 2230 | $mf += $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]; |
---|
| 2231 | } |
---|
| 2232 | } |
---|
| 2233 | $finan = $form['#jse']['sumatotalf']; |
---|
| 2234 | //se obtiene la suma del financiamiento |
---|
| 2235 | foreach($form['#arreglo'] as $id => $arreglo1) { |
---|
| 2236 | foreach($arreglo1 as $id1) { |
---|
| 2237 | $varia = isset($form['#variaciones'][$id1 . '_' . $form['#ae']->nid][0]['value']) ? $form['#variaciones'][$id1 . '_' . $form['#ae']->nid][0]['value'] : 0; |
---|
| 2238 | $min = $form['#ae']->{$id1}[0]['value'] + $varia; |
---|
| 2239 | $start = $form_state['values'][$id1]; |
---|
| 2240 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
| 2241 | if ($start != $value) { |
---|
| 2242 | form_set_error($id1, t('Solo números enteros son permitidos en la fuente de financiamiento #nombre.', array('#nombre' => $form[$id1]['#title']))); |
---|
| 2243 | } |
---|
| 2244 | if ($form_state['values'][$id1] + $min < 0) { |
---|
| 2245 | 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']))); |
---|
| 2246 | } |
---|
| 2247 | $finan += $form_state['values'][$id1]; |
---|
| 2248 | } |
---|
| 2249 | } |
---|
| 2250 | if ($mf != $finan) { |
---|
| 2251 | 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))); |
---|
| 2252 | } |
---|
| 2253 | } |
---|
| 2254 | |
---|
| 2255 | /* |
---|
| 2256 | * Implementation of proyectos_reformulacion_reformula_tab_page_ae_form_validate() |
---|
| 2257 | */ |
---|
| 2258 | function proyectos_reformulacion_reformula_tab_page_ae_form_submit($form, &$form_state) { |
---|
| 2259 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
| 2260 | if ($op == t('Cancelar')) { |
---|
| 2261 | drupal_set_message(t('La reformulación ha sido cancelada.')); |
---|
| 2262 | $form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#id_ref']. '/ae/' . $form['#ae']->nid; |
---|
| 2263 | return; |
---|
| 2264 | } |
---|
| 2265 | 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); |
---|
| 2266 | 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); |
---|
| 2267 | foreach($form['#partidas'] as $tid => $grupo) { |
---|
| 2268 | $suma = 0; |
---|
| 2269 | $field = array(); |
---|
| 2270 | $field[] = $form['#id_ref']; |
---|
| 2271 | $field[] = 'field_accion_esp_programacion_' . $form['#ae']->nid; |
---|
| 2272 | $field[] = $tid; |
---|
| 2273 | $field[] = $form['#node']->nid; |
---|
| 2274 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 2275 | $suma += $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]; |
---|
| 2276 | $field[] = $form_state['values'][$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]; |
---|
| 2277 | } |
---|
| 2278 | if ($suma) { |
---|
| 2279 | $field[] = $form['#ae']->nid; |
---|
| 2280 | 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); |
---|
| 2281 | } |
---|
| 2282 | } |
---|
| 2283 | foreach($form['#arreglo'] as $id => $arreglo1) { |
---|
| 2284 | foreach($arreglo1 as $id1) { |
---|
| 2285 | if ($form_state['values'][$id1]) { |
---|
| 2286 | $field = array(); |
---|
| 2287 | $field[] = $form['#id_ref']; |
---|
| 2288 | $field[] = $id1 . '_' . $form['#ae']->nid; |
---|
| 2289 | $field[] = $form['#node']->nid; |
---|
| 2290 | $field[] = $form['#ae']->nid; |
---|
| 2291 | $field[] = $form_state['values'][$id1]; |
---|
| 2292 | db_query("INSERT INTO {proyectos_reformula_fuente} (id_ref, field_name, nid, ae, value) VALUES (%d, '%s', %d, %d, %f)", $field); |
---|
| 2293 | } |
---|
| 2294 | } |
---|
| 2295 | } |
---|
| 2296 | drupal_set_message(t('Se modifico la formulación de la acción especÃfica @nombre', array('@nombre' => $form['#ae']->titulo_asignado))); |
---|
| 2297 | $form_state['redirect'] = 'proyectosop/' . $form['#node']->nid . '/reformular/' . $form['#id_ref'] . '/ae/' . $form['#ae']->nid; |
---|
| 2298 | } |
---|
| 2299 | |
---|
| 2300 | /* |
---|
| 2301 | * Implementation of theme_proyectos_reformulacion_reformula_tab_page_form() |
---|
| 2302 | */ |
---|
| 2303 | function theme_proyectos_reformulacion_reformula_tab_page_ae_form($form) { |
---|
| 2304 | $planificado = t('planificado'); |
---|
| 2305 | $variacion = t('variación'); |
---|
| 2306 | $totalAEtexto = t('Total AE'); |
---|
| 2307 | $output = ''; |
---|
| 2308 | if ($form['#monto_asignar'] != 0) { |
---|
| 2309 | $output .= '<div id="mensaje_alerta"><label style ="color:red">' . 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']))) . '</label></div>'; |
---|
| 2310 | } |
---|
| 2311 | else { |
---|
| 2312 | $output .= '<div id="mensaje_alerta"><label style ="color:red">' . t('Ya el monto del proyecto ha sido asignado a otras Acciones EspecÃficas') . '</label></div>'; |
---|
| 2313 | } |
---|
| 2314 | $output .= '<fieldset><legend>' . t('Resumen Financiero de las Acciones') . '</legend>'; |
---|
| 2315 | $header = array(); |
---|
| 2316 | $header[] = array('data' => t('Partidas'), 'colspan' => 2); |
---|
| 2317 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 2318 | $header[] = array('data' => $texto); |
---|
| 2319 | } |
---|
| 2320 | $header[] = array('data' => t('TOTAL')); |
---|
| 2321 | $rows = array(); |
---|
| 2322 | $rowsF = array(); |
---|
| 2323 | $i = 0; |
---|
| 2324 | foreach($form['#partidas'] as $tid => $grupo) { |
---|
| 2325 | $i++; |
---|
| 2326 | $row = array(); |
---|
| 2327 | $row1 = array(); |
---|
| 2328 | $row2 = array(); |
---|
| 2329 | $row[] = array('data' => $grupo, 'rowspan' => 3); |
---|
| 2330 | $row[] = array('data' => $planificado, ); |
---|
| 2331 | $row1[] = array('data' => $variacion, ); |
---|
| 2332 | $row2[] = array('data' => $totalAEtexto, ); |
---|
| 2333 | $totales_partida = 0; |
---|
| 2334 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 2335 | $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; |
---|
| 2336 | $min = $form['#partidas_nodo'][$tid][$id_field] + $varia; |
---|
| 2337 | $totales_partida += $min; |
---|
| 2338 | } |
---|
| 2339 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 2340 | $idformu = $form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field; |
---|
| 2341 | $idformuj = str_replace('_', '-', $idformu); |
---|
| 2342 | $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; |
---|
| 2343 | $min = $form['#partidas_nodo'][$tid][$id_field] + $varia; |
---|
| 2344 | $form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]['#attributes']['onchange'] .= ";sumatotalAE('" . $idformuj . "'," . $min . ")"; |
---|
| 2345 | $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 . ");"; |
---|
| 2346 | $form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]['#attributes']['total_partida'] = $totales_partida; |
---|
| 2347 | $row[] = array('data' => number_format($min, 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), ); |
---|
| 2348 | $row1[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field]), ); |
---|
| 2349 | $row2[] = array('data' => '<div id ="' . $idformuj . '-texto">' . number_format($min, 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '</div>', ); |
---|
| 2350 | } |
---|
| 2351 | $row[] = array('data' => number_format($form['#plant'][$tid], 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), ); |
---|
| 2352 | $row1[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_' . $tid . '_t']), ); |
---|
| 2353 | $row2[] = array('data' => '<div id ="' . $form['#ae']->nid . '-field-accion-esp-programacion-' . $tid . '-t' . '-texto">' . number_format($form['#plant'][$tid], 0, $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']) . '</div>', ); |
---|
| 2354 | $rows[] = $row; |
---|
| 2355 | $rows[] = $row1; |
---|
| 2356 | $rows[] = $row2; |
---|
| 2357 | } |
---|
| 2358 | $row = array(); |
---|
| 2359 | $row[] = array('data' => '<b>' . t('TOTAL') . '</b>', 'colspan' => 2, 'align' => 'right'); |
---|
| 2360 | foreach($form['#ftypes'] as $id_field => $texto) { |
---|
| 2361 | $row[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_t_' . $id_field]), ); |
---|
| 2362 | } |
---|
| 2363 | $row[] = array('data' => drupal_render($form[$form['#ae']->nid . '_field_accion_esp_programacion_t']), ); |
---|
| 2364 | $rows[] = $row; |
---|
| 2365 | $output .= theme('table', $header, $rows); |
---|
| 2366 | $output .= '</fieldset>'; |
---|
| 2367 | $rows = array(); |
---|
| 2368 | $row = array(); |
---|
| 2369 | $row1 = array(); |
---|
| 2370 | foreach($form['#arreglo'] as $id => $arreglo1) { |
---|
| 2371 | $row[] = array('data' => drupal_render($form[$id]), ); |
---|
| 2372 | $row1[] = array('data' => drupal_render($form['totalf_' . $id]), ); |
---|
| 2373 | } |
---|
| 2374 | $rows[] = $row; |
---|
| 2375 | $rows[] = $row1; |
---|
| 2376 | $row = array(); |
---|
| 2377 | $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => 3, 'align' => 'right'); |
---|
| 2378 | $row[] = array('data' => drupal_render($form['total_financiamiento']), ); |
---|
| 2379 | $rows[] = $row; |
---|
| 2380 | $output .= '<fieldset><legend>' . t('Distribución por fuentes de Financiamiento') . '</legend>' . theme('table', array(), $rows) . '</fieldset>'; |
---|
| 2381 | $output .= '<div id="proyectos-reformulacion-form-acciones">' . drupal_render($form) .'</div>'; |
---|
| 2382 | return $output; |
---|
| 2383 | } |
---|
| 2384 | |
---|
| 2385 | /* |
---|
| 2386 | * Implementation of _proyectos_reformulacion_reformula_tab_page_ver_ae() |
---|
| 2387 | */ |
---|
| 2388 | function _proyectos_reformulacion_reformula_tab_page_ver_ae($node, $reformulacion_load = 0, $ae = 0) { |
---|
| 2389 | drupal_set_title(t('Consultar Reformulación de A.E.')); |
---|
| 2390 | $planificado = t('planificado'); |
---|
| 2391 | $format_number = array( |
---|
| 2392 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
| 2393 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
| 2394 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
| 2395 | ); |
---|
| 2396 | $variacion = t('variación'); |
---|
| 2397 | $subtotal = t('Total AE'); |
---|
| 2398 | $ftypes = array( |
---|
| 2399 | 'value' => t('January'), |
---|
| 2400 | 'value_1' => t('February'), |
---|
| 2401 | 'value_2' => t('March'), |
---|
| 2402 | 'value_3' => t('April'), |
---|
| 2403 | 'value_4' => t('May'), |
---|
| 2404 | 'value_5' => t('June'), |
---|
| 2405 | 'value_6' => t('July'), |
---|
| 2406 | 'value_7' => t('August'), |
---|
| 2407 | 'value_8' => t('September'), |
---|
| 2408 | 'value_9' => t('Octuber'), |
---|
| 2409 | 'value_10' => t('November'), |
---|
| 2410 | 'value_11' => t('December'), |
---|
| 2411 | ); |
---|
| 2412 | $partidas_nodo = array(); |
---|
| 2413 | foreach ($ae->field_accion_esp_programacion as $partida) { |
---|
| 2414 | if(!empty($partida['tid'])) { |
---|
| 2415 | $partidas_nodo[$partida['tid']] = $partida; |
---|
| 2416 | } |
---|
| 2417 | } |
---|
| 2418 | $id_ref = $reformulacion_load ? $reformulacion_load->id_ref : 0; |
---|
| 2419 | $reformula = _proyectos_reformulacion_load($node, $id_ref); |
---|
| 2420 | $variaciones = _proyectos_reformula_all_partidas_load($node, $id_ref); |
---|
| 2421 | $field = content_fields('field_accion_esp_programacion', 'accion_especifica'); |
---|
| 2422 | $tree = taxonomy_get_tree($field['vid']); |
---|
| 2423 | $vtid = $field['vtid']; |
---|
| 2424 | $partidas = array(); |
---|
| 2425 | $suma_r_ae = total_reformulado_ae($node, $reformula); |
---|
| 2426 | if ($tree) { |
---|
| 2427 | foreach ($tree as $term) { |
---|
| 2428 | if (isset($vtid[$term->tid])) { |
---|
| 2429 | $partidas[$term->tid] = $term->name; |
---|
| 2430 | } |
---|
| 2431 | } |
---|
| 2432 | } |
---|
| 2433 | //financiamiento |
---|
| 2434 | $arreglo_financiamiento = array(); |
---|
| 2435 | $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4); |
---|
| 2436 | for($i = 0; $i < $accion_especifica_number_fields; $i++) { |
---|
| 2437 | $arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : ''; |
---|
| 2438 | $arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array()); |
---|
| 2439 | } |
---|
| 2440 | |
---|
| 2441 | /* |
---|
| 2442 | $arreglo = array(); |
---|
| 2443 | $titles = array( |
---|
| 2444 | 'ordinarios' => t('Recursos Ordinarios'), |
---|
| 2445 | 'propios' => t('Recursos Propios'), |
---|
| 2446 | 'transferencias' => t('Donaciones'), |
---|
| 2447 | 'otros' => t('Otros'), |
---|
| 2448 | ); |
---|
| 2449 | $titles_field = array( |
---|
| 2450 | 'field_accion_esp_transferencias' => t('Recursos Ordinarios'), |
---|
| 2451 | 'field_accion_esp_creditosa' => t('Recursos Propios'), |
---|
| 2452 | 'transferencias' => t('Donaciones'), |
---|
| 2453 | 'otros' => t('Otros'), |
---|
| 2454 | ); |
---|
| 2455 | $arreglo['ordinarios'] = array( |
---|
| 2456 | 'field_accion_esp_transferencias' => 'field_accion_esp_transferencias', |
---|
| 2457 | 'field_accion_esp_creditosa' => 'field_accion_esp_creditosa', |
---|
| 2458 | 'field_accion_esp_mcti' => 'field_accion_esp_mcti', |
---|
| 2459 | ); |
---|
| 2460 | $arreglo['propios'] = array( |
---|
| 2461 | 'field_accion_esp_venta_act' => 'field_accion_esp_venta_act', |
---|
| 2462 | 'field_accion_esp_activos' => 'field_accion_esp_activos', |
---|
| 2463 | 'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja', |
---|
| 2464 | 'field_accion_esp_ventapro' => 'field_accion_esp_ventapro', |
---|
| 2465 | ); |
---|
| 2466 | $arreglo['transferencias'] = array( |
---|
| 2467 | 'field_accion_esp_donaciones' => 'field_accion_esp_donaciones', |
---|
| 2468 | ); |
---|
| 2469 | $arreglo['otros'] = array( |
---|
| 2470 | 'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion', |
---|
| 2471 | 'field_accion_esp_misionc' => 'field_accion_esp_misionc', |
---|
| 2472 | 'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona', |
---|
| 2473 | 'field_accion_esp_fonacit' => 'field_accion_esp_fonacit', |
---|
| 2474 | 'field_accion_esp_fonden' => 'field_accion_esp_fonden', |
---|
| 2475 | 'field_accion_esp_locti' => 'field_accion_esp_locti', |
---|
| 2476 | 'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi', |
---|
| 2477 | 'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie', |
---|
| 2478 | 'field_accion_esp_infocentro' => 'field_accion_esp_infocentro', |
---|
| 2479 | 'field_accion_esp_fidetel' => 'field_accion_esp_fidetel', |
---|
| 2480 | ); |
---|
| 2481 | */ |
---|
| 2482 | $output = ''; |
---|
| 2483 | $ente_planificador = node_load($node->field_proyecto_ente[0]['nid']); |
---|
| 2484 | if ($suma_r_ae != $reformula['total']) { |
---|
| 2485 | $output .= '<div id="mensaje_alerta"><label style ="color:red">' . 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']))) . '</label></div>'; |
---|
| 2486 | } |
---|
| 2487 | $output .= '<fieldset><legend>' . t('Resumen del Proyecto') . '</legend>'; |
---|
| 2488 | $output .= '<div class="field"><div class="field-label">' . t('Código Ãnico del Proyecto') . ':</div>' . $node->field_proyecto_codigo[0]['value'] . '</div>'; |
---|
| 2489 | $output .= '<div class="field"><div class="field-label">' . t('Nombre del Proyecto') . ':</div>' . $node->titulo_asignado . '</div>'; |
---|
| 2490 | $output .= '<div class="field"><div class="field-label">' . t('Organismo') . ':</div>' . $ente_planificador->title . '</div>'; |
---|
| 2491 | $output .= '</fieldset>'; |
---|
| 2492 | $output .= '<fieldset><legend>' . t('Resumen Financiero de las Acciones') . '</legend>'; |
---|
| 2493 | $header = array(); |
---|
| 2494 | $header[] = array('data' => t('Partidas'), 'colspan' => 2); |
---|
| 2495 | foreach($ftypes as $id_field => $texto) { |
---|
| 2496 | $header[] = array('data' => $texto); |
---|
| 2497 | } |
---|
| 2498 | $header[] = array('data' => t('TOTAL')); |
---|
| 2499 | $rows = array(); |
---|
| 2500 | $rowsF = array(); |
---|
| 2501 | $i = 0; |
---|
| 2502 | $totales = array(); |
---|
| 2503 | $totalT = 0; |
---|
| 2504 | $plant = array(); |
---|
| 2505 | $sumaplan = 0; |
---|
| 2506 | $sumaplanm = array(); |
---|
| 2507 | foreach($partidas as $tid => $grupo) { |
---|
| 2508 | $i++; |
---|
| 2509 | $total = 0; |
---|
| 2510 | $total1 = 0; |
---|
| 2511 | $row = array(); |
---|
| 2512 | $row1 = array(); |
---|
| 2513 | $row2 = array(); |
---|
| 2514 | $row[] = array('data' => $grupo, 'rowspan' => 3); |
---|
| 2515 | $row[] = array('data' => $planificado, ); |
---|
| 2516 | $row1[] = array('data' => $variacion, ); |
---|
| 2517 | $row2[] = array('data' => $subtotal, ); |
---|
| 2518 | foreach($ftypes as $id_field => $texto) { |
---|
| 2519 | $varia = isset($variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field]) ? $variaciones['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0; |
---|
| 2520 | $min = $partidas_nodo[$tid][$id_field] + $varia; |
---|
| 2521 | $valor = isset($reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field])? $reformula['field_accion_esp_programacion_' . $ae->nid][$tid][$id_field] : 0; |
---|
| 2522 | $signo = ''; |
---|
| 2523 | if ($valor > 0) { |
---|
| 2524 | $signo = '+'; |
---|
| 2525 | } |
---|
| 2526 | $total1 += $valor; |
---|
| 2527 | $totalT += $min + $valor; |
---|
| 2528 | if (!isset($plant[$tid])) { |
---|
| 2529 | $plant[$tid] = 0; |
---|
| 2530 | } |
---|
| 2531 | $plant[$tid] += $min; |
---|
| 2532 | $sumaplan += $min; |
---|
| 2533 | if (!isset($totales[$id_field])) { |
---|
| 2534 | $totales[$id_field] = 0; |
---|
| 2535 | } |
---|
| 2536 | if (!isset($sumaplanm[$id_field])) { |
---|
| 2537 | $sumaplanm[$id_field] = 0; |
---|
| 2538 | } |
---|
| 2539 | $sumaplanm[$id_field] += $min; |
---|
| 2540 | $totales[$id_field] += $min + $valor; |
---|
| 2541 | $idformu = $ae->nid . '_field_accion_esp_programacion_' . $tid . '_' . $id_field; |
---|
| 2542 | $idformuj = str_replace('_', '-', $idformu); |
---|
| 2543 | $row[] = array('data' => number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2544 | $row1[] = array('data' => $signo . number_format($valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2545 | $row2[] = array('data' => number_format($min + $valor, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2546 | } |
---|
| 2547 | $row[] = array('data' => number_format($plant[$tid], 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2548 | $row1[] = array('data' => number_format($total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2549 | $row2[] = array('data' => number_format($plant[$tid] + $total1, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2550 | $rows[] = $row; |
---|
| 2551 | $rows[] = $row1; |
---|
| 2552 | $rows[] = $row2; |
---|
| 2553 | } |
---|
| 2554 | $row = array(); |
---|
| 2555 | $row[] = array('data' => '<b>' . t('TOTAL') . '</b>', 'colspan' => 2, 'align' => 'right'); |
---|
| 2556 | foreach($ftypes as $id_field => $texto) { |
---|
| 2557 | $row[] = array('data' => number_format($totales[$id_field], 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2558 | } |
---|
| 2559 | $row[] = array('data' => number_format($totalT, 0, $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2560 | $rows[] = $row; |
---|
| 2561 | $output .= theme('table', $header, $rows); |
---|
| 2562 | $output .= '</fieldset>'; |
---|
| 2563 | $rows = array(); |
---|
| 2564 | $row = array(); |
---|
| 2565 | $row1 = array(); |
---|
| 2566 | $sumalT = 0; |
---|
| 2567 | foreach($arreglo_financiamiento as $id_items => $titulo) { |
---|
| 2568 | $sumal = 0; |
---|
| 2569 | $output1 = ''; |
---|
| 2570 | foreach($arreglo_financiamiento_fields[$id_items] as $id1) { |
---|
| 2571 | if ($id1) { |
---|
| 2572 | $field = content_fields($id1, 'accion_especifica'); |
---|
| 2573 | $varia = isset($variaciones[$id1 . '_' . $ae->nid][0]['value']) ? $variaciones[$id1 . '_' . $ae->nid][0]['value'] : 0; |
---|
| 2574 | $min = $ae->{$id1}[0]['value'] + $varia; |
---|
| 2575 | if (!isset($sumafinm[$id_items])) { |
---|
| 2576 | $sumafinm[$id_items] = 0; |
---|
| 2577 | } |
---|
| 2578 | $sumafinm[$id_items] += $min; |
---|
| 2579 | $sumatotalf += $min; |
---|
| 2580 | $field = content_fields($id1, 'accion_especifica'); |
---|
| 2581 | $valor = isset($reformula[$id1 . '_' . $ae->nid][0]['value'])? $reformula[$id1 . '_' . $ae->nid][0]['value'] : 0; |
---|
| 2582 | $total1 += $valor; |
---|
| 2583 | $total += $valor; |
---|
| 2584 | $sumal += $min + $valor; |
---|
| 2585 | $sumalT += $min + $valor; |
---|
| 2586 | $idformuj = str_replace('_', '-', $id1); |
---|
| 2587 | $signo = ''; |
---|
| 2588 | if ($valor > 0) { |
---|
| 2589 | $signo = '+'; |
---|
| 2590 | } |
---|
| 2591 | $output1 .= '<div class="field"><div class="field-label">' . $field['widget']['label'] . ':</div>' . '<div class="field-label-planificado">' . t('Planificado') . ': ' . number_format($min, 0, $format_number['dec_point'], $format_number['thousands_sep']) . '</div><div class="field-label-reformulado">' . t('Variación') . ': ' . $signo . number_format($valor, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '</div>' . '</div>'; |
---|
| 2592 | } |
---|
| 2593 | } |
---|
| 2594 | $row[] = array('data' => $output1, ); |
---|
| 2595 | $row1[] = array('data' => number_format($sumal, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2596 | } |
---|
| 2597 | $rows[] = $row; |
---|
| 2598 | $rows[] = $row1; |
---|
| 2599 | $row = array(); |
---|
| 2600 | $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => 3, 'align' => 'right'); |
---|
| 2601 | $row[] = array('data' => number_format($sumalT, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']), ); |
---|
| 2602 | $rows[] = $row; |
---|
| 2603 | $output .= '<fieldset><legend>' . t('Distribución por fuentes de Financiamiento') . '</legend>' . theme('table', array(), $rows) . '</fieldset>'; |
---|
| 2604 | return $output; |
---|
| 2605 | } |
---|