Option Explicit On
Option Strict On
Imports Extensiones
Imports System.Data
Imports System.IO
Imports System.Xml
Imports System.IO.Compression
Imports System.Net
Imports Microsoft.Reporting.WebForms
Imports System.Net.Http
Partial Class Ventas_PortalCliente
Inherits ClsPaginas
Const TopRegistros = 20
#Region " PROPIEDADES "
Private Property CveCliente As Integer
Get
Return ViewState("CveCliente").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCliente") = value
End Set
End Property
Private Property Destino As String
Set(value As String)
ViewState("Destino") = value
End Set
Get
Return ViewState("Destino").ToString
End Get
End Property
Private Property DTHistorialVentas As DataTable
Get
Return CType(ViewState("DTHistorialVentas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTHistorialVentas") = value
End Set
End Property
Private Property DTCxC As DataTable
Get
Return CType(ViewState("DTCxC"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTCxC") = value
End Set
End Property
Private Property DTCxCHistorial As DataTable
Get
Return CType(ViewState("DTCxCHistorial"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTCxCHistorial") = value
End Set
End Property
Private Property CveVenta As Integer
Get
Return ViewState("CveVenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveVenta") = value
End Set
End Property
Private Property CvePago As Integer
Get
Return ViewState("CvePago").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePago") = value
End Set
End Property
Private Property DtPagos As DataTable
Get
Return CType(ViewState("DtPagos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtPagos") = value
End Set
End Property
Private Property TmpDT As DataTable
Get
Return If(IsNothing(ViewState("TmpDT")), Nothing, CType(ViewState("TmpDT"), DataTable))
End Get
Set(value As DataTable)
ViewState("TmpDT") = value
End Set
End Property
Private Property CveSubProyecto As Integer
Get
Return ViewState("CveSubProyecto").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveSubProyecto") = value
End Set
End Property
Private Property Modalidad As String
Get
Return ViewState("Modalidad").ToString
End Get
Set(value As String)
ViewState("Modalidad") = value
End Set
End Property
Private Property Index As Integer
Get
Return ViewState("Index").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("Index") = value
End Set
End Property
Private Property SubProyectoPorcentajeIVA As Double
Get
Return ViewState("SubProyectoPorcentajeIVA").ToString.ToDouble
End Get
Set(value As Double)
ViewState("SubProyectoPorcentajeIVA") = value
End Set
End Property
Private Property Folio As Integer
Get
Return ViewState("Folio").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("Folio") = value
End Set
End Property
Private Property Serie As String
Get
Return ViewState("Serie").ToString
End Get
Set(value As String)
ViewState("Serie") = value
End Set
End Property
Private Property SubProyecto As String
Get
Return ViewState("SubProyecto").ToString
End Get
Set(value As String)
ViewState("SubProyecto") = value
End Set
End Property
Private Property ErrorList As List(Of String)
Get
Return CType(ViewState("ErrorList"), List(Of String))
End Get
Set(value As List(Of String))
ViewState("ErrorList") = value
End Set
End Property
Private Property MensajeAlert As StringBuilder
Get
Return CType(ViewState("MensajeAlert"), StringBuilder)
End Get
Set(value As StringBuilder)
ViewState("MensajeAlert") = value
End Set
End Property
Private Property ObjFactura As Modelos.Factura
Get
Return CType(ViewState("ObjFactura"), Modelos.Factura)
End Get
Set(value As Modelos.Factura)
ViewState("ObjFactura") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Destino = String.Format("{0}\Compras\", UsuarioActual.Empresa.Ruta)
Session("FileUpload") = ""
ViewState("Orden") = ""
RegistraScript("CargaHeader();")
CvePago = -1
Modalidad = ""
Index = -1
CveSubProyecto = -1
SubProyectoPorcentajeIVA = 0
Folio = -1
Serie = ""
SubProyecto = ""
CveCliente = UsuarioActual.CveCliente
CargaDatosCliente()
'CARGAN PESTANIAS SEGUN PERMISOS
If UsuarioActual.TienePermisoProceso(229) Then ' CARGA TAB HISTORIAL DE COMPRAS
TabHistorialCompras.Visible = True
BtnDescargarPDF.Visible = True
BtnDescargarXML.Visible = True
CargaHistorial()
End If
If UsuarioActual.TienePermisoProceso(230) Then ' CARGA TAB CUENTAS X PAGAR
TabCxP.Visible = True
CargaCxP()
End If
If UsuarioActual.TienePermisoProceso(231) Then ' CARGA TAB ANTICIPOS
TabAnticipos.Visible = True
CargaAnticipos()
End If
If UsuarioActual.TienePermisoProceso(232) Then ' CARGA TAB ORDENES DE SERVICIO
TabOS.Visible = True
End If
If UsuarioActual.TienePermisoProceso(233) Then ' CARGA TAB RH BUZON DE CALIDAD
TabBuzonCalidad.Visible = True
CargarTipoBuzon()
CargarClienteSucursal()
End If
CargaPedidos()
CargaCuentasDepositos()
'??ESTE TAB VA DESAPARECER - PARA QUE SOLO LA EMPRESA GESTIONE A LOS USUARIOS POR CLIENTE??
If UsuarioActual.TienePermisoProceso(234) Then ' CARGA TAB SISTEMA
TabSistema.Visible = False
'CargaUsuariosPortal()
End If
'CARGA TAB CONTRASENIA PARA TODOS LOS USUARIOS
If UsuarioActual.CvePlataforma = 6 Then TabContraseña.Visible = True
If Request("Opt") IsNot Nothing AndAlso IsNumeric(Request("Opt")) Then Tab.ActiveTabIndex = Request("Opt").ToEntero
ChkPermiso4.Enabled = False
ChkPermiso5.Enabled = False
ChkPermiso6.Enabled = False
InicializaProsepago()
CargaProsePago()
'TAB PEDIDOS
InicializaTabPedido()
End If
End Sub
#Region "DATOS DEL CLIENTE"
Private Sub CargaDatosCliente()
LtlTitulo.Text = "Portal del Cliente:"
Dim ObjClientes As New ClsClientes()
If ObjClientes.GetClientes(UsuarioActual.CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then
If ObjClientes.DtResultados.Rows.Count > 0 Then
'Campos para Modificación
LtlCliente.Text = ObjClientes.Nombre
Else
Alert("El Cliente Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia)
End If
End If
ObjClientes.Dispose()
End Sub
#End Region
#Region "TAB HISTORIAL DE VENTAS"
Private Sub CargaHistorial(Optional SelectTop As Integer = 21, Optional CveClienteSucursal As Integer = -1)
Dim ObjClientes As New ClsClientes()
If ObjClientes.GetHistorialVentas(CveCliente, SelectTop, CveClienteSucursal:=CveClienteSucursal) Then
If ObjClientes.DtResultados.Rows.Count > 0 Then
'Carga Generales
LtlCantidad.Text = ObjClientes.DtResultados.Rows(0)("CountTotal").ToString.FormatoNumero(0)
LtlTotalVendido.Text = ObjClientes.DtResultados.Rows(0)("Total").ToString.FormatoNumero(2)
LtlMinima.Text = ObjClientes.DtResultados.Rows(0)("MIN_Total").ToString.FormatoNumero(2)
LtlPromedio.Text = ObjClientes.DtResultados.Rows(0)("AVG_Total").ToString.FormatoNumero(2)
LtlMaxima.Text = ObjClientes.DtResultados.Rows(0)("MAX_Total").ToString.FormatoNumero(2)
'Carga Grid
DTHistorialVentas = ObjClientes.DtResultados
GVHistorial.DataSource = ObjClientes.DtResultados
Else
GVHistorial.DataSource = Nothing
End If
Else
GVHistorial.DataSource = Nothing
End If
ObjClientes.Dispose()
GVHistorial.DataBind()
End Sub
Protected Sub GVHistorial_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVHistorial.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCHyperLink("HlPDF").NavigateUrl = $"/Compras/PopUpVerFactura.aspx?P={ Encripta($"OP=VTA&CVEVENTA={e.Row.DataKey("CveVenta")}")}"
e.Row.FCHyperLink("HlXML").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", e.Row.DataKey("CveVenta"), "XML", e.Row.DBCampo("SerieFolio"), e.Row.DBCampo("TipoDocto"))))
If e.Row.RowIndex = 0 Then
e.Row.BackColor = Drawing.Color.LightGray
e.Row.FCHyperLink("HlPDF").Visible = False
e.Row.FCHyperLink("HlXML").Visible = False
End If
If Not (e.Row.RowState = DataControlRowState.Edit OrElse e.Row.RowState = 5) Then
If e.Row.DBCampo("EstatusFactura") <> "Emitida" Then
e.Row.FCLabel("LtlEstatus").ForeColor = Drawing.Color.Red
End If
End If
e.Row.FCLiteral("LtlFactura").Text = e.Row.DBCampo("Folio")
e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Right
' DirectCast(e.Row.FindControl("HLSendMail"), HtmlAnchor).HRef = "javascript:$get('HdnCveVenta').value='" & e.Row.DBCampo("CveVenta") & "';$get('HdnFolioVenta').value='" & e.Row.DBCampo("folio") & "';$('#DivMail').show(1000);PosicionaObjeto('" & DirectCast(e.Row.FindControl("HLSendMail"), HtmlAnchor).ClientID & "', 'DivMail');"
End If
End Sub
Protected Sub RblTipo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RblTipo.SelectedIndexChanged
If DTHistorialVentas IsNot Nothing AndAlso RblTipo.SelectedValue <> "-1" Then
Dim tmp As DataTable = DTHistorialVentas.FiltraParametros($"TipoDocto = '{RblTipo.SelectedValue}'")
If tmp.Rows.Count > 0 Then
Dim Totales As DataRow = tmp.NewRow
Totales("SubTotal") = tmp.SUM("SubTotal")
Totales("Total") = tmp.SUM("Total")
Totales("Descuento") = tmp.SUM("Descuento")
Totales("Amortizacion") = tmp.SUM("Amortizacion")
Totales("MAX_Total") = tmp.MAX("MAX_Total")
Totales("AVG_Total") = tmp.AVG("AVG_Total")
Totales("MIN_Total") = tmp.MIN("MIN_Total")
Totales("CountTotal") = tmp.COUNT("CountTotal")
tmp.Rows.InsertAt(Totales, 0)
End If
GVHistorial.DataSource = tmp
ElseIf DTHistorialVentas IsNot Nothing AndAlso RblTipo.SelectedValue = "-1" Then
GVHistorial.DataSource = DTHistorialVentas
End If
GVHistorial.DataBind()
End Sub
Protected Sub BtnVerMasVentas_Click(sender As Object, e As EventArgs)
If BtnVerMasVentas.Text = "Ver Más" Then
CargaHistorial(-1)
BtnVerMasVentas.Text = "Ver Menos"
Else
CargaHistorial(21)
BtnVerMasVentas.Text = "Ver Más"
End If
End Sub
Protected Sub BtnSendMail_Click(sender As Object, e As System.EventArgs) Handles BtnSendMail.Click
Try
If HdnCveVenta.Value <> "-1" AndAlso HdnFolioVenta.Value <> "-1" Then
'Dim ObjEmprea As New ClsEmpresas()
'If ObjEmprea.GetEmpresas(UsuarioActual.CveEmpresa, "-1", "-1", "-1", "-1") Then
Dim ObjMail As New ClsSisMail()
Dim Ruta As String = ModExtensiones.DirectorioBaseEmpresas & "Empresas\" & UsuarioActual.CveEmpresa & "\"
If File.Exists(Ruta & "PDF\" & HdnFolioVenta.Value & ".pdf") AndAlso File.Exists(Ruta & "XML\" & HdnFolioVenta.Value & ".xml") Then
Dim PDF As String = Ruta & "PDF\" & HdnFolioVenta.Value & ".pdf"
Dim XML As String = Ruta & "XML\" & HdnFolioVenta.Value & ".xml"
Dim ResultadoMail As Integer = 0
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = PDF})
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = XML})
'If ObjMail.SendMail(UsuarioActual.Empresa, TxtParaMail.Text.Trim, "Entrega de Factura", PDF, XML, ArrayCC, TxtBody.Text.Trim) Then
If ObjMail.SendMail(UsuarioActual.Empresa, TxtParaMail.Text.Trim, "Entrega de Factura", TxtBody.Text.Trim, TxtCC.Text.Trim, LSRutasMail) Then
ResultadoMail = 1
TxtCC.Text = ""
TxtBody.Text = ""
Alert("El correo se envió correctamente", TipoMensaje.MsgInformacion)
CargaHistorial()
UpnHistorial.Update()
Else
ResultadoMail = 3
End If
Dim ObjVentas As New ClsVentas
ObjVentas.UpdateVentaMail(ResultadoMail, HdnCveVenta.Value.ToEntero)
ObjVentas.Dispose()
Else
Alert("No se pudo adjuntar el correo electrónico.", TipoMensaje.MsgAdvertencia)
End If
'End If
'ObjEmprea.Dispose()
Else
Alert("No se seleccionó ninguna factura para envíar.", TipoMensaje.MsgAdvertencia)
End If
Catch ex As Exception
OnError("Ocurrió error al mandar MAIL", ex)
Dim ObjVentas As New ClsVentas
ObjVentas.UpdateVentaMail(3, HdnCveVenta.Value.ToEntero)
ObjVentas.Dispose()
End Try
End Sub
#End Region
#Region "TAB CUENTAS X PAGAR"
Private Sub CargaCxP(Optional VerMas As Integer = -1)
If TabCxP.Visible = True Then
Dim ObjMovtos As New ClsMovimientos()
'CxC Activas
If ObjMovtos.GetCxCClienteDetalle(UsuarioActual.CveCliente, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa, -1) Then
GvCxC.DataSource = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'Act'")
DTCxC = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'Act'")
GvCxCHistorial.DataSource = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'Hist'")
DTCxCHistorial = ObjMovtos.DtResultados.FiltraParametros("Tipo = 'Hist'")
Else
GvCxC.DataSource = Nothing
GvCxCHistorial.DataSource = Nothing
End If
ObjMovtos.Dispose()
GvCxC.DataBind()
GvCxCHistorial.DataBind()
End If
End Sub
Protected Sub GvCxCHistorial_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxCHistorial.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 0 Then
e.Row.Cells(0).ColumnSpan = 4
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Right
e.Row.FCLiteral("LtlFactura").Text = "Total" & " "
e.Row.Cells(1).Visible = False
e.Row.Cells(2).Visible = False
e.Row.Cells(3).Visible = False
'e.Row.Cells(9).ColumnSpan = 2
'e.Row.Cells(10).Visible = False
e.Row.BackColor = Drawing.Color.LightGray
End If
If e.Row.RowIndex = 1 Then
e.Row.Cells(0).Width = Unit.Pixel(60)
e.Row.Cells(1).Width = Unit.Pixel(70)
e.Row.Cells(2).Width = Unit.Pixel(80)
e.Row.Cells(3).Width = Unit.Pixel(80)
e.Row.Cells(4).Width = Unit.Pixel(90)
e.Row.Cells(5).Width = Unit.Pixel(90)
e.Row.Cells(6).Width = Unit.Pixel(105)
e.Row.Cells(7).Width = Unit.Pixel(90)
e.Row.Cells(8).Width = Unit.Pixel(105)
End If
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Right
If e.Row.DBCampo("Saldo").ToDouble < 0 Then e.Row.Cells(5).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("DiasVencidos").ToDouble > 0 AndAlso CType(sender, GridView).ID = "GvCxC" Then e.Row.Cells(3).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("Original").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldoOriginal"), Literal).Text = ""
If e.Row.DBCampo("Abonado").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlAbonado"), Literal).Text = ""
If e.Row.DBCampo("PorRecuperado").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlPorRecuperado"), Literal).Text = ""
If e.Row.DBCampo("Saldo").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldo"), Literal).Text = ""
If e.Row.DBCampo("PorXRecuperar").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlPorXRecuperar"), Literal).Text = ""
e.Row.FCLiteral("LtlFactura").Text = e.Row.DBCampo("Folio")
If CType(sender, GridView).ID = "GvCxCHistorial" Then
DirectCast(e.Row.FindControl("LtlDiasVencido"), Literal).Text = ""
Else
e.Row.Cells(7).Font.Bold = True
e.Row.Cells(8).Font.Bold = True
End If
End If
End Sub
Protected Sub GvCxC_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxC.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCLinkButton("HlVerMas").CommandArgument = e.Row.DataKey("CveVenta")
'e.Row.FCLinkButton("LBPagar").CommandArgument = $"{e.Row.DBCampo("CveVenta")}°{e.Row.DBCampo("Folio")}°{e.Row.DBCampo("Fecha")}°{e.Row.DBCampo("Original")}°{e.Row.DBCampo("Abonado")}°{e.Row.DBCampo("PorRecuperado")}°{e.Row.DBCampo("Saldo")}°{e.Row.DBCampo("PorXRecuperar")}"
If e.Row.RowIndex = 0 Then
e.Row.Cells(0).ColumnSpan = 4
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Right
e.Row.FCLiteral("LtlFactura").Text = "Total" & " "
e.Row.Cells(1).Visible = False
e.Row.Cells(2).Visible = False
e.Row.Cells(3).Visible = False
'e.Row.Cells(9).ColumnSpan = 2
'e.Row.Cells(10).Visible = False
e.Row.BackColor = Drawing.Color.LightGray
e.Row.FCCheckBox("ChkPagar").Visible = False
End If
If e.Row.RowIndex = 1 Then
e.Row.Cells(0).Width = Unit.Pixel(60)
e.Row.Cells(1).Width = Unit.Pixel(70)
e.Row.Cells(2).Width = Unit.Pixel(80)
e.Row.Cells(3).Width = Unit.Pixel(80)
e.Row.Cells(4).Width = Unit.Pixel(90)
e.Row.Cells(5).Width = Unit.Pixel(90)
e.Row.Cells(6).Width = Unit.Pixel(105)
e.Row.Cells(7).Width = Unit.Pixel(90)
e.Row.Cells(8).Width = Unit.Pixel(105)
End If
e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Right
If e.Row.DBCampo("Saldo").ToDouble < 0 Then e.Row.Cells(5).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("DiasVencidos").ToDouble > 0 AndAlso CType(sender, GridView).ID = "GvCxC" Then e.Row.Cells(4).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("Original").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldoOriginal"), Literal).Text = ""
If e.Row.DBCampo("Abonado").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlAbonado"), Literal).Text = ""
If e.Row.DBCampo("PorRecuperado").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlPorRecuperado"), Literal).Text = ""
If e.Row.DBCampo("Saldo").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldo"), Literal).Text = ""
If e.Row.DBCampo("PorXRecuperar").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlPorXRecuperar"), Literal).Text = ""
e.Row.FCLiteral("LtlFactura").Text = e.Row.DBCampo("Folio")
If CType(sender, GridView).ID = "GvCxCHistorial" Then
DirectCast(e.Row.FindControl("LtlDiasVencido"), Literal).Text = ""
Else
e.Row.Cells(7).Font.Bold = True
e.Row.Cells(8).Font.Bold = True
End If
End If
End Sub
Protected Sub HlVerMas_Click(sender As Object, e As EventArgs)
Dim CveVenta = CType(sender, LinkButton).CommandArgument.ToEntero
RegistraScript("$('#ModalBitacora').modal()")
CargaEventoBitacora(CveVenta)
End Sub
Private Sub CargaEventoBitacora(CveVenta As Integer)
Dim ObjEventoBitacora As New ClsOIEventos()
If ObjEventoBitacora.GetAgendaBitacora(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=CveVenta) Then
GvEB.DataSource = ObjEventoBitacora.DtResultados.FiltraParametros("CveTipoEvento = 6 OR CveTipoEvento = 2").ToString
Else
GvEB.DataSource = Nothing
End If
ObjEventoBitacora.Dispose()
UPAddEventoBitacora.Update()
End Sub
#Region " PAGO PROSEPAGO "
Private Sub InicializaProsepago()
If Not UsuarioActual.CveEmpresa.Contiene(1, 4, 7, 11, 12, 145) Then
GvCxC.Columns(10).Visible = False
LBPagar.Visible = False
End If
End Sub
Protected Sub LBPagar_Click(sender As Object, e As EventArgs)
DtPagos = New DataTable
DtPagos.TableName = "PagoPortalCliente"
DtPagos.Columns.Add("CveCliente", GetType(Integer))
DtPagos.Columns.Add("CveVenta", GetType(Integer))
DtPagos.Columns.Add("Factura", GetType(String))
DtPagos.Columns.Add("CveSubProyecto", GetType(Integer))
DtPagos.Columns.Add("CveMoneda", GetType(Integer))
DtPagos.Columns.Add("TCVenta", GetType(Decimal))
DtPagos.Columns.Add("ImporteVenta", GetType(Decimal))
DtPagos.Columns.Add("IVA", GetType(Decimal))
DtPagos.Columns.Add("PorcentajeIVA", GetType(Decimal))
DtPagos.Columns.Add("RetIVA", GetType(Decimal))
DtPagos.Columns.Add("PorcentajeRetIVA", GetType(Decimal))
DtPagos.Columns.Add("RetISR", GetType(Decimal))
DtPagos.Columns.Add("PorcentajeRetISR", GetType(Decimal))
DtPagos.Columns.Add("IEPS", GetType(Decimal))
DtPagos.Columns.Add("PorcentajeIEPS", GetType(Decimal))
DtPagos.Columns.Add("TCPago", GetType(Decimal))
DtPagos.Columns.Add("ImportePago", GetType(Decimal))
DtPagos.Columns.Add("ImportePagoMX", GetType(Decimal))
Dim Facturas = ""
Dim TCPago = GlobalTipoCambio(Now)
For Each Gvr As GridViewRow In GvCxC.Rows
If Gvr.FCCheckBox("ChkPagar").Checked Then
Dim Dr = DtPagos.NewRow
Dr("CveCliente") = CveCliente
Dr("CveVenta") = Gvr.DataKey("CveVenta").ToEntero
Dr("Factura") = Gvr.DataKey("Folio")
Dr("CveSubProyecto") = Gvr.DataKey("CveSubProyecto").ToEntero
Dr("CveMoneda") = Gvr.DataKey("CveMoneda").ToEntero
Dr("TCVenta") = Gvr.DataKey("TipoCambio").ToDecimal
Dr("ImporteVenta") = Gvr.DataKey("Original").ToDecimal
Dr("IVA") = Gvr.DataKey("IVA").ToDecimal
Dr("PorcentajeIVA") = Gvr.DataKey("PorcentajeIVA").ToDecimal
Dr("RetIVA") = Gvr.DataKey("RetIVA").ToDecimal
Dr("PorcentajeRetIVA") = Gvr.DataKey("PorcentajeRetIVA").ToDecimal
Dr("RetISR") = Gvr.DataKey("RetISR").ToDecimal
Dr("PorcentajeRetISR") = Gvr.DataKey("PorcentajeRetISR").ToDecimal
Dr("IEPS") = Gvr.DataKey("IEPS").ToDecimal
Dr("PorcentajeIEPS") = Gvr.DataKey("PorcentajeIEPS").ToDecimal
Dr("TCPago") = If(Gvr.DataKey("CveMoneda").ToEntero = 1, 1, TCPago)
Dr("ImportePago") = Gvr.DataKey("Saldo").ToDecimal
If Gvr.DataKey("CveMoneda").ToEntero > 1 Then
Dr("ImportePagoMX") = (Gvr.DataKey("Saldo").ToDecimal * TCPago).RoundAD()
Else
Dr("ImportePagoMX") = Gvr.DataKey("Saldo").ToDecimal
End If
DtPagos.Rows.Add(Dr)
Facturas += $"{Gvr.DataKey("Folio")},"
End If
Next
'SIN REGISTROS SELECCIONADOS
If Facturas = "" Then
Alert("No se seleccionó ningun documento para pagar. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If DtPagos.MAX("CveMoneda").ToEntero > 1 Then
DivPagoDolares.Visible = True
LtTC.Text = TCPago.FormatoNumero(4)
Else
DivPagoDolares.Visible = False
End If
'LbFactura.Text = Facturas.Substring(0, Facturas.Length - 2)
TxtImporte.Text = DtPagos.SUM("ImportePagoMX").FormatoNumero(2)
RVTxtImporte.MaximumValue = DtPagos.SUM("ImportePagoMX").FormatoNumero(2)
TxtConcepto.Text = "Pago de facturas"
TxtReferencia.Text = CveCliente.ToString
TxtNombreCompleto.Text = LtlCliente.Text
RegistraScript("$('#ModalProsePago').modal()")
UpProsePago.Update()
End Sub
Protected Sub BtnProsePago_Click(sender As Object, e As EventArgs)
Dim ClavePago = $"{UsuarioActual.CveUsuario}-{Now.Ticks}"
Dim Carpeta = $"{AppDomain.CurrentDomain.BaseDirectory}/PortalCliente/ePagos/{CveCliente}"
Carpeta.DirectoryExistsCreate
DtPagos.WriteXml($"{Carpeta}/{ClavePago}.xml", XmlWriteMode.WriteSchema)
Dim Parametro = Encripta($"Cve={ClavePago}&CveCliente={CveCliente}")
Dim uriString = ""
Select Case UsuarioActual.CveEmpresa
Case 1, 4, 7, 11, 12, 145
uriString = "https://www.prosepago.com/tvirtual/tvds.aspx?ppost=1&t=123" ' VSH SEGURIDAD
Case Else
Alert("Sin terminal de pago configurada. Por favor comuniquese con su proveedor para verificar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End Select
Dim myNameValueCollection As New NameValueCollection()
Dim Nombre = LimpiaTextoSoloLetras(TxtNombreCompleto.Text)
myNameValueCollection.Add("nom", Nombre.Substring(0, If(Nombre.Length > 200, 200, Nombre.Length)))
myNameValueCollection.Add("con", TxtConcepto.Text)
myNameValueCollection.Add("ref", TxtReferencia.Text)
myNameValueCollection.Add("imp", TxtImporte.Text)
myNameValueCollection.Add("ema", UsuarioActual.Usuario) '
myNameValueCollection.Add("urlOk", $"{Request.Url.GetLeftPart(UriPartial.Authority)}/PortalCliente/PortalCliente.aspx?okpp=1&p={Parametro}")
myNameValueCollection.Add("urlKo", $"{Request.Url.GetLeftPart(UriPartial.Authority)}/PortalCliente/PortalCliente.aspx?okpp=0&p={Parametro}")
myNameValueCollection.Add("autoBack", "1")
myNameValueCollection.Add("datbloq", "1")
''PARA SIMULAR RESPUESTA
'Dim Liga = $"{Request.Url.GetLeftPart(UriPartial.Authority)}/PortalCliente/PortalCliente.aspx?okpp=1&p={Parametro}"
'Alert(Liga, TipoMensaje.MsgInformacion)
'Exit Sub
Response.RedirectWithData(uriString, myNameValueCollection)
End Sub
Private Function LimpiaTextoSoloLetras(Texto As String) As String
Dim pattern As String = "[^A-Za-z\s]"
Dim replacement As String = ""
Return Regex.Replace(Texto, pattern, replacement)
End Function
Private Function LimpiaTextoSoloLetrasNumeros(Texto As String) As String
Dim pattern As String = "[^A-Za-z0-9\s]"
Dim replacement As String = ""
Return Regex.Replace(Texto, pattern, replacement)
End Function
Private Sub CargaProsePago()
Dim TieneError = False
Dim MensajeError As New StringBuilder
Dim EstatusPagoProsepago = -1
If Request("okpp") IsNot Nothing AndAlso IsNumeric(Request("okpp")) Then
EstatusPagoProsepago = Request("okpp").ToEntero
End If
If EstatusPagoProsepago < 0 Then
Exit Sub
End If
If EstatusPagoProsepago = 0 Then
Alert("Ocurrió un error al procesar el pago, no se a realizadó ningun cargo. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If EstatusPagoProsepago = 1 Then
Dim ParametrosTexto As String = Decripta(Request("p"))
If ParametrosTexto <> "" Then
CargaParametros(ParametrosTexto)
Dim ClavePago = UrlParametros("CVE").ToString
Dim CveCliente = UrlParametros("CVECLIENTE").ToString.ToEntero
Dim Carpeta = $"{AppDomain.CurrentDomain.BaseDirectory}/PortalCliente/ePagos/{CveCliente}"
Dim Archivo = $"{Carpeta}/{ClavePago}.xml"
Dim CveProveedorIntermediario = -1
Dim ImporteComision = 0.0D
If File.Exists(Archivo) Then
DtPagos = New DataTable
DtPagos.ReadXml(Archivo)
If DtPagos.Rows.Count > 0 Then
Dim MensajeAlert As New StringBuilder
Dim ObjConta As New ClsContabilidad
Dim ObjCliente As New ClsClientes(ObjConta.IniciaTransacSQL)
Dim CveCuentacliente = -1
Dim IdCuentaCliente = -1
Dim IdCtaContMonedaExtranjera = -1
Dim CveCuentaComplementaria = -1
Dim CveCuentaMonedaExtranjera = -1
Dim IdCtaContRetIVA = -1
Dim IdCtaContRetISR = -1
Dim CveCuentaRetIVA = -1
Dim CveCuentaRetISR = -1
If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1) AndAlso ObjCliente.DtResultados.Rows.Count > 0 Then
IdCuentaCliente = ObjCliente.IdCtaContClientes
CveCuentacliente = ObjCliente.CveCuentaClientes
IdCtaContMonedaExtranjera = ObjCliente.IdCtaContMonedaExtranjera
CveCuentaMonedaExtranjera = ObjCliente.CveCuentaMonedaExtranjera
CveCuentaComplementaria = ObjCliente.CveCuentaComplementaria
IdCtaContRetIVA = ObjCliente.IdCtaContRetIVA
IdCtaContRetISR = ObjCliente.IdCtaContRetISR
CveCuentaRetIVA = ObjCliente.CveCuentaRetIVA
CveCuentaRetISR = ObjCliente.CveCuentaRetISR
Else
TieneError = True
MensajeError.Append("Ocurrió un error al cargar la información contable del cliente. Por favor vuelva a intentar
")
End If
' PREPOLIZA
Dim CvePlantillaPoliza = 11
Dim FechaMovimiento As Date = Now
Dim Concepto = "Prosepago"
Dim DtConceptos As New DataTable
Dim CveMonedaPago = 1
' DETALLES
Dim ConceptoContable = -1
Dim TipoMovimiento = False
Dim ImporteMovimiento = 0.0D
Dim importeMX = 0.0D
Dim IdCtaContable = 0
Dim CveCuenta = 0
Dim ConceptoMovimiento = ""
Dim Referencia = ""
Dim CveSubProyecto = -1
Dim CveVenta = -1
Dim CveMonedaVenta = 1
Dim TCVenta = 0.0D
Dim IVAVenta = 0.0D
Dim PorcentajeIVA = 0.0D
Dim RetIVAVenta = 0.0D
Dim PorcentajeRetIVA = 0.0D
Dim RetISRVenta = 0.0D
Dim PorcentajeRetISR = 0.0D
Dim IEPSVenta = 0.0D
Dim PorcentajeIEPS = 0.0D
Dim TCPago = 0.0D
Dim PorcentajePago = 0.0D
Dim ImportePago = 0.0D
Dim ImportePagoMX = 0.0D
Dim TCGeneral = 0.0D
Dim TCFluctuacion = 0.0D
Dim CveProveedorContabilizar = -1
Dim PorcentajeImpuesto As Decimal = 0
Dim CvePrePoliza = ObjConta.AddPrePolizas("PortalCliente/Pago-Prosepago", CvePlantillaPoliza, TxtImporte.Text.Trim.ToDecimal, TxtImporte.Text.Trim.ToDecimal, CveMonedaPago, FechaMovimiento, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CvePrePoliza > 0 Then
If ObjConta.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPoliza) Then
DtConceptos = ObjConta.DtResultados
End If
End If
If DtConceptos IsNot Nothing AndAlso DtConceptos.Rows.Count > 0 Then
For Each DrPago As DataRow In DtPagos.Rows
For Each DrConcepto As DataRow In DtConceptos.Rows
'REINICIALIZA VALORES
ConceptoContable = DrConcepto("CveConcepto").ToString.ToEntero
TipoMovimiento = If(DrConcepto("TipoMovto").ToString = "True", True, False)
ImporteMovimiento = 0
importeMX = 0
IdCtaContable = 0
CveCuenta = 0
PorcentajeImpuesto = 0
ConceptoMovimiento = ObjConta.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, ConceptoContable, LtlCliente.Text, DrPago("Factura").ToString, DrPago("Factura").ToString)
'VALORES DE LA VENTA
Referencia = DrPago("Factura").ToString
CveSubProyecto = DrPago("CveSubProyecto").ToString.ToEntero
CveVenta = DrPago("CveVenta").ToString.ToEntero
CveMonedaVenta = DrPago("CveMoneda").ToString.ToEntero
TCVenta = DrPago("TCVenta").ToString.ToDecimal
IVAVenta = DrPago("IVA").ToString.ToDecimal
PorcentajeIVA = DrPago("PorcentajeIVA").ToString.ToDecimal
RetIVAVenta = DrPago("RetIVA").ToString.ToDecimal
PorcentajeRetIVA = DrPago("PorcentajeRetIVA").ToString.ToDecimal
RetISRVenta = DrPago("RetISR").ToString.ToDecimal
PorcentajeRetISR = DrPago("PorcentajeRetISR").ToString.ToDecimal
IEPSVenta = DrPago("IEPS").ToString.ToDecimal
PorcentajeIEPS = DrPago("PorcentajeIEPS").ToString.ToDecimal
TCPago = DrPago("TCPago").ToString.ToDecimal
ImportePago = DrPago("ImportePago").ToString.ToDecimal
ImportePagoMX = DrPago("ImportePagoMX").ToString.ToDecimal
PorcentajePago = DrPago("ImportePago").ToString.ToDecimal / DrPago("ImporteVenta").ToString.ToDecimal 'EL IMPORTE PAGO ES EL IMPORTE QUE SE PAGÓ EN LA MONEDA ORIGINAL DE LA VENTA
TCFluctuacion = If(UsuarioActual.Empresa.Funcionalidad(159) = "1", TCVenta, TCPago)
'CONFIGURACION POR CONCEPTO DE PREPOLIZA
Select Case ConceptoContable
Case 2 'PAGO CLIENTE
ImporteMovimiento = ImportePago.RoundSQL()
importeMX = ImportePagoMX.RoundSQL()
TCGeneral = TCVenta
If CveMonedaVenta = 1 Then
IdCtaContable = IdCuentaCliente
CveCuenta = CveCuentacliente
Else
IdCtaContable = IdCtaContMonedaExtranjera
CveCuenta = CveCuentaComplementaria
ConceptoMovimiento += $" TC:{TCPago} ${ImporteMovimiento.FormatoNumero(2)}"
If ImporteMovimiento <> 0 AndAlso IdCtaContable > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, Referencia, 207, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, -1, CveVenta, -1, CveSubProyecto, CveCliente, ImporteMX:=(importeMX - ImporteMovimiento).RoundSQL(), ImporteME:=ImporteMovimiento, CveCuenta:=CveCuenta, TipoCambio:=TCVenta) Then
TieneError = True
MensajeError.Append("No se pudo insertar el detalle de pago de la póliza
")
Exit For
End If
End If
IdCtaContable = IdCtaContMonedaExtranjera
CveCuenta = CveCuentaMonedaExtranjera
End If
Case 134 'PAGO INTERMEDIARIO
ImporteMovimiento = ImportePago.RoundSQL()
importeMX = ImportePagoMX.RoundSQL()
CveProveedorContabilizar = CveProveedorIntermediario
If TCVenta > 1 Then ConceptoMovimiento += $" TC:{TCVenta} ${ImporteMovimiento.FormatoNumero(2)}"
Case 13 'IVA X TRASLADAR
If CveMonedaVenta = 1 Then
ImporteMovimiento = IVAVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = IVAVenta * PorcentajePago
importeMX = ImporteMovimiento * TCVenta
End If
PorcentajeImpuesto = PorcentajeIVA
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCVenta
IdCtaContable = UsuarioActual.Empresa.IdCuentaIVAxTrasladar
CveCuenta = UsuarioActual.Empresa.CveCuentaIVAxTrasladar
If TCVenta > 1 Then ConceptoMovimiento += $" TC:{TCVenta} ${ImporteMovimiento.FormatoNumero(2)}"
Case 61 'IVA TRASLADADO
If CveMonedaVenta = 1 Then
ImporteMovimiento = IVAVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = IVAVenta * PorcentajePago
importeMX = ImporteMovimiento * TCFluctuacion
End If
PorcentajeImpuesto = PorcentajeIVA
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCFluctuacion
IdCtaContable = UsuarioActual.Empresa.IdCuentaIVATrasladado
CveCuenta = UsuarioActual.Empresa.CveCuentaIVATrasladado
If TCFluctuacion > 1 Then ConceptoMovimiento += $" TC:{TCFluctuacion} ${ImporteMovimiento.FormatoNumero(2)}"
Case 8 'RETIVA X TRASLADAR
If CveMonedaVenta = 1 Then
ImporteMovimiento = RetIVAVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = RetIVAVenta * PorcentajePago
importeMX = ImporteMovimiento * TCVenta
End If
PorcentajeImpuesto = PorcentajeRetIVA
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCVenta
If TCVenta > 1 Then ConceptoMovimiento += $" TC:{TCVenta} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetIVA <> 0 Then
IdCtaContable = IdCtaContRetIVA
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetIVACirculacion").ToEntero
End If
End If
'Conta SIG
If CveCuentaRetIVA <> 0 Then
CveCuenta = CveCuentaRetIVA
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetIVACirculacionSIG").ToEntero
End If
End If
Case 62 'RETIVA TRASLADADO
If CveMonedaVenta = 1 Then
ImporteMovimiento = RetIVAVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = RetIVAVenta * PorcentajePago
importeMX = ImporteMovimiento * TCFluctuacion
End If
PorcentajeImpuesto = PorcentajeRetIVA
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCFluctuacion
If TCFluctuacion > 1 Then ConceptoMovimiento += $" TC:{TCFluctuacion} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetIVA <> 0 Then
IdCtaContable = IdCtaContRetIVA
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetIVACirculacion").ToEntero
End If
End If
'Conta SIG
If CveCuentaRetIVA <> 0 Then
CveCuenta = CveCuentaRetIVA
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetIVACirculacionSIG").ToEntero
End If
End If
Case 9 'RETISR X TRASLADAR
If CveMonedaVenta = 1 Then
ImporteMovimiento = RetISRVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = RetISRVenta * PorcentajePago
importeMX = ImporteMovimiento * TCVenta
End If
PorcentajeImpuesto = PorcentajeRetISR
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCVenta
If TCVenta > 1 Then ConceptoMovimiento += $" TC:{TCVenta} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetISR <> 0 Then
IdCtaContable = IdCtaContRetISR
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetISRCirculacion").ToEntero
End If
End If
'Conta SIG
If CveCuentaRetISR <> 0 Then
CveCuenta = CveCuentaRetISR
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetISRCirculacionSIG").ToEntero
End If
End If
Case 63 'RETISR TRASLADADO
If CveMonedaVenta = 1 Then
ImporteMovimiento = RetIVAVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = RetIVAVenta * PorcentajePago
importeMX = ImporteMovimiento * TCFluctuacion
End If
PorcentajeImpuesto = PorcentajeRetISR
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCFluctuacion
If TCFluctuacion > 1 Then ConceptoMovimiento += $" TC:{TCFluctuacion} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetISR <> 0 Then
IdCtaContable = IdCtaContRetISR
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetISRCirculacion").ToEntero
End If
End If
'Conta SIG
If CveCuentaRetISR <> 0 Then
CveCuenta = CveCuentaRetISR
Else
If ObjConta.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjConta.DtResultados.FiltroPrimeroValor("IdCuentaRetISRCirculacionSIG").ToEntero
End If
End If
Case 38 'IEPS X TRASLADAR
If CveMonedaVenta = 1 Then
ImporteMovimiento = IEPSVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = IEPSVenta * PorcentajePago
importeMX = ImporteMovimiento * TCVenta
End If
PorcentajeImpuesto = PorcentajeIEPS
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCVenta
IdCtaContable = UsuarioActual.Empresa.IdCuentaIEPSxTrasladar
CveCuenta = UsuarioActual.Empresa.CveCuentaIEPSxTrasladar
If TCVenta > 1 Then ConceptoMovimiento += $" TC:{TCVenta} ${ImporteMovimiento.FormatoNumero(2)}"
Case 39 'IEPS TRASLADADO
If CveMonedaVenta = 1 Then
ImporteMovimiento = IEPSVenta * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMonedaVenta = 2 Then
ImporteMovimiento = IEPSVenta * PorcentajePago
importeMX = ImporteMovimiento * TCFluctuacion
End If
PorcentajeImpuesto = PorcentajeIEPS
ImporteMovimiento = ImporteMovimiento.RoundSQL()
importeMX = importeMX.RoundSQL()
TCGeneral = TCFluctuacion
IdCtaContable = UsuarioActual.Empresa.IdCuentaIEPSTrasladado
CveCuenta = UsuarioActual.Empresa.CveCuentaIEPSTrasladado
If TCFluctuacion > 1 Then ConceptoMovimiento += $" TC:{TCFluctuacion} ${ImporteMovimiento.FormatoNumero(2)}"
Case 64 'GANANCIA
Continue For 'SKIPEA
If CveMonedaVenta <> 1 Then
IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria
CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria
If TCPago > TCVenta AndAlso CveMonedaVenta = 2 Then
ImporteMovimiento = (ImportePago * TCPago) - (ImportePago * TCVenta)
ImporteMovimiento -= ((IVAVenta * PorcentajePago) * TCFluctuacion) - ((IVAVenta * PorcentajePago) * TCVenta)
ImporteMovimiento += ((RetIVAVenta * PorcentajePago) * TCFluctuacion) - ((RetIVAVenta * PorcentajePago) * TCVenta)
ImporteMovimiento += ((RetISRVenta * PorcentajePago) * TCFluctuacion) - ((RetISRVenta * PorcentajePago) * TCVenta)
ImporteMovimiento -= ((IEPSVenta * PorcentajePago) * TCFluctuacion) - ((IEPSVenta * PorcentajePago) * TCVenta)
ImporteMovimiento = ImporteMovimiento.RoundSQL().Abs()
importeMX = ImporteMovimiento
End If
End If
Case 65 'PERDIDA
Continue For 'SKIPEA
If CveMonedaVenta <> 1 Then
IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria
CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria
If TCPago < TCVenta AndAlso CveMonedaVenta = 2 Then
ImporteMovimiento = (ImportePago * TCPago) - (ImportePago * TCVenta)
ImporteMovimiento -= ((IVAVenta * PorcentajePago) * TCFluctuacion) - ((IVAVenta * PorcentajePago) * TCVenta)
ImporteMovimiento += ((RetIVAVenta * PorcentajePago) * TCFluctuacion) - ((RetIVAVenta * PorcentajePago) * TCVenta)
ImporteMovimiento += ((RetISRVenta * PorcentajePago) * TCFluctuacion) - ((RetISRVenta * PorcentajePago) * TCVenta)
ImporteMovimiento -= ((IEPSVenta * PorcentajePago) * TCFluctuacion) - ((IEPSVenta * PorcentajePago) * TCVenta)
ImporteMovimiento = ImporteMovimiento.RoundSQL().Abs()
importeMX = ImporteMovimiento
End If
End If
End Select
'AGREGA PREPOLIZA DETALLE
If ImporteMovimiento <> 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteMovimiento, Referencia, ConceptoContable, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, -1, CveVenta, -1, CveSubProyecto, CveCliente, CveProveedorContabilizar, ImporteMX:=importeMX, CveCuenta:=CveCuenta, TipoCambio:=TCGeneral, PorcentajeImpuesto:=PorcentajeImpuesto) Then
TieneError = True
MensajeError.Append("No se pudo insertar el detalle de la póliza
")
Exit For
End If
End If
Next
If TieneError Then Exit For
MensajeAlert.Append($"- Factura: {DrPago("Factura")} Importe: $ {DrPago("ImportePagoMX").ToString.FormatoNumero(2)}
")
Next
Else
TieneError = True
MensajeError.Append("Ocurrió un error al procesar los conceptos de contabilización. Por favor verifique y vuelva a intentar.
")
End If
If Not TieneError Then
ObjConta.Commit()
Alert($"Se realizó el pago exitoso de las siguientes facturas:
{MensajeAlert.ToString}", TipoMensaje.MsgInformacion)
Else
ObjConta.RollBack()
Alert(MensajeError.ToString, TipoMensaje.MsgError)
End If
ObjConta.Dispose()
Else
TieneError = True
MensajeError.Append("Ocurrió un error al obtener la información de los documentos pagados. Por favor comuniquese con su proveedor para verificar.")
End If
Else
TieneError = True
MensajeError.Append("Ocurrió un error al obtener la información desde el emisor de pago. Por favor comuniquese con su proveedor para verificar.")
End If
Else
TieneError = True
MensajeError.Append("Ocurrió un error al obtener los parametros desde el emisor de pago. Por favor comuniquese con su proveedor para verificar.")
End If
'SI EL PAGO SE PROCESO BIEN RECARGA CXP
If Not TieneError Then
MandaCorreoNotificacionPago()
CargaCxP()
End If
If TieneError Then
Alert(MensajeError.ToString, TipoMensaje.MsgError)
MandaCorreoERROR(MensajeError.ToString)
End If
End If
End Sub
Private Sub MandaCorreoNotificacionPago()
'CABECERA CORREO
Dim CorreoDestino = UsuarioActual.Usuario
Dim CorreoCC = "rene.molina@adssistemas.mx;israel.pina@adssistemas.mx"
Dim Asunto = $"Notificación de pago - {UsuarioActual.Empresa.Empresa}"
'CUERPO CORREO
Dim strBody As New StringBuilder
strBody.Append(" ")
strBody.Append("
") strBody.Append($" Se le informa estimado cliente {LtlCliente.Text} que hemos recibido exitósamente su pago mediante nuestro portal de cliente SIG.") strBody.Append("
") strBody.Append("| Importe pagado | ") strBody.Append($"$ {DtPagos.SUM("ImportePagoMX").FormatoNumero()} | ") strBody.Append("
| Fecha | ") strBody.Append($"{Now.ToString("dd/MM/yyyy HH:ss")} | ") strBody.Append("
| Factura | ") strBody.Append("Importe pagado | ") strBody.Append("
|---|---|
| {DrPago("Factura")} | ") strBody.Append($"$ {DrPago("ImportePagoMX").ToString.FormatoNumero()} | ") strBody.Append("
Agradecemos su preferencia. Gracias por su pago.
") strBody.Append("") strBody.Append("") 'ENVIO CORREO Dim Mail As New ClsSisMail() Mail.SendMail(ClsPaginas.EmpresaNotificaciones, CorreoDestino, Asunto, strBody.ToString, CorreoCC) End Sub Private Sub MandaCorreoERROR(MensajeError As String) 'CABECERA CORREO Dim CorreoDestino = "rene.molina@adssistemas.mx;israel.pina@adssistemas.mx" Dim Asunto = $"ERROR PROCESO DE PAGO PROSEPAGO - EMPRESA:{UsuarioActual.Empresa.CveEmpresa} CLIENTE:{CveCliente}" Dim Body = $"PARAMETROS LIGA: {Request("p")}
"
'End If
'FIN CARGAR IMAGENES DE PERSONAL
e.Row.Cells(1).Width = Unit.Pixel(250)
End If
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center
End If
End Sub
Private Sub CargaGridRHPersonal(Orden As String)
If Orden <> String.Empty Then
Dim DV As New DataView(CType(ViewState("DTRHPersonal"), DataTable), "", Orden, DataViewRowState.CurrentRows)
GvRHPersonal.DataSource = DV.ToTable()
DV.Dispose()
Else
GvRHPersonal.DataSource = CType(ViewState("DTRHPersonal"), DataTable)
End If
GvRHPersonal.DataBind()
End Sub
Protected Sub BtnConsultarPersonal_Click(sender As Object, e As System.EventArgs) Handles BtnConsultarPersonal.Click
CargaRHPersonal()
End Sub
Protected Sub BtnEnviar_Click(sender As Object, e As System.EventArgs) Handles BtnEnviar.Click
'GvRHPersonal
Dim ObjQueja As New ClsRH
For Each Row As GridViewRow In GvRHPersonal.Rows
If Row.FCCheckBox("ChbSeleccionado").Checked Then
If ObjQueja.AddBuzonCalidad(GvRHPersonal.DataKeys(Row.RowIndex).Value.ToString.ToEntero, UsuarioActual.CveCliente, DdlClienteSucursal.SelectedValue.ToEntero, DdlTipoBuzon.SelectedValue.ToEntero, TxtFechaQueja.Text.ToDate(), TxtDescripcion.Text, TxtNombreReporto.Text, TxtTelefonoReporto.Text, TxtMailReporto.Text, TxtObservaciones.Text, UsuarioActual.CveEmpresa, -1) Then
Alert("Se Envió Correctamente", TipoMensaje.MsgInformacion)
End If
'Si está seleccionado el check del GridView quiere decir que lo seleccionaron. Hay que hacer el insert
'La clave personal se saca de:
'(string)this.grid.DataKeys[rowIndex]["myKey"];
'GvRHPersonal.DataKeys(Row.RowIndex)("CvePersonal").ToString
End If
Next
ObjQueja.Dispose()
End Sub
#End Region
#Region "TAB SISTEMA"
Private Sub CargaUsuariosPortal()
Dim ObjUsuario As New ClsSisUsuarios()
If ObjUsuario.GetUsuariosPortal(-1, CveCliente, -1) Then
Dim dtUsr As DataTable = ObjUsuario.DtResultados
'Dim dr As DataRow = dtUsr.FiltroPrimero("CveUsuario = " & UsuarioActual.CveUsuario)
'If dr IsNot Nothing Then
' If True Then TabHistorialCompras.Visible = True 'Compras 'dr("Permiso1").ToString = "True"
' If True Then TabCxP.Visible = True 'Cuentas por pagar
' If True Then TabAnticipos.Visible = True 'Anticipos
' If True Then TabOS.Visible = True 'Ordenes de Servicio
' If True Then TabBuzonCalidad.Visible = True 'Buzón Calidad
' 'If dr("Permiso6").ToString = "True" Then TabCotizaciones.Visible = True 'Cotizaciones
' If True Then TabSistema.Visible = True 'Sistemas
'End If
dtUsr = dtUsr.FiltraParametros("Nombre <> 'Admin' AND CveUsuario <> " & UsuarioActual.CveUsuario)
ViewState("OrdenUsuarios") = ""
''busco la clave del admin, si es que existe
'Dim dr As DataRow = dtUsr.FiltroPrimero("Usuario = 'Admin'")
'If dr IsNot Nothing Then
' HdnCveUsuarioPortalAdmin.Value = dr("CveUsuarioPortal").ToString
' If dr("Estatus").ToString = "1" Then
' HdnCveUsuarioPortalActivado.Value = "1"
' End If
'End If
'If HdnCveUsuarioPortalActivado.Value.ToEntero > 0 Then
' trEnviarActivacion.Visible = False
' trRecuperacionContraseña.Visible = True
'End If
GvUsuariosPortal.DataSource = dtUsr
ViewState("DTUsuariosCliente") = dtUsr
Else
GvUsuariosPortal.DataSource = Nothing
ViewState("DTUsuariosCliente") = Nothing
End If
ObjUsuario.Dispose()
GvUsuariosPortal.DataBind()
End Sub
#Region "GESTION DE USUARIOS DEL PORTAL"
Protected Sub LnkAgregarUsuario_Click(sender As Object, e As EventArgs) Handles LnkAgregarUsuario.Click
Dim ObjParametro As SisParametro = GlobalDTParametros(SisParametros.URL)
Dim ObjUsuario As New ClsSisUsuarios
Dim CveUsuario As Integer = -1
Dim Liga As String = $"{ObjParametro.Cadena1}LogIn.aspx"
Dim CvePlataforma As Integer = 6
If UsuarioActual.CveEmpresa = 43 Then
Liga = ObjParametro.Cadena1 & "AIMMGM/Portal.aspx"
End If
ObjUsuario.IniciaTransacSQL()
CveUsuario = ObjUsuario.AddUsuarioPortal(TxtCorreoPortal.Text, ContraseñaPredeterminadaEncriptada, TxtNombrePortal.Text, TxtCorreoPortal.Text, CveCliente, -1, CvePlataforma, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CveUsuario > 0 Then
If ObjUsuario.UpdateUsuariosModulos(CveUsuario, 1101, True, UsuarioActual.CveUsuario) Then
ObjUsuario.GetUsuariosPortal(-1, CveCliente, -1)
ViewState("DTUsuariosCliente") = ObjUsuario.DtResultados.FiltraParametros("Nombre <> 'Admin' AND CveUsuario <> " & UsuarioActual.CveUsuario)
TxtNombrePortal.Text = ""
TxtCorreoPortal.Text = ""
EnviaCorreo(Liga)
Alert("Usuario Creado.
ADSistemas