[303fae2] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
| 5 | * @file accion_especifica.module |
---|
| 6 | * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
| 7 | * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify |
---|
| 10 | * it under the terms of the GNU General Public License as published by |
---|
| 11 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | * (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | * |
---|
| 23 | * @author Cenditel Merida - Msc. Juan Vizcarrondo |
---|
| 24 | * @date 2013-02-02 // (año-mes-dia) |
---|
| 25 | * @version 0.1 // (0.1) |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /* |
---|
| 31 | * Impletations of hook_form_alter() |
---|
| 32 | */ |
---|
| 33 | function accion_especifica_mcti_form_alter(&$form, $form_state, $form_id) { |
---|
| 34 | if ($form_id == 'proyectos_operativos_admin_settings') { |
---|
| 35 | $form['accion_especifica']['proyectos_operativos_muestra_proyecto_ubicacion_geografica'] = array( |
---|
| 36 | '#type' => 'checkbox', |
---|
| 37 | '#title' => t('Recolectar la ubicación geografica de la Accion EspecÃfica.'), |
---|
| 38 | '#default_value' => variable_get('proyectos_operativos_muestra_proyecto_ubicacion_geografica', TRUE), |
---|
| 39 | '#weight' => 0, |
---|
| 40 | ); |
---|
| 41 | } |
---|
| 42 | if ($form_id == 'proyectos_operativos_accion_especifica_crear_form') { |
---|
| 43 | $node_type = content_types('accion_especifica'); |
---|
| 44 | $fields = $node_type['fields']; |
---|
[7d9e4be] | 45 | |
---|
| 46 | $proyecto = $form['#proyecto']; |
---|
| 47 | $ae_leido = $form['#node']; |
---|
| 48 | $ejecucion = 0; |
---|
[303fae2] | 49 | $montos = 0; |
---|
| 50 | $porcentajes = array(); |
---|
[7d9e4be] | 51 | foreach($proyecto->field_proyecto_accion_esp as $accion) { |
---|
[303fae2] | 52 | if ($accion['nid'] && $nid != $accion['nid']) { |
---|
| 53 | $accion_load = node_load($accion['nid']); |
---|
| 54 | if ($accion_load && $accion_load->type == 'accion_especifica') { |
---|
| 55 | if ($accion_load->field_accion_esp_programacion[0]['tid']) { |
---|
[7d9e4be] | 56 | foreach($accion_load->field_accion_esp_programacion as $programacion) { |
---|
| 57 | foreach($programacion as $id_value => $mesp){ |
---|
[303fae2] | 58 | if ($id_value != 'tid') { |
---|
| 59 | $montos +=$mesp; |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | $acciones_especificas[$accion_load->nid] = $accion_load; |
---|
| 65 | $porcentajes[$accion_load->field_accion_esp_ponderacion[0]['value']] = 1; |
---|
| 66 | $ejecucion += $accion_load->field_accion_esp_ponderacion[0]['value']; |
---|
| 67 | } |
---|
[7d9e4be] | 68 | } |
---|
| 69 | elseif($nid == $accion['nid']) { |
---|
| 70 | $acciones_especificas[$ae->nid] = $ae; |
---|
| 71 | } |
---|
[303fae2] | 72 | } |
---|
| 73 | $et = 100 - $ejecucion; |
---|
[7d9e4be] | 74 | $form['#mensaje_mostrar'] = t('Quedan @asignar% de ponderación en las Acciones EspecÃficas.', array('@asignar' => $et)); |
---|
| 75 | |
---|
| 76 | //agregando el campo geo |
---|
| 77 | if (variable_get('proyectos_operativos_muestra_proyecto_ubicacion_geografica', TRUE)) { |
---|
| 78 | $arreglo = array( |
---|
| 79 | 'field_accion_esp_geo' => 'field_accion_esp_geo', |
---|
| 80 | ); |
---|
| 81 | if (is_array($fields) && count($fields)) { |
---|
| 82 | foreach ($fields as $field_id => $field) { |
---|
| 83 | if (array_key_exists($field_id, $arreglo)) { |
---|
| 84 | $field_form[] = $field_id; |
---|
| 85 | $form['#proyectos_operativos_fields'][] = $field_id; |
---|
| 86 | } |
---|
| 87 | elseif (variable_get('proyectos_operativos_ac_muestra_geo_' . $field_id, FALSE)) { |
---|
| 88 | $field_form[] = $field_id; |
---|
| 89 | $form['#proyectos_operativos_fields'][] = $field_id; |
---|
| 90 | } |
---|
| 91 | } |
---|
[303fae2] | 92 | } |
---|
[7d9e4be] | 93 | |
---|
| 94 | if (is_array($field_form) && count($field_form)) { |
---|
| 95 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
| 96 | foreach ($field_form as $field_id) { |
---|
| 97 | $field = content_fields($field_id, 'accion_especifica'); |
---|
| 98 | $form['#field_info'][$field_id] = $field; |
---|
| 99 | $form += (array) content_field_form($form, $form_state, $field); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | foreach ($form['#validate'] as $id => $name) { |
---|
| 104 | if ($name == 'proyectos_operativos_accion_especifica_crear_form_validate') { |
---|
| 105 | $form['#validate'][$id] = 'proyectos_operativos_mcti_accion_especifica_crear_form_validate'; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | $nuevo_submit = array(); |
---|
| 109 | foreach ($form['#submit'] as $id => $name) { |
---|
| 110 | if ($name == 'proyectos_operativos_accion_especifica_crear_form_submit') { |
---|
| 111 | $nuevo_submit[] = 'proyectos_operativos_mcti_accion_especifica_crear_form_submit'; |
---|
| 112 | } |
---|
| 113 | $nuevo_submit[] = $name; |
---|
| 114 | } |
---|
[5edffdb] | 115 | $form['#esplurianual'] = ($proyecto->field_proyecto_plurianual[0]['value'] == variable_get('proyectos_operativos_plurianual', 0)) ? 1 : 0; |
---|
[7d9e4be] | 116 | $form['#submit'] = $nuevo_submit; |
---|
[303fae2] | 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * Validar accion especifica |
---|
| 122 | */ |
---|
| 123 | function proyectos_operativos_mcti_accion_especifica_crear_form_validate($form, &$form_state) { |
---|
| 124 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
| 125 | if ($op == t('Cancelar') || $op == t('Terminar')) { |
---|
| 126 | return; |
---|
| 127 | } |
---|
| 128 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
| 129 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
| 130 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos.js'); |
---|
| 131 | drupal_add_js($proyectos_operativos_path . '/js/accion_especifica.js'); |
---|
| 132 | drupal_add_js($form['#format_number'], 'setting'); |
---|
[7d9e4be] | 133 | drupal_add_js(array('accion_esp' => array('unidadmpers' => $form['#personas'])), 'setting'); |
---|
[303fae2] | 134 | //validamos que el porc sea mayor que cero |
---|
| 135 | if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) { |
---|
| 136 | form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser menor que 100')); |
---|
| 137 | } |
---|
[7d9e4be] | 138 | |
---|
[303fae2] | 139 | //validamos que el porc sea mayor que cero |
---|
| 140 | if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] <= 0) { |
---|
| 141 | form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser mayor que cero')); |
---|
| 142 | } |
---|
| 143 | //validamos que la ponderacion no sea mayor a 100 |
---|
| 144 | $suma_porc = $form['#ejecucion'] + $form_state['values']['field_accion_esp_ponderacion'][0]['value']; |
---|
| 145 | if ($suma_porc > 100) { |
---|
[7d9e4be] | 146 | form_set_error('field_accion_esp_ponderacion', t('La suma de las ponderaciones de la Acción especifica debe ser menor o igual a 100%')); |
---|
[303fae2] | 147 | } |
---|
[7d9e4be] | 148 | // validamos que la cantidad de acciones permitidas cumpla con la minima permitida |
---|
| 149 | if (variable_get('accion_especifica_100_ponderation', 0) && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) { |
---|
| 150 | form_set_error('field_accion_esp_ponderacion', t('La ponderación de la Acción especifica debe ser menor o igual a 100%')); |
---|
| 151 | } |
---|
[303fae2] | 152 | //validamos que la ponderacion no se encuentre repetida |
---|
| 153 | if (!variable_get('accion_especifica_allow_ponderation', 0) && isset($form['#porcentajes'][$form_state['values']['field_accion_esp_ponderacion'][0]['value']])) { |
---|
| 154 | form_set_error('field_accion_esp_ponderacion', t('Ya existe una acción especifica con esta ponderación')); |
---|
| 155 | } |
---|
| 156 | //validamos que las fechas esten dentro de la del proyecto |
---|
| 157 | if ($form_state['values']['field_accion_esp_fechai'][0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) { |
---|
| 158 | form_set_error('field_accion_esp_fechai', t('La fecha de inicio de la Acción especifica debe ser menor a la fecha de fin')); |
---|
| 159 | } |
---|
| 160 | if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) { |
---|
| 161 | form_set_error('field_accion_esp_fechai', t('La fecha de inicio de la Acción especifica debe ser mayor o igual a la fecha de inicio del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_i[0]['value']))); |
---|
| 162 | } |
---|
| 163 | if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechai'][0]['value']) { |
---|
| 164 | form_set_error('field_accion_esp_fechai', t('La fecha de inicio de la Acción especifica debe ser mayor o igual a la fecha de fin del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_f[0]['value']))); |
---|
| 165 | } |
---|
| 166 | if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechaf'][0]['value']) { |
---|
| 167 | form_set_error('field_accion_esp_fechaf', t('La fecha de fin de la Acción especifica debe ser menor o igual a la fecha de inicio del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_i[0]['value']))); |
---|
| 168 | } |
---|
| 169 | if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechaf'][0]['value']) { |
---|
| 170 | form_set_error('field_accion_esp_fechaf', t('La fecha de fin de la Acción especifica debe ser menor o igual a la fecha de fin del proyecto @fecha', array('@fecha' => $form['#proyecto']->field_proyecto_fecha_f[0]['value']))); |
---|
| 171 | } |
---|
| 172 | //obtener la fecha de inicio y fin |
---|
| 173 | $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']); |
---|
| 174 | $mes_inicio = 0; |
---|
[a4d4ed9] | 175 | $year_inicio = 0; |
---|
[303fae2] | 176 | if (count($mes)) { |
---|
| 177 | $mes_inicio = $mes[1] - 1; |
---|
[a4d4ed9] | 178 | $year_inicio = $mes[0]; |
---|
[303fae2] | 179 | } |
---|
| 180 | //obtener la fecha de inicio y fin |
---|
| 181 | $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']); |
---|
| 182 | $mes_final = 0; |
---|
[a4d4ed9] | 183 | $year_final = 0; |
---|
[303fae2] | 184 | if (count($mes)) { |
---|
| 185 | $mes_final = $mes[1] - 1; |
---|
[a4d4ed9] | 186 | $year_final = $mes[0]; |
---|
| 187 | } |
---|
[a10aa85] | 188 | |
---|
[a4d4ed9] | 189 | //validamos los proyectos plurianuales |
---|
| 190 | if ($form['#esplurianual']) { |
---|
| 191 | //se valida que el anho de inicio sea <= año del proyecto |
---|
| 192 | if ($form['#year_current']['year_current'] < $year_inicio) { |
---|
| 193 | form_set_error('field_accion_esp_fechai', t('El año de la fecha de inicio de la Acción especifica (@year_i) debe ser menor o igual a la fecha de ejecución del proyecto (@year_p)', array('@year_i' => $year_inicio, '@year_p' => $form['#year_current']['year_current']))); |
---|
| 194 | } |
---|
| 195 | elseif ($form['#year_current']['year_current'] > $year_inicio) { |
---|
| 196 | $mes_inicio = 0; |
---|
| 197 | } |
---|
| 198 | if ($form['#year_current']['year_current'] > $year_final) { |
---|
| 199 | form_set_error('field_accion_esp_fechai', t('El año de la fecha de finalización de la Acción especifica (@year_i) debe ser mayor o igual al año de ejecución del proyecto (@year_p)', array('@year_i' => $year_final, '@year_p' => $form['#year_current']['year_current']))); |
---|
| 200 | } |
---|
| 201 | elseif ($form['#year_current']['year_current'] < $year_final) { |
---|
| 202 | $mes_final = 12; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | else { |
---|
| 206 | if ($form['#year_current']['year_current'] != $year_inicio) { |
---|
| 207 | form_set_error('field_accion_esp_fechai', t('El año de la fecha de inicio de la Acción especifica (@year_i) debe ser igual a la fecha de ejecución del proyecto (@year_p)', array('@year_i' => $year_inicio, '@year_p' => $form['#year_current']['year_current']))); |
---|
| 208 | } |
---|
| 209 | if ($form['#year_current']['year_current'] > $year_final) { |
---|
| 210 | form_set_error('field_accion_esp_fechai', t('El año de la fecha de finalización de la Acción especifica (@year_i) debe ser igual al año de ejecución del proyecto (@year_p)', array('@year_i' => $year_final, '@year_p' => $form['#year_current']['year_current']))); |
---|
| 211 | } |
---|
[303fae2] | 212 | } |
---|
| 213 | if (isset($form_state['values']['field_accion_esp_metaf'])) { |
---|
| 214 | $suma = 0; |
---|
| 215 | for ($i = 0; $i < 12; $i++) { |
---|
| 216 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
| 217 | $valor = $i ? 'value_' . $i : 'value'; |
---|
| 218 | $suma += $form_state['values']['field_accion_esp_metaf'][0][$valor]; |
---|
| 219 | } |
---|
| 220 | } |
---|
[a10aa85] | 221 | if (!$suma && !($form['#esplurianual'])) { |
---|
[303fae2] | 222 | form_set_error('field_accion_esp_metaf', t('La Distribución de la Meta FisÃca de la Acción especifica debe tener al menos un resultado')); |
---|
| 223 | } |
---|
[7d9e4be] | 224 | /* |
---|
| 225 | $personas = $form['#personas']; |
---|
| 226 | if (count($personas) && isset($personas[$form_state['values']['field_accion_esp_unidadm'][0]['value']])) { |
---|
| 227 | $totalpersonas = $form_state['values']['field_accion_esp_meta_m'][0]['value'] + $form_state['values']['field_accion_esp_meta_f'][0]['value']; |
---|
| 228 | if ($totalpersonas != $suma) { |
---|
| 229 | form_set_error('field_accion_esp_meta_m', t('El total de Distribución de la Meta FisÃca de la Acción especifica debe ser igual a la cantidad de personas')); |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | */ |
---|
[303fae2] | 233 | } |
---|
| 234 | //validamos la accion especifica |
---|
| 235 | if (isset($form_state['values']['field_accion_esp_programacion']) && count($form_state['values']['field_accion_esp_programacion'])) { |
---|
| 236 | $sumap = 0; |
---|
[7d9e4be] | 237 | foreach($form_state['values']['field_accion_esp_programacion'] as $id_programacion => $programacion) { |
---|
[303fae2] | 238 | if (is_numeric($id_programacion)) { |
---|
| 239 | for ($i = 0; $i < 12; $i++) { |
---|
| 240 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
| 241 | $valor = $i ? 'value_' . $i : 'value'; |
---|
| 242 | $sumap += (float) $programacion[$valor]; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | if (!$sumap) { |
---|
| 248 | form_set_error('field_accion_esp_programacion', t('La Programación Financiera de la Acción especifica debe tener al menos un valor')); |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | $sumaf = 0; |
---|
| 252 | //validamos el financiamiento |
---|
| 253 | $first_field = FALSE; |
---|
| 254 | if (count($form['#fields_financiamiento'])) { |
---|
[7d9e4be] | 255 | foreach($form['#fields_financiamiento'] as $field_id) { |
---|
[303fae2] | 256 | $start = (float) $form_state['values'][$field_id][0]['value']; |
---|
| 257 | $start = number_format($start, $form['#format_number']['format_number']['decimals'], '.', ''); |
---|
| 258 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
| 259 | if ($start && $start != $value) { |
---|
| 260 | form_set_error($field_id, t('Solo números enteros son permitidos en la fuente de financiamiento.')); |
---|
| 261 | } |
---|
| 262 | if ($value < 0) { |
---|
| 263 | form_set_error($field_id, t('Solo números positivos son permitidos en la fuente de financiamiento.')); |
---|
| 264 | } |
---|
| 265 | if (!$first_field) { |
---|
| 266 | $first_field = $field_id; |
---|
| 267 | } |
---|
| 268 | if (isset($form_state['values'][$field_id][0]['value'])) { |
---|
| 269 | $sumaf += $form_state['values'][$field_id][0]['value']; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | } |
---|
[c25d016] | 273 | if ($first_field && $sumaf > $sumap) { |
---|
| 274 | form_set_error($first_field, t('Las fuentes de financiamiento (@f_financiamiento) deben ser menor o igual a la programación presupuestaria (@fuente)', array('@fuente' => number_format($sumap, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@f_financiamiento' => number_format($sumaf, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep'])))); |
---|
[303fae2] | 275 | } |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | /** |
---|
| 279 | * Implementation of hook_theme_registry_alter(). |
---|
| 280 | */ |
---|
| 281 | function accion_especifica_mcti_theme_registry_alter(&$theme_registry) { |
---|
| 282 | if ($theme_registry['proyectos_operativos_accion_especifica_crear_form']) { |
---|
| 283 | $theme_registry['proyectos_operativos_accion_especifica_crear_form']['function'] = 'theme_proyectos_operativos_accion_especifica_mcti_crear_form'; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | /** |
---|
| 288 | * tema a aplicar en el formulario proyectos_operativos_accion_especifica_crear_form |
---|
| 289 | */ |
---|
| 290 | function theme_proyectos_operativos_accion_especifica_mcti_crear_form($form) { |
---|
[7d9e4be] | 291 | $output = ''; |
---|
[303fae2] | 292 | if (!$form['#proyecto_completed']) { |
---|
| 293 | $output .= '<div id="mensaje-mostrar" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $form['#mensaje_mostrar'] . '</div>'; |
---|
| 294 | $output .= '<fieldset><legend>' . t('Definición de la Acción Especifica') . '</legend>' . drupal_render($form['field_accion_titulo']) . drupal_render($form['field_accion_esp_fechai']) . drupal_render($form['field_accion_esp_fechaf']);$output .= drupal_render($form['field_accion_esp_ejecutor']) . drupal_render($form['field_accion_esp_bien']) . '</fieldset>'; |
---|
| 295 | $output .= '<fieldset><legend>' . t('Distribución de la Meta Fisica de la acción Especifica') . '</legend>'; |
---|
| 296 | $output .= drupal_render($form['field_accion_esp_unidadm']); |
---|
| 297 | if (isset($form['field_accion_esp_meta_m']) && $form['field_accion_esp_meta_f']) { |
---|
| 298 | $output .= '<div id="meta-unidm-pers"><table id="unidm-persona" style="width:400px"><tr><th>' . $form['field_accion_esp_meta_m']['#title'] . '</th><th>' . $form['field_accion_esp_meta_f']['#title'] . '</th><th>' . t('Total') . '</th></tr><tr>'; |
---|
| 299 | $form['field_accion_esp_meta_m'][0]['value']['#title'] = ''; |
---|
| 300 | $form['field_accion_esp_meta_f'][0]['value']['#title'] = ''; |
---|
| 301 | $total = $form['field_accion_esp_meta_m'][0]['#value']['value'] + $form['field_accion_esp_meta_f'][0]['#value']['value']; |
---|
| 302 | $output .= '<td>' . drupal_render($form['field_accion_esp_meta_m']) . '</td>'; |
---|
| 303 | $output .= '<td>' . drupal_render($form['field_accion_esp_meta_f']) . '</td>'; |
---|
| 304 | $output .= '<td style="width:100px; text-align: center"><div class="unidad_personas_total">' . number_format($total, $format_number['decimals'], $format_number['dec_point'], $format_number['thousands_sep']) . '</div></td></tr></table></div>'; |
---|
| 305 | } |
---|
| 306 | $output .= drupal_render($form['field_accion_esp_ponderacion']); |
---|
[c25d016] | 307 | |
---|
| 308 | $output .= '<span title="Este campo es obligatorio." class="form-required" style="margin-left: 180px; position: absolute;">*</span>' . drupal_render($form['field_accion_esp_metaf']); |
---|
[303fae2] | 309 | $output .= '</fieldset>'; |
---|
| 310 | $output .= drupal_render($form['distribucion']); |
---|
[ef2ed7ba] | 311 | $output .= '<fieldset><legend>' . t('Programación Financiera de la Acción (Bs.)') . '</legend>' . drupal_render($form['field_accion_esp_programacion']); |
---|
[303fae2] | 312 | $ftypes = array( |
---|
| 313 | 'tid' => t('Account'), |
---|
| 314 | 'value' => t('Ene'), |
---|
| 315 | 'value_1' => t('Feb'), |
---|
| 316 | 'value_2' => t('Mar'), |
---|
| 317 | 'value_3' => t('Abr'), |
---|
| 318 | 'value_4' => t('May'), |
---|
| 319 | 'value_5' => t('Jun'), |
---|
| 320 | 'value_6' => t('Jul'), |
---|
| 321 | 'value_7' => t('Aug'), |
---|
| 322 | 'value_8' => t('Sep'), |
---|
| 323 | 'value_9' => t('Oct'), |
---|
| 324 | 'value_10' => t('Nov'), |
---|
| 325 | 'value_11' => t('Dic'), |
---|
| 326 | ); |
---|
| 327 | $output .= '<div style="width:2250px">'; |
---|
| 328 | $i = -1; |
---|
| 329 | foreach ($ftypes as $ftype => $label) { |
---|
| 330 | if($ftype != 'tid') { |
---|
| 331 | $output .= '<div class = "field_accion_esp_programacion_m' . $i . '_field_total field_accion_esp_programacion_totales" style = "width:143px;float:left;margin-left:10px; border: 1px solid #D5D5D5;text-align:center;overflow:auto">0</div>'; |
---|
| 332 | } |
---|
| 333 | else { |
---|
| 334 | $output .= '<div style = "width:180px;float:left;margin-left:5px;text-align:right"><b>' . t('TOTAL') . '</b></div>'; |
---|
| 335 | } |
---|
| 336 | $i++; |
---|
| 337 | } |
---|
| 338 | $output .= '<div class = "field_accion_esp_programacion_dato_field_total" style = "width:143px;float:left;margin-left:10px; border: 1px solid #D5D5D5;text-align:center;overflow:auto">0</div>'; |
---|
| 339 | $output .= '</div></fieldset>'; |
---|
[1ac0b21] | 340 | |
---|
| 341 | $output .= '<fieldset class="fuentes-de-financiamiento"><legend>' . t('Fuentes de Financiamiento en otras monedas') . '<span title="Este campo es obligatorio." class="form-required">*</span></legend>' . drupal_render($form['field_ae_finamonedas']) . '</fieldset>'; |
---|
| 342 | |
---|
[303fae2] | 343 | $rows = array(); |
---|
| 344 | $row = array(); |
---|
| 345 | $row1 = array(); |
---|
| 346 | $cantidad_campos = count($form['#arreglo_financiamiento']); |
---|
| 347 | if (is_array($form['#arreglo_financiamiento']) && count($form['#arreglo_financiamiento'])) { |
---|
| 348 | foreach ($form['#arreglo_financiamiento'] as $id => $macro) { |
---|
| 349 | $row[] = array('data' => drupal_render($form[$id]), ); |
---|
| 350 | $row1[] = array('data' => drupal_render($form['total_' . $id]), ); |
---|
| 351 | } |
---|
| 352 | $rows[] = $row; |
---|
| 353 | $rows[] = $row1; |
---|
| 354 | $row = array(); |
---|
| 355 | $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => $cantidad_campos - 1, 'align' => 'right'); |
---|
| 356 | $row[] = array('data' => drupal_render($form['total_financiamiento']), ); |
---|
| 357 | $rows[] = $row; |
---|
[a4d4ed9] | 358 | $output .= '<fieldset class="fuentes-de-financiamiento"><legend>' . t('Fuentes de Financiamiento (BS)') . '<span title="Este campo es obligatorio." class="form-required">*</span></legend>' . theme('table', array(), $rows) . '</fieldset>'; |
---|
[303fae2] | 359 | } |
---|
[7d9e4be] | 360 | $localizacion = variable_get('proyectos_operativos_muestra_accion_esp', TRUE); |
---|
[303fae2] | 361 | if ($localizacion) { |
---|
| 362 | $output .= '<fieldset><legend>' . t('Localización Geográfica') . '</legend>'; |
---|
| 363 | $output .= drupal_render($form['field_accion_esp_localizacion']) . drupal_render($form['field_accion_esp_latitud']) . drupal_render($form['field_accion_esp_longitud']); |
---|
| 364 | $output .= '</fieldset>'; |
---|
| 365 | $output .= drupal_render($form); |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | $geo = variable_get('proyectos_operativos_muestra_proyecto_ubicacion_geografica', TRUE); |
---|
| 369 | if ($geo) { |
---|
| 370 | $output .= '<fieldset><legend>' . t('Localización Geográfica de Ejecución') . '</legend>'; |
---|
| 371 | $output .= drupal_render($form['field_accion_esp_geo']); |
---|
| 372 | $output .= '</fieldset>'; |
---|
| 373 | } |
---|
| 374 | $output .= drupal_render($form); |
---|
| 375 | } |
---|
| 376 | $header = array(); |
---|
| 377 | $cab = 6; |
---|
| 378 | $header[] = array('data' => t('Nro')); |
---|
| 379 | $header[] = array('data' => t('Nombre')); |
---|
| 380 | $header[] = array('data' => t('Fecha de inicio')); |
---|
| 381 | $header[] = array('data' => t('Fecha de Fin')); |
---|
| 382 | $header[] = array('data' => t('%')); |
---|
| 383 | $header[] = array('data' => t('Acción')); |
---|
| 384 | $rows = array(); |
---|
| 385 | $i = 1; |
---|
| 386 | if (count($form['#acciones_especificas'])) { |
---|
| 387 | $suma = 0; |
---|
| 388 | foreach ($form['#acciones_especificas'] as $accion) { |
---|
| 389 | if (isset($accion->nid)) { |
---|
| 390 | $row = array(); |
---|
| 391 | $row[] = array('data' => $i,); |
---|
| 392 | $row[] = array('data' => $accion->titulo_asignado,); |
---|
| 393 | //Se cambia el formato de la fecha |
---|
| 394 | $fecha = explode(' ', $accion->field_accion_esp_fechai[0]['value']); |
---|
| 395 | $formato = explode('-', $fecha[0]); |
---|
| 396 | $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],); |
---|
| 397 | //Se cambia el formato de la fecha |
---|
| 398 | $fecha = explode(' ', $accion->field_accion_esp_fechaf[0]['value']); |
---|
| 399 | $formato = explode('-', $fecha[0]); |
---|
| 400 | $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],); |
---|
| 401 | $suma += $accion->field_accion_esp_ponderacion[0]['value']; |
---|
| 402 | $row[] = array('data' => $accion->field_accion_esp_ponderacion[0]['value'],); |
---|
| 403 | $links = array(); |
---|
| 404 | $links[] = l(t('Modificar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/edit'); |
---|
| 405 | $links[] = l(t('Eliminar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/remove'); |
---|
| 406 | $row[] = array('data' => theme('item_list', $links),); |
---|
| 407 | $rows[] = $row; |
---|
| 408 | $i++; |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | if (count($rows)) { |
---|
| 413 | $output .= theme('table', $header, $rows); |
---|
| 414 | } |
---|
| 415 | //no mostrar el formulario si ya se alcanzo lo asignado |
---|
| 416 | if ($form['#proyecto_completed']) { |
---|
| 417 | $output .= drupal_render($form); |
---|
| 418 | } |
---|
| 419 | return $output; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | /** |
---|
| 423 | * Agrega el valor total de la accion especifica al campo field_accion_total_financia |
---|
| 424 | */ |
---|
[90ee623] | 425 | function proyectos_operativos_mcti_accion_especifica_crear_form_submit(&$form, &$form_state) { |
---|
[303fae2] | 426 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
| 427 | $node_type = content_types('accion_especifica'); |
---|
[90ee623] | 428 | module_load_include('inc', 'node', 'node.pages'); |
---|
| 429 | $node_load = $form['#node']; |
---|
[303fae2] | 430 | if ($op != t('Cancelar')) { |
---|
[983abba] | 431 | //obtener la fecha de inicio y fin |
---|
| 432 | $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']); |
---|
[ef2ed7ba] | 433 | $mes_inicio = 0; |
---|
[983abba] | 434 | $year_inicio = 0; |
---|
| 435 | if (count($mes)) { |
---|
| 436 | $mes_inicio = $mes[1] - 1; |
---|
| 437 | $year_inicio = $mes[0]; |
---|
| 438 | } |
---|
| 439 | //obtener la fecha de inicio y fin |
---|
| 440 | $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']); |
---|
| 441 | $mes_final = 0; |
---|
| 442 | $year_final = 0; |
---|
| 443 | if (count($mes)) { |
---|
| 444 | $mes_final = $mes[1] - 1; |
---|
| 445 | $year_final = $mes[0]; |
---|
| 446 | } |
---|
| 447 | if ($form['#year_current']['year_current'] > $year_final) { |
---|
[dccd21a] | 448 | $mes_final = 11; |
---|
[983abba] | 449 | } |
---|
| 450 | if ($form['#year_current']['year_current'] < $year_inicio) { |
---|
| 451 | $mes_inicio = 0; |
---|
| 452 | } |
---|
[c25d016] | 453 | $suma = 0; |
---|
| 454 | if (isset($form_state['values']['field_accion_esp_programacion'])) { |
---|
| 455 | foreach($form_state['values']['field_accion_esp_programacion'] as $id => $programacion) { |
---|
| 456 | for ($i = 0; $i < 12; $i++) { |
---|
| 457 | $valor = $i ? 'value_' . $i : 'value'; |
---|
| 458 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
| 459 | $suma += $form_state['values']['field_accion_esp_programacion'][$id][$valor]; |
---|
| 460 | } |
---|
| 461 | else { |
---|
| 462 | $form_state['values']['field_accion_esp_programacion'][$id][$valor] = 0; |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | } |
---|
| 466 | } |
---|
[90ee623] | 467 | |
---|
| 468 | if (!$node_load->nid) { |
---|
| 469 | $result = db_query("SELECT SUM(ae.field_accion_esp_monto_finan_value) AS financiar, SUM(ae.field_accion_esp_total_fuent_value) AS fuentes FROM content_type_accion_especifica AS ae INNER JOIN node AS nodeae ON nodeae.nid = ae.nid AND ae.vid = nodeae.vid INNER JOIN content_field_proyecto_accion_esp AS aep ON aep.field_proyecto_accion_esp_nid = ae.nid INNER JOIN node AS nodep ON nodep.nid = aep.nid AND nodep.vid = aep.vid WHERE nodep.nid = %d", $form['#proyecto']->nid); |
---|
| 470 | } |
---|
| 471 | else { |
---|
| 472 | $result = db_query("SELECT SUM(ae.field_accion_esp_monto_finan_value) AS financiar, SUM(ae.field_accion_esp_total_fuent_value) AS fuentes FROM content_type_accion_especifica AS ae INNER JOIN node AS nodeae ON nodeae.nid = ae.nid AND ae.vid = nodeae.vid INNER JOIN content_field_proyecto_accion_esp AS aep ON aep.field_proyecto_accion_esp_nid = ae.nid INNER JOIN node AS nodep ON nodep.nid = aep.nid AND nodep.vid = aep.vid WHERE nodep.nid = %d AND nodeae.nid != %d", $form['#proyecto']->nid, $node_load->nid); |
---|
| 473 | |
---|
| 474 | } |
---|
| 475 | $montos_acciones = db_fetch_array($result); |
---|
| 476 | |
---|
| 477 | //monto totales |
---|
| 478 | $form['#montos_afinan'] = $montos_acciones['financiar']; |
---|
| 479 | $form['#montos_financiamiento'] = $montos_acciones['fuentes']; |
---|
| 480 | $form['#montos'] = $form['#montos_afinan'] + $form['#montos_financiamiento']; |
---|
| 481 | |
---|
[c25d016] | 482 | $sumaT = $form['#montos'] + $suma; |
---|
[7d9e4be] | 483 | $form['#proyecto']->field_proyecto_monto_anual[0]['value'] = $sumaT; |
---|
| 484 | if (!$form['#esplurianual']) { |
---|
| 485 | $form['#proyecto']->field_proyecto_total[0]['value'] = $sumaT; |
---|
| 486 | } |
---|
[303fae2] | 487 | } |
---|
[90ee623] | 488 | return $form; |
---|
[303fae2] | 489 | } |
---|