Пример #1
0
        public static void SaveSale(Sale sale)
        {
            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                retailDbContext.Sales.Add(sale);
                retailDbContext.SaveChanges(); //This will give us a unique SaleID

                //QtyOnHand change
                foreach (Saleline sl in sale.Salelines)
                {
                    StoreProduct storeProduct = retailDbContext.StoreProducts.ToList().SingleOrDefault <StoreProduct>(x => (x.ProductID == sl.ProductID) && (x.StoreID == sale.StoreID));
                    if (storeProduct == null)
                    {
                        storeProduct            = new StoreProduct();
                        storeProduct.ProductID  = sl.ProductID;
                        storeProduct.StoreID    = sale.StoreID;
                        storeProduct.QtyOnHand -= sl.Quantity;
                        retailDbContext.StoreProducts.Add(storeProduct);
                    }
                    else
                    {
                        storeProduct.QtyOnHand -= sl.Quantity;
                    }

                    StoreProductTran storeProductTran = new StoreProductTran();
                    storeProductTran.ProductID     = storeProduct.ProductID;
                    storeProductTran.DocumentType  = "S";
                    storeProductTran.DocumentID    = sale.SaleID;
                    storeProductTran.Quantity      = sl.Quantity;
                    storeProductTran.EffectiveTime = sale.TransactionTime;
                    retailDbContext.StoreProductTrans.Add(storeProductTran);
                }
                retailDbContext.SaveChanges();
            }
        }
Пример #2
0
        public static void SaveGrn(Grn grn)
        {
            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                retailDbContext.Grns.Add(grn);
                retailDbContext.SaveChanges(); //This will give us a unique GrnID

                //QtyOnHand change
                foreach (Grnline gl in grn.Grnlines)
                {
                    StoreProduct storeProduct = retailDbContext.StoreProducts.ToList().SingleOrDefault <StoreProduct>(x => (x.ProductID == gl.ProductID) && (x.StoreID == grn.StoreID));
                    if (storeProduct == null)
                    {
                        storeProduct            = new StoreProduct();
                        storeProduct.ProductID  = gl.ProductID;
                        storeProduct.StoreID    = grn.StoreID;
                        storeProduct.QtyOnHand += gl.Quantity;
                        retailDbContext.StoreProducts.Add(storeProduct);
                    }
                    else
                    {
                        storeProduct.QtyOnHand += gl.Quantity;
                    }

                    StoreProductTran storeProductTran = new StoreProductTran();
                    storeProductTran.ProductID     = storeProduct.ProductID;
                    storeProductTran.DocumentType  = "G";
                    storeProductTran.DocumentID    = grn.GrnID;
                    storeProductTran.Quantity      = gl.Quantity;
                    storeProductTran.EffectiveTime = grn.TransactionTime;
                    retailDbContext.StoreProductTrans.Add(storeProductTran);
                }
                retailDbContext.SaveChanges();
            }
        }
Пример #3
0
        public static void SaveStocktake(Stocktake st)
        {
            using (RetailDbContext retailDbContext = new RetailDbContext())
            {
                retailDbContext.Stocktakes.Add(st);
                retailDbContext.SaveChanges(); //This will give us a unique StocktakeID

                //QtyOnHand change
                foreach (Stocktakeline stl in st.Stocktakelines)
                {
                    int          QtyBefore    = 0;
                    StoreProduct storeProduct = retailDbContext.StoreProducts.ToList().SingleOrDefault <StoreProduct>(x => (x.ProductID == stl.ProductID) && (x.StoreID == st.StoreID));
                    if (storeProduct == null)
                    {
                        storeProduct           = new StoreProduct();
                        storeProduct.ProductID = stl.ProductID;
                        storeProduct.StoreID   = st.StoreID;
                        storeProduct.QtyOnHand = stl.CountedQty;
                        retailDbContext.StoreProducts.Add(storeProduct);
                    }
                    else
                    {
                        QtyBefore = storeProduct.QtyOnHand;
                        storeProduct.QtyOnHand = stl.CountedQty;
                    }

                    //QtyOnHand change history
                    StoreProductTran storeProductTran = new StoreProductTran();
                    storeProductTran.ProductID     = storeProduct.ProductID;
                    storeProductTran.DocumentType  = "A";
                    storeProductTran.DocumentID    = st.StocktakeID;
                    storeProductTran.Quantity      = stl.CountedQty - QtyBefore;
                    storeProductTran.EffectiveTime = st.TransactionTime;
                    retailDbContext.StoreProductTrans.Add(storeProductTran);
                }
                retailDbContext.SaveChanges();
            }
        }
Пример #4
0
 public StoreProductTranVM()
 {
     // Initialise the entity or inserts will fail
     TheEntity = new StoreProductTran();
 }