482 lines
19 KiB
VB.net
482 lines
19 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
Imports System.Data
|
|
Imports ADSNetLibrary.Helpers
|
|
Imports Extensiones
|
|
Imports Extensiones.ModExtensiones
|
|
Partial Class Boletos
|
|
Inherits ClsPaginas
|
|
#Region "Propiedades"
|
|
Private Property AsientoSeleccionado As String
|
|
Get
|
|
Return ViewState("AsientoSeleccionado").ToString()
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("AsientoSeleccionado") = value
|
|
End Set
|
|
End Property
|
|
Private Property Importe As Decimal
|
|
Get
|
|
Return If(IsNothing(ViewState("Importe")), 0, ViewState("Importe")).ToString().ToDecimal()
|
|
End Get
|
|
Set(value As Decimal)
|
|
ViewState("Importe") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveViaje As Integer
|
|
Get
|
|
Return ViewState("CveViaje").ToString().ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveViaje") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property Contrato As DataTable
|
|
Get
|
|
Return CType(ViewState("Contrato"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("Contrato") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtDestinos As DataTable
|
|
Get
|
|
Return CType(ViewState("DtDestinos"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtDestinos") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtPasajeros As DataTable
|
|
Get
|
|
Return CType(ViewState("DtPasajeros"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtPasajeros") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
#End Region
|
|
#Region "Carga Página"
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
If Request.QueryString("CveViaje") Is Nothing And UsuarioActual.CveVendedor <> Nothing And UsuarioActual.CveVendedor <> -1 Then
|
|
Response.Redirect("/Transportes/RepViajes.aspx")
|
|
End If
|
|
AsientoSeleccionado = ""
|
|
CveViaje = IfNull(Request("CveViaje"), "0").ToString.ToEntero
|
|
If CveViaje > 0 Then
|
|
CargaDatos()
|
|
Else
|
|
Alert("Viaje no definido")
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
Dim ObjContratos As New ClsContratos
|
|
Dim ObjViaje As New ClsTransportes
|
|
|
|
If ObjContratos.GetContratos(CveViaje, UsuarioActual.CveEmpresa) Then
|
|
Contrato = ObjContratos.DtResultados.Copy()
|
|
|
|
If ObjContratos.DtResultados IsNot Nothing AndAlso ObjContratos.DtResultados.Rows.Count > 0 Then
|
|
TxtRuta.Text = Contrato.Rows(0)("SubProyecto").ToString
|
|
TxtFecha.Text = Contrato.Rows(0)("FechaInicial").ToString.ToDate.ToShortDateString
|
|
DtPasajeros = New DataTable
|
|
DtPasajeros.Columns.Add("CveViajePasajero", GetType(Integer))
|
|
DtPasajeros.Columns.Add("Numero", GetType(Integer))
|
|
DtPasajeros.Columns.Add("Nombre", GetType(String))
|
|
DtPasajeros.Columns.Add("INE", GetType(String))
|
|
DtPasajeros.Columns.Add("Visa", GetType(String))
|
|
DtPasajeros.Columns.Add("VisaVigencia", GetType(Date))
|
|
DtPasajeros.Columns.Add("FechaNacimiento", GetType(Date))
|
|
DtPasajeros.Columns.Add("Sexo", GetType(String))
|
|
DtPasajeros.Columns.Add("CveSexo", GetType(Integer))
|
|
DtPasajeros.Columns.Add("Celular", GetType(String))
|
|
DtPasajeros.Columns.Add("Observaciones", GetType(String))
|
|
DtPasajeros.Columns.Add("Partida", GetType(String))
|
|
DtPasajeros.Columns.Add("Destino", GetType(String))
|
|
DtPasajeros.Columns.Add("CveDestinoOrigen", GetType(Integer))
|
|
DtPasajeros.Columns.Add("CveDestinoFinal", GetType(Integer))
|
|
DtPasajeros.Columns.Add("Asiento", GetType(String))
|
|
DtPasajeros.Columns.Add("Importe", GetType(Decimal))
|
|
InicializaCombos()
|
|
|
|
'Boletos Vendidos
|
|
Dim dt As DataTable
|
|
If ObjViaje.GetViajesPasajeros(CveViaje, Estatus:=1) Then 'Poner párametro para estatus y cancelado de viajes
|
|
dt = ObjViaje.DtResultados
|
|
Dim cph As ContentPlaceHolder = CType(Me.Master.FindControl("C"), ContentPlaceHolder)
|
|
For Each dr As DataRow In dt.Rows
|
|
Dim lnk As LinkButton = CType(cph.FindControl($"A{dr("Asiento")}"), LinkButton)
|
|
If lnk IsNot Nothing Then
|
|
lnk.Enabled = False
|
|
lnk.CssClass = "nodisponible"
|
|
lnk.ToolTip = dr("Nombre").ToString
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
|
|
ObjContratos.Dispose()
|
|
ObjViaje.Dispose()
|
|
|
|
Else
|
|
ObjContratos.Dispose()
|
|
ObjViaje.Dispose()
|
|
|
|
Response.Redirect($"~/Transportes/RepContratos.aspx")
|
|
End If
|
|
|
|
|
|
'Boletos Vendidos
|
|
|
|
End Sub
|
|
Protected Sub InicializaCombos()
|
|
Dim CveSubProyecto As Integer = Contrato.Rows(0)("CveSubProyecto").ToString.ToEntero
|
|
|
|
'Lista Destinos''carga específicos
|
|
Dim ObjDestinos As New ClsTransportes()
|
|
|
|
If ObjDestinos.GetDestinosTarifas(CveSubProyecto, -1, -1) Then
|
|
If ObjDestinos.DtResultados.Rows.Count > 0 Then
|
|
DtDestinos = ObjDestinos.DtResultados
|
|
DdlPartida.DataSource = DtDestinos.FiltraParametros("", DistinctColumns:={"CveDestinoOrigen", "Partida"}) : DataBind()
|
|
DdlPartida.Items.Insert(0, New ListItem("Seleccione Partida", "-1"))
|
|
End If
|
|
End If
|
|
|
|
ObjDestinos.Dispose()
|
|
End Sub
|
|
#End Region
|
|
|
|
Protected Sub CotizarTarifa()
|
|
If DdlDestino.SelectedValue <> "-1" And DdlPartida.SelectedValue <> "-1" Then
|
|
Dim ImporteR As Decimal = 0
|
|
Dim ObjDestinos As New ClsTransportes()
|
|
Dim CveSubProyecto As Integer = Contrato.Rows(0)("CveSubProyecto").ToString.ToEntero
|
|
|
|
If ObjDestinos.GetDestinosTarifas(CveSubProyecto, DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero) Then
|
|
Dim fechaHoy As Date = Date.Today
|
|
Dim fechaNacimiento As Date = TxtFechaNacimiento.Text.ToDate
|
|
Dim edad As Integer
|
|
|
|
' Calcular la diferencia en años entre la fecha actual y la fecha de nacimiento
|
|
edad = CInt(DateDiff(DateInterval.Year, fechaNacimiento, fechaHoy))
|
|
If edad < 8 Or edad > 65 Then
|
|
ImporteR = ObjDestinos.DtResultados.FiltroPrimeroValor("Importe").ToDecimal.RoundSQL - 20
|
|
Else
|
|
ImporteR = ObjDestinos.DtResultados.FiltroPrimeroValor("Importe").ToDecimal.RoundSQL
|
|
|
|
End If
|
|
End If
|
|
If ImporteR > 0 Then
|
|
ViewState("Importe") = ImporteR
|
|
LbCostos.Text = $"El precio de su boleto es ${ImporteR.FormatoNumero}"
|
|
LbCostos.Visible = True
|
|
BtnAgregarPasajero.Visible = True
|
|
LbAviso.Visible = True
|
|
Else
|
|
ViewState("Importe") = 0
|
|
BtnAgregarPasajero.Visible = False
|
|
LbCostos.Visible = False
|
|
Alert("No se encontro una tarifa para estos destinos", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
|
|
ObjDestinos.Dispose()
|
|
|
|
End If
|
|
End Sub
|
|
Protected Sub OnLinkButtonClick(sender As Object, e As EventArgs)
|
|
'quitamos la selección anterior, en caso de existir.
|
|
If AsientoSeleccionado <> "" Then
|
|
Dim cph As ContentPlaceHolder = CType(Me.Master.FindControl("C"), ContentPlaceHolder)
|
|
Dim lnk As LinkButton = CType(cph.FindControl(AsientoSeleccionado), LinkButton)
|
|
lnk.CssClass = "disponible"
|
|
End If
|
|
|
|
Dim linkButton As LinkButton = DirectCast(sender, LinkButton)
|
|
Dim buttonID As String = linkButton.ID
|
|
linkButton.CssClass += " activo"
|
|
AsientoSeleccionado = buttonID
|
|
|
|
UpPanel.Update()
|
|
End Sub
|
|
Protected Sub FinalizarVenta(sender As Object, e As EventArgs)
|
|
|
|
Dim SbAlert As New StringBuilder()
|
|
Dim Retorno As New Modelos.Factura.MMensajeFactura()
|
|
|
|
Dim ObjTransporte As New ClsTransportes()
|
|
ObjTransporte.IniciaTransacSQL()
|
|
|
|
Dim TieneError As Boolean = False
|
|
|
|
Try
|
|
For Each dr As DataRow In DtPasajeros.Rows
|
|
|
|
|
|
Dim CveViajePasajero As Integer = ObjTransporte.AddViajesPasajeros(CveViaje, dr("CveDestinoOrigen").ToString.ToEntero, dr("CveDestinoFinal").ToString.ToEntero, UsuarioActual.CveVendedor, dr("Importe").ToString.ToDecimal, dr("Asiento").ToString.ToEntero, dr("Nombre").ToString, dr("INE").ToString, dr("FechaNacimiento").ToString.ToDate, dr("CveSexo").ToString.ToBool, dr("Visa").ToString, dr("VisaVigencia").ToString.ToDate, dr("Celular").ToString, dr("Observaciones").ToString, UsuarioActual.CveUsuario)
|
|
|
|
If CveViajePasajero < 1 Then
|
|
TieneError = True
|
|
SbAlert.Append("Ocurrió un error al generar el viaje")
|
|
Exit For
|
|
End If
|
|
|
|
dr("CveViajePasajero") = CveViajePasajero
|
|
Next
|
|
|
|
|
|
If Not TieneError Then
|
|
Retorno = CrearRemision(ObjTransporte)
|
|
End If
|
|
|
|
If Retorno IsNot Nothing Then
|
|
TieneError = Retorno.TieneError
|
|
|
|
If Not TieneError Then
|
|
|
|
If Not Retorno.TieneError Then
|
|
If Retorno.CveVenta <= 0 Then
|
|
Retorno.TieneError = True
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
SbAlert.Append("Ocurrió un error al generar la factura")
|
|
End If
|
|
|
|
If Retorno.Mensajes IsNot Nothing AndAlso Retorno.Mensajes.Count > 0 Then
|
|
For Each Mensaje As String In Retorno.Mensajes
|
|
SbAlert.AppendFormat("{0} <br/>", Mensaje)
|
|
Next
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
Else
|
|
If Retorno.Mensajes IsNot Nothing AndAlso Retorno.Mensajes.Count > 0 Then
|
|
For Each Mensaje As String In Retorno.Mensajes
|
|
SbAlert.AppendFormat("{0} <br/>", Mensaje)
|
|
Next
|
|
End If
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
SbAlert.Append("Ocurrió un error al generar la factura")
|
|
End If
|
|
|
|
If SbAlert.Length = 0 Then
|
|
SbAlert.Append("Ocurrió un error al generar la factura")
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
TieneError = True
|
|
SbAlert.Append("Ocurrió un error al generar la factura." + ex.ToString())
|
|
GuardaLog(ex.ToString())
|
|
Finally
|
|
If TieneError Then
|
|
ObjTransporte.RollBack()
|
|
ObjTransporte.Dispose()
|
|
Else
|
|
ObjTransporte.Commit()
|
|
ObjTransporte.Dispose()
|
|
|
|
SbAlert.Append("El boleto se genero correctamente.")
|
|
|
|
DtPasajeros.Clear()
|
|
GvB.DataSource = DtPasajeros
|
|
GvB.DataBind()
|
|
|
|
DdlPartida.SelectedIndex = -1
|
|
'DdlPartida.SelectedValueExist("-1")
|
|
|
|
DdlDestino.SelectedIndex = -1
|
|
'DdlDestino.SelectedValueExist("-1")
|
|
|
|
AsientoSeleccionado = ""
|
|
CargaDatos()
|
|
End If
|
|
|
|
Alert(SbAlert.ToString(), If(TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion), ShowCloseButton:=False)
|
|
End Try
|
|
|
|
LbAviso.Visible = False
|
|
BtnAgregarPasajero.Visible = False
|
|
BtnGuardar.Visible = False
|
|
LbCostos.Visible = False
|
|
UpPanel.Update()
|
|
|
|
End Sub
|
|
Protected Sub DdlPartida_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
DdlDestino.DataSource = DtDestinos.FiltraParametros($"CveDestinoOrigen = {DdlPartida.SelectedValue}")
|
|
DdlDestino.DataBind()
|
|
DdlDestino.Items.Insert(0, New ListItem("Seleccione Destino", "-1"))
|
|
End Sub
|
|
Protected Sub DdlDestino_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlDestino.SelectedIndexChanged
|
|
If TxtFechaNacimiento.Text = "" Then
|
|
DdlDestino.SelectedValue = "-1"
|
|
DdlPartida.SelectedValue = "-1"
|
|
Alert("Debe seleccionar la fecha de nacimiento", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
CotizarTarifa()
|
|
End Sub
|
|
Private Sub GeneraPasajeros(Cantidad As Integer)
|
|
DtPasajeros.Clear()
|
|
For i As Integer = 1 To Cantidad
|
|
Dim Dr1 As DataRow = DtPasajeros.NewRow
|
|
Dr1("Numero") = i
|
|
'asiento
|
|
DtPasajeros.Rows.Add(Dr1)
|
|
Next
|
|
GvB.DataSource = DtPasajeros
|
|
GvB.DataBind()
|
|
End Sub
|
|
Protected Sub AgregarPasajero(sender As Object, e As EventArgs)
|
|
|
|
If AsientoSeleccionado = "" Then
|
|
Alert("No se ha seleccionado el asiento.")
|
|
Exit Sub
|
|
End If
|
|
|
|
If Me.Importe <= 0 Then
|
|
Alert("No hay un importe asignado.")
|
|
Exit Sub
|
|
End If
|
|
Dim Dr1 As DataRow = DtPasajeros.NewRow
|
|
Dr1("Partida") = DdlPartida.SelectedItem
|
|
Dr1("Destino") = DdlDestino.SelectedItem
|
|
Dr1("CveDestinoOrigen") = DdlPartida.SelectedValue.ToEntero
|
|
Dr1("CveDestinoFinal") = DdlDestino.SelectedValue.ToEntero
|
|
Dr1("Importe") = Me.Importe
|
|
Dr1("Asiento") = AsientoSeleccionado.Replace("A", "")
|
|
Dr1("Nombre") = TxtNombre.Text.Trim
|
|
Dr1("INE") = TxtINE.Text.Trim
|
|
Dr1("FechaNacimiento") = TxtFechaNacimiento.Text.Trim
|
|
Dr1("Sexo") = RblSexo.SelectedItem
|
|
Dr1("CveSexo") = RblSexo.SelectedValue.ToBool
|
|
Dr1("Visa") = TxtVisa.Text.Trim
|
|
Dr1("VisaVigencia") = TxtVisaVigencia.Text.Trim
|
|
Dr1("Celular") = TxtCelular.Text.Trim
|
|
Dr1("Observaciones") = TxtObservaciones.Text.Trim
|
|
|
|
'Reiniciamos Datos'
|
|
DtPasajeros.Rows.Add(Dr1)
|
|
AsientoSeleccionado = ""
|
|
TxtNombre.Text = ""
|
|
TxtINE.Text = ""
|
|
TxtFechaNacimiento.Text = ""
|
|
TxtVisa.Text = ""
|
|
TxtVisaVigencia.Text = ""
|
|
TxtCelular.Text = ""
|
|
TxtObservaciones.Text = ""
|
|
GvB.DataSource = DtPasajeros
|
|
GvB.DataBind()
|
|
|
|
'identifico los asientos seleccionados para la venta
|
|
Dim cph As ContentPlaceHolder = CType(Me.Master.FindControl("C"), ContentPlaceHolder)
|
|
For Each dr As DataRow In DtPasajeros.Rows
|
|
Dim lnk As LinkButton = CType(cph.FindControl($"A{dr("Asiento")}"), LinkButton)
|
|
If lnk IsNot Nothing Then
|
|
lnk.Enabled = False
|
|
lnk.CssClass = "seleccionado"
|
|
lnk.ToolTip = dr("Nombre").ToString
|
|
End If
|
|
Next
|
|
BtnGuardar.Visible = True
|
|
UpPanel.Update()
|
|
End Sub
|
|
Private Function CrearRemision(ByRef objTrans As ClsTransportes) As Modelos.Factura.MMensajeFactura
|
|
Dim Retorno As New Modelos.Factura.MMensajeFactura
|
|
|
|
Dim CveCliente As Integer = 1154164
|
|
Dim CveMoneda As Integer = 2
|
|
Dim CveSubProyecto As Integer = -1
|
|
|
|
Dim CvePSBoleto As Integer = 912720
|
|
|
|
If EsProduccion Then
|
|
CvePSBoleto = 986337
|
|
CveCliente = 1172306
|
|
End If
|
|
|
|
If CveCliente <= 0 Then
|
|
Retorno.Mensajes.Add("No se pudo cargar el cliente")
|
|
Return Retorno
|
|
End If
|
|
|
|
Dim ObjFactura As Modelos.Factura = Modelos.Factura.CrearVentaNueva(UsuarioActual, -1, CveCliente, CveMoneda, "Rem")
|
|
|
|
If ObjFactura IsNot Nothing Then
|
|
'TOMA EL SUBPROYECTO DEL CLIENTE
|
|
CveSubProyecto = ObjFactura.Cliente.CveSubProyecto
|
|
|
|
If CveSubProyecto <= 0 Then
|
|
Retorno.Mensajes.Add("No se pudo cargar el subproyecto")
|
|
Return Retorno
|
|
End If
|
|
|
|
ObjFactura.CveSubProyecto = CveSubProyecto
|
|
ObjFactura.CveSubProyectoCobranza = CveSubProyecto
|
|
ObjFactura.CveSubProyectoEjecucion = CveSubProyecto
|
|
ObjFactura.SetSubProyecto()
|
|
ObjFactura.SetSubProyectoMatriz()
|
|
|
|
For Each Dr As DataRow In DtPasajeros.Rows
|
|
Dim Obs As String = Dr("Observaciones").ToString
|
|
Dim Importe As Decimal = Dr("Importe").ToString.ToDecimal()
|
|
|
|
If Importe <= 0 Then
|
|
Retorno.Mensajes.Add("El importe debe ser mayor a 0")
|
|
Return Retorno
|
|
End If
|
|
|
|
Dim PorcentajeIVA As Decimal = 0
|
|
|
|
Dim DrPS As DataRow = ClsPaginas.GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSBoleto).FiltroPrimero("") ' Estado = -1
|
|
|
|
If DrPS Is Nothing Then
|
|
Retorno.Mensajes.Add("No se pudo agregar el producto")
|
|
Return Retorno
|
|
End If
|
|
|
|
If DrPS("IVA").ToString().Contiene("-1", "") Then
|
|
PorcentajeIVA = ObjFactura.SubProyecto.IVA
|
|
Else
|
|
PorcentajeIVA = DrPS("IVA").ToString().ToDecimal()
|
|
End If
|
|
|
|
If PorcentajeIVA > 0 Then
|
|
Importe = (Importe / (1D + PorcentajeIVA)).RoundSQL(6)
|
|
End If
|
|
|
|
If Not ObjFactura.AgregarPS(CvePSBoleto, 1D, Importe, 0D, Obs, CveSubProyecto:=CveSubProyecto, PorcentajeIVA:=PorcentajeIVA, CveViajePasajero:=Dr("CveViajePasajero").ToString().ToEntero()) Then
|
|
Retorno.Mensajes.Add("No se pudo agregar el producto")
|
|
Return Retorno
|
|
End If
|
|
Next
|
|
|
|
ObjFactura.CalculaTotales()
|
|
|
|
Try
|
|
Retorno = ObjFactura.EmitirFactura(False, Transac:=objTrans.IniciaTransacSQL())
|
|
Catch ex As Exception
|
|
Retorno = Nothing
|
|
GuardaLog(ex.ToString())
|
|
End Try
|
|
|
|
If ObjFactura IsNot Nothing Then
|
|
ObjFactura.Dispose()
|
|
End If
|
|
Else
|
|
Retorno.Mensajes.Add("No se pudo generar la factura")
|
|
End If
|
|
|
|
Return Retorno
|
|
End Function
|
|
|
|
End Class
|