public bool CancelPurchaseNotice(ORD_PurchaseNoticeParam param) { bool flag = true; try { ORD_PurchaseNoticeResult noticeResult = this.GetInfo(param); if (noticeResult != null) { if (noticeResult.PurchaseQty > 0) { flag = false; throw new WarnException("当前采购通知已存在关联的采购信息,不允许取消通知!"); } this.DelInfo(param);//删除当前采购通知 //汇总采购通知所关联的销售明细下所有关联的有效的采购通知的数量 List <ORD_PurchaseNoticeResult> noticeList = this.GetList(new ORD_PurchaseNoticeParam() { SOLineGuid = noticeResult.SOLineGuid }); int?noticeQty = 0; if (noticeList != null && noticeList.Count > 0) { noticeQty = noticeList.Sum(a => a.NoticeQty); } ORD_SalesOrderLineBLL orderLineBLL = new ORD_SalesOrderLineBLL(); orderLineBLL.SessionInfo = this.SessionInfo; ORD_SalesOrderLineResult orderLineResult = orderLineBLL.GetInfo(new ORD_SalesOrderLineParam() { SOLineGuid = noticeResult.SOLineGuid }); orderLineResult.NotifyQty = noticeQty; orderLineBLL.AddOrUpdate(orderLineResult); ORD_SalesOrderBLL orderBLL = new ORD_SalesOrderBLL(); orderBLL.SessionInfo = this.SessionInfo; orderBLL.UpdateStatus(new ORD_SalesOrderParam() { SOGuid = noticeResult.SOGuid }); //更新销售明细的通知状态 } else { flag = false; throw new WarnException("当前采购通知记录在系统中不存在!"); } } catch (WarnException exp) { throw exp; } catch (Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(flag); }
public bool SubmitSalesReturnBill(ORD_SalesReturnParam param) { this.CheckSession(); bool submitFlag = true; try { ORD_SalesReturnResult returnResult = this.GetInfo(param); if (returnResult != null) { #region 判断是否可以提交 bool isAllowSubmit = true; if (returnResult.ApproveStatus == "待审核") { isAllowSubmit = false; throw new WarnException("销售退货单当前状态为:【已提交,待审核】,禁止重复提交!"); } else if (returnResult.ApproveStatus == "审核完成") { isAllowSubmit = false; throw new WarnException("销售退货单当前状态为:【审核完成】,撤单后才可以再次提交!"); } if (isAllowSubmit) { returnResult.Status = "Approve"; returnResult.ApproveStatus = "待审核"; WCFAddUpdateResult ret = this.AddOrUpdate(returnResult); if (ret.KeyGuid.ToGuid() == Guid.Empty) { submitFlag = false; } else { #region 定义相关变量 ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL(); saleOrderBLL.SessionInfo = this.SessionInfo; ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL(); saleOrderLineBLL.SessionInfo = this.SessionInfo; STK_OutBLL outBLL = new STK_OutBLL(); outBLL.SessionInfo = this.SessionInfo; STK_OutLineBLL outLineBLL = new STK_OutLineBLL(); outLineBLL.SessionInfo = this.SessionInfo; ORD_SalesReturnLineBLL returnLineBLL = new ORD_SalesReturnLineBLL(); returnLineBLL.SessionInfo = this.SessionInfo; Guid?[] SOLineGuids = null; Guid?[] StkOutLineGuids = null; Guid?[] SRGuids = null; Guid?[] effSRGuids = null; Guid?[] SOGuids = null; List <STK_OutLineResult> linkOutLineList = new List <STK_OutLineResult>(); List <ORD_SalesOrderLineResult> linkSaleOrderLineList = new List <ORD_SalesOrderLineResult>(); List <ORD_SalesReturnResult> linkReturnList = new List <ORD_SalesReturnResult>(); List <ORD_SalesReturnLineResult> linkReturnLineList = new List <ORD_SalesReturnLineResult>(); List <ORD_SalesReturnLineResult> effReturnLineList = new List <ORD_SalesReturnLineResult>(); #endregion List <ORD_SalesReturnLineResult> salesReturnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam() { SRGuid = returnResult.SRGuid }); #region 更新出库明细的数量 //获取退货明细关联的出库明细ID集合 StkOutLineGuids = salesReturnLineList.Select(a => a.StkOutLineGuid).Distinct().ToArray(); if (StkOutLineGuids != null && StkOutLineGuids.Length > 0) { //退货明细关联的出库明细 linkOutLineList = outLineBLL.GetList(new STK_OutLineParam() { StkOutLineGuids = StkOutLineGuids }); //关联的出库明细所关联的退货明细 linkReturnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam() { StkOutLineGuids = StkOutLineGuids }); SRGuids = linkReturnLineList.Select(a => a.SRGuid).Distinct().ToArray(); if (SRGuids != null && SRGuids.Length > 0) { //关联的出库明细所关联的退货明细对应的退货主单 linkReturnList = this.GetList(new ORD_SalesReturnParam() { SRGuids = SRGuids, StatusArr = new string[] { "Complete", "Approve" } }); if (linkReturnList != null && linkReturnList.Count > 0) { effSRGuids = linkReturnList.Select(a => (Guid?)a.SRGuid).Distinct().ToArray(); effReturnLineList = linkReturnLineList.Where(a => effSRGuids.Contains(a.SRGuid)).ToList(); foreach (STK_OutLineResult outLineResult in linkOutLineList) { int?qty = effReturnLineList.Where(a => a.StkOutLineGuid == outLineResult.StkOutLineGuid).Sum(a => a.Qty.ToInt32()); outLineResult.ReturnOccQty = qty; } } } //更新退货明细关联的出库明细的退货数量 outLineBLL.UpdateOrInsertList(linkOutLineList); } #endregion #region 更新销售明细的退货占有数量和销售主单的退货占有状态 //获取关联的销售明细ID集合 SOLineGuids = salesReturnLineList.Select(a => a.SOLineGuid).Distinct().ToArray(); linkSaleOrderLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam() { SOLineGuids = SOLineGuids, IsCancel = false }); //获取关联的销售明细所关联的退货明细 linkReturnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam() { SOLineGuids = SOLineGuids }); SRGuids = linkReturnLineList.Select(a => a.SRGuid).Distinct().ToArray(); if (SRGuids != null && SRGuids.Length > 0) { //销售明细所关联的退货明细对应的退货主单 linkReturnList = this.GetList(new ORD_SalesReturnParam() { SRGuids = SRGuids, StatusArr = new string[] { "Complete", "Approve" } }); if (linkReturnList != null && linkReturnList.Count > 0) { effSRGuids = linkReturnList.Select(a => (Guid?)a.SRGuid).Distinct().ToArray(); effReturnLineList = linkReturnLineList.Where(a => effSRGuids.Contains(a.SRGuid)).ToList(); foreach (ORD_SalesOrderLineResult saleLineResult in linkSaleOrderLineList) { int?qty = effReturnLineList.Where(a => a.SOLineGuid == saleLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32()); saleLineResult.ReturnOccQty = qty; } } } saleOrderLineBLL.UpdateOrInsertList(linkSaleOrderLineList); SOGuids = linkSaleOrderLineList.Select(a => a.SOGuid).Distinct().ToArray(); foreach (Guid soguid in SOGuids) { saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam() { SOGuid = soguid }); } #endregion } } #endregion } else { throw new WarnException("要提交的销售退货单在系统中不存在!"); } } catch (WarnException exp) { throw exp; } catch (Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(submitFlag); }
/// <summary> /// 批量修改和插入 /// </summary> /// <param name="paramList"></param> /// <returns></returns> public WCFAddUpdateResult UpdateOrInsertList(List <ORD_PurchaseNoticeResult> list) { this.CheckSession(); WCFAddUpdateResult ret = new WCFAddUpdateResult(); try { #region 判断 if (list.Count <= 0) { throw new WarnException("没有需要操作的对象!"); } #endregion foreach (ORD_PurchaseNoticeResult noticeResult in list) { if (noticeResult.NoticeGuid.ToGuid() != Guid.Empty) { noticeResult.UpdatedEmpID = this.SessionInfo.UserID; noticeResult.UpdatedEmpName = this.SessionInfo.UserName; noticeResult.UpdatedTime = DateTime.Now; } else { noticeResult.NoticeGuid = Guid.NewGuid(); noticeResult.CreatedEmpID = this.SessionInfo.UserID; noticeResult.CreatedEmpName = this.SessionInfo.UserName; noticeResult.CreatedTime = DateTime.Now; noticeResult.IsDeleted = false; } } int affect = 0; this.BatchInsertOrUpdate <ORD_PurchaseNoticeResult>(list); affect = this.BatchExecute(); #region 设置返回值 ret.Key = affect; #endregion if (affect > 0) { Guid?[] SOLineGuids = list.Where(a => a.SOLineGuid.ToGuid() != Guid.Empty).Select(a => a.SOLineGuid).Distinct().ToArray(); if (SOLineGuids.Length > 0) { List <ORD_PurchaseNoticeResult> noticeList = this.GetList(new ORD_PurchaseNoticeParam() { SOLineGuids = SOLineGuids }); List <ORD_SalesOrderLineResult> lineResultList = new List <ORD_SalesOrderLineResult>(); ORD_SalesOrderLineResult lineResult = null; foreach (Guid soLineGuid in SOLineGuids) { lineResult = new ORD_SalesOrderLineResult(); lineResult.SOLineGuid = soLineGuid; int Qty = noticeList.Where(a => a.SOLineGuid == soLineGuid).Sum(a => a.NoticeQty.ToInt32()); lineResult.NotifyQty = Qty; lineResultList.Add(lineResult); } ORD_SalesOrderLineBLL lineBLL = new ORD_SalesOrderLineBLL(); lineBLL.SessionInfo = this.SessionInfo; lineBLL.UpdateOrInsertList(lineResultList);//更新销售明细的通知数量 ORD_SalesOrderBLL orderBLL = new ORD_SalesOrderBLL(); orderBLL.UpdateStatus(new ORD_SalesOrderParam() { SOGuid = list[0].SOGuid }); //更新销售明细的通知状态 } } } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(ret); }