Exemplo n.º 1
0
        public ActionResult XemChiTietHDN(string mahoadon)
        {
            var model = new List <CTHDNhapModel>();
            var list  = db.ChiTietHDNs.Where(x => x.MaHDN == mahoadon).ToList();
            int i     = 0;

            foreach (var item in list)
            {
                var itemmodel = new CTHDNhapModel();
                i++;
                itemmodel.TenNguyenLieu = new NguyenLieuDao().getById(item.MaNguyenLieu).TenNguyenLieu;
                itemmodel.TenDonViTinh  = new DonViTinhDao().getById(item.MaDonViTinh).TenDonViTinh;
                itemmodel.GiaNhap       = item.GiaNhap.ToString();
                itemmodel.SoLuong       = item.SoLuong.ToString();
                itemmodel.ChietKhau     = item.ChietKhau.ToString();
                itemmodel.ThanhTien     = item.ThanhTien;
                itemmodel.STT           = i;
                model.Add(itemmodel);
            }
            var hoadonnhap = db.HoaDonNhaps.FirstOrDefault(x => x.Id == mahoadon);
            var hdnmodel   = new HoaDonNhapModel();

            hdnmodel.TenDangNhap = db.KhachHangs.FirstOrDefault(x => x.Id == hoadonnhap.MaNhanVien).TenDangNhap;
            hdnmodel.NgayNhap    = hoadonnhap.NgayNhap;
            hdnmodel.TenNCC      = db.NhaCungCaps.FirstOrDefault(x => x.Id == hoadonnhap.MaNCC).TenNCC;
            hdnmodel.TongTien    = hoadonnhap.TongTien;
            hdnmodel.ChietKhau   = String.Format("{0:0,0}", hoadonnhap.ChietKhau);
            var chietkhau = new ChuoiCuaHangTraSua.Common.ConvertMoney().ConvertTien(hdnmodel.ChietKhau);

            hdnmodel.PhaiTra   = (hdnmodel.TongTien - chietkhau);
            ViewBag.HoaDonNhap = hdnmodel;
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult SuaCTHDN(int id, string soluong, string gianhap, string chietkhau)
        {
            var cthdn   = db.ChiTietHDNs.FirstOrDefault(x => x.Id == id);
            var convert = new ChuoiCuaHangTraSua.Common.ConvertMoney();

            cthdn.SoLuong   = convert.ConvertTien(soluong);
            cthdn.GiaNhap   = convert.ConvertTien(gianhap);
            cthdn.ChietKhau = convert.ConvertTien(chietkhau);
            cthdn.ThanhTien = cthdn.SoLuong * cthdn.GiaNhap - cthdn.ChietKhau;
            db.SaveChanges();
            return(RedirectToAction("CreateHDN", "HoaDonNhapAdmin"));
        }