-1
I’m new to the business and I’m on my first steps.
I am trying to create a system of financial consolidation. I need it to return me the total expenses of a certain Rubric.
using System;
using System.Linq;
using System.Web;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Siscongest.Models
{
public class Despesa
{
[Key]
public int IdDespesa { get; set; }
[Range(1, double.MaxValue, ErrorMessage = "Selecione a Empresa")]
[Display(Name = "Empresa")]
public int IdEmpresa { get; set; }
[Range(1, double.MaxValue, ErrorMessage = "Selecione a Rubrica")]
[Display(Name = "Rubrica")]
public int IdRubricaDespesa { get; set; }
[Required(ErrorMessage = "O campo {0} é requerido!!")]
[MaxLength(150, ErrorMessage = "O campo {0 } recebe no máximo {1} caracteres")]
[Display(Name = "Descrição")]
public string Descricao { get; set; }
[DataType(DataType.Date)]
[Required(ErrorMessage = "O campo {0} é requerido!!")]
[Display(Name = "Data da Despesa")]
public DateTime DataDespesa { get; set; }
[Required(ErrorMessage = "O campo {0} é requerido!!")]
[Display(Name = "Valor da Despesa")]
public double Valor { get; set; }
[Range(1, double.MaxValue, ErrorMessage = "Selecione a Moeda")]
[Required(ErrorMessage = "O campo {0} é requerido!!")]
[Display(Name = "Moeda")]
public int IdMoeda { get; set; }
public virtual Moeda Moeda { get; set; }
public virtual RubricaDespesa RubricaDespesa { get; set; }
public virtual Empresa Empresa { get; set; }
}
}
I have the complete Expense List :
public ActionResult Index()
{
var despesas = db.Despesas
.Include(d => d.RubricaDespesa)
.Include(d => d.Empresa)
.Include(d => d.Moeda);
return View(despesas.ToList());
}
I need him now to return me to List with the Total for Rubric , Total per Companies and Total by Coins.
I’m trying to use the code for the report but it doesn’t work
public ActionResult GraficoDespesaRubrica(int? idRubrica)
{
var list = db.Despesas.OrderBy(d => d.DataDespesa)
.Where(d => d.IdRubricaDespesa == idRubrica);
foreach(var rubri in list)
{
list.Where(d => d.IdRubricaDespesa == idRubrica).
Sum(d => d.Valor);
}
var rubrica = new List<int>();
var val = list.Select(x => x.Valor);
var data = list.Select(x => x.RubricaDespesa.Descricao);
var rub = rubrica;
ViewBag.VALOR = val;
ViewBag.Data = data;
}
I tried and it didn’t work
– Manuel Xavier
What didn’t work? You asked for a lot of things and I asked you to indicate the format of the final list.
– MauroAlmeida
Would you like a normal listing, or return in graphic form
– Manuel Xavier
What is the format of the list? what objects do you have? If you want totals by each entity want id’s indication together with totals?
– MauroAlmeida
I want a list of Totals by Items, Totals by Company and by Currencies
– Manuel Xavier
Mauroalmeida?
– Manuel Xavier
Someone who can help me?
– Manuel Xavier
"I want a list of Totals by Items, Totals by Company and by Currencies" - This does not explain how you want objectively the data, you have to give a concrete example of the format of the final result.
– MauroAlmeida
Something Like What
– Manuel Xavier
wanted a listing with the sum of all Items, Description of Item - Total Value - Currency
– Manuel Xavier
I wonder if you could help me remotely?
– Manuel Xavier
Can someone give me a little help?
– Manuel Xavier
Manuel, see if this is what you want, I don’t know your Model for Headings and for Companies, but from what you asked I calculated that the Rubric had a field Description and the Enterprise a field Name. If my answers have helped you to learn and to solve your problem, or part of it, put the answer as accepted.
– MauroAlmeida
Now I’m Getting This Error " The model item passed into the Dictionary is of type 'System.Data.Entity.Infrastructure.Dbquery
1[<>f__AnonymousType4
2[System.String,System.Double]]', but this Dictionary requires a model item of type 'System.Collections.Generic.Ienumerable`1[Siscongest.Models.Expense]'. "– Manuel Xavier
on which code line?
– MauroAlmeida
when I call - http://localhost:54990/Expenses/Jobsworking. I wonder if you could help me remotely?
– Manuel Xavier
I tried several ways and I couldn’t. I don’t know how you could help me
– Manuel Xavier