630 lines
28 KiB
Plaintext
630 lines
28 KiB
Plaintext
<%@ WebHandler Language="VB" Class="E140" %>
|
|
|
|
Imports System
|
|
Imports System.Web
|
|
Imports System.Data
|
|
Imports Newtonsoft.Json
|
|
Imports Extensiones
|
|
Imports System.IO
|
|
Imports Newtonsoft.Json.Linq
|
|
Imports Microsoft.Reporting.WebForms
|
|
|
|
Public Class E140 : Implements IHttpHandler, IRequiresSessionState
|
|
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
|
Get
|
|
Return False
|
|
End Get
|
|
End Property
|
|
Public Shared ReadOnly Property EsProduccion As Boolean
|
|
Get
|
|
If IsNothing(System.Configuration.ConfigurationManager.AppSettings("EsProduccion")) Then
|
|
Return False
|
|
Else
|
|
Return (System.Configuration.ConfigurationManager.AppSettings("EsProduccion").ToString() = "1")
|
|
End If
|
|
End Get
|
|
End Property
|
|
Private ReadOnly Property CveEmpresa As Integer = 140
|
|
Private ReadOnly Property UsuarioWSE140 As String = "bdh_apiuser_"
|
|
Private ReadOnly Property PasswordWSE140 As String = "*863.fy03pon.8kmn_vbtu"
|
|
Public ReadOnly Property TokenAutorizacion As String
|
|
Get
|
|
Return "$2y$10$LGqtRWUloKQmAt.jcUldc.PmS5LJ6l.WU2w1G4PBOTLMVKZRNQFPS"
|
|
End Get
|
|
End Property
|
|
|
|
Private Function ValidaUsuarioSistema(CveUsuario As Integer, CveEmpresa As Integer) As Usuario
|
|
Dim UsuarioActual As Usuario = Nothing
|
|
Dim NombreCadena As String = ClsPaginas.GlobalNombreCadenaConexion(CveEmpresa)
|
|
Dim ObjUsuarios As New ClsSisUsuarioAutenticacion(NombreCadena:=NombreCadena)
|
|
UsuarioActual = ObjUsuarios.GetUsuarioDetalle(100, CveEmpresa)
|
|
If UsuarioActual IsNot Nothing Then
|
|
HttpContext.Current.Session("UsuarioSIG") = UsuarioActual
|
|
'CreaObjetoEmpresa(UsuarioActual)
|
|
End If
|
|
ObjUsuarios.Dispose()
|
|
|
|
Return UsuarioActual
|
|
End Function
|
|
|
|
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
|
Dim retorno As String
|
|
Try
|
|
Dim Metodo As String = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString())
|
|
Select Case Metodo
|
|
Case "MetasVendedores"
|
|
MetasVendedores(context)
|
|
End Select
|
|
|
|
If Metodo = "ConsultaRemisiones" Then
|
|
context.Response.ContentType = "application/json"
|
|
Dim Auth As AuthMessage = ValidarSolicitud(context)
|
|
|
|
If Auth.IsSucces Then
|
|
retorno = ConsultaRemisiones(context, "")
|
|
Else
|
|
context.Response.StatusCode = Auth.StatusCode
|
|
retorno = JsonConvert.SerializeObject(Auth.ErrorMessage)
|
|
End If
|
|
context.Response.Write(retorno)
|
|
ElseIf Metodo = "RegistraPago" Then
|
|
context.Response.ContentType = "application/json"
|
|
Dim Auth As AuthMessage = ValidarSolicitud(context)
|
|
|
|
If Auth.IsSucces Then
|
|
retorno = RegistraPagoRemision(context, "")
|
|
Else
|
|
context.Response.StatusCode = Auth.StatusCode
|
|
retorno = JsonConvert.SerializeObject(Auth.ErrorMessage)
|
|
End If
|
|
context.Response.Write(retorno)
|
|
End If
|
|
Catch ex As Exception
|
|
ex.GuardaLog(ex.Message)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Function ValidarSolicitud(ByVal context As HttpContext) As AuthMessage
|
|
Dim unauthorized As Boolean = True
|
|
Dim respuesta As New AuthMessage
|
|
|
|
Dim authHeader = context.Request.Headers("Authorization")
|
|
If authHeader IsNot Nothing Then
|
|
Dim basicAuth As String = authHeader.Replace("Basic ", "")
|
|
|
|
Dim usernamePasswordArray = Encoding.UTF8.GetString(Convert.FromBase64String(basicAuth)).Split(":"c)
|
|
|
|
Dim userName = usernamePasswordArray(0)
|
|
Dim password = usernamePasswordArray(1)
|
|
unauthorized = Not (userName = Me.UsuarioWSE140 AndAlso password = Me.PasswordWSE140)
|
|
|
|
Else
|
|
respuesta.ErrorMessage = New AppsResponseError() With {.message = "el usuario y/o contraseña son requeridos"}
|
|
respuesta.IsSucces = False
|
|
respuesta.StatusCode = 200
|
|
|
|
Return respuesta
|
|
End If
|
|
|
|
If unauthorized Then
|
|
respuesta.ErrorMessage = New AppsResponseError() With {.message = "el usuario y/o contraseña no son validos"}
|
|
respuesta.IsSucces = False
|
|
respuesta.StatusCode = 200
|
|
|
|
Return respuesta
|
|
Else
|
|
respuesta.ErrorMessage = Nothing
|
|
respuesta.IsSucces = True
|
|
respuesta.StatusCode = 200
|
|
|
|
Return respuesta
|
|
End If
|
|
|
|
End Function
|
|
|
|
Private Function ConsultaRemisiones(ByVal context As HttpContext, Codigo As String) As String
|
|
Dim Respuesta As New AppsResponse
|
|
Dim RespuestaError As New AppsResponseError
|
|
Dim TieneError As Boolean = False
|
|
Dim CveSubProyecto As String = "11790"
|
|
|
|
Dim Usuario As Usuario = ValidaUsuarioSistema(100, CveEmpresa)
|
|
Dim data As New JArray
|
|
Dim dtt As New DataTable
|
|
Dim ObjVentas As New ClsVentas
|
|
Dim FechaInicio As String = Now.AddYears(-2).ToShortDateString
|
|
If ObjVentas.GetRepRemisionesSinFacturar(FechaInicio, Now.AddDays(1).ToShortDateString, Now.AddDays(1).ToShortDateString, CveSubProyecto, -1, -1, "-1", CveEmpresa, CveUsuarioConsulta:=100, PrimerProducto:=True) Then
|
|
dtt = ObjVentas.DtResultados.FiltraParametros("CveVenta > 0")
|
|
End If
|
|
ObjVentas.Dispose()
|
|
|
|
If dtt IsNot Nothing Then
|
|
Try
|
|
For Each Row As DataRow In dtt.Rows
|
|
Dim objVenta As New JObject(
|
|
New JProperty("cveventa", Row("CveVenta")),
|
|
New JProperty("folio", Row("Folio")),
|
|
New JProperty("cliente", Row("Cliente")),
|
|
New JProperty("fecha", Row("Fecha")),
|
|
New JProperty("total", Row("Total")),
|
|
New JProperty("moneda", Row("Abreviatura")),
|
|
New JProperty("primerproducto", Row("PrimerCodigoPS"))
|
|
)
|
|
data.Add(objVenta)
|
|
Next
|
|
Catch ex As Exception
|
|
TieneError = True
|
|
RespuestaError.message = "Ocurrió un error al obtener las remisiones pendientes."
|
|
End Try
|
|
dtt.Dispose()
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
Respuesta.data = data
|
|
|
|
If TieneError Then
|
|
context.Response.StatusCode = 200
|
|
Return JsonConvert.SerializeObject(RespuestaError)
|
|
Else
|
|
context.Response.StatusCode = 200
|
|
Return JsonConvert.SerializeObject(Respuesta)
|
|
End If
|
|
End Function
|
|
|
|
Private Function RegistraPagoRemision(ByVal context As HttpContext, CveVenta As String) As String
|
|
Dim Respuesta As New AppsResponse
|
|
Dim RespuestaError As New AppsResponseError
|
|
Dim TieneError As Boolean = False
|
|
Dim CveSubProyecto As String = "11790"
|
|
Dim JsonRequest As JObject = Nothing
|
|
|
|
If context.Request.InputStream IsNot Nothing Then
|
|
Using reader As New StreamReader(context.Request.InputStream)
|
|
Dim json = reader.ReadToEnd
|
|
If Not String.IsNullOrEmpty(json) Then
|
|
JsonRequest = JObject.Parse(json)
|
|
If JsonRequest Is Nothing Then
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End Using
|
|
End If
|
|
|
|
Dim UsuarioActual As Usuario = ValidaUsuarioSistema(100, CveEmpresa)
|
|
Dim data As New JArray
|
|
Dim dtt As New DataTable
|
|
Dim MsgError As String = ""
|
|
Dim CveCuentaBancaria As Integer = 8075
|
|
Dim ImportePago As Decimal = JsonRequest("importe_pago").ToString.ToDecimal
|
|
Dim FechaPago As Date = JsonRequest("fecha_pago").ToString.ToDate
|
|
Dim FolioPago As String = JsonRequest("referencia_pago").ToString
|
|
Dim CveTipoTransaccion As Integer = If(JsonRequest("referencia_pago").ToString = "tdc", 12, 11)
|
|
Dim CveMonedaPago As Integer = If(JsonRequest("moneda_pago").ToString = "USD", 2, 1)
|
|
Dim pCveVenta As Integer = JsonRequest("cveventa").ToString.ToEntero
|
|
Dim Referencia As String = ""
|
|
'validaciones
|
|
|
|
Dim ObjVenta As New ClsVentas()
|
|
Dim ObjClientes As New ClsClientes
|
|
If ObjVenta.GetVenta(pCveVenta, CveEmpresa) Then
|
|
If ObjVenta.DtResultados IsNot Nothing AndAlso ObjVenta.DtResultados.Rows.Count > 0 Then
|
|
Dim dr As DataRow = ObjVenta.DtResultados.Rows(0)
|
|
'importe y forma de pago.
|
|
Dim VentaRemision As New ClsPaginas.Venta(UsuarioActual)
|
|
VentaRemision.CveVenta = dr("CveVenta").ToString.ToEntero
|
|
VentaRemision.Fecha = dr("Fecha").ToString.ToDate
|
|
VentaRemision.CveCliente = dr("CveCliente").ToString.ToEntero
|
|
VentaRemision.CveMoneda = dr("CveMoneda").ToString.ToEntero
|
|
VentaRemision.TipoDocto = dr("TipoDocto").ToString
|
|
VentaRemision.SerieFolio = dr("SerieFolio").ToString
|
|
VentaRemision.ClienteNombre = dr("ClienteNombre").ToString
|
|
VentaRemision.TC = dr("TipoCambio").ToString.ToDecimal
|
|
VentaRemision.Total = dr("Total").ToString.ToDecimal
|
|
VentaRemision.IVA = dr("IVA").ToString.ToDecimal
|
|
VentaRemision.IEPS = dr("IEPS").ToString.ToDecimal
|
|
VentaRemision.RetIVA = dr("RetIVA").ToString.ToDecimal
|
|
VentaRemision.RetISR = dr("RetISR").ToString.ToDecimal
|
|
VentaRemision.PorcentajeIVA = dr("PorcentajeIVA").ToString.ToDecimal
|
|
VentaRemision.CveSubProyecto = dr("CveSubProyecto").ToString.ToEntero
|
|
|
|
Dim ObjFactura = Modelos.Factura.CrearVentaNueva(UsuarioActual, VentaRemision.CveSubProyecto, VentaRemision.CveCliente, VentaRemision.CveMoneda, "Ing")
|
|
ObjFactura.CveMoneda = VentaRemision.CveMoneda
|
|
ObjFactura.CveVendedor = dr("CveVendedor").ToString.ToEntero
|
|
ObjFactura.CveFormaPago = dr("CveFormaPago33").ToString.ToEntero
|
|
'ObjFactura.ClaveFormaPagoSAT = "99"
|
|
ObjFactura.CveMetodoPago = dr("CveMetodoPago").ToString.ToEntero
|
|
'ObjFactura.ClaveMetodoPagoSAT = "PPD"
|
|
Dim DtRemisionesPS As DataTable = Nothing
|
|
If ObjClientes.GetVentasRemisionesTotales(VentaRemision.CveCliente, VentaRemision.CveVenta.ToString(), 1, CveEmpresa) Then
|
|
DtRemisionesPS = ObjClientes.DtResultados.Copy()
|
|
End If
|
|
For Each drr As DataRow In DtRemisionesPS.Rows
|
|
ObjFactura.AgregarPS(drr("CvePS").ToString().ToEntero(), drr("Cantidad").ToString().ToDecimal(), drr("PU").ToString().ToDecimal(), drr("Descuento").ToString().ToDecimal, drr("Obs").ToString(), CveUM:=drr("CveUM").ToString().ToEntero(),
|
|
CveProyecto:=drr("CveProyecto").ToString().ToEntero(), CveSubProyecto:=drr("CveSubProyecto").ToString().ToEntero(), CveVentaDetallePadre:=drr("CveVentaDetalle").ToString().ToEntero(), CveVentaDetalleRemision:=drr("CveVentaDetalle").ToString().ToEntero(),
|
|
PorcentajeIVA:=drr("PorcentajeIVA").ToString().ToDecimal(), CvePromocionDetalle:=drr("CvePromocionDetalle").ToString.ToEntero)
|
|
Next
|
|
|
|
ObjFactura.GenerarSalidaAlmacen = True
|
|
ObjFactura.DtInventario = ObjFactura.DtDetalle.FiltraParametros("CveTipoPS = 2").Copy()
|
|
'ObjFactura.CveAlmacen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $"CveTipoAlmacen = 1 AND CveSubProyecto = {VentaRemision.CveSubProyecto}", "Orden").ToString().ToEntero()
|
|
|
|
ObjFactura.CalculaTotales()
|
|
|
|
Dim ObjConta As New ClsContabilidad()
|
|
Dim ObjIE As New ClsBancos(ObjConta.IniciaTransacSQL())
|
|
Dim ObjVentas As New ClsVentas(ObjConta.IniciaTransacSQL())
|
|
Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Ashx/E140", 4, 0, 0, 1, FechaPago, "Venta Kiosco", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
|
|
If CvePrePoliza > 0 Then
|
|
'registro de venta y pago
|
|
|
|
Dim Retorno As Modelos.Factura.MMensajeFactura = Nothing
|
|
Retorno = ObjFactura.EmitirFactura(False, Transac:=ObjVentas.IniciaTransacSQL(), Modulo:="Cobranza/GuardarVenta", MostrarURL:=True)
|
|
Retorno.Factura = ObjFactura
|
|
|
|
If Retorno IsNot Nothing AndAlso Retorno.CveVenta > 0 Then
|
|
VentaRemision.CveVenta = ObjFactura.CveVenta
|
|
'Respuesta.data = Retorno.SerieFolio
|
|
|
|
If TieneError Then
|
|
Dim sb As New StringBuilder()
|
|
For Each msg As String In Retorno.Mensajes
|
|
sb.AppendFormat("{0}. ", msg)
|
|
Next
|
|
RespuestaError.message = sb.ToString()
|
|
End If
|
|
'11- tdd, 12-tdc
|
|
Dim CveIE As Integer = ObjIE.AddBancos_IE(CveCuentaBancaria, CveTipoTransaccion, FechaPago, "-1", "", ImportePago, VentaRemision.CveMoneda,
|
|
VentaRemision.TC, "", "", False, True, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
|
|
If CveIE > 0 Then
|
|
'Importe de pago
|
|
Dim Pago As New ClsPaginas.VentaPago
|
|
Pago.TipoPago = "XXX"
|
|
Pago.Fecha = FechaPago
|
|
Pago.CveIE = CveIE
|
|
Pago.CveMonedaPago = CveMonedaPago
|
|
Pago.ImportePago = ImportePago
|
|
Pago.ImportePagoVenta = ImportePago
|
|
Pago.Referencia = Referencia
|
|
|
|
If MsgError = "" AndAlso ClsPaginas.AplicaPrePolizaPagoVenta(VentaRemision, Pago, CvePrePoliza, ObjConta) Then
|
|
MsgError = "No se pudo insertar la póliza"
|
|
End If
|
|
Else
|
|
MsgError = "No se pudo insertar el pago"
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
MsgError = "Falta información para completar la venta."
|
|
End If
|
|
End If
|
|
If Not TieneError Then
|
|
Dim bytesPDF As Byte() = DescargarFactura(ObjFactura.SerieFolio, CveEmpresa, ObjFactura.CveVenta) 'ClsPaginas.PdfFactura(ObjFactura, AplicaPagare:="0", Guardar:=True, RegenerarQR:=True, EsTicket:=False)
|
|
|
|
'generar el pdf y mandarlo
|
|
Dim objretorno As New JObject(
|
|
New JProperty("CveVenta", ObjFactura.CveVenta),
|
|
New JProperty("SerieFolio", ObjFactura.SerieFolio),
|
|
New JProperty("pdf", Convert.ToBase64String(bytesPDF))
|
|
)
|
|
data.Add(objretorno)
|
|
Respuesta.data = data
|
|
ObjConta.RollBack()
|
|
'ObjConta.Commit()
|
|
Else
|
|
ObjConta.RollBack()
|
|
End If
|
|
ObjConta.Dispose()
|
|
ObjIE.Dispose()
|
|
End If
|
|
End If
|
|
ObjVenta.Dispose()
|
|
ObjClientes.Dispose()
|
|
|
|
Respuesta.data = data
|
|
|
|
If TieneError Then
|
|
context.Response.StatusCode = 200
|
|
Return JsonConvert.SerializeObject(RespuestaError)
|
|
Else
|
|
context.Response.StatusCode = 200
|
|
Return JsonConvert.SerializeObject(Respuesta)
|
|
End If
|
|
End Function
|
|
|
|
|
|
#Region "M E T A S V E N D E D O R E S"
|
|
|
|
Private Shared Sub MetasVendedores(ByVal context As HttpContext)
|
|
|
|
Dim CveEmpresa = 140
|
|
Dim RutaEmpresa As String = String.Format("{0}Empresas\{1}\", DirectorioBaseEmpresas, CveEmpresa)
|
|
|
|
Dim ObjEmpresa As New ClsSisEmpresas()
|
|
If ObjEmpresa.GetEmpresas(CveEmpresa, "-1", "-1", "-1", "-1") Then
|
|
End If
|
|
|
|
If ObjEmpresa.Empresa.Ruta.Trim.Length > 0 Then
|
|
RutaEmpresa = ObjEmpresa.Empresa.Ruta.Trim
|
|
End If
|
|
|
|
ObjEmpresa.Dispose()
|
|
|
|
Dim DTVendedores As System.Data.DataTable = New System.Data.DataTable()
|
|
Dim Temporal As String = ""
|
|
|
|
Temporal = String.Format("{0}\Temp\", RutaEmpresa, CveEmpresa)
|
|
Dim Empresa As String = "BDH BATERIAS DISTRIBUCIONES DE HERMOSILLO SA DE CV"
|
|
|
|
DTVendedores.Columns.Add("CveSubProyecto", GetType(Integer))
|
|
DTVendedores.Columns.Add("Sucursal")
|
|
DTVendedores.Columns.Add("Nombre")
|
|
DTVendedores.Columns.Add("Correo")
|
|
|
|
Dim Row_11791 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11993 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11796 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11797 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11793 As DataRow = DTVendedores.NewRow
|
|
Dim Row_12010 As DataRow = DTVendedores.NewRow
|
|
Dim Row_12011 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11790 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11795 As DataRow = DTVendedores.NewRow
|
|
Dim Row_11794 As DataRow = DTVendedores.NewRow
|
|
|
|
Row_11791("CveSubProyecto") = 11791
|
|
Row_11791("Sucursal") = "SOLIDARIDAD"
|
|
Row_11791("Nombre") = "Fernando grijalva López"
|
|
Row_11791("Correo") = "hmo.martirezdecananea@bdhbaterias.com.mx"
|
|
|
|
Row_11993("CveSubProyecto") = 11993
|
|
Row_11993("Sucursal") = "PROGRESO"
|
|
Row_11993("Nombre") = "Brayam Uriel Corrales Soto"
|
|
Row_11993("Correo") = "cajaprogreso.hmo@bdhbaterias.com"
|
|
|
|
Row_11796("CveSubProyecto") = 11796
|
|
Row_11796("Sucursal") = "OBREGON"
|
|
Row_11796("Nombre") = "Brayam Uriel Corrales Soto"
|
|
Row_11796("Correo") = "cen.pisocentro@bdhbaterias.mx"
|
|
|
|
Row_11797("CveSubProyecto") = 11797
|
|
Row_11797("Sucursal") = "NAVOJOA"
|
|
Row_11797("Nombre") = "Orlando Lagarda Cantú"
|
|
Row_11797("Correo") = "almacen.nvj@bdhbaterias.mx"
|
|
|
|
Row_11793("CveSubProyecto") = 11793
|
|
Row_11793("Sucursal") = "LOMA LINDA"
|
|
Row_11793("Nombre") = "Adrian fernando murrieta Rodríguez"
|
|
Row_11793("Correo") = "adrian.murrieta@bdhbaterias.com"
|
|
|
|
Row_12010("CveSubProyecto") = 12010
|
|
Row_12010("Sucursal") = "LOS NOGALES"
|
|
Row_12010("Nombre") = "GERMAN LUNA CASTRO"
|
|
Row_12010("Correo") = ""
|
|
|
|
Row_12011("CveSubProyecto") = 12011
|
|
Row_12011("Sucursal") = "NOGALES CENTRO"
|
|
Row_12011("Nombre") = "GERMAN LUNA CASTRO"
|
|
Row_12011("Correo") = "german.luna@bdhbaterias.com"
|
|
|
|
Row_11790("CveSubProyecto") = 11790
|
|
Row_11790("Sucursal") = "MATRIZ"
|
|
Row_11790("Nombre") = "Luis Fernando grijalva cota"
|
|
Row_11790("Correo") = "luis.grijalva@bdhbaterias.com"
|
|
|
|
|
|
Row_11795("CveSubProyecto") = 11795
|
|
Row_11795("Sucursal") = "GUAYMAS CENTRO"
|
|
Row_11795("Nombre") = "Gastelum Hurtado Juan Daniel"
|
|
Row_11795("Correo") = "daniel.gastelum@bdhbaterias.com"
|
|
|
|
Row_11794("CveSubProyecto") = 11794
|
|
Row_11794("Sucursal") = "GUAYMAS AURORA"
|
|
Row_11794("Nombre") = "Gastelum Hurtado Juan Daniel"
|
|
Row_11794("Correo") = "daniel.gastelum@bdhbaterias.com"
|
|
|
|
DTVendedores.Rows.Add(Row_11791)
|
|
DTVendedores.Rows.Add(Row_11993)
|
|
DTVendedores.Rows.Add(Row_11796)
|
|
DTVendedores.Rows.Add(Row_11797)
|
|
DTVendedores.Rows.Add(Row_11793)
|
|
DTVendedores.Rows.Add(Row_12010)
|
|
DTVendedores.Rows.Add(Row_12011)
|
|
DTVendedores.Rows.Add(Row_11790)
|
|
DTVendedores.Rows.Add(Row_11795)
|
|
DTVendedores.Rows.Add(Row_11794)
|
|
|
|
For Each dRow As System.Data.DataRow In DTVendedores.Rows
|
|
|
|
Dim CorreoSupervisor As String = dRow("Correo").ToString()
|
|
Dim Sucursal As String = dRow("Sucursal").ToString
|
|
Dim Vendedor As String = dRow("Nombre").ToString()
|
|
Dim CveSubProyecto As Integer = dRow("CveSubProyecto").ToString.ToEntero
|
|
CorreoSupervisor = "oscar.irigoyen@adssistemas.mx;rene.molina@adssistemas.mx"
|
|
|
|
Dim ObjGen = New ClsVentas
|
|
|
|
Dim RutaRDLC As String = If(File.Exists($"{RutaEmpresa}\Formatos\MetasVendedores.rdlc"), $"{RutaEmpresa}\Formatos\MetasVendedores.rdlc", $"{DirectorioBaseEmpresas}\Empresas\Grales\Formatos\MetasVendedores.rdlc")
|
|
|
|
If ObjGen.GetRepMetasVendedores(ClsPaginas.NowADS(), CveEmpresa, -1, -1, -1, -1, -1, CveSubProyecto, -1, -1, 0) Then
|
|
|
|
|
|
Dim Imagen As System.IO.FileInfo = New System.IO.FileInfo(String.Format("{0}/Logo.png", RutaEmpresa))
|
|
Dim parametros As List(Of ReportParameter) = New List(Of ReportParameter)()
|
|
parametros.Add(New ReportParameter("pEmp", Empresa))
|
|
|
|
If Imagen.Exists Then
|
|
parametros.Add(New ReportParameter("pImg", $"file://{Imagen.FullName}"))
|
|
Else
|
|
parametros.Add(New ReportParameter("pImg", ""))
|
|
End If
|
|
|
|
parametros.Add(New ReportParameter("UsuarioImprimio", "Sistema"))
|
|
parametros.Add(New ReportParameter("FechaImpresion", ClsPaginas.NowADS().ToString("dd/MM/yyyy")))
|
|
parametros.Add(New ReportParameter("SubProyecto", Sucursal))
|
|
parametros.Add(New ReportParameter("Agente", Vendedor))
|
|
|
|
Dim bytes As Byte() = Nothing
|
|
|
|
Dim rds1 As ReportDataSource = New ReportDataSource()
|
|
rds1.Name = "DataSet1"
|
|
rds1.Value = ObjGen.DtResultados
|
|
|
|
If EsProduccion Then
|
|
|
|
Dim wsreport As New WSRDLC2.WebServiceSoapClient
|
|
Dim params As New List(Of WSRDLC2.ReportParameter)
|
|
Dim reportobjects As New List(Of WSRDLC2.ReportObjects)
|
|
|
|
Dim jsonData As String = Nothing
|
|
Dim ds As New DataSet
|
|
|
|
Dim dt As DataTable = DirectCast(rds1.Value, Data.DataTable)
|
|
dt = dt.Copy()
|
|
dt.TableName = rds1.Name
|
|
ds.Tables.Add(dt)
|
|
|
|
For Each rpds As ReportParameter In parametros
|
|
Dim param As New WSRDLC2.ReportParameter
|
|
param.Name = rpds.Name
|
|
'SI ES TEXTO, QUITAR TABS Y OTROS ESPACIOS QUE DEN PROBLEMAS AL MANDAR LA PETICION
|
|
If rpds IsNot Nothing AndAlso rpds.Values IsNot Nothing AndAlso rpds.Values.Count > 0 AndAlso rpds.Values(0) IsNot Nothing AndAlso rpds.Values(0).GetType() = GetType(String) Then
|
|
param.Values = {rpds.Values(0).Replace(vbVerticalTab, "")}
|
|
Else
|
|
param.Values = {rpds.Values(0)}
|
|
End If
|
|
params.Add(param)
|
|
Next
|
|
|
|
bytes = wsreport.StreamNEWPDFBytes(RutaRDLC, ds, reportobjects.ToArray(), params.ToArray(), "MetasVendedores", "PDF", CveEmpresa, 100, jsonData)
|
|
wsreport = Nothing
|
|
params = Nothing
|
|
ds.Dispose() : ds = Nothing
|
|
|
|
Else
|
|
|
|
Using MR As ReportViewer = New ReportViewer()
|
|
|
|
MR.LocalReport.DataSources.Add(rds1)
|
|
MR.LocalReport.ReportPath = RutaRDLC
|
|
MR.ProcessingMode = ProcessingMode.Local
|
|
MR.LocalReport.EnableExternalImages = True
|
|
MR.LocalReport.SetParameters(parametros)
|
|
MR.LocalReport.Refresh()
|
|
Dim warnings As Warning() = Nothing
|
|
Dim streamids As String() = Nothing
|
|
Dim mimeType As String = Nothing
|
|
Dim encoding As String = Nothing
|
|
Dim extension As String = Nothing
|
|
|
|
bytes = MR.LocalReport.Render("PDF", Nothing, mimeType, encoding, extension, streamids, warnings)
|
|
|
|
End Using
|
|
|
|
End If
|
|
|
|
MandaCorreo(CorreoSupervisor, $"Envió de estado de scorecard sucursal {Sucursal} a {ClsPaginas.NowADS().ToString("dd/MM/yyyy")}", bytes)
|
|
bytes = Nothing
|
|
|
|
End If
|
|
|
|
ObjGen.Dispose()
|
|
|
|
Next
|
|
|
|
End Sub
|
|
#End Region
|
|
Private Function DescargarFactura(FilePDF As String, CveEmpresa As Integer, CveVenta As Integer) As Byte()
|
|
'
|
|
Dim Url = New Uri(String.Format("{0}://{1}:{2}/Compras/PopUpVerFactura.aspx?P={3}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1®ENERAR=1", CveVenta))))
|
|
Dim File As Byte() = Nothing
|
|
Try
|
|
Using httpClient = New System.Net.Http.HttpClient()
|
|
httpClient.Timeout = New TimeSpan(0, 1, 0)
|
|
Using request = New System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, Url)
|
|
request.Headers.Add("ADSToken", Encripta(String.Format("CVEEMPRESA={0}&TICKS={1}&CVEUSUARIO=100", CveEmpresa, DateTime.UtcNow.Ticks)))
|
|
Dim response = httpClient.SendAsync(request).Result
|
|
If response.StatusCode = Net.HttpStatusCode.OK Then
|
|
File = response.Content.ReadAsByteArrayAsync().Result
|
|
End If
|
|
End Using
|
|
End Using
|
|
Catch ex As Exception
|
|
File = Nothing
|
|
OnError("Ocurrió un error al descargar la factura", ex)
|
|
End Try
|
|
|
|
Return File
|
|
End Function
|
|
|
|
|
|
Private Shared Sub MandaCorreo(Para As String, Cuerpo As String, bytes As Byte())
|
|
Try
|
|
Dim ListaArchivos As List(Of ClsSisMail.ArchivoMail) = New List(Of ClsSisMail.ArchivoMail)()
|
|
|
|
Dim AdjuntoReporte As ClsSisMail.ArchivoMail = New ClsSisMail.ArchivoMail()
|
|
|
|
AdjuntoReporte.NombreArchivo = "MetasVendedores.Pdf"
|
|
AdjuntoReporte.ArchivoBinario = bytes
|
|
ListaArchivos.Add(AdjuntoReporte)
|
|
|
|
Dim Correo As ClsSisMail = New ClsSisMail()
|
|
|
|
Dim Asunto As String = Cuerpo
|
|
Correo.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Cuerpo, Archivos:=ListaArchivos)
|
|
|
|
Catch ex As Exception
|
|
Extensiones.ModExtensiones.GuardaLog(Nothing, $"Error Tareas Programadas 140 error enviar mail --> {ex.Message} ")
|
|
End Try
|
|
End Sub
|
|
|
|
Private Shared Function IsValidJson(ByVal strInput As String) As Boolean
|
|
If String.IsNullOrWhiteSpace(strInput) Then
|
|
Return False
|
|
End If
|
|
|
|
strInput = strInput.Trim()
|
|
|
|
If (strInput.StartsWith("{") AndAlso strInput.EndsWith("}")) OrElse (strInput.StartsWith("[") AndAlso strInput.EndsWith("]")) Then
|
|
|
|
Try
|
|
Dim obj = JToken.Parse(strInput)
|
|
Return True
|
|
Catch jex As JsonReaderException
|
|
Console.WriteLine(jex.Message)
|
|
Return False
|
|
Catch ex As Exception
|
|
Console.WriteLine(ex.ToString())
|
|
Return False
|
|
End Try
|
|
Else
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Private Class AppsResponse
|
|
Sub New()
|
|
status = "success"
|
|
End Sub
|
|
Public Property status As String
|
|
Public Property data As Object
|
|
Public Property message As String
|
|
End Class
|
|
|
|
Private Class AppsResponseError
|
|
Sub New()
|
|
status = "error"
|
|
End Sub
|
|
Public Property status As String
|
|
Public Property message As String
|
|
End Class
|
|
|
|
Private Class AuthMessage
|
|
Public Property IsSucces As Boolean
|
|
Public Property ErrorMessage As AppsResponseError
|
|
Public Property StatusCode As Integer
|
|
End Class
|
|
|
|
End Class |