Author: danydb
Date: 2011-11-01 04:57:17 +0100 (Tue, 01 Nov 2011)
New Revision: 4284

Modified:
   phpcompta/trunk/html/js/anc_script.js
Log:
433: am?\195?\169lioration Compta Analytique : montant v?\195?\169rifi?\195?\169

Modified: phpcompta/trunk/html/js/anc_script.js
===================================================================
--- phpcompta/trunk/html/js/anc_script.js       2011-11-01 00:38:37 UTC (rev 
4283)
+++ phpcompta/trunk/html/js/anc_script.js       2011-11-01 03:57:17 UTC (rev 
4284)
@@ -29,17 +29,25 @@
 function add_row(p_table,p_seq)
 {
     var mytable=g(p_table).tBodies[0];
-
+       var max=parseFloat(g('amount_t'+p_seq).value);
     if ( ! mytable )
     {
         return;
     }
     var new_value=mytable.rows.length+1;
+
+
     if ( mytable.rows.length > 5 )
     {
         alert("Maximum 5 lignes ");
         return;
     }
+       amount=compute_total_table(p_table,p_seq);
+       if ( max < amount )
+       {
+               alert('Montant incorrect : max = '+max+" calculé="+amount);
+               return;
+       }
     // For the detail view (modify_op) there is several form and then several 
time the
     // element
     var rowToCopy=mytable.rows[1];
@@ -52,8 +60,33 @@
 //     txt=txt.replace(/row_1/g,"row_"+new_value);
         cell.innerHTML=txt;
     }
+       var col=document.getElementsByName("val["+p_seq+"][]");
+       col[col.length-1].value=max-amount;
 
 }
+/**
+ *@bug cannot compute total for ANC_TABLE
+ *@todo fix this bug
+ */
+function compute_total_table(p_table,seq)
+{
+       try{
+
+       var i=0;var tot=0;
+       var col=document.getElementsByName("val["+seq+"][]");
+       for (i=0;i<col.length;i++)
+               {
+                       // here is the problem
+                       tot+=parseFloat(col[i].value);
+
+               }
+               return tot;
+       }
+       catch(e)
+       {
+               alert(e.message);
+       }
+}
 /*!
  * \brief Check the amount of the CA
  * \param p_style : error or ok, if ok show a ok box if the amount are equal


_______________________________________________
Phpcompta-dev mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/phpcompta-dev

Reply via email to