|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Fee.Dtos
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 费用汇总统计模型
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FeeStatistics
|
|
|
|
|
{
|
|
|
|
|
//默认本币
|
|
|
|
|
static readonly string LocalCurrency = "CNY";
|
|
|
|
|
readonly IEnumerable<FeeRecord> _source;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 使用指定的数据源初始化统计。
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="source">数据源</param>
|
|
|
|
|
public FeeStatistics(IEnumerable<FeeRecord> source)
|
|
|
|
|
{
|
|
|
|
|
_source = source;
|
|
|
|
|
|
|
|
|
|
var localReceivable = _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency == LocalCurrency).Sum(x => x.Amount).GetValueOrDefault();
|
|
|
|
|
//其他币种按汇率转换为本币金额,下同
|
|
|
|
|
var otherReceivable = (from s in _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != 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).Sum(x => x.Amount).GetValueOrDefault();
|
|
|
|
|
var otherPayable = (from s in _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != 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 == LocalCurrency).Sum(x => x.NoTaxAmount);
|
|
|
|
|
var otherNoTaxReceivable = (from s in _source.Where(x => x.FeeType == FeeType.Receivable && x.Currency != 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 == LocalCurrency).Sum(x => x.NoTaxAmount);
|
|
|
|
|
var otherNoTaxPayable = (from s in _source.Where(x => x.FeeType == FeeType.Payable && x.Currency != 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).GetValueOrDefault();
|
|
|
|
|
PayableCNY = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "CNY").Sum(x => x.Amount).GetValueOrDefault();
|
|
|
|
|
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).GetValueOrDefault();
|
|
|
|
|
PayableUSD = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "USD").Sum(x => x.Amount).GetValueOrDefault();
|
|
|
|
|
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).GetValueOrDefault();
|
|
|
|
|
PayableOther = _source.Where(x => x.FeeType == FeeType.Payable && x.Currency == "USD" && x.Currency != "CNY").Sum(x => x.Amount).GetValueOrDefault();
|
|
|
|
|
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 CustomerFeeStatistics
|
|
|
|
|
{
|
|
|
|
|
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 == "CNY").Sum(x => x.Amount).GetValueOrDefault(),
|
|
|
|
|
PayableCNY = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == "CNY").Sum(x => x.Amount).GetValueOrDefault(),
|
|
|
|
|
ReceivableUSD = g.Where(x => x.FeeType == FeeType.Receivable && x.Currency == "USD").Sum(x => x.Amount).GetValueOrDefault(),
|
|
|
|
|
PayableUSD = g.Where(x => x.FeeType == FeeType.Payable && x.Currency == "USD").Sum(x => x.Amount).GetValueOrDefault()
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应收款总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ReceivableTotal { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税应收款总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxReceivableTotal { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应付款总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal PayableTotal { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税应付款总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxPayableTotal { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 利润总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ProfitTotal { get { return ReceivableTotal - PayableTotal; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 利润率
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ProfitMargin
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (PayableTotal == 0)
|
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
|
|
//利润率=利润÷成本×100%
|
|
|
|
|
return string.Concat((ReceivableTotal / PayableTotal) * 100, "%");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税利润总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxProfitTotal { get { return NoTaxReceivableTotal - NoTaxPayableTotal; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 人民币应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ReceivableCNY { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税人民币应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxReceivableCNY { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 人民币应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal PayableCNY { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税人民币应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxPayableCNY { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 人民币利润
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ProfitCNY { get { return ReceivableCNY - PayableCNY; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税人民币利润
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxProfitCNY { get { return NoTaxReceivableCNY - NoTaxPayableCNY; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 美元应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ReceivableUSD { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税美元应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxReceivableUSD { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 美元应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal PayableUSD { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税美元应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxPayableUSD { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 美元利润
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ProfitUSD { get { return ReceivableUSD - PayableUSD; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税美元利润
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxProfitUSD { get { return NoTaxReceivableUSD - NoTaxPayableUSD; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 其他币种应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ReceivableOther { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税其他币种应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxReceivableOther { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 其他币种应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal PayableOther { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税其他币种应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxPayableOther { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 其他币种利润
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal ProfitOther { get { return ReceivableOther - PayableOther; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不含税其他币种利润
|
|
|
|
|
/// </summary>
|
|
|
|
|
public decimal NoTaxProfitOther { get { return NoTaxReceivableOther - NoTaxPayableOther; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按客户统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<CustomerFeeStatistics> ByCustomers { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 费用记录按客户统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CustomerFeeStatistics
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string CustomerName { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应收款总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual decimal ReceivableTotal { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 应付款总计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual decimal PayableTotal { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 人民币应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual decimal ReceivableCNY { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 人民币应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual decimal PayableCNY { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 美元应收款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual decimal ReceivableUSD { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 美元应付款
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual decimal PayableUSD { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class FeeStatisticsRequest
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string QueryCondition { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|