Beispiel #1
0
        /// <summary>
        /// 修改分配主表和明细表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel UpdateMain(UserModel user, Model.CashInAllot allot, ref List<Model.CashInAllotDetail> details)
        {
            ResultModel result = new ResultModel();

            if (details.Count == 0)
            {
                result.ResultStatus = -1;
                result.Message = "修改收款分配失败,未分配任何款项";
                return result;
            }

            //验证明细币种是否相同
            int currencyId = 0;
            NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();
            foreach (Model.CashInAllotDetail detail in details)
            {
                result = cashInDAL.Get(user, detail.CashInId);
                if (result.ResultStatus != 0)
                    return result;

                Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                if (cashIn == null || cashIn.CashInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记不存在";
                    return result;
                }

                if (cashIn.CashInStatus != StatusEnum.已生效)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记状态错误";
                    return result;
                }

                if (currencyId == 0)
                    currencyId = cashIn.CurrencyId;

                if (currencyId != cashIn.CurrencyId)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记币种不相同";
                    return result;
                }
            }

            //获取分配
            result = this.cashinallotDAL.Get(user, allot.AllotId);
            if (result.ResultStatus != 0)
                return result;

            Model.CashInAllot resultObj = result.ReturnValue as Model.CashInAllot;
            if (resultObj == null || resultObj.AllotId <= 0)
            {
                result.Message = "分配不存在,不能进行修改";
                result.ResultStatus = -1;
                return result;
            }

            //更新主表
            decimal sumBala = details.Sum(temp => temp.AllotBala);

            resultObj.AllotBala = sumBala;
            resultObj.Alloter = user.EmpId;
            resultObj.AllotTime = DateTime.Now;
            resultObj.CurrencyId = currencyId;

            result = this.cashinallotDAL.Update(user, resultObj);
            if (result.ResultStatus != 0)
                return result;

            //获取原有明细并作废
            DAL.CashInAllotDetailDAL detailDAL = new CashInAllotDetailDAL();
            result = detailDAL.Load(user, resultObj.AllotId);
            if (result.ResultStatus != 0)
                return result;

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

            foreach (Model.CashInAllotDetail detail in resultDetails)
            {
                if (detail.DetailStatus == StatusEnum.已生效)
                    detail.DetailStatus = StatusEnum.已录入;

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

            foreach (Model.CashInAllotDetail detail in details)
            {
                int detailId = 0;

                detail.DetailStatus = StatusEnum.已生效;
                detail.AllotId = resultObj.AllotId;
                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId))
                {
                    result.ResultStatus = -1;
                    result.Message = "收款分配明细新增失败";
                    return result;
                }

                detail.DetailId = detailId;
            }

            return result;
        }
Beispiel #2
0
        /// <summary>
        /// 创建分配主表和明细表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel CreateMain(UserModel user, ref Model.CashInAllot allot, ref List<Model.CashInAllotDetail> details)
        {
            ResultModel result = new ResultModel();

            if (details.Count == 0)
            {
                result.ResultStatus = -1;
                result.Message = "新增收款分配失败,未分配任何款项";
                return result;
            }

            //验证明细币种是否相同
            int currencyId = 0;
            NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();
            foreach (Model.CashInAllotDetail detail in details)
            {
                result = cashInDAL.Get(user, detail.CashInId);
                if (result.ResultStatus != 0)
                    return result;

                Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                if (cashIn == null || cashIn.CashInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记不存在";
                    return result;
                }

                if (cashIn.CashInStatus != StatusEnum.已生效)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记状态错误";
                    return result;
                }

                if (currencyId == 0)
                    currencyId = cashIn.CurrencyId;

                if (currencyId != cashIn.CurrencyId)
                {
                    result.ResultStatus = -1;
                    result.Message = "分配的收款登记币种不相同";
                    return result;
                }
            }

            decimal sumBala = details.Sum(temp => temp.AllotBala);

            allot.AllotBala = sumBala;
            allot.AllotStatus = StatusEnum.已录入;
            allot.Alloter = user.EmpId;
            allot.AllotTime = DateTime.Now;
            allot.CurrencyId = currencyId;

            result = this.cashinallotDAL.Insert(user, allot);
            if (result.ResultStatus != 0)
                return result;

            int allotId = 0;
            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId))
            {
                result.ResultStatus = -1;
                result.Message = "收款分配失败";
                return result;
            }

            DAL.CashInAllotDetailDAL detailDAL = new CashInAllotDetailDAL();
            foreach (Model.CashInAllotDetail detail in details)
            {
                int detailId = 0;

                detail.DetailStatus = StatusEnum.已生效;
                detail.AllotId = allotId;
                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId))
                {
                    result.ResultStatus = -1;
                    result.Message = "收款分配明细新增失败";
                    return result;
                }

                detail.DetailId = detailId;
            }

            return result;
        }