예제 #1
0
        public IHttpActionResult PostComplete(NvKiemKeVm.Dto instance)
        {
            string   unitCode   = _service.GetCurrentUnitCode();
            MdPeriod curentDate = CurrentSetting.GetKhoaSo(unitCode);
            int      period     = curentDate.Period;
            int      year       = curentDate.Year;
            string   tablleName = curentDate.GetTableName();

            instance.NgayDuyetPhieu = curentDate.ToDate;

            try
            {
                string msg = _serviceKK.Approval(instance, tablleName, year.ToString(), period);
                if (msg.Length > 0)
                {
                    return(BadRequest(msg));
                }

                _serviceKK.UpdateApproval(instance);
                _serviceKK.UnitOfWork.Save();
                return(Ok(msg));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> Put(string id, NvKiemKeVm.Dto instance)
        {
            //Lấy danh sách các mã không thuộc kệ để update lại mã kệ cho các mã đó
            List <NvKiemKeVm.DtoDetails> hangKhongThuocKe = new List <NvKiemKeVm.DtoDetails>();

            foreach (NvKiemKeVm.DtoDetails data in instance.DataDetails)
            {
                if (data.KeKiemKe == instance.KeKiemKe)
                {
                }
                else
                {
                    hangKhongThuocKe.Add(data);
                }
            }

            //Update mã kệ trong danh mục hàng hóa
            foreach (NvKiemKeVm.DtoDetails value in hangKhongThuocKe)
            {
                MdMerchandise maHangHoa = _service.Repository.DbSet.FirstOrDefault(x => x.MaVatTu == value.MaVatTu);
                if (maHangHoa != null)
                {
                    maHangHoa.MaKeHang = instance.KeKiemKe;
                    _service.Update(maHangHoa);
                }
            }
            await _service.UnitOfWork.SaveAsync();

            //end cập nhật mã kệ

            TransferObj <NvKiemKe> result = new TransferObj <NvKiemKe>();
            NvKiemKe check = _serviceKK.FindById(instance.Id);

            if (id != instance.Id || check.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(NotFound());
            }
            try
            {
                NvKiemKe item = _serviceKK.UpdatePhieu(instance);
                await _serviceKK.UnitOfWork.SaveAsync();

                result.Status = true;
                result.Data   = item;
                return(Ok(result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
예제 #3
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));
        }
예제 #4
0
        public async Task <IHttpActionResult> Post(NvKiemKeVm.Dto instance)
        {
            TransferObj <NvKiemKe> result = new TransferObj <NvKiemKe>();

            try
            {
                NvKiemKe item = _serviceKK.InsertPhieu(instance);
                await _serviceKK.UnitOfWork.SaveAsync();

                result.Data   = item;
                result.Status = true;
                return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.MaPhieuKiemKe }, result));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
예제 #5
0
        public async Task <IHttpActionResult> GetDetails(string id)
        {
            TransferObj <NvKiemKeVm.Dto> result = new TransferObj <NvKiemKeVm.Dto>();

            NvKiemKeVm.Dto temp  = new NvKiemKeVm.Dto();
            NvKiemKe       phieu = _serviceKK.FindById(id);

            if (phieu != null)
            {
                temp = Mapper.Map <NvKiemKe, NvKiemKeVm.Dto>(phieu);
                List <NvKiemKeChiTiet> chiTietPhieu = _service.UnitOfWork.Repository <NvKiemKeChiTiet>().DbSet.Where(x => x.MaPhieuKiemKe == phieu.MaPhieuKiemKe).ToList();
                temp.DataDetails = Mapper.Map <List <NvKiemKeChiTiet>, List <NvKiemKeVm.DtoDetails> >(chiTietPhieu);
                result.Data      = temp;
                result.Status    = true;
                return(Ok(result));
            }
            return(NotFound());
        }
예제 #6
0
        public async Task <IHttpActionResult> GetInfoMerchandiseByCode(string code)
        {
            string id      = code.Substring(0, 36);
            string maVatTu = code.Substring(37);
            var    result  = new TransferObj <NvKiemKeVm.Dto>();
            var    temp    = new NvKiemKeVm.Dto();
            var    phieu   = _serviceKK.FindById(id);

            if (phieu != null)
            {
                temp = Mapper.Map <NvKiemKe, NvKiemKeVm.Dto>(phieu);
                var chiTietPhieu = _service.UnitOfWork.Repository <NvKiemKeChiTiet>().DbSet.Where(x => x.MaPhieuKiemKe == phieu.MaPhieuKiemKe).Where(x => x.MaVatTu.Contains(maVatTu)).ToList();
                temp.DataDetails = Mapper.Map <List <NvKiemKeChiTiet>, List <NvKiemKeVm.DtoDetails> >(chiTietPhieu);
                result.Data      = temp;
                result.Status    = true;
                return(Ok(result));
            }
            return(NotFound());
        }
예제 #7
0
        public async Task <IHttpActionResult> PostComplete(NvKiemKeVm.Dto instance)
        {
            string   unitCode    = _service.GetCurrentUnitCode();
            MdPeriod curentDate  = CurrentSetting.GetKhoaSo(unitCode);
            int      period      = curentDate.Period;
            int      year        = curentDate.Year;
            string   tablleName  = curentDate.GetTableName();
            NvKiemKe phieuKiemKe = _serviceKK.FindById(instance.Id);

            instance.NgayDuyetPhieu = curentDate.ToDate;
            //thực hiện tạo phiếu kiểm kê nhập, kiểm kê xuất
            try
            {
                _serviceKK.Approval(instance, tablleName, year.ToString(), period);
                _serviceKK.UpdateApproval(instance);
                _serviceKK.UnitOfWork.Save();
                return(Ok(true));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
예제 #8
0
        public async Task <IHttpActionResult> GetDataKiemKe(string id)
        {
            string para         = id.Substring(0, 36);
            string typeKiemKe   = id.Substring(37);
            var    result       = new TransferObj <NvKiemKeVm.Dto>();
            var    temp         = new NvKiemKeVm.Dto();
            var    phieu        = _serviceKK.FindById(para);
            var    chiTietPhieu = new List <NvKiemKeChiTiet>();

            if (phieu != null)
            {
                temp = Mapper.Map <NvKiemKe, NvKiemKeVm.Dto>(phieu);
                //thua
                if (typeKiemKe == "1")
                {
                    chiTietPhieu       = _service.UnitOfWork.Repository <NvKiemKeChiTiet>().DbSet.Where(x => x.MaPhieuKiemKe == phieu.MaPhieuKiemKe).Where(x => x.SoLuongKiemKe == x.SoLuongTonMay).ToList();
                    temp.SoPhieuKiemKe = "1";
                }
                else if (typeKiemKe == "2")
                {
                    chiTietPhieu       = _service.UnitOfWork.Repository <NvKiemKeChiTiet>().DbSet.Where(x => x.MaPhieuKiemKe == phieu.MaPhieuKiemKe).Where(x => x.SoLuongKiemKe > x.SoLuongTonMay).ToList();
                    temp.SoPhieuKiemKe = "2";
                }
                else
                {
                    chiTietPhieu       = _service.UnitOfWork.Repository <NvKiemKeChiTiet>().DbSet.Where(x => x.MaPhieuKiemKe == phieu.MaPhieuKiemKe).Where(x => x.SoLuongKiemKe < x.SoLuongTonMay).ToList();
                    temp.SoPhieuKiemKe = "3";
                }
                //thieu
                temp.DataDetails = Mapper.Map <List <NvKiemKeChiTiet>, List <NvKiemKeVm.DtoDetails> >(chiTietPhieu);
                result.Data      = temp;
                result.Status    = true;
                return(Ok(result));
            }
            return(NotFound());
        }
예제 #9
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));
        }