public IHttpActionResult PostBH_DON_BAN_HANG(BH_DON_BAN_HANG bH_DON_BAN_HANG) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BH_DON_BAN_HANG.Add(bH_DON_BAN_HANG); try { db.SaveChanges(); } catch (DbUpdateException) { if (BH_DON_BAN_HANGExists(bH_DON_BAN_HANG.MA_SO_BH)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = bH_DON_BAN_HANG.MA_SO_BH }, bH_DON_BAN_HANG)); }
public ActionResult DeleteConfirmed(string id) { BH_DON_BAN_HANG bH_DON_BAN_HANG = db.BH_DON_BAN_HANG.Find(id); db.BH_DON_BAN_HANG.Remove(bH_DON_BAN_HANG); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "MA_SO_BH,NGAY_BH,MA_KHACH_HANG,TEN_LIEN_HE,HINH_THUC_THANH_TOAN,TONG_TIEN_HANG,SO_TIEN_VIET_BANG_CHU,NGAY_GIAO_HANG,DIA_DIEM_GIAO_HANG,NHAN_VIEN_QUAN_LY,DA_XUAT_KHO,MA_SO_XUAT_KHO,TRUC_THUOC,TONG_TIEN_THANH_TOAN,TONG_TIEN_THUE_GTGT,DA_LAP_HOA_DON")] BH_DON_BAN_HANG bH_DON_BAN_HANG) { if (ModelState.IsValid) { db.Entry(bH_DON_BAN_HANG).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MA_KHACH_HANG = new SelectList(db.KHs, "MA_KHACH_HANG", "TEN_CONG_TY", bH_DON_BAN_HANG.MA_KHACH_HANG); ViewBag.NHAN_VIEN_QUAN_LY = new SelectList(db.CCTC_NHAN_VIEN, "USERNAME", "GIOI_TINH", bH_DON_BAN_HANG.NHAN_VIEN_QUAN_LY); ViewBag.TRUC_THUOC = new SelectList(db.CCTC_CONG_TY, "MA_CONG_TY", "TEN_CONG_TY", bH_DON_BAN_HANG.TRUC_THUOC); return(View(bH_DON_BAN_HANG)); }
// GET: BanHang/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BH_DON_BAN_HANG bH_DON_BAN_HANG = db.BH_DON_BAN_HANG.Find(id); if (bH_DON_BAN_HANG == null) { return(HttpNotFound()); } return(View(bH_DON_BAN_HANG)); }
public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BH_DON_BAN_HANG bH_DON_BAN_HANG = db.BH_DON_BAN_HANG.Find(id); if (bH_DON_BAN_HANG == null) { return(HttpNotFound()); } ViewBag.MA_KHACH_HANG = new SelectList(db.KHs, "MA_KHACH_HANG", "TEN_CONG_TY", bH_DON_BAN_HANG.MA_KHACH_HANG); ViewBag.NHAN_VIEN_QUAN_LY = new SelectList(db.CCTC_NHAN_VIEN, "USERNAME", "GIOI_TINH", bH_DON_BAN_HANG.NHAN_VIEN_QUAN_LY); ViewBag.TRUC_THUOC = new SelectList(db.CCTC_CONG_TY, "MA_CONG_TY", "TEN_CONG_TY", bH_DON_BAN_HANG.TRUC_THUOC); return(View(bH_DON_BAN_HANG)); }
public IHttpActionResult DeleteBH_DON_BAN_HANG(string id) { BH_DON_BAN_HANG donbanhang = db.BH_DON_BAN_HANG.Find(id); if (donbanhang == null) { return(NotFound()); } List <BH_CT_DON_BAN_HANG> listChiTiet = new List <BH_CT_DON_BAN_HANG>(); listChiTiet = db.BH_CT_DON_BAN_HANG.Where(x => x.MA_SO_BH == id).ToList(); foreach (var item in listChiTiet) { db.BH_CT_DON_BAN_HANG.Remove(item); } db.BH_DON_BAN_HANG.Remove(donbanhang); db.SaveChanges(); return(Ok(donbanhang)); }
public IHttpActionResult PostThemPhieuBanHang(ThongTinDonPO thongtinPO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BH_DON_BAN_HANG baogia = new BH_DON_BAN_HANG(); baogia.MA_SO_BH = GenerateSoBanHang(); baogia.NGAY_BH = DateTime.Today.Date; baogia.MA_KHACH_HANG = thongtinPO.MA_KHACH_HANG; baogia.TEN_LIEN_HE = thongtinPO.TEN_LIEN_HE; baogia.HINH_THUC_THANH_TOAN = thongtinPO.HINH_THUC_THANH_TOAN; baogia.TONG_TIEN_THANH_TOAN = thongtinPO.TONG_TIEN_THANH_TOAN; baogia.TONG_TIEN_HANG = thongtinPO.TONG_TIEN_HANG; baogia.TONG_TIEN_THUE_GTGT = thongtinPO.TONG_TIEN_THUE_GTGT; baogia.SO_TIEN_VIET_BANG_CHU = thongtinPO.SO_TIEN_VIET_BANG_CHU; baogia.TRUC_THUOC = thongtinPO.TRUC_THUOC; baogia.DA_LAP_HOA_DON = thongtinPO.DA_LAP_HOA_DON; baogia.NHAN_VIEN_QUAN_LY = thongtinPO.NHAN_VIEN_QUAN_LY; if (thongtinPO.NGAY_GIAO_HANG != null) { baogia.NGAY_GIAO_HANG = xlnt.Xulydatetime(thongtinPO.NGAY_GIAO_HANG.ToString()); } baogia.DIA_DIEM_GIAO_HANG = thongtinPO.DIA_DIEM_GIAO_HANG; baogia.DA_XUAT_KHO = thongtinPO.DA_XUAT_KHO; baogia.MA_SO_PO = thongtinPO.MA_SO_PO; db.BH_DON_BAN_HANG.Add(baogia); db.SaveChanges(); foreach (var item in thongtinPO.ChiTietPO) { BH_CT_DON_BAN_HANG lienhe = new BH_CT_DON_BAN_HANG(); lienhe.MA_SO_BH = baogia.MA_SO_BH; lienhe.MA_HANG = item.MA_HANG; lienhe.MA_DIEU_CHINH = item.MA_DIEU_CHINH; lienhe.MA_PO = item.MA_SO_PO; lienhe.TK_CO = item.TK_CO; lienhe.TK_NO = item.TK_NO; lienhe.TK_THUE = item.TK_THUE; lienhe.SO_LUONG = item.SO_LUONG; lienhe.DVT = item.DVT; lienhe.DON_GIA = item.DON_GIA; lienhe.THANH_TIEN_HANG = item.THANH_TIEN_HANG; lienhe.THUE_GTGT = item.THUE_GTGT; lienhe.TIEN_THUE_GTGT = ((Convert.ToDouble(item.THANH_TIEN_HANG) * (item.THUE_GTGT / 100))); lienhe.TIEN_THANH_TOAN = Convert.ToDouble(lienhe.THANH_TIEN_HANG) + lienhe.TIEN_THUE_GTGT; lienhe.DIEN_GIAI_THUE = item.DIEN_GIAI_THUE; db.BH_CT_DON_BAN_HANG.Add(lienhe); } foreach (var item in thongtinPO.ChiTietPO) { var query = db.BH_CT_DON_HANG_PO.Where(x => x.ID == item.ID).FirstOrDefault(); if (query != null) { query.DA_BAN = true; db.SaveChanges(); } } var data = db.BH_CT_DON_HANG_PO.Where(x => x.MA_SO_PO == thongtinPO.MA_SO_PO && x.DA_BAN == false).ToList(); if (data.Count() == 0) { var data1 = db.BH_DON_HANG_PO.Where(x => x.MA_SO_PO == thongtinPO.MA_SO_PO).FirstOrDefault(); if (data1 != null) { data1.DA_BAN_HANG = true; } } try { db.SaveChanges(); } catch (DbUpdateException) { throw; } return(Ok(baogia.MA_SO_BH)); }
public IHttpActionResult PostKHO_XUAT_KHO(XuatKhoBH kho_xuatkho) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Lưu thông tin nhập kho KHO_XUAT_KHO xk = new KHO_XUAT_KHO(); xk.NGAY_CHUNG_TU = GeneralFunction.ConvertToTime(kho_xuatkho.NGAY_CHUNG_TU); xk.NGAY_HACH_TOAN = GeneralFunction.ConvertToTime(kho_xuatkho.NGAY_HACH_TOAN); xk.SO_CHUNG_TU = GeneralChungTu(); xk.NGUOI_NHAN = kho_xuatkho.NGUOI_NHAN; xk.KHACH_HANG = kho_xuatkho.KHACH_HANG; xk.LY_DO_XUAT = kho_xuatkho.LY_DO_XUAT; xk.NHAN_VIEN_BAN_HANG = kho_xuatkho.NHAN_VIEN_BAN_HANG; xk.NGUOI_LAP_PHIEU = kho_xuatkho.NGUOI_LAP_PHIEU; xk.TRUC_THUOC = "HOPLONG"; xk.LOAI_XUAT_KHO = kho_xuatkho.LOAI_XUAT_KHO; xk.PHIEU_BAN_HANG = kho_xuatkho.PHIEU_BAN_HANG; db.KHO_XUAT_KHO.Add(xk); // Lưu Đơn bán hàng BH_DON_BAN_HANG dbh = db.BH_DON_BAN_HANG.Where(x => x.MA_SO_BH == xk.PHIEU_BAN_HANG).FirstOrDefault(); if (dbh.DA_XUAT_KHO == false) { dbh.DA_XUAT_KHO = true; } //Lưu thông tin tham chiếu if (kho_xuatkho.ThamChieu.Count > 0) { foreach (ThamChieu item in kho_xuatkho.ThamChieu) { XL_THAM_CHIEU_CHUNG_TU newItem = new XL_THAM_CHIEU_CHUNG_TU(); newItem.SO_CHUNG_TU_GOC = xk.SO_CHUNG_TU; newItem.SO_CHUNG_TU_THAM_CHIEU = item.SO_CHUNG_TU; db.XL_THAM_CHIEU_CHUNG_TU.Add(newItem); } } //Lưu chi tiết decimal tongtien = 0; //TONKHO_HOPLONG HHTon = new TONKHO_HOPLONG(); //HH_NHOM_VTHH NhomHang = new HH_NHOM_VTHH(); if (kho_xuatkho.ChiTiet != null && kho_xuatkho.ChiTiet.Count > 0) { foreach (ChiTietXuatKhoBH item in kho_xuatkho.ChiTiet) { KHO_CT_XUAT_KHO newItem = new KHO_CT_XUAT_KHO(); newItem.SO_CHUNG_TU = xk.SO_CHUNG_TU; newItem.MA_HANG = item.MA_HANG; newItem.MA_DIEU_CHINH = item.MA_DIEU_CHINH; newItem.MA_KHO_CON = item.MA_KHO_CON; newItem.TK_CO = item.TK_CO; newItem.TK_NO = item.TK_NO; newItem.DVT = item.DVT; newItem.DON_GIA_BAN = Convert.ToDecimal(item.DON_GIA); newItem.DON_GIA_VON = Convert.ToDecimal(item.DON_GIA_VON); newItem.SO_LUONG = Convert.ToInt32(item.SO_LUONG); newItem.THANH_TIEN = newItem.DON_GIA_BAN * newItem.SO_LUONG; tongtien += newItem.THANH_TIEN; newItem.TK_KHO = item.TK_HACH_TOAN_KHO; db.KHO_CT_XUAT_KHO.Add(newItem); //Cập nhật hàng tồn TONKHO_HOPLONG newHangTon = db.TONKHO_HOPLONG.Where(x => x.MA_HANG == item.MA_HANG && x.MA_KHO_CON == item.MA_KHO_CON).FirstOrDefault(); if (newHangTon == null || newHangTon.SL_HOPLONG < item.SO_LUONG) { return(Ok("Hàng không có trong kho hoặc SL tồn không đủ")); } newHangTon.SL_HOPLONG -= Convert.ToInt32(item.SO_LUONG); //if (newHangTon == null) //{ // db.TONKHO_HOPLONG.Add(newHangTon); //} ////Cập nhật nhóm hàng //TONKHO_HANG hangton = NhomHang.GetNhomHang(item.MA_HANG); //if (hangton != null) //{ // hangton.SL_HANG = Convert.ToInt32(item.SO_LUONG); //} // Lưu Nhật ký KT_SO_NHAT_KY_CHUNG sonhatky = new KT_SO_NHAT_KY_CHUNG(); sonhatky.SO_CHUNG_TU = newItem.SO_CHUNG_TU; sonhatky.NGAY_CHUNG_TU = xk.NGAY_CHUNG_TU; sonhatky.NGAY_HACH_TOAN = xk.NGAY_HACH_TOAN; if (xk.NGUOI_NHAN == null) { sonhatky.DOI_TUONG = xk.KHACH_HANG; } else { sonhatky.DOI_TUONG = xk.NGUOI_NHAN; } sonhatky.TRUC_THUOC = "HOPLONG"; sonhatky.DIEN_GIAI_CHUNG = xk.LY_DO_XUAT; sonhatky.DIEN_GIAI_CHI_TIET = xk.LY_DO_XUAT; sonhatky.TAI_KHOAN_HACH_TOAN = newItem.TK_NO; sonhatky.TAI_KHOAN_DOI_UNG = newItem.TK_CO; sonhatky.PHAT_SINH_NO = tongtien; sonhatky.PHAT_SINH_CO = 0; db.KT_SO_NHAT_KY_CHUNG.Add(sonhatky); KT_SO_NHAT_KY_CHUNG sonhatky1 = new KT_SO_NHAT_KY_CHUNG(); sonhatky1.SO_CHUNG_TU = newItem.SO_CHUNG_TU; sonhatky1.NGAY_CHUNG_TU = xk.NGAY_CHUNG_TU; sonhatky1.NGAY_HACH_TOAN = xk.NGAY_HACH_TOAN; if (xk.NGUOI_NHAN == null) { sonhatky1.DOI_TUONG = xk.KHACH_HANG; } else { sonhatky1.DOI_TUONG = xk.NGUOI_NHAN; } sonhatky1.TRUC_THUOC = "HOPLONG"; sonhatky1.DIEN_GIAI_CHUNG = xk.LY_DO_XUAT; sonhatky1.DIEN_GIAI_CHI_TIET = xk.LY_DO_XUAT; sonhatky1.TAI_KHOAN_HACH_TOAN = newItem.TK_CO; sonhatky1.TAI_KHOAN_DOI_UNG = newItem.TK_NO; sonhatky1.PHAT_SINH_NO = 0; sonhatky1.PHAT_SINH_CO = tongtien; db.KT_SO_NHAT_KY_CHUNG.Add(sonhatky1); } } xk.TONG_TIEN = tongtien; try { db.SaveChanges(); } catch (DbUpdateException) { if (KHO_XUAT_KHOExists(kho_xuatkho.SO_CHUNG_TU)) { return(Conflict()); } else { throw; } } return(Ok(xk.SO_CHUNG_TU)); }