/// <summary> /// 获取入库明细的分页信息 /// </summary> /// <param name="param"></param> /// <returns></returns> public PageList <STK_InLineResult> GetPageList(STK_InLineParam param) { PageList <STK_InLineResult> ret = new PageList <STK_InLineResult>(); try { STK_InParam InParam = new STK_InParam() { SourceBillNo = param.SourceBillNo, BillNo = param.StkInBillNo, PageIndex = 1, PageSize = 5000, Status = param.Status }; STK_InBLL inBLL = new STK_InBLL(); inBLL.SessionInfo = this.SessionInfo; PageList <STK_InResult> inList = inBLL.GetPageList(InParam); if (inList != null && inList.ResultList.Count > 0) { Guid?[] StkInGuids = inList.ResultList.Select(a => (Guid?)a.StkInGuid).Distinct().ToArray(); param.StkInGuids = StkInGuids; ret = this.SelectList <STK_InLineResult>(param.PageIndex.GetValueOrDefault(1), param.PageSize.GetValueOrDefault(50), new List <Field>() { Field.All }, GetWhereClip(param), STK_OutLine._.CreatedTime.Desc); if (ret != null && ret.ResultList.Count > 0) { foreach (STK_InLineResult inLineResult in ret.ResultList) { //获取入库单号 STK_InResult inResult = inList.ResultList.FirstOrDefault(a => a.StkInGuid == inLineResult.StkInGuid); if (inResult != null) { inLineResult.StkInBillNo = inResult.BillNo; inLineResult.SourceBillNo = inResult.SourceBillNo; } } } } } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(ret); }
/// <summary> /// 获取集合 /// </summary> /// <param name="param"></param> /// <returns></returns> public List <STK_InLineResult> GetList(STK_InLineParam param) { this.CheckSession(); List <STK_InLineResult> ret = new List <STK_InLineResult>(); try { WhereClip whereClip = GetWhereClip(param); ret = this.SelectList <STK_InLineResult>(whereClip, STK_InLine._.CreatedTime.Asc); if (ret != null && ret.Count > 0) { Guid?[] StkInGuids = ret.Select(a => a.StkInGuid).Distinct().ToArray(); STK_InBLL stkInBLL = new STK_InBLL(); stkInBLL.SessionInfo = this.SessionInfo; List <STK_InResult> inResultList = stkInBLL.GetList(new STK_InParam() { StkInGuids = StkInGuids }); foreach (STK_InLineResult inLineResult in ret) { STK_InResult inResult = inResultList.FirstOrDefault(a => a.StkInGuid == inLineResult.StkInGuid); if (inResult != null) { inLineResult.StkInBillNo = inResult.BillNo; inLineResult.SourceBillNo = inResult.SourceBillNo; } } } } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(ret); }
public bool AuditStkOutBill(STK_OutParam param) { bool auditFlag = true; try { STK_OutResult outResult = this.GetInfo(param); if (outResult != null) { bool isAllowAudit = true; if (outResult.ApproveStatus == "待提交") { isAllowAudit = false; throw new WarnException("出库单当前状态为:【待提交】,请先提交!"); } else if (outResult.ApproveStatus == "审核完成") { isAllowAudit = false; throw new WarnException("出库单当前状态为:【审核完成】,禁止重复审核!"); } if (isAllowAudit) { outResult.Status = "Complete"; outResult.ApproveStatus = "审核完成"; WCFAddUpdateResult ret = this.AddOrUpdate(outResult); if (ret.KeyGuid.ToGuid() == Guid.Empty) { auditFlag = false; } else { #region 定义相关变量(可重复使用) STK_OutLineBLL outLineBLL = new STK_OutLineBLL(); outLineBLL.SessionInfo = this.SessionInfo; STK_InBLL inBLL = new STK_InBLL(); inBLL.SessionInfo = this.SessionInfo; STK_InLineBLL inLineBLL = new STK_InLineBLL(); inLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL(); purOrderLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL(); purOrderBLL.SessionInfo = this.SessionInfo; ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL(); saleOrderBLL.SessionInfo = this.SessionInfo; ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL(); saleOrderLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseReturnBLL purReturnBLL = new ORD_PurchaseReturnBLL(); purReturnBLL.SessionInfo = this.SessionInfo; ORD_PurchaseReturnLineBLL purReturnLineBLL = new ORD_PurchaseReturnLineBLL(); purReturnLineBLL.SessionInfo = this.SessionInfo; STK_StockSheetBLL stockSheetBLL = new STK_StockSheetBLL(); stockSheetBLL.SessionInfo = this.SessionInfo; STK_StockBLL stockBLL = new STK_StockBLL(); stockBLL.SessionInfo = this.SessionInfo; STK_InOutLinkBLL inOutLinkBLL = new STK_InOutLinkBLL(); inOutLinkBLL.SessionInfo = this.SessionInfo; List <ORD_SalesOrderResult> saleList = null; List <ORD_SalesOrderLineResult> saleLineList = null; List <ORD_PurchaseOrderLineResult> purLineList = null; List <ORD_PurchaseReturnResult> purReturnList = null; List <ORD_PurchaseReturnLineResult> purReturnLineList = null; List <STK_InResult> stkInList = null; List <STK_InLineResult> stkInLineList = null; List <STK_InLineResult> effStkInLineList = null; List <STK_OutResult> stkOutList = null; List <STK_OutLineResult> stkOutLineList = null; List <STK_OutLineResult> effStkOutLineList = null; List <STK_StockResult> stockList = null; List <STK_StockSheetResult> stkStockSheetList = null; Guid?[] ItemCodes = null; Guid?[] StkInGuids = null; Guid?[] StkInLineGuids = null; Guid?[] EffStkInGuids = null; Guid?[] StkOutGuids = null; Guid?[] _stkOutLineGuids = null; Guid?[] EffStkOutGuids = null; Guid?[] POGuids = null; Guid?[] POLineGuids = null; Guid?[] SOGuids = null; Guid?[] SOLineGuids = null; Guid?[] PRGuids = null; Guid?[] PRLineGuids = null; #endregion //获取出库单下的出库明细集合 List <STK_OutLineResult> outLineList = outLineBLL.GetList(new STK_OutLineParam() { StkOutGuid = ret.KeyGuid }); //获取出库单下的关联明细集合 List <STK_InOutLinkResult> inOutLinkList = inOutLinkBLL.GetList(new STK_InOutLinkParam() { StkOutGuid = ret.KeyGuid }); if (outLineList != null && outLineList.Count > 0) { #region 减少库存,形成出库流水 ItemCodes = outLineList.Select(a => a.ItemCode).Distinct().ToArray(); stockList = stockBLL.GetList(new STK_StockParam() { ItemCodes = ItemCodes }); stkStockSheetList = new List <STK_StockSheetResult>(); STK_StockSheetResult stkStockSheetResult = null; foreach (STK_OutLineResult outLineResult in outLineList) { STK_StockResult stockResult = stockList.FirstOrDefault(a => a.ItemCode == outLineResult.ItemCode.ToGuid()); if (stockResult != null) { stockResult.InvQty -= outLineResult.Qty; stockResult.BookedQty -= outLineResult.Qty; stkStockSheetResult = new STK_StockSheetResult(); stkStockSheetResult.SSType = 2; stkStockSheetResult.SourceBillGuid = outResult.StkOutGuid; stkStockSheetResult.SourceBillNo = outResult.BillNo; stkStockSheetResult.SourceBillLineGuid = outLineResult.StkOutLineGuid; stkStockSheetResult.ItemCode = outLineResult.ItemCode; stkStockSheetResult.Model = outLineResult.Model; stkStockSheetResult.Brand = outLineResult.Brand; stkStockSheetResult.Batch = outLineResult.Batch; stkStockSheetResult.Package = outLineResult.Package; stkStockSheetResult.Quality = outLineResult.Quality; stkStockSheetResult.MPQ = outLineResult.MPQ; stkStockSheetResult.MarkCode = outLineResult.MarkCode; stkStockSheetResult.Currency = outLineResult.Currency; stkStockSheetResult.FlowQty = outLineResult.Qty; stkStockSheetResult.FlowPrice = outLineResult.UnitPrice; stkStockSheetResult.FlowAmount = outLineResult.Amount; stkStockSheetList.Add(stkStockSheetResult); } } stockBLL.UpdateOrInsertList(stockList); stockSheetBLL.UpdateOrInsertList(stkStockSheetList); #endregion #region 回写关联的入库单的出库数量和出库状态,入库单关联单据的出库数量和出库状态,出库单关联单据的出库数量和出库状态 #region 回写关联入库单的出库数量出库状态 //获取出库明细的guid StkInLineGuids = inOutLinkList.Select(a => a.StkInLineGuid).Distinct().ToArray(); if (StkInLineGuids != null && StkInLineGuids.Length > 0) { //获取出库明细所关联的入库明细 stkInLineList = inLineBLL.GetList(new STK_InLineParam() { StkInLineGuids = StkInLineGuids }); if (stkInLineList != null && stkInLineList.Count > 0) { //获取出库明细所关联的入库明细对应的出库明细 List <STK_InOutLinkResult> linkList = inOutLinkBLL.GetList(new STK_InOutLinkParam() { StkInLineGuids = StkInLineGuids }); if (linkList != null && linkList.Count > 0) { _stkOutLineGuids = linkList.Select(a => a.StkOutLineGuid).Distinct().ToArray(); stkOutLineList = outLineBLL.GetList(new STK_OutLineParam() { StkOutLineGuids = _stkOutLineGuids }); if (stkOutLineList != null && stkOutLineList.Count > 0) { //获取出库明细对应的出库主单guid StkOutGuids = stkOutLineList.Select(a => a.StkOutGuid).Distinct().ToArray(); if (StkOutGuids != null && StkOutGuids.Length > 0) { //获取出库明细对应的出库主单 stkOutList = this.GetList(new STK_OutParam() { StkOutGuids = StkOutGuids, Status = "Complete" }); if (stkOutList != null && stkOutList.Count > 0) { //获取有效的出库主单guid EffStkOutGuids = stkOutList.Select(a => a.StkOutGuid).Distinct().ToArray(); //获取有效的出库明细集合 effStkOutLineList = stkOutLineList.Where(a => EffStkOutGuids.Contains(a.StkOutGuid)).ToList(); foreach (STK_InLineResult stkInLineResult in stkInLineList) { //汇总出库明细的出库数量 int?qty = effStkOutLineList.Where(a => a.StkInLineGuid == stkInLineResult.StkInLineGuid).Sum(a => a.Qty.ToInt32()); //回写入库明细的出库数量 stkInLineResult.StkOutQty = qty; } } } //更新入库明细的集合 inLineBLL.UpdateOrInsertList(stkInLineList); //获取入库主单guid StkInGuids = stkInLineList.Select(a => a.StkInGuid).Distinct().ToArray(); foreach (Guid stkinguid in StkInGuids) { //更新入库单的状态 inBLL.UpdateStatus(new STK_InParam() { StkInGuid = stkinguid }); //获取入库单 STK_InResult stkInResult = inBLL.GetInfo(new STK_InParam() { StkInGuid = stkinguid }); if (stkInResult.BillType == "PO_IN") { #region 回写采购单的出库的数量出库状态 //找到入库明细所关联的采购明细guid和采购明细集合 POLineGuids = stkInLineList.Where(a => a.StkInGuid == stkinguid).Select(a => a.SourceBillLineGuid).Distinct().ToArray(); if (POLineGuids != null && POLineGuids.Length > 0) { purLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam() { POLineGuids = POLineGuids }); if (purLineList != null && purLineList.Count > 0) { //找到采购单明细关联的入库明细 List <STK_InLineResult> linkInLineList = inLineBLL.GetList(new STK_InLineParam() { SourceBillLineGuids = POLineGuids }); if (linkInLineList != null && linkInLineList.Count > 0) { //找到采购明细关联的入库明细的入库主单guid Guid?[] LinkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray(); if (LinkInGuids != null && LinkInGuids.Length > 0) { //找到采购单明细关联的入库明细所在的入库主单 stkInList = inBLL.GetList(new STK_InParam() { StkInGuids = LinkInGuids, Status = "Complete" }); if (stkInList != null && stkInList.Count > 0) { //有效的入库主单guid EffStkInGuids = stkInList.Select(a => a.StkInGuid).Distinct().ToArray(); //有效的入库明细集合 effStkInLineList = linkInLineList.Where(a => EffStkInGuids.Contains(a.StkInGuid)).ToList(); foreach (ORD_PurchaseOrderLineResult purLineResult in purLineList) { //汇总有效的入库明细的出库数量 int?qty = effStkInLineList.Where(a => a.SourceBillLineGuid == purLineResult.POLineGuid).Sum(a => a.StkOutQty).ToInt32(); //更新采购明细的出库数量 purLineResult.StkOutQty = qty; } } } } //更新采购明细集合 purOrderLineBLL.UpdateOrInsertList(purLineList); POGuids = purLineList.Select(a => a.POGuid).Distinct().ToArray(); foreach (Guid poguid in POGuids) { purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam() { POGuid = poguid }); } } } #endregion } else if (stkInResult.BillType == "SOR_IN") { } else if (stkInResult.BillType == "ZX_IN") { } } } } } } #endregion #region 回写出库单关联的业务单据的出库数量和出库状态 if (outResult.BillType == "SO_OUT") { #region 回写销售单的出库数量和出库状态 //获取出库明细对应的销售明细guid SOLineGuids = outLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray(); if (SOLineGuids != null && SOLineGuids.Length > 0) { //获取出库明细对应的销售明细 saleLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam() { SOLineGuids = SOLineGuids }); if (saleLineList != null && saleLineList.Count > 0) { //获取出库明细对应的销售明细关联关联的出库明细 stkOutLineList = outLineBLL.GetList(new STK_OutLineParam() { SourceBillLineGuids = SOLineGuids }); if (stkOutLineList != null && stkOutLineList.Count > 0) { //获取出库明细对应的出库主单guid StkOutGuids = stkOutLineList.Select(a => a.StkOutGuid).Distinct().ToArray(); if (StkOutGuids != null && StkOutGuids.Length > 0) { //获取出库明细对应的出库主单 stkOutList = this.GetList(new STK_OutParam() { StkOutGuids = StkOutGuids, Status = "Complete" }); if (stkOutList != null && stkOutList.Count > 0) { //获取有效的出库主单guid EffStkOutGuids = stkOutList.Select(a => a.StkOutGuid).Distinct().ToArray(); //获取有效的出库明细集合 effStkOutLineList = stkOutLineList.Where(a => EffStkOutGuids.Contains(a.StkOutGuid)).ToList(); foreach (ORD_SalesOrderLineResult orderLineResult in saleLineList) { //汇总有效的出库明细的出库数量 int?qty = effStkOutLineList.Where(a => a.SourceBillLineGuid == orderLineResult.SOLineGuid).Sum(a => a.Qty).ToInt32(); orderLineResult.StkOutQty = qty; } } } } saleOrderLineBLL.UpdateOrInsertList(saleLineList); SOGuids = saleLineList.Select(a => a.SOGuid).Distinct().ToArray(); foreach (Guid soguid in SOGuids) { saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam() { SOGuid = soguid }); } } } #endregion } else if (outResult.BillType == "POR_OUT") { #region 回写采购退货单的出库数量和出库状态 //获取出库明细对应的退货明细guid PRLineGuids = outLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray(); if (PRLineGuids != null && PRLineGuids.Length > 0) { //获取出库明细对应的退货明细 purReturnLineList = purReturnLineBLL.GetList(new ORD_PurchaseReturnLineParam() { PRLineGuids = PRLineGuids }); if (purReturnLineList != null && purReturnLineList.Count > 0) { //获取出库明细对应的退货明细关联关联的出库明细 stkOutLineList = outLineBLL.GetList(new STK_OutLineParam() { SourceBillLineGuids = PRLineGuids }); if (stkOutLineList != null && stkOutLineList.Count > 0) { //获取出库明细对应的出库主单guid StkOutGuids = stkOutLineList.Select(a => a.StkOutGuid).Distinct().ToArray(); if (StkOutGuids != null && StkOutGuids.Length > 0) { //获取出库明细对应的出库主单 stkOutList = this.GetList(new STK_OutParam() { StkOutGuids = StkOutGuids, Status = "Complete" }); if (stkOutList != null && stkOutList.Count > 0) { //获取有效的出库主单guid EffStkOutGuids = stkOutList.Select(a => a.StkOutGuid).Distinct().ToArray(); //获取有效的出库明细集合 effStkOutLineList = stkOutLineList.Where(a => EffStkOutGuids.Contains(a.StkOutGuid)).ToList(); foreach (ORD_PurchaseReturnLineResult purReturnLineResult in purReturnLineList) { //汇总有效的出库明细的出库数量 int?qty = effStkOutLineList.Where(a => a.SourceBillLineGuid == purReturnLineResult.PRLineGuid).Sum(a => a.Qty).ToInt32(); purReturnLineResult.StkOutQty = qty; } } } } purReturnLineBLL.UpdateOrInsertList(purReturnLineList); PRGuids = purReturnLineList.Select(a => a.PRGuid).Distinct().ToArray(); foreach (Guid prguid in PRGuids) { purReturnBLL.UpdateStatus(new ORD_PurchaseReturnParam() { PRGuid = prguid }); } } } #endregion } else if (outResult.BillType == "ZX_OUT") { } #endregion #endregion } } } } else { throw new WarnException("要审核的出库单在系统中不存在!"); } } catch (WarnException exp) { throw exp; } catch (Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(auditFlag); }
public bool SubmitStkInBill(STK_InParam param) { this.CheckSession(); bool submitFlag = true; try { STK_InResult inResult = this.GetInfo(param); if (inResult != null) { #region 更新关联单据的相关数据(回写)和状态 //入库单关联的入库明细 List <STK_InLineResult> inLineList = inResult.StkInLineList; if (inLineList != null && inLineList.Count > 0) { #region 定义相关变量(可重复使用) #region 申明逻辑层变量 ORD_PurchaseOrderLineBLL purLineBLL = new ORD_PurchaseOrderLineBLL(); purLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL(); purOrderBLL.SessionInfo = this.SessionInfo; ORD_SalesReturnBLL returnBLL = new ORD_SalesReturnBLL(); returnBLL.SessionInfo = this.SessionInfo; ORD_SalesReturnLineBLL returnLineBLL = new ORD_SalesReturnLineBLL(); returnLineBLL.SessionInfo = this.SessionInfo; STK_InLineBLL stkInLineBLL = new STK_InLineBLL(); stkInLineBLL.SessionInfo = this.SessionInfo; STK_InBLL inBLL = new STK_InBLL(); inBLL.SessionInfo = this.SessionInfo; #endregion #region 初始化变量 Guid? POGuid = null; Guid?[] POLineGuids = null; Guid? SRGuid = null; Guid?[] SRLineGuids = null; Guid?[] StkInGuids = null; Guid?[] effInGuids = null; List <ORD_PurchaseOrderLineResult> purLineList = null; List <ORD_SalesReturnLineResult> returnLineList = null; List <STK_InResult> inList = null; List <STK_InLineResult> linkInLineList = null; List <STK_InLineResult> effInLineList = null; #endregion #endregion if (inResult.BillType == "PO_IN") { #region 更新采购明细的占有数量和采购主单的占有状态 POGuid = inResult.SourceBillGuid; //关联的采购主单 POLineGuids = inLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray(); //关联的采购明细ID集合 if (POLineGuids != null && POLineGuids.Length > 0) { purLineList = purLineBLL.GetList(new ORD_PurchaseOrderLineParam() { POLineGuids = POLineGuids }); //采购明细 linkInLineList = stkInLineBLL.GetList(new STK_InLineParam() { SourceBillLineGuids = POLineGuids }); //采购明细所关联的入库明细 StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray(); if (StkInGuids != null && StkInGuids.Length > 0) { //采购明细所关联的入库明细对应的入库主单 inList = this.GetList(new STK_InParam() { StkInGuids = StkInGuids, StatusArr = new string[] { "Complete", "Approve" } }); if (inList != null && inList.Count > 0) { effInGuids = inList.Select(a => a.StkInGuid).Distinct().ToArray(); effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList(); foreach (ORD_PurchaseOrderLineResult purLineResult in purLineList) { int?qty = effInLineList.Where(a => a.SourceBillLineGuid == purLineResult.POLineGuid).Sum(a => a.Qty.ToInt32()); purLineResult.StkInOccQty = qty; } } } purLineBLL.UpdateOrInsertList(purLineList); purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam() { POGuid = POGuid }); } #endregion } else if (inResult.BillType == "SOR_IN") { #region 更新销售退货明细的入库占有数量和退货主单的占有状态 //关联的销售退货主单 SRGuid = inResult.SourceBillGuid; //关联的销售退货明细ID集合 SRLineGuids = inLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray(); if (SRLineGuids != null && SRLineGuids.Length > 0) { //退货明细 returnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam() { SRLineGuids = SRLineGuids }); //退货明细所关联的入库明细 linkInLineList = stkInLineBLL.GetList(new STK_InLineParam() { SourceBillLineGuids = SRLineGuids }); StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray(); if (StkInGuids != null && StkInGuids.Length > 0) { //退货明细所关联的入库明细对应的入库主单 inList = this.GetList(new STK_InParam() { StkInGuids = StkInGuids, StatusArr = new string[] { "Complete", "Approve" } }); if (inList != null && inList.Count > 0) { effInGuids = inList.Select(a => a.StkInGuid).Distinct().ToArray(); effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList(); foreach (ORD_SalesReturnLineResult returnLineResult in returnLineList) { int?qty = effInLineList.Where(a => a.SourceBillLineGuid == returnLineResult.SRLineGuid).Sum(a => a.Qty.ToInt32()); returnLineResult.StkInOccQty = qty; } } } returnLineBLL.UpdateOrInsertList(returnLineList); } #endregion } else if (inResult.BillType == "ZX_IN") { } } #endregion } else { throw new WarnException("要提交的入库单在系统中不存在!"); } } catch (WarnException exp) { throw exp; } catch (Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(submitFlag); }