Ejemplo n.º 1
0
        public ResultModel Update(UserModel user, NFMT.DoPrice.Model.Interest interest, List<NFMT.DoPrice.Model.InterestDetail> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.InterestDetailDAL detailDAL = new InterestDetailDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    if (details == null || details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "请添加利息信息";
                        return result;
                    }

                    //获取结算
                    result = this.interestDAL.Get(user, interest.InterestId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Interest resultInterest = result.ReturnValue as Model.Interest;
                    if (resultInterest == null || resultInterest.InterestId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "结息不存在";
                        return result;
                    }

                    //本金计息方式下,计算当前结息成本
                    if (resultInterest.InterestStyle == (int)NFMT.DoPrice.InterestStyleEnum.本金计息)
                    {
                        decimal curCapital = details.Where(temp => temp.InterestType != (int)NFMT.DoPrice.InterestTypeEnum.差额计息).Sum(temp => temp.StockBala);
                        interest.CurCapital = Math.Round(curCapital, 2, MidpointRounding.AwayFromZero);

                        decimal sumCapital = details.Sum(temp => temp.StockBala);
                        if (sumCapital != interest.PayCapital)
                        {
                            result.Message = "结算总金额必须等于预付本金";
                            result.ResultStatus = -1;
                            return result;
                        }
                    }

                    decimal sumInterestBala = details.Sum(temp => temp.InterestBala);
                    if (sumInterestBala != interest.InterestBala)
                    {
                        result.Message = "利息明细之和必须等于利息总额";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //赋值主表
                    resultInterest.CurCapital = interest.CurCapital;
                    resultInterest.InterestAmount = interest.InterestAmount;
                    resultInterest.InterestAmountDay = interest.InterestAmountDay;
                    resultInterest.InterestBala = interest.InterestBala;
                    resultInterest.InterestDate = interest.InterestDate;
                    resultInterest.InterestPrice = interest.InterestPrice;
                    resultInterest.InterestRate = interest.InterestRate;
                    resultInterest.Memo = interest.Memo;
                    resultInterest.OtherPrice = interest.OtherPrice;
                    resultInterest.PayCapital = interest.PayCapital;
                    resultInterest.Premium = interest.Premium;
                    resultInterest.PricingUnit = interest.PricingUnit;

                    result = this.interestDAL.Update(user, resultInterest);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废原有明细
                    result = detailDAL.Load(user, resultInterest.InterestId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.InterestDetail> resultDetails = result.ReturnValue as List<Model.InterestDetail>;
                    if (resultDetails == null || resultDetails.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "结息明细获取失败";
                        return result;
                    }

                    foreach (Model.InterestDetail detail in resultDetails)
                    {
                        detail.DetailStatus = StatusEnum.已录入;
                        result = detailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //添加新明细
                    foreach (NFMT.DoPrice.Model.InterestDetail detail in details)
                    {
                        detail.InterestId = resultInterest.InterestId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.SubContractId = interest.SubContractId;
                        detail.ContractId = interest.ContractId;
                        detail.InterestPrice = interest.InterestPrice;
                        detail.PricingUnit = interest.PricingUnit;
                        detail.Premium = interest.Premium;
                        detail.OtherPrice = interest.OtherPrice;

                        if (detail.InterestType != (int)InterestTypeEnum.差额计息)
                        {
                            if (resultInterest.InterestStyle == (int)InterestStyleEnum.本金计息)
                                detail.InterestType = (int)InterestTypeEnum.本金计息;
                            else
                                detail.InterestType = (int)InterestTypeEnum.货值计息;

                        }
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (this.Log.IsInfoEnabled)
                    this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Ejemplo n.º 2
0
        public ResultModel Invalid(UserModel user, int interestId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.InterestDetailDAL detailDAL = new InterestDetailDAL();
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.interestDAL.Get(user, interestId);
                    if (result.ResultStatus != 0)
                        return result;
                    Model.Interest interest = result.ReturnValue as Model.Interest;
                    if (interest == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能作废";
                        return result;
                    }

                    //获取明细
                    result = detailDAL.Load(user, interest.InterestId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.InterestDetail> details = result.ReturnValue as List<Model.InterestDetail>;
                    if (details == null || details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "结息明细获取失败";
                        return result;
                    }

                    //作废明细
                    foreach (Model.InterestDetail detail in details)
                    {
                        detail.DetailStatus = StatusEnum.已录入;
                        result = detailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //作废主表
                    result = this.interestDAL.Invalid(user, interest);
                    if (result.ResultStatus != 0)
                        return result;

                    if (result.ResultStatus == 0)
                        result.Message = "作废成功";

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }