Jump to content
Fórum Script Brasil
  • 0

Calcular 2 Tabelas


hemerson321

Question

Ola bom dia a todos tenho 2 tabelas uma com valor de entrada e outra com valor de saída abaixo queria diminuir o valor da entrada com o valor da saída e totalizar tipo assim:


Entrada: 200,00 R$
Saida :50,00 R$

Totalizando: 150,00 R$

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="" border="1" >
<tr>
<td> ENTRADA</td>
</tr>
</table>
<table width="198" border="1" >
<tr>
<td width="39%"> PRODUTO</td>
<td width="12%">VALOR</td>
</tr>
<tr>
<td >1</td>
<td>100,00</td>
</tr>
<tr>
<td >2</td>
<td>100,00</td>
</tr>
</table>
<p>&nbsp;</p>
<table width="" border="1" >
<tr>
<td> SAIDA</td>
</tr>
</table>
<table width="196" border="1" >
<tr>
<td width="39%"> DESCRICAO</td>
<td width="12%">VALOR</td>
</tr>
<td >SAIDA</td>
<td>50,00</td>
</tr>
</table>
<p>&nbsp;</p>
<p>TOTAL ENTRADA =R$ 200,00</p>
<p>TOTAL SAIDA =R$ 50,00</p>
<p>TOTAL GERAL =R$ 150,00</p>
<p>&nbsp;</p>
</body>
</html>
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

O total em termo de formatação não fica exactamente como pretendes mas foi o melhor que consegui.

Fica um exemplo, utilizando jQuery:

$(document).ready(function () {
    var entrada = 0,
        saida = 0,
        total = 0;
    $.each($("td[name='entrada']"), function() {
        entrada += parseFloat($(this).text().replace(",", "."));
    });
    $.each($("td[name='saida']"), function() {
        saida += parseFloat($(this).text().replace(",", "."));
    });
    total = entrada - saida;
    $("body").append("TOTAL ENTRADA = R$ " + entrada + "<br />")
             .append("TOTAL SAIDA = R$ " + saida + "<br />")
             .append("TOTAL GERAL = R$ " + total + "<br />");
});

Para tal tens de colocar o atributo name "entrada" nos td com os valores de entrada e "saida" nos td de saída.

Edited by wootzor
Link to comment
Share on other sites

  • 0

Basta adicionar uma nova tabela para os totais:

<table border="1">
    <tr>
        <td>TOTAL ENTRADA</td>
        <td id="totalEntrada"></td>
    </tr>
    <tr>
        <td>TOTAL SAIDA</td>
        <td id="totalSaida"></td>
    </tr>
    <tr>
        <td>TOTAL GERAL</td>
        <td id="totalGeral"></td>
    </tr>
</table>

E alterar as últimas três linhas do código jQuery:

$("#totalEntrada").append("R$ " + entrada);
$("#totalSaida").append("R$ " + saida)
$("#totalGeral").append("R$ " + total);

Exemplo

Edited by wootzor
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...