--Generacion de remisiones al guardar boletos

This commit is contained in:
2024-02-17 10:39:57 -07:00
parent 87e070d1c7
commit 82c5ce2b4d
2 changed files with 602 additions and 507 deletions

View File

@@ -1,6 +1,6 @@
<%@ Page Language="VB" Title="Transportes V&A - Comprar Boleto" AutoEventWireup="false"
MasterPageFile="~/Site.master" CodeFile="Boletos.aspx.vb"
Inherits="Boletos" EnableEventValidation="true" %>
Inherits="Boletos" EnableEventValidation="false" %>
<asp:Content ID="Content3" ContentPlaceHolderID="E" runat="Server">
Comprar Boleto
@@ -85,7 +85,8 @@
<ContentTemplate>
<%-- Datos de cliente y su viaje --%>
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
<div class="portlet light xspadding bordered ">
<div class="portlet-title">
<div class="caption font-yellow">
@@ -93,7 +94,6 @@
<span class="caption-subject bold uppercase">Datos del Viaje</span>
</div>
</div>
<div class="portlet-body form">
<div class="row">
@@ -107,11 +107,9 @@
<div class="col-md-6">
<div class="form-group form-md-line-input input-iconright">
<asp:DropDownList ID="DdlPartida" AppendDataBoundItems="true" DataTextField="Destino"
<asp:DropDownList ID="DdlPartida" DataTextField="Destino"
AutoPostBack="true"
DataValueField="CveDestino" Class="form-control input-sm select2me"
OnTextChanged="CotizarTarifa"
Width="200px" runat="server">
DataValueField="CveDestino" Class="form-control input-sm select2me" Width="200px" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVPartida" runat="server" ControlToValidate="DdlPartida"
Display="None" ErrorMessage="<b><span style='text-decoration: underline'>ERROR:</span></b><br />El campo <b>''Partida''</b> es necesario, por favor ingréselo."
@@ -131,10 +129,9 @@
<div class="col-md-6">
<div class="form-group form-md-line-input input-iconright">
<asp:DropDownList ID="DdlDestino" AppendDataBoundItems="true" DataTextField="Destino"
<asp:DropDownList ID="DdlDestino" DataTextField="Destino"
AutoPostBack="true"
DataValueField="CveDestino" Class="form-control input-sm select2me"
OnTextChanged="CotizarTarifa"
Width="200px" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFVDestino" runat="server" ControlToValidate="DdlDestino"
@@ -149,18 +146,22 @@
<asp:Label runat="server" ID="TxtCosto" CssClass="text-success bold mx-1"></asp:Label>
<br />
<div class="text-center">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="portlet light xspadding bordered">
<div class="portlet-title">
<div class="caption font-green">
<i class="fa fa-users font-green"></i>
<span class="caption-subject bold uppercase">Datos del Pasajero <asp:Label ID="LblNum" runat="server" Text='<%# Eval("Numero") %>'></asp:Label> </span>
<span class="caption-subject bold uppercase">Datos del Pasajero
<asp:Label ID="LblNum" runat="server" Text='<%# Eval("Numero") %>'></asp:Label>
</span>
</div>
<div class="actions">
<div class="btn-group">
@@ -190,7 +191,7 @@
<div class="row">
<div class="col-md-6">
<div class="form-group form-md-line-input input-iconright">
<asp:DropDownList ID="RblSexo" CssClass="form-control" runat="server">
<asp:DropDownList ID="RblSexo" CssClass="form-control input-sm select2me" runat="server">
<asp:ListItem Text="Masculino" Value="1" Selected="True" />
<asp:ListItem Text="Femenino" Value="0" />
</asp:DropDownList>
@@ -222,25 +223,28 @@
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<asp:GridView ID="GvB" runat="server" Width="100%" AutoGenerateColumns="false" CssClass="table table-advance table-hover" GridLines="None" DataKeyNames="Nombre,Visa,Asiento">
<Columns>
<asp:BoundField DataField="Nombre" HeaderText="Nombre" />
<asp:BoundField DataField="Visa" HeaderText="Visa" />
<asp:BoundField DataField="Asiento" HeaderText="Asiento" />
<asp:BoundField DataField="Importe" HeaderText="Importe" DataFormatString="${0:N2}" />
<asp:BoundField DataField="Asiento" HeaderText="Asiento" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Importe" HeaderText="Importe" DataFormatString="${0:N2}" ItemStyle-HorizontalAlign="Right" />
</Columns>
</asp:GridView>
</div>
</div>
<div class="row">
<div class="col-md-5"></div>
<div class="col-md-2">
<asp:Button ID="BtnGuardar" Visible="False" OnClick="FinalizarVenta" runat="server" CssClass="btn btn-success "
Text="Finalizar Compra"
ValidationGroup="GrpGuardar"></asp:Button>
</div>
<div class="col-md-5"></div>
</div>
</div>
<%-- Asientos --%>
<div class="col-md-4">
@@ -495,6 +499,7 @@
</tbody>
</table>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

View File

@@ -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
@@ -49,6 +49,8 @@ Partial Class Boletos
ViewState("DtPasajeros") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
@@ -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
@@ -79,7 +81,9 @@ Partial Class Boletos
DtPasajeros.Columns.Add("Nombre", GetType(String))
DtPasajeros.Columns.Add("Visa", 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()
Response.Redirect($"~/Transportes/RepContratos.aspx")
End If
ObjContratos.Dispose()
ObjViaje.Dispose()
Dim ObjViaje As New ClsTransportes
Response.Redirect($"~/Transportes/RepContratos.aspx")
End If
ObjContratos.Dispose()
ObjViaje.Dispose()
'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
Alert("No se encontro una tarifa para esta ruta", TipoMensaje.MsgAdvertencia)
TxtCosto.Text = ""
BtnGuardar.Visible = False
UpPanel.Visible = False
ViewState("Importe") = 0
End If
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 = ""
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} <br/>", 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)
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 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