コード例 #1
0
        /// <summary>
        /// 获取记录期初数据
        /// </summary>
        /// <param name="settlement">能源结算</param>
        /// <param name="record">能源结算记录</param>
        /// <returns>期初用量,期初金额</returns>
        private Tuple <decimal, decimal> GetBeginData(Settlement settlement, SettlementRecord record)
        {
            TargetRecordBusiness trBusiness = new TargetRecordBusiness();
            var targetRecord = trBusiness.FindByDepartment(settlement.TargetId, record.DepartmentId, record.EnergyType);

            decimal beginQuantum = 0;
            decimal beginAmount  = 0;

            if (string.IsNullOrEmpty(settlement.PreviousId))
            {
                if (targetRecord != null)
                {
                    beginQuantum = targetRecord.PlanQuantum;
                    beginAmount  = targetRecord.PlanAmount;
                }
                else
                {
                    beginQuantum = 0;
                    beginAmount  = 0;
                }
            }
            else
            {
                SettlementBusiness settlementBusiness = new SettlementBusiness();
                var previous = settlementBusiness.FindById(settlement.PreviousId);

                var dal            = this.baseDal as ISettlementRecordRepository;
                var previousRecord = dal.FindOne(previous.Id, record.DepartmentId, record.EnergyType);

                beginQuantum = previousRecord.BeginQuantum - previousRecord.Quantum;
                beginAmount  = previousRecord.BeginAmount - previousRecord.Amount;
            }

            return(new Tuple <decimal, decimal>(beginQuantum, beginAmount));
        }
コード例 #2
0
        /// <summary>
        /// 删除计划指标
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public override bool Delete(Target entity)
        {
            // delete the records
            TargetRecordBusiness recordBusiness = new TargetRecordBusiness();

            recordBusiness.DeleteByTarget(entity.Id);

            return(base.Delete(entity));
        }
コード例 #3
0
        /// <summary>
        /// 添加默认结算记录
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <param name="user">操作用户</param>
        public void Create(SettlementRecord entity, LoginUser user)
        {
            var dal = this.baseDal as ISettlementRecordRepository;

            SettlementBusiness settlementBusiness = new SettlementBusiness();
            var settlement = settlementBusiness.FindById(entity.SettlementId);

            TargetRecordBusiness trBusiness = new TargetRecordBusiness();
            var targetRecord = trBusiness.FindByDepartment(settlement.TargetId, entity.DepartmentId, entity.EnergyType);

            DateTime now = DateTime.Now;

            entity.Quantum  = 0;
            entity.Amount   = 0;
            entity.Status   = 0;
            entity.CreateBy = new UpdateStamp
            {
                UserId = user.Id,
                Name   = user.Name,
                Time   = now
            };
            entity.UpdateBy = new UpdateStamp
            {
                UserId = user.Id,
                Name   = user.Name,
                Time   = now
            };

            var begin = GetBeginData(settlement, entity);

            entity.BeginQuantum = begin.Item1;
            entity.BeginAmount  = begin.Item2;

            dal.Create(entity);
            return;
        }
コード例 #4
0
        /// <summary>
        /// 获取能源结算金额汇总
        /// </summary>
        /// <param name="year">年度</param>
        /// <param name="energyType">能源类型</param>
        /// <param name="department">部门</param>
        /// <returns></returns>
        public SettlementAmountSummary GetDepartmentAmountSummary(int year, EnergyType energyType, Department department)
        {
            SettlementAmountSummary summary = new SettlementAmountSummary();

            summary.DepartmentName = department.Name;
            summary.Year           = year;
            summary.EnergyType     = energyType.DisplayName();

            TargetBusiness targetBusiness = new TargetBusiness();
            var            target         = targetBusiness.FindByYear(year);

            SettlementRecordBusiness srBusiness = new SettlementRecordBusiness();
            var settlements = FindByYear(year).ToList();

            if (settlements.Count == 0)
            {
                return(null);
            }

            bool flag = false;

            for (int i = 0; i < settlements.Count; i++)
            {
                var settle = settlements[i];
                var record = srBusiness.FindByDepartment(settle.Id, department.Id, energyType);
                if (record == null)
                {
                    continue;
                }

                switch (i)
                {
                case 0:
                    summary.UnitPrice    = record.UnitPrice;
                    summary.PlanAmount   = record.BeginAmount;
                    summary.FirstQuarter = record.Amount;
                    break;

                case 1:
                    summary.SecondQuarter = record.Amount;
                    break;

                case 2:
                    summary.ThirdQuarter = record.Amount;
                    break;

                case 3:
                    summary.FourthQuarter = record.Amount;
                    break;
                }
                flag = true;
            }

            summary.TotalAmount  = summary.FirstQuarter + summary.SecondQuarter + summary.ThirdQuarter + summary.FourthQuarter;
            summary.RemainAmount = summary.PlanAmount - summary.TotalAmount;

            if (summary.RemainAmount < 0)
            {
                TargetRecordBusiness trBusiness = new TargetRecordBusiness();
                var targetRecord = trBusiness.FindByDepartment(target.Id, department.Id, (int)energyType);

                summary.SchoolTake = Math.Round(-summary.RemainAmount * targetRecord.SchoolTake);
                summary.SelfTake   = -summary.RemainAmount - summary.SchoolTake;
            }

            if (!flag)
            {
                return(null);
            }

            return(summary);
        }
コード例 #5
0
        /// <summary>
        /// 获取部门结算汇总
        /// </summary>
        /// <param name="year">年度</param>
        /// <param name="energyType">能源类型</param>
        /// <param name="department">部门</param>
        /// <returns></returns>
        public DepartmentSettlementSummary GetDepartmentSummary(int year, EnergyType energyType, Department department)
        {
            DepartmentSettlementSummary data = new DepartmentSettlementSummary();

            data.Year           = year;
            data.DepartmentId   = department.Id;
            data.DepartmentName = department.Name;
            data.EnergyType     = energyType.DisplayName();
            data.SettleQuantum  = 0;
            data.SettleAmount   = 0;

            TargetBusiness targetBusiness = new TargetBusiness();
            var            target         = targetBusiness.FindByYear(year);

            SettlementRecordBusiness srBusiness = new SettlementRecordBusiness();
            var settlements = FindByYear(year).ToList();

            if (settlements.Count == 0)
            {
                return(null);
            }

            bool flag = false;

            for (int i = 0; i < settlements.Count; i++)
            {
                var settle = settlements[i];
                var record = srBusiness.FindByDepartment(settle.Id, department.Id, energyType);
                if (record == null)
                {
                    continue;
                }

                if (i == 0)
                {
                    data.PlanQuantum = record.BeginQuantum;
                    data.PlanAmount  = record.BeginAmount;
                    data.UnitPrice   = record.UnitPrice;
                }

                data.SettleQuantum += record.Quantum;
                data.SettleAmount  += record.Amount;
                flag = true;
            }

            if (!flag)
            {
                return(null);
            }

            data.RemainQuantum = data.PlanQuantum - data.SettleQuantum;
            data.RemainAmount  = data.PlanAmount - data.SettleAmount;

            if (data.RemainAmount < 0)
            {
                TargetRecordBusiness trBusiness = new TargetRecordBusiness();
                var targetRecord = trBusiness.FindByDepartment(target.Id, department.Id, (int)energyType);
                if (targetRecord == null)
                {
                    data.SchoolTake = 0;
                    data.SelfTake   = -data.RemainAmount;
                }
                else
                {
                    data.SchoolTake = Math.Round(-data.RemainAmount * targetRecord.SchoolTake);
                    data.SelfTake   = -data.RemainAmount - data.SchoolTake;
                }
            }

            return(data);
        }