Exemplo n.º 1
0
 public static void UpdateCtPhieuXuat(this CtPhieuXuat ctPhieuXuat, CtPhieuXuatViewModel ctPhieuXuatVm)
 {
     ctPhieuXuat.Id          = ctPhieuXuatVm.Id;
     ctPhieuXuat.IdPhieuXuat = ctPhieuXuatVm.IdPhieuXuat;
     ctPhieuXuat.IdSach      = ctPhieuXuatVm.IdSach;
     ctPhieuXuat.SoLuongXuat = ctPhieuXuatVm.SoLuongXuat;
     ctPhieuXuat.ThanhTien   = ctPhieuXuatVm.ThanhTien;
     ctPhieuXuat.DonGiaXuat  = ctPhieuXuatVm.DonGiaXuat;
 }
Exemplo n.º 2
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));
        }