internal ResultModel Create(NFMT.Common.UserModel user, Contract.Model.Contract contract, Model.ContractDetail contractDetail, Model.ContractPrice contractPrice, List<Model.ContractCorporationDetail> outCorps, List<Model.ContractCorporationDetail> inCorps, List<Model.ContractDept> depts, List<NFMT.Contract.Model.ContractClause> contractClauses,List<Model.ContractTypeDetail> contractTypes = null) { ResultModel result = new ResultModel(); try { DAL.ContractDetailDAL detailDAL = new ContractDetailDAL(); DAL.ContractPriceDAL priceDAL = new ContractPriceDAL(); DAL.ContractCorporationDetailDAL corpDAL = new ContractCorporationDetailDAL(); DAL.ContractDeptDAL deptDAL = new ContractDeptDAL(); NFMT.User.DAL.CorporationDAL dal = new User.DAL.CorporationDAL(); result = this.ValidateAuth(user, contract, outCorps, inCorps); if (result.ResultStatus != 0) return result; contract.ContractStatus = StatusEnum.已录入; result = contractDAL.Insert(user, contract); if (result.ResultStatus != 0) return result; //获取合约序号 int contractId = (int)result.ReturnValue; contractDetail.ContractId = contractId; contractDetail.MoreOrLess = contractDetail.MoreOrLess / 100; contractDetail.DiscountRate = contractDetail.DiscountRate / 100; result = detailDAL.Insert(user, contractDetail); if (result.ResultStatus != 0) return result; contractPrice.ContractId = contractId; result = priceDAL.Insert(user, contractPrice); if (result.ResultStatus != 0) return result; NFMT.User.Model.Corporation outCorpTemp = null; //新增合约对方抬头明细 foreach (ContractCorporationDetail corp in outCorps) { NFMT.User.Model.Corporation c = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corp.CorpId); if (c == null || c.CorpId <= 0) return result; if (outCorpTemp == null) outCorpTemp = c; if ((outCorpTemp.ParentId == 0 && outCorps.Count > 1) || (outCorpTemp.ParentId != c.ParentId)) { result.ResultStatus = -1; result.Message = "选择的外部公司不属于同一集团"; return result; } corp.ContractId = contractId; corp.CorpName = c.CorpName; corp.IsInnerCorp = false; if (outCorps.IndexOf(corp) == 0) corp.IsDefaultCorp = true; else corp.IsDefaultCorp = false; corp.DetailStatus = StatusEnum.已生效; result = corpDAL.Insert(user, corp); if (result.ResultStatus != 0) return result; } //新增己方合约抬头明细 foreach (ContractCorporationDetail corp in inCorps) { result = dal.Get(user, corp.CorpId); if (result.ResultStatus != 0) return result; NFMT.User.Model.Corporation c = result.ReturnValue as NFMT.User.Model.Corporation; if (c == null) return result; corp.CorpName = c.CorpName; corp.ContractId = contractId; corp.IsInnerCorp = true; if (inCorps.IndexOf(corp) == 0) corp.IsDefaultCorp = true; else corp.IsDefaultCorp = false; corp.DetailStatus = StatusEnum.已生效; result = corpDAL.Insert(user, corp); if (result.ResultStatus != 0) return result; } //新增执行部门 foreach (Model.ContractDept dept in depts) { dept.ContractId = contractId; dept.DetailStatus = Common.StatusEnum.已生效; result = deptDAL.Insert(user, dept); if (result.ResultStatus != 0) return result; } //新增合约类型明细 if (contractTypes != null) { DAL.ContractTypeDetailDAL contractTypeDAL = new ContractTypeDetailDAL(); foreach (Model.ContractTypeDetail contractType in contractTypes) { contractType.ContractId = contractId; contractType.DetailStatus = StatusEnum.已生效; result = contractTypeDAL.Insert(user, contractType); if (result.ResultStatus != 0) return result; } } //新增合约条款 if (contractClauses != null && contractClauses.Any()) { DAL.ContractClauseDAL contractClauseDAL = new ContractClauseDAL(); foreach (Model.ContractClause contractClause in contractClauses) { contractClause.ContractId = contractId; result = contractClauseDAL.Insert(user, contractClause); if (result.ResultStatus != 0) return result; } } if (result.ResultStatus == 0) { contract.ContractId = contractId; result.ReturnValue = contract; } //附件使用 //创建方法最后返回业务数据Id if (result.ResultStatus == 0) { contract.ContractId = contractId; result.ReturnValue = contract; } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Update(UserModel user, NFMT.Operate.Model.Invoice invoice, Model.SI si, List<Model.SIDetail> siDetails) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.InvoiceDAL invoiceDAL = new Operate.DAL.InvoiceDAL(); DAL.SIDAL sIDAL = new SIDAL(); DAL.SIDetailDAL sIDetailDAL = new SIDetailDAL(); NFMT.User.DAL.CorporationDAL corporationDAL = new User.DAL.CorporationDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //获取发票信息 result = invoiceDAL.Get(user, invoice.InvoiceId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Invoice resultObj = result.ReturnValue as NFMT.Operate.Model.Invoice; if (resultObj == null || resultObj.InvoiceId <= 0) { result.Message = "获取发票信息失败"; result.ResultStatus = -1; return result; } //获取公司信息 result = corporationDAL.Get(user, invoice.InCorpId); if (result.ResultStatus != 0) return result; NFMT.User.Model.Corporation corp = result.ReturnValue as NFMT.User.Model.Corporation; if (corp == null) { result.ResultStatus = -1; result.Message = "公司信息不存在"; return result; } resultObj.InCorpName = corp.CorpName; result = corporationDAL.Get(user, invoice.OutCorpId); if (result.ResultStatus != 0) return result; corp = result.ReturnValue as NFMT.User.Model.Corporation; if (corp == null) { result.ResultStatus = -1; result.Message = "公司信息不存在"; return result; } resultObj.OutCorpName = corp.CorpName; resultObj.InvoiceDate = invoice.InvoiceDate; resultObj.InvoiceName = invoice.InvoiceName; resultObj.InvoiceType = invoice.InvoiceType; resultObj.InvoiceBala = invoice.InvoiceBala; resultObj.CurrencyId = invoice.CurrencyId; resultObj.InvoiceDirection = invoice.InvoiceDirection; resultObj.OutCorpId = invoice.OutCorpId; resultObj.InCorpId = invoice.InCorpId; resultObj.Memo = invoice.Memo; //更新发票信息 result = invoiceDAL.Update(user, resultObj); if (result.ResultStatus != 0) return result; //更新价外票信息 result = sIDAL.Update(user, si); if (result.ResultStatus != 0) return result; //作废价外票 result = sIDetailDAL.InvalidAll(user, si.SIId); if (result.ResultStatus != 0) return result; foreach (Model.SIDetail detail in siDetails) { detail.SIId = si.SIId; result = sIDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception e) { result.ResultStatus = -1; result.Message = e.Message; } return result; }
public ResultModel Create(UserModel user, NFMT.Operate.Model.Invoice invoice, Model.SI si, List<Model.SIDetail> siDetails) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.InvoiceDAL invoiceDAL = new Operate.DAL.InvoiceDAL(); DAL.SIDAL sIDAL = new SIDAL(); DAL.SIDetailDAL sIDetailDAL = new SIDetailDAL(); NFMT.User.DAL.CorporationDAL corporationDAL = new User.DAL.CorporationDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = corporationDAL.Get(user, invoice.InCorpId); if (result.ResultStatus != 0) return result; NFMT.User.Model.Corporation corp = result.ReturnValue as NFMT.User.Model.Corporation; if (corp == null) { result.ResultStatus = -1; result.Message = "公司信息不存在"; return result; } invoice.InCorpName = corp.CorpName; result = corporationDAL.Get(user, invoice.OutCorpId); if (result.ResultStatus != 0) return result; corp = result.ReturnValue as NFMT.User.Model.Corporation; if (corp == null) { result.ResultStatus = -1; result.Message = "公司信息不存在"; return result; } invoice.OutCorpName = corp.CorpName; result = invoiceDAL.Insert(user, invoice); if (result.ResultStatus != 0) return result; int invoiceId = (int)result.ReturnValue; si.InvoiceId = invoiceId; result = sIDAL.Insert(user, si); if (result.ResultStatus != 0) return result; int sIId = (int)result.ReturnValue; foreach (Model.SIDetail detail in siDetails) { detail.SIId = sIId; result = sIDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } invoice.InvoiceId = invoiceId; if (result.ResultStatus == 0) result.ReturnValue = invoice; scope.Complete(); } } catch (Exception e) { result.ResultStatus = -1; result.Message = e.Message; } return result; }
public ResultModel ReceivableStockUpdateHandle(UserModel user, List<Model.CorpReceivable> corpReceivables, int curId, string memo, int allotId,int stockId, int stockNameId,int allotFrom) { ResultModel result = new ResultModel(); DAL.ReceivableDAL receivableDAL = new ReceivableDAL(); DAL.CorpReceivableDAL corpReceivableDAL = new CorpReceivableDAL(); DAL.ContractReceivableDAL contractReceivableDAL = new ContractReceivableDAL(); DAL.StcokReceivableDAL stcokReceivableDAL = new StcokReceivableDAL(); NFMT.User.DAL.CorporationDAL corporationDAL = new User.DAL.CorporationDAL(); NFMT.WareHouse.DAL.StockLogDAL stockLogDAL=new WareHouse.DAL.StockLogDAL(); Model.Receivable receivable = new Receivable(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { decimal allotBala = 0; foreach (Model.CorpReceivable corpReceivable in corpReceivables) { //allotBala += corpReceivable.AllotBala; } result = receivableallotDAL.Get(user, allotId); if (result.ResultStatus != 0) return result; Model.ReceivableAllot receivableAllot = result.ReturnValue as Model.ReceivableAllot; receivableAllot.AllotDesc = memo; receivableAllot.AllotBala = allotBala; receivableAllot.CurrencyId = curId; receivableAllot.AllotFrom = allotFrom; //更新收款分配表 result = receivableallotDAL.Update(user, receivableAllot); if (result.ResultStatus != 0) return result; //作废公司收款分配 result = corpReceivableDAL.InvalidAll(user, allotId); if (result.ResultStatus != 0) return result; //作废合约收款分配 result = contractReceivableDAL.InvalidAll(user, allotId); if (result.ResultStatus != 0) return result; //作废库存收款分配 result = stcokReceivableDAL.InvalidAll(user, allotId); if (result.ResultStatus != 0) return result; //获取合约Id result = stockLogDAL.GetStockContractId(user, stockId); if (result.ResultStatus != 0) return result; string contractStr = result.ReturnValue.ToString(); foreach (Model.CorpReceivable corpReceivable in corpReceivables) { result = corporationDAL.Get(user, corpReceivable.CorpId); if (result.ResultStatus != 0) return result; User.Model.Corporation corp = result.ReturnValue as User.Model.Corporation; corpReceivable.BlocId = corp.ParentId; //写入公司收款分配 result = corpReceivableDAL.Insert(user, corpReceivable); if (result.ResultStatus != 0) return result; int corpRefId = (int)result.ReturnValue; Model.ContractReceivable contractReceivable = new ContractReceivable() { CorpRefId = corpRefId, AllotId = allotId, RecId = corpReceivable.RecId, ContractId = Convert.ToInt32(contractStr.Split(',')[0]), SubContractId = Convert.ToInt32(contractStr.Split(',')[1]), //AllotBala = corpReceivable.AllotBala }; //写入合约收款分配 result = contractReceivableDAL.Insert(user, contractReceivable); if (result.ResultStatus != 0) return result; int contractRefId = (int)result.ReturnValue; Model.StcokReceivable stcokReceivable = new StcokReceivable() { AllotId = allotId, CorpRefId = corpRefId, ContractRefId = contractRefId, RecId = corpReceivable.RecId, StockId = stockId, StockNameId = stockNameId, //AllotBala = corpReceivable.AllotBala }; //写入库存收款分配 result = stcokReceivableDAL.Insert(user, stcokReceivable); 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; }
public ResultModel ReceivableStockUpdateForContractHandle(UserModel user, List<Model.StcokReceivable> stcokReceivables, int curId, string memo, int allotId, int allotFrom) { ResultModel result = new ResultModel(); DAL.ReceivableDAL receivableDAL = new ReceivableDAL(); DAL.CorpReceivableDAL corpReceivableDAL = new CorpReceivableDAL(); DAL.ContractReceivableDAL contractReceivableDAL = new ContractReceivableDAL(); DAL.StcokReceivableDAL stcokReceivableDAL = new StcokReceivableDAL(); NFMT.User.DAL.CorporationDAL corporationDAL = new User.DAL.CorporationDAL(); NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new WareHouse.DAL.StockLogDAL(); Model.Receivable receivable = new Receivable(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { decimal allotBala = 0; foreach (Model.StcokReceivable stcokReceivable in stcokReceivables) { //allotBala += stcokReceivable.AllotBala; } result = receivableallotDAL.Get(user, allotId); if (result.ResultStatus != 0) return result; Model.ReceivableAllot receivableAllot = result.ReturnValue as Model.ReceivableAllot; receivableAllot.AllotDesc = memo; receivableAllot.AllotBala = allotBala; receivableAllot.CurrencyId = curId; receivableAllot.AllotFrom = allotFrom; //更新收款分配表 result = receivableallotDAL.Update(user, receivableAllot); if (result.ResultStatus != 0) return result; ////作废公司收款分配 //result = corpReceivableDAL.InvalidAll(user, allotId); //if (result.ResultStatus != 0) // return result; ////作废合约收款分配 //result = contractReceivableDAL.InvalidAll(user, allotId); //if (result.ResultStatus != 0) // return result; //作废库存收款分配 result = stcokReceivableDAL.InvalidAll(user, allotId); if (result.ResultStatus != 0) return result; foreach (Model.StcokReceivable stcokReceivable in stcokReceivables) { result = contractReceivableDAL.Get(user, stcokReceivable.ContractRefId); if (result.ResultStatus != 0) return result; Model.ContractReceivable contractReceivable = result.ReturnValue as Model.ContractReceivable; stcokReceivable.CorpRefId = contractReceivable.CorpRefId; stcokReceivable.RecId = contractReceivable.RecId; //写入库存收款分配 result = stcokReceivableDAL.Insert(user, stcokReceivable); 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; }
public ResultModel ReceivableAllotUpdateHandle(UserModel user, List<Model.CorpReceivable> corpReceivables, int curId, string memo, int allotId, int contractId, int subId) { ResultModel result = new ResultModel(); DAL.ReceivableDAL receivableDAL = new ReceivableDAL(); DAL.ContractReceivableDAL contractReceivableDAL = new ContractReceivableDAL(); DAL.CorpReceivableDAL corpReceivableDAL = new CorpReceivableDAL(); NFMT.User.DAL.CorporationDAL corporationDAL = new User.DAL.CorporationDAL(); Model.Receivable receivable = new Receivable(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { decimal allotBala = 0; foreach (Model.CorpReceivable corpReceivable in corpReceivables) { //allotBala += corpReceivable.AllotBala; } result = receivableallotDAL.Get(user, allotId); if (result.ResultStatus != 0) return result; Model.ReceivableAllot receivableAllot = result.ReturnValue as Model.ReceivableAllot; receivableAllot.AllotDesc = memo; receivableAllot.AllotBala = allotBala; //更新分配信息 result = receivableallotDAL.Update(user, receivableAllot); if (result.ResultStatus != 0) return result; //作废所有allotId下的合约收款分配 result = contractReceivableDAL.InvalidAll(user, allotId); if (result.ResultStatus != 0) return result; //作废所有allotId下的公司收款分配 result = corpReceivableDAL.InvalidAll(user, allotId); if (result.ResultStatus != 0) return result; foreach (Model.CorpReceivable corpReceivable in corpReceivables) { corpReceivable.AllotId = allotId; result = corporationDAL.Get(user, corpReceivable.CorpId); if (result.ResultStatus != 0) return result; //获取公司信息 NFMT.User.Model.Corporation corp = result.ReturnValue as NFMT.User.Model.Corporation; if (corp == null) return result; corpReceivable.BlocId = corp.ParentId; //写入公司收款分配表 result = corpReceivableDAL.Insert(user, corpReceivable); if (result.ResultStatus != 0) return result; int refId = (int)result.ReturnValue; Model.ContractReceivable contractReceivable = new ContractReceivable() { CorpRefId = refId, AllotId = corpReceivable.AllotId, RecId = corpReceivable.RecId, ContractId = contractId, SubContractId = subId, //AllotBala = corpReceivable.AllotBala }; //写入合约收款分配表 result = contractReceivableDAL.Insert(user, contractReceivable); 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; }