public ResultModel Update(UserModel user, Model.CashInAllot cashInAllot, Model.CashInCorp cashInCorp, Model.CashInContract cashInContract, List<Model.CashInStcok> cashInStocks, List<NFMT.Funds.Model.CashInInvoice> cashInInvoices) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = cashinallotDAL.Get(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; Model.CashInAllot cashInAllotres = result.ReturnValue as Model.CashInAllot; if (cashInAllotres == null) { result.ResultStatus = -1; result.Message = "获取收款分配失败"; return result; } cashInAllotres.Alloter = user.EmpId; cashInAllotres.AllotTime = DateTime.Now; cashInAllotres.AllotBala = cashInAllot.AllotBala; cashInAllotres.AllotType = cashInAllot.AllotType; cashInAllotres.CurrencyId = cashInAllot.CurrencyId; cashInAllotres.AllotDesc = cashInAllot.AllotDesc; result = cashinallotDAL.Update(user, cashInAllotres); if (result.ResultStatus != 0) return result; //作废收款分配至公司 DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL(); result = cashInCorpDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; result = cashInCorpDAL.Insert(user, cashInCorp); if (result.ResultStatus != 0) return result; int corpRefId = (int)result.ReturnValue; //作废收款分配至合同 DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL(); result = cashInContractDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; cashInContract.CorpRefId = corpRefId; result = cashInContractDAL.Insert(user, cashInContract); if (result.ResultStatus != 0) return result; int contractRefId = (int)result.ReturnValue; if (cashInStocks != null && cashInStocks.Any()) { DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL(); result = cashInStcokDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; foreach (Model.CashInStcok cashInStcok in cashInStocks) { cashInStcok.CashInId = cashInCorp.CashInId; cashInStcok.AllotId = cashInAllot.AllotId; cashInStcok.CorpRefId = corpRefId; cashInStcok.ContractRefId = contractRefId; result = cashInStcokDAL.Insert(user, cashInStcok); if (result.ResultStatus != 0) return result; } } if (cashInInvoices != null && cashInInvoices.Any()) { DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL(); result = cashInInvoiceDAL.InvalidAll(user, cashInAllot.AllotId); if (result.ResultStatus != 0) return result; foreach (Model.CashInInvoice cashInInvoice in cashInInvoices) { cashInInvoice.CashInId = cashInCorp.CashInId; cashInInvoice.AllotId = cashInAllot.AllotId; cashInInvoice.CorpRefId = corpRefId; cashInInvoice.ContractRefId = contractRefId; result = cashInInvoiceDAL.Insert(user, cashInInvoice); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; result.ResultStatus = -1; } 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; }
public ResultModel Create(UserModel user, Model.CashInAllot cashInAllot, Model.CashInCorp cashInCorp, Model.CashInContract cashInContract, List<Model.CashInStcok> cashInStocks, List<NFMT.Funds.Model.CashInInvoice> cashInInvoices) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = cashinallotDAL.Insert(user, cashInAllot); if (result.ResultStatus != 0) return result; int cashInAllotId = (int)result.ReturnValue; cashInCorp.AllotId = cashInAllotId; DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL(); result = cashInCorpDAL.Insert(user, cashInCorp); if (result.ResultStatus != 0) return result; int corpRefId = (int)result.ReturnValue; int cashInContractCId = 0; if (cashInContract.SubContractId > 0) { NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); result = contractDAL.Get(user, cashInContract.SubContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract; if (contract == null || contract.ContractId <= 0) { result.ResultStatus = -1; result.Message = "获取合约失败"; return result; } cashInContractCId = contract.ContractId; } cashInContract.CorpRefId = corpRefId; cashInContract.AllotId = cashInAllotId; cashInContract.ContractId = cashInContractCId; DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL(); result = cashInContractDAL.Insert(user, cashInContract); if (result.ResultStatus != 0) return result; int contractRefId = (int)result.ReturnValue; if (cashInStocks != null && cashInStocks.Any()) { DAL.CashInStcokDAL cashInStcokDAL = new CashInStcokDAL(); foreach (Model.CashInStcok cashInStcok in cashInStocks) { cashInStcok.CashInId = cashInCorp.CashInId; cashInStcok.AllotId = cashInAllotId; cashInStcok.CorpRefId = corpRefId; cashInStcok.ContractRefId = contractRefId; result = cashInStcokDAL.Insert(user, cashInStcok); if (result.ResultStatus != 0) return result; } } if (cashInInvoices != null && cashInInvoices.Any()) { DAL.CashInInvoiceDAL cashInInvoiceDAL = new CashInInvoiceDAL(); foreach (Model.CashInInvoice cashInInvoice in cashInInvoices) { cashInInvoice.CashInId = cashInCorp.CashInId; cashInInvoice.AllotId = cashInAllotId; cashInInvoice.CorpRefId = corpRefId; cashInInvoice.ContractRefId = contractRefId; result = cashInInvoiceDAL.Insert(user, cashInInvoice); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; result.ResultStatus = -1; } 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; }
public ResultModel Create(UserModel user, CashInAllot allot, List<CashInContractDirect> directs, int subId) { ResultModel result = new ResultModel(); try { NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL(); DAL.CashInDAL cashInDAL = new CashInDAL(); DAL.CashInAllotDAL cashInAllotDAL = new CashInAllotDAL(); DAL.CashInCorpDAL cashInCorpDAL = new CashInCorpDAL(); DAL.CashInContractDAL cashInContractDAL = new CashInContractDAL(); DAL.CashInStcokDAL cashInStockDAL = new CashInStcokDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { if (directs == null || directs.Count == 0) { result.ResultStatus = -1; result.Message = "未分配任务收款"; return result; } //获取子合约 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; } //判断合约状态 if (sub.SubStatus != StatusEnum.已生效) { 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); } //获取合约关联库存信息 result = stockLogDAL.LoadStockLogBySubId(user, sub.SubId); if (result.ResultStatus != 0) return result; List<NFMT.WareHouse.Model.StockLog> stockLogs = result.ReturnValue as List<NFMT.WareHouse.Model.StockLog>; if (stockLogs == null) { result.ResultStatus = -1; result.Message = "合约库存流水获取失败"; return result; } 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 (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 = allotId; result = cashInCorpDAL.Insert(user, cashCorp); if (result.ResultStatus != 0) return result; int corpRefId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out corpRefId) || corpRefId <= 0) { result.ResultStatus = -1; result.Message = "公司收款分配新增失败"; return result; } //新增合约分配 CashInContract cashContract = new CashInContract(); cashContract.AllotBala = cashCorp.AllotBala; cashContract.AllotId = cashCorp.AllotId; cashContract.CashInId = cashCorp.CashInId; cashContract.ContractId = sub.ContractId; cashContract.CorpRefId = corpRefId; cashContract.DetailStatus = StatusEnum.已生效; cashContract.SubContractId = sub.SubId; result = this.cashincontractDAL.Insert(user, cashContract); if (result.ResultStatus != 0) return result; int contractRefId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out contractRefId) || contractRefId <= 0) { result.ResultStatus = -1; result.Message = "合约收款分配新增失败"; return result; } //新增库存分配 if (direct.StockLogId > 0) { result = stockLogDAL.Get(user, direct.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; } if (stockLog.SubContractId != sub.SubId) { result.ResultStatus = -1; result.Message = "库存流水与合约不匹配"; return result; } Model.CashInStcok cashInStock = new CashInStcok(); cashInStock.AllotBala = cashContract.AllotBala; cashInStock.AllotId = cashContract.AllotId; cashInStock.CashInId = cashContract.CashInId; cashInStock.ContractRefId = contractRefId; cashInStock.CorpRefId = cashContract.CorpRefId; cashInStock.DetailStatus = StatusEnum.已生效; cashInStock.StockLogId = stockLog.StockLogId; cashInStock.StockId = stockLog.StockId; cashInStock.StockNameId = stockLog.StockNameId; result = cashInStockDAL.Insert(user, cashInStock); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }