/// <summary> /// 读取商品库存数量 /// </summary> /// <param name="StoreId"></param> /// <param name="GoodsId"></param> /// <param name="Model"></param> /// <returns></returns> public int GetGoodsStockNum(int StoreId, int GoodsId, string Model) { GoodsStore gs = new GoodsStore(); gs.Load(StoreId, GoodsId); return(gs.Num); }
/// <summary> /// 计算Ac /// </summary> /// <param name="branchId"></param> /// <param name="storeId"></param> /// <param name="goodsId"></param> /// <param name="pNum"></param> /// <param name="pInPrice"></param> /// <returns></returns> public double GetAc(int branchId, int storeId, int goodsId, int pNum, double pInPrice) { double Ac = 0; GoodsStore gs = new GoodsStore(); if (gs.GetGoodsStorePosition(branchId, storeId, goodsId)) { Ac = (gs.AC * gs.Num + pNum * pInPrice) / (gs.Num + pNum); } else { Ac = pInPrice; } return(Ac); }
/// <summary> /// 出库一种商品,返回其 最新的成本价 /// </summary> /// <param name="gsd1"></param> /// <returns></returns> public double OutBoundGoods(GoodsStoreDetail gsd1) { GoodsStore gs = new GoodsStore(); if (!gs.Load(gsd1.StoreId, gsd1.GoodsId))//商品不在库存中时需要添加此商品 { gs.GoodsId = gsd1.GoodsId; gs.StoreId = gsd1.StoreId; //gs.Model = gsd1.Model; gs.Num = 0; int Id = gs.Save(); gs.Id = Id; } gs.Num = gs.Num - gsd1.Num; gs.UpdateTime = DateTime.Now; if (gs.Save() <= 0) { return(-1); } GoodsStoreDetail gsd = new GoodsStoreDetail(); gsd.GoodsId = gsd1.GoodsId; gsd.Id = 0; gsd.NewNum = gs.Num; gsd.Num = gsd1.Num; gsd.OldNum = gs.Num + gsd1.Num; gsd.Operate = gsd1.Operate; gsd.RelationId = gsd1.RelationId; gsd.StoreId = gsd1.StoreId; gsd.UpdateTime = DateTime.Now; gsd.UserId = gsd1.UserId; gsd.AC = gs.AC; gsd.TaxAC = gs.TaxAC; if (gsd.Save() > 0) { return(gs.AC); } else { return(-1); } }
/// <summary> /// 调拨入库,撤销入库 /// </summary> /// <param name="TransferId"></param> /// <param name="storeId"></param> /// <param name="UserId"></param> /// <returns></returns> public bool InBoundT(int TransferId, int storeId, int UserId) { Transfer t = new Transfer(); t.Id = TransferId; t.Load(); bool storevalid = false; if (t.InStoreId == storeId) { t.InStoreDate = DateTime.Now; t.Status = CommenClass.TransferStatus.调拨入库.ToString(); t.InStoreUserId = UserId; t.Save(); storevalid = true; } else if (t.OutStoreId == storeId) { t.UpdateDate = DateTime.Now; t.Status = CommenClass.TransferStatus.待出库.ToString(); t.OutStoreDate = new DateTime(1900, 1, 1); t.Save(); storevalid = true; } else { return(false); } if (storevalid) { DataSet ds = ReadTransferDetail(TransferId); foreach (DataRow row in ds.Tables[0].Rows) { int goodsId = DBTool.GetIntFromRow(row, "GoodsId", 0); int num = DBTool.GetIntFromRow(row, "Num", 0); int Id = DBTool.GetIntFromRow(row, "Id", 0); double AC = DBTool.GetDoubleFromRow(row, "AC", 0); GoodsStore gs = new GoodsStore(); gs.GoodsId = goodsId; gs.StoreId = storeId; gs.Load(storeId, goodsId); //修改库存 成本和数量,如果是固定成本的 直接赋值 GoodsAC ga = new GoodsAC(); if (ga.Load(t.InBranchId, goodsId)) { gs.AC = ga.Goods_AC; } else { if ((gs.Num + num) != 0) { gs.AC = (gs.AC * gs.Num + num * AC) / (gs.Num + num); } else { gs.AC = AC; } } gs.Num = gs.Num + num; gs.UpdateTime = DateTime.Now; gs.Save(); GoodsStoreDetail gsd = new GoodsStoreDetail(); gsd.GoodsId = goodsId; gsd.Id = 0; gsd.NewNum = gs.Num; gsd.Num = num; gsd.OldNum = gs.Num - num; gsd.Operate = t.Status; gsd.RelationId = TransferId; gsd.StoreId = storeId; gsd.UpdateTime = DateTime.Now; gsd.UserId = UserId; gsd.Save(); } } return(true); }
public int GetGoodsStockNum(int Id) { GoodsStore gs = new GoodsStore(Id); return(gs.Num); }
///<summary> ///采购单明细入库库存数量操作 ///</summary> ///<returns></returns> private bool PurchaseDetailSave(DataSet pdset, int branchId, int userId) { bool result = false; int count = 0; for (int i = 0; i < pdset.Tables[0].Rows.Count; i++) { int storeId = Convert.ToInt32(pdset.Tables[0].Rows[i]["StoreId"]); int goodsId = Convert.ToInt32(pdset.Tables[0].Rows[i]["GoodsId"]); int num = Convert.ToInt32(pdset.Tables[0].Rows[i]["Num"]); string purchaseType = pdset.Tables[0].Rows[i]["PurchaseType"].ToString(); double inPrice = Convert.ToDouble(pdset.Tables[0].Rows[i]["InPrice"]); double taxInPrice = Convert.ToDouble(pdset.Tables[0].Rows[i]["TaxInPrice"]); int purchaseId = Convert.ToInt32(pdset.Tables[0].Rows[i]["PurchaseId"]); GoodsStore gs = new GoodsStore(); //读取商品库存位置,有库存说明之前采购过,此时入库需要加权平均;否则不需加权平均 if (gs.Load(storeId, goodsId)) { if (inPrice != 0 && num != 0) //inPrice=0:赠品;num=0:错误数据 { if (gs.Num + num != 0) //防止gs.Num为负值(错误数据) { gs.AC = (gs.AC * gs.Num + num * inPrice) / (gs.Num + num); gs.TaxAC = (gs.TaxAC * gs.Num + num * taxInPrice) / (gs.Num + num); } else { gs.AC = inPrice; gs.TaxAC = taxInPrice; } } gs.Num += num; gs.CargoNum += num; gs.UpdateTime = DateTime.Now; } else { gs.CargoNum = num; gs.GoodsId = goodsId; gs.StoreId = storeId; gs.Num = num; gs.UpdateTime = DateTime.Now; gs.AC = inPrice; gs.TaxAC = taxInPrice; } if (gs.Save() > 0) { //记录商品库存变化明细 GoodsStoreDetail gsd = new GoodsStoreDetail(); gsd.GoodsId = goodsId; gsd.OldNum = gs.Num - num; gsd.Num = num; gsd.NewNum = gs.Num; gsd.Operate = "PDA商品入库"; gsd.RelationId = purchaseId; gsd.StoreId = storeId; gsd.UpdateTime = DateTime.Now; gsd.UserId = userId; gsd.AC = gs.AC; gsd.TaxAC = gs.TaxAC; gsd.Save(); count++; } } if (count == pdset.Tables[0].Rows.Count) { result = true; } return(result); }