using System;
using System.Collections.Generic;
using System.Linq;
using Edu.Common.Enum.Finance;
using Edu.Common.Plugin;
using Edu.Model.Entity.Finance;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Finance;
using Edu.Repository.Course;
using Edu.Repository.Finance;
using Edu.Repository.StudyAbroad;
using Edu.Repository.User;

namespace Edu.Module.Finance
{
    /// <summary>
    /// 财务处理类
    /// </summary>
    public class FinanceModule
    {
        /// <summary>
        /// 财务单据
        /// </summary>
        private readonly RB_FinanceRepository RB_FinanceRepository = new RB_FinanceRepository();
        /// <summary>
        /// 财务单据详情
        /// </summary>
        private readonly RB_FinanceDetailRepository RB_FinanceDetailRepository = new RB_FinanceDetailRepository();
        /// <summary>
        /// 财务单据模板
        /// </summary>
        private readonly Repository.Finance.Rb_Workflow_TemplateRepository Finance_TemplateRepository = new Repository.Finance.Rb_Workflow_TemplateRepository();
        /// <summary>
        /// 交易方式
        /// </summary>
        private readonly RB_TradeWayRepository tradeWayRepository = new RB_TradeWayRepository();
        /// <summary>
        /// 银行账户
        /// </summary>
        private readonly RB_BackAccountRepository RB_BackAccountRepository = new RB_BackAccountRepository();
        /// <summary>
        /// 币种
        /// </summary>
        private readonly RB_CurrencyRepository RB_CurrencyRepository = new RB_CurrencyRepository();
        /// <summary>
        /// 现金账户
        /// </summary>
        private readonly RB_CashAccountRepository cashAccountRepository = new RB_CashAccountRepository();
        /// <summary>
        /// 资金池账户仓储层对象
        /// </summary>
        private readonly RB_CashPoolAccountRepository cashPoolAccountRepository = new RB_CashPoolAccountRepository();
        /// <summary>
        /// 平台账户仓储层对象
        /// </summary>
        private readonly RB_PlatformAccountRepository platformAccountRepository = new RB_PlatformAccountRepository();
        /// <summary>
        /// 费用类型仓储层对象
        /// </summary>
        private readonly RB_CosttypeRepository costtypeRepository = new RB_CosttypeRepository();
        /// <summary>
        /// 账户类型管理
        /// </summary>
        private readonly RB_AccountTypeRepository RB_AccountTypeRepository = new RB_AccountTypeRepository();
        /// <summary>
        /// 财务单据凭证仓储层对象
        /// </summary>
        private readonly RB_VoucherRepository voucherRepository = new RB_VoucherRepository();
        /// <summary>
        /// 营收报表
        /// </summary>
        private readonly RB_Edu_RevenueReportRepository edu_RevenueReportRepository = new RB_Edu_RevenueReportRepository();
        /// <summary>
        /// 简易报表
        /// </summary>
        private readonly RB_SimpleReportRepository edu_simpleReportRepository = new RB_SimpleReportRepository();
        /// <summary>
        /// 报表更新记录
        /// </summary>
        private readonly RB_Report_UpdateRecordRepository edu_UpdateRecordRepository = new RB_Report_UpdateRecordRepository();
        /// <summary>
        /// 班级
        /// </summary>
        private readonly RB_ClassRepository classRepository = new RB_ClassRepository();
        /// <summary>
        /// 订单列表
        /// </summary>
        private readonly RB_OrderRepository orderRepository = new RB_OrderRepository();
        /// <summary>
        /// 教师奖励明细
        /// </summary>
        private readonly RB_Teaching_BonusDetailRepository teaching_BonusDetailRepository = new RB_Teaching_BonusDetailRepository();
        /// <summary>
        /// 教师绩效
        /// </summary>
        private readonly RB_Teaching_PerfRepository teaching_PerfRepository = new RB_Teaching_PerfRepository();
        /// <summary>
        /// 学校仓储层对象
        /// </summary>
        private readonly RB_SchoolRepository schoolRepository = new RB_SchoolRepository();
        /// <summary>
        /// 留学就业
        /// </summary>
        private readonly RB_StudyAbroadRepository studyAbroadRepository = new RB_StudyAbroadRepository();
        /// <summary>
        /// 供应商
        /// </summary>
        private readonly RB_SupplierRepository supplierRepository = new RB_SupplierRepository();



        public List<RB_Finance_Extend> GetFinanceInfoList(RB_Finance_Extend model)
        {
            var list = RB_FinanceRepository.GetListSingle(model)?.Where(x => x.Status != FinanceAuditStatus.Delete).ToList();
            List<RB_TradeWay_Extend> tdlist = new List<RB_TradeWay_Extend>();
            List<RB_FinanceDetail_Extend> fdlist = new List<RB_FinanceDetail_Extend>();
            List<Rb_Workflow_Auditrecord> walist = new List<Rb_Workflow_Auditrecord>();
            List<RB_Costtype_Extend> costlist = new List<RB_Costtype_Extend>();
            List<RB_Finance_Extend> tclist = new List<RB_Finance_Extend>();
            List<RB_Voucher_Extend> volist = new List<RB_Voucher_Extend>();
            if (list.Any())
            {
                string fridStr = string.Join(",", list.Select(x => x.FrID));
                tdlist = GetBankListForFrIdStr(fridStr, model.RB_Group_Id ?? 2);
                fdlist = RB_FinanceDetailRepository.GetList(new RB_FinanceDetail_Extend() { FrIds = fridStr });
                if (fdlist.Any())
                {
                    costlist = costtypeRepository.GetList(new RB_Costtype_Extend() { CostIds = string.Join(",", fdlist.Select(x => x.CostTypeId ?? 0)) });
                }
                walist = Finance_TemplateRepository.GetAgreeOrWaitList(new Rb_Workflow_Auditrecord() { AuditStatus = WFRrocessStatus.NotAudit }, fridStr);
                volist = voucherRepository.GetList(new RB_Voucher_Extend() { FrIdStr = fridStr });
            }

            foreach (var item in list)
            {
                item.BankList = new List<RB_TradeWay_Extend>();
                item.BankList = tdlist.Where(x => x.FinanceId == item.FrID).ToList();
                item.CostTypeList = new List<string>();
                var detailList = fdlist.Where(x => x.FinanceId == item.FrID).ToList();
                item.detailList = detailList;
                foreach (var detailitem in detailList)
                {
                    var cmodel = costlist.Where(x => x.ID == detailitem.CostTypeId).FirstOrDefault();
                    item.CostTypeList.Add(cmodel?.Name ?? "");
                }
                #region 判断是否可以操作单据
                item.AuditList = new List<AuditInfo>();
                if (item.Status == FinanceAuditStatus.InReview)
                {
                    var Auditdata = walist.Where(x => x.WorkFlowId == item.FrID).ToList();
                    foreach (var sitem in Auditdata)
                    {
                        AuditInfo auditInfo = new AuditInfo()
                        {
                            AuditEmId = sitem.AuditEmId,
                            AuditDate = null,
                            AuditEmName = sitem.AuditEmIdName
                        };
                        item.AuditList.Add(auditInfo);
                    }
                }
                if (item.Type == WFTempLateClassEnum.IN && item.Status == FinanceAuditStatus.CTemporary)
                {
                    //判断如果是平台的单子  需要把实付清0
                    var bankModel = item.BankList.FirstOrDefault();
                    if (bankModel != null)
                    {
                        if (bankModel.Type == BranchAccountEnum.Platform && (item.PayMoney ?? 0) > 0)
                        {
                            item.PayMoney = 0;
                        }
                    }
                }
                #endregion
                #region 团队编号
                //item.TCIDAndTCNUMList = tclist.Where(x => x.FrID == item.FrID).FirstOrDefault()?.TCIDAndTCNUMList ?? new List<TCIDInfo>();
                #endregion
                #region  凭证
                item.vorcherInos = volist.Where(x => x.FinanceId == item.FrID).ToList();
                #endregion
            }
            return list;
        }


        /// <summary>
        /// 批量获取财务单据的交易方式
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public List<RB_TradeWay_Extend> GetBankListForFrIdStr(string FrIdStr, int GroupId)
        {
            if (string.IsNullOrWhiteSpace(FrIdStr))
            {
                return null;
            }
            List<RB_TradeWay_Extend> list = new List<RB_TradeWay_Extend>();
            var TradeList = tradeWayRepository.GetList(new RB_TradeWay_Extend() { FrIdStr = FrIdStr });
            //获取币种列表
            var CurrencyList = RB_CurrencyRepository.GetList(new Model.Entity.Finance.RB_Currency() { RB_Group_Id = GroupId });
            //查询四大账户
            var BankList = RB_BackAccountRepository.GetList(new RB_BackAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == BranchAccountEnum.Bank).Select(x => x.AccountId ?? 0).Distinct()) });
            var CashList = cashAccountRepository.GetList(new RB_CashAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == BranchAccountEnum.Cash).Select(x => x.AccountId ?? 0).Distinct()) });
            var CashPoolList = cashPoolAccountRepository.GetList(new RB_CashPoolAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == BranchAccountEnum.CashPool).Select(x => x.AccountId ?? 0).Distinct()) });
            var PlatformList = platformAccountRepository.GetList(new RB_PlatformAccount_Extend() { AccountIdStr = string.Join(",", TradeList.Where(x => x.Type == BranchAccountEnum.Platform).Select(x => x.AccountId ?? 0).Distinct()) });

            foreach (var TradeModel in TradeList)
            {
                RB_TradeWay_Extend accountInFo = TradeModel.RefMapperTo<RB_TradeWay_Extend>();
                accountInFo.CurrencyName = CurrencyList.Where(x => x.ID == TradeModel.CurrencyId).FirstOrDefault()?.Name ?? "";
                if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.Bank)
                {
                    var bank = BankList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                    if (bank != null)
                    {
                        accountInFo.Alias = bank.Alias;
                        accountInFo.BankNo = bank.BackNo;
                        accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.Bank;
                        accountInFo.AccountTypeId = bank.TypeId;
                        var accountType = RB_AccountTypeRepository.GetEntity(bank.TypeId.Value);
                        accountInFo.AccountType = accountType?.IsPublic == 0 ? "对私" : "对公";
                    }
                }
                else if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.Cash)
                {
                    var cash = CashList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                    if (cash != null)
                    {
                        accountInFo.Alias = cash.Alias;
                        accountInFo.BankNo = "";
                        accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.Cash;
                        accountInFo.AccountTypeId = cash.TypeId;
                        var accountType = RB_AccountTypeRepository.GetEntity(cash.TypeId.Value);
                        accountInFo.AccountType = accountType?.IsPublic == 0 ? "对私" : "对公";
                    }
                }
                else if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.CashPool)
                {
                    var pool = CashPoolList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                    if (pool != null)
                    {
                        accountInFo.Alias = pool.Alias;
                        accountInFo.BankNo = "";
                        accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.CashPool;
                        accountInFo.AccountTypeId = pool.TypeId;
                        var accountType = RB_AccountTypeRepository.GetEntity(pool.TypeId.Value);
                        accountInFo.AccountType = accountType?.IsPublic == 0 ? "对私" : "对公";
                    }
                }
                else if (TradeModel.Type == Common.Enum.Finance.BranchAccountEnum.Platform)
                {
                    var platform = PlatformList.Where(x => x.ID == TradeModel.AccountId).FirstOrDefault();
                    if (platform != null)
                    {
                        accountInFo.Alias = platform.Alias;
                        accountInFo.BankNo = platform.PlatformNo;
                        accountInFo.Type = Common.Enum.Finance.BranchAccountEnum.Platform;
                        accountInFo.AccountTypeId = platform.TypeId;
                        var accountType = RB_AccountTypeRepository.GetEntity(platform.TypeId.Value);
                        accountInFo.AccountType = accountType?.IsPublic == 0 ? "对私" : "对公";
                    }
                }
                list.Add(accountInFo);
            }
            return list;
        }


        #region 营收报表+简易报表初始化

        /// <summary>
        /// 更新营收报表
        /// </summary>
        /// <param name="GroupId"></param>
        /// <param name="StartTime"></param>
        /// <param name="EndTime"></param>
        /// <returns></returns>
        public bool SetEduRevenueReport(int GroupId, string StartTime, bool IsUpdateHistory)
        {
            edu_UpdateRecordRepository.Insert(new RB_Report_UpdateRecord()
            {
                Type = 1,
                StartDate = DateTime.Now
            });
            string STime = "";string ETime = "";
            if (IsUpdateHistory == true)
            {
                //历史 往后倒退一年
                STime = Convert.ToDateTime(StartTime).AddYears(-1).ToString("yyyy-MM-dd");
                ETime = StartTime;
            }
            else {
                STime = StartTime;
                ETime = DateTime.Now.AddYears(1).ToString("yyyy-MM-dd");
            }

            //查询日期范围内所有的班级
            var classList = classRepository.GetClassAndCourseListRepository(new RB_Class_ViewModel() { Group_Id = GroupId, StartTime = STime, EndTime = ETime }).Where(x => x.ClassStatus != Common.Enum.Course.ClassStatusEnum.CancelClass).ToList();
            List<RB_Order_ViewModel> orderAllList = new List<RB_Order_ViewModel>();
            List<RB_Finance_Extend> FAllList = new List<RB_Finance_Extend>();
            List<RB_Teaching_BonusDetail_ViewModel> teacherBonusList = new List<RB_Teaching_BonusDetail_ViewModel>();
            List<RB_Teaching_Perf_ViewModel> meritsProfitList = new List<RB_Teaching_Perf_ViewModel>();
            if (classList.Any())
            {
                string classIds = string.Join(",", classList.Select(x => x.ClassId));
                //根据班级查询所有的订单列表
                orderAllList = orderRepository.GetList(new RB_Order_ViewModel() { Group_Id = GroupId, ClassIds = classIds, OrderType = Common.Enum.Sale.OrderTypeEnum.CourseOrder, Q_OrderState = 1 });
                //查询班级下所有的财务单据
                FAllList = RB_FinanceRepository.GetDataStatisticsListThree(new RB_Finance_Extend() { TCIDStr = classIds, OrderSource = OrderResourceEnum.Education });
                teacherBonusList = teaching_BonusDetailRepository.GetList(new RB_Teaching_BonusDetail_ViewModel { Group_Id = GroupId, ClassIds = classIds });
                meritsProfitList = teaching_PerfRepository.GetList(new RB_Teaching_Perf_ViewModel { Group_Id = GroupId, ClassIds = classIds });
            }
            //排序取消/删除班级
            var oldlist = edu_RevenueReportRepository.GetList(new RB_Edu_RevenueReport_Extend() { StartTime = STime, EndTime = ETime, DateType = 1, Rb_Group_Id = GroupId });
            var delList = oldlist.Where(x => !classList.Select(y => y.ClassId).Contains(x.ClassId)).ToList();
            if (delList.Any())
            {
                edu_RevenueReportRepository.DeleteBatch(delList);
            }

            foreach (var item in classList) {
                try
                {
                    Console.WriteLine("班级：" + item.ClassName + "|" + item.ClassId);
                    bool IsNew = false;//是否新增
                    var orderList = orderAllList.Where(x => x.ClassId == item.ClassId).ToList();
                    var financeList = FAllList.Where(x => x.TCID == item.ClassId).ToList();
                    var demodel = oldlist.Where(x => x.ClassId == item.ClassId).FirstOrDefault();
                    if (demodel == null) {
                        IsNew = true;
                        //新增
                        demodel = new RB_Edu_RevenueReport_Extend()
                        {
                            Id = 0,
                            ClassId = item.ClassId,
                            Rb_Group_Id = GroupId,
                            SchoolId = item.School_Id,
                            SchoolName = item.SchoolName,
                            DateType = 1
                        };
                    }
                    #region 初始化数据
                    demodel.ClassBegins = item.OpenTime;
                    demodel.ClassName = item.ClassName;
                    demodel.ClassState = (int)item.ClassStatus;
                    demodel.CourseId = item.CouseId;
                    demodel.CourseName = item.CourseName;
                    demodel.TeacherId = item.Teacher_Id;
                    demodel.TeacherName = item.TeacherName;
                    demodel.SchoolId = item.School_Id;
                    demodel.SchoolName = item.SchoolName;
                    #endregion

                    #region 统计数据
                    #region 订单
                    demodel.YingShou = orderList.Sum(x => x.PreferPrice);
                    demodel.ShiShou = orderList.Sum(x => x.Income);
                    demodel.TuiKuan = orderList.Sum(x => x.Refund);
                    demodel.PingTaiShuiJin = orderList.Sum(x => x.PlatformTax);
                    demodel.ZaiTu = 0;//暂时在途未做
                    demodel.YouHui = orderList.Sum(x => x.DiscountMoney);
                    demodel.DaiShou = (demodel.YingShou - demodel.ShiShou + demodel.TuiKuan - demodel.PingTaiShuiJin - demodel.YouHui);
                    demodel.YiShou = -demodel.DaiShou;
                    demodel.GuestNum = orderList.Sum(x => x.GuestNum);
                    #endregion
                    #region 财务单据
                    //排序订单单据
                    var cfinanceList = financeList.Where(x => x.OrderID == 0 && x.Type == WFTempLateClassEnum.IN).ToList();
                    demodel.QTShouRu = cfinanceList.Where(y => y.Is_Cashier == 1).Sum(x => x.Money ?? 0);
                    demodel.QTShouRu -= cfinanceList.Where(x => x.Is_Cashier == 1 && x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                    //支出
                    demodel.TiCheng = orderList.Where(x => x.IsCommissionGive == 1).Sum(x => x.CommissionMoney);//销售提成
                    demodel.ClassFee = teacherBonusList.Where(x => x.ClassId == item.ClassId).Sum(x => x.Money);//老师提成
                    demodel.JiXiaoMoney = meritsProfitList.Where(x => x.ClassId == item.ClassId && x.PerfState == Common.Enum.Course.PerfStateEnum.Confirmed).OrderByDescending(x => x.CreateTime).FirstOrDefault()?.Money ?? 0;//绩效提成

                    var ofinanceList = financeList.Where(x => x.Type == WFTempLateClassEnum.OUT).ToList();// 支出包括退款
                    demodel.QTZhiChu = ofinanceList.Sum(x => x.Money ?? 0);
                    demodel.YingFu = demodel.QTZhiChu + demodel.TiCheng + demodel.ClassFee + demodel.JiXiaoMoney;
                    #endregion

                    demodel.MaoLi = demodel.ShiShou - demodel.YingFu;
                    demodel.ShiJiLiRun = demodel.MaoLi + demodel.QTShouRu;

                    //毛利率
                    if (demodel.ShiShou != 0)
                    {
                        demodel.MaoLiRate = Math.Round(demodel.MaoLi / demodel.ShiShou * 100, 2, MidpointRounding.AwayFromZero);
                    }
                    if (demodel.GuestNum > 0)
                    {
                        //平均收入=实收+自费收入+其他收入+佣金收入（属于佣金的所有）/参团+单团报入
                        demodel.AverageIncome = Math.Round((demodel.ShiShou + demodel.QTShouRu) / demodel.GuestNum, 2, MidpointRounding.AwayFromZero);
                        //平均成本=应付/参团+单团报入
                        demodel.AverageCost = Math.Round((demodel.YingFu / demodel.GuestNum), 2, MidpointRounding.AwayFromZero);
                    }
                    //平均利润=平均收入-平均成本
                    demodel.AverageProfit = demodel.AverageIncome - demodel.AverageCost;
                    #endregion

                    if (IsNew)
                    {
                        edu_RevenueReportRepository.Insert(demodel);
                    }
                    else {
                        edu_RevenueReportRepository.Update(demodel);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("班级：" + item.ClassName + "|" + item.ClassId + ",错误：" + ex.Message);
                    LogHelper.Write(ex, "SetEduRevenueReport");
                }
            }


            #region 留学就业
            //查询日期范围内所有的留学就业项目
            var saList = studyAbroadRepository.GetStudyAbroadListExtRepository(new Model.ViewModel.StudyAbroad.RB_StudyAbroad_ViewModel() { Group_Id = GroupId, SaleState = Common.Enum.Sale.SaleStateEnum.Sell, StartTime = STime, EndTime = ETime });
            if (saList.Any()) {
                string saIds = string.Join(",", saList.Select(x => x.Id));
                //根据班级查询所有的订单列表
                orderAllList = orderRepository.GetList(new RB_Order_ViewModel() { Group_Id = GroupId, SourceIds = saIds, OrderType = Common.Enum.Sale.OrderTypeEnum.StudyabroadOrder, Q_OrderState = 1 });
                //查询班级下所有的财务单据
                FAllList = RB_FinanceRepository.GetDataStatisticsListThree(new RB_Finance_Extend() { TCIDStr = saIds, OrderSource = OrderResourceEnum.EducationStudy });
            }
            //排除取消/删除项目
            oldlist = edu_RevenueReportRepository.GetList(new RB_Edu_RevenueReport_Extend() { StartTime = STime, EndTime = ETime, IsSelectStuAbroad = 1, Rb_Group_Id = GroupId });
            delList = oldlist.Where(x => !saList.Select(y => y.Id).Contains(x.ClassId)).ToList();
            if (delList.Any())
            {
                edu_RevenueReportRepository.DeleteBatch(delList);
            }

            foreach (var item in saList) {
                try
                {
                    Console.WriteLine("留学就业：" + item.Name + "|" + item.Id);
                    bool IsNew = false;//是否新增
                    var orderList = orderAllList.Where(x => x.SourceId == item.Id).ToList();
                    var financeList = FAllList.Where(x => x.TCID == item.Id).ToList();
                    var demodel = oldlist.Where(x => x.ClassId == item.Id).FirstOrDefault();
                    if (demodel == null)
                    {
                        IsNew = true;
                        //新增
                        demodel = new RB_Edu_RevenueReport_Extend()
                        {
                            Id = 0,
                            ClassId = item.Id,
                            Rb_Group_Id = GroupId,
                            SchoolId = item.School_Id,
                            SchoolName = item.SchoolName,
                            DateType = item.Type == 1 ? 2 : 3
                        };
                    }
                    #region 初始化数据
                    demodel.ClassBegins = item.CreateTime;
                    demodel.ClassName = item.Name;
                    demodel.ClassState = 0;
                    demodel.CourseId = 0;
                    demodel.CourseName = item.SupplierName;
                    demodel.TeacherId = 0;
                    demodel.TeacherName = item.Type == 1 ? "留学" : "就业";
                    demodel.SchoolId = item.School_Id;
                    demodel.SchoolName = item.SchoolName;
                    #endregion

                    #region 统计数据
                    #region 订单
                    demodel.YingShou = orderList.Sum(x => x.PreferPrice);
                    demodel.ShiShou = orderList.Sum(x => x.Income);
                    demodel.TuiKuan = orderList.Sum(x => x.Refund);
                    demodel.PingTaiShuiJin = orderList.Sum(x => x.PlatformTax);
                    demodel.ZaiTu = 0;//暂时在途未做
                    demodel.YouHui = orderList.Sum(x => x.DiscountMoney);
                    demodel.DaiShou = (demodel.YingShou - demodel.ShiShou + demodel.TuiKuan - demodel.PingTaiShuiJin - demodel.YouHui);
                    demodel.YiShou = -demodel.DaiShou;
                    demodel.GuestNum = orderList.Sum(x => x.GuestNum);
                    #endregion
                    #region 财务单据
                    //排序订单单据
                    var cfinanceList = financeList.Where(x => x.OrderID == 0 && x.Type == WFTempLateClassEnum.IN).ToList();
                    demodel.QTShouRu = cfinanceList.Where(y => y.Is_Cashier == 1).Sum(x => x.Money ?? 0);
                    demodel.QTShouRu -= cfinanceList.Where(x => x.Is_Cashier == 1 && x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                    //支出
                    demodel.TiCheng = orderList.Where(x => x.IsCommissionGive == 1).Sum(x => x.CommissionMoney);//销售提成
                    demodel.ClassFee = 0;//老师提成   -留学暂定
                    demodel.JiXiaoMoney = 0;//绩效提成   -留学暂定

                    var ofinanceList = financeList.Where(x => x.Type == WFTempLateClassEnum.OUT).ToList();// 支出包括退款
                    demodel.QTZhiChu = ofinanceList.Sum(x => x.Money ?? 0);
                    demodel.YingFu = demodel.QTZhiChu + demodel.TiCheng + demodel.ClassFee + demodel.JiXiaoMoney;
                    #endregion

                    demodel.MaoLi = demodel.ShiShou - demodel.YingFu;
                    demodel.ShiJiLiRun = demodel.MaoLi + demodel.QTShouRu;

                    //毛利率
                    if (demodel.ShiShou != 0)
                    {
                        demodel.MaoLiRate = Math.Round(demodel.MaoLi / demodel.ShiShou * 100, 2, MidpointRounding.AwayFromZero);
                    }
                    if (demodel.GuestNum > 0)
                    {
                        //平均收入=实收+自费收入+其他收入+佣金收入（属于佣金的所有）/参团+单团报入
                        demodel.AverageIncome = Math.Round((demodel.ShiShou + demodel.QTShouRu) / demodel.GuestNum, 2, MidpointRounding.AwayFromZero);
                        //平均成本=应付/参团+单团报入
                        demodel.AverageCost = Math.Round((demodel.YingFu / demodel.GuestNum), 2, MidpointRounding.AwayFromZero);
                    }
                    //平均利润=平均收入-平均成本
                    demodel.AverageProfit = demodel.AverageIncome - demodel.AverageCost;
                    #endregion

                    if (IsNew)
                    {
                        edu_RevenueReportRepository.Insert(demodel);
                    }
                    else
                    {
                        edu_RevenueReportRepository.Update(demodel);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("留学就业：" + item.Name + "|" + item.Id + ",错误：" + ex.Message);
                    LogHelper.Write(ex, "SetEduRevenueReport");
                }
            }
            #endregion

            var fumodel = edu_UpdateRecordRepository.GetList(new RB_Report_UpdateRecord() { Type = 1 }).FirstOrDefault();
            if (fumodel != null)
            {
                fumodel.EndDate = DateTime.Now;
                edu_UpdateRecordRepository.Update(fumodel);
            }
            return true;
        }

        /// <summary>
        /// 获取营收报表分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="dmodel"></param>
        /// <returns></returns>
        public List<RB_Edu_RevenueReport_Extend> GetRevenueReportPageList(int pageIndex, int pageSize, out long count, RB_Edu_RevenueReport_Extend dmodel)
        {
            var list = edu_RevenueReportRepository.GetPageList(pageIndex, pageSize, out count, dmodel);
            //统计
            var Statistics = edu_RevenueReportRepository.GetRevenueReportStatistics(dmodel);
            if (count > 0) {
                Statistics.MaoLiRate = Math.Round(Statistics.MaoLiRate / count, 2, MidpointRounding.AwayFromZero);
                Statistics.AverageIncome = Math.Round(Statistics.AverageIncome / count, 2, MidpointRounding.AwayFromZero);
                Statistics.AverageCost = Math.Round(Statistics.AverageCost / count, 2, MidpointRounding.AwayFromZero);
                Statistics.AverageProfit = Math.Round(Statistics.AverageProfit / count, 2, MidpointRounding.AwayFromZero);
            }
            list.Add(Statistics);
            return list;
        }

        /// <summary>
        /// 获取最新记录
        /// </summary>
        /// <returns></returns>
        public RB_Report_UpdateRecord GetUpdateRecordNew()
        {
            return edu_UpdateRecordRepository.GetList(new RB_Report_UpdateRecord() { Type = 1 }).FirstOrDefault();
        }

        /// <summary>
        /// 更新简易报表
        /// </summary>
        /// <param name="GroupId"></param>
        /// <param name="Year"></param>
        /// <returns></returns>
        public bool InsertBatchSimple(int GroupId, int Year)
        {
            edu_UpdateRecordRepository.Insert(new RB_Report_UpdateRecord()
            {
                Type = 2,
                StartDate = DateTime.Now
            });
            try
            {
                string sDate = Year + "-01-01";
                string eDate = DateTime.Now.AddYears(1).AddDays(-1).ToString("yyyy-MM-dd");
                int i = 1;
                string FYLX = "营业总收入,其他收入,待收金额,退款金额,平台税金,优惠金额,营业总成本,营业总毛利,工资,员工提成,社保,员工福利及竞赛奖金,办公用品,差旅费,电话费(通訊費),快递费,物管水电费,房租,广告费,业务招待,税金,平台使用费,電腦系统费,市内交通费,团队建设费,会务费,工会经费,律师费,服务器管理费,汇款手续费,其他,管销费用,利息收入,汇兑损益,财务费用,营业外收入,其他营业支出,营业利润(亏损),所得税费用,净利润(亏损),以下项均不计入计算,股东权益(投资款),股东权益(利润分配),股东权益(员工红利),小计1,预付款(教育),预付款(保证金.押金),小计2,备用金,个人借款,其他代垫代收,陈芳英款项,小计3";
                string RZFYLX = "营业总收入,其他收入,待收金额,退款金额,平台税金,优惠金额,营业总成本,营业总毛利,营业利润(亏损),净利润(亏损)";
                var FYLXList = new List<string>(FYLX.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                var RZFYLXList = new List<string>(RZFYLX.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                //财务单据
                var RZFinancelist = RB_FinanceRepository.GetListForReport(new RB_Finance_Extend() { sAduitDate = DateTime.Parse(sDate), eAduitDate = DateTime.Now.AddYears(1).AddDays(-1), RB_Branch_Id = -1, RB_Group_Id = GroupId, Is_TCID = 1, TCID = -1 });
                //获取资金调拨单据
                var CapitalAllocationFinanceList = RB_FinanceRepository.GetTradeWayForCapitalAllocation(new RB_Finance_Extend() { sAduitDate = DateTime.Parse(sDate), eAduitDate = DateTime.Now.AddYears(1).AddDays(-1), RB_Branch_Id = -1, RB_Group_Id = GroupId, Is_TCID = 1, TCID = -1 });
                //营收报表数据
                var YSBBList = edu_RevenueReportRepository.GetList(new RB_Edu_RevenueReport_Extend() { DateType = 0, StartTime = sDate, EndTime = eDate, Rb_Group_Id = GroupId });
                //历史简易
                var oldlist = edu_simpleReportRepository.GetList(new RB_SimpleReport_Extend() { Year = Year, Rb_Group_Id = GroupId });
                //查询校区
                var schoolList = schoolRepository.GetSchoolListRepository(new Model.ViewModel.User.RB_School_ViewModel() { Group_Id = GroupId });
                List<string> shareList = new List<string>() { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
                foreach (var branchitem in schoolList)
                {
                    var srList = oldlist.Where(x => x.BranchId == branchitem.SId).ToList();
                    edu_simpleReportRepository.DeleteBatch(srList);
                    foreach (var ditem in FYLXList)
                    {
                        RB_SimpleReport ousimpleReport = new RB_SimpleReport();
                        decimal January = 0, February = 0, March = 0, April = 0, May = 0, June = 0, July = 0, August = 0, September = 0, October = 0, November = 0, December = 0;

                        foreach (var item in shareList)
                        {
                            sDate = Convert.ToDateTime(Year + "-" + item + "-01").ToString("yyyy-MM-dd");
                            eDate = DateTime.Parse((Year + "-" + item + "-01")).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
                            #region 营业总收入，佣金收入，待收金额，退款金额，平台税金，联运成本，营业总成本，联运营业额支出
                            decimal YSJE = 0, YYZSR = 0, DSJE = 0, TKJE = 0, PJSJ = 0, YouHui = 0, YYZCB = 0, QTShouRu = 0;



                            var financelist = new List<RB_Finance_Extend>();

                            var NowYSBBList = YSBBList.Where(x => x.SchoolId == branchitem.SId && x.ClassBegins.ToString("yyyy-MM") == Convert.ToDateTime(sDate).ToString("yyyy-MM")).ToList();
                            if (RZFYLXList.Contains(ditem))
                            {
                                YSJE = NowYSBBList.Sum(x => x.YingShou);
                                YYZSR = NowYSBBList.Sum(x => x.ShiShou);
                                TKJE = NowYSBBList.Sum(x => x.TuiKuan);
                                PJSJ = NowYSBBList.Sum(x => x.PingTaiShuiJin);
                                YouHui = NowYSBBList.Sum(x => x.YouHui);
                                //待收金额=应收-已收-凭条税金-在途金额+退款+问题账户；
                                DSJE = YSJE - YYZSR - PJSJ + TKJE - YouHui;
                                YYZCB = NowYSBBList.Sum(x => x.YingFu);
                                QTShouRu = NowYSBBList.Sum(x => x.QTShouRu);
                            }
                            #endregion

                            #region 日常费用类
                            decimal GXFY = 0;//管销费用
                            decimal YYZML = 0;//营业总毛利=(营业总收入+退款总金额-待收金额-平台税金-在途金额(这个是营收报表的实收))-营业总成本（营收报表的应付）+佣金总收入+自费收入-联运成本-旅游意外保险
                            var Financelist = RZFinancelist.Where(x => ((x.Type == WFTempLateClassEnum.OUT && x.CreateDate.Value.ToString("yyyy-MM") == Convert.ToDateTime(sDate).ToString("yyyy-MM")) || (x.Type != WFTempLateClassEnum.OUT && x.TradeDate.Value.ToString("yyyy-MM") == Convert.ToDateTime(sDate).ToString("yyyy-MM"))) && x.RB_Branch_Id == branchitem.SId).ToList();

                            YYZML = NowYSBBList.Sum(x => x.ShiJiLiRun);

                            decimal GZ = 0;//工资
                            decimal YGTC = 0;//员工提成
                            decimal SB = 0;//社保
                            decimal YGFL = 0;//员工福利及竞赛奖金
                            decimal BGYP = 0;//办公用品
                            decimal CLF = 0;//差旅费
                            decimal TEL = 0;//电话费
                            decimal KDF = 0;//快递费
                            decimal WGSDF = 0;//物管水电费
                            decimal FZ = 0;//房租
                            decimal GGF = 0;//广告费
                            decimal YWZD = 0;//业务招待
                            decimal LJZK = 0;//累计折扣
                            decimal Sj = 0;//税金
                            decimal PTSYF = 0;//平台使用费
                            decimal DNSYF = 0;//电脑使用费
                            decimal SNJTF = 0;//市内交通费
                            decimal TJF = 0;//团建费
                            decimal HWF = 0;//会务费
                            decimal GHJF = 0;//工会经费
                            decimal LSF = 0;//律师费
                            decimal FWQGLF = 0;//服务器管理员费
                            decimal HKSXF = 0;//汇款手续费
                            decimal JYQT = 0;//其他
                            decimal LXSR = 0;//利息收入
                            decimal HDSY = 0;//汇兑损益
                            decimal CWFY = 0;//财务费用=利息收入-汇兑损益
                            decimal YYWSR1 = 0;//营业外收入1
                                               //decimal YYWSR2 = 0;//营业外收入2（领队）
                                               //decimal QTYYSR = 0;//其他营业收入
                            decimal YYWSR = 0;//营业外收入=营业外收入+营业外收入1，更正：营业外收入=营业外收入1+营业外收入2（领队）+其他营业收入;
                                              //YYWSR = GetCostIds(44, Financelist, true) + YYWSR1;
                            YYWSR = YYWSR1;//更正：营业外收入=营业外收入1
                            decimal QTYYZC = 0;//其他营业支出
                            decimal YSYF = 0;//应收应付
                                             //decimal YSYFTZ = 0;//应收应付投资
                            decimal YYLRKS = 0;//营业利润亏损=营业总毛利-分摊金额-营业税金及附加-管销费用+财务费用+营业外收入-其他营业支出-应收应付款
                            YYLRKS = YYZML - GXFY + CWFY + YYWSR - QTYYZC - YSYF;
                            decimal SDSFY = 0;//所得税费用
                            decimal JLRKS = 0;//净利润亏损=营业利润+所得税费用，更正：净利润（亏损）=营业利润（亏损）-所得税费用
                            #endregion

                            #region 资金调拨汇兑损益
                            decimal ZJTBHDSYMoney = 0;
                            if (ditem == "汇兑损益" || ditem == "财务费用" || ditem == "营业利润(亏损)" || ditem == "净利润(亏损)")
                            {
                                var calist = CapitalAllocationFinanceList.Where(x => x.AllotDate.Value.ToString("yyyy-MM") == Convert.ToDateTime(sDate).ToString("yyyy-MM") && x.BranchId == branchitem.SId).ToList();
                                //资金调拨的汇兑损益
                                decimal iMoney = calist.Where(x => x.AllotType == 1)?.Sum(x => x.Money ?? 0) ?? 0;
                                decimal oMoney = calist.Where(x => x.AllotType == 2)?.Sum(x => x.Money ?? 0) ?? 0;
                                ZJTBHDSYMoney = oMoney - iMoney;
                            }
                            #endregion
                            #region 赋值
                            decimal Money = 0;
                            if (ditem == "营业总收入")
                            {
                                Money = YSJE;
                            }
                            else if (ditem == "其他收入")
                            {
                                Money = QTShouRu;
                            }
                            else if (ditem == "待收金额")
                            {
                                Money = DSJE;
                            }
                            if (ditem == "平台税金")
                            {
                                Money = PJSJ;
                            }
                            else if (ditem == "退款金额")
                            {
                                Money = TKJE;
                            }
                            else if (ditem == "优惠金额")
                            {
                                Money = YouHui;
                            }
                            else if (ditem == "营业总成本")
                            {
                                Money = YYZCB;
                            }
                            else if (ditem == "营业总毛利")
                            {
                                Money = YYZML;
                            }
                            else if (ditem == "工资")
                            {
                                GZ = GetCostIds(15, Financelist, false, 1, true);
                                Money = GZ;
                            }
                            else if (ditem == "员工提成")
                            {
                                YGTC = GetCostIds(16, Financelist, false, 1, true);
                                Money = YGTC;
                            }
                            else if (ditem == "社保")
                            {
                                SB = GetCostIds(17, Financelist, false, 1, true);
                                Money = SB;
                            }
                            else if (ditem == "员工福利及竞赛奖金")
                            {
                                YGFL = GetCostIds(18, Financelist, false, 1, true);
                                Money = YGFL;
                            }
                            else if (ditem == "办公用品")
                            {
                                BGYP = GetCostIds(19, Financelist, false, 1, true);
                                Money = BGYP;
                            }
                            else if (ditem == "差旅费")
                            {
                                CLF = GetCostIds(20, Financelist, false, 1, true);
                                Money = CLF;
                            }
                            else if (ditem == "电话费(通訊費)")
                            {
                                TEL = GetCostIds(21, Financelist, false, 1, true);
                                Money = TEL;
                            }
                            else if (ditem == "快递费")
                            {
                                KDF = GetCostIds(52, Financelist, false, 1, true);
                                Money = KDF;
                            }
                            else if (ditem == "物管水电费")
                            {
                                WGSDF = GetCostIds(22, Financelist, false, 1, true);
                                Money = WGSDF;
                            }
                            else if (ditem == "房租")
                            {
                                FZ = GetCostIds(23, Financelist, false, 1, true);
                                Money = FZ;
                            }
                            else if (ditem == "广告费")
                            {
                                GGF = GetCostIds(24, Financelist, false, 1, true);
                                Money = GGF;
                            }
                            else if (ditem == "业务招待")
                            {
                                YWZD = GetCostIds(25, Financelist, false, 1, true);
                                Money = YWZD;
                            }
                            else if (ditem == "累计折旧")
                            {
                                LJZK = GetCostIds(26, Financelist, false, 1, true);
                                Money = LJZK;
                            }
                            else if (ditem == "税金")
                            {
                                Sj = GetCostIds(27, Financelist, false, 1, true);
                                Money = Sj;
                            }
                            else if (ditem == "平台使用费")
                            {
                                PTSYF = GetCostIds(28, Financelist, false, 1, true);
                                Money = PTSYF;
                            }
                            else if (ditem == "電腦系统费")
                            {
                                DNSYF = GetCostIds(29, Financelist, false, 1, true);
                                Money = DNSYF;
                            }
                            else if (ditem == "市内交通费")
                            {
                                SNJTF = GetCostIds(30, Financelist, false, 1, true);
                                Money = SNJTF;
                            }
                            else if (ditem == "团队建设费")
                            {
                                TJF = GetCostIds(31, Financelist, false, 1, true);
                                Money = TJF;
                            }
                            else if (ditem == "会务费")
                            {
                                HWF = GetCostIds(32, Financelist, false, 1, true);
                                Money = HWF;
                            }
                            else if (ditem == "工会经费")
                            {
                                GHJF = GetCostIds(34, Financelist, false, 1, true);
                                Money = GHJF;
                            }
                            else if (ditem == "律师费")
                            {
                                LSF = GetCostIds(35, Financelist, false, 1, true);
                                Money = LSF;
                            }
                            else if (ditem == "服务器管理费")
                            {
                                FWQGLF = GetCostIds(36, Financelist, false, 1, true);
                                Money = FWQGLF;
                            }
                            else if (ditem == "汇款手续费")
                            {
                                HKSXF = GetCostIds(41, Financelist, false, 1, true);
                                Money = HKSXF;
                            }
                            else if (ditem == "其他")
                            {
                                JYQT = GetCostIds(51, Financelist, false, 1, true);
                                Money = JYQT;
                            }
                            else if (ditem == "管销费用")
                            {
                                GXFY = GetGXFY(Financelist);
                                Money = GXFY;
                            }
                            else if (ditem == "利息收入")
                            {
                                LXSR = GetCostIds(42, Financelist, false, 1, true);
                                Money = -LXSR;
                            }
                            else if (ditem == "汇兑损益")
                            {
                                HDSY = GetCostIds(43, Financelist, false, 1, true);
                                Money = HDSY + ZJTBHDSYMoney;
                            }
                            else if (ditem == "财务费用")
                            {
                                //财务费用=利息收入-汇兑损益
                                CWFY = -GetCostIds(42, Financelist, false, 1, true) - GetCostIds(43, Financelist, false, 1, true) - ZJTBHDSYMoney;
                                Money = CWFY;
                            }
                            else if (ditem == "营业外收入")
                            {
                                Money = GetCostIds(44, Financelist, true, 1);
                            }
                            else if (ditem == "其他营业支出")
                            {
                                Money = GetCostIds(48, Financelist, false, 1);
                            }
                            else if (ditem == "应收应付款")
                            {
                                //应收应付款=出纳审核过的收款单之和-所有应付款
                                decimal YS = GetCostIds(55, Financelist, true, 1);
                                decimal YF = GetCostIds(56, Financelist, false, 1);
                                Money = YF - YS;
                            }
                            else if (ditem == "营业利润(亏损)")
                            {
                                decimal yywsrMoney = GetCostIds(44, Financelist, true, 1);
                                decimal yywzcMoney = GetCostIds(48, Financelist, false, 1);

                                //营业利润亏损 = 营业总毛利 - 分摊金额 - 管销费用 + 财务费用 + 营业外收入 - 其他营业支出 - 应收应付款(应收-应付)
                                Money = YYZML - GetGXFY(Financelist) + (-GetCostIds(42, Financelist, false, 1, true) - GetCostIds(43, Financelist, false, 1, true)) - ZJTBHDSYMoney + yywsrMoney - yywzcMoney - (GetCostIds(56, Financelist, true, 1) - GetCostIds(55, Financelist, false, 1));
                            }
                            else if (ditem == "所得税费用")
                            {
                                SDSFY = GetCostIds(49, Financelist, false, 1, true);
                                Money = SDSFY;
                            }
                            else if (ditem == "净利润(亏损)")
                            {
                                decimal yywsrMoney = GetCostIds(44, Financelist, true, 1);
                                decimal yywzcMoney = GetCostIds(48, Financelist, false, 1);
                                //净利润亏损=营业利润+所得税费用，更正：净利润（亏损）=营业利润（亏损）-所得税费用
                                JLRKS = YYZML - GetGXFY(Financelist) + (-GetCostIds(42, Financelist, false, 1, true) - GetCostIds(43, Financelist, false, 1, true)) - ZJTBHDSYMoney + yywsrMoney - yywzcMoney - (GetCostIds(56, Financelist, true, 1) - GetCostIds(55, Financelist, false, 1)) - GetCostIds(49, Financelist, false, 1, true);
                                Money = JLRKS;
                            }
                            else if (ditem == "股东权益(投资款)")
                            {
                                //应收应付款=出纳审核过的收款单之和-所有应付款
                                decimal YS = GetCostIds(58, Financelist, true, 1);
                                decimal YF = GetCostIds(59, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "股东权益(利润分配)")
                            {
                                decimal YS = GetCostIds(61, Financelist, true, 1);
                                decimal YF = GetCostIds(62, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "股东权益(员工红利)")
                            {
                                decimal YS = GetCostIds(63, Financelist, true, 1);
                                decimal YF = GetCostIds(64, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "预付款(教育)")
                            {
                                decimal YS = GetCostIds(73, Financelist, true, 1);
                                decimal YF = GetCostIds(74, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "预付款(保证金.押金)")
                            {
                                decimal YS = GetCostIds(75, Financelist, true, 1);
                                decimal YF = GetCostIds(76, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "备用金")
                            {
                                decimal YS = GetCostIds(81, Financelist, true, 1);
                                decimal YF = GetCostIds(82, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "个人借款")
                            {
                                decimal YS = GetCostIds(83, Financelist, true, 1);
                                decimal YF = GetCostIds(84, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "其他代垫代收")
                            {
                                decimal YS = GetCostIds(85, Financelist, true, 1);
                                decimal YF = GetCostIds(86, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "陈芳英款项")
                            {
                                decimal YS = GetCostIds(87, Financelist, true, 1);
                                decimal YF = GetCostIds(88, Financelist, false, 1);
                                Money = YS - YF;
                            }
                            else if (ditem == "小计1")
                            {
                                //投资款
                                decimal YS = GetCostIds(58, Financelist, true, 1);
                                decimal YF = GetCostIds(59, Financelist, false, 1);
                                Money = YS - YF;
                                //利润分配
                                YS = GetCostIds(61, Financelist, true, 1);
                                YF = GetCostIds(62, Financelist, false, 1);
                                Money += YS - YF;
                                //员工红利
                                YS = GetCostIds(63, Financelist, true, 1);
                                YF = GetCostIds(64, Financelist, false, 1);
                                Money += YS - YF;
                            }
                            else if (ditem == "小计2")
                            {
                                //预付款(教育)
                                decimal YS = GetCostIds(73, Financelist, true, 1);
                                decimal YF = GetCostIds(74, Financelist, false, 1);
                                Money += YS - YF;
                                //预付款(保证金.押金)
                                YS = GetCostIds(75, Financelist, true, 1);
                                YF = GetCostIds(76, Financelist, false, 1);
                                Money += YS - YF;
                            }
                            else if (ditem == "小计3")
                            {
                                //备用金
                                decimal YS = GetCostIds(81, Financelist, true, 1);
                                decimal YF = GetCostIds(82, Financelist, false, 1);
                                Money = YS - YF;
                                //个人借款
                                YS = GetCostIds(83, Financelist, true, 1);
                                YF = GetCostIds(84, Financelist, false, 1);
                                Money += YS - YF;
                                //其他代垫代收
                                YS = GetCostIds(85, Financelist, true, 1);
                                YF = GetCostIds(86, Financelist, false, 1);
                                Money += YS - YF;
                                //陈芳英款项
                                YS = GetCostIds(87, Financelist, true, 1);
                                YF = GetCostIds(88, Financelist, false, 1);
                                Money += YS - YF;
                            }
                            else if (ditem == "以下项均不计入计算")
                            {
                                Money = 0;
                            }

                            if (item == "01")
                            {
                                January = Money;
                            }
                            else if (item == "02")
                            {
                                February = Money;
                            }
                            else if (item == "03")
                            {
                                March = Money;
                            }
                            else if (item == "04")
                            {
                                April = Money;
                            }
                            else if (item == "05")
                            {
                                May = Money;
                            }
                            else if (item == "06")
                            {
                                June = Money;
                            }
                            else if (item == "07")
                            {
                                July = Money;
                            }
                            else if (item == "08")
                            {
                                August = Money;
                            }
                            else if (item == "09")
                            {
                                September = Money;
                            }
                            else if (item == "10")
                            {
                                October = Money;
                            }
                            else if (item == "11")
                            {
                                November = Money;
                            }
                            else if (item == "12")
                            {
                                December = Money;
                            }

                            #endregion

                            Console.WriteLine(branchitem.SName + "：" + Year + "年" + item + "月" + "费用名称：" + ditem + "金额：" + Money);
                        }

                        var simpleReport = new RB_SimpleReport()
                        {
                            Year = Year,
                            Abstract = ditem,
                            January = January,
                            February = February,
                            March = March,
                            FirstQuarter = January + February + March,
                            April = April,
                            May = May,
                            June = June,
                            SecondQuarter = April + May + June,
                            HalfReport = January + February + March + April + May + June,
                            July = July,
                            August = August,
                            September = September,
                            ThirdQuarter = July + August + September,
                            October = October,
                            November = November,
                            December = December,
                            FourthQuarter = October + November + December,
                            LastHalfReport = July + August + September + October + November + December,
                            Total = January + February + March + April + May + June + July + August + September + October + November + December,
                            Sort = i,
                            Rb_Group_Id = GroupId,
                            BranchId = branchitem.SId
                        };
                        i++;
                        edu_simpleReportRepository.Insert(simpleReport);
                    }
                }

                int j = 1;
                var oldALLlist = edu_simpleReportRepository.GetList(new RB_SimpleReport_Extend() { Year = Year, Rb_Group_Id = GroupId, BranchId = -1 });
                edu_simpleReportRepository.DeleteBatch(oldALLlist);
                foreach (var FYLXitem in FYLXList)
                {
                    //汇总
                    var simpleReportList = edu_simpleReportRepository.GetList(new RB_SimpleReport_Extend() { Year = Year, Abstract = FYLXitem, Rb_Group_Id = GroupId }).Where(x => x.BranchId > -1).ToList();
                    var simpleReport = new RB_SimpleReport
                    {
                        Year = Year,
                        Abstract = FYLXitem.ToString(),
                        January = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.January.Value),
                        February = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.February.Value),
                        March = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.March.Value),
                        FirstQuarter = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.FirstQuarter.Value),
                        April = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.April.Value),
                        May = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.May.Value),
                        June = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.June.Value),
                        SecondQuarter = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.SecondQuarter.Value),
                        HalfReport = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.HalfReport.Value),
                        July = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.July.Value),
                        August = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.August.Value),
                        September = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.September.Value),
                        ThirdQuarter = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.ThirdQuarter.Value),
                        October = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.October.Value),
                        November = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.November.Value),
                        December = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.December.Value),
                        FourthQuarter = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.FourthQuarter.Value),
                        LastHalfReport = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.LastHalfReport.Value),
                        Total = simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.Total.Value),
                        Sort = j,
                        Rb_Group_Id = GroupId,
                        BranchId = -1
                    };
                    j++;
                    Console.WriteLine("总计：" + FYLXitem + "金额：" + simpleReportList.Where(x => x.Abstract == FYLXitem.ToString()).Sum(x => x.January.Value));
                    edu_simpleReportRepository.Insert(simpleReport);
                }

                var fumodel = edu_UpdateRecordRepository.GetList(new RB_Report_UpdateRecord() { Type = 2 }).FirstOrDefault();
                if (fumodel != null)
                {
                    fumodel.EndDate = DateTime.Now;
                    edu_UpdateRecordRepository.Update(fumodel);
                }
                return true;

            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "InsertBatchSimple");
            }
            return true;
        }


        /// <summary>
        /// 获取简易报表列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<RB_SimpleReport_Extend> GetEasyReportList(RB_SimpleReport_Extend model)
        {
            var list = edu_simpleReportRepository.GetList(model);
            var clist = costtypeRepository.GetList(new RB_Costtype_Extend() { RB_Group_Id = model.Rb_Group_Id });
            foreach (var item in list)
            {
                if (item.Abstract == "工资")
                {
                    item.CostIds = GetCostIds((int)CostEnum.GZ, clist);
                }
                else if (item.Abstract == "旅游意外保险")
                {
                    item.CostIds = GetCostIds((int)CostEnum.YWX, clist);
                }
                else if (item.Abstract == "员工提成")
                {
                    item.CostIds = GetCostIds((int)CostEnum.YGTC, clist);
                }
                else if (item.Abstract == "社保")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.SB), clist);
                }
                else if (item.Abstract == "员工福利及竞赛奖金")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YGFL), clist);
                }
                else if (item.Abstract == "办公用品")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.BGYP), clist);
                }
                else if (item.Abstract == "差旅费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.CLF), clist);
                }
                else if (item.Abstract == "电话费(通訊費)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.DH), clist);
                }
                else if (item.Abstract == "快递费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.KDF), clist);
                }
                else if (item.Abstract == "物管水电费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.WGSDF), clist);
                }
                else if (item.Abstract == "房租")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.FZ), clist);
                }
                else if (item.Abstract == "广告费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.GGF), clist);
                }
                else if (item.Abstract == "业务招待")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YWZDF), clist);
                }
                else if (item.Abstract == "累计折扣")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.LJZK), clist);
                }
                else if (item.Abstract == "税金")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.SJ), clist);
                }
                else if (item.Abstract == "平台使用费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.PTSYF), clist);
                }
                else if (item.Abstract == "電腦系统费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.DNXTF), clist);
                }
                else if (item.Abstract == "市内交通费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.SNJTF), clist);
                }
                else if (item.Abstract == "团队建设费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.TDJSF), clist);
                }
                else if (item.Abstract == "会务费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.HWF), clist);
                }
                else if (item.Abstract == "同行返利")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.THFL), clist);
                }
                else if (item.Abstract == "工会经费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.GFJF), clist);
                }
                else if (item.Abstract == "律师费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.LSF), clist);
                }
                else if (item.Abstract == "服务器管理费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.FWQGLF), clist);
                }
                else if (item.Abstract == "汇款手续费")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.HKSXF), clist);
                }
                else if (item.Abstract == "代收代付(导游佣金)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.DYYJ), clist);
                }
                else if (item.Abstract == "代收代付(领队佣金)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.LDYJ), clist);
                }
                else if (item.Abstract == "航空公司保证金（会退）")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.HKBZJ), clist);
                }
                else if (item.Abstract == "航空公司大订金（会抵扣）")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.HKDDJ), clist);
                }
                else if (item.Abstract == "其他")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.JYBBQT), clist);
                }
                else if (item.Abstract == "利息收入")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.LXSR), clist);
                }
                else if (item.Abstract == "汇兑损益")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.HDSY), clist);
                }
                else if (item.Abstract == "营业外收入")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YYWSR), clist);
                }
                else if (item.Abstract == "其他营业支出")
                {
                    item.CostIds = GetCostIds(48, clist);
                }
                else if (item.Abstract == "居间佣金")
                {
                    item.CostIds = GetCostIds((int)CostEnum.JJYJ, clist);
                }
                else if (item.Abstract == "应收应付款")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YSYFK), clist);
                }
                else if (item.Abstract == "股东权益(投资款)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YSYFKTZ), clist);
                }
                else if (item.Abstract == "股东权益(利润分配)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.GZLRFP), clist);
                }
                else if (item.Abstract == "股东权益(员工红利)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.GZYGHL), clist);
                }
                else if (item.Abstract == "预付款(教育)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YFKCZ), clist);
                }
                else if (item.Abstract == "预付款(保证金.押金)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.YFKBZJYJ), clist);
                }
                else if (item.Abstract == "代收代付(领队.导游保证金)")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.LDDYBZJ), clist);
                }
                else if (item.Abstract == "备用金")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.BYJ), clist);
                }
                else if (item.Abstract == "个人借款")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.GRJD), clist);
                }
                else if (item.Abstract == "其他代垫代收")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.QTDDDF), clist);
                }
                else if (item.Abstract == "陈芳英款项")
                {
                    item.CostIds = GetCostIds(((int)CostEnum.CYFKX), clist);
                }
            }
            return list;
        }


        /// <summary>
        /// 获取管销费用
        /// </summary>
        /// <param name="financeList"></param>
        /// <returns></returns>
        public decimal GetGXFY(List<RB_Finance_Extend> Financelist)
        {
            decimal GXFY = 0;
            GXFY += GetCostIds(50, Financelist, false, 1, true);
            GXFY += GetCostIds(15, Financelist, false, 1, true);
            GXFY += GetCostIds(16, Financelist, false, 1, true);
            GXFY += GetCostIds(17, Financelist, false, 1, true);
            GXFY += GetCostIds(18, Financelist, false, 1, true);
            GXFY += GetCostIds(19, Financelist, false, 1, true);
            GXFY += GetCostIds(20, Financelist, false, 1, true);
            GXFY += GetCostIds(21, Financelist, false, 1, true);
            GXFY += GetCostIds(22, Financelist, false, 1, true);
            GXFY += GetCostIds(23, Financelist, false, 1, true);
            GXFY += GetCostIds(52, Financelist, false, 1, true);
            GXFY += GetCostIds(24, Financelist, false, 1, true);
            GXFY += GetCostIds(25, Financelist, false, 1, true);
            GXFY += GetCostIds(26, Financelist, false, 1, true);
            GXFY += GetCostIds(27, Financelist, false, 1, true);
            GXFY += GetCostIds(28, Financelist, false, 1, true);
            GXFY += GetCostIds(29, Financelist, false, 1, true);
            GXFY += GetCostIds(30, Financelist, false, 1, true);
            GXFY += GetCostIds(31, Financelist, false, 1, true);
            GXFY += GetCostIds(32, Financelist, false, 1, true);
            GXFY += GetCostIds(33, Financelist, false, 1, true);
            GXFY += GetCostIds(34, Financelist, false, 1, true);
            GXFY += GetCostIds(35, Financelist, false, 1, true);
            GXFY += GetCostIds(36, Financelist, false, 1, true);
            GXFY += GetCostIds(41, Financelist, false, 1, true);
            GXFY += GetCostIds(39, Financelist, false, 1, true);
            GXFY += GetCostIds(40, Financelist, false, 1, true);
            GXFY += GetCostIds(51, Financelist, false, 1, true);
            return GXFY;
        }

        public decimal GetCostIds(int Type, List<RB_Finance_Extend> NewfinanceList, bool flag = false, int count = 0, bool IsRCSZ = false)
        {
            string ids = string.Empty;
            decimal Money = 0, Fee = 0;
            if (NewfinanceList != null && NewfinanceList.Count() > 0)
            {
                //var costList = costtypeRepository.GetList();
                switch (Type)
                {
                    //佣金收入
                    case 1:
                        NewfinanceList = NewfinanceList.Where(z => (z.Name.Contains("乳胶") || z.Name.Contains("御宝") || z.Name.Contains("乐天") || z.Name.Contains("茶道") || z.Name.Contains("高岛屋") || z.Name.Contains("TOKIS") || z.Name.Contains("电器LAOX") || z.Name.Contains("机场免税店") || z.Name.Contains("永山免税店") || z.Name.Contains("公社免税店") || z.Name.Contains("电器AKKYONE") || z.Name.Contains("橡胶店") || z.Name.Contains("琅勃拉邦古丝绸") || z.Name.Contains("老挝万象金沉香") || z.Name.Contains("老挝万象东盟珠宝") || z.Name.Contains("琅勃拉邦皇家乳胶") || z.Name.Contains("老挝土产") || z.Name.Contains("老挝红木") || z.Name.Contains("琅勃拉邦风情园") || z.Name.Contains("锅具") || z.Name.Contains("琅勃拉邦银寨") || z.Name.Contains("琅勃拉邦咖啡庄园") || z.Name.Contains("金占巴百草园")) && z.Type == WFTempLateClassEnum.IN).ToList();
                        break;
                    //自费收入
                    case 2:
                        NewfinanceList = NewfinanceList.Where(z => (z.Name.Contains("自费") || z.Name.Contains("自费收支结算")) && z.Type == WFTempLateClassEnum.IN).ToList();
                        break;
                    //其他收入
                    case -1:
                        var NoOtherList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && (z.Name.Contains("团费") || z.Name.Contains("小费") || z.Name.Contains("地接费（结算）") || z.Name.Contains("自费") || z.Name.Contains("自费收支结算") || z.Name.Contains("乳胶") || z.Name.Contains("御宝") || z.Name.Contains("御宝（珠宝店）") || z.Name.Contains("乐天") || z.Name.Contains("茶道") || z.Name.Contains("高岛屋") || z.Name.Contains("TOKIS") || z.Name.Contains("电器LAOX") || z.Name.Contains("机场免税店") || z.Name.Contains("永山免税店") || z.Name.Contains("公社免税店") || z.Name.Contains("电器AKKYONE") || z.Name.Contains("橡胶店") || z.Name.Contains("琅勃拉邦古丝绸") || z.Name.Contains("老挝万象金沉香") || z.Name.Contains("老挝万象东盟珠宝") || z.Name.Contains("琅勃拉邦皇家乳胶") || z.Name.Contains("老挝土产") || z.Name.Contains("老挝红木") || z.Name.Contains("琅勃拉邦风情园") || z.Name.Contains("锅具") || z.Name.Contains("琅勃拉邦银寨") || z.Name.Contains("琅勃拉邦咖啡庄园") || z.Name.Contains("金占巴百草园"))).ToList();
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && !NoOtherList.Select(x => x.FrID).Contains(z.FrID)).ToList();
                        break;
                    //小费收入
                    case 3:
                        var xflist = NewfinanceList.Where(z => z.Name.Contains("小费") && z.Type == WFTempLateClassEnum.IN).ToList();
                        NewfinanceList = NewfinanceList.Where(x => xflist.Select(z => z.FrID).Contains(x.FrID)).ToList();
                        break;
                    //佣金+小费+自费
                    case 4:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && (z.Name.Contains("地接收入") || z.Name.Contains("小费") || z.Name.Contains("自费"))).ToList();
                        break;
                    //邀请函、名单表
                    case 5:
                        NewfinanceList = NewfinanceList.Where(z => (z.Name.Contains("邀请函") || z.Name.Contains("名单表")) && z.Type == WFTempLateClassEnum.OUT).ToList();
                        break;
                    //车资
                    case 6:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("车资") && z.Type == WFTempLateClassEnum.OUT).ToList(); break;
                    //国内联运机票
                    case 7:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("国内联运") && z.Type == WFTempLateClassEnum.OUT).ToList(); break;
                    //签证
                    case 8:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("签证") && z.Type == WFTempLateClassEnum.OUT).ToList(); break;
                    //其他支出
                    case 9:
                        //同时排除取消退款那种情况
                        var dellist = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("取消退款")).ToList();
                        if (dellist != null && dellist.Count() > 0)
                        {
                            List<int> FrIdList = dellist.Select(x => x.FrID).ToList();
                            foreach (var item in FrIdList)
                            {
                                var delClist = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("国际段机票") && z.FrID == item).ToList();
                                if (delClist != null && delClist.Count() > 0)
                                {
                                    //说明这个是属于机票的取消
                                    NewfinanceList = NewfinanceList.Where(z => z.FrID != item).ToList();
                                }
                            }
                        }
                        NewfinanceList = NewfinanceList.Where(z =>
                        (
                        z.Type == WFTempLateClassEnum.OUT && (!z.Name.Contains("邀请函") && !z.Name.Contains("名单表") && !z.Name.Contains("车资") && !z.Name.Contains("国际段机票") && !z.Name.Contains("机票罚金") && !z.Name.Contains("机票税金") && !z.Name.Contains("机票定金") && !z.Name.Contains("机票退税") && !z.Name.Contains("国际内陆段机票") && !z.Name.Contains("延时费") && !z.Name.Contains("国内联运") && !z.Name.Contains("签证") && !z.Name.Contains("地接费（领取）") && !z.Name.Contains("地接费（结算）") && !z.Name.Contains("赔偿") && !z.Name.Contains("领队佣金") && !z.Name.Contains("领队奖励金") && !z.Name.Contains("导游佣金") && !z.Name.Contains("旅游责任险") && !z.Name.Contains("保险费")))
                        ).ToList();
                        break;
                    //地接款支出  2019-04-24  ld   徐总需求  小于0的表示收入
                    case 10:
                        NewfinanceList.Where(z => z.Name.Contains("地接费（结算）")).ToList().ForEach(z =>
                        {
                            //判断  如果是负数的地接费结算  表示是收入
                            if (z.Type == WFTempLateClassEnum.OUT && (z.Money ?? 0) < 0)
                            {
                                z.Type = WFTempLateClassEnum.IN;
                                z.Money = 0 - z.Money;
                                z.PayMoney = 0 - (z.PayMoney ?? 0);
                                z.Fee = 0 - (z.Fee ?? 0);
                            }
                        });
                        NewfinanceList = NewfinanceList.Where(z => (z.Name.Contains("地接费（领取）") || z.Name.Contains("地接费（结算）")) && z.Type == WFTempLateClassEnum.OUT).ToList(); break;
                    //地接款收入   2019-04-24  ld   徐总需求  小于0的表示收入
                    case 11:
                        NewfinanceList.Where(z => z.Name.Contains("地接费（结算）")).ToList().ForEach(z =>
                        {
                            //判断  如果是负数的地接费结算  表示是收入
                            if (z.Type == WFTempLateClassEnum.OUT && (z.Money ?? 0) < 0)
                            {
                                z.Type = WFTempLateClassEnum.IN;
                                z.Money = 0 - z.Money;
                                z.PayMoney = 0 - (z.PayMoney ?? 0);
                                z.Fee = 0 - (z.Fee ?? 0);
                            }
                        });
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("地接费（结算）") && z.Type == WFTempLateClassEnum.IN).ToList(); break;
                    //小费收入
                    case 12:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("小费") && z.Type == WFTempLateClassEnum.IN).ToList(); break;
                    //自费收入
                    case 13:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("自费") && z.Type == WFTempLateClassEnum.IN).ToList(); break;
                    //简易报表
                    //意外险
                    case 14:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("旅游责任险") || z.Name.Contains("保险费")).ToList(); break;
                    //工资
                    case 15:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("工资") && !z.Name.Contains("员工工资(还款)")).ToList(); break;
                    //业务提成
                    case 16:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("业务提成（签证）") || z.Name.Contains("业务提成（地接）") || z.Name.Contains("业务提成（票务）") || z.Name.Contains("人头奖励（销售）")).ToList(); break;
                    //社保
                    case 17:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("社会保障费")).ToList(); break;
                    //员工福利及竞赛奖金
                    case 18:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("福利及奖金")).ToList(); break;
                    //办公用品
                    case 19:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("办公用品")).ToList(); break;
                    //差旅费
                    case 20:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("差旅费")).ToList(); break;
                    //电话费(通訊費)
                    case 21:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("电话费") || z.Name.Contains("通讯费")).ToList(); break;
                    //物管水电费
                    case 22:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("物管水电费")).ToList(); break;
                    //房租
                    case 23:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("房租")).ToList(); break;
                    //广告费
                    case 24:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("广告费")).ToList(); break;
                    //业务招待
                    case 25:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("业务招待")).ToList(); break;
                    //累计折旧
                    case 26:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("累计折旧")).ToList(); break;
                    //税金
                    case 27:
                        NewfinanceList = NewfinanceList.Where(z => z.Name == "税金").ToList(); break;
                    //平台使用费
                    case 28:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("平台使用费")).ToList(); break;
                    //電腦系统费
                    case 29:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("電腦系统费") || z.Name.Contains("系统使用费")).ToList(); break;
                    //市内交通费
                    case 30:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("市内交通费")).ToList(); break;
                    //团队建设费
                    case 31:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("团队建设费")).ToList(); break;
                    //会务费
                    case 32:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("会务费")).ToList(); break;
                    //同行返利
                    case 33:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("同行返利") || z.Name.Contains("平台大红包返款") || z.Name.Contains("平台佣金")).ToList(); break;
                    //工会经费
                    case 34:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("工会经费")).ToList(); break;
                    //律师费
                    case 35:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("律师费")).ToList(); break;
                    //服务器管理费
                    case 36:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("服务器管理费")).ToList(); break;
                    //导游佣金
                    case 37:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("导游佣金")).ToList(); break;
                    //领队佣金
                    case 38:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("领队佣金") || z.Name.Contains("领队奖励金")).ToList(); break;
                    //航空公司保证金（会退）
                    case 39:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("航空公司保证金（会退）")).ToList(); break;
                    //航空公司大订金（会抵扣）
                    case 40:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("航空公司大订金（会抵扣）")).ToList(); break;
                    //汇款手续费
                    case 41:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("付款手续费") || z.Name.Contains("刷卡手续费") || z.Name.Contains("转账手续费")).ToList(); break;
                    //利息收入
                    case 42:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("利息收入")).ToList(); break;
                    //汇兑损益
                    case 43:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("汇兑损益")).ToList(); break;
                    //营业外收入
                    case 44:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("营业外收入") || z.Name.Contains("商品收入") || z.Name.Contains("运费收入") || z.Name.Contains("司导保险收入")).ToList(); break;
                    //其他营业支出
                    case 48:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("其他营业支出") || z.Name.Contains("退换货费用") || z.Name.Contains("采购成本") || z.Name.Contains("商品退款") || z.Name.Contains("税费") || z.Name.Contains("司导保险成本") || z.Name.Contains("采购退回") || z.Name.Contains("溢收款退款")).ToList(); break;
                    //所得税费用
                    case 49:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("所得税费用")).ToList(); break;
                    //营业税金
                    case 50:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("营业税金及附加")).ToList(); break;
                    //简易报表其他
                    case 51://&& !z.Name.Contains("营业外收入")
                        NewfinanceList = NewfinanceList.Where(z => !z.Name.Contains("所得税费用")
                        && !z.Name.Contains("其他营业支出")
                        && !z.Name.Contains("营业外收入")
                        && !z.Name.Contains("应付款")
                        && !z.Name.Contains("应收款")
                        && !z.Name.Contains("汇兑损益")
                        && !z.Name.Contains("利息收入")
                        && (!z.Name.Contains("付款手续费") && !z.Name.Contains("刷卡手续费") && !z.Name.Contains("转账手续费"))
                        && !z.Name.Contains("航空公司大订金（会抵扣）")
                        && !z.Name.Contains("航空公司保证金（会退）")
                        && !z.Name.Contains("领队佣金")
                        && !z.Name.Contains("领队奖励金")
                        && !z.Name.Contains("导游佣金")
                        && !z.Name.Contains("服务器管理费")
                        && !z.Name.Contains("律师费")
                        && !z.Name.Contains("工会经费")
                        && !z.Name.Contains("同行返利")
                        && !z.Name.Contains("平台大红包返款")
                        && !z.Name.Contains("会务费")
                        && !z.Name.Contains("团队建设费")
                        && !z.Name.Contains("市内交通费")
                        && !z.Name.Contains("電腦系统费")
                        && !z.Name.Contains("系统使用费")
                        && !z.Name.Contains("系统费")
                        && !z.Name.Contains("平台使用费")
                        && z.Name != "税金"
                        && !z.Name.Contains("累计折旧")
                        && !z.Name.Contains("业务招待")
                        && !z.Name.Contains("累计折旧")
                        && !z.Name.Contains("广告费")
                        && !z.Name.Contains("房租")
                        && !z.Name.Contains("物管水电费")
                        && !z.Name.Contains("电话费")
                        && !z.Name.Contains("通讯费")
                        && !z.Name.Contains("差旅费")
                        && !z.Name.Contains("办公用品")
                        && !z.Name.Contains("福利及奖金")
                        && !z.Name.Contains("社会保障费")
                        && !z.Name.Contains("业务提成")
                        && !z.Name.Contains("人头奖励")
                        && !z.Name.Contains("工资")
                        && !z.Name.Contains("旅游责任险")
                        && !z.Name.Contains("保险费")
                        && !z.Name.Contains("营业税金及附加")
                        && z.Type != WFTempLateClassEnum.ShouldIncome
                        && z.Type != WFTempLateClassEnum.ShouldPay
                        && !z.Name.Contains("投资款")
                        && !z.Name.Contains("利润分配")
                        && !z.Name.Contains("员工红利")
                        && !z.Name.Contains("酒店预付款")
                        && !z.Name.Contains("CHI包房")
                        && !z.Name.Contains("预付环球门票")
                        && !z.Name.Contains("门票预付款")
                        && !z.Name.Contains("餐厅预付款")
                        && !z.Name.Contains("车资预付款")
                        && !z.Name.Contains("机票预付款")
                        && !z.Name.Contains("电商预付款")
                        && !z.Name.Contains("保证金")
                        && !z.Name.Contains("其他保证金")
                        && !z.Name.Contains("机票保证金")
                        && !z.Name.Contains("押金")
                        && !z.Name.Contains("员工工资(还款)")
                        && !z.Name.Contains("挂账单冲抵")
                        && !z.Name.Contains("机票收入")
                        && !z.Name.Contains("快递费")
                        && !z.Name.Contains("照片服务费")
                        && !z.Name.Contains("地接OP备用金")
                        && !z.Name.Contains("领队罚金")
                        && !z.Name.Contains("景点门票")
                        && !z.Name.Contains("用房手配费")
                        && !z.Name.Contains("餐厅手配费")
                        && !z.Name.Contains("景点门票手配费")
                        && !z.Name.Contains("平台佣金")
                        && !z.Name.Contains("居间佣金")
                        && !z.Name.Contains("商品收入")
                        && !z.Name.Contains("运费收入")
                        && !z.Name.Contains("退换货费用")
                        && !z.Name.Contains("采购成本")
                        && !z.Name.Contains("运杂费")
                        && !z.Name.Contains("商品退款")
                        && !z.Name.Contains("电商存货")
                        && !z.Name.Contains("采购退回")
                        && !z.Name.Contains("溢收款退款")
                        && !z.Name.Contains("税费")
                        && !z.Name.Contains("司导保险收入")
                        && !z.Name.Contains("司导保险成本")
                        && !z.Name.Contains("备用金")
                        && !z.Name.Contains("个人借款")
                        && !z.Name.Contains("其他代垫代收")
                        && !z.Name.Contains("陈芳英款项")
                        ).ToList();
                        break;
                    //管销费用
                    case 57:
                        NewfinanceList = NewfinanceList.Where(z => (!z.Name.Contains("所得税费用")
                        && !z.Name.Contains("其他营业支出")
                        && !z.Name.Contains("营业外收入")
                        && !z.Name.Contains("应付款")
                        && !z.Name.Contains("应收款")
                        && !z.Name.Contains("汇兑损益")
                        && !z.Name.Contains("利息收入")
                        && !z.Name.Contains("旅游责任险")
                        && !z.Name.Contains("保险费")
                        && z.Type != WFTempLateClassEnum.ShouldIncome
                        && z.Type != WFTempLateClassEnum.ShouldPay
                        && !z.Name.Contains("投资款")
                        && !z.Name.Contains("利润分配")
                        && !z.Name.Contains("领队保证金")
                        && !z.Name.Contains("导游保证金")
                        && !z.Name.Contains("员工红利")
                        && !z.Name.Contains("平台保证金")
                        && !z.Name.Contains("其他保证金")
                        && !z.Name.Contains("挂账单冲抵")
                        && !z.Name.Contains("押金")) || (z.Name.Contains("快递费"))).ToList(); break;
                    //快递费
                    case 52:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("快递费") || z.Name.Contains("运杂费")).ToList(); break;
                    ////营业总成本
                    //case 53:
                    //    NewfinanceList =NewfinanceList.Where(z => z.Name.Contains("邀请函") || z.Name.Contains("名单表") || z.Name.Contains("车资") || z.Name.Contains("签证") || z.Name.Contains("地接费（领取）") || z.Name.Contains("地接费（结算）")).ToList();
                    //    break;
                    //赔偿
                    case 54:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("赔偿")).ToList();
                        break;
                    //应收款
                    case 55:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.ShouldIncome).ToList(); break;
                    //应付款
                    case 56:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.ShouldPay).ToList(); break;
                    //应收款投资
                    case 58:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("投资款")).ToList(); break;
                    //应付款投资
                    case 59:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("投资款")).ToList(); break;
                    //收入利润分配
                    case 61:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("利润分配")).ToList(); break;
                    //支出利润分配
                    case 62:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("利润分配")).ToList(); break;
                    //收入员工红利
                    case 63:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("员工红利")).ToList(); break;
                    //支出员工红利
                    case 64:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("员工红利")).ToList(); break;
                    //收入预付款
                    case 73:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("预付款")).ToList(); break;
                    //支出预付款
                    case 74:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("预付款")).ToList(); break;
                    //收入保证金.押金预付款
                    case 75:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && (z.Name.Contains("平台保证金") || z.Name.Contains("押金") || z.Name.Contains("机票保证金") || z.Name.Contains("其他保证金"))).ToList(); break;
                    //支出保证金.押金预付款
                    case 76:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && (z.Name.Contains("平台保证金") || z.Name.Contains("押金") || z.Name.Contains("机票保证金") || z.Name.Contains("其他保证金"))).ToList(); break;
                    case 79://日本印象  手配费
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("用房手配费") && z.Name.Contains("餐厅手配费") && z.Name.Contains("景点门票手配费")).ToList(); break;
                    //电商居间佣金
                    case 80:
                        NewfinanceList = NewfinanceList.Where(z => z.Name.Contains("居间佣金")).ToList(); break;
                    //备用金
                    case 81:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("备用金")).ToList(); break;
                    //备用金
                    case 82:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("备用金")).ToList(); break;
                    //个人借款
                    case 83:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("个人借款")).ToList(); break;
                    //个人借款
                    case 84:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("个人借款")).ToList(); break;
                    //其他代垫代收
                    case 85:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("其他代垫代收")).ToList(); break;
                    //其他代垫代收
                    case 86:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("其他代垫代收")).ToList(); break;
                    //陈芳英款项
                    case 87:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.IN && z.Name.Contains("陈芳英款项")).ToList(); break;
                    //陈芳英款项
                    case 88:
                        NewfinanceList = NewfinanceList.Where(z => z.Type == WFTempLateClassEnum.OUT && z.Name.Contains("陈芳英款项")).ToList(); break;
                }
                if (NewfinanceList != null && NewfinanceList.Count() > 0)
                {
                    if (IsRCSZ)
                    {
                        Money = NewfinanceList.Where(y => y.Type == WFTempLateClassEnum.IN).Sum(x => x.Money.Value);
                        Fee = NewfinanceList.Where(x => x.Type == WFTempLateClassEnum.IN && x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                        Money = Money - Fee;
                        Money = NewfinanceList.Where(y => y.Type == WFTempLateClassEnum.OUT).Sum(x => x.Money.Value) - Money;
                    }
                    else
                    {
                        if (Type == 9)
                        {
                            if (flag)
                            {
                                //收
                                Money = NewfinanceList.Where(y => y.Type == WFTempLateClassEnum.IN && y.Is_Cashier == 1).Sum(x => x.Money.Value);
                                Fee = NewfinanceList.Where(x => x.Type == WFTempLateClassEnum.IN && x.Is_Cashier == 1 && x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                                Money = Money - Fee;
                                //支
                                Money = NewfinanceList.Where(y => y.Type == WFTempLateClassEnum.OUT && y.Is_Cashier == 1).Sum(x => x.Money.Value) - Money;
                            }
                            else
                            {
                                Money = NewfinanceList.Where(y => y.Type == WFTempLateClassEnum.IN).Sum(x => x.Money.Value);
                                Fee = NewfinanceList.Where(x => x.Type == WFTempLateClassEnum.IN && x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                                Money = Money - Fee;
                                Money = NewfinanceList.Where(y => y.Type == WFTempLateClassEnum.OUT).Sum(x => x.Money.Value) - Money;
                            }
                        }
                        else if (Type == 66 || Type == 68 || Type == 70 || Type == 72 || Type == 74)
                        {
                            //预付款 冲抵
                            Money = NewfinanceList.Sum(x => x.Money.Value);
                            Fee = NewfinanceList.Where(x => x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                            Money = Money - Fee;
                            var MatchList = NewfinanceList.Where(x => x.MatchMoney > 0).ToList();
                            if (MatchList.Count() > 0)
                            {
                                //减去冲抵的金额
                                var newFList = MatchList.Select(x => x.FrID).Distinct().ToList();
                                decimal DelMoney = 0;
                                foreach (var item in newFList)
                                {
                                    DelMoney += MatchList.Where(x => x.FrID == item).FirstOrDefault()?.MatchMoney ?? 0;
                                }
                                Money = Money - DelMoney;
                            }
                        }
                        else
                        {
                            if (flag)
                            {
                                Money = NewfinanceList.Where(y => y.Is_Cashier == 1).Sum(x => x.Money.Value);
                                Fee = NewfinanceList.Where(x => x.Is_Cashier == 1 && x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                                Money = Money - Fee;
                            }
                            else
                            {
                                Money = NewfinanceList.Sum(x => x.Money.Value);
                                Fee = NewfinanceList.Where(x => x.Fee > 0).GroupBy(x => new { x.FrID, x.Fee }).Sum(x => x.Key.Fee ?? 0);
                                Money = Money - Fee;
                            }
                        }
                    }
                }
            }
            return Money;
        }

        public string GetCostIds(int Type, List<RB_Costtype_Extend> costList)
        {
            string ids = string.Empty;
            switch (Type)
            {
                //佣金收入
                case 1:
                    ids = string.Join(",", costList.Where(z => (z.Name.Contains("乳胶") || z.Name.Contains("御宝") || z.Name.Contains("乐天") || z.Name.Contains("茶道") || z.Name.Contains("高岛屋") || z.Name.Contains("TOKIS") || z.Name.Contains("电器LAOX") || z.Name.Contains("机场免税店") || z.Name.Contains("永山免税店") || z.Name.Contains("公社免税店") || z.Name.Contains("电器AKKYONE") || z.Name.Contains("橡胶店") || z.Name.Contains("琅勃拉邦古丝绸") || z.Name.Contains("老挝万象金沉香") || z.Name.Contains("老挝万象东盟珠宝") || z.Name.Contains("琅勃拉邦皇家乳胶") || z.Name.Contains("老挝土产") || z.Name.Contains("老挝红木") || z.Name.Contains("琅勃拉邦风情园") || z.Name.Contains("锅具") || z.Name.Contains("琅勃拉邦银寨") || z.Name.Contains("琅勃拉邦咖啡庄园") || z.Name.Contains("金占巴百草园"))).Select(x => x.ID + "").ToList());
                    break;
                //自费收入
                case 2:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("自费") || z.Name.Contains("自费收支结算")).Select(x => x.ID + "").ToList());
                    break;
                //小费收入
                case 3:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("小费")).Select(x => x.ID + "").ToList());
                    break;
                //佣金+小费+自费
                case 4:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("地接收入") || z.Name.Contains("小费") || z.Name.Contains("自费")).Select(x => x.ID + "").ToList());
                    break;
                //邀请函、名单表
                case 5:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("邀请函") || z.Name.Contains("名单表")).Select(x => x.ID + "").ToList());
                    break;
                //车资
                case 6:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("车资")).Select(x => x.ID + "").ToList()); break;
                //国内联运机票
                case 7:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("国内联运")).Select(x => x.ID + "").ToList()); break;
                //签证
                case 8:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("签证")).Select(x => x.ID + "").ToList()); break;
                //其他
                case 9:
                    ids = string.Join(",", costList.Where(z => !z.Name.Contains("邀请函") && !z.Name.Contains("名单表") && !z.Name.Contains("车资") && !z.Name.Contains("机票") && !z.Name.Contains("联运机票") && !z.Name.Contains("签证") && !z.Name.Contains("地接费（领取）") && !z.Name.Contains("地接费（结算）") && !z.Name.Contains("自费") && !z.Name.Contains("御宝") && !z.Name.Contains("乐天") && !z.Name.Contains("茶道") && !z.Name.Contains("高岛屋") && !z.Name.Contains("TOKIS") && !z.Name.Contains("电器LAOX") && !z.Name.Contains("机场免税店") && !z.Name.Contains("永山免税店") && !z.Name.Contains("公社免税店") && !z.Name.Contains("电器AKKONE") && !z.Name.Contains("橡胶店")).Select(x => x.ID + "").ToList());
                    break;
                case 10:
                    //地接款支出
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("地接费（领取）")).Select(x => x.ID + "").ToList()); break;
                //地接款收入
                case 11:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("地接费（结算）")).Select(x => x.ID + "").ToList()); break;
                //小费收入
                case 12:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("小费")).Select(x => x.ID + "").ToList()); break;
                //自费收入
                case 13:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("自费")).Select(x => x.ID + "").ToList()); break;
                //简易报表
                //意外险
                case 14:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("保险费") || z.Name.Contains("旅游责任险")).Select(x => x.ID + "").ToList()); break;
                //工资
                case 15:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("工资") && !z.Name.Contains("员工工资(还款)")).Select(x => x.ID + "").ToList()); break;
                //员工提成
                case 16:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("业务提成（操作）") || z.Name.Contains("业务提成（签证）") || z.Name.Contains("业务提成（票务）") || z.Name.Contains("业务提成（地接）") || z.Name.Contains("业务提成（销售）") || z.Name.Contains("人头奖励（销售）")).Select(x => x.ID + "").ToList()); break;
                //社保
                case 17:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("社会保障费")).Select(x => x.ID + "").ToList()); break;
                //员工福利及竞赛奖金
                case 18:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("福利及奖金")).Select(x => x.ID + "").ToList()); break;
                //办公用品
                case 19:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("办公用品")).Select(x => x.ID + "").ToList()); break;
                //差旅费
                case 20:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("差旅费")).Select(x => x.ID + "").ToList()); break;
                //电话费(通訊費)
                case 21:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("电话费") || z.Name.Contains("通讯费")).Select(x => x.ID + "").ToList()); break;
                //物管水电费
                case 22:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("物管水电费")).Select(x => x.ID + "").ToList()); break;
                //房租
                case 23:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("房租")).Select(x => x.ID + "").ToList()); break;
                //广告费
                case 24:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("广告费")).Select(x => x.ID + "").ToList()); break;
                //业务招待
                case 25:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("业务招待")).Select(x => x.ID + "").ToList()); break;
                //累计折旧
                case 26:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("累计折旧")).Select(x => x.ID + "").ToList()); break;
                //税金
                case 27:
                    ids = string.Join(",", costList.Where(z => z.Name == "税金").Select(x => x.ID + "").ToList()); break;
                //平台使用费
                case 28:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("平台使用费")).Select(x => x.ID + "").ToList()); break;
                //電腦系统费
                case 29:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("電腦系统费") || z.Name.Contains("系统使用费")).Select(x => x.ID + "").ToList()); break;
                //市内交通费
                case 30:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("市内交通费")).Select(x => x.ID + "").ToList()); break;
                //团队建设费
                case 31:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("团队建设费")).Select(x => x.ID + "").ToList()); break;
                //会务费
                case 32:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("会务费")).Select(x => x.ID + "").ToList()); break;
                //同行返利
                case 33:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("同行返利") || z.Name.Contains("平台大红包返款") || z.Name.Contains("平台佣金")).Select(x => x.ID + "").ToList()); break;
                //工会经费
                case 34:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("工会经费")).Select(x => x.ID + "").ToList()); break;
                //律师费
                case 35:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("律师费")).Select(x => x.ID + "").ToList()); break;
                //服务器管理费
                case 36:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("服务器管理费")).Select(x => x.ID + "").ToList()); break;
                //导游佣金
                case 37:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("导游佣金")).Select(x => x.ID + "").ToList()); break;
                //领队佣金
                case 38:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("领队佣金") || z.Name.Contains("领队奖励金")).Select(x => x.ID + "").ToList()); break;
                //航空公司保证金（会退）
                case 39:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("航空公司保证金（会退）")).Select(x => x.ID + "").ToList()); break;
                //航空公司大订金（会抵扣）
                case 40:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("航空公司大订金（会抵扣）")).Select(x => x.ID + "").ToList()); break;
                //汇款手续费
                case 41:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("付款手续费") || z.Name.Contains("刷卡手续费") || z.Name.Contains("转账手续费")).Select(x => x.ID + "").ToList()); break;
                //利息收入
                case 42:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("利息收入")).Select(x => x.ID + "").ToList()); break;
                //汇兑损益
                case 43:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("汇兑损益")).Select(x => x.ID + "").ToList()); break;
                //营业外收入
                case 44:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("营业外收入") || z.Name.Contains("商品收入") || z.Name.Contains("运费收入") || z.Name.Contains("司导保险收入")).Select(x => x.ID + "").ToList()); break;
                //营业外收入1（公司日常收入单）
                case 45:
                //ids = string.Join(",", costList.Where(z => z.Name.Contains("营业外收入1")).Select(x => x.ID + "").ToList()); break;
                //应收款(老系统type=6)
                case 46:
                    ids = string.Join(",", costList.Where(z => z.Type == WFTempLateClassEnum.ShouldIncome || (z.Type == WFTempLateClassEnum.IN && (z.Name.Contains("投资款") || z.Name.Contains("平台保证金") || z.Name.Contains("押金") || z.Name.Contains("其他保证金")))).Select(x => x.ID + "").ToList()); break;
                //应付款(老系统type=7)
                case 47:
                    ids = string.Join(",", costList.Where(z => z.Type == WFTempLateClassEnum.ShouldPay || (z.Type == WFTempLateClassEnum.OUT && (z.Name.Contains("投资款") || z.Name.Contains("平台保证金") || z.Name.Contains("押金") || z.Name.Contains("其他保证金")))).Select(x => x.ID + "").ToList()); break;
                //其他营业支出
                case 48:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("其他营业支出") || z.Name.Contains("退换货费用") || z.Name.Contains("采购成本") || z.Name.Contains("商品退款") || z.Name.Contains("税费") || z.Name.Contains("司导保险成本") || z.Name.Contains("采购退回") || z.Name.Contains("溢收款退款")).Select(x => x.ID + "").ToList()); break;
                //所得税费用
                case 49:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("所得税费用")).Select(x => x.ID + "").ToList()); break;
                //营业税金
                case 50:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("营业税金及附加")).Select(x => x.ID + "").ToList()); break;
                //简易报表其他
                case 51:
                    ids = string.Join(",",
                        costList.Where(z => !z.Name.Contains("所得税费用")
                        && !z.Name.Contains("其他营业支出")
                        && !z.Name.Contains("应付款")
                        && !z.Name.Contains("应收款")
                        && !z.Name.Contains("营业外收入")
                        && !z.Name.Contains("汇兑损益")
                        && !z.Name.Contains("利息收入")
                        && (!z.Name.Contains("付款手续费")
                        && !z.Name.Contains("刷卡手续费")
                        && !z.Name.Contains("转账手续费"))
                        && !z.Name.Contains("航空公司大订金（会抵扣）")
                        && !z.Name.Contains("航空公司保证金（会退）")
                        && !z.Name.Contains("领队佣金")
                        && !z.Name.Contains("领队奖励金")
                        && !z.Name.Contains("导游佣金")
                        && !z.Name.Contains("服务器管理费")
                        && !z.Name.Contains("律师费")
                        && !z.Name.Contains("工会经费")
                        && !z.Name.Contains("同行返利")
                        && !z.Name.Contains("平台大红包返款")
                        && !z.Name.Contains("会务费")
                        && !z.Name.Contains("团队建设费")
                        && !z.Name.Contains("市内交通费")
                        && !z.Name.Contains("電腦系统费")
                        && !z.Name.Contains("系统使用费")
                        && !z.Name.Contains("系统费")
                        && !z.Name.Contains("平台使用费")
                        && z.Name != "税金"
                        && !z.Name.Contains("累计折旧")
                        && !z.Name.Contains("业务招待")
                        && !z.Name.Contains("累计折旧")
                        && !z.Name.Contains("广告费")
                        && !z.Name.Contains("房租")
                        && !z.Name.Contains("物管水电费")
                        && !z.Name.Contains("电话费")
                        && !z.Name.Contains("通讯费")
                        && !z.Name.Contains("差旅费")
                        && !z.Name.Contains("办公用品")
                        && !z.Name.Contains("福利及奖金")
                        && !z.Name.Contains("社会保障费")
                        && !z.Name.Contains("业务提成")
                        && !z.Name.Contains("人头奖励")
                        && !z.Name.Contains("工资")
                        && !z.Name.Contains("保险费")
                        && !z.Name.Contains("旅游责任险")
                        && !z.Name.Contains("营业税金及附加")
                        && z.Type != WFTempLateClassEnum.ShouldIncome
                        && z.Type != WFTempLateClassEnum.ShouldPay
                        && !z.Name.Contains("投资款")
                        && !z.Name.Contains("利润分配")
                        && !z.Name.Contains("员工红利")
                        && !z.Name.Contains("保证金")
                        && !z.Name.Contains("其他保证金")
                        && !z.Name.Contains("酒店预付款")
                        && !z.Name.Contains("CHI包房")
                        && !z.Name.Contains("预付环球门票")
                        && !z.Name.Contains("门票预付款")
                        && !z.Name.Contains("餐厅预付款")
                        && !z.Name.Contains("车资预付款")
                        && !z.Name.Contains("机票预付款")
                        && !z.Name.Contains("机票保证金")
                        && !z.Name.Contains("电商预付款")
                        && !z.Name.Contains("押金")
                        && !z.Name.Contains("员工工资(还款)")
                        && !z.Name.Contains("挂账单冲抵")
                        && !z.Name.Contains("机票收入")
                        && !z.Name.Contains("快递费")
                        && !z.Name.Contains("照片服务费")
                        && !z.Name.Contains("地接OP备用金")
                        && !z.Name.Contains("领队罚金")
                        && !z.Name.Contains("景点门票")
                        && !z.Name.Contains("用房手配费")
                        && !z.Name.Contains("餐厅手配费")
                        && !z.Name.Contains("景点门票手配费")
                        && !z.Name.Contains("平台佣金")
                        && !z.Name.Contains("居间佣金")
                        && !z.Name.Contains("商品收入")
                        && !z.Name.Contains("运费收入")
                        && !z.Name.Contains("退换货费用")
                        && !z.Name.Contains("采购成本")
                        && !z.Name.Contains("运杂费")
                        && !z.Name.Contains("商品退款")
                        && !z.Name.Contains("电商存货")
                        && !z.Name.Contains("采购退回")
                        && !z.Name.Contains("溢收款退款")
                        && !z.Name.Contains("税费")
                        && !z.Name.Contains("司导保险")
                        && !z.Name.Contains("备用金")
                        && !z.Name.Contains("个人借款")
                        && !z.Name.Contains("其他代垫代收")
                        && !z.Name.Contains("陈芳英款项")
                        ).Select(x => x.ID + "").ToList()); break;
                //快递费
                case 52:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("快递费") || z.Name.Contains("运杂费")).Select(x => x.ID + "").ToList()); break;
                //应收应付款
                case 53:
                    ids = string.Join(",", costList.Where(z => z.Type == WFTempLateClassEnum.ShouldIncome || z.Type == WFTempLateClassEnum.ShouldPay).Select(x => x.ID + "").ToList()); break;
                //应收应付款(投资款)
                case 55:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("投资款")).Select(x => x.ID + "").ToList()); break;
                //利润分配
                case 61:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("利润分配")).Select(x => x.ID + "").ToList()); break;
                //员工红利
                case 62:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("员工红利")).Select(x => x.ID + "").ToList()); break;
                //酒店预付款	
                case 63:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("酒店预付款") || z.Name.Contains("CHI包房")).Select(x => x.ID + "").ToList()); break;
                //门票预付款
                case 64:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("门票预付款") || z.Name.Contains("预付环球门票")).Select(x => x.ID + "").ToList()); break;
                //餐厅预付款
                case 65:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("餐厅预付款")).Select(x => x.ID + "").ToList()); break;
                //车资预付款
                case 66:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("预付款")).Select(x => x.ID + "").ToList()); break;
                //机票预付款
                case 67:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("机票预付款")).Select(x => x.ID + "").ToList()); break;
                //保证金押金预付款
                case 68:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("平台保证金") || z.Name.Contains("押金") || z.Name.Contains("机票保证金") || z.Name.Contains("其他保证金")).Select(x => x.ID + "").ToList()); break;
                //领队导游保证金
                case 69:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("领队保证金") || z.Name.Contains("导游保证金")).Select(x => x.ID + "").ToList()); break;
                //同行返利
                case 70:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("居间佣金")).Select(x => x.ID + "").ToList()); break;
                //备用金
                case 71:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("备用金")).Select(x => x.ID + "").ToList()); break;
                //个人借款
                case 72:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("个人借款")).Select(x => x.ID + "").ToList()); break;
                //其他代垫代收
                case 73:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("其他代垫代收")).Select(x => x.ID + "").ToList()); break;
                //陈芳英款项
                case 74:
                    ids = string.Join(",", costList.Where(z => z.Name.Contains("陈芳英款项")).Select(x => x.ID + "").ToList()); break;
            }
            return ids;
        }

        #endregion
    }
}
