KellyReport_D/Model/ImportContext.cs

49 lines
2.1 KiB
C#
Raw Normal View History

2025-08-11 23:48:45 +08:00
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KellyReport_D.Model
{
internal class ImportContext
{
public Workbook ImportWorkbook { get; set; }
public Microsoft.Office.Interop.Excel.Application Application { get; set; }
public IList<ClientContact> ClientContactList { get; set; }
public IList<SalesDetail> SalesDetails { get; set; }
public class GroupedSalesDetailModel
{
public string SalesName { get; set; }
public string ClientName { get; set; }
public string ProductNameEN { get; set; }
public decimal TotalAmount { get; set; }
public List<SalesDetail> Details { get; set; }
}
public IEnumerable<GroupedSalesDetailModel> GroupedSalesDetailBySalesName => SalesDetails
.GroupBy(x => x.SalesName.ToUpper())
.Select(grouped => new GroupedSalesDetailModel
{
SalesName = grouped.Key,
TotalAmount = grouped.Sum(x => x.TotalAmount ?? 0),
Details = grouped.ToList()
});
public IEnumerable<GroupedSalesDetailModel> GetGroupedSalesDetailByClientName(IList<SalesDetail> salesDetails)
{
return salesDetails
.GroupBy(x => new { SalesName = x.SalesName.ToUpper(), x.ClientName, x.ProductNameEN })
.Select(grouped => new GroupedSalesDetailModel
{
SalesName = grouped.Key.SalesName,
ClientName = grouped.Key.ClientName,
ProductNameEN = grouped.Key.ProductNameEN,
TotalAmount = grouped.Sum(x => x.TotalAmount ?? 0),
Details = grouped.ToList()
});
}
}
}