Esempio n. 1
0
        public ResultModel Complete_NewVersion(UserModel user, int allotId)
        {
            ResultModel result = new ResultModel();
            DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
            DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
            DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL();
            DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
            DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL();

            try
            {
                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.Complete(user, cashInAllot);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取已生效的收款分配至公司
                    result = cashInCorpDAL.Load(user, cashInAllot.AllotId, NFMT.Common.StatusEnum.已生效);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.CashInCorp> cashInCorps = result.ReturnValue as List<Model.CashInCorp>;
                    if (cashInCorps == null || !cashInCorps.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取收款分配至公司失败";
                        return result;
                    }

                    Model.CashInCorp cashInCorp = cashInCorps.FirstOrDefault(a => a.RefId > 0);

                    //完成收款分配至公司
                    result = cashInCorpDAL.Complete(user, cashInCorp);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取已生效的收款分配至合约
                    result = cashInContractDAL.LoadDetail(user, cashInAllot.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;
                    }

                    Model.CashInContract cashInContract = cashInContracts.FirstOrDefault(a => a.RefId > 0);

                    //完成收款分配至合约
                    result = cashInContractDAL.Complete(user, cashInContract);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取已生效的收款分配至库存
                    result = cashInStcokDAL.LoadByAllot(user, cashInAllot.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.Complete(user, cashInStcok);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取已生效的收款分配至发票
                    result = cashInInvoiceDAL.LoadByAllot(user, cashInAllot.AllotId, StatusEnum.已生效);
                    if (result.ResultStatus == 0)
                    {
                        List<Model.CashInInvoice> cashInInvoices = result.ReturnValue as List<Model.CashInInvoice>;
                        if (cashInInvoices == null || !cashInInvoices.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款分配至发票失败";
                            return result;
                        }

                        foreach (Model.CashInInvoice cashInInvoice in cashInInvoices)
                        {
                            //完成收款分配至发票
                            result = cashInInvoiceDAL.Complete(user, cashInInvoice);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    //获取资金流水
                    result = fundsLogDAL.Get(user, cashInCorp.FundsLogId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //资金流水完成
                    result = fundsLogDAL.Complete(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;
        }
Esempio n. 2
0
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();
            DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL();
            DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL();
            DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL();
            DAL.CashInDAL cashInDAL = new CashInDAL();
            DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
            DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL();

            Model.CashIn cashIn = null;

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = cashinallotDAL.Get(user, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CashInAllot cashInAllot = result.ReturnValue as Model.CashInAllot;
                    if (cashInAllot == null || cashInAllot.AllotId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款分配不存在";
                        return result;
                    }

                    //审核,修改数据状态
                    result = cashinallotDAL.Audit(user, cashInAllot, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //获取已生效的收款分配至公司
                        result = cashInCorpDAL.Load(user, cashInAllot.AllotId, NFMT.Common.StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CashInCorp> cashInCorps = result.ReturnValue as List<Model.CashInCorp>;
                        if (cashInCorps == null || !cashInCorps.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款分配至公司失败";
                            return result;
                        }

                        Model.CashInCorp cashInCorp = cashInCorps.FirstOrDefault(a => a.RefId > 0);

                        //获取已生效的收款分配至合约
                        result = cashInContractDAL.LoadDetail(user, cashInAllot.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;
                        }

                        Model.CashInContract cashInContract = cashInContracts.FirstOrDefault(a => a.RefId > 0);

                        //获取已生效的收款分配至库存
                        result = cashInStcokDAL.LoadByAllot(user, cashInAllot.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;
                        }

                        //获取已生效的收款分配至发票
                        List<Model.CashInInvoice> cashInInvoices = new List<CashInInvoice>();
                        result = cashInInvoiceDAL.LoadByAllot(user, cashInAllot.AllotId, StatusEnum.已生效);
                        if (result.ResultStatus == 0 && result.ReturnValue != null)
                        {
                            cashInInvoices = result.ReturnValue as List<Model.CashInInvoice>;
                            if (cashInInvoices == null || !cashInInvoices.Any())
                            {
                                result.ResultStatus = -1;
                                result.Message = "获取收款分配至发票失败";
                                return result;
                            }
                        }

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

                        cashIn = result.ReturnValue as Model.CashIn;
                        if (cashIn == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取收款失败";
                            return result;
                        }

                        result = fundsLogDAL.Insert(user, new FundsLog()
                        {
                            //FundsLogId
                            ContractId = cashInContract.ContractId,
                            SubId = cashInContract.SubContractId,
                            //InvoiceId
                            LogDate = DateTime.Now,
                            InBlocId = cashIn.CashInBlocId,
                            InCorpId = cashIn.CashInCorpId,
                            InBankId = cashIn.CashInBank,
                            InAccountId = cashIn.CashInAccoontId,
                            OutBlocId = cashIn.PayBlocId,
                            OutCorpId = cashIn.PayCorpId,
                            OutBankId = cashIn.PayBankId,
                            OutBank = cashIn.PayBank,
                            OutAccountId = cashIn.PayAccountId,
                            OutAccount = cashIn.PayAccount,
                            FundsBala = cashInAllot.AllotBala,
                            //FundsType
                            CurrencyId = cashInAllot.CurrencyId,
                            LogDirection = (int)NFMT.WareHouse.LogDirectionEnum.In,
                            LogType = (int)NFMT.WareHouse.LogTypeEnum.收款,
                            //PayMode
                            //IsVirtualPay
                            FundsDesc = cashInAllot.AllotDesc,
                            OpPerson = user.EmpId,
                            LogSourceBase = "NFMT",
                            LogSource = "dbo.Fun_CashInAllot",
                            SourceId = dataSource.RowId,
                            LogStatus = StatusEnum.已生效
                        });
                        if (result.ResultStatus != 0)
                            return result;

                        int fundsLogId = (int)result.ReturnValue;

                        //反向更新流水ID
                        cashInCorp.FundsLogId = fundsLogId;
                        result = cashInCorpDAL.Update(user, cashInCorp);
                        if (result.ResultStatus != 0)
                            return result;

                        cashInContract.FundsLogId = fundsLogId;
                        result = cashInContractDAL.Update(user, cashInContract);
                        if (result.ResultStatus != 0)
                            return result;

                        foreach (Model.CashInStcok cashInStock in cashInStcoks)
                        {
                            cashInStock.FundsLogId = fundsLogId;
                            result = cashInStcokDAL.Update(user, cashInStock);
                            if (result.ResultStatus != 0)
                                return result;
                        }

                        if (cashInInvoices != null && cashInInvoices.Any())
                        {
                            foreach (Model.CashInInvoice cashInInvoice in cashInInvoices)
                            {
                                cashInInvoice.FundsLogId = fundsLogId;
                                result = cashInInvoiceDAL.Update(user, cashInInvoice);
                                if (result.ResultStatus != 0)
                                    return result;
                            }
                        }
                    }

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

            return result;
        }