source: sipes/0.3-modules/proyectos_operativos_mcti/accion_especifica_mcti.module @ 303fae2

stableversion-3.0
Last change on this file since 303fae2 was 303fae2, checked in by José Gregorio Puentes <jpuentes@…>, 9 años ago

se agregaron los modulos

  • Propiedad mode establecida a 100755
File size: 24.6 KB
Línea 
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&#241;o-mes-dia)
25  * @version 0.1 // (0.1)
26  *
27  */
28
29
30/*
31 * Impletations of hook_form_alter()
32 */
33function 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'];
45                foreach ($form['#parameters'] as $id => $proyecto) {
46      if ($proyecto->type == 'accion_especifica') {
47        $ae = $proyecto;
48      }
49    }
50    if (!$ae) {
51                $ae_leido = new stdClass();
52        $ae_leido->type = 'accion_especifica';
53        $nid = 0;
54          }
55        else {
56        $ae_leido = $ae;
57                $ae_leido->field_accion_titulo[0]['value'] = trim($ae_leido->field_accion_titulo[0]['value']) == '' ? $ae_leido->title : $ae_leido->field_accion_titulo[0]['value'];
58        $nid = $ae->nid;
59        }
60    //nid node
61    foreach ($form['#parameters'] as $id => $proyectos) {
62      if ($proyectos->type == 'proyectos_operativos') {
63        $proyecto = $proyectos;
64      }
65    }
66    if (!$proyecto) {
67      $proyecto = new stdClass();
68      $proyecto->type = 'proyectos_operativos';
69    }
70    else {
71      $proyecto = $proyecto;
72    }
73    $geo = variable_get('proyectos_operativos_muestra_proyecto_ubicacion_geografica', TRUE);
74    if ($geo) {
75      //agregando el campo geo
76      $arreglo = array(
77        'field_accion_esp_geo' => 'field_accion_esp_geo',
78      );
79    }
80    if (is_array($fields) && count($fields)) {
81      foreach ($fields as $field_id => $field) {
82        if (array_key_exists($field_id, $arreglo)) {
83          $field_form[] = $field_id;
84          $fields_form[] = $field_id;
85        }
86        elseif (variable_get('proyectos_operativos_ac_muestra_geo_' . $field_id, FALSE)) {
87          $field_form[] = $field_id;
88          $fields_form[] = $field_id;
89        }
90      }
91    }
92                $ejecucion = 0;
93          $acciones_especificas = array();
94    $montos = 0;
95    $porcentajes = array();
96    foreach ($proyecto->field_proyecto_accion_esp as $accion) {
97      if ($accion['nid'] && $nid != $accion['nid']) {
98        $accion_load = node_load($accion['nid']);
99        if ($accion_load && $accion_load->type == 'accion_especifica') {
100          if ($accion_load->field_accion_esp_programacion[0]['tid']) {
101            foreach ($accion_load->field_accion_esp_programacion as $programacion) {
102              foreach ($programacion as $id_value => $mesp){
103                if ($id_value != 'tid') {
104                  $montos +=$mesp;
105                }
106              }
107            }
108          }
109          $acciones_especificas[$accion_load->nid] = $accion_load;
110          $porcentajes[$accion_load->field_accion_esp_ponderacion[0]['value']] = 1;
111          $ejecucion += $accion_load->field_accion_esp_ponderacion[0]['value'];
112        }
113          }
114      elseif ($nid == $accion['nid']) {
115          $acciones_especificas[$ae->nid] = $ae;
116          }
117    }
118          $monto_restante = $form['#proyecto']->field_proyecto_monto_anual[0]['value'] - $montos;
119    $et = 100 - $ejecucion;
120    if ($et != 100) {
121            $form['#mensaje_mostrar'] =  t('Se tiene @asignar % de ponderación sin asignar, con un monto de @montos BS asignados en las Acciones Específicas.', array('@asignar' => $et, '@montos' => number_format($monto_restante, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'],               $form['#format_number']['format_number']['thousands_sep'])));
122    }
123    else {
124      $form['#mensaje_mostrar'] =  t('Se tiene @asignar % de ponderación Asignada, con un monto total de @montos BS asignados en las Acciones Específicas.', array('@asignar' => $et, '@montos' => number_format($monto_restante, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'],                  $form['#format_number']['format_number']['thousands_sep'])));
125    }
126                $form['#proyectos_operativos_fields'] = array_merge($form['#proyectos_operativos_fields'] , $fields_form);
127    if (is_array($field_form) && count($field_form)) {
128      module_load_include('inc', 'content', 'includes/content.node_form');
129      foreach ($field_form as $field_id) {
130        $field = content_fields($field_id, 'accion_especifica');
131        $form['#field_info'][$field_id] = $field;
132        $form += (array) content_field_form($form, $form_state, $field);
133      }
134    }
135    foreach ($form['#validate'] as $id => $name) {
136            if ($name == 'proyectos_operativos_accion_especifica_crear_form_validate') {
137                        $form['#validate'][$id] = 'proyectos_operativos_mcti_accion_especifica_crear_form_validate';
138            }
139        }
140        $form['#submit'][] = 'proyectos_operativos_mcti_accion_especifica_crear_form_submit';
141  }
142}
143
144/*
145 * Validar accion especifica
146 */
147function proyectos_operativos_mcti_accion_especifica_crear_form_validate($form, &$form_state) {
148  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
149  if ($op == t('Cancelar') || $op == t('Terminar')) {
150    return;
151  }
152  $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos');
153  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js');
154  drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos.js');
155  drupal_add_js($proyectos_operativos_path . '/js/accion_especifica.js');
156  drupal_add_js($form['#format_number'], 'setting');
157  //validamos que el porc sea mayor que cero
158  if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) {
159    form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser menor que 100'));
160  }
161  //validamos que el porc sea mayor que cero
162  if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] <= 0) {
163    form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser mayor que cero'));
164  }
165  //validamos que la ponderacion no sea mayor a 100
166  $suma_porc = $form['#ejecucion'] + $form_state['values']['field_accion_esp_ponderacion'][0]['value'];
167  if ($suma_porc > 100) {
168    form_set_error('field_accion_esp_ponderacion', t('La suma de las ponderaciones de la Acción especifica debe ser menor o igual a 1oo%'));
169  }
170  //validamos que la ponderacion no se encuentre repetida
171  if (!variable_get('accion_especifica_allow_ponderation', 0) && isset($form['#porcentajes'][$form_state['values']['field_accion_esp_ponderacion'][0]['value']])) {
172    form_set_error('field_accion_esp_ponderacion', t('Ya existe una acción especifica con esta ponderación'));
173  }
174  //validamos que las fechas esten dentro de la del proyecto
175  if ($form_state['values']['field_accion_esp_fechai'][0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) {
176    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'));
177  }
178  if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) {
179    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'])));
180  }
181  if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechai'][0]['value']) {
182    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'])));
183  }
184  if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechaf'][0]['value']) {
185    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'])));
186  }
187  if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechaf'][0]['value']) {
188    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'])));
189  }
190  //obtener la fecha de inicio y fin
191  $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']);
192  $mes_inicio = 0;
193  if (count($mes)) {
194    $mes_inicio = $mes[1] - 1;
195  }
196  //obtener la fecha de inicio y fin
197  $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']);
198  $mes_final = 0;
199  if (count($mes)) {
200    $mes_final = $mes[1] - 1;
201  }
202  if (isset($form_state['values']['field_accion_esp_metaf'])) {
203    $suma = 0;
204    for ($i = 0; $i < 12; $i++) {
205      if ($mes_inicio <= $i && $mes_final >= $i) {
206        $valor = $i ? 'value_' . $i : 'value';
207        $suma += $form_state['values']['field_accion_esp_metaf'][0][$valor];
208      }
209    }
210    if (!$suma) {
211      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'));
212    }
213  }
214  //validamos la accion especifica
215  if (isset($form_state['values']['field_accion_esp_programacion']) && count($form_state['values']['field_accion_esp_programacion'])) {
216    $sumap = 0;
217    foreach ($form_state['values']['field_accion_esp_programacion'] as $id_programacion => $programacion) {
218      if (is_numeric($id_programacion)) {
219        for ($i = 0; $i < 12; $i++) {
220          if ($mes_inicio <= $i && $mes_final >= $i) {
221            $valor = $i ? 'value_' . $i : 'value';
222            $sumap += (float) $programacion[$valor];
223          }
224        }
225      }
226    }
227    if (!$sumap) {
228      form_set_error('field_accion_esp_programacion', t('La Programación Financiera de la Acción especifica debe tener al menos un valor'));
229    }
230  }
231  $sumaf = 0;
232  //validamos el financiamiento
233  $first_field = FALSE;
234  if (count($form['#fields_financiamiento'])) {
235    foreach ($form['#fields_financiamiento'] as $field_id) {
236      $start = (float) $form_state['values'][$field_id][0]['value'];
237      $start = number_format($start, $form['#format_number']['format_number']['decimals'], '.', '');
238      $value = preg_replace('@[^-0-9]@', '', $start);
239      if ($start && $start != $value) {
240        form_set_error($field_id, t('Solo números enteros son permitidos en la fuente de financiamiento.'));
241      }
242      if ($value < 0) {
243        form_set_error($field_id, t('Solo números positivos son permitidos en la fuente de financiamiento.'));
244      }
245      if (!$first_field) {
246        $first_field = $field_id;
247      }
248      if (isset($form_state['values'][$field_id][0]['value'])) {
249        $sumaf += $form_state['values'][$field_id][0]['value'];
250      }
251    }
252  }
253  if ($first_field && $sumaf != $sumap) {
254    form_set_error($first_field, t('Las fuentes de financiamiento (@f_financiamiento) deben ser 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']))));
255  }
256  //validamos que la suma de la programacion financiera sea + las otras acciones sean inferiores o iguales a la suma total del proyecto
257  $sumaT = $form['#montos'] +$sumap;
258  if ($suma_porc == 100 && $sumaT < $form['#proyecto']->field_proyecto_monto_anual[0]['value']) {
259    form_set_error('field_accion_esp_programacion', t('La suma de los montos de las acciones especificas (@monto) debe ser menor igual al monto anual del proyecto (@fuente) cuando las ponderaciones de las Acciones Específicas sume 100%', array('@fuente' => number_format($form['#proyecto']->field_proyecto_monto_anual[0]['value'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto' => number_format($sumaT, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));   
260  }
261  elseif ($suma_porc < 100 && $sumaT == $form['#proyecto']->field_proyecto_monto_anual[0]['value']) {
262    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% (@suma_porc % alcanzado) y el monto por asignar no es suficiente para nuevas Acciones (Monto Asignado: @monto_asignado Bs, Monto del proyecto: @monto_proyecto Bs)', array('@suma_porc' => number_format($suma_porc, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto_asignado' => number_format($sumaT, $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']), '@monto_proyecto' => number_format($form['#proyecto']->field_proyecto_monto_anual[0]['value'], $form['#format_number']['format_number']['decimals'], $form['#format_number']['format_number']['dec_point'], $form['#format_number']['format_number']['thousands_sep']))));
263  }
264}
265
266/**
267 * Implementation of hook_theme_registry_alter().
268 */
269function accion_especifica_mcti_theme_registry_alter(&$theme_registry) {
270  if ($theme_registry['proyectos_operativos_accion_especifica_crear_form']) {   
271    $theme_registry['proyectos_operativos_accion_especifica_crear_form']['function'] = 'theme_proyectos_operativos_accion_especifica_mcti_crear_form';
272  }
273}
274
275/**
276 * tema a aplicar en el formulario proyectos_operativos_accion_especifica_crear_form
277 */
278function theme_proyectos_operativos_accion_especifica_mcti_crear_form($form) {
279$output = '';
280  if (!$form['#proyecto_completed']) {
281    $output .= '<div id="mensaje-mostrar" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $form['#mensaje_mostrar'] . '</div>';
282    $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>';
283    $output .= '<fieldset><legend>' . t('Distribución de la Meta Fisica de la acción Especifica') . '</legend>';
284    $output .= drupal_render($form['field_accion_esp_unidadm']);
285    if (isset($form['field_accion_esp_meta_m']) && $form['field_accion_esp_meta_f']) {
286      $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>';
287      $form['field_accion_esp_meta_m'][0]['value']['#title'] = '';
288      $form['field_accion_esp_meta_f'][0]['value']['#title'] = '';
289      $total = $form['field_accion_esp_meta_m'][0]['#value']['value'] + $form['field_accion_esp_meta_f'][0]['#value']['value'];
290      $output .= '<td>' . drupal_render($form['field_accion_esp_meta_m']) . '</td>';
291      $output .= '<td>' . drupal_render($form['field_accion_esp_meta_f']) . '</td>';
292      $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>';
293    }
294    $output .= drupal_render($form['field_accion_esp_ponderacion']);
295    $output .= drupal_render($form['field_accion_esp_metaf']);
296    $output .= '</fieldset>';
297    $output .= drupal_render($form['distribucion']);
298    $output .= '<fieldset><legend>' . t('Programación Financiera de la Acción') . '</legend>' . drupal_render($form['field_accion_esp_programacion']);
299    $ftypes = array(
300      'tid' => t('Account'),
301      'value' => t('Ene'),
302      'value_1' => t('Feb'),
303      'value_2' => t('Mar'),
304      'value_3' => t('Abr'),
305      'value_4' => t('May'),
306      'value_5' => t('Jun'),
307      'value_6' => t('Jul'),
308      'value_7' => t('Aug'),
309      'value_8' => t('Sep'),
310      'value_9' => t('Oct'),
311      'value_10' => t('Nov'),
312      'value_11' => t('Dic'),
313    );
314    $output .= '<div style="width:2250px">';
315    $i = -1;
316    foreach ($ftypes as $ftype => $label) {
317      if($ftype != 'tid') {
318        $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>';
319      }
320      else {
321        $output .= '<div style = "width:180px;float:left;margin-left:5px;text-align:right"><b>' . t('TOTAL') . '</b></div>';
322      }
323      $i++;
324    }
325    $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>';
326    $output .= '</div></fieldset>';
327    $rows = array();
328    $row = array();
329    $row1 = array();
330    $cantidad_campos = count($form['#arreglo_financiamiento']);
331    if (is_array($form['#arreglo_financiamiento']) && count($form['#arreglo_financiamiento'])) {
332      foreach ($form['#arreglo_financiamiento'] as $id => $macro) {
333        $row[] = array('data' => drupal_render($form[$id]), );
334        $row1[] = array('data' => drupal_render($form['total_' . $id]), );
335      }
336      $rows[] = $row;
337      $rows[] = $row1;
338      $row = array();
339      $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => $cantidad_campos - 1, 'align' => 'right');
340      $row[] = array('data' => drupal_render($form['total_financiamiento']), );
341      $rows[] = $row;
342      $output .= '<fieldset><legend>' . t('Fuentes de Financiamiento') . '</legend>' . theme('table', array(), $rows) . '</fieldset>';
343    }
344    $localizacion = variable_get('proyectos_operativos_muestra_localizacion_accion', TRUE);
345    if ($localizacion) {
346      $output .= '<fieldset><legend>' . t('Localización Geográfica') . '</legend>';
347      $output .= drupal_render($form['field_accion_esp_localizacion']) . drupal_render($form['field_accion_esp_latitud']) . drupal_render($form['field_accion_esp_longitud']);
348      $output .= '</fieldset>';
349      $output .= drupal_render($form);
350    }
351 
352    $geo = variable_get('proyectos_operativos_muestra_proyecto_ubicacion_geografica', TRUE);
353    if ($geo) {
354      $output .= '<fieldset><legend>' . t('Localización Geográfica de Ejecución') . '</legend>';
355     // $output .= drupal_render($form['field_accion_esp_localizacion']) . drupal_render($form['field_accion_esp_latitud']) . drupal_render($form['field_accion_esp_longitud']);
356      $output .= drupal_render($form['field_accion_esp_geo']);
357      $output .= '</fieldset>';
358    }
359    $output .= drupal_render($form);
360  }
361  $header = array();
362  $cab = 6;
363  $header[] = array('data' => t('Nro'));
364  $header[] = array('data' => t('Nombre'));
365  $header[] = array('data' => t('Fecha de inicio'));
366  $header[] = array('data' => t('Fecha de Fin')); 
367  $header[] = array('data' => t('%'));
368  $header[] = array('data' => t('Acción'));
369  $rows = array();
370  $i = 1;
371  if (count($form['#acciones_especificas'])) {
372    $suma = 0;
373    foreach ($form['#acciones_especificas'] as $accion) {
374      if (isset($accion->nid)) {
375        $row = array();
376        $row[] = array('data' => $i,);
377        $row[] = array('data' => $accion->titulo_asignado,);
378        //Se cambia el formato de la fecha
379        $fecha = explode(' ', $accion->field_accion_esp_fechai[0]['value']);
380        $formato = explode('-', $fecha[0]);
381        $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],);
382        //Se cambia el formato de la fecha
383        $fecha = explode(' ', $accion->field_accion_esp_fechaf[0]['value']);
384        $formato = explode('-', $fecha[0]);
385        $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],);
386        $suma += $accion->field_accion_esp_ponderacion[0]['value'];
387        $row[] = array('data' => $accion->field_accion_esp_ponderacion[0]['value'],);
388        $links = array();
389        $links[] = l(t('Modificar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/edit');
390        $links[] = l(t('Eliminar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/remove');
391        $row[] = array('data' => theme('item_list', $links),);
392        $rows[] = $row;
393        $i++;
394      }
395    }
396  }
397  if (count($rows)) {
398    $output .= theme('table', $header, $rows);
399  }
400  //no mostrar el formulario si ya se alcanzo lo asignado
401  if ($form['#proyecto_completed']) {
402    $output .= drupal_render($form);
403  }
404  return $output;
405}
406
407/**
408 * Agrega el valor total de la accion especifica al campo field_accion_total_financia
409 */
410function proyectos_operativos_mcti_accion_especifica_crear_form_submit($form, &$form_state) {
411  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
412  $node_type = content_types('accion_especifica');
413  if ($op != t('Cancelar')) {
414    if (isset($form_state['values']['field_accion_esp_programacion']) && count($form_state['values']['field_accion_esp_programacion'])) {
415      $sumap = 0;
416      foreach ($form_state['values']['field_accion_esp_programacion'] as $id_programacion => $programacion) {
417                                //obtener la fecha de inicio y fin
418                        $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']);
419                        $mes_inicio = 0;
420                        if (count($mes)) {
421                        $mes_inicio = $mes[1] - 1;
422                        }
423                         //obtener la fecha de inicio y fin
424                 $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']);
425                 $mes_final = 0;
426                 if (count($mes)) {
427                 $mes_final = $mes[1] - 1;
428                 }
429       if (is_numeric($id_programacion)) {
430         for ($i = 0; $i < 12; $i++) {
431            if ($mes_inicio <= $i && $mes_final >= $i) {
432              $valor = $i ? 'value_' . $i : 'value';
433              $sumap += (float) $programacion[$valor];
434            }
435          }
436        }
437      }
438    }
439    $sumaf = 0;
440    //validamos el financiamiento
441    $first_field = FALSE;
442    if (count($form['#fields_financiamiento'])) {
443      foreach ($form['#fields_financiamiento'] as $field_id) {
444        $start = (float) $form_state['values'][$field_id][0]['value'];
445        $start = number_format($start, $form['#format_number']['format_number']['decimals'], '.', '');
446        $value = preg_replace('@[^-0-9]@', '', $start);
447        if (!$first_field) {
448          $first_field = $field_id;
449        }
450        if (isset($form_state['values'][$field_id][0]['value'])) {
451          $sumaf += $form_state['values'][$field_id][0]['value'];
452        }
453      }
454    }
455    $sumaT = $form['#montos'] + $sumap;
456    db_query("UPDATE {content_type_proyectos_operativos} SET field_proyecto_monto_anual_value = %d WHERE nid = %d", $sumaT, $form['#proyecto']->nid);
457    db_query("UPDATE {content_type_accion_especifica} SET       field_accion_total_financia_value = %d WHERE field_accion_esp_proyecto_nid = %d", $sumaT, $form['#proyecto']->nid);
458  }
459}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.