noalyss Version-9
compute_direct.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 "Ecriture directe"
20 */
21/**
22 * Compute the sum of the debit and credit of the operation in the input screen for misceallenous operation
23 * Call CurrencyComputeMisc to update the amount in default currency for DEB (domid = default_currency_deb)
24 * and CRED ( domid = default_currency_cred),
25 * @returns {Boolean} true if ok
26 */
27function checkTotalDirect()
28{
29 var ie4=false;
30 if ( document.all )
31 {
32 ie4=true;
33 }// Ajouter getElementById par document.all[str]
34 var total_deb=0.0;
35 var total_cred=0.0;
36
37
38 var nb_item_id=document.getElementById('nb_item');
39 if ( ! nb_item_id )
40 {
41 return;
42 }
43
44 var nb_item=nb_item_id.value;
45
46 for (var i=0;i <nb_item ;i++)
47 {
48 var doc_amount=document.getElementById("amount"+i);
49 if ( ! doc_amount )
50 {
51 return;
52 }
53 var side=document.getElementsByName("ck"+i);
54 if ( ! side )
55 {
56 return;
57 }
58 var amount=parseFloat(doc_amount.value);
59
60 if ( isNaN(amount) == true)
61 {
62 amount=0.0;
63 }
64 for (var e=0;e<side.length;e++)
65 {
66 if ( side[e].checked == true)
67 {
68 // alert_box('checked !!! '+side[e].value);
69 total_deb+=amount;
70 }
71 else
72 {
73 total_cred+=amount;
74 }
75 }
76
77 // alert_box("amount ="+i+"="+amount+" cred/deb = "+deb+"total d/b"+total_deb+"/"+total_cred);
78 }
79
80
81
82 r_total_cred=Math.round(total_cred*100)/100;
83 r_total_deb=Math.round(total_deb*100)/100;
84 document.getElementById('totalDeb').innerHTML=r_total_deb;
85 document.getElementById('totalCred').innerHTML=r_total_cred;
86 // Currency , update the amount in default currency for DEB (domid = default_currency_deb)
87 // and CRED ( domid = default_currency_cred),
88 CurrencyComputeMisc('p_currency_rate','p_currency_euro');
89
90 var diff=0;
91 if ( r_total_deb != r_total_cred )
92 {
93 document.getElementById("totalDiff").style.color="red";
94 document.getElementById("totalDiff").style.fontWeight="bold";
95 document.getElementById("totalDiff").innerHTML="Différence";
96 diff=total_deb-total_cred;
97 diff=Math.round(diff*100)/100;
98 document.getElementById("totalDiff").innerHTML=diff;
99 return false;
100
101 }
102 else
103 {
104 document.getElementById("totalDiff").innerHTML="0.0";
105 return true;
106 }
107}
108function controleBalance()
109{
110 if ( checkTotalDirect() == true ) { return true;}
111 else {
112 smoke.alert(content[58]);
113 return false;
114 }
115}