// 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)); }
protected override void OnActionExecuted(ActionExecutedContext filterContext) { var sess = (NguoiDung)Session[Core.Constants.SESSION.USERNAME]; if (sess == null) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary(new { controller = "Account", action = "Login", area = "" })); } else if (!sess.PhanQuyen.Contains("admin")) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary(new { controller = "Account", action = "Login" })); } else { ViewBag.currentUser = sess; var request = String.Format("{{ {0} = chưa duyệt }}", nameof(HoaDonDaiLyManager.Properties.TrangThai)); ViewBag.HoaDonChuaDuyet = HoaDonDaiLyManager.filter(request).Count; request = String.Format("{{ {0} = chưa duyệt }}", nameof(PhieuXuatManager.Properties.TrangThai)); ViewBag.PhieuXuatChuaDuyet = PhieuXuatManager.filter(request).Count; request = String.Format("{{ {0} = đã duyệt }} {{ {1} = {2} }}", nameof(HoaDonDaiLyManager.Properties.TrangThai), nameof(HoaDonDaiLyManager.Properties.NgayLap), String.Format("{0:yyyy/MM}", DateTime.Now)); ViewBag.ThanhToanTrongThang = HoaDonDaiLyManager.filter(request).Count; if (Session[Core.Constants.SESSION.PAGE_SIZE] != null) { ViewBag.PageSize = Session[Core.Constants.SESSION.PAGE_SIZE]; } } }
public List <HoaDonDaiLy> getAllHoaDon() { var param = new Dictionary <string, dynamic>(); param.Add(HoaDonDaiLyManager.Properties.MaSoDaiLy, this.MaSoDaiLy); return(HoaDonDaiLyManager.findBy(param)); }
//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 })); } }
//khi Lưu lại hóa đơn private void btnLuu_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn lưu", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { List <ChiTietHoaDonDaiLy> ListChiTiet = new List <ChiTietHoaDonDaiLy>(); HoaDonDaiLy hd = new HoaDonDaiLy(); hd.MaSoDaiLy = int.Parse(txbMaSoDaiLy.Text.ToString()); hd.NgayLap = DateTime.Parse(dtpNgayLap.Value.ToString("yyyy-MM-dd")); for (int i = 0; i < gdvChiTiet.RowCount - 1; i++) { if (!String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[0].Value)) && !String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[1].Value)) && !String.IsNullOrEmpty(Convert.ToString(gdvChiTiet.Rows[i].Cells[2].Value))) { ChiTietHoaDonDaiLy ct = new ChiTietHoaDonDaiLy(); ct.MaSoSach = int.Parse(gdvChiTiet.Rows[i].Cells[0].Value.ToString()); ct.SoLuong = int.Parse(gdvChiTiet.Rows[i].Cells[1].Value.ToString()); ct.DonGia = int.Parse(gdvChiTiet.Rows[i].Cells[2].Value.ToString()); ListChiTiet.Add(ct); } } if (ListChiTiet.Count > 1) { for (int i = 0; i < ListChiTiet.Count - 1; i++) { for (int j = i + 1; j < ListChiTiet.Count; j++) { if (ListChiTiet[i].MaSoSach.Equals(ListChiTiet[j].MaSoSach)) { MessageBox.Show("Không nhập trùng sách"); return; } } } } hd.ChiTiet = ListChiTiet; int x = HoaDonDaiLyManager.add(hd); if (x != 0) { MessageBox.Show("Đã thêm thành công hóa đơn đại lý"); txbMaHoaDon.Text = x + ""; } } else if (dialogResult == DialogResult.No) { return; } }
// 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)); }
private void btXoa_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn xóa", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (HoaDonDaiLyManager.delete(_CurrentHD.MaSoHoaDon)) { MessageBox.Show("Đã xóa thành công hóa đơn"); } else { MessageBox.Show("Không xóa được"); } } else if (dialogResult == DialogResult.No) { return; } }
// GET: PhieuNhap public ActionResult All(int page = 1, int pageSize = 10, string search = null) { List <HoaDonDaiLy> DMHoaDon = null; ViewBag.cultureInfo = CultureInfo; if (!String.IsNullOrEmpty(search)) { DMHoaDon = HoaDonDaiLyManager.filter(search); ViewBag.SearchKey = search; } else { DMHoaDon = HoaDonDaiLyManager.getAll(); } ViewBag.tongTien = DMHoaDon.Sum(hd => hd.TongTien); var models = DMHoaDon.ToPagedList(page, pageSize); setAlertMessage(); return(View(models)); }
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)); } }
public ActionResult ThanhToan(HoaDonDaiLy model, FormCollection collection) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var result = HoaDonDaiLyManager.add(model); if (result != 0) { _hoadon = null; putSuccessMessage("Thanh toán thành công"); return(RedirectToAction("Details", new { id = result })); } else { putErrorMessage("Thanh toán không thành công"); } } else { putModelStateFailErrors(ModelState); } //ViewBag.cultureInfo = CultureInfo; //ViewBag.currentDaiLy = _hoadon.DaiLy; //ViewBag.DMSach = new SelectList(_hoadon.DaiLy.getSachNo(), // nameof(SachManager.Properties.MaSoSach), // nameof(SachManager.Properties.TenSach), ""); //_hoadon.NgayLap = DateTime.Now; //return View(_hoadon); return(RedirectToAction("ThanhToan", new { masodaily = _hoadon.MaSoDaiLy })); } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("ThanhToan", new { masodaily = _hoadon.MaSoDaiLy })); } }
public ActionResult Delete(int?id, FormCollection collection) { try { if (HoaDonDaiLyManager.delete((int)id)) { putSuccessMessage("Xóa thành công"); _currentHoaDon = null; return(RedirectToAction("All")); } else { putErrorMessage("Xóa không thành công"); return(RedirectToAction("Delete", new { id })); } } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("Delete", new { id })); } }
// 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)); } }
private void btDuyet_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn duyệt hóa đơn", "Thông báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (_CurrentHD != null && _CurrentHD.TrangThai == 0) { if (_CurrentHD.accept()) { MessageBox.Show("Duyệt hóa đơn thành công"); gdvHoaDon.DataSource = HoaDonDaiLyManager.getAll(); } else { MessageBox.Show("Duyệt không thành công, vui lòng kiểm tra lại Công nợ"); } } } else if (dialogResult == DialogResult.No) { return; } }
public ActionResult Edit(HoaDonDaiLy model, FormCollection collection) { try { if (ModelState.IsValid) { if (HoaDonDaiLyManager.edit(model)) { _currentHoaDon = null; putSuccessMessage("Cập nhật thành công"); return(RedirectToAction("Details", new { id = model.MaSoHoaDon })); } else { putErrorMessage("Cập nhật thất bại"); } } else { putModelStateFailErrors(ModelState); } // TODO: Add update logic here //_hoadon = model; //ViewBag.currentDaiLy = _hoadon.DaiLy; //ViewBag.DMSach = new SelectList(_hoadon.DaiLy.getSachNo(), // nameof(SachManager.Properties.MaSoSach), // nameof(SachManager.Properties.TenSach), ""); //return View(_hoadon); return(RedirectToAction("Edit", new { id = model.MaSoHoaDon })); } catch (Exception ex) { putErrorMessage(ex.Message); return(RedirectToAction("Edit", new { id = model.MaSoHoaDon })); } }
public bool accept() { //Kiểm tra số lượng có thể duyệt không foreach (ChiTietHoaDonDaiLy ct in this.ChiTiet) { //Nếu tổng số lượng sách mà đại lý nợ ít hơn só sách sẽ thanh toán thì hủy duyệt if (ct.Sach.TongSoLuongDaiLyNo < ct.SoLuong) { return(false); } } //Duyệt từng chi tiết foreach (ChiTietHoaDonDaiLy ct in this.ChiTiet) { // //Cập nhật công nợ var sl = ct.SoLuong; // Số lượng sách thanh toán var count = ct.Sach.CongNoDaiLy.Count; // Số lượng các công nợ var index = 0; while (sl > 0) { if (index == count) { //Đã duyệt hết các công nợ break; } if (ct.Sach.CongNoDaiLy[index].SoLuong >= sl) // Nếu công nợ nhiều hơn hoặc bằng số lượng thanh toán { //Giảm số lượng công nợ ct.Sach.CongNoDaiLy[index].SoLuong -= sl; sl -= sl; //Cập nhật if (!CongNoDaiLyManager.edit(ct.Sach.CongNoDaiLy[index])) { return(false); } } else // Nếu công nợ ít hơn số lượng thanh toán { sl -= ct.Sach.CongNoDaiLy[index].SoLuong; ct.Sach.CongNoDaiLy[index].SoLuong = 0; //Cập nhật if (!CongNoDaiLyManager.edit(ct.Sach.CongNoDaiLy[index])) { return(false); } } index++; } ct.TrangThai = 1; } //Thay đổi trang thái phiếu nhập this.TrangThai = 1; if (HoaDonDaiLyManager.edit(this)) { return(true); } else { return(false); } }
private void btLoadAll_Click(object sender, EventArgs e) { gdvHoaDon.DataSource = HoaDonDaiLyManager.getAll(); }
private void btChuaDuyet_Click(object sender, EventArgs e) { gdvHoaDon.DataSource = HoaDonDaiLyManager.getUnaproved(); }