Beispiel #1
0
 public Hoadon(HoadonViewModel hoadonViewModel)
 {
     this.ID          = hoadonViewModel.ID;
     this.Ngaylaphd   = hoadonViewModel.Ngaylaphd;
     this.Tongtien    = hoadonViewModel.Tongtien;
     this.Ptthanhtoan = hoadonViewModel.Ptthanhtoan;
     this.Tinhtrang   = hoadonViewModel.Tinhtrang;
     this.Ghichu      = hoadonViewModel.Ghichu;
     this.KhachHangID = hoadonViewModel.KhachhangID;
 }
Beispiel #2
0
 public JsonResult GetAllCthdById(int id)
 {
     try
     {
         HoadonViewModel res = _hoadonService.GetById(id);
         return(Json(res, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(Json(ex.Message, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #3
0
        public HoadonViewModel Add(HoadonViewModel hoadonVm)
        {
            var hd = Mapper.Map <HoadonViewModel, Hoadon>(hoadonVm);

            _repository.AddReturn(hd);
            hd.mahd        = hd.KeyId;
            hoadonVm.KeyId = hd.KeyId;
            hoadonVm.mahd  = hd.KeyId;
            //sanphamVm.Id = _convertFunction.Instance.Create_Code(true, sp.KeyId,
            //CommonConstants.defaultLengthNumberCode, const_AddressbookType.Employee);
            //sp.Id = HP_EmployeeVm.Id;
            //employee.UserBy.IsEmployee = true;
            return(hoadonVm);
        }
        public HoadonViewModel GetPTThanhToan()
        {
            var pttt = new HoadonViewModel();

            //using Dapper
            using (var conn = new SqlConnection(this._db.Database.GetDbConnection().ConnectionString))
            {
                conn.Open();
                pttt = conn.Query <HoadonViewModel>(@"select top 1 * from HoaDon where Ptthanhtoan = N'Tiền mặt' 
                                                        or Ptthanhtoan = N'Thanh toán online' 
                                                        or Ptthanhtoan = N'Chuyển khoản'
                                                        order by ID desc").FirstOrDefault();
                conn.Close();
            }
            return(pttt);
        }
        //đặt tour tự chọn
        public void DatTourTuChon(TourTuChonValidation validation)
        {
            var ks = _db.KhachSans.FirstOrDefault(n => n.ID == validation.ID);
            var kh = _db.Khachhangs.FirstOrDefault(k => k.Cmnd == validation.Cmnd);

            if (kh == null)
            {
                KhachhangViewModel khs = new KhachhangViewModel
                {
                    Hoten  = validation.Hoten,
                    Cmnd   = validation.Cmnd,
                    Diachi = validation.Diachi,
                    Sdt    = validation.Sdt,
                    Email  = validation.Email
                };
                var newKH = new Khachhang(khs);
                _db.Khachhangs.Add(newKH);
                _db.SaveChanges();
                HoadonViewModel hd = new HoadonViewModel
                {
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = "Thanh toán online",
                    Tongtien    = validation.Tongtien,
                    Tinhtrang   = 0,
                    KhachhangID = newKH.ID
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();
                CTHoadonTuChonViewModel cthd = new CTHoadonTuChonViewModel()
                {
                    Ngaynhan     = validation.Ngaynhan,
                    Ngaytra      = validation.Ngaytra,
                    Sophong      = validation.Sophong,
                    Sogiuongthem = validation.Sogiuongthem,
                    Sotreem      = validation.Sotreem,
                    Hoten        = validation.Hoten,
                    Sdt          = validation.Sdt,
                    Email        = validation.Email,
                    Ghichu       = validation.Ghichu,
                    Hoadoncode   = RandomString(),
                    KhachsanID   = ks.ID,
                    HoadonID     = newHD.ID
                };
                var newCTHD = new CTHoadonTuChon(cthd);
                _db.CTHoadonTuChons.Add(newCTHD);
                _db.SaveChanges();

                //send mail
                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingtourtuchon.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{hoadoncode}}", cthd.Hoadoncode);
                body = body.Replace("{{ngaylaphd}}", hd.Ngaylaphd.ToShortDateString());
                body = body.Replace("{{hoten}}", validation.Hoten);
                body = body.Replace("{{email}}", validation.Email);
                body = body.Replace("{{sogiuongthem}}", validation.Sogiuongthem.ToString());
                body = body.Replace("{{sdt}}", validation.Sdt);
                body = body.Replace("{{tinhtrang}}", "chưa thanh toán");
                body = body.Replace("{{ghichu}}", validation.Ghichu);
                body = body.Replace("{{tenks}}", ks.Tenks);
                body = body.Replace("{{diachi}}", ks.Diachi);
                body = body.Replace("{{ngaynhanphong}}", validation.Ngaynhan.ToShortDateString());
                body = body.Replace("{{ngaytraphong}}", validation.Ngaytra.ToShortDateString());
                body = body.Replace("{{loaiphong}}", ks.Loaiphong);
                body = body.Replace("{{sophong}}", validation.Sophong.ToString());
                body = body.Replace("{{gia}}", ks.Gia.ToString());
                body = body.Replace("{{giaphuthu}}", ks.Giaphuthu.ToString());
                body = body.Replace("{{sotreem}}", validation.Sotreem.ToString());
                body = body.Replace("{{giatreem}}", ks.Giatreem.ToString());
                body = body.Replace("{{tongtien}}", validation.Tongtien.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour tự chọn", body);
            }
            else
            {
                HoadonViewModel hd = new HoadonViewModel
                {
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = "Thanh toán online",
                    Tongtien    = validation.Tongtien,
                    Tinhtrang   = 0,
                    KhachhangID = kh.ID
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();
                CTHoadonTuChonViewModel cthd = new CTHoadonTuChonViewModel()
                {
                    Ngaynhan     = validation.Ngaynhan,
                    Ngaytra      = validation.Ngaytra,
                    Sophong      = validation.Sophong,
                    Sogiuongthem = validation.Sogiuongthem,
                    Sotreem      = validation.Sotreem,
                    Hoten        = validation.Hoten,
                    Sdt          = validation.Sdt,
                    Email        = validation.Email,
                    Ghichu       = validation.Ghichu,
                    Hoadoncode   = RandomString(),
                    KhachsanID   = ks.ID,
                    HoadonID     = newHD.ID
                };
                var newCTHD = new CTHoadonTuChon(cthd);
                _db.CTHoadonTuChons.Add(newCTHD);
                _db.SaveChanges();

                //send mail
                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingtourtuchon.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{hoadoncode}}", cthd.Hoadoncode);
                body = body.Replace("{{ngaylaphd}}", hd.Ngaylaphd.ToShortDateString());
                body = body.Replace("{{hoten}}", validation.Hoten);
                body = body.Replace("{{email}}", validation.Email);
                body = body.Replace("{{sogiuongthem}}", validation.Sogiuongthem.ToString());
                body = body.Replace("{{sdt}}", validation.Sdt);
                body = body.Replace("{{tinhtrang}}", "chưa thanh toán");
                body = body.Replace("{{ghichu}}", validation.Ghichu);
                body = body.Replace("{{tenks}}", ks.Tenks);
                body = body.Replace("{{diachi}}", ks.Diachi);
                body = body.Replace("{{ngaynhanphong}}", validation.Ngaynhan.ToShortDateString());
                body = body.Replace("{{ngaytraphong}}", validation.Ngaytra.ToShortDateString());
                body = body.Replace("{{loaiphong}}", ks.Loaiphong);
                body = body.Replace("{{sophong}}", validation.Sophong.ToString());
                body = body.Replace("{{gia}}", ks.Gia.ToString());
                body = body.Replace("{{giaphuthu}}", ks.Giaphuthu.ToString());
                body = body.Replace("{{sotreem}}", validation.Sotreem.ToString());
                body = body.Replace("{{giatreem}}", ks.Giatreem.ToString());
                body = body.Replace("{{tongtien}}", validation.Tongtien.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour tự chọn", body);
            }
        }
        public void DatTourMienTrung(DatTourValidation validation)
        {
            var tour = _db.Tours.FirstOrDefault(n => n.ID == validation.TourID);
            var kh   = _db.Khachhangs.FirstOrDefault(n => n.Cmnd == validation.Cmnd);

            if (kh == null)
            {
                var newKH = new Khachhang(validation);
                _db.Khachhangs.Add(newKH);
                _db.SaveChanges();

                //thêm thông tin tour miền Trung
                //thêm hóa đơn

                HoadonViewModel hd = new HoadonViewModel
                {
                    KhachhangID = newKH.ID,
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = validation.Ptthanhtoan,
                    Tongtien    = validation.Tongtien,
                    Ghichu      = validation.Ghichu
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();

                if (tour.Songuoi > 1)
                {
                    tour.Songuoi = tour.Songuoi - validation.Songuoidi;
                    _db.SaveChanges();
                }
                else
                {
                    tour.Songuoi   = tour.Songuoi - validation.Songuoidi;
                    tour.Trangthai = "hết chỗ";
                    _db.SaveChanges();
                }

                //thêm chi tiết hóa đơn

                CTHoadonTrungViewModel cthd = new CTHoadonTrungViewModel
                {
                    Hotenkhachhang = newKH.Hoten,
                    Sdt            = newKH.Sdt,
                    Email          = newKH.Email,
                    Hoadoncode     = RandomString(),
                    Songuoidi      = validation.Songuoidi,
                    HoadonID       = newHD.ID,
                    TourID         = tour.ID
                };
                var newCTHD = new CTHoadonTrung(cthd);
                _db.CTHoadonTrungs.Add(newCTHD);
                _db.SaveChanges();

                //send mail

                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingdetail.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{TourName}}", tour.Tentour);
                body = body.Replace("{{Code}}", tour.Code);
                body = body.Replace("{{Noixuatphat}}", tour.Diadiemkhoihanh);
                body = body.Replace("{{Diemden}}", tour.Diemden);
                body = body.Replace("{{Ngaydi}}", tour.Ngaydi.ToString());
                //body = body.Replace("{{Ngayve}}", tour.Ngayve.ToString());
                body = body.Replace("{{Sobooking}}", cthd.Hoadoncode);
                body = body.Replace("{{Tongtien}}", hd.Tongtien.ToString());
                body = body.Replace("{{Ngaydangky}}", hd.Ngaylaphd.ToString());
                body = body.Replace("{{Hinhthucthanhtoan}}", hd.Ptthanhtoan);
                body = body.Replace("{{Thoihanthanhtoan}}", "Vui lòng thanh toán trước khi tour khởi hành 3 ngày");
                body = body.Replace("{{Hoten}}", validation.Hoten);
                body = body.Replace("{{Diachi}}", validation.Diachi);
                body = body.Replace("{{Sdt}}", validation.Sdt);
                body = body.Replace("{{Email}}", validation.Email);
                body = body.Replace("{{Songuoidi}}", validation.Songuoidi.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour", body);
            }
            else
            {
                //thêm thông tin tour miền Trung
                //thêm hóa đơn

                HoadonViewModel hd = new HoadonViewModel
                {
                    KhachhangID = kh.ID,
                    Ngaylaphd   = DateTime.Now,
                    Ptthanhtoan = validation.Ptthanhtoan,
                    Tongtien    = validation.Tongtien,
                    Ghichu      = validation.Ghichu
                };
                var newHD = new Hoadon(hd);
                _db.Hoadons.Add(newHD);
                _db.SaveChanges();

                if (tour.Songuoi > 1)
                {
                    tour.Songuoi = tour.Songuoi - validation.Songuoidi;
                    _db.SaveChanges();
                }
                else
                {
                    tour.Songuoi   = tour.Songuoi - validation.Songuoidi;
                    tour.Trangthai = "hết chỗ";
                    _db.SaveChanges();
                }

                //thêm chi tiết hóa đơn

                CTHoadonTrungViewModel cthd = new CTHoadonTrungViewModel();
                cthd.Hotenkhachhang = kh.Hoten;
                cthd.Sdt            = kh.Sdt;
                cthd.Email          = kh.Email;
                cthd.Hoadoncode     = RandomString();
                cthd.Songuoidi      = validation.Songuoidi;
                cthd.HoadonID       = newHD.ID;
                cthd.TourID         = tour.ID;
                var newCTHD = new CTHoadonTrung(cthd);
                _db.CTHoadonTrungs.Add(newCTHD);
                _db.SaveChanges();

                //send mail

                var webRoot    = _hostingEnvironment.WebRootPath;
                var body       = string.Empty;
                var pathToFile = _hostingEnvironment.WebRootPath
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "templates"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "email"
                                 + Path.DirectorySeparatorChar.ToString()
                                 + "bookingdetail.html";
                using (StreamReader reader = new StreamReader(pathToFile))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{{TourName}}", tour.Tentour);
                body = body.Replace("{{Code}}", tour.Code);
                body = body.Replace("{{Noixuatphat}}", tour.Diadiemkhoihanh);
                body = body.Replace("{{Diemden}}", tour.Diemden);
                body = body.Replace("{{Ngaydi}}", tour.Ngaydi.ToString());
                //body = body.Replace("{{Ngayve}}", tour.Ngayve.ToString());
                body = body.Replace("{{Sobooking}}", cthd.Hoadoncode);
                body = body.Replace("{{Tongtien}}", hd.Tongtien.ToString());
                body = body.Replace("{{Ngaydangky}}", hd.Ngaylaphd.ToString());
                body = body.Replace("{{Hinhthucthanhtoan}}", hd.Ptthanhtoan);
                //int day = hd.Ngaylaphd.Date + 7;
                body = body.Replace("{{Thoihanthanhtoan}}", "N/A");
                body = body.Replace("{{Hoten}}", validation.Hoten);
                body = body.Replace("{{Diachi}}", validation.Diachi);
                body = body.Replace("{{Sdt}}", validation.Sdt);
                body = body.Replace("{{Email}}", validation.Email);
                body = body.Replace("{{Songuoidi}}", validation.Songuoidi.ToString());
                var mailHelper = new MailHelpers();
                mailHelper.SendMail(validation.Email, "Thông tin booking tour", body);
            }
        }
Beispiel #7
0
        public void Update(HoadonViewModel hoadonVm)
        {
            var sp = Mapper.Map <HoadonViewModel, Hoadon>(hoadonVm);

            _repository.Update(sp);
        }
Beispiel #8
0
        public JsonResult SaveAllEntity(HoadonViewModel Information, List <CtGiohangViewModel> Products)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                    return(Json(allErrors, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    #region Add new invoice
                    //Current Customer
                    var kh = UserLoginViewModel.Current;
                    //Get all ncc distinct
                    List <int> ncc = new List <int>();
                    List <SanphamViewModel> spVm = new List <SanphamViewModel>();
                    foreach (var item in Products)
                    {
                        var sp = _sanphamService.GetById(item.masp);
                        spVm.Add(sp);
                        if (ncc.FirstOrDefault(x => x == sp.NccNavigation.User_FK) == 0)
                        {
                            ncc.Add(sp.NccNavigation.User_FK);
                        }
                    }
                    List <HoadonViewModel> hdVm = new List <HoadonViewModel>();
                    //Create Invoice foreach ncc
                    foreach (var i in ncc)
                    {
                        //var accountNcc = _userService.GetUser(i);
                        HoadonViewModel hd = new HoadonViewModel();
                        hd.KeyId     = 0;
                        hd.mahd      = 0;
                        hd.makh      = kh.KeyId;
                        hd.ncc_FK    = i;
                        hd.tongtien  = 0;
                        hd.thoigian  = DateTime.Now.ToShortDateString();
                        hd.tinhtrang = "Chờ xác nhận";
                        hd.Name      = Information.Name;
                        hd.Phone     = Information.Phone;
                        hd.Address   = Information.Address;
                        hd.Note      = Information.Note;
                        hd.Cthdons   = new HashSet <CthdViewModel>();
                        foreach (var item in Products)
                        {
                            var pro = spVm.FirstOrDefault(x => x.KeyId == item.masp);
                            if (pro.NccNavigation.User_FK == i)
                            {
                                CthdViewModel cthd = new CthdViewModel();
                                cthd.mahd      = 0;
                                cthd.masp      = pro.KeyId;
                                cthd.soluong   = item.soluong;
                                cthd.thanhtien = pro.dongia * (double)item.soluong;
                                hd.Cthdons.Add(cthd);
                                hd.tongtien += cthd.thanhtien;
                                //Products.Remove(item);

                                //Update Number of Product
                                pro.conlai -= cthd.soluong;
                                if (pro.conlai < 1)
                                {
                                    pro.Status = Data.Enum.ProductStatus.Sold;
                                }
                                _sanphamService.Update(pro);
                            }
                        }
                        hdVm.Add(_hoadonService.Add(hd));
                    }
                    #endregion

                    #region Clear cart
                    var        Customer = _userService.GetUser(kh.KeyId);
                    List <int> cart     = new List <int>();

                    foreach (var i in Customer.KhachhangNavigation.CtGiohangs)
                    {
                        cart.Add(i.KeyId);
                    }
                    foreach (var cartItem in cart)
                    {
                        _ctGiohangService.Delete(cartItem);
                    }
                    #endregion


                    if (_hoadonService.Save())
                    {
                        return(Json(new { Result = hdVm, Status = "OK" }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new { Result = "Đã có lỗi xảy ra khi đặt hàng!", Status = "FAIL" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Result = ex.Message, Status = "FAIL" }, JsonRequestBehavior.AllowGet));
            }
        }