public ActionResult ThemPhieuXuat(PhieuXuatViewModel pxViewModel, string TenDaiLy) { if (ModelState.IsValid) { var daiLy = daiLyService.GetSingleByName(TenDaiLy); if (daiLy == null) { ModelState.AddModelError("", "Thông tin đại lý không tồn tại."); } else { pxViewModel.IdDaiLy = daiLy.Id; var soTienNo = congNoDLService.GetSingleByIdAndDate(daiLy.Id, pxViewModel.ThoiGianXuat).TongTienConNo; if (soTienNo > CommonConstant.NO_CHO_PHEP) { ModelState.AddModelError("", "Đã vượt quá số tiền cho phép nợ, không thể lập phiếu nữa."); } else { pxViewModel.DaiLy = Mapper.Map <DaiLy, DaiLyViewModel>(daiLy); pxViewModel.TongTien = 0; pxViewModel.TongSoLuong = 0; Session["PhieuXuat"] = pxViewModel; // Open current session to save the Export data info Session["dsCtPhieuXuat"] = new List <CtPhieuXuatViewModel>(); return(Redirect("them-chi-tiet/")); } } } return(View(pxViewModel)); }
public ActionResult TaoBaoCao(BaoCaoDLViewModel baoCaoDLVm, string TenDaiLy) { if (ModelState.IsValid) { var daiLy = daiLyService.GetSingleByName(TenDaiLy); if (daiLy == null) { ModelState.AddModelError("", "Thông tin đại lý không tồn tại."); } else { baoCaoDLVm.IdDaiLy = daiLy.Id; var ngayBatDau = baoCaoDLService.GetStartDateToCreateReport(daiLy.Id); if (ngayBatDau != null) { if (ngayBatDau <= baoCaoDLVm.NgayKetThuc) { baoCaoDLVm.NgayBatDau = ngayBatDau.Value; } else { ModelState.AddModelError("", "Thời gian báo cáo không hợp lệ."); return(View(baoCaoDLVm)); } } else { var ngayBatDauTaoPhieuXuat = phieuXuatService.GetFirstDateToCreateReport(daiLy.Id).Value; if (ngayBatDauTaoPhieuXuat != null) { if (ngayBatDauTaoPhieuXuat <= baoCaoDLVm.NgayKetThuc) { baoCaoDLVm.NgayBatDau = ngayBatDauTaoPhieuXuat; } else { ModelState.AddModelError("", "Thời gian báo cáo không hợp lệ."); return(View(baoCaoDLVm)); } } else { ModelState.AddModelError("", "Chưa xuất sách cho đại lý này, không thể lập báo cáo."); return(View(baoCaoDLVm)); } } var dsSachDaMua = baoCaoDLService.GetListAnalysisReport(baoCaoDLVm.IdDaiLy, baoCaoDLVm.NgayBatDau, baoCaoDLVm.NgayKetThuc); if (baoCaoDLService.CheckReportIsCreated(baoCaoDLVm.IdDaiLy, baoCaoDLVm.NgayKetThuc)) { ModelState.AddModelError("", "Khoảng thời gian đã được lập báo cáo rồi."); } else if (dsSachDaMua == null || dsSachDaMua.Count == 0) { ModelState.AddModelError("", "Đại lý chưa có nhập sách vào khoảng thời gian này."); } else { baoCaoDLVm.DaiLy = Mapper.Map <DaiLy, DaiLyViewModel>(daiLy); Session["BaoCao"] = baoCaoDLVm; Session["dsCtBaoCao"] = new List <CtBaoCaoDLViewModel>(); return(Redirect("them-chi-tiet/")); } } } return(View(baoCaoDLVm)); }