noalyss Version-9
compute.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18/*!\file
19 *\brief common function for accountancy module
20 */
21function checkTotal()
22{
23 var ie4=false;
24 if ( document.all )
25 {
26 ie4=true;
27 }// Ajouter getElementById par document.all[str]
28 var total_deb=0.0;
29 var total_cred=0.0;
30
31
32 var nb_item_id=document.getElementById('nb_item');
33 if ( ! nb_item_id )
34 {
35 return;
36 }
37 var nb_item=nb_item_id.value;
38
39 for (var i=0;i <nb_item ;i++)
40 {
41 var doc_amount=document.getElementById("e_account"+i+"_amount");
42 if ( ! doc_amount )
43 {
44 return;
45 }
46 var side=document.getElementsByName("e_account"+i+"_type");
47 if ( ! side )
48 {
49 return;
50 }
51 var amount=parseFloat(doc_amount.value);
52
53 if ( isNaN(amount) == true)
54 {
55 amount=0.0;
56 }
57 for (var e=0;e<side.length;e++)
58 {
59 if ( side[e].checked == true)
60 {
61 // alert_box('checked !!! '+side[e].value);
62 deb=side[e].value;
63 }
64 }
65 if ( deb == 'c' )
66 {
67 total_cred+=amount;
68 }
69 if ( deb == 'd' )
70 {
71 total_deb+=amount;
72 }
73
74 // alert_box("amount ="+i+"="+amount+" cred/deb = "+deb+"total d/b"+total_deb+"/"+total_cred);
75 }
76
77
78
79 r_total_cred=Math.round(total_cred*100)/100;
80 r_total_deb=Math.round(total_deb*100)/100;
81 document.getElementById('totalDeb').innerHTML=r_total_deb;
82 document.getElementById('totalCred').innerHTML=r_total_cred;
83
84 if ( r_total_deb != r_total_cred )
85 {
86 document.getElementById("totalDiff").style.color="red";
87 document.getElementById("totalDiff").style.fontWeight="bold";
88 document.getElementById("totalDiff").innerHTML="Différence";
89 diff=total_deb-total_cred;
90 diff=Math.round(diff*100)/100;
91 document.getElementById("totalDiff").innerHTML=diff;
92
93 }
94 else
95 {
96 document.getElementById("totalDiff").innerHTML="0.0";
97 }
98}
99