Example #1
0
        public override BarcodeHistory Handle(string barcode)
        {
            var caseCode = barcode.Substring(0, 15);
            var boxCode  = "";

            BarcodeHistory history = new BarcodeHistory()
            {
                Id            = Guid.NewGuid().ToString(),
                CreateTime    = DateTime.Now,
                UserLogin     = user,
                WareHouse     = wareActionInfo.wCode,
                WareHouseType = wareActionInfo.wType,
                WareHouseName = wareActionInfo.wName,
                PStatus       = "NK",
                Barcode       = barcode,
                CaseCode      = caseCode,
                IsSuccess     = 0
            };


            var product = GetProduct(barcode);

            if (product == null)
            {
                history.ProductCode = "";
                history.ProductName = "";
                history.Messenge    = "Mã sản phẩm sai";

                return(history);
            }

            history.ProductName = product.PName;
            history.ProductCode = product.Barcode;

            var wareInfo = db.Warehouses.Where(p => p.Code == wareActionInfo.wType).FirstOrDefault();

            PHistory checkHistory = null;

            decimal quantity = 1.0M;

            if (product.IsBox == 1 && wareInfo.IsScanBox == 1)
            {
                boxCode = barcode.Substring(0, 16);
                // check ma co phai la hop ko
                var lastChar = barcode.Substring(barcode.Length - 1, 1);
                if (lastChar != "1")
                {
                    history.Messenge = "Sản phẩm này chỉ quét hộp";
                    return(history);
                }

                checkHistory = db.PHistories.Where(p => p.BoxCode == boxCode && p.WCode == wareActionInfo.wCode && p.PStatus == "NK").FirstOrDefault();

                if (checkHistory != null)
                {
                    history.Messenge = "Sản phẩm đã xuất kho : " + checkHistory.CreateDate.ToString();
                    return(history);
                }

                quantity = 1.0M / (int)product.QuantityBox;
            }
            else
            {
                checkHistory = db.PHistories.Where(p => p.CaseCode == caseCode && p.WCode == wareActionInfo.wCode && p.PStatus == "NK").FirstOrDefault();

                if (checkHistory != null)
                {
                    history.Messenge = "Sản phẩm đã nhập kho: " + checkHistory.CreateDate.ToString();
                    return(history);
                }
            }

            // check kho truoc
            PHistory checkLastImport = null;

            if (product.IsBox == 1 && wareInfo.IsScanBox == 1)
            {
                checkLastImport = db.PHistories.Where(p => p.CaseCode == caseCode && p.BoxCode == boxCode).OrderByDescending(p => p.CreateDate).FirstOrDefault();

                if (checkLastImport == null)
                {
                    checkLastImport = db.PHistories.Where(p => p.CaseCode == caseCode).OrderByDescending(p => p.CreateDate).FirstOrDefault();
                }
            }
            else
            {
                checkLastImport = db.PHistories.Where(p => p.CaseCode == caseCode).OrderByDescending(p => p.CreateDate).FirstOrDefault();
            }

            if (checkLastImport != null)
            {
                // kiem tra do phai kho cha khong
                var wareLastImport = db.Warehouses.Where(p => p.Code == checkLastImport.WType).FirstOrDefault();

                if (!wareLastImport.WareReceive.Contains(wareActionInfo.wType))
                {
                    if (wareActionInfo.wType == "CII")
                    {
                        history.Messenge = "Mã đã đại lý cấp 2 khác sử dụng";
                    }
                    else
                    {
                        history.Messenge = "Mã đã được sử dụng";
                    }

                    return(history);
                }

                if (checkLastImport.PStatus == "NK")
                {
                    // tru kho
                    saveHistory(barcode, caseCode, boxCode, product, "XK", quantity, new WavehouseInfo()
                    {
                        wCode = checkLastImport.WCode,
                        wName = checkLastImport.WName,
                        wType = checkLastImport.WType
                    });

                    history.WareRelative     = checkLastImport.WCode;
                    history.WareRelativeName = checkLastImport.WName;
                    history.WareRelativeType = checkLastImport.WType;
                }
            }
            else
            {
                if (wareActionInfo.wType != "W")
                {
                    history.Messenge = "Phải nhập kho tổng";
                    return(history);
                }
            }

            saveHistory(barcode, caseCode, boxCode, product, "NK", quantity, wareActionInfo);
            history.Quantity = quantity;
            history.Messenge = "Đã nhập kho";
            if (wareActionInfo.wType == "CII")
            {
                // neu la cap 2
                // kiem tra xem co trong ds barcode k dc tham gia
                var checkPermiss = db.BarcodeNotPermisses.Where(p => p.CaseCode == caseCode).FirstOrDefault();
                if (checkPermiss != null)
                {
                    history.Messenge = "Đã nhập kho - mã không được tham gia chương trình khuyến mãi";
                }
            }
            history.IsSuccess = 1;
            return(history);
        }
Example #2
0
        public override BarcodeHistory Handle(string barcode)
        {
            var caseCode = barcode.Substring(0, 15);
            var boxCode  = "";

            BarcodeHistory history = new BarcodeHistory()
            {
                Id            = Guid.NewGuid().ToString(),
                CreateTime    = DateTime.Now,
                UserLogin     = user,
                WareHouse     = wareActionInfo.wCode,
                WareHouseType = wareActionInfo.wType,
                WareHouseName = wareActionInfo.wName,
                PStatus       = "XK",
                Barcode       = barcode,
                CaseCode      = caseCode,
                IsSuccess     = 0
            };


            var product = GetProduct(barcode);

            if (product == null)
            {
                history.ProductCode = "";
                history.ProductName = "";
                history.Messenge    = "Mã sản phẩm sai";

                return(history);
            }

            history.ProductName = product.PName;
            history.ProductCode = product.Barcode;

            var wareInfo = db.Warehouses.Where(p => p.Code == wareActionInfo.wType).FirstOrDefault();

            PHistory checkHistory = null;

            decimal quantity = 1.0M;
            var     remain   = getInventory(caseCode, wareActionInfo.wCode);

            if (product.IsBox == 1 && wareInfo.IsScanBox == 1)
            {
                boxCode = barcode.Substring(0, 16);
                // check ma co phai la hop ko
                var lastChar = barcode.Substring(barcode.Length - 1, 1);
                if (lastChar != "1")
                {
                    history.Messenge = "Sản phẩm này chỉ quét hộp";
                    return(history);
                }

                checkHistory = db.PHistories.Where(p => p.BoxCode == boxCode && p.WCode == wareActionInfo.wCode).OrderByDescending(p => p.CreateDate).FirstOrDefault();

                quantity = 1.0M / (int)product.QuantityBox;
            }
            else
            {
                checkHistory = db.PHistories.Where(p => p.CaseCode == caseCode && p.WCode == wareActionInfo.wCode).OrderByDescending(p => p.CreateDate).FirstOrDefault();
            }

            if (checkHistory != null)
            {
                if (checkHistory.PStatus == "XK")
                {
                    history.Messenge = "Sản phẩm đã xuất kho : " + checkHistory.CreateDate.ToString();
                    return(history);
                }
            }
            else
            {
                history.Messenge = "Sản phẩm phải nhập kho";
                return(history);
            }

            if (remain < quantity)
            {
                history.Messenge = "Không đủ hàng để xuất";
                return(history);
            }


            saveHistory(barcode, caseCode, boxCode, product, "XK", quantity, wareActionInfo);

            if (wareReceieInfo != null)
            {
                saveHistory(barcode, caseCode, boxCode, product, "NK", quantity, wareReceieInfo);
                history.WareRelative     = wareReceieInfo.wCode;
                history.WareRelativeName = wareReceieInfo.wName;
                history.WareRelativeType = wareReceieInfo.wType;
            }

            history.Quantity  = quantity;
            history.IsSuccess = 1;
            history.Messenge  = "Đã xuất kho";
            return(history);
        }