public async Task Create(PhieuNhapViewModel O) { DateTime today = DateTime.Now; PhieuNhap order = new PhieuNhap { SoPhieuNhap = O.soPhieuNhap, NgayNhap = today, MaNhanVien = O.maNhanVien, MaNhaCungCap = O.maNhaCungCap, TongTien = O.tongTien, Ghichu = O.ghiChu, TrangThai = true, NgayChinhSua = today, }; int thang = today.Month; int nam = today.Year; foreach (var i in O.chiTietPhieuNhap) { order.ChiTietPhieuNhaps.Add(i); _hangHoaBus.CapNhapHangHoaVaoBaoCaoTonKhiTaoPhieuNhap(i.MaHangHoa, i.SoLuong, thang, nam); _hangHoaBus.CapNhatHangHoaKhiTaoPhieuNhap(i.MaHangHoa, i.SoLuong, i.GiaNhap); } await _phieuNhapRepo.InsertAsync(order); }
public static void UpdatePhieuNhap(this PhieuNhap pn, PhieuNhapViewModel pnVm) { pn.Id = pnVm.Id; pn.IdNXB = pnVm.IdNXB; pn.NguoiGiao = pnVm.NguoiGiao; pn.ThoiGianNhap = pnVm.ThoiGianNhap; pn.TongSoLuong = pnVm.TongSoLuong; pn.TongTien = pnVm.TongTien; pn.TrangThai = true; }
public ActionResult ThemChiTietPhieuNhap(PhieuNhapViewModel pnViewModel, 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 { var dsSachCuaNXB = sachService.GetAllByIdNXB(pnViewModel.IdNXB).ToList(); var tonTaiSachNXB = dsSachCuaNXB.Find(X => X.Id == sach.Id); if (tonTaiSachNXB == null) { ModelState.AddModelError("", "Thông tin sách không thuộc nhà xuất bản hiện tại."); } else { // Set Id was found into IdSach of ctPhieuNhap pnViewModel.ctPhieuNhap.IdSach = sach.Id; // Create a entity model and insert into db var newCtPhieuNhapVm = new CtPhieuNhapViewModel(); newCtPhieuNhapVm = pnViewModel.ctPhieuNhap; newCtPhieuNhapVm.ThanhTien = newCtPhieuNhapVm.SoLuongNhap * newCtPhieuNhapVm.DonGiaNhap; newCtPhieuNhapVm.Sach = Mapper.Map <Sach, SachViewModel>(sach); var sachDaNhap = ((List <CtPhieuNhapViewModel>)Session["dsCtPhieuNhap"]).Find(x => x.IdSach == newCtPhieuNhapVm.IdSach); if (sachDaNhap == null) { pnViewModel.ctPhieuNhap = null; ((PhieuNhapViewModel)Session["PhieuNhap"]).TongTien += newCtPhieuNhapVm.ThanhTien; ((PhieuNhapViewModel)Session["PhieuNhap"]).TongSoLuong += newCtPhieuNhapVm.SoLuongNhap; ((List <CtPhieuNhapViewModel>)Session["dsCtPhieuNhap"]).Add(newCtPhieuNhapVm); 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(pnViewModel)); }
public async Task <JsonResult> LuuPhieuNhap(PhieuNhapViewModel phieuNhap) { bool status = false; if (ModelState.IsValid) { await _phieuNhapKhoBus.Create(phieuNhap); status = true; SetAlert("Đã Lưu Phiếu Nhập Kho Thành Công!!!", "success"); } else { status = false; SetAlert("Đã Xảy Ra Lỗi! Bạn Hãy Tạo Lại Phiếu Nhập Kho", "error"); } return(new JsonResult { Data = new { status = status } }); }
public ActionResult ThemPhieuNhap(PhieuNhapViewModel pnViewModel, string TenNXB) { if (ModelState.IsValid) { var nxb = nhaXuatBanService.GetSingleByName(TenNXB); if (nxb == null) { ModelState.AddModelError("", "Thông tin nhà xuất bản không tồn tại."); } else { pnViewModel.IdNXB = nxb.Id; pnViewModel.NhaXuatBan = Mapper.Map <NhaXuatBan, NhaXuatBanViewModel>(nxb); pnViewModel.TongTien = 0; pnViewModel.TongSoLuong = 0; Session["PhieuNhap"] = pnViewModel; // Open current session to save the Import data info Session["dsCtPhieuNhap"] = new List <CtPhieuNhapViewModel>(); return(Redirect("them-chi-tiet/")); } } return(View(pnViewModel)); }