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

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

                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.Message = "库存流水不存在";
                        result.ResultStatus = -1;
                        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.Message = "子合约不存在";
                        result.ResultStatus = -1;
                        return result;
                    }

                    allot.AllotBala = details.Sum(temp => temp.AllotBala);
                    allot.Alloter = user.EmpId;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.AllotTime = DateTime.Now;
                    allot.AllotType = (int)NFMT.Funds.CashInAllotTypeEnum.Stock;
                    allot.CurrencyId = sub.SettleCurrency;

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

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

                    //获取外部公司
                    NFMT.Contract.DAL.ContractCorporationDetailDAL corpDAL = new Contract.DAL.ContractCorporationDetailDAL();
                    result = corpDAL.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.CashInCorp corpDetail in details)
                    {
                        NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corpDetail.CorpId);
                        if (corp == null || corp.CorpId <= 0)
                        {
                            result.Message = "收款分配公司不存在";
                            result.ResultStatus = -1;
                            return result;
                        }

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

                        result = cashInDAL.Get(user, corpDetail.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;
                        }

                        corpDetail.AllotId = allotId;
                        corpDetail.BlocId = corp.ParentId;
                        corpDetail.CashInId = cashIn.CashInId;
                        corpDetail.CorpId = corp.CorpId;
                        corpDetail.DetailStatus = StatusEnum.已生效;
                        corpDetail.IsShare = false;

                        result = cashInCorpDAL.Insert(user, corpDetail);
                        if (result.ResultStatus != 0)
                            return result;

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

                        Model.CashInContract cashInContract = new CashInContract();
                        cashInContract.AllotBala = corpDetail.AllotBala;
                        cashInContract.AllotId = corpDetail.AllotId;
                        cashInContract.CashInId = corpDetail.CashInId;
                        cashInContract.ContractId = sub.ContractId;
                        cashInContract.CorpRefId = corpRefId;
                        cashInContract.DetailStatus = StatusEnum.已生效;
                        cashInContract.SubContractId = sub.SubId;

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

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

                        Model.CashInStcok cashInStock = new CashInStcok();
                        cashInStock.AllotBala = cashInContract.AllotBala;
                        cashInStock.AllotId = cashInContract.AllotId;
                        cashInStock.CashInId = cashInContract.CashInId;
                        cashInStock.ContractRefId = contractRefId;
                        cashInStock.CorpRefId = cashInContract.CorpRefId;
                        cashInStock.DetailStatus = StatusEnum.已生效;
                        cashInStock.StockId = stockLog.StockId;
                        cashInStock.StockLogId = stockLog.StockLogId;
                        cashInStock.StockNameId = stockLog.StockNameId;

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

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

            return result;
        }
示例#2
0
        public ResultModel LoadByCorpRefId(UserModel user, int corpRefId, StatusEnum status = StatusEnum.已生效)
        {
            ResultModel result = new ResultModel();
            try
            {
                string cmdText = string.Format("select * from dbo.Fun_CashInContract_Ref where CorpRefId = {0} and DetailStatus={1}", corpRefId, (int)status);
                DataTable dt = SqlHelper.ExecuteDataTable(ConnectString, cmdText, null, CommandType.Text);

                List<CashInContract> cashInContracts = new List<CashInContract>();

                foreach (DataRow dr in dt.Rows)
                {
                    CashInContract cashincontract = new CashInContract();
                    cashincontract.RefId = Convert.ToInt32(dr["RefId"]);

                    if (dr["CorpRefId"] != DBNull.Value)
                    {
                        cashincontract.CorpRefId = Convert.ToInt32(dr["CorpRefId"]);
                    }
                    if (dr["AllotId"] != DBNull.Value)
                    {
                        cashincontract.AllotId = Convert.ToInt32(dr["AllotId"]);
                    }
                    if (dr["CashInId"] != DBNull.Value)
                    {
                        cashincontract.CashInId = Convert.ToInt32(dr["CashInId"]);
                    }
                    if (dr["ContractId"] != DBNull.Value)
                    {
                        cashincontract.ContractId = Convert.ToInt32(dr["ContractId"]);
                    }
                    if (dr["SubContractId"] != DBNull.Value)
                    {
                        cashincontract.SubContractId = Convert.ToInt32(dr["SubContractId"]);
                    }
                    if (dr["AllotBala"] != DBNull.Value)
                    {
                        cashincontract.AllotBala = Convert.ToDecimal(dr["AllotBala"]);
                    }
                    if (dr["DetailStatus"] != DBNull.Value)
                    {
                        cashincontract.DetailStatus = (Common.StatusEnum)Enum.Parse(typeof(Common.StatusEnum), dr["DetailStatus"].ToString());
                    }
                    cashInContracts.Add(cashincontract);
                }
                result.AffectCount = dt.Rows.Count;
                result.Message = "获取列表成功";
                result.ResultStatus = 0;
                result.ReturnValue = cashInContracts;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return result;
        }
示例#3
0
        public override IModel CreateModel(DataRow dr)
        {
            CashInContract cashincontract = new CashInContract();

            cashincontract.RefId = Convert.ToInt32(dr["RefId"]);

            if (dr["CorpRefId"] != DBNull.Value)
            {
                cashincontract.CorpRefId = Convert.ToInt32(dr["CorpRefId"]);
            }

            if (dr["AllotId"] != DBNull.Value)
            {
                cashincontract.AllotId = Convert.ToInt32(dr["AllotId"]);
            }

            if (dr["CashInId"] != DBNull.Value)
            {
                cashincontract.CashInId = Convert.ToInt32(dr["CashInId"]);
            }

            if (dr["ContractId"] != DBNull.Value)
            {
                cashincontract.ContractId = Convert.ToInt32(dr["ContractId"]);
            }

            if (dr["SubContractId"] != DBNull.Value)
            {
                cashincontract.SubContractId = Convert.ToInt32(dr["SubContractId"]);
            }

            if (dr["AllotBala"] != DBNull.Value)
            {
                cashincontract.AllotBala = Convert.ToDecimal(dr["AllotBala"]);
            }

            if (dr["DetailStatus"] != DBNull.Value)
            {
                cashincontract.DetailStatus = (Common.StatusEnum)Convert.ToInt32(dr["DetailStatus"]);
            }

            if (dr["FundsLogId"] != DBNull.Value)
            {
                cashincontract.FundsLogId = Convert.ToInt32(dr["FundsLogId"]);
            }

            return cashincontract;
        }
示例#4
0
        public override IModel CreateModel(SqlDataReader dr)
        {
            CashInContract cashincontract = new CashInContract();

            int indexRefId = dr.GetOrdinal("RefId");
            cashincontract.RefId = Convert.ToInt32(dr[indexRefId]);

            int indexCorpRefId = dr.GetOrdinal("CorpRefId");
            if (dr["CorpRefId"] != DBNull.Value)
            {
                cashincontract.CorpRefId = Convert.ToInt32(dr[indexCorpRefId]);
            }

            int indexAllotId = dr.GetOrdinal("AllotId");
            if (dr["AllotId"] != DBNull.Value)
            {
                cashincontract.AllotId = Convert.ToInt32(dr[indexAllotId]);
            }

            int indexCashInId = dr.GetOrdinal("CashInId");
            if (dr["CashInId"] != DBNull.Value)
            {
                cashincontract.CashInId = Convert.ToInt32(dr[indexCashInId]);
            }

            int indexContractId = dr.GetOrdinal("ContractId");
            if (dr["ContractId"] != DBNull.Value)
            {
                cashincontract.ContractId = Convert.ToInt32(dr[indexContractId]);
            }

            int indexSubContractId = dr.GetOrdinal("SubContractId");
            if (dr["SubContractId"] != DBNull.Value)
            {
                cashincontract.SubContractId = Convert.ToInt32(dr[indexSubContractId]);
            }

            int indexAllotBala = dr.GetOrdinal("AllotBala");
            if (dr["AllotBala"] != DBNull.Value)
            {
                cashincontract.AllotBala = Convert.ToDecimal(dr[indexAllotBala]);
            }

            int indexDetailStatus = dr.GetOrdinal("DetailStatus");
            if (dr["DetailStatus"] != DBNull.Value)
            {
                cashincontract.DetailStatus = (Common.StatusEnum)Convert.ToInt32(dr[indexDetailStatus]);
            }

            int indexFundsLogId = dr.GetOrdinal("FundsLogId");
            if (dr["FundsLogId"] != DBNull.Value)
            {
                cashincontract.FundsLogId = Convert.ToInt32(dr[indexFundsLogId]);
            }

            return cashincontract;
        }
示例#5
0
        public ResultModel CreateDirectContract(UserModel user, CashInAllot allot, List<CashInContractDirect> directs, int subId)
        {
            ResultModel result = new ResultModel();

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

                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;
                    }

                    //判断合约状态

                    //获取合约对方抬头
                    result = subDAL.GetContractOutCorp(user, sub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    DataTable outCorpTable = result.ReturnValue as DataTable;

                    if (outCorpTable == null || outCorpTable.Rows.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约对方抬头不存在,收款分配失败";
                        return result;
                    }

                    List<int> outCorpIds = new List<int>();
                    foreach (DataRow dr in outCorpTable.Rows)
                    {
                        int outCorpId = 0;
                        if (dr["CorpId"] == DBNull.Value || !int.TryParse(dr["CorpId"].ToString(), out outCorpId) || outCorpId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "合约对方抬头获取失败";
                            return result;
                        }

                        outCorpIds.Add(outCorpId);
                    }

                    List<Model.CashInCorp> cashCorps = new List<CashInCorp>();

                    foreach (CashInContractDirect direct in directs)
                    {
                        //判断收款分配到的对方抬头是否包含在合约抬头中
                        if (!outCorpIds.Contains(direct.AllotCorpId))
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款分配选择的分配公司不在该合约对方抬头中,收款分配失败";
                            return result;
                        }

                        //判断收款登记的币种是否和合约币种相同
                        result = cashInDAL.Get(user, direct.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 (cashIn.CurrencyId != sub.SettleCurrency)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款登记币种与合约币种不相同,分配错误";
                            return result;
                        }

                        CashInCorp cashCorp = new CashInCorp();

                        NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == direct.AllotCorpId);
                        if (corp == null || corp.CorpId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款分配选择的分配公司不存在,分配失败";
                            return result;
                        }

                        cashCorp.AllotBala = direct.AllotBala;
                        cashCorp.BlocId = corp.ParentId;
                        cashCorp.CashInId = direct.CashInId;
                        cashCorp.CorpId = corp.CorpId;
                        cashCorp.DetailStatus = StatusEnum.已生效;
                        cashCorp.IsShare = false;
                        cashCorp.AllotId = 0;

                        cashCorps.Add(cashCorp);

                    }

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

                    allot.AllotBala = sumBala;
                    allot.Alloter = user.EmpId;
                    allot.AllotStatus = StatusEnum.已录入;
                    allot.AllotTime = DateTime.Now;
                    allot.AllotType = (int)NFMT.Funds.CashInAllotTypeEnum.Contract;
                    allot.CurrencyId = sub.SettleCurrency;

                    //新增主分配
                    result = cashInAllotDAL.Insert(user, allot);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //新增公司收款分配
                    foreach (Model.CashInCorp cd in cashCorps)
                    {
                        cd.AllotId = allotId;
                        result = cashInCorpDAL.Insert(user, cd);
                        if (result.ResultStatus != 0)
                            return result;

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

                        CashInContract cashContract = new CashInContract();

                        cashContract.AllotBala = cd.AllotBala;
                        cashContract.AllotId = cd.AllotId;
                        cashContract.CashInId = cd.CashInId;
                        cashContract.ContractId = sub.ContractId;
                        cashContract.CorpRefId = refId;
                        cashContract.DetailStatus = StatusEnum.已生效;
                        cashContract.SubContractId = sub.SubId;

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

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

            return result;
        }