public ActionResult SaveStocking() { bool StockingType = Convert.ToBoolean(Request.Form["StockingType"]); //true为盘盈 false为盘亏 int DeliveryCounts = Convert.ToInt32(Request.Form["DeliveryCounts"]); int StorageCode = -2; //盘库入库为盘点库-2 string StockingTypeInfo = ""; if (StockingType) { StockingTypeInfo = "MatertalOutType-4"; //盘盈出库单 DeliveryCounts = -DeliveryCounts; } else { StockingTypeInfo = "MatertalOutType-5"; //盘亏出库单 } List <I_DeliveryDetail> relist = new List <I_DeliveryDetail>(); I_DeliveryDetail info = new I_DeliveryDetail(); info.RealBatchNo = Request.Form["RealBatchNo"].ToString(); info.BatchNo = Request.Form["BatchNo"].ToString(); info.MaterialID = Convert.ToInt32(Request.Form["MaterialID"]); info.DeliveryCounts = DeliveryCounts; info.EntryStorageCode = int.Parse(Request.Form["StorageCode"]); //来源仓库编码 info.Remark = Request.Form["Remark"].ToString(); info.TargetStorageCode = StorageCode; relist.Add(info); I_Delivery delivery = new I_Delivery(); delivery.DeliveryCode = DateTime.Now.AddSeconds(1).ToString("yyyyMMddHHmmss") + UserOperateContext.Current.Session_UsrInfo.ID; //生成入库编码 delivery.ConsigneeID = UserOperateContext.Current.Session_UsrInfo.ID.ToString(); delivery.DeliveryTime = DateTime.Now; delivery.Remark = info.Remark; delivery.OperatorCode = UserOperateContext.Current.Session_UsrInfo.ID; delivery.OperationTime = DateTime.Now; delivery.ReceivingStoreID = StorageCode; delivery.DeliveryType = StockingTypeInfo; string errorMsg = ""; if (new I_DeliveryBLL().DeliveryOerate(delivery, relist, ref errorMsg)) { return(this.JsonResult(Utility.E_JsonResult.OK, "盘点物资仓库成功!", null, null)); } else { return(this.JsonResult(Utility.E_JsonResult.Error, errorMsg, null, null)); } }
/// <summary> /// 记录报废物资 /// </summary> /// <returns></returns> public ActionResult SaveScrapOverdueMaterial() { int StorageCode = -3; //报废入库为报废库-3 List <I_DeliveryDetail> relist = new List <I_DeliveryDetail>(); I_DeliveryDetail info = new I_DeliveryDetail(); info.RealBatchNo = Request.Form["RealBatchNo"].ToString(); info.BatchNo = Request.Form["BatchNo"].ToString(); info.MaterialID = Convert.ToInt32(Request.Form["MaterialID"]); info.DeliveryCounts = Convert.ToInt32(Request.Form["DeliveryCounts"]); info.EntryStorageCode = int.Parse(Request.Form["StorageCode"]); //来源仓库编码 info.Remark = Request.Form["Remark"].ToString(); info.TargetStorageCode = StorageCode; relist.Add(info); I_Delivery delivery = new I_Delivery(); delivery.DeliveryCode = DateTime.Now.AddSeconds(1).ToString("yyyyMMddHHmmss") + UserOperateContext.Current.Session_UsrInfo.ID; //生成入库编码 delivery.ConsigneeID = UserOperateContext.Current.Session_UsrInfo.ID.ToString(); delivery.DeliveryTime = DateTime.Now; delivery.Remark = info.Remark; delivery.OperatorCode = UserOperateContext.Current.Session_UsrInfo.ID; delivery.OperationTime = DateTime.Now; delivery.ReceivingStoreID = StorageCode; delivery.DeliveryType = "MatertalOutType-6"; string errorMsg = ""; if (new I_DeliveryBLL().DeliveryOerate(delivery, relist, ref errorMsg)) { return(this.JsonResult(Utility.E_JsonResult.OK, "报废物资成功!", null, null)); } else { return(this.JsonResult(Utility.E_JsonResult.Error, errorMsg, null, null)); } }
/// <summary> /// 保存出库结余信息 /// TODO:1.先查询出库结余 2.如果有则更新结余 3.如没有则提示错误 4.插入出库入库流水 /// </summary> /// <param name="info"></param> /// <param name="strEntryType"></param> public void SaveDeliverySurplusInfo(I_DeliveryDetail info, string strDeliveryType, ref string errorMsg) { decimal price = 0; try { //查结余 I_Surplus surplusinfo = base.GetModelWithOutTrace(s => s.BatchNo == info.BatchNo && s.MaterialID == info.MaterialID && s.StorageCode == info.EntryStorageCode && s.RealBatchNo == info.RealBatchNo); if (surplusinfo != null) //有结余数据 { double surplus = surplusinfo.Surplus - info.DeliveryCounts; if (surplusinfo.Surplus > 0) //剩余必须大于 0 才能计算出平均单价 { price = surplusinfo.SurplusPrice / Convert.ToDecimal(surplusinfo.Surplus); } if (surplus >= 0) { surplusinfo.Surplus = surplusinfo.Surplus - info.DeliveryCounts; } else { errorMsg = "该批次号库存不足,出库失败!"; throw new Exception(errorMsg); } surplusinfo.SurplusPrice = surplusinfo.SurplusPrice - price * Convert.ToDecimal(info.DeliveryCounts); base.Modify(surplusinfo, "Surplus", "SurplusPrice"); //更新结余信息 } else { errorMsg = "未找到该批次号商品信息,出库失败!"; throw new Exception(errorMsg); } #region 2.记录出库信息 I_InventoryRecord record = new I_InventoryRecord(); record.BatchNo = info.BatchNo; //批次号 record.RealBatchNo = info.RealBatchNo; //真实批次号 record.DeliveryEntryType = strDeliveryType; //出入库类型 record.DeliveryDetailCode = info.DeliveryDetailCode; //出库详细编码 record.Is_Entry = false; //入库标识 record.MaterialID = info.MaterialID; //物资编码 record.OperatorDateTime = info.DeliveryTime; //出库日期 record.StorageCode = info.EntryStorageCode; //仓储编码 record.OriginalSurplus = surplusinfo.Surplus + info.DeliveryCounts; // 原结余数量= 当前库存结余数量+ 出库数量 record.ChangeSurplus = -info.DeliveryCounts; //改变数量=出库数量 record.Surplus = surplusinfo.Surplus; //当前库存结余数量 record.SurplusPrice = surplusinfo.SurplusPrice; //当前库存结余价格 record.OperatorCode = info.OperatorCode; //操作人员编码 //插入出入库流水 dalContext.II_InventoryRecordDAL.Add(record); #endregion #region 3.自动生成转库入库单 I_Entry entry = new I_Entry(); // 入库主表 entry.EntryCode = info.DeliveryCode; //出库编码 entry.EntryDate = info.DeliveryTime; // 出库时间 entry.EntryStorageID = info.TargetStorageCode; //入库仓库编码=出库目的编码 if (info.RedDeliveryDetailCode != null) { entry.EntryType = "MatertalInType-3"; //红充入库单 } else { entry.EntryType = "MatertalInType-2"; //转库入库单 } entry.OperationTime = DateTime.Now; // 操作时刻 entry.OperatorCode = info.OperatorCode; entry.Remark = ""; I_EntryDetail entryDetail = new I_EntryDetail(); //入库从表 entryDetail.BatchNo = info.BatchNo; entryDetail.RealBatchNo = info.RealBatchNo; //真实批次号 entryDetail.EntryCode = info.DeliveryCode; //入库编码=出库编码 entryDetail.EntryCounts = info.DeliveryCounts; //入库数量 = 出库数量 entryDetail.EntryDate = info.DeliveryTime; // 入库时间 = 出库时间 entryDetail.EntryDetailCode = info.DeliveryDetailCode; //出库子编码 entryDetail.MaterialID = info.MaterialID; entryDetail.OperatorCode = info.OperatorCode; entryDetail.StorageCode = info.TargetStorageCode; entryDetail.TotalPrice = price; //当前库存结余价格; entryDetail.ValidityDate = surplusinfo.ValidityDate; //有效期 //如果被红充的出库信息不为空 if (info.RedDeliveryDetailCode != null) { entryDetail.RedEntryDetailCode = info.RedDeliveryDetailCode; //被红充入库编码 = 被红充出库编码 } List <I_EntryDetail> list = new List <I_EntryDetail>(); list.Add(entryDetail); //入库操作 new I_EntryDAL().DoEntry(entry, list, ref errorMsg); //调用入库流程 #endregion } catch (Exception e) { errorMsg = "结余操作失败!原因: " + e.Message; throw new Exception(errorMsg); } }