public bool CapNhatHangHoaKhiTaoPhieuNhap(int maHangHoa, int soLuongNhap, decimal giaNhap) { try { var loinhuan = from loaihanghoa in _dbContext.LoaiHangHoas join hanghoa in _hangHoaRepo.GetAll() on loaihanghoa.MaLoaiHangHoa equals hanghoa.MaLoaiHangHoa where hanghoa.MaHangHoa.Equals(maHangHoa) select new { loaihanghoa.PhanTramLoiNhuan }; decimal phantramloinhuan = loinhuan.FirstOrDefault().PhanTramLoiNhuan; decimal phantram = 1 + phantramloinhuan / 100; var result = _dbContext.HangHoas.FirstOrDefault(x => x.MaHangHoa == maHangHoa); if (result != null) { decimal giaChuaTinhLoiNhuan = Math.Round(result.GiaBan / phantram); decimal giaBinhQuan = Math.Round((result.SoLuongTon * giaChuaTinhLoiNhuan + soLuongNhap * giaNhap) / (result.SoLuongTon + soLuongNhap)); result.GiaBan = Math.Round(giaBinhQuan + giaBinhQuan * phantramloinhuan / 100); result.SoLuongTon += soLuongNhap; _dbContext.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public bool Insert(ChiTietPhieuDatHang detail) { try { dbContext.ChiTietPhieuDatHanges.Add(detail); dbContext.SaveChanges(); return(true); } catch { return(false); } }
public int Insert(PhieuDatHang order) { dbContext.PhieuDatHangs.Add(order); dbContext.SaveChanges(); return(order.SoPhieuDatHang); }