using DS.Module.Core; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Op.Entity; namespace DS.WMS.Core.Fee.Dtos { /// /// 费用汇总统计项 /// public class FeeStatItem { /// /// 应收款总计(RMB) /// public decimal ReceivableTotal { get; set; } /// /// 应付款总计(RMB) /// public decimal PayableTotal { get; set; } /// /// 利润总计(RMB) /// public decimal ProfitTotal { get { return ReceivableTotal - PayableTotal; } } /// /// 利润率(利润/应付) /// public string ProfitMargin { get { if (PayableTotal == 0) return string.Empty; //利润率=利润÷应付/应收×100% return string.Concat(Math.Round(ProfitTotal / PayableTotal * 100, 2, MidpointRounding.AwayFromZero), "%"); } } /// /// 应收利润率(利润/应收) /// public string RecvProfitMargin { get { if (ReceivableTotal == 0) return string.Empty; //利润率=利润÷应付/应收×100% return string.Concat(Math.Round(ProfitTotal / ReceivableTotal * 100, 2, MidpointRounding.AwayFromZero), "%"); } } /// /// 人民币应收款 /// public decimal ReceivableCNY { get; set; } /// /// 人民币应付款 /// public decimal PayableCNY { get; set; } /// /// 人民币利润 /// public decimal ProfitCNY { get { return ReceivableCNY - PayableCNY; } } /// /// 美元应收款 /// public decimal ReceivableUSD { get; set; } /// /// 美元应付款 /// public decimal PayableUSD { get; set; } /// /// 美元利润 /// public decimal ProfitUSD { get { return ReceivableUSD - PayableUSD; } } /// /// 其他币种应收款 /// public decimal ReceivableOther { get; set; } /// /// 其他币种应付款 /// public decimal PayableOther { get; set; } /// /// 其他币种利润 /// public decimal ProfitOther { get { return ReceivableOther - PayableOther; } } } /// /// 费用汇总统计项(附不含税统计) /// public class NoTaxFeeStatItem : FeeStatItem { /// /// 不含税应收款总计 /// public decimal NoTaxReceivableTotal { get; set; } /// /// 不含税应付款总计 /// public decimal NoTaxPayableTotal { get; set; } /// /// 不含税利润总计 /// public decimal NoTaxProfitTotal { get { return NoTaxReceivableTotal - NoTaxPayableTotal; } } /// /// 不含税人民币应收款 /// public decimal NoTaxReceivableCNY { get; set; } /// /// 不含税人民币应付款 /// public decimal NoTaxPayableCNY { get; set; } /// /// 不含税人民币利润 /// public decimal NoTaxProfitCNY { get { return NoTaxReceivableCNY - NoTaxPayableCNY; } } /// /// 不含税美元应收款 /// public decimal NoTaxReceivableUSD { get; set; } /// /// 不含税美元应付款 /// public decimal NoTaxPayableUSD { get; set; } /// /// 不含税美元利润 /// public decimal NoTaxProfitUSD { get { return NoTaxReceivableUSD - NoTaxPayableUSD; } } /// /// 不含税其他币种应收款 /// public decimal NoTaxReceivableOther { get; set; } /// /// 不含税其他币种应付款 /// public decimal NoTaxPayableOther { get; set; } /// /// 不含税其他币种利润 /// public decimal NoTaxProfitOther { get { return NoTaxReceivableOther - NoTaxPayableOther; } } } /// /// 费用汇总统计模型 /// public class FeeStatistics : NoTaxFeeStatItem { readonly IEnumerable _source; /// /// 使用指定的数据源初始化统计。 /// /// 数据源 public FeeStatistics(IEnumerable source) { _source = source; var localReceivable = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == x.LocalCurrency).Sum(x => x.Amount); //其他币种按汇率转换为本币金额,下同 var otherReceivable = (from s in _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.Amount * x.Key.ExchangeRate)).GetValueOrDefault(); ReceivableTotal = localReceivable + otherReceivable;//应收合计 var localPayable = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == x.LocalCurrency).Sum(x => x.Amount); var otherPayable = (from s in _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.Amount * x.Key.ExchangeRate)).GetValueOrDefault(); PayableTotal = localPayable + otherPayable;//应付合计 var localNoTaxReceivable = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == x.LocalCurrency).Sum(x => x.NoTaxAmount); var otherNoTaxReceivable = (from s in _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.NoTaxAmount * x.Key.ExchangeRate)).GetValueOrDefault(); NoTaxReceivableTotal = localNoTaxReceivable + NoTaxReceivableTotal; var localNoTaxPayable = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == x.LocalCurrency).Sum(x => x.NoTaxAmount); var otherNoTaxPayable = (from s in _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.NoTaxAmount * x.Key.ExchangeRate)).GetValueOrDefault(); NoTaxPayableTotal = localNoTaxPayable + otherNoTaxPayable; //人民币 ReceivableCNY = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "CNY").Sum(x => x.Amount); PayableCNY = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "CNY").Sum(x => x.Amount); NoTaxReceivableCNY = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "CNY").Sum(x => x.NoTaxAmount); NoTaxPayableCNY = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "CNY").Sum(x => x.NoTaxAmount); //美元 ReceivableUSD = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "USD").Sum(x => x.Amount); PayableUSD = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "USD").Sum(x => x.Amount); NoTaxReceivableUSD = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "USD").Sum(x => x.NoTaxAmount); NoTaxPayableUSD = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "USD").Sum(x => x.NoTaxAmount); //其他 ReceivableOther = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != "USD" && x.Currency != "CNY").Sum(x => x.Amount); PayableOther = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != "USD" && x.Currency != "CNY").Sum(x => x.Amount); NoTaxReceivableOther = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != "USD" && x.Currency != "CNY").Sum(x => x.NoTaxAmount); NoTaxPayableOther = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != "USD" && x.Currency != "CNY").Sum(x => x.NoTaxAmount); //按客户统计 ByCustomers = (from s in _source group s by s.CustomerName into g select new ByCustomerStat { CustomerName = g.Key, ReceivableTotal = g.Where(x => x.FeeType == FeeType.Receivable).Sum(x => x.Amount), PayableTotal = g.Where(x => x.FeeType == FeeType.Payable).Sum(x => x.Amount), ReceivableCNY = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "CNY").Sum(x => x.Amount), PayableCNY = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == "CNY").Sum(x => x.Amount), ReceivableUSD = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "USD").Sum(x => x.Amount), PayableUSD = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == "USD").Sum(x => x.Amount) }).ToList(); } /// /// 按客户统计 /// public List ByCustomers { get; private set; } } /// /// 用于费用审核的汇总统计模型 /// public class FeeAuditStatistics : FeeStatItem { readonly IEnumerable _source; /// /// 销项金额 /// public decimal AccValue => ReceivableTotal - Math.Round(ReceivableTotal * AccTaxRate.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); /// /// 销项税额 /// public decimal? AccTaxRate { get; set; } /// /// 进项金额 /// public decimal IncomeValue => PayableTotal - Math.Round(PayableTotal * IncomeTaxRate.GetValueOrDefault(), 2, MidpointRounding.AwayFromZero); /// /// 进项税额 /// public decimal? IncomeTaxRate { get; set; } /// /// 使用指定的数据源初始化统计。 /// /// 数据源 public FeeAuditStatistics(IEnumerable source) { _source = source; AccTaxRate = source.FirstOrDefault()?.AccTaxRate; IncomeTaxRate = source.FirstOrDefault()?.TaxRate; var localReceivable = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == x.LocalCurrency).Sum(x => x.Amount).GetValueOrDefault(); //其他币种按汇率转换为本币金额,下同 var otherReceivable = (from s in _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.Amount * x.Key.ExchangeRate)).GetValueOrDefault(); ReceivableTotal = localReceivable + otherReceivable;//应收合计 var localPayable = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == x.LocalCurrency).Sum(x => x.Amount).GetValueOrDefault(); var otherPayable = (from s in _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.Amount * x.Key.ExchangeRate)).GetValueOrDefault(); PayableTotal = localPayable + otherPayable;//应付合计 //人民币 ReceivableCNY = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(); PayableCNY = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(); //美元 ReceivableUSD = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount).GetValueOrDefault(); PayableUSD = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount).GetValueOrDefault(); //其他 ReceivableOther = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != FeeCurrency.USD_CODE && x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(); PayableOther = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != FeeCurrency.USD_CODE && x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(); //按客户统计 ByCustomer = (from s in _source group s by s.CustomerName into g select new ByCustomerStat { CustomerName = g.Key, ReceivableTotal = g.Where(x => x.FeeType == FeeType.Receivable).Sum(x => x.Amount).GetValueOrDefault(), PayableTotal = g.Where(x => x.FeeType == FeeType.Payable).Sum(x => x.Amount).GetValueOrDefault(), ReceivableCNY = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(), PayableCNY = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(), ReceivableUSD = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount).GetValueOrDefault(), PayableUSD = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount).GetValueOrDefault(), ReceivableOther = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency != FeeCurrency.USD_CODE && x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.Amount * x.ExchangeRate).GetValueOrDefault(), PayableOther = g.Where(x => x.FeeType == FeeType.Payable && x.Currency != FeeCurrency.USD_CODE && x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.Amount * x.ExchangeRate).GetValueOrDefault() }).ToList(); ByCustomer.Add(new ByCustomerStat { CustomerName = "合计", ReceivableTotal = ReceivableTotal, PayableTotal = PayableTotal, ReceivableCNY = ReceivableCNY, PayableCNY = PayableCNY, ReceivableUSD = ReceivableUSD, PayableUSD = PayableUSD, ReceivableOther = ReceivableOther, PayableOther = PayableOther }); //按业务统计 ByBusiness = (from s in _source group s by s.BillNO into g select new ByBusinessStat { BillNO = g.Key, ReceivableTotal = g.Where(x => x.FeeType == FeeType.Receivable).Sum(x => x.Amount).GetValueOrDefault(), PayableTotal = g.Where(x => x.FeeType == FeeType.Payable).Sum(x => x.Amount).GetValueOrDefault(), ReceivableCNY = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(), PayableCNY = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == FeeCurrency.RMB_CODE).Sum(x => x.Amount).GetValueOrDefault(), ReceivableUSD = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount).GetValueOrDefault(), PayableUSD = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == FeeCurrency.USD_CODE).Sum(x => x.Amount).GetValueOrDefault(), ReceivableOther = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency != FeeCurrency.USD_CODE && x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.Amount * x.ExchangeRate).GetValueOrDefault(), PayableOther = g.Where(x => x.FeeType == FeeType.Payable && x.Currency != FeeCurrency.USD_CODE && x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.Amount * x.ExchangeRate).GetValueOrDefault() }).ToList(); ByBusiness.Add(new ByBusinessStat { BillNO = "合计", ReceivableTotal = ReceivableTotal, PayableTotal = PayableTotal, ReceivableCNY = ReceivableCNY, PayableCNY = PayableCNY, ReceivableUSD = ReceivableUSD, PayableUSD = PayableUSD, ReceivableOther = ReceivableOther, PayableOther = PayableOther }); //按币种统计 ByCurrency = (from s in _source group s by s.Currency into g select new ByCurrencyStat { Currency = g.Key, ReceivableTotal = g.Where(x => x.FeeType == FeeType.Receivable).Sum(x => x.Amount).GetValueOrDefault(), PayableTotal = g.Where(x => x.FeeType == FeeType.Payable).Sum(x => x.Amount).GetValueOrDefault(), NoTaxReceivableTotal = g.Where(x => x.FeeType == FeeType.Receivable).Sum(x => x.NoTaxAmount), NoTaxPayableTotal = g.Where(x => x.FeeType == FeeType.Payable).Sum(x => x.NoTaxAmount), }).ToList(); var bcs = new ByCurrencyStat { Currency = "合计", ReceivableTotal = ReceivableTotal, PayableTotal = PayableTotal, NoTaxReceivableTotal = _source.Where(x => x.FeeType == FeeType.Receivable).Sum(x => x.NoTaxAmount), }; var localNoTaxReceivable = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == x.LocalCurrency).Sum(x => x.NoTaxAmount); //其他币种按汇率转换为本币金额,下同 var otherNoTaxReceivable = (from s in _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.NoTaxAmount * x.Key.ExchangeRate)).GetValueOrDefault(); bcs.NoTaxReceivableTotal = localReceivable + otherReceivable;//不含税应收合计 var localNoTaxPayable = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == x.LocalCurrency).Sum(x => x.NoTaxAmount); var otherNoTaxPayable = (from s in _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != x.LocalCurrency) group s by new { s.Currency, s.ExchangeRate } into g select new { g.Key, Items = g }).Sum(x => x.Items.Sum(y => y.NoTaxAmount * x.Key.ExchangeRate)).GetValueOrDefault(); bcs.NoTaxPayableTotal = localPayable + otherPayable;//不含税应付合计 ByCurrency.Add(bcs); } /// /// 按客户统计 /// public List ByCustomer { get; private set; } /// /// 按业务统计 /// public List ByBusiness { get; private set; } /// /// 按币种统计 /// public List ByCurrency { get; private set; } } /// /// 按客户统计费用 /// public class ByCustomerStat : FeeStatItem { /// /// 客户名称 /// public string CustomerName { get; set; } } /// /// 按业务统计费用 /// public class ByBusinessStat : FeeStatItem { /// /// 业务编号 /// public string BillNO { get; set; } } /// /// 按业务统计费用 /// public class ByCurrencyStat { /// /// 币种 /// public string Currency { get; set; } /// /// 应收款总计 /// public decimal ReceivableTotal { get; set; } /// /// 应付款总计 /// public decimal PayableTotal { get; set; } /// /// 利润总计 /// public decimal ProfitTotal => ReceivableTotal - PayableTotal; /// /// 不含税应收款总计 /// public decimal NoTaxReceivableTotal { get; set; } /// /// 不含税应付款总计 /// public decimal NoTaxPayableTotal { get; set; } /// /// 不含税利润总计 /// public decimal NoTaxProfitTotal => NoTaxReceivableTotal - NoTaxPayableTotal; } public class FeeStatisticsRequest { /// /// 查询条件 /// public string QueryCondition { get; set; } } public class FeeStatisticsRequestV2 { /// /// 业务ID /// public long Id { get; set; } /// /// 业务类型 /// public BusinessType BusinessType { get; set; } /// /// 费用ID(可空) /// public long? FeeId { get; set; } } }