A set of technologies in the .NET Framework for building web applications and XML web services.
simple linq:
define ResultData class:
public class ResultData
{
public int Company_ID { get; set; }
public int Year { get; set; }
public int Month { get; set; }
public decimal Payment { get; set; }
public decimal Received { get; set; }
}
query:
var result = source.Select(r => new ResultData
{
Company_ID = r.Company_ID,
Year = (r.AgainstMonth ?? r.Date).Year,
Month = (r.AgainstMonth ?? r.Date).Month,
Payment = r.Type == "Payment" ? r.Amount : 0,
Received = r.Type == "Received" ? r.Amount : 0,
Balance = r.Type == "Payment" ? r.Amount
: r.Type == "Received" ? -r.Amount
: 0
}).GroupBy(
r => (r.Company_ID, r.Year, r.Month),
r => r,
(k, v) => new ResultData
{
Company_ID = k.Item1,
Year = k.Item2,
Month = k.Item3,
Payment = v.Sum(s => s.Payment),
Received = v.Sum(s => s.Received),
Balance = v.Sum(s => s.Balance)
}
);