Ejemplo n.º 1
0
        public ActionResult ThemChiTietPhieuXuat(PhieuXuatViewModel pxViewModel, string TenSach)
        {
            if (ModelState.IsValid)
            {
                var sach = sachService.GetSingleByName(TenSach);
                if (sach == null)
                {
                    ModelState.AddModelError("", "Thông tin sách không tồn tại.");
                }
                else
                {
                    pxViewModel.ctPhieuXuat.IdSach = sach.Id;

                    var giaBan           = sach.GiaBan;
                    var newCtPhieuXuatVm = new CtPhieuXuatViewModel();
                    newCtPhieuXuatVm            = pxViewModel.ctPhieuXuat;
                    newCtPhieuXuatVm.DonGiaXuat = (double)giaBan;
                    newCtPhieuXuatVm.ThanhTien  = newCtPhieuXuatVm.SoLuongXuat * newCtPhieuXuatVm.DonGiaXuat;
                    newCtPhieuXuatVm.Sach       = Mapper.Map <Sach, SachViewModel>(sach);

                    var sachDaNhap = ((List <CtPhieuXuatViewModel>)Session["dsCtPhieuXuat"]).Find(x => x.IdSach == newCtPhieuXuatVm.IdSach);
                    if (sachDaNhap == null)
                    {
                        var tonKho     = tonKhoService.GetSingleByIdAndDate(sach.Id, pxViewModel.ThoiGianXuat);
                        var soLuongTon = tonKho != null ? tonKho.SoLuong : 0;

                        if (soLuongTon < newCtPhieuXuatVm.SoLuongXuat)
                        {
                            ModelState.AddModelError("", "Số lượng tồn là " + soLuongTon + " không đủ đáp ứng yêu cầu.");
                        }
                        else
                        {
                            if (!tonKhoService.CheckCreatePermission(sach.Id, newCtPhieuXuatVm.SoLuongXuat))
                            {
                                ModelState.AddModelError("", "Thời gian xuất không cho phép tạo phiếu xuất này.");
                            }
                            else
                            {
                                // Con phai kiem tra co cho them cac phieu truoc do
                                pxViewModel.ctPhieuXuat = null;
                                ((PhieuXuatViewModel)Session["PhieuXuat"]).TongTien    += newCtPhieuXuatVm.ThanhTien;
                                ((PhieuXuatViewModel)Session["PhieuXuat"]).TongSoLuong += newCtPhieuXuatVm.SoLuongXuat;
                                ((List <CtPhieuXuatViewModel>)Session["dsCtPhieuXuat"]).Add(newCtPhieuXuatVm);

                                TempData["Success"] = "Đã lưu thành công một chi tiết.";
                                return(Redirect("them-chi-tiet/"));
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Mã sách đã được thêm vào danh sách chi tiết rồi.");
                    }
                }
            }
            return(View(pxViewModel));
        }
Ejemplo n.º 2
0
        public ActionResult TonKho(DateTime NgayThongKe)
        {
            var listSach   = sachService.GetAll();
            var listSachVm = Mapper.Map <IEnumerable <Sach>, IEnumerable <SachViewModel> >(listSach);

            listSachVm.ToList().ForEach(x =>
            {
                var tonKho   = tonKhoService.GetSingleByIdAndDate(x.Id, NgayThongKe);
                var tonKhoVm = Mapper.Map <TonKho, TonKhoViewModel>(tonKho);
                if (tonKhoVm != null)
                {
                    x.TonKho = tonKhoVm;
                }
                else
                {
                    x.TonKho = new TonKhoViewModel();
                }
            });
            return(View(listSachVm));
        }