//Duyệt phiếu
        public ActionResult Accept(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không đúng");
                return(RedirectToAction("All"));
            }
            var model = HoaDonDaiLyManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            if (model.TrangThai == 1)
            {
                putErrorMessage("Hóa đơn đã duyệt");
                return(RedirectToAction("Details", new { id }));
            }
            if (model.accept())
            {
                putSuccessMessage("Duyệt hóa đơn thành công");
                return(RedirectToAction("Details", new { id }));
            }
            else
            {
                putErrorMessage("Duyệt không thành công, vui lòng kiểm tra lại công nợ");
                return(RedirectToAction("Edit", new { id }));
            }
        }
 // GET: PhieuNhap/Edit/5
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         putErrorMessage("Đường dẫn không chính xác");
         return(RedirectToAction("All"));
     }
     if (_currentHoaDon == null || _currentHoaDon != id)
     {
         _currentHoaDon = id;
         _hoadon        = HoaDonDaiLyManager.find((int)id);
         if (_hoadon == null)
         {
             putErrorMessage("Không tìm thấy");
             return(RedirectToAction("All"));
         }
         if (_hoadon.TrangThai == 1)
         {
             //Nếu đã duyệt thì không cho sửa, chuyển sang trang chi tiết
             _currentHoaDon = null;
             putErrorMessage("Hóa đơn đã duyệt");
             return(RedirectToAction("Details", new { id = id }));
         }
     }
     ViewBag.cultureInfo  = CultureInfo;
     ViewBag.currentDaiLy = _hoadon.DaiLy;
     ViewBag.DMSach       = new SelectList(_hoadon.DaiLy.getSachNo(),
                                           nameof(SachManager.Properties.MaSoSach),
                                           nameof(SachManager.Properties.TenSach), "");
     setAlertMessage();
     return(View(_hoadon));
 }
        // GET: PhieuNhap/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không chính xác");
                return(RedirectToAction("All"));
            }
            var model = HoaDonDaiLyManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            setAlertMessage();
            return(View(model));
        }
 public ActionResult DeleteBill(int id)
 {
     if (isUserSessionExisted())
     {
         var user = Session[Core.Constants.SESSION.USERNAME] as NguoiDung;
         if (user.DaiLy == null)
         {
             putErrorMessage("Chưa đăng ký thông tin đại lý");
             return(RedirectToAction("Agency"));
         }
         var model = HoaDonDaiLyManager.find(id);
         if (model == null)
         {
             putErrorMessage("Không tìm thấy đơn");
             return(RedirectToAction("PayHistory"));
         }
         if (user.DaiLy.getAllHoaDon().Contains(model))
         {
             if (HoaDonDaiLyManager.delete((int)id))
             {
                 putSuccessMessage("Xóa thành công");
                 return(RedirectToAction("PayHistory"));
             }
             else
             {
                 putErrorMessage("Xóa không thành công");
                 return(RedirectToAction("PayHistory"));
             }
         }
         else
         {
             putErrorMessage("Không tìm thấy đơn");
             return(RedirectToAction("PayHistory"));
         }
     }
     else
     {
         return(RedirectToAction("Index", "Home", null));
     }
 }
        // GET: PhieuNhap/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                putErrorMessage("Đường dẫn không đúng");
                return(RedirectToAction("All"));
            }
            var model = HoaDonDaiLyManager.find((int)id);

            if (model == null)
            {
                putErrorMessage("Không tìm thấy");
                return(RedirectToAction("All"));
            }
            if (model.TrangThai == 1)
            {
                putErrorMessage("Hóa đơn đã duyệt");
                return(RedirectToAction("Details", new { id = model.MaSoHoaDon }));
            }
            setAlertMessage();
            return(View(model));
        }
 public ActionResult BillDetail(int?id)
 {
     if (id == null)
     {
         putErrorMessage("Đường dẫn không đúng");
         return(RedirectToAction("PayHistory"));
     }
     if (isUserSessionExisted())
     {
         var user = Session[Core.Constants.SESSION.USERNAME] as NguoiDung;
         if (user.DaiLy == null)
         {
             putErrorMessage("Chưa đăng ký thông tin đại lý");
             return(RedirectToAction("Agency"));
         }
         var model = HoaDonDaiLyManager.find((int)id);
         if (model == null)
         {
             putErrorMessage("Không tìm thấy đơn");
             return(RedirectToAction("PayHistory"));
         }
         if (user.DaiLy.getAllHoaDon().Contains(model))
         {
             setAlertMessage();
             return(View(model));
         }
         else
         {
             putErrorMessage("Không tìm thấy đơn");
             return(RedirectToAction("PayHistory"));
         }
     }
     else
     {
         return(RedirectToAction("Index", "Home", null));
     }
 }