public void Congno(Phieuxuat px) { int tongtien = 0; int tongsl = 0; foreach (var i in px.CTPXes) { var gia = (from c in db.Saches where c.IdSach == i.IdSach select c.GiaXuat).FirstOrDefault(); tongtien += gia * i.SoLuong; tongsl += i.SoLuong; } Congno a = db.Congnoes.OrderByDescending(c => c.IdDL == px.IdDL).FirstOrDefault(); if (a == null || a.Ngay.Date != px.NgayXuat.Date) { a = new Congno(); a.Ngay = px.NgayXuat; a.IdDL = px.IdDL; a.SLsachlay = tongsl; a.Tongtienno = tongtien; a.Tongtiendatra = 0; db.Congnoes.Add(a); List <Congno> list = db.Congnoes.ToList(); } else if (a.Ngay.Date == px.NgayXuat.Date)//cùng ngay thi update lại { a.SLsachlay += tongsl; a.Tongtienno += tongtien; db.Entry(a).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); }
public ActionResult DatHang(FormCollection collection) { Phieuxuat ddh = new Phieuxuat(); Nhanvien nv = (Nhanvien)Session["Taikhoan"]; try { List <Nhap> gh = Layds(); ddh.NhanVien = nv.MaNV; ddh.Ngaylap = DateTime.Now; kho.Phieuxuats.InsertOnSubmit(ddh); kho.SubmitChanges(); foreach (var item in gh) { CTPHIEUXUAT ctpn = new CTPHIEUXUAT(); ctpn.Maxuat = ddh.MaXuat; ctpn.MaMH = item.iMaMH; ctpn.SoluongXuat = item.iSoluong; ctpn.GiaXuat = item.dDonggia; ctpn.TongTien = item.dThanhtien; kho.CTPHIEUXUATs.InsertOnSubmit(ctpn); } kho.SubmitChanges(); //Session["Nhap"] = null; return(RedirectToAction("Xacnhan", "Nhap")); } catch { TempData["LoiSoLuong"] = "Số lượng xuất phải ít hơn số lượng mặt hàng trong kho!"; return(RedirectToAction("DatHang")); } }
public ActionResult DeleteConfirmed(string id) { Phieuxuat phieuxuat = db.Phieuxuats.Find(id); db.Phieuxuats.Remove(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Maphieuxuat,Ngaytao,Makhachhang")] Phieuxuat phieuxuat) { if (ModelState.IsValid) { db.Entry(phieuxuat).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Makhachhang = new SelectList(db.Khachhangs, "Makhachhang", "Tenkhachhang", phieuxuat.Makhachhang); return(View(phieuxuat)); }
public ActionResult Edit([Bind(Include = "IdPx,NgayXuat,NguoiNhan,IdDL")] Phieuxuat phieuxuat) { if (ModelState.IsValid) { db.Entry(phieuxuat).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdDL = new SelectList(db.Dailis, "IdDL", "TenDL", phieuxuat.IdDL); return(View(phieuxuat)); }
public ActionResult Create([Bind(Include = "Maphieuxuat,Ngaytao,Makhachhang")] Phieuxuat phieuxuat) { if (ModelState.IsValid) { db.Phieuxuats.Add(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Makhachhang = new SelectList(db.Khachhangs, "Makhachhang", "Tenkhachhang", phieuxuat.Makhachhang); return(View(phieuxuat)); }
public ActionResult Create([Bind(Include = "IdPx,NgayXuat,NguoiNhan,IdDL")] Phieuxuat phieuxuat, [Bind(Prefix = "ct")] CTPX[] ctpx) { if (ModelState.IsValid) { if (ctpx == null) { ModelState.AddModelError("", "Chưa thêm chi tiết phiếu nhập"); ViewBag.IdDL = new SelectList(db.Dailis, "IdDL", "TenDL"); ViewBag.idsach = new SelectList(db.Saches, "IdSach", "TenSach"); return(View()); } if (!new XuatBUS().KTSL(ctpx)) { ModelState.AddModelError("", "Không đủ số lượng hoặc có sách chưa nhập về"); ViewBag.IdDL = new SelectList(db.Dailis, "IdDL", "TenDL"); ViewBag.idsach = new SelectList(db.Saches, "IdSach", "TenSach"); PXvaCTPXmodel view1 = new PXvaCTPXmodel(); phieuxuat.CTPXes = ctpx; view1.phieuxuat = phieuxuat; return(View(view1)); } else { foreach (var i in ctpx) { //cap nhat sl sách trong kho new XuatBUS().CapnhatSLtrongKho(phieuxuat.NgayXuat, i.SoLuong, i.IdSach); //cap nhat kho dai li KhoDL khodaily = new KhoDL(); khodaily.IdSach = i.IdSach; khodaily.IdDL = phieuxuat.IdDL; khodaily.SL = i.SoLuong; new XuatBUS().AddKhoDL(khodaily); phieuxuat.CTPXes.Add(i); } db.Phieuxuats.Add(phieuxuat); new XuatBUS().Congno(phieuxuat); db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.IdDL = new SelectList(db.Dailis, "IdDL", "TenDL"); ViewBag.idsach = new SelectList(db.Saches, "IdSach", "TenSach"); PXvaCTPXmodel view2 = new PXvaCTPXmodel(); phieuxuat.CTPXes = ctpx; view2.phieuxuat = phieuxuat; return(View(view2)); }
// GET: Phieuxuats/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Phieuxuat phieuxuat = db.Phieuxuats.Find(id); if (phieuxuat == null) { return(HttpNotFound()); } return(View(phieuxuat)); }
// GET: Phieuxuats/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Phieuxuat phieuxuat = db.Phieuxuats.Find(id); if (phieuxuat == null) { return(HttpNotFound()); } ViewBag.Makhachhang = new SelectList(db.Khachhangs, "Makhachhang", "Tenkhachhang", phieuxuat.Makhachhang); return(View(phieuxuat)); }
// GET: Phieuxuats/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Phieuxuat phieuxuat = db.Phieuxuats.Find(id); if (phieuxuat == null) { return(HttpNotFound()); } ViewBag.IdDL = new SelectList(db.Dailis, "IdDL", "TenDL", phieuxuat.IdDL); return(View(phieuxuat)); }
public ActionResult Create(FormCollection collection, Phieuxuat px) { kho.Phieuxuats.InsertOnSubmit(px); kho.SubmitChanges(); return(RedirectToAction("Index", "Phieuxuat")); }