Beispiel #1
0
 public ProductScanAction(NDHDBEntities db, WavehouseInfo wareActionInfo, string user, WavehouseInfo wareReceieInfo)
 {
     this.db             = db;
     this.user           = user;
     this.wareActionInfo = wareActionInfo;
     this.wareReceieInfo = wareReceieInfo;
 }
Beispiel #2
0
        public ResultProduct UpdateProduct()
        {
            //stt: nhập kho: NK
            // Xuất kho : XK
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/product/updateproduct",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new ResultProduct()
            {
                id  = "1",
                msg = "success"
            };

            var requestContent = Request.Content.ReadAsStringAsync().Result;

            log.Content = requestContent;
            try
            {
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <RequestProduct>(requestContent);
                //  log.Content = new JavaScriptSerializer().Serialize(paser);

                if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                {
                    throw new Exception("Tài khoản của bạn đã bị đăng nhập trên một thiết bị khác!");
                }

                WavehouseInfo wareActionInfo = new WavehouseInfo();

                var staff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault();

                if (staff != null)
                {
                    wareActionInfo.wCode = staff.HaiBranch.Code;
                    wareActionInfo.wName = staff.HaiBranch.Name;

                    var userStaff = db.AspNetUsers.Where(p => p.UserName == paser.user).FirstOrDefault();

                    var role = userStaff.AspNetRoles.FirstOrDefault();

                    if (role.Name == "Warehouse")
                    {
                        wareActionInfo.wType = "W";
                    }
                    else
                    {
                        wareActionInfo.wType = "B";
                    }
                }
                else
                {
                    var agency = db.CInfoCommons.Where(p => p.UserLogin == paser.user).FirstOrDefault();

                    if (agency != null)
                    {
                        wareActionInfo.wCode = agency.CCode;
                        wareActionInfo.wName = agency.CName;
                        wareActionInfo.wType = agency.CType;
                    }
                }

                // check user receiver
                WavehouseInfo wareReceiInfo = null;
                // lay thong tin noi nhan
                if (!String.IsNullOrEmpty(paser.receiver.Trim()) && paser.status == "XK")
                {
                    wareReceiInfo = new WavehouseInfo();
                    var branchReceiver = db.HaiBranches.Where(p => p.Code == paser.receiver).FirstOrDefault();
                    if (branchReceiver != null)
                    {
                        wareReceiInfo.wType = "B";
                        wareReceiInfo.wCode = branchReceiver.Code;
                        wareReceiInfo.wName = branchReceiver.Name;
                    }
                    else
                    {
                        var agencyReceiver = db.CInfoCommons.Where(p => p.CCode == paser.receiver).FirstOrDefault();
                        if (agencyReceiver != null)
                        {
                            wareReceiInfo.wType = agencyReceiver.CType;
                            wareReceiInfo.wCode = agencyReceiver.CCode;
                            wareReceiInfo.wName = agencyReceiver.CName;
                        }
                    }

                    if (String.IsNullOrEmpty(wareReceiInfo.wCode) || wareActionInfo.wCode == wareReceiInfo.wCode)
                    {
                        throw new Exception("Sai thông tin nơi nhập hàng");
                    }
                }

                ProductScanAction wareAction = null;

                if (paser.status == "NK")
                {
                    wareAction = new ImportAction(db, wareActionInfo, paser.user, null);
                }
                else if (paser.status == "XK")
                {
                    wareAction = new ExportAction(db, wareActionInfo, paser.user, wareReceiInfo);
                }

                if (wareAction == null)
                {
                    throw new Exception("Sai thông tin quét");
                }

                string msg = wareAction.checkRole();
                if (msg != null)
                {
                    throw new Exception(msg);
                }

                // kiem tra nhap kho
                List <GeneralInfo> productsReturn = new List <GeneralInfo>();
                foreach (string barcode in paser.products)
                {
                    BarcodeHistory resultSave = wareAction.Handle(barcode);
                    db.BarcodeHistories.Add(resultSave);
                    db.SaveChanges();
                    productsReturn.Add(new GeneralInfo()
                    {
                        code    = resultSave.Barcode,
                        name    = resultSave.ProductName,
                        status  = resultSave.Messenge,
                        success = Convert.ToInt32(resultSave.IsSuccess)
                    });
                }

                result.products = productsReturn;
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);
            mongoHelper.createHistoryAPI(log);

            return(result);
        }
Beispiel #3
0
        public ResultProduct HelpAgencyImport()
        {
            //stt: nhập kho: NK
            // Xuất kho : XK
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/product/helpagencyimport",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new ResultProduct()
            {
                id  = "1",
                msg = "success"
            };

            var requestContent = Request.Content.ReadAsStringAsync().Result;

            log.Content = requestContent;
            try
            {
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <RequestProductHelp>(requestContent);
                log.Content = new JavaScriptSerializer().Serialize(paser);


                if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                {
                    throw new Exception("Tài khoản của bạn đã bị đăng nhập trên một thiết bị khác!");
                }

                WavehouseInfo wareActionInfo = new WavehouseInfo();
                var           staff          = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault();
                if (staff == null)
                {
                    throw new Exception("Chỉ nhân viên công ty mới sử dụng chức năng này");
                }

                var agency = db.CInfoCommons.Where(p => p.CCode == paser.agency).FirstOrDefault();

                if (agency != null)
                {
                    wareActionInfo.wCode = agency.CCode;
                    wareActionInfo.wName = agency.CName;
                    wareActionInfo.wType = agency.CType;
                }
                else
                {
                    throw new Exception("Sai mã khách hàng");
                }

                // kiem tra toa do

                ProductScanAction wareAction = new ImportAction(db, wareActionInfo, paser.user, null);

                string msg = wareAction.checkRole();
                if (msg != null)
                {
                    throw new Exception(msg);
                }

                // kiem tra nhap kho
                List <GeneralInfo> productsReturn = new List <GeneralInfo>();
                foreach (string barcode in paser.products)
                {
                    BarcodeHistory resultSave = wareAction.Handle(barcode);
                    resultSave.StaffHelp = staff.Code;
                    if (paser.nearAgency == 1)
                    {
                        resultSave.StaffHelpIssue = "locationin";
                    }
                    else
                    {
                        resultSave.StaffHelpIssue = "locationout";
                    }
                    resultSave.LocationStaff = paser.latitude + "|" + paser.longitude;
                    db.BarcodeHistories.Add(resultSave);
                    db.SaveChanges();

                    productsReturn.Add(new GeneralInfo()
                    {
                        code    = resultSave.Barcode,
                        name    = resultSave.ProductName,
                        status  = resultSave.Messenge,
                        success = Convert.ToInt32(resultSave.IsSuccess)
                    });
                }

                result.products = productsReturn;
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);
            mongoHelper.createHistoryAPI(log);

            return(result);
        }
Beispiel #4
0
        // save history
        protected void saveHistory(string barcode, string caseCode, string boxCode, ProductInfo product, string stt, decimal?quantity, WavehouseInfo wInfo)
        {
            var history = new PHistory()
            {
                Id          = Guid.NewGuid().ToString(),
                Barcode     = barcode,
                PStatus     = stt,
                BoxCode     = boxCode,
                UserSend    = user,
                WCode       = wInfo.wCode,
                WName       = wInfo.wName,
                WType       = wInfo.wType,
                ProductCode = product.Barcode,
                CreateDate  = DateTime.Now,
                CaseCode    = caseCode,
                Quantity    = quantity
            };

            db.PHistories.Add(history);
            db.SaveChanges();

            var tracking = db.PTrackings.Where(p => p.CaseCode == caseCode && p.WCode == wInfo.wCode).FirstOrDefault();


            if (tracking == null)
            {
                var pTracking = new PTracking()
                {
                    Id        = Guid.NewGuid().ToString(),
                    WCode     = wInfo.wCode,
                    WType     = wInfo.wType,
                    WName     = wInfo.wName,
                    CaseCode  = caseCode,
                    ProductId = product.Id,
                    Quantity  = quantity
                };

                if (stt == "NK")
                {
                    pTracking.ImportTime = DateTime.Now;
                }
                else
                {
                    pTracking.ExportTime = DateTime.Now;
                }
                db.PTrackings.Add(pTracking);
                db.SaveChanges();
            }
            else
            {
                if (stt == "NK")
                {
                    tracking.Quantity   = tracking.Quantity + quantity;
                    tracking.ImportTime = DateTime.Now;
                }
                else
                {
                    tracking.Quantity   = tracking.Quantity - quantity;
                    tracking.ExportTime = DateTime.Now;
                }

                db.Entry(tracking).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
Beispiel #5
0
 public ImportAction(NDHDBEntities db, WavehouseInfo wareAction, string user, WavehouseInfo waveReceie)
     : base(db, wareAction, user, waveReceie)
 {
 }