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); }
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); }
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); }
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); }