Exemplo n.º 1
0
        public static PhoiVeModel toModel(this PhoiVe e)
        {
            PhoiVeModel m = new PhoiVeModel();

            m.Id          = e.Id;
            m.NguonVeXeId = e.NguonVeXeId;
            //neu co nguon ve xe con, tuc la khach hang dang chon tuyen con de dat ve
            //chuyen doi thong tin gia ve gia ve cua tuyen con
            m.GiaVe     = e.GiaVeHienTai;
            m.GiaVeText = e.GiaVeHienTai.ToSoNguyen();
            m.NgayDi    = e.NgayDi;
            var nguonve = e.getNguonVeXe();

            m.TenHanhTrinh      = string.Format(" {0}- {1}", nguonve.TenDiemDon, nguonve.TenDiemDen);
            m.TenLichTrinh      = string.Format("{0} - {1}", nguonve.ThoiGianDi.ToString("HH:mm"), nguonve.ThoiGianDen.ToString("HH:mm"));
            m.TrangThaiId       = e.TrangThaiId;
            m.CustomerId        = e.CustomerId;
            m.SoDoGheXeQuyTacId = e.SoDoGheXeQuyTacId;
            m.KyHieuGhe         = e.sodoghexequytac.Val;
            m.Tang         = e.sodoghexequytac.Tang;
            m.isChonVe     = e.isChonVe;
            m.NgayTao      = e.NgayTao;
            m.NgayUpd      = e.NgayUpd;
            m.SessionId    = e.SessionId;
            m.ViTriLenXe   = e.ViTriLenXe;
            m.ViTriXuongXe = e.ViTriXuongXe;
            m.GhiChu       = e.GhiChu;
            return(m);
        }
Exemplo n.º 2
0
        public ActionResult KiemTraChoNgoi(int NguonVeXeId, int ParentId, long NgayDi, string KyHieuGhe, string Tang)
        {
            // This action method gets called via an ajax request
            if (String.IsNullOrEmpty(KyHieuGhe) || String.IsNullOrEmpty(Tang))
            {
                throw new ArgumentNullException("KiemTraChoNgoi");
            }
            if (Session["DAT_MUA_VE_XE_ID"] == null)
            {
                return(Loi());
            }
            var item = new PhoiVe();

            item.NguonVeXeId = NguonVeXeId;
            //neu la ve con, thi lay ve cha lam phieu dat ve
            if (ParentId > 0)
            {
                item.NguonVeXeId    = ParentId;
                item.NguonVeXeConId = NguonVeXeId;
            }

            item.NgayDi = new DateTime(NgayDi);
            var nguonvexe = _vexeService.GetNguonVeXeById(item.NguonVeXeId.GetValueOrDefault(0));

            item.SoDoGheXeQuyTacId = _vexeService.GetSoDoGheXeQuyTacID(nguonvexe.LoaiXeId, KyHieuGhe, Convert.ToInt32(Tang));
            if (item.SoDoGheXeQuyTacId > 0)
            {
                item.TrangThai    = ENTrangThaiPhoiVe.DatCho;
                item.isChonVe     = true; //giao dich nay cua chonve.vn
                item.CustomerId   = _workContext.CurrentCustomer.Id;
                item.SessionId    = Session["DAT_MUA_VE_XE_ID"].ToString();
                item.GiaVeHienTai = nguonvexe.GiaVeHienTai;
                if (_phoiveService.DatVe(item))
                {
                    var model = nguonvexe.ToModel(_priceFormatter);
                    model.phoives = _phoiveService.GetPhoiVeDatChoBySession(Session["DAT_MUA_VE_XE_ID"]);
                    bool kq       = _phoiveService.GetPhoiVeByNguonVe(item.NguonVeXeId.GetValueOrDefault(0), item.SessionId, item.CustomerId, item.NgayDi);
                    var  nguonves = new List <NguonVeXeModel>();
                    if (kq)
                    {
                        foreach (var pv in model.phoives)
                        {
                            var result = new NguonVeXeModel();
                            if (string.IsNullOrEmpty(result.KyHieuGhe))
                            {
                                result.KyHieuGhe = pv.sodoghexequytac.Val;
                            }
                            else
                            {
                                result.KyHieuGhe += "," + pv.sodoghexequytac.Val;
                            }
                            result.TongTien += pv.GiaVeHienTai;
                            nguonves.Add(result);
                        }
                    }
                    return(Json(nguonves.ToList(), JsonRequestBehavior.AllowGet));
                }
            }
            return(Json("ERROR", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Su dung trong truong hop nha xe ko quan tam toi so do, so tien tuy bien
        /// </summary>
        /// <param name="NhaXeId"></param>
        /// <param name="CustomerId"></param>
        /// <param name="XeXuatBenId"></param>
        /// <param name="HanhTrinhGiaVeId"></param>
        /// <param name="DiemLen"></param>
        /// <param name="apiToken"></param>
        /// <returns></returns>
        public ActionResult LenXeV2(int NhaXeId, int CustomerId, int XeXuatBenId, int HanhTrinhGiaVeId, int GiaTien, string DiemLen, string apiToken)
        {
            //kiem tra xac thuc
            string _checkauthentication = isAuthentication(NhaXeId, CustomerId, apiToken, XeXuatBenId);

            if (!String.IsNullOrEmpty(_checkauthentication))
            {
                return(ErrorOccured(_checkauthentication));
            }
            //kiem tra trang thai xe xuat ben
            if (xexuatben.TrangThai == ENTrangThaiXeXuatBen.KET_THUC)
            {
                return(ErrorOccured("Chuyến đi đã kết thúc"));
            }
            var giave = _hanhtrinhService.GetHanhTrinhGiaVeId(HanhTrinhGiaVeId);

            if (giave == null)
            {
                return(ErrorOccured("Dữ liệu không hợp lệ"));
            }
            var hanhtrinh = _hanhtrinhService.GetHanhTrinhById(giave.HanhTrinhId);
            var phoive    = new PhoiVe();

            phoive.NguonVeXeId = xexuatben.NguonVeId;
            phoive.NgayDi      = xexuatben.NgayDi;
            phoive.TrangThai   = ENTrangThaiPhoiVe.ConTrong;

            phoive.GiaVeHienTai = Convert.ToDecimal(GiaTien);
            phoive.ChangId      = HanhTrinhGiaVeId;
            phoive.ViTriLenXe   = DiemLen;
            phoive.ViTriXuongXe = giave.DiemDen.TenDiemDon;

            phoive.NguoiDatVeId = currentNhanVien.Id;
            phoive.CustomerId   = CommonHelper.KhachVangLaiId;//khach vang lai


            if (_phoiveService.DatVe(phoive, ENTrangThaiPhoiVe.DaGiaoHang))
            {
                var datveinfo = new
                {
                    Id               = phoive.Id,
                    MaVe             = phoive.MaVe,
                    VeXeItemId       = phoive.VeXeItemId,
                    HanhTrinhGiaVeId = phoive.ChangId
                };
                return(Successful(datveinfo));
            }
            return(ErrorOccured("Không đặt được ở vị trí này"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Print an order to PDF
        /// </summary>
        /// <param name="order">Order</param>
        /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param>
        /// <returns>A path of generates file</returns>
        public virtual string PrintOrderToPdf(PhoiVe _phoive, int languageId)
        {
            if (_phoive == null)
            {
                throw new ArgumentNullException("order");
            }
            var    order    = _orderService.GetOrderById(_phoive.OrderId);
            string fileName = string.Format("Ve{0}_{1}.pdf", order.OrderGuid, CommonHelper.GenerateRandomDigitCode(4));
            string filePath = Path.Combine(_webHelper.MapPath("~/content/files/ExportImport"), fileName);

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                PrintOrdersToPdf(fileStream, _phoive, languageId);
            }
            return(filePath);
        }
Exemplo n.º 5
0
        public ActionResult DatVeSoLuong(int HanhTrinhGiaVeId, string soLuong, string NgayDi)
        {
            if (this.CheckNoAccessIntoNhaXe(_workContext, _permissionService, StandardPermissionProvider.CVHoatDongBanVe))
            {
                return(AccessDeniedView());
            }

            var hanhtrinhgiave = _hanhtrinhService.GetHanhTrinhGiaVeId(HanhTrinhGiaVeId);

            var isluotdi = false;

            if (hanhtrinhgiave.HanhTrinhId > 0)
            {
                isluotdi = hanhtrinhgiave.HanhTrinh.isTuyenDi;
            }
            var _sl = Convert.ToInt32(soLuong);

            for (int i = 0; i < _sl; i++)
            {
                var item = new PhoiVe();
                item.HanhTrinhGiaVeId = HanhTrinhGiaVeId;
                item.NgayDi           = Convert.ToDateTime(NgayDi);
                item.TrangThaiId      = (int)ENTrangThaiPhoiVe.DaGiaoHang;
                item.isChonVe         = false;
                item.NguoiDatVeId     = _workContext.CurrentNhanVien.Id;
                item.GiaVeHienTai     = hanhtrinhgiave.GiaVe;
                item.NgayTao          = DateTime.Now;
                item.NgayUpd          = DateTime.Now;
                _phoiveService.ThanhToanVeTaiQuay(item);
                var vexeitems = _giaodichkeveService.BanVeTaiQuay(_workContext.NhaXeId, _workContext.CurrentNhanVien.Id, HanhTrinhGiaVeId, hanhtrinhgiave.GiaVe, isluotdi, item.NgayDi, _workContext.CurrentVanPhong.Id);
                if (vexeitems != null)
                {
                    item.VeXeItemId = vexeitems.Id;
                    item.MaVe       = vexeitems.SoSeri;
                    _phoiveService.UpdatePhoiVe(item);
                }
            }


            return(ThanhCong());
        }
Exemplo n.º 6
0
 void PhoiVeToModel(PhoiVe e, PhoiVeModel m)
 {
     m.Id          = e.Id;
     m.NguonVeXeId = e.NguonVeXeId;
     //neu co nguon ve xe con, tuc la khach hang dang chon tuyen con de dat ve
     //chuyen doi thong tin gia ve gia ve cua tuyen con
     m.GiaVe = e.getNguonVeXe().ProductInfo.Price;
     if (e.NguonVeXeConId > 0)
     {
         var nguonvecon = _vexeService.GetNguonVeXeById(e.NguonVeXeConId.GetValueOrDefault(0));
         m.GiaVe = nguonvecon.ProductInfo.Price;
     }
     m.GiaVeText         = _priceFormatter.FormatPrice(m.GiaVe, true, false);
     m.NgayDi            = e.NgayDi;
     m.TrangThaiId       = e.TrangThaiId;
     m.CustomerId        = e.CustomerId;
     m.SoDoGheXeQuyTacId = e.SoDoGheXeQuyTacId.GetValueOrDefault(0);
     m.KyHieuGhe         = e.sodoghexequytac.Val;
     m.Tang      = e.sodoghexequytac.Tang;
     m.isChonVe  = e.isChonVe;
     m.NgayTao   = e.NgayTao;
     m.NgayUpd   = e.NgayUpd;
     m.SessionId = e.SessionId;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Print orders to PDF
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <param name="orders">Orders</param>
        /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param>
        public virtual void PrintOrdersToPdf(Stream stream, PhoiVe _phoive, int languageId = 0)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (_phoive == null)
            {
                throw new ArgumentNullException("Không có vé");
            }
            //get thong tin nguon ve
            var order = _orderService.GetOrderById(_phoive.OrderId);

            if (order == null)
            {
                throw new ArgumentNullException("Không có đơn hàng");
            }
            var nguonvexe = _hanhtrinhService.GetNguonVeXeById(_phoive.NguonVeXeId);

            if (nguonvexe.ParentId > 0)
            {
                nguonvexe = _hanhtrinhService.GetNguonVeXeById(_phoive.NguonVeXeConId);
            }
            //get thong tin nha xe
            var nhaxe = _nhaxeService.GetNhaXeById(nguonvexe.NhaXeId);

            var diachi = _diachiService.GetById(nhaxe.DiaChiID);
            //get thong tin xe xuan ben
            var xexuatbenInfo = _nhaxeService.GetHistoryXeXuatBenByNguonVeId(nguonvexe.Id, _phoive.NgayDi);
            var TenXe         = "";
            var BienSo        = "";

            if (xexuatbenInfo != null)
            {
                var xeInfo = _xeinfoService.GetXeInfoById(xexuatbenInfo.XeVanChuyenId.GetValueOrDefault(0));
                TenXe  = xeInfo.TenXe;
                BienSo = xeInfo.BienSo;
            }


            //logo
            var logoPicture = _pictureService.GetPictureById(nhaxe.LogoID);
            var logoExists  = logoPicture != null;
            var doc         = new Document();
            var pdfWriter   = PdfWriter.GetInstance(doc, stream);

            doc.Open();
            //fonts
            var titleFont = GetFont();

            titleFont.Size = BaseFont.SUPERSCRIPT_SIZE;
            //font ten nha xe
            var TenNhaXe = GetFont();

            TenNhaXe.SetStyle("initial");

            //font thong tin
            var InfoFont = GetFont();

            InfoFont.Size = 14;
            var font = GetFont();

            font.Size = 13;

            var pdfSettingsByStore = _settingContext.LoadSetting <PdfSettings>(order.StoreId);
            var lang = _workContext.WorkingLanguage;

            //header
            float[] widths     = { 3, 7 };
            var     HeaderVeIn = new PdfPTable(widths);

            HeaderVeIn.DefaultCell.Border = Rectangle.NO_BORDER;

            if (logoExists)
            {
                var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false);
                var logo         = Image.GetInstance(logoFilePath);
                logo.ScaleToFit(200, 100);

                PdfPCell CellLeft = new PdfPCell(logo);
                CellLeft.Border      = Rectangle.NO_BORDER;
                CellLeft.FixedHeight = 80f;
                HeaderVeIn.AddCell(CellLeft);
            }
            PdfPCell CellRight = new PdfPCell();

            CellRight.Border = Rectangle.NO_BORDER;
            var ParaTenNhaXe = new Paragraph(string.Format(_localizationService.GetResource("PDFInvoice.TenNhaXe", lang.Id),
                                                           nhaxe.TenNhaXe), font);

            ParaTenNhaXe.Alignment = Element.ALIGN_RIGHT;
            CellRight.AddElement(ParaTenNhaXe);
            var ParaDiaChi = new Paragraph(string.Format(_localizationService.GetResource("PDFInvoice.DiaChiNhXe", lang.Id),
                                                         diachi.DiaChi1 + " " + diachi.DiaChi2), font);

            ParaDiaChi.Alignment = Element.ALIGN_RIGHT;
            CellRight.AddElement(ParaDiaChi);
            var ParaSdt = new Paragraph(string.Format(_localizationService.GetResource("PDFInvoice.SDTNhaXe", lang.Id),
                                                      nhaxe.DienThoai), font);

            ParaSdt.Alignment = Element.ALIGN_RIGHT;
            CellRight.AddElement(ParaSdt);
            HeaderVeIn.AddCell(CellRight);
            doc.Add(HeaderVeIn);
            doc.Add(new Paragraph(""));
            doc.Add(new Paragraph(""));
            //add line
            var line = new iTextSharp.text.pdf.draw.LineSeparator(0, 100, BaseColor.GRAY, Element.ALIGN_CENTER, 1);

            doc.Add(new Chunk(line));
            //content
            Paragraph vexekhach = new Paragraph(_localizationService.GetResource("PDFInvoice.VeXeKhach", lang.Id), titleFont);

            vexekhach.Alignment = Element.ALIGN_CENTER;
            doc.Add(vexekhach);
            doc.Add(new Paragraph(""));
            doc.Add(new Paragraph(""));
            var Table1 = new PdfPTable(2);

            float[] widthTable1 = new float[] { 1f, 2f };
            Table1.SetWidths(widthTable1);
            Table1.RunDirection       = GetDirection(lang);
            Table1.DefaultCell.Border = Rectangle.NO_BORDER;
            Table1.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.Tuyen", lang.Id), font));
            Table1.AddCell(new Paragraph(nguonvexe.TenDiemDon + " -- " + nguonvexe.TenDiemDen, InfoFont));
            Table1.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.GiaVe", lang.Id), font));
            Table1.AddCell(new Paragraph(nguonvexe.LichTrinhInfo.GiaVeToanTuyen.ToString() + " VNĐ", InfoFont));
            doc.Add(Table1);
            //add ghe,xe
            var Table2 = new PdfPTable(4);

            float[] widthTable2 = new float[] { 1f, 2f, 1f, 2f };
            Table2.SetWidths(widthTable2);
            Table2.RunDirection       = GetDirection(lang);
            Table2.DefaultCell.Border = Rectangle.NO_BORDER;
            Table2.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.SoXe", lang.Id), font));
            Table2.AddCell(new Paragraph(TenXe + "/" + BienSo, InfoFont));
            Table2.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.SoGhe", lang.Id), font));
            Table2.AddCell(new Paragraph(_phoive.sodoghexequytac.Val + " ( Tầng" + _phoive.sodoghexequytac.Tang + ")", InfoFont));
            doc.Add(Table2);
            //add thoi gian khoi hanh
            var Table3 = new PdfPTable(4);

            float[] widthTable3 = new float[] { 2f, 1f, 1f, 2f };
            Table3.SetWidths(widthTable3);
            Table3.RunDirection       = GetDirection(lang);
            Table3.DefaultCell.Border = Rectangle.NO_BORDER;
            Table3.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.ThoiGianDi", lang.Id), font));
            Table3.AddCell(new Paragraph(nguonvexe.ThoiGianDi.ToString("HH:mm"), InfoFont));
            Table3.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.NgayDi", lang.Id), font));
            Table3.AddCell(new Paragraph(_phoive.NgayDi.ToString("dd/MM/yyyy"), InfoFont));
            doc.Add(Table3);
            //add footer
            var FooterNgayBan = new Paragraph("Ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year, font);

            FooterNgayBan.Alignment = Element.ALIGN_RIGHT;
            var FooterNguoiBanTitle = new Paragraph("Người bán vé", font);

            FooterNguoiBanTitle.Alignment = Element.ALIGN_RIGHT;
            var firtname          = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName);
            var lastname          = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.LastName);
            var FooterTenNguoiBan = new Paragraph(firtname + " " + lastname, font);

            FooterTenNguoiBan.Alignment = Element.ALIGN_RIGHT;
            var Table4 = new PdfPTable(1);

            Table4.DefaultCell.Border = Rectangle.NO_BORDER;
            PdfPCell CellFooter = new PdfPCell();

            CellFooter.Border = Rectangle.NO_BORDER;
            CellFooter.AddElement(FooterNgayBan);
            CellFooter.AddElement(FooterNguoiBanTitle);
            CellFooter.AddElement(FooterTenNguoiBan);
            Table4.AddCell(CellFooter);
            doc.Add(Table4);
            doc.Add(new Paragraph(" "));
            doc.NewPage();
            doc.Close();
        }
Exemplo n.º 8
0
        public ActionResult LenXeV1(int NhaXeId, int CustomerId, int XeXuatBenId, int SoDoGheXeQuyTacId, int HanhTrinhGiaVeId, string SoSeri, string DiemLen, string apiToken)
        {
            //kiem tra xac thuc
            string _checkauthentication = isAuthentication(NhaXeId, CustomerId, apiToken, XeXuatBenId);

            if (!String.IsNullOrEmpty(_checkauthentication))
            {
                return(ErrorOccured(_checkauthentication));
            }
            //kiem tra trang thai xe xuat ben
            if (xexuatben.TrangThai == ENTrangThaiXeXuatBen.KET_THUC)
            {
                return(ErrorOccured("Chuyến đi đã kết thúc"));
            }
            var giave = _hanhtrinhService.GetHanhTrinhGiaVeId(HanhTrinhGiaVeId);

            if (giave == null)
            {
                return(ErrorOccured("Dữ liệu không hợp lệ"));
            }
            var hanhtrinh = _hanhtrinhService.GetHanhTrinhById(giave.HanhTrinhId);
            var phoive    = new PhoiVe();

            if (SoDoGheXeQuyTacId > 0)
            {
                var sodo = _xeinfoService.GetSoDoGheXeQuyTacById(SoDoGheXeQuyTacId);
                if (sodo == null)
                {
                    return(ErrorOccured("Dữ liệu không hợp lệ"));
                }
                phoive = _phoiveService.GetPhoiVe(xexuatben.NguonVeId, sodo, xexuatben.NgayDi, true);
            }
            else
            {
                phoive.NguonVeXeId = xexuatben.NguonVeId;
                phoive.NgayDi      = xexuatben.NgayDi;
                phoive.TrangThai   = ENTrangThaiPhoiVe.ConTrong;
            }
            phoive.GiaVeHienTai = giave.GiaVe;
            phoive.ChangId      = HanhTrinhGiaVeId;
            phoive.ViTriLenXe   = DiemLen;
            phoive.ViTriXuongXe = giave.DiemDen.TenDiemDon;


            phoive.NguoiDatVeId = currentNhanVien.Id;
            phoive.CustomerId   = CommonHelper.KhachVangLaiId;//khach vang lai
            phoive.ChuyenDiId   = XeXuatBenId;
            if (!string.IsNullOrEmpty(SoSeri))
            {
                //su dung ve da ban o quay de len xe
                var vexeitemsold = _giaodichkeveService.SuDungVe(NhaXeId, xexuatben.NguonVeId, SoSeri, true);
                if (vexeitemsold != null)
                {
                    phoive.MaVe       = vexeitemsold.SoSeri;
                    phoive.VeXeItemId = vexeitemsold.Id;
                    phoive.ChangId    = vexeitemsold.ChangId.GetValueOrDefault(0);
                }
                else
                {
                    return(ErrorOccured("Seri vé không hợp lệ"));
                }
            }
            else
            {
                //lay thong tin ve xe item theo menh gia, va thuc hien ban ve
                var vexeitemsold = _giaodichkeveService.BanVe(NhaXeId, currentNhanVien.Id, XeXuatBenId, xexuatben.NguonVeId, HanhTrinhGiaVeId, giave.GiaVe, true);
                if (vexeitemsold != null)
                {
                    phoive.MaVe       = vexeitemsold.SoSeri;
                    phoive.VeXeItemId = vexeitemsold.Id;
                    phoive.ChangId    = HanhTrinhGiaVeId;
                }
                else
                {
                    return(ErrorOccured("Hết vé"));
                }
            }


            if (_phoiveService.DatVe(phoive, ENTrangThaiPhoiVe.DaGiaoHang))
            {
                var datveinfo = new
                {
                    Id               = phoive.Id,
                    MaVe             = phoive.MaVe,
                    VeXeItemId       = phoive.VeXeItemId,
                    HanhTrinhGiaVeId = phoive.ChangId
                };
                return(Successful(datveinfo));
            }
            return(ErrorOccured("Không đặt được ở vị trí này"));
        }