/// <summary> /// 获取一条信息记录 /// </summary> /// <param name="param"></param> /// <returns></returns> public STK_StockReserveResult GetInfo(STK_StockReserveParam param) { this.CheckSession(); STK_StockReserveResult rst = new STK_StockReserveResult(); #region 判断 if (param.SRGuid == null) { throw new WarnException("请指定GUID!"); } #endregion #region 获取实体 try { rst = this.Select <STK_StockReserveResult>(GetWhereClip(param)); } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } #endregion return(rst); }
private void btnOK_Click(object sender, EventArgs e) { List <STK_StockReserveResult> tempReserveList = new List <STK_StockReserveResult>(); foreach (DataGridViewRow row in dgvReserve.Rows) { Guid?srGuid = row.Cells["colSRGuid"].Value.ToGuid(); int? reserveQty = row.Cells["colReserveQty"].Value.ToInt32(); int? oldReserveQty = row.Cells["colReserveQty"].Tag.ToInt32(); STK_StockReserveResult reserveResult = reserveList.FirstOrDefault(a => a.SRGuid == srGuid); if (reserveResult != null) { if (reserveQty != oldReserveQty) { reserveResult.ReserveQty = reserveQty; tempReserveList.Add(reserveResult); } } } if (tempReserveList.Count > 0) { reserveLogic.OperateReserveList(tempReserveList); InitData(); BindReserveDataGridView(); BindStockDataGridView(1); if (RefreshParentForm != null) { RefreshParentForm(); } } }
/// <summary> /// 删除实体 /// </summary> /// <param name="param">删除条件实体</param> /// <returns></returns> public WCFAddUpdateResult DelInfo(STK_StockReserveParam param) { this.CheckSession(); WCFAddUpdateResult ret = new WCFAddUpdateResult(); int affect = 0; try { #region 判断 if (param.SRGuid == null) { throw new WarnException("请指定GUID!"); } #endregion WhereClip whereClip = GetWhereClip(param); STK_StockReserveResult info = new STK_StockReserveResult(); info.IsDeleted = true; affect = this.Update <STK_StockReserveResult>(info, whereClip); #region 设置返回值 ret.Key = affect; #endregion } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(ret); }
public STK_StockReserveResult GetInfo(STK_StockReserveParam param) { STK_StockReserveResult ret = new STK_StockReserveResult(); ExeResult rst = new ExeResult(); rst = this.Execute("ZNLCRM.BLL.STK.STK_StockReserveBLL", "GetInfo", param); ret = (rst == null ? new STK_StockReserveResult() : rst.Result as STK_StockReserveResult); return(ret); }
public WCFAddUpdateResult AddOrUpdate(STK_StockReserveResult param) { WCFAddUpdateResult ret = new WCFAddUpdateResult(); ExeResult rst = new ExeResult(); rst = this.Execute("ZNLCRM.BLL.STK.STK_StockReserveBLL", "AddOrUpdate", param); ret = (rst == null ? new WCFAddUpdateResult() : rst.Result as WCFAddUpdateResult); return(ret); }
public bool OperateReserve(STK_StockReserveResult result) { bool flag = false; ExeResult rst = new ExeResult(); rst = this.Execute("ZNLCRM.BLL.STK.STK_StockReserveBLL", "OperateReserve", result); flag = (rst == null ? true : (bool)rst.Result); return(flag); }
private void usgSource_RowActivated(object sender, GridRowActivatedEventArgs e) { if (e.NewActiveRow.RowIndex > -1) { GridRow gridRow = usgSource.PrimaryGrid.Rows[e.NewActiveRow.RowIndex] as GridRow; if (gridRow != null) { Guid?SourceBillLineGuid = gridRow.Cells["colSourceBillLineGuid"].Value.ToGuid(); STK_StockReserveResult reserveResult = reserveList.FirstOrDefault(a => a.SourceBillLineGuid == SourceBillLineGuid); if (reserveResult != null) { usgReserve.PrimaryGrid.DataSource = reserveResult.ReserveList; } } } }
private void dgvReserve_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1 && e.ColumnIndex > -1) { if (dgvReserve.Columns[e.ColumnIndex].Name == "colAddReserve") { DataGridViewRow row = dgvReserve.Rows[e.RowIndex]; Guid? srGuid = row.Cells["colSRGuid"].Value.ToGuid(); STK_StockReserveResult reserveResult = new STK_StockReserveResult(); reserveResult.SRGuid = srGuid; reserveResult.IsDeleted = true; reserveLogic.OperateReserve(reserveResult); InitData(); BindReserveDataGridView(); BindStockDataGridView(1); if (RefreshParentForm != null) { RefreshParentForm(); } } } }
private void dgvStock_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1 && e.ColumnIndex > -1) { if (dgvStock.Columns[e.ColumnIndex].Name == "colAddReserve") { DataGridViewRow row = dgvStock.Rows[e.RowIndex]; Guid? itemCode = row.Cells["col_Stock_ItemCode"].Value.ToGuid(); STK_StockReserveResult reserveResult = new STK_StockReserveResult(); reserveResult.SourceBillGuid = SourceBillGuid; reserveResult.SourceBillNo = SourceBillNo; reserveResult.SourceBillLineGuid = SourceBillLineGuid; reserveResult.SourceBillType = SourceBillType; reserveResult.ReserveType = 1; reserveResult.OperType = true; STK_StockResult stockResult = stockLogic.GetInfo(new STK_StockParam() { ItemCode = itemCode }); if (stockResult != null) { reserveResult.StkInLineGuid = stockResult.StkInLineGuid; } reserveResult.ItemCode = itemCode; reserveResult.OperFlag = true;//增加 reserveLogic.OperateReserve(reserveResult); InitData(); BindReserveDataGridView(); BindStockDataGridView(1); if (RefreshParentForm != null) { RefreshParentForm(); } } } }
public void SetStkLineObjectValue(STK_OutLineResult outLineRst, STK_StockReserveResult reserveResult) { outLineRst.SRGuid = reserveResult.SRGuid; outLineRst.StkInLineGuid = reserveResult.StkInLineGuid; outLineRst.ItemCode = reserveResult.ItemCode; outLineRst.SourceBillGuid = reserveResult.SourceBillGuid; outLineRst.SourceBillLineGuid = reserveResult.SourceBillLineGuid; outLineRst.Model = reserveResult.Model; outLineRst.Brand = reserveResult.Brand; outLineRst.Package = reserveResult.Package; outLineRst.Batch = reserveResult.Batch; outLineRst.TaxRate = cboTaxRate.SelectedValue.ToDecimal(); outLineRst.InvType = reserveResult.InvType; outLineRst.Currency = cboCurrency.SelectedValue.ToStringHasNull(); outLineRst.Unit = reserveResult.Unit; outLineRst.Qty = reserveResult.ReserveQty.ToInt32() - reserveResult.UsedQty.ToInt32(); outLineRst.Amount = outLineRst.Qty * outLineRst.UnitPrice; outLineRst.Warehouse = reserveResult.Warehouse; outLineRst.Location = reserveResult.Location; outLineRst.IsCut = true; outLineRst.IsPCut = true; outLineRst.IsRaiseTaxes = false; outLineRst.IsDeleted = false; }
/// <summary> /// 添加和新增修改 /// </summary> /// <param name="param">新增或修改的实体</param> /// <returns></returns> public WCFAddUpdateResult AddOrUpdate(STK_StockReserveResult param) { this.CheckSession(); WCFAddUpdateResult ret = new WCFAddUpdateResult(); try { int affect = 0; #region 判断 if (param.ItemCode == null) { throw new WarnException("没有关联库存"); } #endregion #region 系统默认值 if (param.SRGuid != null) { WhereClip where = STK_StockReserve._.SRGuid == param.SRGuid; param.UpdatedEmpID = this.SessionInfo.UserID; param.UpdatedEmpName = this.SessionInfo.UserName; param.UpdatedTime = DateTime.Now; affect = this.Update <STK_StockReserveResult>(param, where); } else { param.SRGuid = Guid.NewGuid(); param.GCompanyID = this.SessionInfo.CompanyID; param.IsDeleted = false; param.CreatedEmpID = this.SessionInfo.UserID; param.CreatedEmpName = this.SessionInfo.UserName; param.CreatedTime = DateTime.Now; affect = this.Insert <STK_StockReserveResult>(param); param = this.Select <STK_StockReserveResult>(new List <Field>() { STK_StockReserve._.All }, STK_StockReserve._.SRGuid == param.SRGuid); } #region 设置返回值 ret.KeyGuid = param.SRGuid; ret.CreatedTime = param.CreatedTime; ret.CreatedEmpID = param.CreatedEmpID; ret.CreatedEmpName = param.CreatedEmpName; ret.UpdatedEmpID = param.UpdatedEmpID; ret.UpdatedEmpName = param.UpdatedEmpName; ret.UpdatedTime = param.UpdatedTime; #endregion #endregion } 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 PageList <STK_StockReserveResult> GetPageList(STK_StockReserveParam param) { this.CheckSession(); PageList <STK_StockReserveResult> ret = new PageList <STK_StockReserveResult>(); try { #region 处理销售明细 WhereClip orderClip = ORD_SalesOrder._.IsDeleted == 0; if (!string.IsNullOrEmpty(param.SourceBillNo)) { orderClip = orderClip && ORD_SalesOrder._.BillNo.Like(param.SourceBillNo + "%"); } if (param.SourceBillGuid != null) { orderClip = orderClip && ORD_SalesOrder._.SOGuid == param.SourceBillGuid; } PageList <ORD_SalesOrderResult> orderList = this.SelectList <ORD_SalesOrderResult>(1, 5000, new List <Field>() { Field.All }, orderClip, ORD_SalesOrder._.CreatedTime.Desc); PageList <ORD_SalesOrderLineResult> lineList = null; Guid?[] SOGuids = null; if (orderList.ResultList != null && orderList.ResultList.Count > 0) { SOGuids = orderList.ResultList.Select(a => a.SOGuid).Distinct().ToArray(); } WhereClip lineClip = ORD_SalesOrderLine._.IsDeleted == 0; if (SOGuids != null) { lineClip = lineClip && ORD_SalesOrderLine._.SOGuid.In(SOGuids); } if (!string.IsNullOrEmpty(param.Model)) { lineClip = lineClip && ORD_SalesOrderLine._.Model.Like(param.Model + "%"); } if (!string.IsNullOrEmpty(param.SourceBillLineCode)) { lineClip = lineClip && ORD_SalesOrderLine._.SOLineCode.Like(param.SourceBillLineCode + "%"); } lineList = this.SelectList <ORD_SalesOrderLineResult>(param.PageIndex.GetValueOrDefault(1), param.PageSize.GetValueOrDefault(100), new List <Field>() { Field.All }, lineClip, ORD_SalesOrderLine._.CreatedTime.Desc); if (lineList != null && lineList.ResultList.Count > 0) { #region 获取业务明细下的预留信息 Guid?[] SOLineGuids = lineList.ResultList.Select(a => (Guid?)a.SOLineGuid).Distinct().ToArray(); STK_StockReserveParam reserveParam = new STK_StockReserveParam(); reserveParam.SourceBillLineGuids = SOLineGuids; List <STK_StockReserveResult> childReserveResultList = this.GetList(reserveParam); #endregion List <STK_StockReserveResult> reserveResultList = new List <STK_StockReserveResult> (); STK_StockReserveResult reserveResult = null; foreach (ORD_SalesOrderLineResult lineResult in lineList.ResultList) { reserveResult = new STK_StockReserveResult(); ORD_SalesOrderResult orderResult = orderList.ResultList.FirstOrDefault(a => a.SOGuid == lineResult.SOGuid); if (orderResult != null) { reserveResult.SourceBillNo = orderResult.BillNo; reserveResult.SourceBillType = "销售出库"; reserveResult.BelongEmpName = orderResult.SalerName; reserveResult.SourceBillDate = orderResult.SODate; } reserveResult.SourceBillGuid = lineResult.SOGuid; reserveResult.SourceBillLineGuid = lineResult.SOLineGuid; reserveResult.SourceBillLineCode = lineResult.SOLineCode; reserveResult.Model = lineResult.Model; reserveResult.Brand = lineResult.Brand; reserveResult.Qty = lineResult.Qty; reserveResult.ReserveQty = lineResult.ReserveQty; reserveResult.CreatedEmpName = lineResult.CreatedEmpName; reserveResult.CreatedTime = lineResult.CreatedTime; reserveResult.UpdatedEmpName = lineResult.UpdatedEmpName; reserveResult.UpdatedTime = lineResult.UpdatedTime; if (childReserveResultList != null && childReserveResultList.Count > 0) { List <STK_StockReserveResult> srList = childReserveResultList.Where(a => a.SourceBillLineGuid == lineResult.SOLineGuid).ToList(); if (srList != null && srList.Count > 0) { Guid?[] ItemCodes = srList.Select(a => a.ItemCode).Distinct().ToArray(); STK_StockBLL stockBLL = new STK_StockBLL(); stockBLL.SessionInfo = this.SessionInfo; List <STK_StockResult> stockList = stockBLL.GetList(new STK_StockParam() { ItemCodes = ItemCodes }); foreach (STK_StockReserveResult sr in srList) { if (stockList != null && stockList.Count > 0) { STK_StockResult stockResult = stockList.FirstOrDefault(a => a.ItemCode == sr.ItemCode); sr.Model = stockResult.Model; sr.Brand = stockResult.Brand; sr.Batch = stockResult.Batch; sr.Package = stockResult.Package; sr.Quality = stockResult.Quality; sr.MPQ = stockResult.MPQ; sr.MarkCode = stockResult.MarkCode; sr.Warehouse = stockResult.Warehouse; sr.Location = stockResult.Location; sr.InvType = stockResult.InvType; sr.InBatchNo = stockResult.InBatchNo; } } reserveResult.ReserveList = srList; } } reserveResultList.Add(reserveResult); } if (ret.ResultList == null) { ret.ResultList = new List <STK_StockReserveResult>(); } ret.ResultList.AddRange(reserveResultList); ret.TotalCount = lineList.TotalCount; } #endregion #region 处理采购退货明细 #endregion } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(ret); }
/// <summary> /// 操作预留 /// </summary> /// <param name="result"></param> /// <returns></returns> public bool OperateReserve(STK_StockReserveResult result) { this.CheckSession(); try { //预留调整量 int?tempReserveQty = 0; ORD_SalesOrderLineResult orderLineResult = new ORD_SalesOrderLineResult(); ORD_SalesOrderLineBLL orderLineBLL = new ORD_SalesOrderLineBLL(); orderLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseReturnLineResult returnLineResult = new ORD_PurchaseReturnLineResult(); ORD_PurchaseReturnLineBLL returnLineBLL = new ORD_PurchaseReturnLineBLL(); returnLineBLL.SessionInfo = this.SessionInfo; //空值转换为零 if (result.ReserveQty == null) { result.ReserveQty = 0; } // 预留明细的业务类型 switch (result.SourceBillType) { case "销售出库": orderLineResult = orderLineBLL.GetInfo(new ORD_SalesOrderLineParam() { SOLineGuid = result.SourceBillLineGuid }); if (orderLineResult != null) { if (orderLineResult.Qty == null) { orderLineResult.Qty = 0; } if (orderLineResult.ReserveQty == null) { orderLineResult.ReserveQty = 0; } tempReserveQty = orderLineResult.Qty - orderLineResult.ReserveQty; } break; case "采购退货出库": returnLineResult = returnLineBLL.GetInfo(new ORD_PurchaseReturnLineParam() { PRLineGuid = result.SourceBillLineGuid }); if (returnLineResult != null) { if (returnLineResult.Qty == null) { returnLineResult.Qty = 0; } if (returnLineResult.ReserveQty == null) { returnLineResult.ReserveQty = 0; } tempReserveQty = returnLineResult.Qty - returnLineResult.ReserveQty; } break; } //获取已存在的预留信息 STK_StockReserveResult oldReserveResult = null; if (result.SRGuid != null) { STK_StockReserveParam reserveParam = new STK_StockReserveParam(); reserveParam.SRGuid = result.SRGuid; oldReserveResult = this.GetInfo(reserveParam); } if (oldReserveResult != null) { if (oldReserveResult.ReserveQty == null) { orderLineResult.ReserveQty = 0; } //修改预留数量,预留量增加 if (result.ReserveQty >= oldReserveResult.ReserveQty) { tempReserveQty = result.ReserveQty - oldReserveResult.ReserveQty; result.OperFlag = true; } //修改预留数量,预留量减少 else if (result.ReserveQty < oldReserveResult.ReserveQty) { tempReserveQty = oldReserveResult.ReserveQty - result.ReserveQty; result.OperFlag = false; } } //获取库存信息 STK_StockBLL stockBLL = new STK_StockBLL(); stockBLL.SessionInfo = this.SessionInfo; STK_StockResult stockResult = stockBLL.GetInfo(new STK_StockParam() { ItemCode = result.ItemCode }); if (stockResult != null) { //空值转换为零 if (stockResult.UsableQty == null) { stockResult.UsableQty = 0; } if (stockResult.BookedQty == null) { stockResult.BookedQty = 0; } } int?UsableQty = stockResult.UsableQty; //删除预留信息 if (result.IsDeleted.ToBooleanHasNull()) { result = oldReserveResult; stockResult.UsableQty += result.ReserveQty; stockResult.BookedQty -= result.ReserveQty; switch (result.SourceBillType) { case "销售出库": orderLineResult.ReserveQty -= result.ReserveQty; break; case "采购退货出库": returnLineResult.ReserveQty -= result.ReserveQty; break; } } //新增或者修改预留信息 else { switch (result.OperFlag) { case true: //增加 //预留信息已经存在 if (oldReserveResult != null) { result = oldReserveResult; if (UsableQty >= tempReserveQty) //大于需要预留数量 { result.ReserveQty += tempReserveQty; } else //小于需要预留数量 { result.ReserveQty += UsableQty; } } //新的预留 else { if (UsableQty >= tempReserveQty) //大于需要预留数量 { result.ReserveQty = tempReserveQty; } else //小于需要预留数量 { result.ReserveQty = UsableQty; } } if (UsableQty >= tempReserveQty) //大于需要预留数量 { stockResult.UsableQty -= tempReserveQty; stockResult.BookedQty += tempReserveQty; switch (result.SourceBillType) { case "销售出库": orderLineResult.ReserveQty += tempReserveQty; break; case "采购退货出库": returnLineResult.ReserveQty += tempReserveQty; break; } } else { stockResult.UsableQty -= UsableQty; stockResult.BookedQty += UsableQty; switch (result.SourceBillType) { case "销售出库": orderLineResult.ReserveQty += UsableQty; break; case "采购退货出库": returnLineResult.ReserveQty += UsableQty; break; } } break; case false: //减少库存量 result = oldReserveResult; result.ReserveQty -= tempReserveQty; stockResult.UsableQty += tempReserveQty; stockResult.BookedQty -= tempReserveQty; switch (result.SourceBillType) { case "销售出库": orderLineResult.ReserveQty -= tempReserveQty; break; case "采购退货出库": returnLineResult.ReserveQty -= tempReserveQty; break; } break; } // end of switch } //end of if else //更改预留表 this.AddOrUpdate(result); //更改库存 stockBLL.AddOrUpdate(stockResult); //更新预留关联单据明细 switch (result.SourceBillType) { case "销售出库": orderLineBLL.AddOrUpdate(orderLineResult); break; case "采购退货出库": returnLineBLL.AddOrUpdate(returnLineResult); break; } // end of if else } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(true); }
public bool AuditStkInBill(STK_InParam param) { bool auditFlag = true; try { STK_InResult inResult = this.GetInfo(param);; if (inResult != null) { bool isAllowAudit = true; if (inResult.ApproveStatus == "待提交") { isAllowAudit = false; throw new WarnException("入库单当前状态为:【待提交】,请先提交!"); } else if (inResult.ApproveStatus == "审核完成") { isAllowAudit = false; throw new WarnException("入库单当前状态为:【审核完成】,禁止重复审核!"); } if (isAllowAudit) { inResult.Status = "Complete"; inResult.ApproveStatus = "审核完成"; WCFAddUpdateResult ret = this.AddOrUpdate(inResult); if (ret.KeyGuid.ToGuid() == Guid.Empty) { auditFlag = false; } else { #region 定义相关变量(可重复使用) STK_InLineBLL stkInLineBLL = new STK_InLineBLL(); stkInLineBLL.SessionInfo = this.SessionInfo; STK_StockBLL stkStockBLL = new STK_StockBLL(); stkStockBLL.SessionInfo = this.SessionInfo; STK_StockSheetBLL stkStockSheetBLL = new STK_StockSheetBLL(); stkStockSheetBLL.SessionInfo = this.SessionInfo; STK_StockReserveBLL reserveBLL = new STK_StockReserveBLL(); reserveBLL.SessionInfo = this.SessionInfo; ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL(); saleOrderBLL.SessionInfo = this.SessionInfo; ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL(); saleOrderLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL(); purOrderBLL.SessionInfo = this.SessionInfo; ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL(); purOrderLineBLL.SessionInfo = this.SessionInfo; ORD_SalesReturnBLL returnBLL = new ORD_SalesReturnBLL(); returnBLL.SessionInfo = this.SessionInfo; ORD_SalesReturnLineBLL returnLineBLL = new ORD_SalesReturnLineBLL(); returnLineBLL.SessionInfo = this.SessionInfo; Guid?[] _ItemCodes = null; List <STK_InLineResult> stkInLineList = stkInLineBLL.GetList(new STK_InLineParam() { StkInGuid = inResult.StkInGuid }); #endregion #region 形成库存,回写库存ID到入库明细,形成库存流水,预留库存 ,回写采购单,销售单的入库数量和入库状态 List <STK_StockResult> stkStockList = new List <STK_StockResult>(); List <STK_StockSheetResult> stkStockSheetList = new List <STK_StockSheetResult>(); if (stkInLineList != null && stkInLineList.Count > 0) { if (inResult.BillType == "SOR_IN") { _ItemCodes = stkInLineList.Where(a => a.ItemCode != null).Select(a => a.ItemCode).Distinct().ToArray(); stkStockList = stkStockBLL.GetList(new STK_StockParam() { ItemCodes = _ItemCodes }); } #region 形成库存,回写库存ID,形成流水 STK_StockResult stkStockResult = null; STK_StockSheetResult stkStockSheetResult = null; foreach (STK_InLineResult stkInLineResult in stkInLineList) { //形成ItemCode,如果是采购入库则new一个实体,如果是销售退货入库则使用传递过来的退货明细的itemCode Guid?itemCode = null; #region 形成库存 if (inResult.BillType == "PO_IN")//采购入库 { itemCode = Guid.NewGuid(); stkStockResult = new STK_StockResult(); stkStockResult.BuyerID = stkInLineResult.BuyerID; stkStockResult.BuyerName = stkInLineResult.BuyerName; stkStockResult.POGuid = stkInLineResult.SourceBillGuid; stkStockResult.POBillNo = stkInLineResult.SourceBillNo; stkStockResult.POLineGuid = stkInLineResult.SourceBillLineGuid; stkStockResult.StkInGuid = inResult.StkInGuid; stkStockResult.StkInBillNo = inResult.BillNo; stkStockResult.StkInLineGuid = stkInLineResult.StkInLineGuid; stkStockResult.ItemCode = itemCode; stkStockResult.Model = stkInLineResult.Model; stkStockResult.Brand = stkInLineResult.Brand; stkStockResult.Batch = stkInLineResult.Batch; stkStockResult.Package = stkInLineResult.Package; stkStockResult.Quality = stkInLineResult.Quality; stkStockResult.MPQ = stkInLineResult.MPQ; stkStockResult.MarkCode = stkInLineResult.MarkCode; stkStockResult.Remark = stkInLineResult.Remark; stkStockResult.Warehouse = stkInLineResult.Warehouse; stkStockResult.Location = stkInLineResult.Location; stkStockResult.InvType = stkInLineResult.InvType; stkStockResult.InvQty = stkInLineResult.Qty; stkStockResult.BookedQty = 0; stkStockResult.UsableQty = stkInLineResult.Qty; stkStockResult.Unit = stkInLineResult.Unit; stkStockResult.Currency = stkInLineResult.Currency; stkStockResult.BuyPrice = stkInLineResult.CostPrice; stkStockResult.BuyPriceRMB = stkInLineResult.CostPrice * stkInLineResult.ExchangeRate; stkStockList.Add(stkStockResult); stkInLineResult.ItemCode = itemCode; //回写入库明细的库存ID } else if (inResult.BillType == "SOR_IN") //销售退货入库 { itemCode = stkInLineResult.ItemCode; stkStockResult = stkStockList.FirstOrDefault(a => a.ItemCode == stkInLineResult.ItemCode); stkStockResult.InvQty += stkInLineResult.Qty; stkStockResult.UsableQty += stkInLineResult.Qty; } else if (inResult.BillType == "ZX_IN") { } #endregion #region 形成流水 stkStockSheetResult = new STK_StockSheetResult(); stkStockSheetResult.OperEmpID = stkInLineResult.BuyerID; stkStockSheetResult.OperEmpName = stkInLineResult.BuyerName; stkStockSheetResult.SSType = 1; stkStockSheetResult.SourceBillGuid = inResult.StkInGuid; stkStockSheetResult.SourceBillNo = inResult.BillNo; stkStockSheetResult.SourceBillLineGuid = stkInLineResult.StkInLineGuid; stkStockSheetResult.ItemCode = itemCode; stkStockSheetResult.Model = stkInLineResult.Model; stkStockSheetResult.Brand = stkInLineResult.Brand; stkStockSheetResult.Batch = stkInLineResult.Batch; stkStockSheetResult.Package = stkInLineResult.Package; stkStockSheetResult.Quality = stkInLineResult.Quality; stkStockSheetResult.MPQ = stkInLineResult.MPQ; stkStockSheetResult.MarkCode = stkInLineResult.MarkCode; stkStockSheetResult.Currency = stkInLineResult.Currency; stkStockSheetResult.FlowQty = stkInLineResult.Qty; stkStockSheetResult.FlowPrice = stkInLineResult.CostPrice; stkStockSheetResult.FlowAmount = stkInLineResult.Amount; stkStockSheetList.Add(stkStockSheetResult); #endregion } stkStockBLL.UpdateOrInsertList(stkStockList); stkStockSheetBLL.UpdateOrInsertList(stkStockSheetList); stkInLineBLL.UpdateOrInsertList(stkInLineList); #endregion #region 预留库存 if (inResult.BillType == "PO_IN")//采购入库 { //有关联销售的采购入库会有销售明细Guid List <STK_InLineResult> tempInLineList = stkInLineList.Where(a => a.SOLineGuid != null).ToList(); if (tempInLineList != null && tempInLineList.Count > 0) { Guid?[] POLineGuids = tempInLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray(); List <ORD_PurchaseOrderLineResult> purOrderLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam() { POLineGuids = POLineGuids }); foreach (STK_InLineResult stkInLineResult in tempInLineList) { //入库明细所对应的采购明细 ORD_PurchaseOrderLineResult purOrderLineResult = purOrderLineList.FirstOrDefault(a => a.POLineGuid == stkInLineResult.SourceBillLineGuid); if (purOrderLineResult != null) { //创建预留明细 STK_StockReserveResult reserveResult = new STK_StockReserveResult(); reserveResult.SourceBillGuid = purOrderLineResult.SOGuid; //销售单guid reserveResult.SourceBillNo = purOrderLineResult.SOBillNo; //销售单编号 reserveResult.SourceBillLineGuid = purOrderLineResult.SOLineGuid; //销售明细guid reserveResult.SourceBillType = "销售出库"; reserveResult.ReserveType = 1; //采购预留 reserveResult.OperType = false; //系统预留 reserveResult.StkInLineGuid = stkInLineResult.StkInLineGuid; // 入库明细guid reserveResult.ItemCode = stkInLineResult.ItemCode; reserveResult.OperFlag = true; //增加 reserveBLL.OperateReserve(reserveResult); } } } } #endregion #region 回写关联单据的入库数量和入库状态 //入库单关联的入库明细 if (stkInLineList != null && stkInLineList.Count > 0) { #region 定义相关变量(可重复使用) Guid?[] SOGuids = null; Guid?[] SOLineGuids = null; Guid? POGuid = null; Guid?[] POLineGuids = null; Guid? SRGuid = null; Guid?[] SRLineGuids = null; Guid?[] StkInGuids = null; Guid?[] effInGuids = null; List <ORD_SalesReturnLineResult> returnLineList = null; List <ORD_PurchaseOrderLineResult> purLineList = null; List <STK_InResult> inList = null; List <STK_InLineResult> linkInLineList = null; List <STK_InLineResult> effInLineList = null; #endregion if (inResult.BillType == "PO_IN") { #region 更新采购明细的入库数量和采购主单的入库状态 //关联的采购主单 POGuid = inResult.SourceBillGuid; //关联的采购明细ID集合 POLineGuids = stkInLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray(); if (POLineGuids != null && POLineGuids.Length > 0) { //采购明细 purLineList = purOrderLineBLL.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, Status = "Complete" }); 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.StkInQty = qty; } } } purOrderLineBLL.UpdateOrInsertList(purLineList); purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam() { POGuid = POGuid }); } #endregion #region 更新销售明细的入库数量和销售主单的入库状态 List <STK_InLineResult> tempInLineList = stkInLineList.Where(a => a.SOLineGuid != null).ToList(); if (tempInLineList != null) { //获取关联的销售明细ID集合 SOLineGuids = tempInLineList.Select(a => a.SOLineGuid).Distinct().ToArray(); List <ORD_SalesOrderLineResult> saleOrderLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam() { SOLineGuids = SOLineGuids }); //获取关联的销售明细所关联的入库明细 linkInLineList = stkInLineBLL.GetList(new STK_InLineParam() { SOLineGuids = SOLineGuids }); StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray(); if (StkInGuids != null && StkInGuids.Length > 0) { //销售明细所关联的入库明细对应的入库主单 inList = this.GetList(new STK_InParam() { StkInGuids = StkInGuids, Status = "Complete" }); 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_SalesOrderLineResult saleLineResult in saleOrderLineList) { int?qty = effInLineList.Where(a => a.SOLineGuid == saleLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32()); saleLineResult.StkInQty = qty; } } } saleOrderLineBLL.UpdateOrInsertList(saleOrderLineList); SOGuids = saleOrderLineList.Select(a => a.SOGuid).Distinct().ToArray(); foreach (Guid soguid in SOGuids) { saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam() { SOGuid = soguid }); } } #endregion } else if (inResult.BillType == "SOR_IN") { #region 更新销售退货明细的入库数量和退货主单的入库状态 //关联的销售退货主单 SRGuid = inResult.SourceBillGuid; //关联的销售退货明细ID集合 SRLineGuids = stkInLineList.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, Status = "Complete" }); 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.StkInQty = qty; } } } returnLineBLL.UpdateOrInsertList(returnLineList); } #endregion } else if (inResult.BillType == "ZX_IN") { } } #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 SubmitPurchaseReturnBill(ORD_PurchaseReturnParam param) { this.CheckSession(); bool submitFlag = true; try { ORD_PurchaseReturnResult 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_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL(); purOrderBLL.SessionInfo = this.SessionInfo; ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL(); purOrderLineBLL.SessionInfo = this.SessionInfo; STK_InBLL inBLL = new STK_InBLL(); inBLL.SessionInfo = this.SessionInfo; STK_InLineBLL inLineBLL = new STK_InLineBLL(); inLineBLL.SessionInfo = this.SessionInfo; ORD_PurchaseReturnLineBLL returnLineBLL = new ORD_PurchaseReturnLineBLL(); returnLineBLL.SessionInfo = this.SessionInfo; STK_StockReserveBLL reserveBLL = new STK_StockReserveBLL(); reserveBLL.SessionInfo = this.SessionInfo; Guid?[] POLineGuids = null; Guid?[] StkInLineGuids = null; Guid?[] PRGuids = null; Guid?[] effPRGuids = null; Guid?[] POGuids = null; List <STK_InLineResult> linkInLineList = new List <STK_InLineResult>(); List <ORD_PurchaseOrderLineResult> linkPurchaseOrderLineList = new List <ORD_PurchaseOrderLineResult>(); List <ORD_PurchaseReturnResult> linkReturnList = new List <ORD_PurchaseReturnResult>(); List <ORD_PurchaseReturnLineResult> linkReturnLineList = new List <ORD_PurchaseReturnLineResult>(); List <ORD_PurchaseReturnLineResult> effReturnLineList = new List <ORD_PurchaseReturnLineResult>(); #endregion List <ORD_PurchaseReturnLineResult> purReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam() { PRGuid = returnResult.PRGuid }); #region 预留库存 foreach (ORD_PurchaseReturnLineResult returnLineResult in purReturnLineList) { //创建预留明细 STK_StockReserveResult reserveResult = new STK_StockReserveResult(); reserveResult.SourceBillGuid = returnResult.PRGuid; //采购退货单guid reserveResult.SourceBillNo = returnResult.BillNo; //退货单编号 reserveResult.SourceBillLineGuid = returnLineResult.PRLineGuid; //退货明细guid reserveResult.SourceBillType = "采购退货出库"; reserveResult.ReserveType = 4; //退货预留 reserveResult.OperType = false; //系统预留 reserveResult.StkInLineGuid = returnLineResult.StkInLineGuid; // 入库明细guid reserveResult.ItemCode = returnLineResult.ItemCode; reserveResult.OperFlag = true; //增加 reserveBLL.OperateReserve(reserveResult); } #endregion #region 更新入库明细的退货数量 //获取退货明细关联的入库明细ID集合 StkInLineGuids = purReturnLineList.Select(a => a.StkInLineGuid).Distinct().ToArray(); if (StkInLineGuids != null && StkInLineGuids.Length > 0) { //退货明细关联的入库明细 linkInLineList = inLineBLL.GetList(new STK_InLineParam() { StkInLineGuids = StkInLineGuids }); //关联的入库明细所关联的退货明细 linkReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam() { StkInLineGuids = StkInLineGuids }); PRGuids = linkReturnLineList.Select(a => a.PRGuid).Distinct().ToArray(); if (PRGuids != null && PRGuids.Length > 0) { //关联的入库明细所关联的退货明细对应的退货主单 linkReturnList = this.GetList(new ORD_PurchaseReturnParam() { PRGuids = PRGuids, StatusArr = new string[] { "Complete", "Approve" } }); if (linkReturnList != null && linkReturnList.Count > 0) { effPRGuids = linkReturnList.Select(a => (Guid?)a.PRGuid).Distinct().ToArray(); effReturnLineList = linkReturnLineList.Where(a => effPRGuids.Contains(a.PRGuid)).ToList(); foreach (STK_InLineResult inLineResult in linkInLineList) { int?qty = effReturnLineList.Where(a => a.StkInLineGuid == inLineResult.StkInLineGuid).Sum(a => a.Qty.ToInt32()); inLineResult.ReturnOccQty = qty; } } } //更新退货明细关联的入库明细的退货占有数量 inLineBLL.UpdateOrInsertList(linkInLineList); } #endregion #region 更新采购明细的采购占有数量和采购主单的退货占有状态 //获取关联采购明细ID集合 POLineGuids = purReturnLineList.Select(a => a.POLineGuid).Distinct().ToArray(); linkPurchaseOrderLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam() { POLineGuids = POLineGuids, IsCancel = false }); //获取关联的采购明细所关联的退货明细 linkReturnLineList = returnLineBLL.GetList(new ORD_PurchaseReturnLineParam() { POLineGuids = POLineGuids }); PRGuids = linkReturnLineList.Select(a => a.PRGuid).Distinct().ToArray(); if (PRGuids != null && PRGuids.Length > 0) { //采购明细所关联的退货明细对应的退货主单 linkReturnList = this.GetList(new ORD_PurchaseReturnParam() { PRGuids = PRGuids, StatusArr = new string[] { "Complete", "Approve" } }); if (linkReturnList != null && linkReturnList.Count > 0) { effPRGuids = linkReturnList.Select(a => (Guid?)a.PRGuid).Distinct().ToArray(); effReturnLineList = linkReturnLineList.Where(a => effPRGuids.Contains(a.PRGuid)).ToList(); foreach (ORD_PurchaseOrderLineResult purLineResult in linkPurchaseOrderLineList) { int?qty = effReturnLineList.Where(a => a.POLineGuid == purLineResult.POLineGuid).Sum(a => a.Qty.ToInt32()); purLineResult.ReturnOccQty = qty; } } } purOrderLineBLL.UpdateOrInsertList(linkPurchaseOrderLineList); POGuids = linkPurchaseOrderLineList.Select(a => a.SOGuid).Distinct().ToArray(); foreach (Guid poguid in POGuids) { purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam() { POGuid = poguid }); } #endregion } } #endregion } else { throw new WarnException("要提交的采购退货单在系统中不存在!"); } } catch (WarnException exp) { throw exp; } catch (Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(submitFlag); }