Esempio n. 1
0
        public async Task <IHttpActionResult> GetMerchandiseByCodeKK(string MaHang)
        {
            var    unitCode = _service.GetCurrentUnitCode();
            string MaKho    = unitCode + "-K2";

            NvKiemKeVm.Dto lst = new NvKiemKeVm.Dto();
            try
            {
                String[] strArray  = new String[] { MaHang };
                string   paraVatTu = String.Join(",", strArray);
                lst.DataDetails = ProcedureCollection.GetInventoryForActionInventoryByOne(unitCode, MaKho, paraVatTu);
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
            return(Ok(lst));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> ReceiveDataKiemKe(string MaKho)
        {
            string UNITCODE_GLOBAL = "";

            NvKiemKeVm.Dto returnList = new NvKiemKeVm.Dto();
            if (!string.IsNullOrEmpty(MaKho))
            {
                UNITCODE_GLOBAL = MaKho.Substring(0, MaKho.LastIndexOf('-'));
                NvKiemKeVm.Dto lst     = new NvKiemKeVm.Dto();
                List <string>  vatTu   = new List <string>();
                string         path    = HttpContext.Current.Server.MapPath("/Upload/KiemKe/");
                HttpRequest    request = HttpContext.Current.Request;
                if (request.Files.Count > 0)
                {
                    try
                    {
                        HttpPostedFile file = request.Files[0];
                        file.SaveAs(path + file.FileName);
                        //kiem tra ton tai file
                        if (File.Exists(path + file.FileName))
                        {
                            if (file.FileName.Contains(".txt"))
                            {
                                //doc du lieu tu file text
                                string[] lines = File.ReadAllLines(path + file.FileName);
                                foreach (string line in lines)
                                {
                                    string[] data        = line.Split(',');
                                    string   MaVatTu     = data[0].ToString();
                                    string   SoTonKiemKe = data[1].ToString();
                                    vatTu.Add(MaVatTu);
                                }
                                string[] arrayVatTu = vatTu.ToArray();
                                string   paraVatTu  = String.Join(",", arrayVatTu);
                                lst.DataDetails = ProcedureCollection.GetInventoryForActionInventoryByOne(UNITCODE_GLOBAL, MaKho, paraVatTu);
                                foreach (var value in lst.DataDetails)
                                {
                                    foreach (string line in lines)
                                    {
                                        string[] data = line.Split(',');
                                        if (data[0].ToString() == value.MaVatTu)
                                        {
                                            decimal SoLuongKiemKe = 0;
                                            decimal.TryParse(data[1].ToString(), out SoLuongKiemKe);
                                            value.SoLuongKiemKe = SoLuongKiemKe;
                                            returnList.DataDetails.Add(value);
                                        }
                                    }
                                }
                                returnList.KhoKiemKe  = MaKho;
                                returnList.NgayKiemKe = DateTime.Now.Date;
                                returnList.NgayIn     = DateTime.Now.Date;
                                int    number = 0;
                                string maKe   = "";
                                if (lst.DataDetails.Count > 10)
                                {
                                    for (int i = 0; i < 10; i++)
                                    {
                                        if (lst.DataDetails[i].KeKiemKe == lst.DataDetails[i + 1].KeKiemKe)
                                        {
                                            number++;
                                            maKe = lst.DataDetails[i].KeKiemKe;
                                        }
                                    }
                                }
                                if (number > 5)
                                {
                                    returnList.KeKiemKe = maKe;
                                }
                                else
                                {
                                    returnList.KeKiemKe = lst.DataDetails[0].KeKiemKe;
                                }
                                returnList.MaPhieuKiemKe = _serviceKK.BuildCode();
                            }
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLogs.LogError(ex);
                        return(InternalServerError());
                    }
                }
                //lấy những mã không kiểm kê nhưng nằm trong kệ
                string maKeHangHoa = returnList.KeKiemKe;
                var    hangTrongKe = ProcedureCollection.LayThongTinHangThuocKe(UNITCODE_GLOBAL, returnList.KhoKiemKe, maKeHangHoa);
                try
                {
                    if (hangTrongKe != null && hangTrongKe.Count > 0)
                    {
                        for (int i = 0; i < hangTrongKe.Count; i++)
                        {
                            var data = returnList.DataDetails.Find(x => x.MaVatTu == hangTrongKe[i].MaVatTu);
                            if (data == null)
                            {
                                hangTrongKe[i].SoLuongKiemKe = 0;
                                returnList.DataDetails.Add(hangTrongKe[i]);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteLogs.LogError(ex);
                }
            }
            else
            {
                return(NotFound());
            }
            return(Ok(returnList));
        }