1 | /** |
---|
2 | * Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
3 | * @file acciones_centralizadas.js |
---|
4 | * Drupal part Module to Sistema Integral de Planificación y Presupuesto (SIPP) |
---|
5 | * Copyright 2013 Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana (CENDITEL) |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or modify |
---|
8 | * it under the terms of the GNU General Public License as published by |
---|
9 | * the Free Software Foundation; either version 2 of the License, or |
---|
10 | * (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
20 | * |
---|
21 | * @author Cenditel Merida - Msc. Juan Vizcarrondo |
---|
22 | * @date 2013-02-02 // (año-mes-dia) |
---|
23 | * @version 0.1 // (0.1) |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | /* |
---|
28 | * Implementation of sumatexto() |
---|
29 | */ |
---|
30 | function sumatexto(clase) { |
---|
31 | var sum = 0; |
---|
32 | var i = 0; |
---|
33 | var valor = 0; |
---|
34 | var valores = 0; |
---|
35 | $('.' + clase).each(function() { |
---|
36 | valor = parseFloat($(this).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
37 | if (isNaN(valor) || !isFinite(valor)) { |
---|
38 | $(this).val(0); |
---|
39 | valor = 0; |
---|
40 | } |
---|
41 | sum += valor; |
---|
42 | valores = $(this).attr('valor'); |
---|
43 | if (typeof valores !== 'undefined' && valores !== false) { |
---|
44 | valores = parseFloat(valores.replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
45 | sum += valores; |
---|
46 | } |
---|
47 | }); |
---|
48 | if (sum == 0){sum = '0';} |
---|
49 | $('.' + clase + '_total').html($.number(sum, Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
50 | } |
---|
51 | |
---|
52 | /* |
---|
53 | * Implementation of calculaporc() |
---|
54 | */ |
---|
55 | Drupal.behaviors.accionesCentralizadas = function (context) { |
---|
56 | /* |
---|
57 | * Implementacion function $.number |
---|
58 | * basada en la libreria jQuery number plug-in 2.1.3 de Sam Sehnert |
---|
59 | * Copyright 2012, Digital Fusion |
---|
60 | * liberada bajo MIT license |
---|
61 | * http://www.teamdf.com/web/jquery-number-format-redux/196/ |
---|
62 | */ |
---|
63 | $.number = function( number, decimals, dec_point, thousands_sep ){ |
---|
64 | // Set the default values here, instead so we can use them in the replace below. |
---|
65 | thousands_sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep; |
---|
66 | dec_point = (typeof dec_point === 'undefined') ? '.' : dec_point; |
---|
67 | decimals = !isFinite(+decimals) ? 0 : Math.abs(decimals); |
---|
68 | // Work out the unicode representation for the decimal place and thousand sep. |
---|
69 | var u_dec = ('\\u'+('0000'+(dec_point.charCodeAt(0).toString(16))).slice(-4)); |
---|
70 | var u_sep = ('\\u'+('0000'+(thousands_sep.charCodeAt(0).toString(16))).slice(-4)); |
---|
71 | // Fix the number, so that it's an actual number. |
---|
72 | number = (number + '') |
---|
73 | .replace('\.', dec_point) // because the number if passed in as a float (having . as decimal point per definition) we need to replace this with the passed in decimal point character |
---|
74 | .replace(new RegExp(u_sep,'g'),'') |
---|
75 | .replace(new RegExp(u_dec,'g'),'.') |
---|
76 | .replace(new RegExp('[^0-9+\-Ee.]','g'),''); |
---|
77 | var n = !isFinite(+number) ? 0 : +number, |
---|
78 | s = '', |
---|
79 | toFixedFix = function (n, decimals) { |
---|
80 | var k = Math.pow(10, decimals); |
---|
81 | return '' + Math.round(n * k) / k; |
---|
82 | }; |
---|
83 | // Fix for IE parseFloat(0.55).toFixed(0) = 0; |
---|
84 | s = (decimals ? toFixedFix(n, decimals) : '' + Math.round(n)).split('.'); |
---|
85 | if (s[0].length > 3) { |
---|
86 | s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, thousands_sep); |
---|
87 | } |
---|
88 | if ((s[1] || '').length < decimals) { |
---|
89 | s[1] = s[1] || ''; |
---|
90 | s[1] += new Array(decimals - s[1].length + 1).join('0'); |
---|
91 | } |
---|
92 | return s.join(dec_point); |
---|
93 | } |
---|
94 | $('.' + 'campo-asignado').attr('readonly', true); |
---|
95 | $(".number").each(function() { |
---|
96 | $(this).val($.number($(this).val(), Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
97 | }); |
---|
98 | $(".number1").each(function() { |
---|
99 | $(this).html($.number($(this).html(), Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
100 | }); |
---|
101 | $(".number").keyup(function(evt) { |
---|
102 | $(this).val($.number($(this).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.'), Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
103 | }); |
---|
104 | $(".numberref").each(function() { |
---|
105 | var valor = $(this).val(); |
---|
106 | valor.replace(/[+\s]/g, ''); |
---|
107 | var signo = ''; |
---|
108 | if (valor > 0) { |
---|
109 | signo = '+'; |
---|
110 | } |
---|
111 | $(this).val(signo + $.number(valor, Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
112 | var valores = $(this).attr('partida_campo'); |
---|
113 | if (typeof valores !== 'undefined' && valores !== false) { |
---|
114 | sumatexto(valores); |
---|
115 | } |
---|
116 | }); |
---|
117 | $(".numberref").keyup(function(evt) { |
---|
118 | var signo = ''; |
---|
119 | var valor = $(this).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.'); |
---|
120 | if (valor > 0) { |
---|
121 | signo = '+'; |
---|
122 | valor.replace(/[+\s]/g, ''); |
---|
123 | } |
---|
124 | if (valor != '-' || valor != '+') { |
---|
125 | if (valor == '0-') { |
---|
126 | $(this).val('-'); |
---|
127 | } |
---|
128 | else if(valor == '0+') { |
---|
129 | $(this).val('+'); |
---|
130 | } |
---|
131 | else { |
---|
132 | valor.replace(/^[0]+/g,""); |
---|
133 | $(this).val(signo + $.number(valor, Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
134 | } |
---|
135 | } |
---|
136 | }); |
---|
137 | |
---|
138 | sumatexto('field_ac_ac1_ae1_dato_field'); |
---|
139 | sumatexto('field_ac_ac1_ae2_dato_field'); |
---|
140 | sumatexto('field_ac_ac2_ae2_dato_field'); |
---|
141 | sumatexto('field_ac_ac2_ae3_dato_field'); |
---|
142 | sumatexto('field_ac_ac3_ae1_dato_field'); |
---|
143 | sumatexto('field_ac_ac4_ae1_dato_field'); |
---|
144 | |
---|
145 | for (i = 0; i < 12;i++) { |
---|
146 | sumatexto('field_ac_ac1_ae1_m' + i + '_field'); |
---|
147 | sumatexto('field_ac_ac1_ae2_m' + i + '_field'); |
---|
148 | sumatexto('field_ac_ac2_ae2_m' + i + '_field'); |
---|
149 | sumatexto('field_ac_ac2_ae3_m' + i + '_field'); |
---|
150 | sumatexto('field_ac_ac3_ae1_m' + i + '_field'); |
---|
151 | sumatexto('field_ac_ac4_ae1_m' + i + '_field'); |
---|
152 | } |
---|
153 | |
---|
154 | sumatoria_textos('field_ac_ac1_ae1'); |
---|
155 | sumatoria_textos('field_ac_ac1_ae2'); |
---|
156 | sumatoria_textos('field_ac_ac2_ae2'); |
---|
157 | sumatoria_textos('field_ac_ac2_ae3'); |
---|
158 | sumatoria_textos('field_ac_ac3_ae1'); |
---|
159 | sumatoria_textos('field_ac_ac4_ae1'); |
---|
160 | |
---|
161 | $("#node-form, #acciones-centralizadas-reformula-tab-page-form, #acciones-centralizadas-seguimiento-tab-page-form").submit(function( event ) { |
---|
162 | $(".number, .numberref").each(function() { |
---|
163 | $(this).val($(this).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
164 | }); |
---|
165 | return ; |
---|
166 | }); |
---|
167 | } |
---|
168 | |
---|
169 | /* |
---|
170 | * Implementation of sumatotales() |
---|
171 | */ |
---|
172 | function sumatotales(clase) { |
---|
173 | var sum = 0; |
---|
174 | var i = 0; |
---|
175 | var valor = 0; |
---|
176 | $('.' + clase).each(function() { |
---|
177 | valor = parseFloat($(this).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
178 | if (valor < 0 || isNaN(valor) || !isFinite(valor)) { |
---|
179 | $(this).val(0); |
---|
180 | valor = 0; |
---|
181 | } |
---|
182 | sum += valor; |
---|
183 | }); |
---|
184 | $('.' + clase + '_total').text($.number(sum, Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
185 | } |
---|
186 | |
---|
187 | /* |
---|
188 | * Implementation of calculaporc() |
---|
189 | */ |
---|
190 | function calculaporc(partida) { |
---|
191 | var asignado = parseFloat($('#edit-' + partida + '-asignado').val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
192 | var causado = parseFloat($('#edit-' + partida + '-causado').val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
193 | var porc = asignado; |
---|
194 | if (asignado > 0) { |
---|
195 | porc = (100 * causado) / asignado; |
---|
196 | $('#edit-' + partida + '-porcen').val(porc.toFixed(2) + '%'); |
---|
197 | var estilo = 'font-weight: bold;'; |
---|
198 | if (porc < 11){ |
---|
199 | $('#' + partida + '-inversion-form').html(Drupal.settings.acciones_centralizadas[1]['texto']); |
---|
200 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[1]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[1]['tcolor']; |
---|
201 | } |
---|
202 | else if (porc < 51){ |
---|
203 | $('#' + partida + '-inversion-form').html(Drupal.settings.acciones_centralizadas[2]['texto']); |
---|
204 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[2]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[2]['tcolor']; |
---|
205 | } |
---|
206 | else if (porc < 80){ |
---|
207 | $('#' + partida + '-inversion-form').html(Drupal.settings.acciones_centralizadas[3]['texto']); |
---|
208 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[3]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[3]['tcolor']; |
---|
209 | } |
---|
210 | else if (porc <= 100){ |
---|
211 | $('#' + partida + '-inversion-form').html(Drupal.settings.acciones_centralizadas[4]['texto']); |
---|
212 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[4]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[4]['tcolor']; |
---|
213 | } |
---|
214 | else{ |
---|
215 | $('#' + partida + '-inversion-form').html(Drupal.settings.acciones_centralizadas[5]['texto']); |
---|
216 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[5]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[5]['tcolor']; |
---|
217 | } |
---|
218 | $('#' + partida + '-inversion-form'). attr('style', estilo); |
---|
219 | } |
---|
220 | else { |
---|
221 | /* |
---|
222 | $('#edit-' + partida + '-porcen').val('N/A'); |
---|
223 | var estilo = $('#' + partida + '-inversion-form'). attr('style'); |
---|
224 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[0]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[0]['tcolor']; |
---|
225 | $('#' + partida + '-inversion-form'). attr('style', estilo); |
---|
226 | */ |
---|
227 | if (causado > 0) { |
---|
228 | $('#' + partida + '-inversion-form').html(Drupal.settings.acciones_centralizadas[5]['texto']); |
---|
229 | $('#edit-' + partida + '-porcen').val('N/D'); |
---|
230 | var estilo = $('#' + partida + '-inversion-form'). attr('style'); |
---|
231 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[5]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[5]['tcolor']; |
---|
232 | $('#' + partida + '-inversion-form'). attr('style', estilo); |
---|
233 | } |
---|
234 | else { |
---|
235 | $('#edit-' + partida + '-porcen').val('N/A'); |
---|
236 | var estilo = $('#' + partida + '-inversion-form'). attr('style'); |
---|
237 | estilo += ';background:' + Drupal.settings.acciones_centralizadas[0]['color'] + ';color:' + Drupal.settings.acciones_centralizadas[0]['tcolor']; |
---|
238 | $('#' + partida + '-inversion-form'). attr('style', estilo); |
---|
239 | } |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | /* |
---|
244 | * Implementation of valpositivo() |
---|
245 | */ |
---|
246 | function valpositivo(elemento){ |
---|
247 | var valor = parseFloat($('#edit-' + elemento).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
248 | if (valor <= 0) { |
---|
249 | $('#edit-' + elemento).val(0); |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | /* |
---|
254 | * Implementation of sumaref() |
---|
255 | */ |
---|
256 | function sumaref(clase) { |
---|
257 | var sum = 0; |
---|
258 | var i = 0; |
---|
259 | var valor = 0; |
---|
260 | $('.' + clase).each(function() { |
---|
261 | valor = parseFloat($(this).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
262 | if (isNaN(valor) || !isFinite(valor)) { |
---|
263 | alert('Debe introducir solo números'); |
---|
264 | $(this).val(0); |
---|
265 | valor = 0; |
---|
266 | } |
---|
267 | sum += valor; |
---|
268 | }); |
---|
269 | $('.' + clase + '_total').val($.number(sum, Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
270 | } |
---|
271 | |
---|
272 | /* |
---|
273 | * Implementation of valminimo() |
---|
274 | */ |
---|
275 | function valminimo(elemento, minimo){ |
---|
276 | var valor = parseFloat($('#edit-' + elemento).val().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
277 | if (isNaN(valor) || !isFinite(valor)) { |
---|
278 | alert('Debe introducir solo números'); |
---|
279 | $('#edit-' + elemento).val(0); |
---|
280 | return; |
---|
281 | } |
---|
282 | minimo = parseFloat(minimo); |
---|
283 | if (minimo + valor < 0) { |
---|
284 | alert('el monto para esta celda debe ser mayor a -' + minimo) |
---|
285 | $('#edit-' + elemento).val(0); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | function sumatoria_textos(clase) { |
---|
290 | var sum = 0; |
---|
291 | var i = 0; |
---|
292 | var valor = 0; |
---|
293 | var valores = 0; |
---|
294 | var entra = false; |
---|
295 | $('.' + clase + '_totalesR').each(function() { |
---|
296 | entra = true; |
---|
297 | valor = parseFloat($(this).html().replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
298 | if (isNaN(valor) || !isFinite(valor)) { |
---|
299 | $(this).val(0); |
---|
300 | valor = 0; |
---|
301 | } |
---|
302 | sum += valor; |
---|
303 | valores = $(this).attr('valor'); |
---|
304 | if (typeof valores !== 'undefined' && valores !== false) { |
---|
305 | valores = parseFloat(valores.replace(/[Drupal.settings.format_number.thousands_sep\s]/g, '').replace(/[Drupal.settings.format_number.dec_point\s]/g, '.')); |
---|
306 | sum += valores; |
---|
307 | } |
---|
308 | }); |
---|
309 | if (sum == 0){sum = '0';} |
---|
310 | if (entra == true) { |
---|
311 | $('.' + clase + '_dato_field_total').html($.number(sum, Drupal.settings.format_number.decimals, Drupal.settings.format_number.dec_point, Drupal.settings.format_number.thousands_sep)); |
---|
312 | } |
---|
313 | } |
---|