I have a view that returns me data that the taxpayer paid the pension in the current year, where I return the monthly payment of the same. I need to complete the sum of the months, creating a monthly subTotal. With help I managed to work, leaving the result as the example:
JsFiddle Example
But I need the sum to restart at the end of the year. This logic I can not elaborate.
I need the final result to do something like:
Example Expected result
My controller looks like this:
public ActionResult Index()
{
//realizo a busca no BD
var usuario =
previdenciaRepository.Previdencias.Where(p => p.CdMatricula == matricula && p.SqContrato == contrato).ToList();
return View(usuario);
}
And in the view I make the calculation to sum the data returned, thus:
<table border="1">
<thead>
<tr>
<th rowspan="2">
Mês
</th>
<th colspan="4">
<p align="center">
Contribuinte
</p>
</th>
</tr>
<tr>
<th>
%
</th>
<th>
R$ Ano
</th>
<th>
Acumulado R$
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Previdencia.GroupBy(g => g.NmPessoa))
{
double subtotal = 0;
foreach (var contribuicoes in item.ToList())
{
subtotal += contribuicoes.Contribuinte;
<tr>
<td>
@Html.DisplayFor(modelItem => contribuicoes.dtCompetencia)
</td>
<td>
11
</td>
<td>
@Html.DisplayFor(modelItem => contribuicoes.Contribuinte)
</td>
<td>
@subtotal.ToString("c")
</td>
</tr>
}
}
</tbody>
</table>
My Model looks like this:
public class Previdencia
{
[Key]
public Int64 Cod_Previdencia { get; set; }
public int CdMatricula { get; set; }
public Int16 SqContrato { get; set; }
public string NmPessoa { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? dtCompetencia { get; set; }
}