public ResultModel Update(UserModel user, NFMT.WareHouse.Model.StockReceipt stockReceipt, List<NFMT.WareHouse.Model.StockReceiptDetail> details) { ResultModel result = new ResultModel(); try { NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL(); DAL.StockLogDAL stockLogDAL = new StockLogDAL(); DAL.StockReceiptDAL receiptDAL = new StockReceiptDAL(); DAL.StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证仓库回执 result = receiptDAL.Get(user, stockReceipt.ReceiptId); if (result.ResultStatus != 0) return result; Model.StockReceipt resultReceipt = result.ReturnValue as Model.StockReceipt; if (resultReceipt == null || resultReceipt.ReceiptId <= 0) { result.ResultStatus = -1; result.Message = "仓库回执不存在"; return result; } //获取仓库回执明细 result = detailDAL.Load(user, resultReceipt.ReceiptId); if (result.ResultStatus != 0) return result; List<Model.StockReceiptDetail> resultDetails = result.ReturnValue as List<Model.StockReceiptDetail>; if (resultDetails == null) { result.ResultStatus = -1; result.Message = "仓库回执明细获取失败"; return result; } //作废现有仓库回执明细 foreach (Model.StockReceiptDetail d in resultDetails) { if (d.DetailStatus == StatusEnum.已生效) d.DetailStatus = StatusEnum.已录入; result = detailDAL.Invalid(user, d); if (result.ResultStatus != 0) return result; } //验证合约 result = subDAL.Get(user, resultReceipt.ContractSubId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub; if (sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } result = contractDAL.Get(user, sub.ContractId); 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; } decimal sumNetAmount = 0; decimal sumReceiptAmount = 0; decimal sumMissAmount = 0; decimal missRate = 0; //明细验证 foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details) { //验证库存 result = stockDAL.Get(user, detail.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //验证流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; Model.StockLog stockLog = result.ReturnValue as Model.StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "库存流水不存在"; return result; } if (stockLog.StockId != stock.StockId) { result.ResultStatus = -1; result.Message = "库存与库存流水不匹配"; return result; } if (stockLog.SubContractId != stockReceipt.ContractSubId) { result.ResultStatus = -1; result.Message = "库存流水与合约不匹配"; return result; } detail.ReceiptId = resultReceipt.ReceiptId; detail.ContractId = sub.ContractId; detail.ContractSubId = sub.SubId; detail.DetailStatus = StatusEnum.已生效; detail.PreNetAmount = stock.NetAmount; detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount; detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100; sumNetAmount += stock.NetAmount; sumReceiptAmount += detail.ReceiptAmount; //新增仓库回执明细 result = detailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } sumMissAmount = sumReceiptAmount - sumNetAmount; missRate = (sumReceiptAmount / sumNetAmount - 1) / 100; //赋值StockReceipt resultReceipt.PreNetAmount = sumReceiptAmount; resultReceipt.QtyMiss = sumMissAmount; resultReceipt.QtyRate = missRate; resultReceipt.ReceiptAmount = sumReceiptAmount; resultReceipt.Receipter = user.EmpId; resultReceipt.Memo = stockReceipt.Memo; resultReceipt.ReceiptDate = stockReceipt.ReceiptDate; if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) resultReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt; else resultReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt; resultReceipt.UnitId = sub.UnitId; //修改StockReceipt result = stockreceiptDAL.Update(user, resultReceipt); if (result.ResultStatus != 0) return result; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel CreateStockReceipt(UserModel user, NFMT.WareHouse.Model.StockReceipt stockReceipt, List<NFMT.WareHouse.Model.StockReceiptDetail> details, List<NFMT.WareHouse.Model.StockReceiptDetail> saleDetails, bool isAudit) { ResultModel result = new ResultModel(); try { NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL(); NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL(); DAL.StockReceiptDAL receiptDAL = new StockReceiptDAL(); DAL.StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证合约 result = subDAL.Get(user, stockReceipt.ContractSubId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub; if (sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } result = contractDAL.Get(user, sub.ContractId); 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; } decimal sumNetAmount = 0; decimal sumReceiptAmount = 0; decimal sumMissAmount = 0; decimal missRate = 0; //明细验证 foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details) { if (detail.ReceiptAmount > 0) { //验证库存 result = stockDAL.Get(user, detail.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //验证流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; Model.StockLog stockLog = result.ReturnValue as Model.StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "库存流水不存在"; return result; } if (stockLog.StockId != stock.StockId) { result.ResultStatus = -1; result.Message = "库存与库存流水不匹配"; return result; } if (stockLog.SubContractId != stockReceipt.ContractSubId) { result.ResultStatus = -1; result.Message = "库存流水与合约不匹配"; return result; } detail.ContractId = sub.ContractId; detail.ContractSubId = sub.SubId; detail.DetailStatus = StatusEnum.已生效; detail.PreNetAmount = stock.NetAmount; detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount; detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100; sumNetAmount += stock.NetAmount; sumReceiptAmount += detail.ReceiptAmount; } } sumMissAmount = sumReceiptAmount - sumNetAmount; missRate = (sumReceiptAmount / sumNetAmount - 1) / 100; //赋值StockReceipt stockReceipt.ContractId = sub.ContractId; stockReceipt.ContractSubId = sub.SubId; stockReceipt.PreNetAmount = sumNetAmount; stockReceipt.QtyMiss = sumMissAmount; stockReceipt.QtyRate = missRate; stockReceipt.ReceiptAmount = sumReceiptAmount; stockReceipt.Receipter = user.EmpId; stockReceipt.ReceiptDate = DateTime.Now; if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt; else stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt; stockReceipt.UnitId = sub.UnitId; //新增StockReceipt result = stockreceiptDAL.Insert(user, stockReceipt); if (result.ResultStatus != 0) return result; int receiptId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out receiptId)) { result.ResultStatus = -1; result.Message = "新增库存回执失败"; return result; } //新增明细 foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details) { detail.ReceiptId = receiptId; result = detailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } stockReceipt.ReceiptId = receiptId; string resultStr = Newtonsoft.Json.JsonConvert.SerializeObject(stockReceipt); //if(isAudit) //{ // stockReceipt.ReceiptId = receiptId; // NFMT.WorkFlow.AutoSubmit submit = new NFMT.WorkFlow.AutoSubmit(); // result = submit.Submit(user, stockReceipt, new TaskProvider.StockReceiptTaskProvider(), NFMT.WorkFlow.MasterEnum.库存净重回执审核); // if (result.ResultStatus != 0) // return result; //} #region 销售合约库存回执 if (saleDetails != null && saleDetails.Any()) { foreach (int subId in saleDetails.Select(a => a.ContractSubId).Distinct()) { //验证合约 result = subDAL.Get(user, subId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.ContractSub saleSub = result.ReturnValue as NFMT.Contract.Model.ContractSub; if (saleSub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } sumNetAmount = 0; sumReceiptAmount = 0; sumMissAmount = 0; missRate = 0; //明细验证 foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in saleDetails.Where(a => a.ContractSubId == subId)) { if (detail.ReceiptAmount > 0) { //验证库存 result = stockDAL.Get(user, detail.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //验证流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; Model.StockLog stockLog = result.ReturnValue as Model.StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "库存流水不存在"; return result; } if (stockLog.StockId != stock.StockId) { result.ResultStatus = -1; result.Message = "库存与库存流水不匹配"; return result; } if (stockLog.SubContractId != subId) { result.ResultStatus = -1; result.Message = "库存流水与合约不匹配"; return result; } detail.ContractId = saleSub.ContractId; detail.ContractSubId = saleSub.SubId; detail.DetailStatus = StatusEnum.已生效; detail.PreNetAmount = stock.NetAmount; detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount; detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100; sumNetAmount += stock.NetAmount; sumReceiptAmount += detail.ReceiptAmount; } } sumMissAmount = sumReceiptAmount - sumNetAmount; missRate = (sumReceiptAmount / sumNetAmount - 1) / 100; //赋值StockReceipt stockReceipt.ContractId = saleSub.ContractId; stockReceipt.ContractSubId = saleSub.SubId; stockReceipt.PreNetAmount = sumNetAmount; stockReceipt.ReceiptAmount = sumReceiptAmount; stockReceipt.UnitId = saleSub.UnitId; stockReceipt.QtyMiss = sumMissAmount; stockReceipt.QtyRate = missRate; stockReceipt.Receipter = user.EmpId; stockReceipt.ReceiptDate = DateTime.Now; if (saleSub.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt; else stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt; //新增StockReceipt result = stockreceiptDAL.Insert(user, stockReceipt); if (result.ResultStatus != 0) return result; receiptId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out receiptId)) { result.ResultStatus = -1; result.Message = "新增库存回执失败"; return result; } //新增明细 foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in saleDetails.Where(a => a.ContractSubId == subId)) { detail.ReceiptId = receiptId; result = detailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } } //if (isAudit) //{ // stockReceipt.ReceiptId = receiptId; // NFMT.WorkFlow.AutoSubmit submit = new NFMT.WorkFlow.AutoSubmit(); // result = submit.Submit(user, stockReceipt, new TaskProvider.StockReceiptTaskProvider(), NFMT.WorkFlow.MasterEnum.库存净重回执审核); // if (result.ResultStatus != 0) // return result; //} } #endregion stockReceipt.ReceiptId = receiptId; if (result.ResultStatus == 0) { if (saleDetails != null && saleDetails.Any()) result.ReturnValue = stockReceipt; else result.ReturnValue = null; result.Message = resultStr; scope.Complete(); } } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Create(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.PricingApply pricingApply, List<NFMT.DoPrice.Model.PricingApplyDetail> pricingApplyDetails) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept); if (dept == null || dept.DeptId <= 0) { result.ResultStatus = -1; result.Message = "申请部门不存在"; return result; } //新增主申请 apply.EmpId = user.EmpId; apply.ApplyTime = DateTime.Now; apply.ApplyType = NFMT.Operate.ApplyType.PricingApply; apply.ApplyDept = dept.DeptId; result = applyDAL.Insert(user, apply); if (result.ResultStatus != 0) return result; int applyId = (int)result.ReturnValue; pricingApply.ApplyId = applyId; //验证子合约 result = subDAL.Get(user, pricingApply.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; } //decimal missRate = Convert.ToDecimal(0.05); //if (pricingApply.PricingWeight > sub.SignAmount) //{ // result.ResultStatus = -1; // result.Message = "点价重量超过子合约签订数量"; // return result; //} //获取合约 result = contractDAL.Get(user, sub.ContractId); 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; } if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) pricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.空头; else pricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.多头; //新增点价申请 result = pricingApplyDAL.Insert(user, pricingApply); if (result.ResultStatus != 0) return result; int pricingApplyId = (int)result.ReturnValue; foreach (Model.PricingApplyDetail detail in pricingApplyDetails) { detail.PricingApplyId = pricingApplyId; detail.DetailStatus = StatusEnum.已生效; result = pricingApplyDetailDAL.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 Update(UserModel user, NFMT.Operate.Model.Apply apply, NFMT.DoPrice.Model.PricingApply pricingApply, List<NFMT.DoPrice.Model.PricingApplyDetail> pricingApplyDetails) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.PricingApplyDAL pricingApplyDAL = new PricingApplyDAL(); DAL.PricingApplyDetailDAL pricingApplyDetailDAL = new PricingApplyDetailDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = applyDAL.Get(user, apply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply getApply = result.ReturnValue as NFMT.Operate.Model.Apply; if (getApply == null || getApply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "获取申请错误"; return result; } NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == apply.ApplyDept); if (dept == null || dept.DeptId <= 0) { result.ResultStatus = -1; result.Message = "申请部门不存在"; return result; } getApply.EmpId = user.EmpId; getApply.ApplyTime = DateTime.Now; getApply.ApplyDept = apply.ApplyDept; getApply.ApplyCorp = apply.ApplyCorp; getApply.ApplyDesc = apply.ApplyDesc; result = applyDAL.Update(user, getApply); if (result.ResultStatus != 0) return result; result = pricingApplyDAL.Get(user, pricingApply.PricingApplyId); if (result.ResultStatus != 0) return result; NFMT.DoPrice.Model.PricingApply getPricingApply = result.ReturnValue as NFMT.DoPrice.Model.PricingApply; if (getPricingApply == null || getPricingApply.PricingApplyId <= 0) { result.ResultStatus = -1; result.Message = "获取点价申请错误"; return result; } getPricingApply.StartTime = pricingApply.StartTime; getPricingApply.EndTime = pricingApply.EndTime; getPricingApply.MinPrice = pricingApply.MinPrice; getPricingApply.MaxPrice = pricingApply.MaxPrice; getPricingApply.CurrencyId = pricingApply.CurrencyId; getPricingApply.PricingCorpId = pricingApply.PricingCorpId; getPricingApply.PricingWeight = pricingApply.PricingWeight; getPricingApply.MUId = pricingApply.MUId; getPricingApply.AssertId = pricingApply.AssertId; getPricingApply.PricingPersoinId = pricingApply.PricingPersoinId; //验证子合约 result = subDAL.Get(user, pricingApply.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 = contractDAL.Get(user, sub.ContractId); 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; } if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy) getPricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.空头; else getPricingApply.PricingDirection = (int)NFMT.DoPrice.PricingDirection.多头; result = pricingApplyDAL.Update(user, getPricingApply); if (result.ResultStatus != 0) return result; //作废明细 result = pricingApplyDetailDAL.InvalidAll(user, getPricingApply.PricingApplyId); if (result.ResultStatus != 0) return result; //写入明细 foreach (Model.PricingApplyDetail detail in pricingApplyDetails) { detail.PricingApplyId = getPricingApply.PricingApplyId; detail.DetailStatus = StatusEnum.已生效; result = pricingApplyDetailDAL.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 CreateStockOutApply(UserModel user, int subId, List<Model.StockOutApplyDetail> details, int deptId, string memo, int corpId, int buyCorpId) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.WareHouse.DAL.StockOutApplyDAL outApplyDAL = new DAL.StockOutApplyDAL(); NFMT.WareHouse.DAL.StockOutApplyDetailDAL detailDAL = new DAL.StockOutApplyDetailDAL(); NFMT.WareHouse.DAL.StockExclusiveDAL exclusiveDAL = new DAL.StockExclusiveDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证分配库存 if (details == null || details.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; } //验证合约 result = contractDAL.Get(user, sub.ContractId); 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; } //获取部门信息 NFMT.User.Model.Department dept = User.UserProvider.Departments.Single(temp => temp.DeptId == deptId); if (dept == null || dept.DeptId <= 0) { result.ResultStatus = -1; result.Message = "部门不存在"; return result; } //添加主申请表 NFMT.Operate.Model.Apply apply = new Operate.Model.Apply(); apply.ApplyDept = deptId; apply.ApplyCorp = corpId; apply.ApplyTime = DateTime.Now; apply.ApplyDesc = memo; apply.ApplyType = NFMT.Operate.ApplyType.出库申请; apply.EmpId = user.EmpId; apply.ApplyStatus = Common.StatusEnum.已录入; result = applyDAL.Insert(user, apply); if (result.ResultStatus != 0) return result; int applyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out applyId) || applyId <= 0) { result.ResultStatus = -1; result.Message = "申请主表添加失败"; return result; } decimal sumGrossAmount = details.Sum(temp => temp.GrossAmount); decimal sumNetAmount = details.Sum(temp => temp.NetAmount); int sumBundles = details.Sum(temp => temp.Bundles); //添加出库申请主表 NFMT.WareHouse.Model.StockOutApply outApply = new StockOutApply(); outApply.ApplyId = applyId; outApply.ContractId = sub.ContractId; outApply.SubContractId = sub.SubId; outApply.GrossAmount = sumGrossAmount; outApply.NetAmount = sumNetAmount; outApply.Bundles = sumBundles; outApply.UnitId = sub.UnitId; outApply.BuyCorpId = buyCorpId; result = outApplyDAL.Insert(user, outApply); if (result.ResultStatus != 0) return result; int outApplyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out outApplyId) || outApplyId <= 0) { result.ResultStatus = -1; result.Message = "出库申请添加失败"; return result; } foreach (Model.StockOutApplyDetail applyDetail in details) { //验证库存 result = stockDAL.Get(user, applyDetail.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.ResultStatus = -1; result.Message = "库存不存在"; return result; } //判断库存品种是否与合约品种相同 if (stock.AssetId != contract.AssetId) { result.ResultStatus = -1; result.Message = "分配库存的品种与合约品种不一致"; return result; } //不允许配货库存 int planStockInStatus = (int)NFMT.WareHouse.StockStatusEnum.预入库存; int planCustomsStatus = (int)NFMT.WareHouse.StockStatusEnum.预报关库存; int stockStatus = (int)stock.StockStatus; if (stockStatus > planCustomsStatus || stockStatus < planStockInStatus) { result.ResultStatus = -1; result.Message = "访笔库存不能进行出库申请分配"; return result; } applyDetail.ContractId = sub.ContractId; applyDetail.DetailStatus = StatusEnum.已生效; applyDetail.SubContractId = sub.SubId; applyDetail.StockOutApplyId = outApplyId; if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.ForeignTrade) applyDetail.GrossAmount = stock.GrossAmount; else applyDetail.GrossAmount = applyDetail.NetAmount; result = detailDAL.Insert(user, applyDetail); if (result.ResultStatus != 0) return result; int detailApplyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailApplyId) || detailApplyId <= 0) { result.ResultStatus = -1; result.Message = "库存明细添加失败"; return result; } //排他表校验 result = exclusiveDAL.LoadByStockId(user, stock.StockId); if (result.ResultStatus != 0) return result; List<Model.StockExclusive> excs = result.ReturnValue as List<Model.StockExclusive>; if (excs == null) { result.ResultStatus = -1; result.Message = "获取排他库存信息失败"; return result; } decimal excAmount = excs.Sum(temp => temp.ExclusiveAmount); if (excAmount >= stock.CurNetAmount) { result.ResultStatus = -1; result.Message = "该笔库存剩余净重不足,配货失败"; return result; } //排他表新增 NFMT.WareHouse.Model.StockExclusive exculsive = new StockExclusive(); exculsive.ApplyId = applyId; exculsive.DetailApplyId = detailApplyId; exculsive.ExclusiveStatus = StatusEnum.已生效; exculsive.StockApplyId = outApplyId; exculsive.StockId = stock.StockId; exculsive.ExclusiveAmount = applyDetail.NetAmount; result = exclusiveDAL.Insert(user, exculsive); if (result.ResultStatus != 0) return result; } //验证出库申请与子合约签订数量 if (sumNetAmount > sub.SignAmount) { result.ResultStatus = -1; result.Message = "出库申请数量不能大于子合约签订数量"; return result; } //获取当前子合约下所有出库申请明细 result = detailDAL.LoadBySubId(user, sub.SubId, NFMT.Common.StatusEnum.已生效); if (result.ResultStatus != 0) return result; List<Model.StockOutApplyDetail> ds = result.ReturnValue as List<Model.StockOutApplyDetail>; sumNetAmount = ds.Sum(temp => temp.NetAmount); if (sumNetAmount > sub.SignAmount) { result.ResultStatus = -1; result.Message = "出库申请数量不能大于子合约可分配数量"; return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (log.IsInfoEnabled) log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
public ResultModel CreateReplaceOrder(UserModel user, Model.DocumentOrder order, List<NFMT.Document.Model.OrderReplaceStock> stockInvoices, NFMT.Document.Model.DocumentOrderDetail detail, bool isSubmitAudit) { ResultModel result = new ResultModel(); try { DAL.DocumentOrderDetailDAL orderDetailDAL = new DocumentOrderDetailDAL(); DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL(); DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL(); NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new WareHouse.DAL.StockNameDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { if (order == null) { result.Message = "制单指令不包含任何数据"; result.ResultStatus = -1; return result; } //验证临票指令 result = this.documentorderDAL.Get(user, order.CommercialId); if (result.ResultStatus != 0) return result; Model.DocumentOrder commercialOrder = result.ReturnValue as Model.DocumentOrder; if (commercialOrder == null || commercialOrder.OrderId <= 0) { result.Message = "临票制单指令不存在"; result.ResultStatus = -1; return result; } if (commercialOrder.OrderStatus != StatusEnum.已生效) { result.Message = "临票制单指令状态不正确,不能替临"; result.ResultStatus = -1; return result; } //验证合约 result = contractDAL.Get(user, order.ContractId); 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.Message = "合约不存在"; result.ResultStatus = -1; return result; } //验证子合约 result = subDAL.Get(user, order.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; } if (sub.SubStatus != StatusEnum.已生效) { result.Message = "子合约非已生效状态,不能进行制单指令新增"; result.ResultStatus = -1; return result; } if (sub.ContractId != order.ContractId) { result.Message = "子合约归属主合约与制单指令主合约不一致"; result.ResultStatus = -1; return result; } result = corpDetailDAL.LoadCorpListByContractId(user, sub.ContractId, true); if (result.ResultStatus != 0) return result; List<NFMT.Contract.Model.ContractCorporationDetail> corps = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>; if (corps == null || corps.Count == 0) { result.Message = "合约我方抬头获取失败"; result.ResultStatus = -1; return result; } int orderId = 0; //制单指令主表数据初始化 //付款方式默认为LC order.PaymentStyle = 19; //卖方默认为合约我方抬头默认公司 order.SellerCorp = corps[0].CorpId; ////临票制单或直接终票制单,临终发票差额为0 //order.InvGap = 0; //LC未加入时LC序号为0 order.LCId = 0; order.ApplyEmpId = user.EmpId; //新增主表 order.OrderStatus = StatusEnum.已录入; result = this.documentorderDAL.Insert(user, order); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out orderId) || orderId <= 0) { result.Message = "制单指令新增失败"; result.ResultStatus = -1; return result; } order.OrderId = orderId; //新增明细表 detail.OrderId = orderId; detail.DetailStatus = StatusEnum.已生效; result = orderDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; //临票指令类型,区分是否分配库存 OrderTypeEnum orderType = (OrderTypeEnum)commercialOrder.OrderType; //新增库存明细与发票明细 foreach (Model.OrderReplaceStock stockInvoice in stockInvoices) { //添加库存明细 Model.DocumentOrderStock orderStock = new DocumentOrderStock(); orderStock.DetailStatus = StatusEnum.已生效; orderStock.OrderId = orderId; orderStock.ApplyAmount = stockInvoice.ApplyWeight; orderStock.ComDetailId = stockInvoice.DetailId; //验证临票库存明细是否存在 result = orderStockDAL.Get(user,stockInvoice.DetailId); if (result.ResultStatus != 0) return result; Model.DocumentOrderStock commercialOrderStock = result.ReturnValue as Model.DocumentOrderStock; if (commercialOrderStock == null || commercialOrderStock.DetailId <= 0) { result.Message = "替换的库存明细不存在"; result.ResultStatus = -1; return result; } if (commercialOrderStock.DetailStatus != StatusEnum.已生效) { result.Message = "替换的库存状态不正确"; result.ResultStatus = -1; return result; } int orderStockId = 0; orderStock.StockId = commercialOrderStock.StockId; orderStock.StockNameId = commercialOrderStock.StockNameId; orderStock.RefNo = commercialOrderStock.RefNo; result = orderStockDAL.Insert(user, orderStock); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out orderStockId) || orderStockId <= 0) { result.Message = "制单指令库存明细新增失败"; result.ResultStatus = -1; return result; } //添加发票明细 Model.DocumentOrderInvoice orderInvoice = new DocumentOrderInvoice(); orderInvoice.DetailStatus = StatusEnum.已生效; orderInvoice.InvoiceBala = stockInvoice.InvoiceBala; orderInvoice.InvoiceNo = stockInvoice.InvoiceNo; orderInvoice.OrderId = orderId; orderInvoice.StockDetailId = orderStockId; result = orderInvoiceDAL.Insert(user, orderInvoice); if (result.ResultStatus != 0) return result; } if (isSubmitAudit) { NFMT.WorkFlow.AutoSubmit submit = new WorkFlow.AutoSubmit(); NFMT.WorkFlow.ITaskProvider taskProvider = new TaskProvider.OrderTaskProvider(); result = submit.Submit(user, order, taskProvider, WorkFlow.MasterEnum.制单指令审核); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = order; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel UpdateReplaceOrder(UserModel user, Model.DocumentOrder order, List<NFMT.Document.Model.OrderReplaceStock> stockInvoices, NFMT.Document.Model.DocumentOrderDetail detail) { ResultModel result = new ResultModel(); try { DAL.DocumentOrderDetailDAL orderDetailDAL = new DocumentOrderDetailDAL(); DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL(); DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL(); NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new WareHouse.DAL.StockNameDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { if (order == null) { result.Message = "制单指令不包含任何数据"; result.ResultStatus = -1; return result; } //验证制单指令 result = this.documentorderDAL.Get(user, order.OrderId); if (result.ResultStatus != 0) return result; Model.DocumentOrder resultOrder = result.ReturnValue as Model.DocumentOrder; if (resultOrder == null || resultOrder.OrderId <= 0) { result.Message = "制单指令不存在"; result.ResultStatus = -1; return result; } resultOrder.OrderDate = order.OrderDate; resultOrder.BankCode = order.BankCode; resultOrder.GrossAmount = order.GrossAmount; resultOrder.NetAmount = order.NetAmount; resultOrder.Bundles = order.Bundles; resultOrder.UnitPrice = order.UnitPrice; resultOrder.InvBala = order.InvBala; resultOrder.InvGap = order.InvGap; resultOrder.Meno = order.Meno; //更新主表 result = this.documentorderDAL.Update(user, resultOrder); if (result.ResultStatus != 0) return result; //获取明细表 result = orderDetailDAL.GetByOrderId(user, resultOrder.OrderId); if (result.ResultStatus != 0) return result; Model.DocumentOrderDetail resultDetail = result.ReturnValue as Model.DocumentOrderDetail; if (resultDetail == null || resultDetail.DetailId <= 0) { result.Message = "制单指令明细获取失败"; result.ResultStatus = -1; return result; } resultDetail.InvoiceCopies = detail.InvoiceCopies; resultDetail.InvoiceSpecific = detail.InvoiceSpecific; resultDetail.QualityCopies = detail.QualityCopies; resultDetail.QualitySpecific = detail.QualitySpecific; resultDetail.WeightCopies = detail.WeightCopies; resultDetail.WeightSpecific = detail.WeightSpecific; resultDetail.TexCopies = detail.TexCopies; resultDetail.TexSpecific = detail.TexSpecific; resultDetail.DeliverCopies = detail.DeliverCopies; resultDetail.DeliverSpecific = detail.DeliverSpecific; resultDetail.TotalInvCopies = detail.TotalInvCopies; resultDetail.TotalInvSpecific = detail.TotalInvSpecific; result = orderDetailDAL.Update(user, resultDetail); if (result.ResultStatus != 0) return result; //作废库存明细与发票明细 result = orderInvoiceDAL.Load(user, resultOrder.OrderId); if (result.ResultStatus != 0) return result; List<Model.DocumentOrderInvoice> orderInvoices = result.ReturnValue as List<Model.DocumentOrderInvoice>; if (orderInvoices == null) { result.Message = "制单指令发票明细获取失败"; result.ResultStatus = -1; return result; } foreach (Model.DocumentOrderInvoice orderInvoice in orderInvoices) { result = orderInvoiceDAL.Invalid(user, orderInvoice); if (result.ResultStatus != 0) return result; } result = orderStockDAL.Load(user, resultOrder.OrderId); if (result.ResultStatus != 0) return result; List<Model.DocumentOrderStock> orderStocks = result.ReturnValue as List<Model.DocumentOrderStock>; if (orderStocks == null) { result.Message = "制单指令库存明细获取失败"; result.ResultStatus = -1; return result; } foreach (Model.DocumentOrderStock orderStock in orderStocks) { result = orderStockDAL.Invalid(user, orderStock); if (result.ResultStatus != 0) return result; } OrderTypeEnum orderType = (OrderTypeEnum)resultOrder.OrderType; //新增库存明细与发票明细 foreach (Model.OrderReplaceStock stockInvoice in stockInvoices) { //验证临票库存明细 result = orderStockDAL.Get(user, stockInvoice.DetailId); if (result.ResultStatus != 0) return result; Model.DocumentOrderStock commercialOrderStock = result.ReturnValue as Model.DocumentOrderStock; if (commercialOrderStock == null || commercialOrderStock.OrderId <= 0) { result.Message = "制单指令替临库存不存在"; result.ResultStatus = -1; return result; } if (commercialOrderStock.DetailStatus != StatusEnum.已生效) { result.Message = "制单指令替临库存状态不正确"; result.ResultStatus = -1; return result; } if (commercialOrderStock.OrderId != resultOrder.CommercialId) { result.Message = "制单指令替临库存不存在"; result.ResultStatus = -1; return result; } Model.DocumentOrderStock orderStock = new DocumentOrderStock(); orderStock.DetailStatus = StatusEnum.已生效; orderStock.OrderId = resultOrder.OrderId; orderStock.ApplyAmount = stockInvoice.ApplyWeight; orderStock.StockId = commercialOrderStock.StockId; orderStock.StockNameId = commercialOrderStock.StockNameId; orderStock.RefNo = commercialOrderStock.RefNo; orderStock.ComDetailId = commercialOrderStock.DetailId; //添加库存明细 int orderStockId = 0; result = orderStockDAL.Insert(user, orderStock); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out orderStockId) || orderStockId <= 0) { result.Message = "制单指令库存明细新增失败"; result.ResultStatus = -1; return result; } //添加发票明细 Model.DocumentOrderInvoice orderInvoice = new DocumentOrderInvoice(); orderInvoice.DetailStatus = StatusEnum.已生效; orderInvoice.InvoiceBala = stockInvoice.InvoiceBala; orderInvoice.InvoiceNo = stockInvoice.InvoiceNo; orderInvoice.OrderId = resultOrder.OrderId; orderInvoice.StockDetailId = orderStockId; result = orderInvoiceDAL.Insert(user, orderInvoice); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = resultOrder; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Update(UserModel user, Model.DocumentOrder order, List<NFMT.Document.Model.OrderStockInvoice> stockInvoices, NFMT.Document.Model.DocumentOrderDetail detail) { ResultModel result = new ResultModel(); try { DAL.DocumentOrderDetailDAL orderDetailDAL = new DocumentOrderDetailDAL(); DAL.DocumentOrderStockDAL orderStockDAL = new DocumentOrderStockDAL(); DAL.DocumentOrderInvoiceDAL orderInvoiceDAL = new DocumentOrderInvoiceDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new WareHouse.DAL.StockDAL(); NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new WareHouse.DAL.StockNameDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); NFMT.Contract.DAL.ContractCorporationDetailDAL corpDetailDAL = new Contract.DAL.ContractCorporationDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { if (order == null) { result.Message = "制单指令不包含任何数据"; result.ResultStatus = -1; return result; } //验证制单指令 result = this.documentorderDAL.Get(user, order.OrderId); if (result.ResultStatus != 0) return result; Model.DocumentOrder resultOrder = result.ReturnValue as Model.DocumentOrder; if (resultOrder == null || resultOrder.OrderId <= 0) { result.Message = "制单指令不存在"; result.ResultStatus = -1; return result; } resultOrder.ContractNo = order.ContractNo; resultOrder.LCNo = order.LCNo; resultOrder.LCDay = order.LCDay; resultOrder.OrderType = order.OrderType; resultOrder.OrderDate = order.OrderDate; resultOrder.ApplyCorp = order.ApplyCorp; resultOrder.ApplyDept = order.ApplyDept; resultOrder.BuyerCorp = order.BuyerCorp; resultOrder.BuyerCorpName = order.BuyerCorpName; resultOrder.BuyerAddress = order.BuyerAddress; resultOrder.RecBankId = order.RecBankId; resultOrder.DiscountBase = order.DiscountBase; resultOrder.AssetId = order.AssetId; resultOrder.BrandId = order.BrandId; resultOrder.AreaName = order.AreaName; resultOrder.BankCode = order.BankCode; resultOrder.GrossAmount = order.GrossAmount; resultOrder.NetAmount = order.NetAmount; resultOrder.UnitId = order.UnitId; resultOrder.Bundles = order.Bundles; resultOrder.Currency = order.Currency; resultOrder.UnitPrice = order.UnitPrice; resultOrder.InvBala = order.InvBala; resultOrder.Meno = order.Meno; //更新主表 result = this.documentorderDAL.Update(user, resultOrder); if (result.ResultStatus != 0) return result; //获取明细表 result = orderDetailDAL.GetByOrderId(user, order.OrderId); if (result.ResultStatus != 0) return result; Model.DocumentOrderDetail resultDetail = result.ReturnValue as Model.DocumentOrderDetail; if (resultDetail == null || resultDetail.DetailId <= 0) { result.Message = "制单指令明细获取失败"; result.ResultStatus = -1; return result; } resultDetail.InvoiceCopies = detail.InvoiceCopies; resultDetail.InvoiceSpecific = detail.InvoiceSpecific; resultDetail.QualityCopies = detail.QualityCopies; resultDetail.QualitySpecific = detail.QualitySpecific; resultDetail.WeightCopies = detail.WeightCopies; resultDetail.WeightSpecific = detail.WeightSpecific; resultDetail.TexCopies = detail.TexCopies; resultDetail.TexSpecific = detail.TexSpecific; resultDetail.DeliverCopies = detail.DeliverCopies; resultDetail.DeliverSpecific = detail.DeliverSpecific; resultDetail.TotalInvCopies = detail.TotalInvCopies; resultDetail.TotalInvSpecific = detail.TotalInvSpecific; result = orderDetailDAL.Update(user, resultDetail); if (result.ResultStatus != 0) return result; //作废库存明细与发票明细 result = orderInvoiceDAL.Load(user, order.OrderId); if (result.ResultStatus != 0) return result; List<Model.DocumentOrderInvoice> orderInvoices = result.ReturnValue as List<Model.DocumentOrderInvoice>; if (orderInvoices == null) { result.Message = "制单指令发票明细获取失败"; result.ResultStatus = -1; return result; } foreach (Model.DocumentOrderInvoice orderInvoice in orderInvoices) { result = orderInvoiceDAL.Invalid(user, orderInvoice); if (result.ResultStatus != 0) return result; } result = orderStockDAL.Load(user,order.OrderId); if(result.ResultStatus!=0) return result; List<Model.DocumentOrderStock> orderStocks = result.ReturnValue as List<Model.DocumentOrderStock>; if (orderStocks == null) { result.Message = "制单指令库存明细获取失败"; result.ResultStatus = -1; return result; } foreach (Model.DocumentOrderStock orderStock in orderStocks) { result = orderStockDAL.Invalid(user, orderStock); if (result.ResultStatus != 0) return result; } OrderTypeEnum orderType = (OrderTypeEnum)order.OrderType; //新增库存明细与发票明细 foreach (Model.OrderStockInvoice stockInvoice in stockInvoices) { Model.DocumentOrderStock orderStock = new DocumentOrderStock(); orderStock.DetailStatus = StatusEnum.已生效; orderStock.OrderId = order.OrderId; orderStock.ApplyAmount = stockInvoice.ApplyWeight; //库存分配制单指令校验库存信息 if (orderType == OrderTypeEnum.临票制单指令 || orderType == OrderTypeEnum.替临制单指令) { //验证库存 result = stockDAL.Get(user, stockInvoice.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; } if (stock.AssetId != order.AssetId) { result.Message = "库存品种不匹配"; result.ResultStatus = -1; return result; } if (stock.CurNetAmount < stockInvoice.ApplyWeight) { result.Message = "申请重量不能大于库存剩余净重"; result.ResultStatus = -1; return result; } //获取业务单号 result = stockNameDAL.Get(user, stock.StockNameId); if (result.ResultStatus != 0) return result; NFMT.WareHouse.Model.StockName stockName = result.ReturnValue as NFMT.WareHouse.Model.StockName; if (stockName == null || stockName.StockNameId <= 0) { result.Message = "业务单号不存在"; result.ResultStatus = -1; return result; } orderStock.StockId = stock.StockId; orderStock.StockNameId = stock.StockNameId; orderStock.RefNo = stockName.RefNo; } else { //无库存配货权录入业务单号 orderStock.RefNo = stockInvoice.RefNo; } //添加库存明细 int orderStockId = 0; result = orderStockDAL.Insert(user, orderStock); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out orderStockId) || orderStockId <= 0) { result.Message = "制单指令库存明细新增失败"; result.ResultStatus = -1; return result; } //添加发票明细 Model.DocumentOrderInvoice orderInvoice = new DocumentOrderInvoice(); orderInvoice.DetailStatus = StatusEnum.已生效; orderInvoice.InvoiceBala = stockInvoice.InvoiceBala; orderInvoice.InvoiceNo = stockInvoice.InvoiceNo; orderInvoice.OrderId = order.OrderId; orderInvoice.StockDetailId = orderStockId; result = orderInvoiceDAL.Insert(user, orderInvoice); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = order; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } 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; }