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 | * Implementation of hook_node_info() |
---|
31 | */ |
---|
32 | function accion_especifica_node_info() { |
---|
33 | return array( |
---|
34 | 'accion_especifica' => array( |
---|
35 | 'name' => t('Acciones Especificas'), |
---|
36 | 'description' => '', |
---|
37 | 'has_title' => TRUE, |
---|
38 | 'title_label' => 'Nombre de la acción especifica', |
---|
39 | 'has_body' => FALSE, |
---|
40 | 'body_label' => 'Cuerpo', |
---|
41 | 'module' => 'accion_especifica', |
---|
42 | ), |
---|
43 | ); |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * hook_form_alter() |
---|
48 | */ |
---|
49 | function accion_especifica_form_alter(&$form, $form_state, $form_id) { |
---|
50 | if ($form_id == 'proyectos_operativos_admin_settings') { |
---|
51 | $node_type = content_types('accion_especifica'); |
---|
52 | $fields = $node_type['fields']; |
---|
53 | $campos = array(); |
---|
54 | foreach($fields as $id => $field) { |
---|
55 | if ($field['module'] == 'number') { |
---|
56 | $campos[$id] = $field['widget']['label']; |
---|
57 | } |
---|
58 | } |
---|
59 | $form['accion_especifica'] = array( |
---|
60 | '#type' => 'fieldset', |
---|
61 | '#title' => t('Accion EspecÃfica'), |
---|
62 | '#collapsible' => TRUE, |
---|
63 | '#collapsed' => FALSE, |
---|
64 | '#weight' => 0, |
---|
65 | ); |
---|
66 | $form['accion_especifica']['accion_especifica_allow_ponderation'] = array( |
---|
67 | '#title' => t('Permitir Acciones Especificas con igual ponderación'), |
---|
68 | '#type' => 'checkbox', |
---|
69 | '#default_value' => variable_get('accion_especifica_allow_ponderation', 0), |
---|
70 | ); |
---|
71 | $form['accion_especifica']['accion_especifica_100_ponderation'] = array( |
---|
72 | '#title' => t('No permitir Acciones Especificas con ponderación mayor o igual a 100'), |
---|
73 | '#type' => 'checkbox', |
---|
74 | '#default_value' => variable_get('accion_especifica_100_ponderation', 0), |
---|
75 | ); |
---|
76 | $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4); |
---|
77 | $numbers = array(); |
---|
78 | for($i = 1; $i < 21; $i++) { |
---|
79 | $numbers[$i] = $i; |
---|
80 | |
---|
81 | } |
---|
82 | $form['accion_especifica']['financiamiento'] = array( |
---|
83 | '#type' => 'fieldset', |
---|
84 | '#title' => t('Financiamiento'), |
---|
85 | '#collapsible' => TRUE, |
---|
86 | '#collapsed' => FALSE, |
---|
87 | ); |
---|
88 | $form['accion_especifica']['financiamiento']['accion_especifica_number_fields'] = array( |
---|
89 | '#title' => t('Cantidad de Campos'), |
---|
90 | '#type' => 'select', |
---|
91 | '#default_value' => $accion_especifica_number_fields, |
---|
92 | '#options' => $numbers, |
---|
93 | ); |
---|
94 | |
---|
95 | if ($accion_especifica_number_fields) { |
---|
96 | for($i = 0; $i < $accion_especifica_number_fields; $i++) { |
---|
97 | $form['accion_especifica']['financiamiento']['financiamiento_' . $i] = array( |
---|
98 | '#type' => 'fieldset', |
---|
99 | '#title' => t('field %number', array('%number' => $i + 1)), |
---|
100 | '#collapsible' => TRUE, |
---|
101 | '#collapsed' => FALSE, |
---|
102 | ); |
---|
103 | $form['accion_especifica']['financiamiento']['financiamiento_' . $i]['accion_especifica_financiamiento_label_' . $i] = array( |
---|
104 | '#type' => 'textfield', |
---|
105 | '#title' => t('Titulo del financiamiento'), |
---|
106 | //'#required' => TRUE, |
---|
107 | '#weight' => -9, |
---|
108 | '#default_value' => variable_get('accion_especifica_financiamiento_label_' . $i, ''), |
---|
109 | ); |
---|
110 | $form['accion_especifica']['financiamiento']['financiamiento_' . $i]['accion_especifica_financiamiento_options_' . $i] = array( |
---|
111 | '#type' => 'checkboxes', |
---|
112 | '#options' => $campos, |
---|
113 | '#default_value' => variable_get('accion_especifica_financiamiento_options_' . $i, array()), |
---|
114 | '#title' => t('Campos a recolectar'), |
---|
115 | '#multiple' => TRUE, |
---|
116 | ); |
---|
117 | //print_r(variable_get('accion_especifica_financiamiento_options_' . $i, array())); |
---|
118 | |
---|
119 | } |
---|
120 | } |
---|
121 | //print "</pre>"; |
---|
122 | /* |
---|
123 | print "<pre>"; |
---|
124 | print_r($campos); |
---|
125 | print "</pre>"; |
---|
126 | */ |
---|
127 | } |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | /* |
---|
135 | * Implementation of hook_form() |
---|
136 | */ |
---|
137 | function accion_especifica_form(&$node, $form_state) { |
---|
138 | return node_content_form($node, $form_state); |
---|
139 | } |
---|
140 | |
---|
141 | /* |
---|
142 | * Implementation of hook_access() |
---|
143 | */ |
---|
144 | function accion_especifica_access($op, $node, $account) { |
---|
145 | if ($op == 'view') { |
---|
146 | return user_access('admin planificador'); |
---|
147 | } |
---|
148 | if ($op == 'create') { |
---|
149 | return user_access('admin planificador'); |
---|
150 | } |
---|
151 | if ($op == 'update') { |
---|
152 | return user_access('admin planificador'); |
---|
153 | } |
---|
154 | if ($op == 'delete') { |
---|
155 | return user_access('admin planificador'); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * Implementation of hook_theme(). |
---|
161 | */ |
---|
162 | function accion_especifica_theme() { |
---|
163 | return array( |
---|
164 | 'proyectos_operativos_accion_especifica_crear_form' => array( |
---|
165 | 'arguments' => array('form' => NULL), |
---|
166 | ), |
---|
167 | ); |
---|
168 | } |
---|
169 | |
---|
170 | /** |
---|
171 | * Implementation of proyectos_operativos_accion_especifica_crear_form(). |
---|
172 | * Crear formulario de accion especifica |
---|
173 | */ |
---|
174 | function proyectos_operativos_accion_especifica_crear_form(&$form_state, $proyecto = 0, $ae = 0) { |
---|
175 | if (!$ae) { |
---|
176 | drupal_set_title('Nueva Acción Especifica'); |
---|
177 | $ae_leido = new stdClass(); |
---|
178 | $ae_leido->type = 'accion_especifica'; |
---|
179 | $nid = 0; |
---|
180 | } |
---|
181 | else { |
---|
182 | $ae_leido = $ae; |
---|
183 | $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']; |
---|
184 | $nid = $ae->nid; |
---|
185 | drupal_set_title(t('Acción Especifica: @titulo', array('@titulo' => $ae_leido->field_accion_titulo[0]['value']))); |
---|
186 | } |
---|
187 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
188 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
189 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos.js'); |
---|
190 | drupal_add_js($proyectos_operativos_path . '/js/accion_especifica.js'); |
---|
191 | $format_number = array( |
---|
192 | 'decimals' => variable_get('proyectos_operativos_number_decimals', 0), |
---|
193 | 'dec_point' => variable_get('proyectos_operativos_number_dec_point', ','), |
---|
194 | 'thousands_sep' => variable_get('proyectos_operativos_number_thousands_sep', '.'), |
---|
195 | ); |
---|
196 | $form = array(); |
---|
197 | $form['#format_number'] = array('format_number' => $format_number); |
---|
198 | drupal_add_js($form['#format_number'], 'setting'); |
---|
199 | $form['#node'] = $ae_leido; |
---|
200 | $form['#proyecto'] = $proyecto; |
---|
201 | $fields_form = array(); |
---|
202 | $ejecucion = 0; |
---|
203 | $acciones_especificas = array(); |
---|
204 | $montos = 0; |
---|
205 | $porcentajes = array(); |
---|
206 | foreach($proyecto->field_proyecto_accion_esp as $accion) { |
---|
207 | if ($accion['nid'] && $nid != $accion['nid']) { |
---|
208 | $accion_load = node_load($accion['nid']); |
---|
209 | if ($accion_load && $accion_load->type == 'accion_especifica') { |
---|
210 | if ($accion_load->field_accion_esp_programacion[0]['tid']) { |
---|
211 | foreach($accion_load->field_accion_esp_programacion as $programacion) { |
---|
212 | foreach($programacion as $id_value => $mesp){ |
---|
213 | if ($id_value != 'tid') { |
---|
214 | $montos +=$mesp; |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|
218 | } |
---|
219 | $acciones_especificas[$accion_load->nid] = $accion_load; |
---|
220 | $porcentajes[$accion_load->field_accion_esp_ponderacion[0]['value']] = 1; |
---|
221 | $ejecucion += $accion_load->field_accion_esp_ponderacion[0]['value']; |
---|
222 | } |
---|
223 | } |
---|
224 | elseif($nid == $accion['nid']) { |
---|
225 | $acciones_especificas[$ae->nid] = $ae; |
---|
226 | } |
---|
227 | } |
---|
228 | $monto_restante = $form['#proyecto']->field_proyecto_monto_anual[0]['value'] - $montos; |
---|
229 | $et = 100 - $ejecucion; |
---|
230 | $form['#mensaje_mostrar'] = t('Quedan @asignar % de ponderación a asignar y @montos BS por asignar 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']))); |
---|
231 | $form['#monto_restante'] = $monto_restante; |
---|
232 | $form['#ejecucion'] = $ejecucion; |
---|
233 | $form['#porcentajes'] = $porcentajes; |
---|
234 | $form['#montos'] = $montos; |
---|
235 | $form['#acciones_especificas'] = $acciones_especificas; |
---|
236 | $node_type = content_types('accion_especifica'); |
---|
237 | $fields = $node_type['fields']; |
---|
238 | $field_form = array(); |
---|
239 | $arreglo = array( |
---|
240 | 'field_accion_titulo' => 'field_accion_titulo', |
---|
241 | 'field_accion_esp_fechai' => 'field_accion_esp_fechai', |
---|
242 | 'field_accion_esp_fechaf' => 'field_accion_esp_fechaf', |
---|
243 | 'field_accion_esp_ejecutor' => 'field_accion_esp_ejecutor', |
---|
244 | 'field_accion_esp_bien' => 'field_accion_esp_bien', |
---|
245 | ); |
---|
246 | if (is_array($fields) && count($fields)) { |
---|
247 | foreach($fields as $field_id => $field) { |
---|
248 | if (array_key_exists($field_id, $arreglo)) { |
---|
249 | $field_form[] = $field_id; |
---|
250 | $fields_form[] = $field_id; |
---|
251 | } |
---|
252 | elseif (variable_get('proyectos_operativos_ac_d_' . $field_id, FALSE)) { |
---|
253 | $field_form[] = $field_id; |
---|
254 | $fields_form[] = $field_id; |
---|
255 | } |
---|
256 | } |
---|
257 | } |
---|
258 | /*caMBIAR*/ |
---|
259 | /* |
---|
260 | $form['title'] = array( |
---|
261 | '#type' => 'textfield', |
---|
262 | '#title' => t('Nombre de la Acción'), |
---|
263 | '#required' => TRUE, |
---|
264 | '#default_value' => $form['#node']->title, |
---|
265 | '#maxlength' => 255, |
---|
266 | '#weight' => -5, |
---|
267 | ); |
---|
268 | */ |
---|
269 | if (is_array($field_form) && count($field_form)) { |
---|
270 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
271 | foreach ($field_form as $field_id) { |
---|
272 | $field = content_fields($field_id, 'accion_especifica'); |
---|
273 | $form['#field_info'][$field_id] = $field; |
---|
274 | $form += (array) content_field_form($form, $form_state, $field); |
---|
275 | } |
---|
276 | } |
---|
277 | $field_form = array(); |
---|
278 | $arreglo = array( |
---|
279 | 'field_accion_esp_unidadm' => 'field_accion_esp_unidadm', |
---|
280 | 'field_accion_esp_ponderacion' => 'field_accion_esp_ponderacion', |
---|
281 | 'field_accion_esp_metaf' => 'field_accion_esp_metaf', |
---|
282 | ); |
---|
283 | if (is_array($fields) && count($fields)) { |
---|
284 | foreach($fields as $field_id => $field) { |
---|
285 | if (array_key_exists($field_id, $arreglo)) { |
---|
286 | $field_form[] = $field_id; |
---|
287 | $fields_form[] = $field_id; |
---|
288 | } |
---|
289 | elseif (variable_get('proyectos_operativos_ac_di_' . $field_id, FALSE)) { |
---|
290 | $field_form[] = $field_id; |
---|
291 | $fields_form[] = $field_id; |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | if (is_array($field_form) && count($field_form)) { |
---|
296 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
297 | foreach ($field_form as $field_id) { |
---|
298 | $field = content_fields($field_id, 'accion_especifica'); |
---|
299 | $form['#field_info'][$field_id] = $field; |
---|
300 | $form += (array) content_field_form($form, $form_state, $field); |
---|
301 | } |
---|
302 | } |
---|
303 | $field_form = array(); |
---|
304 | $arreglo = array( |
---|
305 | 'field_accion_esp_programacion' => 'field_accion_esp_programacion', |
---|
306 | ); |
---|
307 | if (is_array($fields) && count($fields)) { |
---|
308 | foreach($fields as $field_id => $field) { |
---|
309 | if (array_key_exists($field_id, $arreglo)) { |
---|
310 | $field_form[] = $field_id; |
---|
311 | $fields_form[] = $field_id; |
---|
312 | } |
---|
313 | elseif (variable_get('proyectos_operativos_ac_p_' . $field_id, FALSE)) { |
---|
314 | $field_form[] = $field_id; |
---|
315 | $fields_form[] = $field_id; |
---|
316 | } |
---|
317 | } |
---|
318 | } |
---|
319 | if (is_array($field_form) && count($field_form)) { |
---|
320 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
321 | foreach ($field_form as $field_id) { |
---|
322 | $field = content_fields($field_id, 'accion_especifica'); |
---|
323 | $form['#field_info'][$field_id] = $field; |
---|
324 | $form += (array) content_field_form($form, $form_state, $field); |
---|
325 | } |
---|
326 | } |
---|
327 | //financiamiento |
---|
328 | $arreglo_financiamiento = array(); |
---|
329 | $accion_especifica_number_fields = variable_get('accion_especifica_number_fields', 4); |
---|
330 | if ($accion_especifica_number_fields > 0) { |
---|
331 | for($i = 0; $i < $accion_especifica_number_fields; $i++) { |
---|
332 | $arreglo_financiamiento['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_label_' . $i, '') ? variable_get('accion_especifica_financiamiento_label_' . $i, '') : ''; |
---|
333 | $arreglo_financiamiento_fields['financiamiento_' . $i] = variable_get('accion_especifica_financiamiento_options_' . $i, array()); |
---|
334 | } |
---|
335 | } |
---|
336 | /* |
---|
337 | $arreglo_financiamiento = array( |
---|
338 | 'ordinarios' => t('Recursos Ordinarios'), |
---|
339 | 'propios' => t('Recursos Propios'), |
---|
340 | 'transferencias' => t('Transferencias'), |
---|
341 | 'otros' => t('Otros'), |
---|
342 | ); |
---|
343 | $arreglo_financiamiento_fields = array(); |
---|
344 | $arreglo_financiamiento_fields['ordinarios'] = array( |
---|
345 | 'field_accion_esp_transferencias' => 'field_accion_esp_transferencias', |
---|
346 | 'field_accion_esp_creditosa' => 'field_accion_esp_creditosa', |
---|
347 | 'field_accion_esp_mcti' => 'field_accion_esp_mcti', |
---|
348 | ); |
---|
349 | $arreglo_financiamiento_fields['propios'] = array( |
---|
350 | 'field_accion_esp_venta_act' => 'field_accion_esp_venta_act', |
---|
351 | 'field_accion_esp_activos' => 'field_accion_esp_activos', |
---|
352 | 'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja', |
---|
353 | 'field_accion_esp_ventapro' => 'field_accion_esp_ventapro', |
---|
354 | ); |
---|
355 | $arreglo_financiamiento_fields['transferencias'] = array( |
---|
356 | 'field_accion_esp_donaciones' => 'field_accion_esp_donaciones', |
---|
357 | ); |
---|
358 | $arreglo_financiamiento_fields['otros'] = array( |
---|
359 | 'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion', |
---|
360 | 'field_accion_esp_misionc' => 'field_accion_esp_misionc', |
---|
361 | 'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona', |
---|
362 | 'field_accion_esp_fonacit' => 'field_accion_esp_fonacit', |
---|
363 | 'field_accion_esp_fonden' => 'field_accion_esp_fonden', |
---|
364 | 'field_accion_esp_locti' => 'field_accion_esp_locti', |
---|
365 | 'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi', |
---|
366 | 'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie', |
---|
367 | 'field_accion_esp_infocentro' => 'field_accion_esp_infocentro', |
---|
368 | 'field_accion_esp_fidetel' => 'field_accion_esp_fidetel', |
---|
369 | ); |
---|
370 | */ |
---|
371 | $total_financiamiento = 0; |
---|
372 | $fields_financiamiento = array(); |
---|
373 | |
---|
374 | foreach($arreglo_financiamiento as $id_items => $titulo) { |
---|
375 | if (is_array($arreglo_financiamiento_fields[$id_items]) && count($arreglo_financiamiento_fields[$id_items])) { |
---|
376 | $form[$id_items] = array( |
---|
377 | '#type' => 'fieldset', |
---|
378 | '#title' => $titulo, |
---|
379 | ); |
---|
380 | $field_form = array(); |
---|
381 | /* |
---|
382 | $arreglo = array( |
---|
383 | 'field_accion_esp_transferencias' => 'field_accion_esp_transferencias', |
---|
384 | 'field_accion_esp_creditosa' => 'field_accion_esp_creditosa', |
---|
385 | 'field_accion_esp_mcti' => 'field_accion_esp_mcti', |
---|
386 | ); |
---|
387 | */ |
---|
388 | if (is_array($fields) && count($fields)) { |
---|
389 | foreach($fields as $field_id => $field) { |
---|
390 | if (array_key_exists($field_id, $arreglo_financiamiento_fields[$id_items]) && $arreglo_financiamiento_fields[$id_items][$field_id]) { |
---|
391 | $field_form[] = $field_id; |
---|
392 | $fields_form[] = $field_id; |
---|
393 | $fields_financiamiento[] = $field_id; |
---|
394 | } |
---|
395 | } |
---|
396 | } |
---|
397 | $total_local = 0; |
---|
398 | if (is_array($field_form) && count($field_form)) { |
---|
399 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
400 | foreach ($field_form as $field_id) { |
---|
401 | if (isset($form['#node']->{$field_id}[0]['value'])) { |
---|
402 | $total_local += $form['#node']->{$field_id}[0]['value']; |
---|
403 | } |
---|
404 | $field = content_fields($field_id, 'accion_especifica'); |
---|
405 | $form['#field_info'][$field_id] = $field; |
---|
406 | $form[$id_items] += (array) content_field_form($form, $form_state, $field); |
---|
407 | } |
---|
408 | } |
---|
409 | $form['#campo_' . $id_items] = $field_form; |
---|
410 | $form['total_' . $id_items] = array( |
---|
411 | '#type' => 'textfield', |
---|
412 | '#title' => t('SUBTOTAL'), |
---|
413 | '#default_value' => $total_local, |
---|
414 | '#size' => 25, |
---|
415 | '#attributes' => array('class' => 'totales-financieros subtotales'), |
---|
416 | ); |
---|
417 | $total_financiamiento += $total_local; |
---|
418 | } |
---|
419 | } |
---|
420 | /* |
---|
421 | |
---|
422 | |
---|
423 | |
---|
424 | |
---|
425 | |
---|
426 | |
---|
427 | |
---|
428 | |
---|
429 | |
---|
430 | |
---|
431 | $form['ordinarios'] = array( |
---|
432 | '#type' => 'fieldset', |
---|
433 | '#title' => t('Recursos Ordinarios'), |
---|
434 | ); |
---|
435 | $fields_financiamiento = array(); |
---|
436 | $field_form = array(); |
---|
437 | $arreglo = array( |
---|
438 | 'field_accion_esp_transferencias' => 'field_accion_esp_transferencias', |
---|
439 | 'field_accion_esp_creditosa' => 'field_accion_esp_creditosa', |
---|
440 | 'field_accion_esp_mcti' => 'field_accion_esp_mcti', |
---|
441 | ); |
---|
442 | if (is_array($fields) && count($fields)) { |
---|
443 | foreach($fields as $field_id => $field) { |
---|
444 | if (array_key_exists($field_id, $arreglo)) { |
---|
445 | $field_form[] = $field_id; |
---|
446 | $fields_form[] = $field_id; |
---|
447 | $fields_financiamiento[] = $field_id; |
---|
448 | } |
---|
449 | elseif (variable_get('proyectos_operativos_ac_fo_' . $field_id, FALSE)) { |
---|
450 | $field_form[] = $field_id; |
---|
451 | $fields_form[] = $field_id; |
---|
452 | $fields_financiamiento[] = $field_id; |
---|
453 | } |
---|
454 | } |
---|
455 | } |
---|
456 | $total_ordinarios = 0; |
---|
457 | if (is_array($field_form) && count($field_form)) { |
---|
458 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
459 | foreach ($field_form as $field_id) { |
---|
460 | if (isset($form['#node']->{$field_id}[0]['value'])) { |
---|
461 | $total_ordinarios += $form['#node']->{$field_id}[0]['value']; |
---|
462 | } |
---|
463 | $field = content_fields($field_id, 'accion_especifica'); |
---|
464 | $form['#field_info'][$field_id] = $field; |
---|
465 | $form['ordinarios'] += (array) content_field_form($form, $form_state, $field); |
---|
466 | } |
---|
467 | } |
---|
468 | $form['#campo_ordinarios'] = $field_form; |
---|
469 | $form['total_ordinarios'] = array( |
---|
470 | '#type' => 'textfield', |
---|
471 | '#title' => t('SUBTOTAL'), |
---|
472 | '#default_value' => $total_ordinarios, |
---|
473 | '#size' => 25, |
---|
474 | '#attributes' => array('class' => 'totales-financieros subtotales'), |
---|
475 | ); |
---|
476 | |
---|
477 | |
---|
478 | |
---|
479 | |
---|
480 | |
---|
481 | $form['propios'] = array( |
---|
482 | '#type' => 'fieldset', |
---|
483 | '#title' => t('Recursos Propios'), |
---|
484 | ); |
---|
485 | $field_form = array(); |
---|
486 | $arreglo = array( |
---|
487 | 'field_accion_esp_venta_act' => 'field_accion_esp_venta_act', |
---|
488 | 'field_accion_esp_activos' => 'field_accion_esp_activos', |
---|
489 | 'field_accion_esp_flujocaja' => 'field_accion_esp_flujocaja', |
---|
490 | 'field_accion_esp_ventapro' => 'field_accion_esp_ventapro', |
---|
491 | ); |
---|
492 | if (is_array($fields) && count($fields)) { |
---|
493 | foreach($fields as $field_id => $field) { |
---|
494 | if (array_key_exists($field_id, $arreglo)) { |
---|
495 | $field_form[] = $field_id; |
---|
496 | $fields_form[] = $field_id; |
---|
497 | $fields_financiamiento[] = $field_id; |
---|
498 | } |
---|
499 | elseif (variable_get('proyectos_operativos_ac_fp_' . $field_id, FALSE)) { |
---|
500 | $field_form[] = $field_id; |
---|
501 | $fields_form[] = $field_id; |
---|
502 | $fields_financiamiento[] = $field_id; |
---|
503 | } |
---|
504 | } |
---|
505 | } |
---|
506 | $total_propios = 0; |
---|
507 | if (is_array($field_form) && count($field_form)) { |
---|
508 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
509 | foreach ($field_form as $field_id) { |
---|
510 | if (isset($form['#node']->{$field_id}[0]['value'])) { |
---|
511 | $total_propios += $form['#node']->{$field_id}[0]['value']; |
---|
512 | } |
---|
513 | $field = content_fields($field_id, 'accion_especifica'); |
---|
514 | $form['#field_info'][$field_id] = $field; |
---|
515 | $form['propios'] += (array) content_field_form($form, $form_state, $field); |
---|
516 | } |
---|
517 | } |
---|
518 | $form['#campo_propios'] = $field_form; |
---|
519 | $form['total_propios'] = array( |
---|
520 | '#type' => 'textfield', |
---|
521 | '#title' => t('SUBTOTAL'), |
---|
522 | '#default_value' => $total_propios, |
---|
523 | '#size' => 25, |
---|
524 | '#attributes' => array('class' => 'totales-financieros subtotales'), |
---|
525 | ); |
---|
526 | $form['transferencias'] = array( |
---|
527 | '#type' => 'fieldset', |
---|
528 | '#title' => t('Transferencias'), |
---|
529 | ); |
---|
530 | $field_form = array(); |
---|
531 | $arreglo = array( |
---|
532 | 'field_accion_esp_donaciones' => 'field_accion_esp_donaciones', |
---|
533 | ); |
---|
534 | if (is_array($fields) && count($fields)) { |
---|
535 | foreach($fields as $field_id => $field) { |
---|
536 | if (array_key_exists($field_id, $arreglo)) { |
---|
537 | $field_form[] = $field_id; |
---|
538 | $fields_form[] = $field_id; |
---|
539 | $fields_financiamiento[] = $field_id; |
---|
540 | } |
---|
541 | elseif (variable_get('proyectos_operativos_ac_fd_' . $field_id, FALSE)) { |
---|
542 | $field_form[] = $field_id; |
---|
543 | $fields_form[] = $field_id; |
---|
544 | $fields_financiamiento[] = $field_id; |
---|
545 | } |
---|
546 | } |
---|
547 | } |
---|
548 | $total_transferencias = 0; |
---|
549 | if (is_array($field_form) && count($field_form)) { |
---|
550 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
551 | foreach ($field_form as $field_id) { |
---|
552 | if (isset($form['#node']->{$field_id}[0]['value'])) { |
---|
553 | $total_transferencias += $form['#node']->{$field_id}[0]['value']; |
---|
554 | } |
---|
555 | $field = content_fields($field_id, 'accion_especifica'); |
---|
556 | $form['#field_info'][$field_id] = $field; |
---|
557 | $form['transferencias'] += (array) content_field_form($form, $form_state, $field); |
---|
558 | } |
---|
559 | } |
---|
560 | $form['#campo_transferencias'] = $field_form; |
---|
561 | $form['total_transferencias'] = array( |
---|
562 | '#type' => 'textfield', |
---|
563 | '#title' => t('SUBTOTAL'), |
---|
564 | '#default_value' => $total_transferencias, |
---|
565 | '#size' => 25, |
---|
566 | '#attributes' => array('class' => 'totales-financieros subtotales'), |
---|
567 | ); |
---|
568 | $form['otros'] = array( |
---|
569 | '#type' => 'fieldset', |
---|
570 | '#title' => t('Otros'), |
---|
571 | ); |
---|
572 | $field_form = array(); |
---|
573 | $arreglo = array( |
---|
574 | 'field_accion_esp_gobernacion' => 'field_accion_esp_gobernacion', |
---|
575 | 'field_accion_esp_misionc' => 'field_accion_esp_misionc', |
---|
576 | 'field_accion_esp_bid_fona' => 'field_accion_esp_bid_fona', |
---|
577 | 'field_accion_esp_fonacit' => 'field_accion_esp_fonacit', |
---|
578 | 'field_accion_esp_fonden' => 'field_accion_esp_fonden', |
---|
579 | 'field_accion_esp_locti' => 'field_accion_esp_locti', |
---|
580 | 'field_accion_esp_fondoidi' => 'field_accion_esp_fondoidi', |
---|
581 | 'field_accion_esp_capitalrie' => 'field_accion_esp_capitalrie', |
---|
582 | 'field_accion_esp_infocentro' => 'field_accion_esp_infocentro', |
---|
583 | 'field_accion_esp_fidetel' => 'field_accion_esp_fidetel', |
---|
584 | ); |
---|
585 | if (is_array($fields) && count($fields)) { |
---|
586 | foreach($fields as $field_id => $field) { |
---|
587 | if (array_key_exists($field_id, $arreglo)) { |
---|
588 | $field_form[] = $field_id; |
---|
589 | $fields_form[] = $field_id; |
---|
590 | $fields_financiamiento[] = $field_id; |
---|
591 | } |
---|
592 | elseif (variable_get('proyectos_operativos_ac_fo_' . $field_id, FALSE)) { |
---|
593 | $field_form[] = $field_id; |
---|
594 | $fields_form[] = $field_id; |
---|
595 | $fields_financiamiento[] = $field_id; |
---|
596 | } |
---|
597 | } |
---|
598 | } |
---|
599 | $total_otros = 0; |
---|
600 | $clase = 'total_otros'; |
---|
601 | if (is_array($field_form) && count($field_form)) { |
---|
602 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
603 | foreach ($field_form as $field_id) { |
---|
604 | if (isset($form['#node']->{$field_id}[0]['value'])) { |
---|
605 | $total_otros += $form['#node']->{$field_id}[0]['value']; |
---|
606 | } |
---|
607 | $field = content_fields($field_id, 'accion_especifica'); |
---|
608 | $form['#field_info'][$field_id] = $field; |
---|
609 | $form['otros'] += (array) content_field_form($form, $form_state, $field); |
---|
610 | } |
---|
611 | } |
---|
612 | $form['#campo_otros'] = $field_form; |
---|
613 | $form['total_otros'] = array( |
---|
614 | '#type' => 'textfield', |
---|
615 | '#title' => t('SUBTOTAL'), |
---|
616 | '#default_value' => $total_otros, |
---|
617 | '#size' => 25, |
---|
618 | '#attributes' => array('class' => 'totales-financieros subtotales'), |
---|
619 | ); |
---|
620 | */ |
---|
621 | //$total_financiamiento = $total_otros + $total_transferencias + $total_propios + $total_ordinarios; |
---|
622 | $form['total_financiamiento'] = array( |
---|
623 | '#type' => 'textfield', |
---|
624 | '#default_value' => $total_financiamiento, |
---|
625 | '#size' => 25, |
---|
626 | '#attributes' => array('class' => 'totales-financieros'), |
---|
627 | ); |
---|
628 | $field_form = array(); |
---|
629 | $arreglo = array( |
---|
630 | 'field_accion_esp_localizacion' => 'field_accion_esp_localizacion', |
---|
631 | 'field_accion_esp_latitud' => 'field_accion_esp_latitud', |
---|
632 | 'field_accion_esp_longitud' => 'field_accion_esp_longitud', |
---|
633 | ); |
---|
634 | if (is_array($fields) && count($fields)) { |
---|
635 | foreach($fields as $field_id => $field) { |
---|
636 | if (array_key_exists($field_id, $arreglo)) { |
---|
637 | $field_form[] = $field_id; |
---|
638 | $fields_form[] = $field_id; |
---|
639 | } |
---|
640 | elseif (variable_get('proyectos_operativos_ac_fp_' . $field_id, FALSE)) { |
---|
641 | $field_form[] = $field_id; |
---|
642 | $fields_form[] = $field_id; |
---|
643 | } |
---|
644 | } |
---|
645 | } |
---|
646 | if (is_array($field_form) && count($field_form)) { |
---|
647 | module_load_include('inc', 'content', 'includes/content.node_form'); |
---|
648 | foreach ($field_form as $field_id) { |
---|
649 | $field = content_fields($field_id, 'accion_especifica'); |
---|
650 | $form['#field_info'][$field_id] = $field; |
---|
651 | $form += (array) content_field_form($form, $form_state, $field); |
---|
652 | } |
---|
653 | } |
---|
654 | $form['#arreglo_financiamiento'] = $arreglo_financiamiento; |
---|
655 | $form['#arreglo_financiamiento_fields'] = $arreglo_financiamiento_fields; |
---|
656 | |
---|
657 | $form['#fields_financiamiento'] = $fields_financiamiento; |
---|
658 | $form['#proyectos_operativos_fields'] = $fields_form; |
---|
659 | $form['buttons'] = array( |
---|
660 | '#prefix' => '<div class="container-inline">', |
---|
661 | '#suffix' => '</div>', |
---|
662 | ); |
---|
663 | $form['buttons']['registrar'] = array( |
---|
664 | '#type' => 'submit', |
---|
665 | '#default_value' => t('Aceptar'), |
---|
666 | '#weight' => 100, |
---|
667 | ); |
---|
668 | $form['buttons']['cancelar'] = array( |
---|
669 | '#type' => 'submit', |
---|
670 | '#default_value' => t('Cancelar'), |
---|
671 | '#attributes' => array('onClick' => 'window.location="' . base_path() .$_GET['q'] . '"; return false;'), |
---|
672 | '#weight' => 101, |
---|
673 | ); |
---|
674 | $form['#proyecto_completed'] = FALSE; |
---|
675 | $form['#after_build'] = array('proyectos_operativos_accion_especifica_crear_form_after_build'); |
---|
676 | if (!isset($form['#node']->nid) && $form['#ejecucion'] >= 100 && $form['#monto_restante'] == 0){ |
---|
677 | //add aditional variables |
---|
678 | $aux_form = array(); |
---|
679 | $aux_form['#node'] = $form['#node']; |
---|
680 | $aux_form['#proyecto'] = $form['#proyecto']; |
---|
681 | $aux_form['#mensaje_mostrar'] = $form['#mensaje_mostrar']; |
---|
682 | $aux_form['#ejecucion'] = $form['#ejecucion']; |
---|
683 | $aux_form['#porcentajes'] = $form['#porcentajes']; |
---|
684 | $aux_form['#montos'] = $form['#montos']; |
---|
685 | $aux_form['#acciones_especificas'] = $form['#acciones_especificas']; |
---|
686 | |
---|
687 | $aux_form['#campo_ordinarios'] = $form['#campo_ordinarios']; |
---|
688 | $aux_form['#campo_propios'] = $form['#campo_propios']; |
---|
689 | $aux_form['#campo_transferencias'] = $form['#campo_transferencias']; |
---|
690 | $aux_form['#campo_otros'] = $form['#campo_otros']; |
---|
691 | |
---|
692 | $aux_form['#fields_financiamiento'] = $form['#fields_financiamiento']; |
---|
693 | |
---|
694 | $form = $aux_form; |
---|
695 | $form['buttons'] = array( |
---|
696 | '#prefix' => '<div class="container-inline">', |
---|
697 | '#suffix' => '</div>', |
---|
698 | ); |
---|
699 | $form['buttons']['siguiente'] = array( |
---|
700 | '#type' => 'submit', |
---|
701 | '#default_value' => t('Terminar'), |
---|
702 | '#weight' => 100, |
---|
703 | ); |
---|
704 | $form['buttons']['cancelar'] = array( |
---|
705 | '#type' => 'submit', |
---|
706 | '#default_value' => t('Cancelar'), |
---|
707 | '#attributes' => array('onClick' => 'window.location="' . base_path() .$_GET['q'] . '"; return false;'), |
---|
708 | '#weight' => 101, |
---|
709 | ); |
---|
710 | $form['#proyecto_completed'] = TRUE; |
---|
711 | } |
---|
712 | $form['#submit'] = array('proyectos_operativos_accion_especifica_crear_form_submit'); |
---|
713 | return $form; |
---|
714 | } |
---|
715 | |
---|
716 | /* |
---|
717 | * proyectos_operativos_accion_especifica_crear_form_after_build |
---|
718 | * Funcion para agregar funciones javascript al formulario |
---|
719 | */ |
---|
720 | function proyectos_operativos_accion_especifica_crear_form_after_build($form, &$form_state) { |
---|
721 | if (is_array($form['#arreglo_financiamiento']) && count($form['#arreglo_financiamiento'])) { |
---|
722 | foreach ($form['#arreglo_financiamiento'] as $id => $macro) { |
---|
723 | $nuid = str_replace('_', '-', $id); |
---|
724 | if (is_array($form['#campo_' . $id]) && count($form['#campo_' . $id])) { |
---|
725 | foreach ($form['#campo_' . $id] as $field_id) { |
---|
726 | $form[$id][$field_id][0]['value']['#attributes']['class'] .= ' total-' . $nuid; |
---|
727 | if (!isset($form[$id][$field_id]['value']['#attributes']['onchange'])) { |
---|
728 | $form[$id][$field_id][0]['value']['#attributes']['onchange'] = "sumarff('" . $nuid . "');sumarff1('subtotales');"; |
---|
729 | } |
---|
730 | else { |
---|
731 | $form[$id][$field_id][0]['value']['#attributes']['onchange'] .= ";sumarff('" . $nuid . "');sumarff1('subtotales');"; |
---|
732 | } |
---|
733 | } |
---|
734 | } |
---|
735 | } |
---|
736 | } |
---|
737 | return $form; |
---|
738 | } |
---|
739 | |
---|
740 | /* |
---|
741 | * proyectos_operativos_accion_especifica_crear_form_validate |
---|
742 | * Validar accion especifica |
---|
743 | */ |
---|
744 | function proyectos_operativos_accion_especifica_crear_form_validate($form, &$form_state) { |
---|
745 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
746 | if ($op == t('Cancelar') || $op == t('Terminar')) { |
---|
747 | return; |
---|
748 | } |
---|
749 | $proyectos_operativos_path = drupal_get_path('module', 'proyectos_operativos'); |
---|
750 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos_extra.js'); |
---|
751 | drupal_add_js($proyectos_operativos_path . '/js/proyectos_operativos.js'); |
---|
752 | drupal_add_js($proyectos_operativos_path . '/js/accion_especifica.js'); |
---|
753 | drupal_add_js($form['#format_number'], 'setting'); |
---|
754 | //validamos que el porc sea mayor que cero |
---|
755 | if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) { |
---|
756 | form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser menor que 100')); |
---|
757 | } |
---|
758 | |
---|
759 | //validamos que el porc sea mayor que cero |
---|
760 | if (!$form_state['values']['field_accion_esp_ponderacion'][0]['value'] && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] <= 0) { |
---|
761 | form_set_error('field_accion_esp_ponderacion', t('La ponderaciones de la Acción especifica debe ser mayor que cero')); |
---|
762 | } |
---|
763 | //validamos que la ponderacion no sea mayor a 100 |
---|
764 | $suma_porc = $form['#ejecucion'] + $form_state['values']['field_accion_esp_ponderacion'][0]['value']; |
---|
765 | if ($suma_porc > 100) { |
---|
766 | 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%')); |
---|
767 | } |
---|
768 | // validamos que la cantidad de acciones permitidas cumpla con la minima permitida |
---|
769 | if (variable_get('accion_especifica_100_ponderation', 0) && $form_state['values']['field_accion_esp_ponderacion'][0]['value'] >= 100) { |
---|
770 | form_set_error('field_accion_esp_ponderacion', t('La ponderación de la Acción especifica debe ser menor o igual a 100%')); |
---|
771 | } |
---|
772 | //validamos que la ponderacion no se encuentre repetida |
---|
773 | if (!variable_get('accion_especifica_allow_ponderation', 0) && isset($form['#porcentajes'][$form_state['values']['field_accion_esp_ponderacion'][0]['value']])) { |
---|
774 | form_set_error('field_accion_esp_ponderacion', t('Ya existe una acción especifica con esta ponderación')); |
---|
775 | } |
---|
776 | //validamos que las fechas esten dentro de la del proyecto |
---|
777 | if ($form_state['values']['field_accion_esp_fechai'][0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) { |
---|
778 | 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')); |
---|
779 | } |
---|
780 | if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechai'][0]['value']) { |
---|
781 | 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']))); |
---|
782 | } |
---|
783 | if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechai'][0]['value']) { |
---|
784 | 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']))); |
---|
785 | } |
---|
786 | if ($form['#proyecto']->field_proyecto_fecha_i[0]['value'] > $form_state['values']['field_accion_esp_fechaf'][0]['value']) { |
---|
787 | 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']))); |
---|
788 | } |
---|
789 | if ($form['#proyecto']->field_proyecto_fecha_f[0]['value'] < $form_state['values']['field_accion_esp_fechaf'][0]['value']) { |
---|
790 | 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']))); |
---|
791 | } |
---|
792 | //obtener la fecha de inicio y fin |
---|
793 | $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']); |
---|
794 | $mes_inicio = 0; |
---|
795 | if (count($mes)) { |
---|
796 | $mes_inicio = $mes[1] - 1; |
---|
797 | } |
---|
798 | //obtener la fecha de inicio y fin |
---|
799 | $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']); |
---|
800 | $mes_final = 0; |
---|
801 | if (count($mes)) { |
---|
802 | $mes_final = $mes[1] - 1; |
---|
803 | } |
---|
804 | if (isset($form_state['values']['field_accion_esp_metaf'])) { |
---|
805 | $suma = 0; |
---|
806 | for ($i = 0; $i < 12; $i++) { |
---|
807 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
808 | $valor = $i ? 'value_' . $i : 'value'; |
---|
809 | $suma += $form_state['values']['field_accion_esp_metaf'][0][$valor]; |
---|
810 | } |
---|
811 | } |
---|
812 | if (!$suma) { |
---|
813 | 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')); |
---|
814 | } |
---|
815 | } |
---|
816 | //validamos la accion especifica |
---|
817 | if (isset($form_state['values']['field_accion_esp_programacion']) && count($form_state['values']['field_accion_esp_programacion'])) { |
---|
818 | $sumap = 0; |
---|
819 | foreach($form_state['values']['field_accion_esp_programacion'] as $id_programacion => $programacion) { |
---|
820 | if (is_numeric($id_programacion)) { |
---|
821 | for ($i = 0; $i < 12; $i++) { |
---|
822 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
823 | $valor = $i ? 'value_' . $i : 'value'; |
---|
824 | $sumap += (float) $programacion[$valor]; |
---|
825 | } |
---|
826 | } |
---|
827 | } |
---|
828 | } |
---|
829 | if (!$sumap) { |
---|
830 | form_set_error('field_accion_esp_programacion', t('La Programación Financiera de la Acción especifica debe tener al menos un valor')); |
---|
831 | } |
---|
832 | } |
---|
833 | $sumaf = 0; |
---|
834 | //validamos el financiamiento |
---|
835 | $first_field = FALSE; |
---|
836 | if (count($form['#fields_financiamiento'])) { |
---|
837 | foreach($form['#fields_financiamiento'] as $field_id) { |
---|
838 | $start = (float) $form_state['values'][$field_id][0]['value']; |
---|
839 | $start = number_format($start, $form['#format_number']['format_number']['decimals'], '.', ''); |
---|
840 | $value = preg_replace('@[^-0-9]@', '', $start); |
---|
841 | if ($start && $start != $value) { |
---|
842 | form_set_error($field_id, t('Solo números enteros son permitidos en la fuente de financiamiento.')); |
---|
843 | } |
---|
844 | if ($value < 0) { |
---|
845 | form_set_error($field_id, t('Solo números positivos son permitidos en la fuente de financiamiento.')); |
---|
846 | } |
---|
847 | if (!$first_field) { |
---|
848 | $first_field = $field_id; |
---|
849 | } |
---|
850 | if (isset($form_state['values'][$field_id][0]['value'])) { |
---|
851 | $sumaf += $form_state['values'][$field_id][0]['value']; |
---|
852 | } |
---|
853 | } |
---|
854 | } |
---|
855 | if ($first_field && $sumaf != $sumap) { |
---|
856 | 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'])))); |
---|
857 | } |
---|
858 | //validamos que la suma de la programacion financiera sea + las otras acciones sean inferiores o iguales a la suma total del proyecto |
---|
859 | $sumaT = $form['#montos'] +$sumap; |
---|
860 | if ($sumaT > $form['#proyecto']->field_proyecto_monto_anual[0]['value']) { |
---|
861 | form_set_error('field_accion_esp_programacion', t('La suma de los montos de las acciones especificas (@monto) debe ser menor o igual al monto anual del proyecto (@fuente)', 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'])))); |
---|
862 | } |
---|
863 | if ($suma_porc == 100 && $sumaT < $form['#proyecto']->field_proyecto_monto_anual[0]['value']) { |
---|
864 | 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'])))); |
---|
865 | } |
---|
866 | elseif($suma_porc < 100 && $sumaT == $form['#proyecto']->field_proyecto_monto_anual[0]['value']) { |
---|
867 | 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'])))); |
---|
868 | } |
---|
869 | } |
---|
870 | |
---|
871 | /* |
---|
872 | * proyectos_operativos_accion_especifica_crear_form_submit |
---|
873 | * Guardar accion especifica |
---|
874 | */ |
---|
875 | function proyectos_operativos_accion_especifica_crear_form_submit($form, &$form_state) { |
---|
876 | $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; |
---|
877 | if ($op == t('Cancelar')) { |
---|
878 | drupal_set_message(t('Se cancelo el ingreso de la AE.')); |
---|
879 | $form_state['redirect'] = 'proyectosopedit/' . $form['#proyecto']->nid; |
---|
880 | return; |
---|
881 | } |
---|
882 | if ($op == t('Terminar')) { |
---|
883 | $form_state['redirect'] = 'proyectosopedit/' . $form['#proyecto']->nid . '/finacieros'; |
---|
884 | return; |
---|
885 | } |
---|
886 | if (module_exists('hs_content_taxonomy')) { |
---|
887 | foreach ($form['#field_info'] as $field_name => $field_info) { |
---|
888 | if ($field_info['widget']['type'] == 'content_taxonomy_hs') { |
---|
889 | // Change format of values to the one Content Taxonomy expects |
---|
890 | if (is_array($form_state['values'][$field_name]['tids'])) { |
---|
891 | $values = array(); |
---|
892 | foreach($form_state['values'][$field_name]['tids'] as $tid) { |
---|
893 | $values[] = array('value' => $tid); |
---|
894 | array_unshift($form_state['values'][$field_name], array('value' => $tid)); |
---|
895 | } |
---|
896 | $form_state['values'][$field_name]['tids'] = $values; |
---|
897 | } |
---|
898 | else { |
---|
899 | $values[] = array('value' => $form_state['values'][$field_name]['tids']); |
---|
900 | array_unshift($form_state['values'][$field_name],array('value' => $form_state['values'][$field_name]['tids'])); |
---|
901 | $form_state['values'][$field_name]['tids'] = $values; |
---|
902 | } |
---|
903 | } |
---|
904 | } |
---|
905 | } |
---|
906 | global $user; |
---|
907 | $field_form = $form['#proyectos_operativos_fields']; |
---|
908 | module_load_include('inc', 'node', 'node.pages'); |
---|
909 | $node_load = $form['#node']; |
---|
910 | //obtener la fecha de inicio y fin |
---|
911 | $mes = explode('-', $form_state['values']['field_accion_esp_fechai'][0]['value']); |
---|
912 | $mes_inicio = 0; |
---|
913 | if (count($mes)) { |
---|
914 | $mes_inicio = $mes[1] - 1; |
---|
915 | } |
---|
916 | //obtener la fecha de inicio y fin |
---|
917 | $mes = explode('-', $form_state['values']['field_accion_esp_fechaf'][0]['value']); |
---|
918 | $mes_final = 0; |
---|
919 | if (count($mes)) { |
---|
920 | $mes_final = $mes[1] - 1; |
---|
921 | } |
---|
922 | if (isset($form_state['values']['field_accion_esp_metaf'])) { |
---|
923 | $suma = 0; |
---|
924 | for ($i = 0; $i < 12; $i++) { |
---|
925 | $valor = $i ? 'value_' . $i : 'value'; |
---|
926 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
927 | $suma += $form_state['values']['field_accion_esp_metaf'][0][$valor]; |
---|
928 | } |
---|
929 | else { |
---|
930 | $form_state['values']['field_accion_esp_metaf'][0][$valor] = 0; |
---|
931 | } |
---|
932 | } |
---|
933 | } |
---|
934 | if (isset($form_state['values']['field_accion_esp_programacion'])) { |
---|
935 | $suma = 0; |
---|
936 | foreach($form_state['values']['field_accion_esp_programacion'] as $id => $programacion) { |
---|
937 | for ($i = 0; $i < 12; $i++) { |
---|
938 | $valor = $i ? 'value_' . $i : 'value'; |
---|
939 | if ($mes_inicio <= $i && $mes_final >= $i) { |
---|
940 | $suma += $form_state['values']['field_accion_esp_metaf'][$id][$valor]; |
---|
941 | } |
---|
942 | else { |
---|
943 | $form_state['values']['field_accion_esp_programacion'][$id][$valor] = 0; |
---|
944 | } |
---|
945 | } |
---|
946 | } |
---|
947 | } |
---|
948 | $form_values = $form_state['values']; |
---|
949 | //cambiar |
---|
950 | $node_load->title = t('Acción EspecÃfica del proyecto @nombreproyecto', array('@nombreproyecto' => $form['#proyecto']->title)); |
---|
951 | if (is_array($field_form) && count($field_form)) { |
---|
952 | foreach ($field_form as $field_id) { |
---|
953 | if (isset($form_values[$field_id]) && is_array($form_values[$field_id])) { |
---|
954 | foreach($form_values[$field_id] as $id => $value) { |
---|
955 | if (is_numeric($id) && isset($form_values[$field_id][$id]['_error_element'])) { |
---|
956 | unset($form_values[$field_id][$id]['_error_element']); |
---|
957 | } |
---|
958 | } |
---|
959 | $node_load->{$field_id} = $form_values[$field_id]; |
---|
960 | } |
---|
961 | } |
---|
962 | } |
---|
963 | $nid = FALSE; |
---|
964 | if ($node_load->nid) { |
---|
965 | $nid = TRUE; |
---|
966 | $texto = t('Modificada la Acción especifica del proyecto'); |
---|
967 | $node_load->log = $texto; |
---|
968 | drupal_set_message($texto); |
---|
969 | } |
---|
970 | else { |
---|
971 | //se agrega el enlace al proyecto |
---|
972 | $node_load->uid = $user->uid; |
---|
973 | $node_load->field_accion_esp_proyecto = array(); |
---|
974 | $node_load->field_accion_esp_proyecto[] = array('nid' => $form['#proyecto']->nid); |
---|
975 | $node_load->field_accion_esp_ente = array(); |
---|
976 | $node_load->field_accion_esp_ente[] = array('nid' => $form['#proyecto']->field_proyecto_ente[0]['nid']); |
---|
977 | $texto = t('Agregada la Acción especifica del proyecto'); |
---|
978 | $node_load->log = $texto; |
---|
979 | drupal_set_message($texto); |
---|
980 | } |
---|
981 | $node_load->revision = 1; |
---|
982 | node_save($node_load); |
---|
983 | if (!$nid) { |
---|
984 | $proyecto = $form['#proyecto']; |
---|
985 | if (!$proyecto->field_proyecto_accion_esp[0]['nid']) { |
---|
986 | $proyecto->field_proyecto_accion_esp = array(); |
---|
987 | } |
---|
988 | $proyecto->field_proyecto_accion_esp[] = array('nid' => $node_load->nid); |
---|
989 | $proyecto->revision = 1; |
---|
990 | $proyecto->log = t('Agregada Acción especifica del proyecto'); |
---|
991 | node_save($proyecto); |
---|
992 | } |
---|
993 | if (!$_REQUEST['destination']) { |
---|
994 | // add redirect |
---|
995 | $form_state['redirect'] = 'proyectosopedit/' . $form['#proyecto']->nid . '/ae'; |
---|
996 | } |
---|
997 | } |
---|
998 | |
---|
999 | /** |
---|
1000 | * @ingroup themeable |
---|
1001 | * @see proyectos_operativos_accion_especifica_crear_form |
---|
1002 | */ |
---|
1003 | function theme_proyectos_operativos_accion_especifica_crear_form($form) { |
---|
1004 | $output = ''; |
---|
1005 | if (!$form['#proyecto_completed']) { |
---|
1006 | $output .= '<div id="mensaje-mostrar" class="mensaje mensaje-mostrar" style="color:red;font-weight: bold;">' . $form['#mensaje_mostrar'] . '</div>'; |
---|
1007 | $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']) . drupal_render($form['field_accion_esp_ejecutor']) . drupal_render($form['field_accion_esp_bien']) . '</fieldset>'; |
---|
1008 | $output .= '<fieldset><legend>' . t('Distribución de la Meta Fisica de la acción Especifica') . '</legend>' . drupal_render($form['field_accion_esp_unidadm']) . drupal_render($form['field_accion_esp_ponderacion']) . drupal_render($form['field_accion_esp_metaf']) . '</fieldset>'; |
---|
1009 | $output .= drupal_render($form['distribucion']); |
---|
1010 | $output .= '<fieldset><legend>' . t('Programación Financiera de la Acción') . '</legend>' . drupal_render($form['field_accion_esp_programacion']); |
---|
1011 | $ftypes = array( |
---|
1012 | 'tid' => t('Account'), |
---|
1013 | 'value' => t('Ene'), |
---|
1014 | 'value_1' => t('Feb'), |
---|
1015 | 'value_2' => t('Mar'), |
---|
1016 | 'value_3' => t('Abr'), |
---|
1017 | 'value_4' => t('May'), |
---|
1018 | 'value_5' => t('Jun'), |
---|
1019 | 'value_6' => t('Jul'), |
---|
1020 | 'value_7' => t('Aug'), |
---|
1021 | 'value_8' => t('Sep'), |
---|
1022 | 'value_9' => t('Oct'), |
---|
1023 | 'value_10' => t('Nov'), |
---|
1024 | 'value_11' => t('Dic'), |
---|
1025 | ); |
---|
1026 | $output .= '<div style="width:2250px">'; |
---|
1027 | $i = -1; |
---|
1028 | foreach ($ftypes as $ftype => $label) { |
---|
1029 | if($ftype != 'tid') { |
---|
1030 | $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>'; |
---|
1031 | } |
---|
1032 | else { |
---|
1033 | $output .= '<div style = "width:180px;float:left;margin-left:5px;text-align:right"><b>' . t('TOTAL') . '</b></div>'; |
---|
1034 | } |
---|
1035 | $i++; |
---|
1036 | } |
---|
1037 | $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>'; |
---|
1038 | $output .= '</div></fieldset>'; |
---|
1039 | $rows = array(); |
---|
1040 | $row = array(); |
---|
1041 | $row1 = array(); |
---|
1042 | $cantidad_campos = count($form['#arreglo_financiamiento']); |
---|
1043 | if (is_array($form['#arreglo_financiamiento']) && count($form['#arreglo_financiamiento'])) { |
---|
1044 | foreach ($form['#arreglo_financiamiento'] as $id => $macro) { |
---|
1045 | $row[] = array('data' => drupal_render($form[$id]), ); |
---|
1046 | $row1[] = array('data' => drupal_render($form['total_' . $id]), ); |
---|
1047 | } |
---|
1048 | $rows[] = $row; |
---|
1049 | $rows[] = $row1; |
---|
1050 | $row = array(); |
---|
1051 | $row[] = array('data' => '<b>' . t('TOTAL') . ':</b>', 'colspan' => $cantidad_campos - 1, 'align' => 'right'); |
---|
1052 | $row[] = array('data' => drupal_render($form['total_financiamiento']), ); |
---|
1053 | $rows[] = $row; |
---|
1054 | $output .= '<fieldset><legend>' . t('Fuentes de Financiamiento') . '</legend>' . theme('table', array(), $rows) . '</fieldset>'; |
---|
1055 | } |
---|
1056 | $output .= '<fieldset><legend>' . t('Localización Geográfica') . '</legend>' . drupal_render($form['field_accion_esp_localizacion']) . drupal_render($form['field_accion_esp_latitud']) . drupal_render($form['field_accion_esp_longitud']) . '</fieldset>'; |
---|
1057 | $output .= drupal_render($form); |
---|
1058 | } |
---|
1059 | $header = array(); |
---|
1060 | $cab = 6; |
---|
1061 | $header[] = array('data' => t('Nro')); |
---|
1062 | $header[] = array('data' => t('Nombre')); |
---|
1063 | $header[] = array('data' => t('Fecha de inicio')); |
---|
1064 | $header[] = array('data' => t('Fecha de Fin')); |
---|
1065 | $header[] = array('data' => t('%')); |
---|
1066 | $header[] = array('data' => t('Acción')); |
---|
1067 | $rows = array(); |
---|
1068 | $i = 1; |
---|
1069 | if (count($form['#acciones_especificas'])) { |
---|
1070 | $suma = 0; |
---|
1071 | foreach($form['#acciones_especificas'] as $accion) { |
---|
1072 | if (isset($accion->nid)) { |
---|
1073 | $row = array(); |
---|
1074 | $row[] = array('data' => $i,); |
---|
1075 | $row[] = array('data' => $accion->titulo_asignado,); |
---|
1076 | //Se cambia el formato de la fecha |
---|
1077 | $fecha = explode(' ', $accion->field_accion_esp_fechai[0]['value']); |
---|
1078 | $formato = explode('-', $fecha[0]); |
---|
1079 | $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],); |
---|
1080 | //Se cambia el formato de la fecha |
---|
1081 | $fecha = explode(' ', $accion->field_accion_esp_fechaf[0]['value']); |
---|
1082 | $formato = explode('-', $fecha[0]); |
---|
1083 | $row[] = array('data' => $formato[2] . '/' . $formato[1] . '/' . $formato[0],); |
---|
1084 | $suma += $accion->field_accion_esp_ponderacion[0]['value']; |
---|
1085 | $row[] = array('data' => $accion->field_accion_esp_ponderacion[0]['value'],); |
---|
1086 | $links = array(); |
---|
1087 | $links[] = l(t('Modificar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/edit'); |
---|
1088 | $links[] = l(t('Eliminar'), 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/' . $accion->nid . '/remove'); |
---|
1089 | $row[] = array('data' => theme('item_list', $links),); |
---|
1090 | $rows[] = $row; |
---|
1091 | $i++; |
---|
1092 | } |
---|
1093 | } |
---|
1094 | } |
---|
1095 | if (count($rows)) { |
---|
1096 | $output .= theme('table', $header, $rows); |
---|
1097 | } |
---|
1098 | //no mostrar el formulario si ya se alcanzo lo asignado |
---|
1099 | if ($form['#proyecto_completed']) { |
---|
1100 | $output .= drupal_render($form); |
---|
1101 | } |
---|
1102 | $output .= l('Agregar nueva Acción Especifica', 'proyectosopedit/' . $form['#proyecto']->nid . '/ae/'); |
---|
1103 | |
---|
1104 | return $output; |
---|
1105 | } |
---|