示例#1
0
        public ResultModel CreateStock(UserModel user, Model.CashInAllot allot, List<Model.CashInStcok> details, int stockLogId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                DAL.CashInDAL cashInDAL = new CashInDAL();
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取库存流水
                    result = stockLogDAL.Get(user, stockLogId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.Model.StockLog;
                    if (stockLog == null || stockLog.StockLogId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存流水不存在";
                        return result;
                    }

                    //获取库存
                    result = stockDAL.Get(user, stockLog.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                    if (stock == null || stock.StockId <= 0)
                    {
                        result.Message = "库存不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取合约
                    result = subDAL.Get(user, stockLog.SubContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    if (sub.SubStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约状态不允许分配收款";
                        return result;
                    }

                    //获取外部公司
                    result = corpDetailDAL.LoadCorpListByContractId(user, sub.ContractId, false);
                    if (result.ResultStatus != 0)
                        return result;
                    List<NFMT.Contract.Model.ContractCorporationDetail> outCorps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                    if (outCorps == null)
                    {
                        result.Message = "合约对方抬头获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    foreach (Model.CashInStcok 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.Message = "收款登记不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //收款登记与合约币种验证
                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "收款登记币种与合约币种不相同";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //获取合约收款分配
                        result = cashInContractDAL.Get(user, detail.ContractRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInContract cashInContract = result.ReturnValue as Model.CashInContract;
                        if (cashInContract == null || cashInContract.RefId <= 0)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashInContract.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            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 || cashInCorp.RefId <= 0 || cashInCorp.DetailStatus != StatusEnum.已生效)
                        {
                            result.Message = "收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //验证公司抬头
                        if (!outCorps.Any(temp => temp.CorpId == cashInCorp.CorpId))
                        {
                            result.Message = "收款分配公司不在合约对方抬头,收款分配失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        //新增库存收款分配
                        detail.AllotId = cashInContract.AllotId;
                        detail.CashInId = cashInContract.CashInId;
                        detail.ContractRefId = cashInContract.RefId;
                        detail.CorpRefId = cashInContract.CorpRefId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.StockId = stock.StockId;
                        detail.StockLogId = stockLog.StockLogId;
                        detail.StockNameId = stock.StockNameId;

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

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

            return result;
        }
示例#2
0
        public ResultModel CompleteCancel(UserModel user, int allotId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
                Model.FundsLog fundsLog = null;
                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.CompleteCancel(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.CompleteCancel(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.CompleteCancel(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.CompleteCancel(user, cashInCorp);
                        if (result.ResultStatus != 0)
                            return result;

                        result = fundsLogDAL.Get(user, cashInStcok.FundsLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        fundsLog = result.ReturnValue as Model.FundsLog;
                        if (fundsLog == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取资金流水失败";
                            return result;
                        }

                        //完成撤销流水
                        result = fundsLogDAL.CompleteCancel(user, fundsLog);
                        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;
        }
示例#3
0
        public ResultModel UpdateContract(UserModel user, List<CashInContract> details, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInDAL cashInDAL = new CashInDAL();
                DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL();
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                DAL.CashInStcokDAL cashInStockDAL = new CashInStcokDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, subId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.Message = "子合约不存在,不能进行修改";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //获取当前合约下的有效明细
                    result = this.cashincontractDAL.Load(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInContract> resultDetails = result.ReturnValue as List<Model.CashInContract>;

                    if (resultDetails == null)
                    {
                        result.Message = "获取明细失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //作废现有有效明细
                    foreach (Model.CashInContract nd in resultDetails)
                    {
                        //验证当前合约明细是否已分配至库存中
                        result = cashInStockDAL.LoadByContractRefId(user, nd.RefId);
                        if (result.ResultStatus != 0)
                            return result;

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

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

                        result = this.cashincontractDAL.Invalid(user, nd);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //新增明细
                    foreach (Model.CashInContract det in details)
                    {
                        //获取公司分配
                        result = cashInCorpDAL.Get(user, det.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCrop = result.ReturnValue as Model.CashInCorp;
                        if (cashInCrop == null || cashInCrop.RefId <= 0)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

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

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

                        //获取收款登记
                        result = cashInDAL.Get(user, cashInCrop.CashInId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashIn cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null || cashIn.CashInId <= 0)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        if (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.Message = "修改失败";
                            result.ResultStatus = -1;
                            return result;
                        }

                        det.AllotId = cashInCrop.AllotId;
                        det.CorpRefId = cashInCrop.RefId;
                        det.ContractId = sub.ContractId;
                        det.CashInId = cashIn.CashInId;
                        det.CorpRefId = cashInCrop.RefId;
                        det.DetailStatus = StatusEnum.已生效;
                        det.SubContractId = sub.SubId;

                        result = this.cashincontractDAL.Insert(user, det);

                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

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

            return result;
        }
示例#4
0
        public ResultModel CreateContract(UserModel user, List<CashInContract> details, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取子合约
                    result = subDAL.Get(user, subId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub == null || sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    //验证子合约状态

                    foreach (CashInContract detail in details)
                    {
                        //获取公司分配
                        result = cashInCorpDAL.Get(user, detail.CorpRefId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.CashInCorp cashInCorp = result.ReturnValue as Model.CashInCorp;
                        if (cashInCorp == null || cashInCorp.RefId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "公司款不存在";
                            return result;
                        }

                        if (cashInCorp.DetailStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "公司款状态错误,分配失败";
                            return result;
                        }

                        detail.AllotId = cashInCorp.AllotId;
                        detail.CashInId = cashInCorp.CashInId;
                        detail.ContractId = sub.ContractId;
                        detail.CorpRefId = cashInCorp.RefId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.SubContractId = sub.SubId;

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

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

            return result;
        }
示例#5
0
        public ResultModel Invalid(UserModel user, int allotId)
        {
            ResultModel result = new ResultModel();

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

                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 = cashincontractDAL.LoadDetail(user, allotId, StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

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

                    foreach (Model.CashInContract cashInContract in cashInContracts)
                    {
                        //作废 付款分配合约
                        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;
        }