From 82c5ce2b4d9f4b9b81070f3f50434eea4b22335d Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Sat, 17 Feb 2024 10:39:57 -0700 Subject: [PATCH] --Generacion de remisiones al guardar boletos --- Transportes/Boletos.aspx | 875 ++++++++++++++++++------------------ Transportes/Boletos.aspx.vb | 234 +++++++--- 2 files changed, 602 insertions(+), 507 deletions(-) diff --git a/Transportes/Boletos.aspx b/Transportes/Boletos.aspx index 740a84677..cf1b168df 100644 --- a/Transportes/Boletos.aspx +++ b/Transportes/Boletos.aspx @@ -1,12 +1,12 @@ -<%@ Page Language="VB" Title="Transportes V&A - Comprar Boleto" AutoEventWireup="false" - MasterPageFile="~/Site.master" CodeFile="Boletos.aspx.vb" - Inherits="Boletos" EnableEventValidation="true" %> - - - Comprar Boleto - - - +<%@ Page Language="VB" Title="Transportes V&A - Comprar Boleto" AutoEventWireup="false" + MasterPageFile="~/Site.master" CodeFile="Boletos.aspx.vb" + Inherits="Boletos" EnableEventValidation="false" %> + + + Comprar Boleto + + + - - - - - - <%-- Datos de cliente y su viaje --%> -
- -
-
-
- - Datos del Viaje -
-
- -
- -
-
-
- - -
-
- -
-
- - - - - -
-
-
- -
-
-
- - -
-
- -
-
- - - - -
-
-
- -
- -
-
- -
-
- -
-
-
-
-
-
- - Datos del Pasajero -
-
-
-
-
-
-
-
- - - - -
- -
-
-
- - -
-
- -
-
-
-
- - - - - - -
-
-
-
- - - -
-
-
- -
- - - -
-
- - -
-
-
-
- -
- - - - - - - - - - -
-
- -
- -
- <%-- Asientos --%> -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -      - - - -
- - - -
-
- - - - - - - - + + + + + + + <%-- Datos de cliente y su viaje --%> +
+
+
+
+
+
+ + Datos del Viaje +
+
+
+ +
+
+
+ + +
+
+ +
+
+ + + + + +
+
+
+ +
+
+
+ + +
+
+ +
+
+ + + + +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+ + Datos del Pasajero + + +
+
+
+
+
+
+
+
+ + + + +
+ +
+
+
+ + +
+
+ +
+
+
+
+ + + + + + +
+
+
+
+ + + +
+
+
+ +
+ + + +
+
+ + +
+
+
+
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+
+
+
+ <%-- Asientos --%> +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +      + + + +
+ + + +
+
+
+
+
+
+ + + + + diff --git a/Transportes/Boletos.aspx.vb b/Transportes/Boletos.aspx.vb index 9054a5b9e..74451e011 100644 --- a/Transportes/Boletos.aspx.vb +++ b/Transportes/Boletos.aspx.vb @@ -6,7 +6,7 @@ Imports Extensiones.ModExtensiones Imports Microsoft.Ajax.Utilities Partial Class Boletos - Inherits ClsPaginas + Inherits ClsPaginas #Region "Propiedades" Private Property AsientoSeleccionado As String Get @@ -18,7 +18,7 @@ Partial Class Boletos End Property Private Property Importe As Decimal Get - Return ViewState("Importe").ToString().ToDecimal + Return If(IsNothing(ViewState("Importe")), 0, ViewState("Importe")).ToString().ToDecimal() End Get Set(value As Decimal) ViewState("Importe") = value @@ -48,9 +48,11 @@ Partial Class Boletos Set(value As DataTable) ViewState("DtPasajeros") = value End Set - End Property + End Property + + #End Region - + Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then If Request.QueryString("CveViaje") Is Nothing Then @@ -60,7 +62,6 @@ Partial Class Boletos CveViaje = Request.QueryString("CveViaje").ToEntero If CveViaje > 0 Then CargaDatos() - End If End If @@ -69,6 +70,7 @@ Partial Class Boletos Private Sub CargaDatos() Dim ObjContratos As New ClsContratos Dim ObjViaje As New ClsTransportes + If ObjContratos.GetContratos(CveViaje, UsuarioActual.CveEmpresa) Then Contrato = ObjContratos.DtResultados If ObjContratos.DtResultados IsNot Nothing AndAlso ObjContratos.DtResultados.Rows.Count > 0 Then @@ -78,8 +80,10 @@ Partial Class Boletos DtPasajeros.Columns.Add("Numero", GetType(Integer)) DtPasajeros.Columns.Add("Nombre", GetType(String)) DtPasajeros.Columns.Add("Visa", GetType(String)) - DtPasajeros.Columns.Add("Asiento", GetType(String)) + DtPasajeros.Columns.Add("Asiento", GetType(String)) + DtPasajeros.Columns.Add("Celular", GetType(String)) DtPasajeros.Columns.Add("Importe", GetType(Decimal)) + DtPasajeros.Columns.Add("Observaciones", GetType(String)) InicializaCombos() @@ -99,30 +103,18 @@ Partial Class Boletos End If End If - Else ObjContratos.Dispose() + ObjViaje.Dispose() + Response.Redirect($"~/Transportes/RepContratos.aspx") - End If + End If + ObjContratos.Dispose() ObjViaje.Dispose() - Dim ObjViaje As New ClsTransportes - '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 Sub Protected Sub InicializaCombos() @@ -130,48 +122,42 @@ Partial Class Boletos 'Lista Destinos''carga específicos Dim ObjDestinos As New ClsTransportes() - If Not ObjDestinos.GetDestinos(CveRuta:=CveRuta) Then - Else + If ObjDestinos.GetDestinos(CveRuta:=CveRuta) Then If ObjDestinos.DtResultados.Rows.Count > 0 Then DdlPartida.DataSource = ObjDestinos.DtResultados DdlPartida.DataBind() - DdlPartida.Items.Insert(0, New ListItem("Seleccione Partida", "")) + DdlPartida.Items.Insert(0, New ListItem("Seleccione Partida", "-1")) DdlDestino.DataSource = ObjDestinos.DtResultados DdlDestino.DataBind() - DdlDestino.Items.Insert(0, New ListItem("Seleccione Destino", "")) + DdlDestino.Items.Insert(0, New ListItem("Seleccione Destino", "-1")) End If End If ObjDestinos.Dispose() End Sub - Protected Sub CargaDestinos() - - End Sub - Protected Sub CotizarTarifa(sender As Object, e As EventArgs) + Protected Sub CotizarTarifa() If DdlDestino.SelectedValue <> "" And DdlPartida.SelectedValue <> "" Then - + Dim ImporteR As Decimal = 0 Dim ObjDestinos As New ClsTransportes() - Dim retorno As Boolean = ObjDestinos.GetDestinosTarifas(DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero) - Dim ImporteR As Decimal = ObjDestinos.DtResultados.FiltroPrimeroValor("Importe").ToDecimal.RoundSQL + If ObjDestinos.GetDestinosTarifas(DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero) Then + ImporteR = ObjDestinos.DtResultados.FiltroPrimeroValor("Importe").ToDecimal.RoundSQL + End If ObjDestinos.Dispose() - If retorno Then - If ImporteR > 0 Then - ViewState("Importe") = ImporteR - TxtCosto.Text = $"El precio de su boleto es ${ImporteR.FormatoNumero}" - BtnGuardar.Visible = True - UpPanel.Visible = True - Else - TxtCosto.Text = "" - BtnGuardar.Visible = False - UpPanel.Visible = False - ViewState("Importe") = 0 - End If + If ImporteR > 0 Then + ViewState("Importe") = ImporteR + TxtCosto.Text = $"El precio de su boleto es ${ImporteR.FormatoNumero}" + BtnGuardar.Visible = True + Else + Alert("No se encontro una tarifa para esta ruta", TipoMensaje.MsgAdvertencia) + + TxtCosto.Text = "" + BtnGuardar.Visible = False + ViewState("Importe") = 0 End If End If - End Sub Protected Sub OnLinkButtonClick(sender As Object, e As EventArgs) @@ -186,19 +172,20 @@ Partial Class Boletos Dim buttonID As String = linkButton.ID linkButton.CssClass += " activo" AsientoSeleccionado = buttonID + + UpPanel.Update() End Sub Protected Sub FinalizarVenta(sender As Object, e As EventArgs) - If AsientoSeleccionado = "" Then - Alert("Se requiere seleccionar su asiento", TipoMensaje.MsgAdvertencia) - Exit Sub - End If + + Dim SbAlert As New StringBuilder() + Dim Retorno As New Modelos.Factura.MMensajeFactura() Dim ObjTransporte As New ClsTransportes() ObjTransporte.IniciaTransacSQL() - Try - AsientoSeleccionado = AsientoSeleccionado.Replace("A", "") + Dim TieneError As Boolean = False + Try For Each dr As DataRow In DtPasajeros.Rows 'gvr As GridViewRow In GvB.Rows Dim Nombre, Visa, Celular, Obs, Asiento As String Dim Sexo As Boolean = False @@ -210,34 +197,81 @@ Partial Class Boletos Obs = dr("Observaciones").ToString Asiento = dr("Asiento").ToString Importe = dr("Importe").ToString.ToDecimal - '.Text, TxtVisa.Text, TxtCelular.Text, CBool(RblSexo.SelectedValue), TxtObservaciones.Text - If ObjTransporte.AddViajesPasajeros(CveViaje, DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero, Importe, Asiento.ToEntero, Nombre, Visa, Celular, Sexo, Obs, UsuarioActual.CveUsuario, UsuarioActual.CveVendedor) > 1 Then - Alert("Boleto generado correctamente") - ObjTransporte.Commit() - DdlPartida.SelectedValue = "" - DdlDestino.SelectedValue = "" - AsientoSeleccionado = "" - End If - Next + '.Text, TxtVisa.Text, TxtCelular.Text, CBool(RblSexo.SelectedValue), TxtObservaciones.Text + If Not ObjTransporte.AddViajesPasajeros(CveViaje, DdlPartida.SelectedValue.ToEntero, DdlDestino.SelectedValue.ToEntero, Importe, Asiento.ToEntero, Nombre, Visa, Celular, Sexo, Obs, UsuarioActual.CveUsuario, UsuarioActual.CveVendedor) > 1 Then + TieneError = True + SbAlert.Append("Ocurrió un error al generar el viaje") + End If + Next + + If Not TieneError Then + Retorno = CrearRemision(ObjTransporte) + End If + + If Retorno IsNot Nothing Then + TieneError = Retorno.TieneError + + If Not TieneError Then + If Retorno.CveVenta > 0 AndAlso Not Retorno.TieneError Then + SbAlert.AppendFormat("{0}", Retorno.Mensajes(Retorno.Mensajes.Count - 1)) + 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}
", Mensaje) + Next + Else + TieneError = True + 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 - ObjTransporte.RollBack() - Alert($"No se pudo generar el boleto {ex}", TipoMensaje.MsgError) - Finally - ObjTransporte.Dispose() - CargaDatos() + 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 + SbAlert.Append("El boleto se genero correctamente") + ObjTransporte.Commit() + ObjTransporte.Dispose() + + DdlPartida.SelectedValueExist("-1") + DdlDestino.SelectedValueExist("-1") + AsientoSeleccionado = "" + CargaDatos() + End If + + Alert(SbAlert.ToString(), If(TieneError, TipoMensaje.MsgError, TipoMensaje.MsgInformacion), ShowCloseButton:=False) + UpPanel.Update() - End Try + End Try + End Sub - Protected Sub DdlPartida_SelectedIndexChanged(sender As Object, e As EventArgs) - CotizarTarifa(sender, e) + Protected Sub DdlPartida_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPartida.SelectedIndexChanged + CotizarTarifa() + UpPanel.Update() End Sub - Protected Sub DdlDestino_SelectedIndexChanged(sender As Object, e As EventArgs) - CotizarTarifa(sender, e) + Protected Sub DdlDestino_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlDestino.SelectedIndexChanged + CotizarTarifa() + UpPanel.Update() End Sub Protected Sub BtnNumPasajeros_Click(sender As Object, e As EventArgs) @@ -263,10 +297,16 @@ Partial Class Boletos 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("Asiento") = AsientoSeleccionado.Replace("A", "") Dr1("Nombre") = TxtNombre.Text.Trim Dr1("Visa") = TxtVisa.Text.Trim + Dr1("Importe") = Me.Importe 'asiento DtPasajeros.Rows.Add(Dr1) AsientoSeleccionado = "" @@ -284,5 +324,55 @@ Partial Class Boletos lnk.ToolTip = dr("Nombre").ToString End If Next + + UpPanel.Update() End Sub + + Private Function CrearRemision(ByRef objTrans As ClsTransportes) As Modelos.Factura.MMensajeFactura + Dim Retorno As Modelos.Factura.MMensajeFactura = Nothing + + Dim CveCliente As Integer = 1154164 + Dim CveMoneda As Integer = 2 + Dim CveSubProyecto As Integer = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto").ToEntero() + + If CveCliente <= 0 Then + Retorno.Mensajes.Add("No se pudo cargar el cliente") + Return Retorno + End If + + If CveSubProyecto <= 0 Then + Retorno.Mensajes.Add("No se pudo cargar el subproyecto") + Return Retorno + End If + + Dim ObjFactura = Modelos.Factura.CrearVentaNueva(UsuarioActual, CveSubProyecto, CveCliente, CveMoneda, "Rem") + + Dim CvePSBoleto As Integer = 912720 + + For Each Dr As DataRow In DtPasajeros.Rows + Dim Obs = Dr("Nombre").ToString + Dim Importe = Dr("Importe").ToString.ToDecimal() + If Importe <= 0 Then + Retorno.Mensajes.Add("El importe debe ser mayor a 0") + Return Retorno + End If + + ObjFactura.AgregarPS(CvePSBoleto, 1, Importe, 0, Obs, CveSubProyecto:=CveSubProyecto, PorcentajeIVA:=0) + 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 + + Return Retorno + End Function End Class