コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        /// <summary>
        /// 调拨出库
        /// </summary>
        /// <param name="TransferId"></param>
        /// <param name="storeId"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public bool OutBoundT(int TransferId, int storeId, int UserId)
        {
            if (!IsTransferCanOutBound(TransferId, storeId))
            {
                return(false);
            }
            //  修改订单状态

            string sql = string.Format(" update Transfer set Status='调拨出库',OutStoreDate='{0}' where Id={1} ", DateTime.Now.ToString(), TransferId);

            if (m_dbo.ExecuteNonQuery(sql))
            {
                GoodsStoreManager gsm = new GoodsStoreManager();
                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);
                    GoodsStoreDetail gsd = new GoodsStoreDetail();
                    gsd.GoodsId    = goodsId;
                    gsd.Num        = num;
                    gsd.Operate    = CommenClass.TransferStatus.调拨出库.ToString();
                    gsd.RelationId = TransferId;
                    gsd.StoreId    = storeId;
                    gsd.UserId     = UserId;
                    double AC = gsm.OutBoundGoods(gsd);
                    if (AC > 0)
                    {
                        Transferdetail tfd = new Transferdetail();
                        tfd.Id = Id;
                        tfd.Load();
                        tfd.AC = AC;
                        tfd.Save();
                    }
                }
            }
            return(true);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        ///<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);
        }