0

I need to calculate the total of an invoice. This invoice is created with a form, amount, quantity and tax fields, the sum of the fields is made with a bind in cfinput. I can not make the sum of all rows, the total. I tried some operations, but not arriving at the solution

This is an example code:

<cfform action="" method="post">
<cfloop from="1" to="3" index="i">

    Q.ta <cfinput type="text" name="quantita#i#" value="0"> 
    + 
    Importo <cfinput type="text" name="importo#i#" value="0"> 
    +
    Tax <cfinput type="text" name="iva#i#" value="0"> 
    = 
    Totale <cfinput type="text" name="totale#i#" value="0" bind="cfc:somma.getSomma({quantita#i#},{importo#i#},{iva#i#})">

    <br /><br />        

</cfloop>

CFC:

<cfcomponent>
 <cffunction name="getSomma" access="remote" returntype="string">

    <cfargument name="quantita" default="0">
    <cfargument name="importo" default="0">
    <cfargument name="iva" default="0">

    <cfset totaleSomma=#evaluate((importo*quantita)*(1+iva))#>

    <cfreturn totaleSomma>
 </cffunction>  
</cfcomponent>
Marlon
  • 19,924
  • 12
  • 70
  • 101

2 Answers2

1

I think you will need to create a Javascript function if you want to loop through ALL these form feilds and get a "grand total". My suggestion would be to abandon cfform and use jQuery to create an editable grid.

Mark A Kruger
  • 7,183
  • 20
  • 21
0

ok i found the solution, i use cfdiv for the grand total:

<cfparam name="var_tot" default="0">

<cfloop from="1" to="3" index="i">
<cfparam name="totale#i#" default="0">
<cfset var_tot = listappend(var_tot, "{totale"&#i#&"}")>
</cfloop>



<cfform action="" method="post">
<table>
<cfloop from="1" to="3" index="i">
<tr>    
    <td>Q.ta</td><td><cfinput type="text" name="quantita#i#" value="0"></td>  
    <td>Importo</td><td><cfinput type="text" name="importo#i#" value="0"> </td>
    <td>Tax</td><td><cfinput type="text" name="iva#i#" value="0"> </td>
    <td>Totale</td><td class="price"><cfinput type="text" name="totale#i#" value="0" bind="cfc:somma.getSomma({quantita#i#},{importo#i#},{iva#i#})" ></td>      
</tr>
</cfloop>
</table>
</cfform>

<cfdiv bind="url:divtot.cfm?InputText=#var_tot#" id="checktot">

divtot.cfm

<cfparam name="tot" default="0">
<cfset listval=url.InputText>

<cfloop index="i" list="#listval#" delimiters=",">
<cfset tot=tot+i>
</cfloop>


TOTALE: <cfoutput>#tot#</cfoutput>

thank you everybody