public ActionResult XuatSach(DAILY dl, FormCollection f) { PHIEUXUAT px = new PHIEUXUAT(); px.MaDL = int.Parse(f["MaDL"].ToString()); String[] temp = f["NgayXuat"].ToString().Split('-'); DateTime date = new DateTime(int.Parse(temp[2]), int.Parse(temp[1]), int.Parse(temp[0])); px.NgayXuat = date; px.TrangThai = false; db.PHIEUXUATs.Add(px); db.SaveChanges(); int?TongTien = 0; foreach (CT_PhieuXuatViewModel ct in Session["DS_Sach"] as List <CT_PhieuXuatViewModel> ) { CT_PHIEUXUAT ctpx = new CT_PHIEUXUAT(); ctpx.MaPX = px.MaPX; ctpx.MaSach = ct.MaSach; ctpx.SLXuat = ct.SLXuat; ctpx.DonGia = ct.DonGia; ctpx.ThanhTien = ctpx.SLXuat * ctpx.DonGia; TongTien += ctpx.ThanhTien; db.CT_PHIEUXUAT.Add(ctpx); } px.TongTien = TongTien; db.SaveChanges(); CONGNO_DL congno = new CONGNO_DL(); congno.MaDL = dl.MaDL; congno.ThoiGian = new DateTime(int.Parse(temp[2]), int.Parse(temp[1]), int.Parse(temp[0])); congno.TienDaTra = 0; congno.TienNo = px.TongTien; db.CONGNO_DL.Add(congno); db.SaveChanges(); Session.Clear(); return(RedirectToAction("Index")); }
public ActionResult ThemBaoCao(DAILY dl, FormCollection f) { BAOCAODL bc = new BAOCAODL(); bc.MaDL = int.Parse(f["MaDL"].ToString()); bc.NgayLap = date; bc.NgayBD = datebd; bc.NgayKT = datekt; bc.TinhTrang = true; db.BAOCAODLs.Add(bc); db.SaveChanges(); int?TongTien = 0; foreach (CT_BaoCaoDaiLyViewModel ct in Session["DS_BaoCao_DaiLy"] as List <CT_BaoCaoDaiLyViewModel> ) { CT_BAOCAODL ctbc = new CT_BAOCAODL(); ctbc.MaBCDL = bc.MaBCDL; ctbc.MaSach = ct.MaSach; ctbc.SoLuongBan = ct.SoLuongBan; ctbc.DonGiaBan = ct.DonGiaBan; ctbc.ThanhTien = ctbc.SoLuongBan * ctbc.DonGiaBan; TongTien += ctbc.ThanhTien; db.CT_BAOCAODL.Add(ctbc); } bc.ThanhToan = TongTien; db.SaveChanges(); CONGNO_DL congno = new CONGNO_DL(); congno.MaDL = int.Parse(f["MaDL"].ToString()); congno.ThoiGian = date; congno.TienDaTra = bc.ThanhToan; congno.TienNo = 0; db.CONGNO_DL.Add(congno); db.SaveChanges(); Session.Clear(); return(RedirectToAction("Index")); }
public ActionResult CongNoDL(FormCollection f) { String[] temp = f["datepicker"].ToString().Split('-'); DateTime date = new DateTime(int.Parse(temp[2]), int.Parse(temp[1]), int.Parse(temp[0])); List <CONGNO_DL> lst_congno_dl = new List <CONGNO_DL>(); List <DAILY> lst_dl = new List <DAILY>(); lst_dl = db.DAILies.ToList(); foreach (DAILY dl in lst_dl) { CONGNO_DL congno_dl = new CONGNO_DL(); congno_dl = db.CONGNO_DL.Where(x => x.ThoiGian <= date.Date && x.MaDL == dl.MaDL).OrderByDescending(x => x.ThoiGian).FirstOrDefault(); if (congno_dl != null) { congno_dl.TienNo = db.CONGNO_DL.Where(x => x.ThoiGian <= date.Date && x.MaDL == dl.MaDL).Sum(x => x.TienNo - x.TienDaTra); lst_congno_dl.Add(congno_dl); } } ViewBag.NgayCongNo = date.ToString("dd/MM/yyyy"); return(View(lst_congno_dl)); }