Beispiel #1
0
        public ResultModel Invalid(UserModel user, int allotId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = cashInAllotDAL.Get(user, allotId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot cashInAllot = result.ReturnValue as Model.CashInAllot;
                    if (cashInAllot == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    //作废付款分配
                    result = cashInAllotDAL.Invalid(user, cashInAllot);
                    if (result.ResultStatus != 0)
                        return result;

                    result = cashinstcokDAL.LoadByAllot(user, allotId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

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

                    foreach (Model.CashInStcok cashInStcok in cashInStcoks)
                    {
                        //作废明细
                        result = cashinstcokDAL.Invalid(user, cashInStcok);
                        if (result.ResultStatus != 0)
                            return result;

                        result = cashInContractDAL.Get(user, cashInStcok.ContractRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInContract cashInContract = result.ReturnValue as Model.CashInContract;
                        if (cashInContract == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取失败";
                            return result;
                        }

                        result = cashInContractDAL.Invalid(user, cashInContract);
                        if (result.ResultStatus != 0)
                            return result;

                        result = cashInCorpDAL.Get(user, cashInContract.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCorp = result.ReturnValue as Model.CashInCorp;
                        if (cashInCorp == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取失败";
                            return result;
                        }

                        result = cashInCorpDAL.Invalid(user, cashInCorp);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                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;
        }
Beispiel #2
0
        /// <summary>
        /// 创建分配公司关联表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <param name="corpDetail"></param>
        /// <returns></returns>
        public ResultModel UpdateCorp(UserModel user, Model.CashInAllot allot, List<Model.CashInCorp> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInCorpDAL corpDAL = new CashInCorpDAL();
                NFMT.Funds.DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    if (details.Count == 0)
                    {
                        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;
                    }

                    //验证明细币种是否相同
                    int currencyId = 0;

                    foreach (Model.CashInCorp 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);

                    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;

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

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

                    foreach (Model.CashInCorp detail in resultDetails)
                    {
                        //验证公司款是否已分配至合约中
                        result = cashInContractDAL.LoadByCorpRefId(user, detail.RefId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInContract> contracts = result.ReturnValue as List<Model.CashInContract>;
                        if (contracts != null && contracts.Count > 0)
                        {
                            result.Message = "公司款已全部或部分已分配至合约中,不能进行修改";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (detail.DetailStatus == StatusEnum.已生效)
                            detail.DetailStatus = StatusEnum.已录入;

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

                    //添加新明细
                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == resultDetails[0].CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.Message = "公司不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInCorp detail in details)
                    {
                        detail.AllotId = resultObj.AllotId;
                        detail.BlocId = corp.ParentId;
                        detail.CorpId = corp.CorpId;
                        detail.DetailStatus = StatusEnum.已生效;

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

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }