How to add values of a datatable, depending on whether the following value is different from the current one? In MVC C #

0

I have the following datatable in the view, which lists certain data:

<table id="table_listadoLineasComprobante" class="table table-striped table-bordered tableSection_2" style="margin-bottom: 0 !important;">
<thead>
    <tr style="background-color: #ff6a00; color: #fff">
        <th>Fecha</th>
        <th>Tipo</th>
        <th>numero</th>
        <th>Rut</th>
        <th>N° Doc.</th>
        <th>Centro</th>
        <th>Glosa</th>
        <th>Debe</th>
        <th>Haber</th>


    </tr>
</thead>

<tbody>
    <% 
        foreach (var item in Model.listadoLinea)
        { %>

    <tr>
        <td>
           <%:item.fecha %>

        </td>
        <td>
            <%:item.tipo %>                        
        </td>
        <td>
            <%:item.numero %>                        
        </td>
        <td>
            <%:item.rut %>                        
        </td>
        <td>
            <%:item.nrodoc %>                        
        </td>
        <td>
            <%:item.centro %>                        
        </td>
        <td>
            <%:item.glosa %>                        
        </td>
        <td>
            <%:item.debe %>                        
        </td>
        <td>
            <%:item.haber %>                        
        </td>

    </tr>
    <% } %>
 </tbody>
</table>

I would like to know, that when the value of the current date , is different from the next date, show the amount of credit and debit by date. For example:

I would like to get the totals of the debit and credit, as the image looks.

    
asked by Danilo 15.09.2016 в 01:25
source

1 answer

0

I already found a solution, it's like this:

<table id="table" class="table table-striped table-bordered" style="margin-bottom: 0 !important;">
<thead>
    <tr style="background-color: #ff6a00; color: #fff">
        <th>Fecha</th>
        <th>Tipo</th>
        <th>numero</th>
        <th>Rut</th>
        <th>N° Doc.</th>
        <th>Cent</th>
        <th>Glosa</th>
        <th>Debe</th>
        <th>Haber</th>
        <th>total</th>

    </tr>
</thead>

<tbody>
    <% Double totalMes_Debe = 0;
       Double totalMes_Haber = 0;
       for (int i = 0; i < Model.listadoLinea.Count; i++)
       { %>

    <tr>
        <td>
            <%:Model.listadoLinea[i].fecha%>

        </td>
        <td>
            <%:Model.listadoLinea[i].tipo%>

        </td>
        <td>
            <%:Model.listadoLinea[i].numero%>

        </td>
        <td>
            <%:Model.listadoLinea[i].rut%>

        </td>
        <td>
            <%:Model.listadoLinea[i].nrodoc%>

        </td>
        <td>
            <%:Model.listadoLinea[i].centro%>

        </td>
        <td>
            <%:Model.listadoLinea[i].glosa%>

        </td>
        <td>
            <%:Model.listadoLinea[i].debe%>

        </td>
        <td>
            <%:Model.listadoLinea[i].haber%>
            <%  totalMes_Debe = totalMes_Debe + Model.listadoLinea[i].debe;
                totalMes_Haber = totalMes_Haber + Model.listadoLinea[i].haber;%>                    
        </td>
        <td></td>

    </tr>
    <% if ((i + 1) < Model.listadoLinea.Count)
       {%>
    <% if (Model.listadoLinea[i].fecha != Model.listadoLinea[i + 1].fecha)
       {%>
    <tr>
        <td colspan="7">Total día
        </td>
        <td>
            <%:totalMes_Debe %>
        </td>
        <td>
            <%:totalMes_Haber %>

            <%totalMes_Debe = 0;
              totalMes_Haber = 0; %>
        </td>
        <td></td>
    </tr>
    <%}

       }
       else if ((i + 1) == Model.listadoLinea.Count)
       { %>
    <tr>
        <td colspan="7">Total día
        </td>
        <td>
            <%:totalMes_Debe %>
        </td>
        <td>
            <%:totalMes_Haber %>

            <%totalMes_Debe = 0;
              totalMes_Haber = 0; %>
        </td>
        <td></td>
    </tr>
    <%}
       } %>
 </tbody>
</table>
    
answered by 15.09.2016 / 03:02
source