Пример #1
0
        /// <summary>
        ///  not use
        /// </summary>
        /// <param name="fkProduct"></param>
        static void InitialPosStock(int fkProduct)
        {
            SSLsEntities db = new SSLsEntities();
            //using (SSLsEntities db = new SSLsEntities())
            //{
            var products = db.PosStock.Where(w => w.Enable == true && w.FKProduct == fkProduct).ToList();

            if (products.Count() == 0)
            {
                List <PosStock> posStocks = new List <PosStock>();
                PosStock        pos;
                int             i = 1;
                foreach (var item in products)
                {
                    pos             = new PosStock();
                    pos.CreateBy    = "admin";
                    pos.CreateDate  = DateTime.Now;
                    pos.CurrentQty  = 0;
                    pos.Description = "Initial Stock ";
                    pos.Enable      = true;
                    pos.FKProduct   = item.Id;
                    pos.Name        = "-";
                    pos.OldQty      = 0;
                    pos.UpdateBy    = "admin";
                    pos.UpdateDate  = DateTime.Now;
                    pos.FKShelf     = 21;
                    posStocks.Add(pos);
                }
                db.BulkInsert(posStocks);
                db.SaveChanges();
            }
        }
Пример #2
0
        public static void DetectNewBarcode(int fkProduct)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                var posStock = db.PosStock.FirstOrDefault(w => w.FKProduct == fkProduct);
                List <PosStockDetails> dtlsNew = new List <PosStockDetails>();
                PosStockDetails        dtlNewBar;
                if (posStock != null)
                {
                    /// แปลว่ามีฐานสินค้าแล้ว ใน stock หน้าร้าน
                    var getPro = db.Products.SingleOrDefault(w => w.Id == fkProduct);
                    foreach (var item in getPro.ProductDetails.Where(w => w.Enable == true))
                    {
                        var posStockDetails = posStock.PosStockDetails.Where(w => w.Enable == true && w.FKProductDetails == item.Id).ToList();
                        if (posStockDetails.Count > 0)
                        {
                            // แปลว่า บาร์นี้ เคย add เข้าแล้ว
                            continue;
                        }
                        dtlNewBar                   = new PosStockDetails();
                        dtlNewBar.FKPosStock        = posStock.Id;
                        dtlNewBar.Description       = "initial stock new barcode";
                        dtlNewBar.CreateDate        = DateTime.Now;
                        dtlNewBar.CreateBy          = Singleton.SingletonAuthen.Instance().Id;
                        dtlNewBar.UpdateDate        = DateTime.Now;
                        dtlNewBar.UpdateBy          = Singleton.SingletonAuthen.Instance().Id;
                        dtlNewBar.Enable            = true;
                        dtlNewBar.FKTransactionType = MyConstant.PosTransaction.SetStock;
                        dtlNewBar.ActionQty         = 0;
                        dtlNewBar.ActionQtyUnit     = 0;
                        dtlNewBar.FKProductDetails  = item.Id;
                        dtlNewBar.OldQty            = 0;
                        dtlNewBar.ResultQty         = 0;
                        dtlNewBar.ResultQtyUnit     = 0;
                        dtlNewBar.PackSize          = item.PackSize;
                        dtlsNew.Add(dtlNewBar);
                    }
                    db.PosStockDetails.AddRange(dtlsNew);
                    db.SaveChanges();
                }
                else
                {
                    var getPro = db.Products.SingleOrDefault(w => w.Id == fkProduct);
                    // ยังไม่มี
                    PosStock pos = new PosStock();
                    List <PosStockDetails> dtls = new List <PosStockDetails>();
                    PosStockDetails        dtl;
                    var detailsPro = getPro.ProductDetails.Where(w => w.Enable == true).OrderBy(w => w.PackSize);
                    pos.Name        = detailsPro.FirstOrDefault().Code;
                    pos.Description = "initial stock new product";
                    pos.CreateDate  = DateTime.Now;
                    pos.CreateBy    = Singleton.SingletonAuthen.Instance().Id;
                    pos.UpdateDate  = DateTime.Now;
                    pos.UpdateBy    = Singleton.SingletonAuthen.Instance().Id;
                    pos.Enable      = true;
                    pos.CurrentQty  = 0;
                    pos.OldQty      = 0;
                    pos.FKProduct   = fkProduct;
                    pos.FKShelf     = MyConstant.Shelf.ShelfStart;

                    foreach (var item in detailsPro)
                    {
                        dtl                   = new PosStockDetails();
                        dtl.Description       = "initial stock new product";
                        dtl.CreateDate        = DateTime.Now;
                        dtl.CreateBy          = Singleton.SingletonAuthen.Instance().Id;
                        dtl.UpdateDate        = DateTime.Now;
                        dtl.UpdateBy          = Singleton.SingletonAuthen.Instance().Id;
                        dtl.Enable            = true;
                        dtl.FKTransactionType = MyConstant.PosTransaction.SetStock;
                        dtl.ActionQty         = 0;
                        dtl.ActionQtyUnit     = 0;
                        dtl.FKProductDetails  = item.Id;
                        dtl.OldQty            = 0;
                        dtl.ResultQty         = 0;
                        dtl.ResultQtyUnit     = 0;
                        dtl.PackSize          = item.PackSize;
                        dtls.Add(dtl);
                    }
                    pos.PosStockDetails = dtls;
                    db.PosStock.Add(pos);
                    db.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Main Process Store Front Transaction
        /// </summary>
        /// <param name="list">map มา และกรุ๊ปมา ให้เรียบร้อย</param>
        public static void POsTransactionProcess(List <ObjectPOsTransaction> list)
        {
            using (SSLsEntities db = new SSLsEntities())
            {
                decimal actionQty     = 0;
                decimal actionQtyUnit = 0;
                foreach (var item in list)
                {
                    PosStock        headerStock = db.PosStock.FirstOrDefault(w => w.Enable == true && w.FKProduct == item.ProductDetail.FKProduct);
                    TransactionType transaction = SingletonPOsTransaction.Instance().TransactionTypes.SingleOrDefault(w => w.Id == item.FKTransaction);
                    if (transaction.IsPlus)
                    {
                        // แสดงว่า ค่า +
                        actionQtyUnit = item.ActionQty;                               // จำนวนหน่วย
                        actionQty     = item.ActionQty * item.ProductDetail.PackSize; // จำนวน เล็กสุด ชิ้น
                    }
                    else
                    {
                        actionQtyUnit = -item.ActionQty;                               // จำนวนหน่วย
                        actionQty     = -item.ActionQty * item.ProductDetail.PackSize; // จำนวน เล็กสุด ชิ้น
                    }
                    // ถ้าไม่มีใน pos store front
                    if (headerStock == null)
                    {
                        // is add
                        headerStock             = new PosStock();
                        headerStock.Name        = item.ProductDetail.Name;
                        headerStock.Description = "Auto Add";
                        headerStock.CreateDate  = DateTime.Now;
                        headerStock.CreateBy    = SingletonAuthen.Instance().Id;
                        headerStock.UpdateDate  = DateTime.Now;
                        headerStock.UpdateBy    = SingletonAuthen.Instance().Id;
                        headerStock.Enable      = true;
                        headerStock.CurrentQty  = actionQty;
                        headerStock.FKProduct   = item.ProductDetail.FKProduct;

                        // details
                        PosStockDetails details = new PosStockDetails();
                        details.Description       = transaction.Name;
                        details.CreateDate        = DateTime.Now;
                        details.CreateBy          = SingletonAuthen.Instance().Id;
                        details.UpdateBy          = SingletonAuthen.Instance().Id;
                        details.UpdateDate        = DateTime.Now;
                        details.Enable            = true;
                        details.FKTransactionType = item.FKTransaction;
                        details.ActionQty         = actionQty;
                        details.ActionQtyUnit     = actionQtyUnit;
                        details.FKProductDetails  = item.ProductDetail.Id;

                        headerStock.PosStockDetails.Add(details);
                        db.PosStock.Add(headerStock);
                    }
                    else // ถ้ามีแล้วใน store front
                    {
                        // add transaction ก่อน
                        PosStockDetails details = new PosStockDetails();
                        details.Description       = transaction.Name;
                        details.CreateDate        = DateTime.Now;
                        details.CreateBy          = SingletonAuthen.Instance().Id;
                        details.UpdateBy          = SingletonAuthen.Instance().Id;
                        details.UpdateDate        = DateTime.Now;
                        details.Enable            = true;
                        details.FKTransactionType = item.FKTransaction;
                        details.ActionQty         = actionQty;
                        details.ActionQtyUnit     = actionQtyUnit;
                        details.FKProductDetails  = item.ProductDetail.Id;
                        details.FKPosStock        = headerStock.Id;
                        db.PosStockDetails.Add(details);
                        // is Update header
                        headerStock.UpdateDate      = DateTime.Now;
                        headerStock.UpdateBy        = SingletonAuthen.Instance().Id;
                        headerStock.CurrentQty      = headerStock.CurrentQty + actionQty;
                        db.Entry(headerStock).State = EntityState.Modified;
                    }
                }
                db.SaveChanges();
            }
        }