using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Edu.Common.API;
using Edu.Common.Enum.Finance;
using Edu.Common.Plugin;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Finance;
using Edu.Module.Course;
using Edu.Module.Finance;
using Edu.Module.StudyAbroad;
using Edu.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;

namespace Edu.WebApi.Controllers.Finance
{
    /// <summary>
    /// 系统公用接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExceptionFilter]
    [ApiController]
    [EnableCors("AllowCors")]
    public class FinanceController : BaseController
    {
        /// <summary>
        /// 财务处理类对象
        /// </summary>
        private readonly FinanceModule financeModule = AOP.AOPHelper.CreateAOPObject<FinanceModule>();

        /// <summary>
        /// 订单处理类对象
        /// </summary>
        private readonly OrderModule orderModule = AOP.AOPHelper.CreateAOPObject<OrderModule>();

        /// <summary>
        /// 班级处理类对象
        /// </summary>
        private readonly ClassModule classModule = AOP.AOPHelper.CreateAOPObject<ClassModule>();
        /// <summary>
        /// 留学就业处理类对象
        /// </summary>
        private readonly StudyAbroadModule studyAbroadModule = AOP.AOPHelper.CreateAOPObject<StudyAbroadModule>();

        /// <summary>
        /// 教务奖励处理类对象
        /// </summary>
        private readonly TeachingRewardsModule teachingRewardsModule = AOP.AOPHelper.CreateAOPObject<TeachingRewardsModule>();

        /// <summary>
        /// 获取班级/留学就业收支明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ApiResult GetClassBalanceSheet()
        {
            int classId = base.ParmJObj.GetInt("ClassId", 0);
            int schoolId = base.ParmJObj.GetInt("School_Id");
            int SourceId = base.ParmJObj.GetInt("SourceId");
            if (classId <= 0 && SourceId <= 0)
            {
                return ApiResult.Failed("班级Id不存在");
            }

            RB_Finance_Extend model = new RB_Finance_Extend() { TCID = classId, OrderSource = OrderResourceEnum.Education, RB_Group_Id = base.UserInfo.Group_Id, FinanceType = 2 };
            if (SourceId > 0)
            {
                model.TCID = SourceId;
                model.OrderSource = OrderResourceEnum.EducationStudy;
            }
            var financeList = financeModule.GetFinanceInfoList(model).Where(t => (t.Status == FinanceAuditStatus.InReview || t.Status == FinanceAuditStatus.Pass || t.Status == FinanceAuditStatus.CTemporary)).ToList();

            //收入
            decimal IncomeReceive = 0;//应收
            decimal IncomeActual = 0;//实收
            var orderList = orderModule.GetClassOrderList_V2(classId, base.UserInfo.Group_Id, SourceId).Where(x => (int)x.OrderState < 3);
            IncomeReceive = (orderList != null && orderList.Any()) ? orderList.Sum(x => x.PreferPrice) : 0;
            IncomeActual = (orderList != null && orderList.Any()) ? orderList.Sum(x => x.Income) : 0;

            //其他
            decimal OtherIncomeReceive = 0;//应收
            decimal OtherIncomeActual = 0;//实收
            OtherIncomeReceive = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.IN && x.OrderID <= 0).Sum(x => x.Money ?? 0) : 0;
            OtherIncomeActual = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.IN && x.OrderID <= 0).Sum(x => x.PayMoney ?? 0) : 0;
            //支出
            decimal PayReceive = 0;//应付
            decimal PayActual = 0;//实付
            PayReceive = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.OUT).Sum(x => x.Money ?? 0) : 0;
            PayActual = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.OUT).Sum(x => x.PayMoney ?? 0) : 0;

            //利润
            decimal ProfitActual = 0;//实际利润
            decimal ProfitNow = 0;//当前利润
            ProfitActual = (IncomeActual + OtherIncomeActual) - PayReceive;
            ProfitNow = (IncomeActual + OtherIncomeActual) - PayActual;

            //提成
            decimal SaleCommission = (orderList != null && orderList.Any()) ? orderList.Where(x => x.IsCommissionGive == 1).Sum(x => x.CommissionMoney) : 0; ;//销售提成
            var teacherProfitList = teachingRewardsModule.GetBonusDetailList(new RB_Teaching_BonusDetail_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId });
            decimal TeacherProfitNow = (teacherProfitList != null && teacherProfitList.Any()) ? teacherProfitList.Sum(x => x.Money) : 0;//老师提成

            var meritsProfitList = teachingRewardsModule.GetTeachingPerfList(new RB_Teaching_Perf_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId });
            decimal MeritsProfit = (meritsProfitList != null && meritsProfitList.Any()) ? (meritsProfitList.Where(x => x.PerfState == Common.Enum.Course.PerfStateEnum.Confirmed).OrderByDescending(x => x.CreateTime).FirstOrDefault()?.Money ?? 0) : 0;//绩效提成
           
            //项目信息
            var projectInfo = new object();
            if (classId > 0)
            {
                var classInfo = classModule.GetClassAndCourseListRepository(new Model.ViewModel.Course.RB_Class_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId }).FirstOrDefault();
                projectInfo = new { classInfo?.ClassName, classInfo?.CourseName, classInfo?.TeacherName, OpenTime = classInfo?.OpenTime.ToString("yyyy-MM-dd") };
            }
            else if (SourceId > 0)
            {
                var studyInfo = studyAbroadModule.GetStudyAbroadModule(SourceId);
                projectInfo = new { ClassName = studyInfo?.Name, CourseName = "", TeacherName = "", OpenTime = "" };
            }
            var recultFiniceList = financeList.Select(x => new
            {
                x.FrID,
                x.Type,
                x.TCID,
                x.OrderID,
                x.Money,
                x.PayMoney,
                AirTotalMoney = x.AirTotalMoney ?? 0,
                AirTotalPayMoney = x.AirTotalPayMoney ?? 0,
                CostTypeList = x.CostTypeList.Distinct().ToList(),
                x.OrderSource,
                AuditList = x.AuditList.Select(t => new { t.AuditEmId, t.AuditEmName, AuditDate = t.AuditDate.HasValue ? t.AuditDate.Value.ToString("yyyy/MM/dd") : "" }),
                StatusStr = EnumHelper.ToName(x.Status.Value),
                x.RB_CreateByName,
                CreateDate = x.CreateDate.Value.ToString("yyyy-MM-dd"),
                TradeDate = x.TradeDate.HasValue ? x.TradeDate.Value.ToString("yyyy-MM-dd") : "",
                TradeWayList = x.BankList?.Select(y => new { y.AccountType, y.Alias, y.BankNo, TypeName = EnumHelper.ToName(y.Type), y.CurrencyName, y.OriginalMoney, y.Money, y.Rate })
            });

            var classFinanceModel = classModule.GetClassFinanceListRepository(new RB_Class_Finance_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId }).FirstOrDefault();
            if (classFinanceModel == null)
            {
                classFinanceModel = new RB_Class_Finance_ViewModel
                {
                    Group_Id = base.UserInfo.Group_Id,
                    ClassId = classId,
                    School_Id = schoolId
                };
            }
            var resultData = new
            {
                ClassFinance = new { classFinanceModel.ClassId, classFinanceModel.IsOpen, classFinanceModel.Group_Id, classFinanceModel.School_Id, classFinanceModel.FinanceId },
                ClassInfo = projectInfo,
                IncomeReceive,
                IncomeActual,
                OtherIncomeReceive,
                OtherIncomeActual,
                PayReceive,
                PayActual,
                ProfitActual,
                ProfitNow,
                SaleCommission,
                TeacherProfitNow,
                MeritsProfit,
                FiniceReciveList = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.IN && t.OrderID > 0),//学费收入
                OtherFiniceReciveList = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.IN && t.OrderID <= 0),//其他收入
                OtherFinicePayList = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.OUT),//其他支出
                //退费，班级费用（书本，房租等），提成，课时费确定 在弄
            };
            return ApiResult.Success("", resultData);
        }

        /// <summary>
        /// 用户信息下载
        /// </summary>
        [HttpPost]
        [Obsolete]
        public FileContentResult GetClassBalanceSheetToExcel()
        {
            int classId = base.ParmJObj.GetInt("ClassId", 0);
            int schoolId = base.ParmJObj.GetInt("School_Id");
            int SourceId = base.ParmJObj.GetInt("SourceId");
            List<ExcelDataSource> slist = new List<ExcelDataSource>();
            string ExcelName = "用户列表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            if (classId <= 0 && SourceId <= 0)
            {
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", ExcelName);
            }
            RB_Finance_Extend model = new RB_Finance_Extend() { TCID = classId, OrderSource = OrderResourceEnum.Education, RB_Group_Id = base.UserInfo.Group_Id, FinanceType = 2 };
            if (SourceId > 0)
            {
                model.TCID = SourceId;
                model.OrderSource = OrderResourceEnum.EducationStudy;
            }
            var financeList = financeModule.GetFinanceInfoList(model).Where(t => (t.Status == FinanceAuditStatus.InReview || t.Status == FinanceAuditStatus.Pass || t.Status == FinanceAuditStatus.CTemporary)).ToList();

            //收入
            decimal IncomeReceive = 0;//应收
            decimal IncomeActual = 0;//实收
            var orderList = orderModule.GetClassOrderList_V2(classId, base.UserInfo.Group_Id, SourceId).Where(x => (int)x.OrderState < 3);
            IncomeReceive = (orderList != null && orderList.Any()) ? orderList.Sum(x => x.PreferPrice) : 0;
            IncomeActual = (orderList != null && orderList.Any()) ? orderList.Sum(x => x.Income) : 0;

            //其他
            decimal OtherIncomeReceive = 0;//应收
            decimal OtherIncomeActual = 0;//实收
            OtherIncomeReceive = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.IN && x.OrderID <= 0).Sum(x => x.Money ?? 0) : 0;
            OtherIncomeActual = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.IN && x.OrderID <= 0).Sum(x => x.PayMoney ?? 0) : 0;
            //支出
            decimal PayReceive = 0;//应付
            decimal PayActual = 0;//实付
            PayReceive = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.OUT).Sum(x => x.Money ?? 0) : 0;
            PayActual = (financeList != null && financeList.Any()) ? financeList.Where(x => x.Type == WFTempLateClassEnum.OUT).Sum(x => x.PayMoney ?? 0) : 0;

            //利润
            decimal ProfitActual = 0;//实际利润
            decimal ProfitNow = 0;//当前利润
            ProfitActual = (IncomeReceive + OtherIncomeReceive) - PayReceive;
            ProfitNow = (IncomeActual + OtherIncomeActual) - PayActual;

            //提成
            decimal SaleCommission = (orderList != null && orderList.Any()) ? orderList.Where(x => x.IsCommissionGive == 1).Sum(x => x.CommissionMoney) : 0; ;//销售提成
            var teacherProfitList = teachingRewardsModule.GetBonusDetailList(new RB_Teaching_BonusDetail_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId });
            decimal TeacherProfitNow = (teacherProfitList != null && teacherProfitList.Any()) ? teacherProfitList.Sum(x => x.Money) : 0;//老师提成

            var meritsProfitList = teachingRewardsModule.GetTeachingPerfList(new RB_Teaching_Perf_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId });
            decimal MeritsProfit = (meritsProfitList != null && meritsProfitList.Any()) ? (meritsProfitList.OrderByDescending(x => x.CreateTime).FirstOrDefault()?.Money ?? 0) : 0;//绩效提成

            string title = "班级情况";
            string subtitle = "班级名称";
            string thirdTitle = "课程名称：";
            string fourTitle = "开班时间：";

            //项目信息
            var projectInfo = new RB_Class_ViewModel();
            if (classId > 0)
            {
                var classInfo = classModule.GetClassAndCourseListRepository(new Model.ViewModel.Course.RB_Class_ViewModel { Group_Id = base.UserInfo.Group_Id, ClassId = classId, School_Id = schoolId }).FirstOrDefault();
                projectInfo = new RB_Class_ViewModel()
                {
                    ClassName= classInfo?.ClassName,
                    CourseName= classInfo?.CourseName,
                    TeacherName= classInfo?.TeacherName,
                    OpenTimeStr = classInfo?.OpenTime.ToString("yyyy-MM-dd")
                };
            }
            else if (SourceId > 0)
            {
                var studyInfo = studyAbroadModule.GetStudyAbroadModule(SourceId);
                projectInfo = new RB_Class_ViewModel
                {
                    ClassName = studyInfo?.Name,
                    CourseName = "",
                    TeacherName = "",
                    OpenTimeStr = ""
                };
                title = (studyInfo?.Type ?? 0) ==1? "留学情况" : "就业情况";
                subtitle = "项目名称";
                thirdTitle = "";
                fourTitle = "";
            }
            List<RB_Finance_Extend> financeReciveList = financeList.Where(t => t.Type == WFTempLateClassEnum.IN).ToList();
            List<RB_Finance_Extend> financePayList = financeList.Where(t => t.Type == WFTempLateClassEnum.OUT).ToList();

            try
            {
                
                ExcelDataSource teamBalance = new ExcelDataSource(50)
                {
                    ExcelRows = new List<ExcelColumn>()
                    {
                          new ExcelColumn(value: title,colspan:2)
                          {
                               IsBold = true,
                               CellWidth=30,
                               HAlignmentEnum= HAlignmentEnum.LEFT,
                          },
                          new ExcelColumn(value:"学费收入",colspan:2)
                          {
                               IsBold = true,
                               CellWidth=20,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:"其他收入",colspan:2)
                          {
                               IsBold = true,
                               CellWidth=20,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:"支出",colspan:2)
                          {
                               IsBold = true,
                                CellWidth=20,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:"利润",colspan:2)
                          {
                               IsBold = true,
                                CellWidth=20,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:"提成",colspan:2)
                          {
                               IsBold = true,
                                CellWidth=20,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                    }
                };
                slist.Add(teamBalance);

                ExcelDataSource firstRow = new ExcelDataSource(30)
                {
                    ExcelRows = new List<ExcelColumn>()
                    {
                        new ExcelColumn(value: $"{subtitle}：{projectInfo.ClassName}",colspan:2)
                        {
                            HAlignmentEnum= HAlignmentEnum.LEFT,
                        },
                        new ExcelColumn(value:$"应收：￥{IncomeReceive}",colspan:2)
                        {
                            CellWidth=15,
                            HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:$"应收：￥{OtherIncomeReceive}",colspan:2)
                        {
                            HAlignmentEnum= HAlignmentEnum.LEFT
                        }, new ExcelColumn(value:$"应付：￥{PayReceive}",colspan:2)
                        {
                            HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:$"实际利润：￥{ProfitActual}",colspan:2)
                        {
                            HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:$"销售提成：￥{SaleCommission}",colspan:2)
                        {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                        }
                    }
                };
                slist.Add(firstRow);
                ExcelDataSource secondRow = new ExcelDataSource(30)
                {
                    ExcelRows = new List<ExcelColumn>() 
                    {
                          new ExcelColumn(value: $"{thirdTitle}{projectInfo.CourseName}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT,
                          },
                          new ExcelColumn(value:$"实收：￥{IncomeActual}",colspan:2)
                          {
                               CellWidth=15,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:$"实收：￥{OtherIncomeActual}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:$"实付：￥{PayActual}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:$"当前利润：￥{ProfitNow}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          }, 
                          new ExcelColumn(value:$"课时费：￥{TeacherProfitNow}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          }
                    }
                };
                slist.Add(secondRow);
                ExcelDataSource thirdRow = new ExcelDataSource(30)
                {
                    ExcelRows = new List<ExcelColumn>()
                    {
                          new ExcelColumn(value: $"{fourTitle}{projectInfo.OpenTimeStr:yyyy-MM-dd}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT,
                          },
                          new ExcelColumn(value:$"待收：￥{(IncomeReceive-IncomeActual)}",colspan:2)
                          {
                               CellWidth=15,
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:$"待收：￥{(OtherIncomeReceive-OtherIncomeActual)}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                          new ExcelColumn(value:$"待付：￥{(PayReceive-PayActual)}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          },
                           new ExcelColumn(value:"",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          }, new ExcelColumn(value:$"绩效奖励：￥{MeritsProfit}",colspan:2)
                          {
                               HAlignmentEnum= HAlignmentEnum.LEFT
                          }
                 }
                };
                slist.Add(thirdRow);
                ExcelDataSource fourRow = new ExcelDataSource(30)
                {
                    ExcelRows = new List<ExcelColumn>()
                    {
                        new ExcelColumn(value: $"带课老师：{projectInfo.TeacherName}",colspan:2)
                        {
                            HAlignmentEnum= HAlignmentEnum.LEFT,
                        },
                        new ExcelColumn(value:"",colspan:2)
                        {
                            HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:"",colspan:2)
                        {
                           HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:"",colspan:2)
                        {
                           HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:"",colspan:2)
                        {
                           HAlignmentEnum= HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value:"",colspan:2)
                        {
                           HAlignmentEnum= HAlignmentEnum.LEFT
                        }
                    }
                };
                if (classId > 0)
                {
                    slist.Add(fourRow);
                }
                ExcelDataSource splitRow = new ExcelDataSource(40)
                {
                    ExcelRows = new List<ExcelColumn>()
                };
                slist.Add(splitRow);

                #region 收支列表
                ExcelDataSource reciveRow = new ExcelDataSource(40)
                {
                    ExcelRows = new List<ExcelColumn>()
                    {
                          new ExcelColumn(value: "收入",colspan:9)
                          {
                               IsBold = true,
                               IsSetBorder =false,
                               HAlignmentEnum= HAlignmentEnum.LEFT,
                          }
                    }
                };
                slist.Add(reciveRow);
                GenerateTeamBalanceSheet(slist, financeReciveList, WFTempLateClassEnum.IN);
                ExcelDataSource payRow = new ExcelDataSource(40)
                {
                    ExcelRows = new List<ExcelColumn>() 
                    {
                          new ExcelColumn(value: "支出",colspan:9)
                          {
                               IsBold = true,
                               IsSetBorder =false,
                               HAlignmentEnum= HAlignmentEnum.LEFT,
                          }
                    }
                };
                slist.Add(payRow);
                GenerateTeamBalanceSheet(slist, financePayList, WFTempLateClassEnum.OUT);
                #endregion

                var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData, "application/octet-stream", ExcelName);
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, string.Format("GetFileFromWebApi_requestData: {0}", JsonHelper.Serialize(RequestParm)));
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", ExcelName);
            }
        }

        /// <summary>
        /// 添加修改班级收支设置
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult SetClassFinance()
        {
            var extModel = Common.Plugin.JsonHelper.DeserializeObject<RB_Class_Finance_ViewModel>(RequestParm.Msg.ToString());
            extModel.CreateTime = DateTime.Now;
            extModel.CreateBy = UserInfo.Id;
            extModel.UpdateBy = UserInfo.Id;
            extModel.UpdateTime = DateTime.Now;
            extModel.Group_Id = this.UserInfo.Group_Id;
            bool flag = classModule.SetClassFinance(extModel);
            return flag ? ApiResult.Success() : ApiResult.Failed();
        }



        /// <summary>
        /// 生成收入支出excel内容
        /// </summary>
        /// <param name="list">excel容器</param>
        /// <param name="financeList">收支列表</param>
        /// <param name="type">收支类型</param>
        private void GenerateTeamBalanceSheet(List<ExcelDataSource> excelDataSourceContainer, List<RB_Finance_Extend> financeList, WFTempLateClassEnum type)
        {
            ExcelDataSource title = new ExcelDataSource(35)
            {
                ExcelRows = new List<ExcelColumn>() {
                      new ExcelColumn(value: "单号"){
                            IsBold = true,
                          CellWidth = 10,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                      new ExcelColumn(value: "费用类型"){
                            IsBold = true,
                            CellWidth = 20,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                      new ExcelColumn(value: "交易信息",colspan:2){
                            IsBold = true,
                          CellWidth=30,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                      new ExcelColumn(value: "金额"){
                            IsBold = true,
                           CellWidth=30,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                      new ExcelColumn(value: "交易日期"){
                            IsBold = true,
                           CellWidth=15,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                       new ExcelColumn(value: "制单人员"){
                             IsBold = true,
                            CellWidth=15,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                        new ExcelColumn(value: "审核状态"){
                              IsBold = true,
                             CellWidth=20,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      },
                        new ExcelColumn(value: "当前审核人"){
                              IsBold = true,
                             CellWidth=20,
                           HAlignmentEnum= HAlignmentEnum.LEFT,
                      }
                 }
            };
            excelDataSourceContainer.Add(title);
            if (financeList != null && financeList.Count > 0)
            {
                foreach (var item in financeList)
                {
                    ExcelDataSource content = new ExcelDataSource(30);
                    List<ExcelColumn> colums = new List<ExcelColumn>
                    {
                        new ExcelColumn(value: item.FrID.ToString())
                        {
                            HAlignmentEnum = HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value: item.CostTypeList != null ? string.Join(",", item.CostTypeList) : "")
                        {
                            HAlignmentEnum = HAlignmentEnum.LEFT
                        },
                        new ExcelColumn(value: item.BankList != null ? GetCostDetial(item.BankList) : "", colspan: 2)
                        {
                            HAlignmentEnum = HAlignmentEnum.LEFT
                        }
                    };
                    if (type == WFTempLateClassEnum.IN)
                    {
                        colums.Add(new ExcelColumn(value: $"应收:￥{item.Money} 实收：￥{item.PayMoney}")
                        {
                            HAlignmentEnum = HAlignmentEnum.LEFT
                        });
                    }
                    else
                    {
                        colums.Add(new ExcelColumn(value: $"应付:￥{item.Money} 实付：￥{item.PayMoney}")
                        {
                            HAlignmentEnum = HAlignmentEnum.LEFT
                        });
                    }
                    colums.Add(new ExcelColumn(value: item.TradeDate.HasValue ? item.TradeDate.Value.ToString("yyyy/MM/dd") : "")
                    {
                        HAlignmentEnum = HAlignmentEnum.LEFT
                    });
                    string EmName = item.RB_CreateByName;
                    colums.Add(new ExcelColumn(value: string.IsNullOrWhiteSpace(EmName) ? "" : EmName)
                    {
                        HAlignmentEnum = HAlignmentEnum.LEFT
                    });
                    colums.Add(new ExcelColumn(value: EnumHelper.ToName(item.Status.Value))
                    {
                        HAlignmentEnum = HAlignmentEnum.LEFT
                    });
                    List<string> auditNameList = new List<string>();
                    foreach (var audit in item.AuditList)
                    {
                        auditNameList.Add(audit.AuditEmName);
                    }
                    colums.Add(new ExcelColumn(value: string.Join(",", auditNameList))
                    {
                        HAlignmentEnum = HAlignmentEnum.LEFT
                    });
                    content.ExcelRows = colums;
                    excelDataSourceContainer.Add(content);
                }
            }
        }

        /// <summary>
        /// 获取交易明细信息
        /// </summary>
        /// <param name="bankList"></param>
        /// <returns></returns>
        private string GetCostDetial(List<RB_TradeWay_Extend> wayList)
        {
            if (wayList.Count > 0)
            {
                List<string> wayDetialList = new List<string>();
                foreach (var item in wayList)
                {
                    wayDetialList.Add($"{item.Alias} {item.CurrencyName}:{item.OriginalMoney} 汇率:{item.Rate}");
                }
                return string.Join(",", wayDetialList);
            }
            else
            {
                return "";
            }
        }

        #region 获取报价单单据列表

        /// <summary>
        /// 获取报价单收支明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ApiResult GetOfferOrderBalanceSheet()
        {
            int OfferId = base.ParmJObj.GetInt("OfferId", 0);
            if (OfferId <= 0)
            {
                return ApiResult.Failed("班级Id不存在");
            }
            RB_Finance_Extend model = new RB_Finance_Extend() { OtherType = 29, ReFinanceId = OfferId, OrderSource = OrderResourceEnum.Education, RB_Group_Id = base.UserInfo.Group_Id, FinanceType = 2, IsSelectNormal = 1 };
            var financeList = financeModule.GetFinanceInfoList(model);

            var recultFiniceList = financeList.Select(x => new
            {
                x.FrID,
                x.Type,
                x.TCID,
                x.OrderID,
                x.Money,
                x.PayMoney,
                AirTotalMoney = x.AirTotalMoney ?? 0,
                AirTotalPayMoney = x.AirTotalPayMoney ?? 0,
                CostTypeList = x.CostTypeList.Distinct().ToList(),
                x.OrderSource,
                AuditList = x.AuditList.Select(t => new { t.AuditEmId, t.AuditEmName, AuditDate = t.AuditDate.HasValue ? t.AuditDate.Value.ToString("yyyy/MM/dd") : "" }),
                StatusStr = EnumHelper.ToName(x.Status.Value),
                x.RB_CreateByName,
                CreateDate = x.CreateDate.Value.ToString("yyyy-MM-dd"),
                TradeDate = x.TradeDate.HasValue ? x.TradeDate.Value.ToString("yyyy-MM-dd") : "",
                TradeWayList = x.BankList?.Select(y => new { y.AccountType, y.Alias, y.BankNo, TypeName = EnumHelper.ToName(y.Type), y.CurrencyName, y.OriginalMoney, y.Money, y.Rate })
            });

            var resultData = new
            {
                IncomeList = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.IN),//学费收入
                ExpendList = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.OUT),//其他支出
                IncomeReceive = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.IN).Sum(x => x.Money),
                IncomeActual = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.IN).Sum(x => x.PayMoney),
                ExpendReceive = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.OUT).Sum(x => x.Money),
                ExpendActual = recultFiniceList.Where(t => t.Type == WFTempLateClassEnum.OUT).Sum(x => x.PayMoney)
            };
            return ApiResult.Success("", resultData);
        }

        #endregion

        #region 报表查询

        /// <summary>
        /// 获取营收报表分页列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetRevenueReportPageList()
        {
            var userInfo = base.UserInfo;
            var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
            var dmodel = JsonHelper.DeserializeObject<RB_Edu_RevenueReport_Extend>(RequestParm.Msg.ToString());
            dmodel.Rb_Group_Id = userInfo.Group_Id;

            var list = financeModule.GetRevenueReportPageList(pageModel.PageIndex, pageModel.PageSize, out long count, dmodel);
            pageModel.Count = Convert.ToInt32(count);
            pageModel.PageData = list;

            var fumodel = financeModule.GetUpdateRecordNew();
            int Status = 0;
            string UpdateTime = "";
            if (fumodel != null)
            {
                if (fumodel.EndDate.HasValue)
                {
                    Status = 2;//更新完毕了
                    UpdateTime = fumodel.StartDate.Value.ToString("yyyy-MM-dd HH:mm");
                }
                else
                {
                    Status = 1;//正在更新
                    UpdateTime = fumodel.StartDate.Value.ToString("yyyy-MM-dd HH:mm");
                }
            }
            return ApiResult.Success("", new { Status, UpdateTime, pageModel });
        }

        /// <summary>
        /// 营收报表Excel下载
        /// </summary>
        [HttpPost]
        [Obsolete]
        public FileContentResult GetRevenueReportToExcel()
        {
            var userInfo = base.UserInfo;
            var dmodel = JsonHelper.DeserializeObject<RB_Edu_RevenueReport_Extend>(RequestParm.Msg.ToString());
            dmodel.Rb_Group_Id = userInfo.Group_Id;
            string ExcelName = "营收报表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            List<ExcelDataSource> slist = new List<ExcelDataSource>();
            ExcelDataSource header = new ExcelDataSource()
            {
                ExcelRows = new List<ExcelColumn>(30) {
                    new ExcelColumn(value: "校区") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "班级编号") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "班级") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "开班时间") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "班级状态") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "课程") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "教师") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "应收") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "实收") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "退款") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "手续费") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "优惠金额") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "待收") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "溢收") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "客人数量") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "其他收入") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "提成") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "课时费") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "绩效奖金") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "其他支出") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "应付") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "毛利") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "毛利率") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "实际利润") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "备注") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "平均收入") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "平均成本") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                    new ExcelColumn(value: "平均利润") { CellWidth = 15, HAlignmentEnum = HAlignmentEnum.CENTER, VAlignmentEnum = VAlignmentEnum.CENTER },
                }
            };
            slist.Add(header);

            try
            {
                var list = financeModule.GetRevenueReportPageList(1, 100000, out long count, dmodel);
                #region 组装数据
                foreach (var item in list)
                {
                    string ClassState = "结课";
                    if (item.ClassState == 1) { ClassState = "未开班"; }
                    else if (item.ClassState == 2) { ClassState = "学习中"; }
                    if (item.Id == -1)
                    {
                        ClassState = "";
                    }
                    ExcelDataSource datarow = new ExcelDataSource()
                    {
                        ExcelRows = new List<ExcelColumn>(30) {
                            new ExcelColumn(value: item.Id == -1 ? "合计" : item.SchoolName){ },
                            new ExcelColumn(value: item.ClassId.ToString()){ },
                            new ExcelColumn(value: item.ClassName){ },
                            new ExcelColumn(value: item.ClassBeginsStr){ },
                            new ExcelColumn(value: ClassState){ },
                            new ExcelColumn(value: item.CourseName){ },
                            new ExcelColumn(value: item.TeacherName){ },
                            new ExcelColumn(value: item.YingShou.ToString()){ },
                            new ExcelColumn(value: item.ShiShou.ToString()){ },
                            new ExcelColumn(value: item.TuiKuan.ToString()){ },
                            new ExcelColumn(value: item.PingTaiShuiJin.ToString()){ },
                            new ExcelColumn(value: item.YouHui.ToString()){ },
                            new ExcelColumn(value: item.DaiShou.ToString()){ },
                            new ExcelColumn(value: item.YiShou.ToString()){ },
                            new ExcelColumn(value: item.GuestNum.ToString()){ },
                            new ExcelColumn(value: item.QTShouRu.ToString()){ },
                            new ExcelColumn(value: item.TiCheng.ToString()){ },
                            new ExcelColumn(value: item.ClassFee.ToString()){ },
                            new ExcelColumn(value: item.JiXiaoMoney.ToString()){ },
                            new ExcelColumn(value: item.QTZhiChu.ToString()){ },
                            new ExcelColumn(value: item.YingFu.ToString()){ },
                            new ExcelColumn(value: item.MaoLi.ToString()){ },
                            new ExcelColumn(value: item.MaoLiRate.ToString()){ },
                            new ExcelColumn(value: item.ShiJiLiRun.ToString()){ },
                            new ExcelColumn(value: item.Remark){ },
                            new ExcelColumn(value: item.AverageIncome.ToString()){ },
                            new ExcelColumn(value: item.AverageCost.ToString()){ },
                            new ExcelColumn(value: item.AverageProfit.ToString()){ },
                        }
                    };
                    slist.Add(datarow);
                }
                #endregion

                var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData, "application/octet-stream", ExcelName);
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, string.Format("GetFileFromWebApi_requestData: {0}", JsonHelper.Serialize(RequestParm)));
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", ExcelName);
            }

        }

        /// <summary>
        /// 获取简易报表列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ApiResult GetEasyReportList()
        {
            var userInfo = base.UserInfo;
            var model = JsonHelper.DeserializeObject<RB_SimpleReport_Extend>(RequestParm.Msg.ToString());
            model.Rb_Group_Id = userInfo.Group_Id;
            var list = financeModule.GetEasyReportList(new RB_SimpleReport_Extend() { Year = model.Year, Rb_Group_Id = userInfo.Group_Id, BranchId = model.BranchId });

            var fumodel = financeModule.GetUpdateRecordNew();
            int Status = 0;
            string UpdateStartTime = "";
            string UpdateEndTime = "";
            if (fumodel != null)
            {
                if (fumodel.EndDate.HasValue)
                {
                    Status = 2;//更新完毕了
                    UpdateEndTime = fumodel.EndDate.Value.ToString("yyyy-MM-dd HH:mm");
                    UpdateStartTime = fumodel.StartDate.Value.ToString("yyyy-MM-dd HH:mm");
                }
                else
                {
                    Status = 1;//正在更新
                    UpdateStartTime = fumodel.StartDate.Value.ToString("yyyy-MM-dd HH:mm");
                }
            }

            var obj = new { Status, UpdateStartTime, UpdateEndTime, list = list?.Select(y => new { y.ID, y.Year, y.BranchId, y.CostIds, y.Sort, ZhaiYao = y.Abstract, YiYue = y.January, ErYue = y.February, SanYue = y.March, DiYiJiDu = y.FirstQuarter, SiYue = y.April, WuYue = y.May, LiuYue = y.June, DiErJiDu = y.SecondQuarter, ShangBanNianBao = y.HalfReport, QiYue = y.July, BaYue = y.August, JiuYue = y.September, DiSanJiDu = y.ThirdQuarter, ShiYue = y.October, ShiYiYue = y.November, ShiErYue = y.December, DiSiJiDu = y.FourthQuarter, XiaBanNianBao = y.LastHalfReport, ZongJi = y.Total }) };
            return ApiResult.Success("", obj);
        }

        /// <summary>
        /// 导出简易报表列表
        /// </summary>
        /// <returns></returns>
        [Obsolete]
        public FileContentResult OutToExcelEasyReportList()
        {
            List<ExcelDataSource> slist = new List<ExcelDataSource>();
            ExcelDataSource header = new ExcelDataSource()
            {
                ExcelRows = new List<ExcelColumn>(30) {
                            new ExcelColumn(value:"摘要"){CellWidth=20,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"一月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"二月"){CellWidth=20,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"三月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"第一季度"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"四月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"五月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"六月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"第二季度"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"上半年报"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"七月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"八月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"九月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"第三季度"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"十月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"十一月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"十二月"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"第四季度"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"下半年报"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER },
                            new ExcelColumn(value:"总计"){CellWidth=15,HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER }

                         }
            };
            slist.Add(header);
            string ExcelName = "简易报表" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";

            var userInfo = base.UserInfo;
            var model = JsonHelper.DeserializeObject<RB_SimpleReport_Extend>(RequestParm.Msg.ToString());
            model.Rb_Group_Id = userInfo.Group_Id;
            var list = financeModule.GetEasyReportList(new RB_SimpleReport_Extend() { Year = model.Year, Rb_Group_Id = userInfo.Group_Id, BranchId = model.BranchId });
            try
            {
                foreach (var sitem in list)
                {
                    if (sitem.Abstract == "以下项均不计入计算")
                    {
                        ExcelDataSource firstRow = new ExcelDataSource(30)
                        {
                            ExcelRows = new List<ExcelColumn>()
                            {
                                new ExcelColumn(value:sitem.Abstract){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:""){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER}
                            }
                        };
                        slist.Add(firstRow);
                    }
                    else
                    {
                        ExcelDataSource firstRow = new ExcelDataSource(30)
                        {
                            ExcelRows = new List<ExcelColumn>()
                            {
                                new ExcelColumn(value:sitem.Abstract){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.January.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.February.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.March.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.FirstQuarter.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.April.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.May.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.June.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.SecondQuarter.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.HalfReport.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.July.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.August.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.September.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.ThirdQuarter.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.October.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.November.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.December.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.FourthQuarter.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.LastHalfReport.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER},
                                new ExcelColumn(value:sitem.Total.ToString()){HAlignmentEnum= HAlignmentEnum.CENTER,VAlignmentEnum= VAlignmentEnum.CENTER}
                            }
                        };
                        slist.Add(firstRow);
                    }
                }

                var byteData = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData, "application/octet-stream", ExcelName);
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "OutToExcelEasyReportList");
                var byteData1 = ExcelTempLateHelper.ToExcelExtend(slist);
                return File(byteData1, "application/octet-stream", ExcelName);
            }
        }

        #endregion
    }
}
