286 lines
11 KiB
Plaintext
286 lines
11 KiB
Plaintext
<%@ WebHandler Language="VB" Class="E158" %>
|
||
|
||
Imports System
|
||
Imports System.Web
|
||
Imports System.Data
|
||
Imports Newtonsoft.Json
|
||
Imports Newtonsoft.Json.Linq
|
||
Imports Extensiones
|
||
Imports System.IO
|
||
Imports CrystalDecisions.CrystalReports.Engine
|
||
Imports CrystalDecisions.Shared
|
||
Imports Microsoft.Reporting.WebForms
|
||
Imports System.Threading
|
||
Imports System.Threading.Tasks
|
||
Imports System.Net.Http
|
||
Imports System.Net.Http.Headers
|
||
Imports SharpCompress.Archive.Rar
|
||
Imports SharpCompress.Common
|
||
Imports SharpCompress.Reader
|
||
Imports System.Xml
|
||
'Imports ADSistemaLibrary.SatXml
|
||
'Imports ADSistemaLibrary.SatXml.XmlSatCFDI
|
||
Imports System.Diagnostics
|
||
Imports System.Drawing
|
||
Imports System.Drawing.Imaging
|
||
Imports System.ComponentModel
|
||
|
||
|
||
|
||
Public Class E158 : Implements IHttpHandler, IReadOnlySessionState
|
||
|
||
|
||
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
||
Get
|
||
Return False
|
||
End Get
|
||
End Property
|
||
|
||
Private currentcontext As HttpContext
|
||
Private URLParametros As New Hashtable
|
||
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
||
context.Response.ContentType = "text/plain"
|
||
currentcontext = context
|
||
Dim retorno As String = "no se encontro la variable"
|
||
Try
|
||
Dim metodo As String = ""
|
||
Dim FechaActual As DateTime = ClsPaginas.NowADS()
|
||
Dim FechaEnvio As DateTime = FechaActual
|
||
|
||
If context.Request("var") IsNot Nothing Then
|
||
URLParametros = Parametros(context.Request("var"))
|
||
metodo = URLParametros("metodo").ToString
|
||
'SI TRAE UN JSON COMO PARAMETRO
|
||
ElseIf context.Request("metodo") IsNot Nothing Then
|
||
metodo = context.Request("metodo").ToString()
|
||
If context.Request("FechaEnvio") IsNot Nothing Then
|
||
FechaEnvio = context.Request("FechaEnvio").ToString().ToDateTime()
|
||
End If
|
||
End If
|
||
|
||
Select Case metodo
|
||
Case "PreciosVentaCultivo"
|
||
Dim tCveEmpresa As Integer = context.Request("CveEmpresa").ToString.ToEntero
|
||
If PreciosVentaCultivo(tCveEmpresa, context) Then
|
||
retorno = "OK"
|
||
Else
|
||
retorno = "Error"
|
||
End If
|
||
|
||
context.Response.Write(retorno)
|
||
End Select
|
||
Catch ex As Exception
|
||
ex.GuardaLog(ex.ToString())
|
||
context.Response.Write(retorno)
|
||
End Try
|
||
|
||
End Sub
|
||
|
||
Private Function PreciosVentaCultivo(ByVal CveEmpresa As Integer, ByVal context As HttpContext) As Boolean
|
||
Dim Respuesta As Boolean = True
|
||
Dim UsuarioActual As Usuario = ValidaUsuarioSistema(100, CveEmpresa)
|
||
|
||
' Crear una instancia del servicio web
|
||
Dim wsservice As New GrowerService.Service()
|
||
wsservice.Url = "http://webservices.optimaproduce.net/GrowerService/service.asmx"
|
||
|
||
' Llamar al método GetSales con los parámetros necesarios
|
||
|
||
Dim Parametro1 As Integer = 9
|
||
Dim Parametro2 As Integer = 1
|
||
Dim Parametro3 As Integer = 43
|
||
Dim Parametro4 As Integer = 0 '–batchid de una liquidación – 0 Todos
|
||
Dim Parametro5 As Integer = 3 '– Para agropecuaria Jam
|
||
Dim Parametro6 As Integer = 0
|
||
Dim Parametro6Date As Date = Now.AddDays(-3)
|
||
|
||
|
||
|
||
Dim DTresp As DataTable = wsservice.GetSales(Parametro1, Parametro2, Parametro3, Parametro4, Parametro5, Parametro6)
|
||
'DTresp.WriteXml("C:\temp\GrowerService\Sales.xml", XmlWriteMode.WriteSchema)
|
||
'DTresp.FiltraParametros("", "", {"CommodityDesc"}).WriteXml("C:\temp\GrowerService\CommodityDesc.xml", XmlWriteMode.WriteSchema)
|
||
'DTresp.FiltraParametros("", "", {"VarietyDesc"}).WriteXml("C:\temp\GrowerService\VarietyDesc.xml", XmlWriteMode.WriteSchema)
|
||
'DTresp.FiltraParametros("", "", {"SizeDesc"}).WriteXml("C:\temp\GrowerService\SizeDesc.xml", XmlWriteMode.WriteSchema)
|
||
|
||
|
||
DTresp.Columns.Add("InvoiceDateReal", GetType(DateTime))
|
||
|
||
For Each row As DataRow In DTresp.Rows
|
||
Dim fechaTexto As String = row("InvoiceDate").ToString().Trim()
|
||
|
||
If DateTime.TryParseExact(fechaTexto, "MM/dd/yy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing) Then
|
||
row("InvoiceDateReal") = DateTime.ParseExact(fechaTexto, "MM/dd/yy", System.Globalization.CultureInfo.InvariantCulture)
|
||
Else
|
||
row("InvoiceDateReal") = DBNull.Value
|
||
End If
|
||
Next
|
||
|
||
DTresp = DTresp.FiltraParametros(" InvoiceDateReal >= #01/01/2025# ")
|
||
|
||
|
||
Dim ObjVentas As New ClsVentas
|
||
Dim DTCultivo As New DataTable
|
||
Dim DTCultivoVariedad As New DataTable
|
||
Dim DTTamaño As New DataTable
|
||
|
||
If ObjVentas.GetCultivos(-1, CveEmpresa) Then
|
||
DTCultivo = ObjVentas.DtResultados
|
||
Else
|
||
Respuesta = False
|
||
End If
|
||
|
||
If ObjVentas.GetCultivosVariedad(-1, -1, CveEmpresa) Then
|
||
DTCultivoVariedad = ObjVentas.DtResultados
|
||
Else
|
||
Respuesta = False
|
||
End If
|
||
|
||
If ObjVentas.GetEmbarqueTamaño(-1, -1, CveEmpresa) Then
|
||
DTTamaño = ObjVentas.DtResultados
|
||
Else
|
||
Respuesta = False
|
||
End If
|
||
|
||
If Respuesta Then
|
||
ObjVentas.IniciaTransacSQL()
|
||
|
||
For Each dRow As DataRow In DTresp.Rows
|
||
|
||
Dim PalletNum As String = dRow("PalletNum").ToString
|
||
|
||
Try
|
||
Dim CveCultivo As Integer = DTCultivo.FiltroPrimeroValor("CveCultivo", $" Alias = '{dRow("CommodityDesc").ToString}' ").ToEntero
|
||
If Not CveCultivo > 0 Then
|
||
GuardaLog($"No se encontro el cultivo {dRow("CommodityDesc").ToString}")
|
||
Exit For
|
||
End If
|
||
|
||
Dim CveCultivoVariedad As Integer = DTCultivoVariedad.FiltroPrimeroValor("CveCultivoVariedad", $" Alias = '{dRow("VarietyDesc").ToString}' ").ToEntero
|
||
If Not CveCultivoVariedad > 0 Then
|
||
GuardaLog($"No se encontro la variedad {dRow("VarietyDesc").ToString}")
|
||
Exit For
|
||
End If
|
||
|
||
Dim CveTamaño As Integer = DTTamaño.FiltroPrimeroValor("CveTamaño", $" Alias = '{dRow("SizeDesc").ToString.Replace("'", "''")}' ").ToEntero
|
||
If Not CveTamaño > 0 Then
|
||
GuardaLog($"No se encontro el tamaño {dRow("SizeDesc").ToString}")
|
||
Exit For
|
||
End If
|
||
|
||
Dim LoadDate As Date = DateTime.ParseExact(dRow("LoadDate").ToString, "MM/dd/yy", System.Globalization.CultureInfo.InvariantCulture)
|
||
Dim InvoiceDate As Date = DateTime.ParseExact(dRow("InvoiceDate").ToString, "MM/dd/yy", System.Globalization.CultureInfo.InvariantCulture)
|
||
|
||
Dim PaidDate As Date = MinFecha
|
||
If dRow("PaidDate").ToString.Trim.Length > 0 Then
|
||
PaidDate = DateTime.ParseExact(dRow("PaidDate").ToString, "MM/dd/yy", System.Globalization.CultureInfo.InvariantCulture)
|
||
End If
|
||
|
||
|
||
|
||
If Not ObjVentas.AddPreciosVentaManifiesto(dRow("PalletNum").ToString, CveCultivo, CveTamaño, CveCultivoVariedad, dRow("GroReference").ToString,
|
||
LoadDate, InvoiceDate, PaidDate,
|
||
dRow("InvPkgs").ToString.ToDecimal, dRow("NetProdPrice").ToString.ToDecimal, dRow("ProductDesc").ToString,
|
||
UsuarioActual.CveUsuario, CveEmpresa) Then
|
||
Respuesta = False
|
||
Exit For
|
||
End If
|
||
|
||
Catch ex As Exception
|
||
|
||
GuardaLog($"Error PalletNum: {PalletNum} {ex.Message} --> {ex.StackTrace}")
|
||
Respuesta = False
|
||
|
||
End Try
|
||
|
||
|
||
|
||
Next
|
||
|
||
|
||
If Respuesta Then
|
||
ObjVentas.Commit()
|
||
Else
|
||
ObjVentas.RollBack()
|
||
End If
|
||
End If
|
||
|
||
|
||
|
||
ObjVentas.Dispose()
|
||
|
||
|
||
'DTresp.WriteXml("C:\temp\GrowerService\Sales.xml", XmlWriteMode.WriteSchema)
|
||
|
||
|
||
'Dim DTAdjustements As DataTable = wsservice.GetAdjustements(Parametro1, Parametro2, Parametro4, Parametro5, Parametro6)
|
||
'DTAdjustements.WriteXml("C:\temp\GrowerService\Adjustements.xml", XmlWriteMode.WriteSchema)
|
||
|
||
|
||
|
||
'Dim DTGeneralExpenses As DataTable = wsservice.GetGeneralExpenses(Parametro1, Parametro2, Parametro3, Parametro4, Parametro5, Parametro6, expenseID:=)
|
||
'DTGeneralExpenses.WriteXml("C:\temp\GrowerService\GeneralExpenses.xml", XmlWriteMode.WriteSchema)
|
||
|
||
'Dim DTLotexpenses As DataTable = wsservice.GetLotExpenses(Parametro1, Parametro2, Parametro3, Parametro4, Parametro5, Parametro6, expenseID:=)
|
||
'DTLotexpenses.WriteXml("C:\temp\GrowerService\Lotexpenses.xml", XmlWriteMode.WriteSchema)
|
||
|
||
'Dim DTTodayInvoices As DataTable = wsservice.GetTodayInvoices(Parametro1, Parametro2, Parametro3, Parametro4, Parametro5, Parametro6Date, ContractFilter:=1)
|
||
'DTTodayInvoices.WriteXml("C:\temp\GrowerService\TodayInvoices.xml", XmlWriteMode.WriteSchema)
|
||
|
||
Dim InvParametro1 As Integer = 9
|
||
Dim InvParametro2 As Integer = 1
|
||
Dim InvParametro3 As Date = Now.AddDays(-3) ' “01/01/2025” '- ldDate
|
||
Dim InvParametro4 As Integer = 3 '- PackerID
|
||
Dim InvParametro5 As Integer = 0 ' - GrowerID
|
||
Dim InvParametro6 As Integer = 0 '- LabelID(0 = Todos)
|
||
Dim InvParametro7 As String = ”E” '- Language
|
||
|
||
'Dim DTIntentoryActivity As DataTable = wsservice.GetInventoryActivity(InvParametro1, InvParametro2, InvParametro3, InvParametro4, InvParametro5, InvParametro6, InvParametro7)
|
||
'DTIntentoryActivity.WriteXml("C:\temp\GrowerService\IntentoryActivity.xml", XmlWriteMode.WriteSchema)
|
||
|
||
|
||
|
||
|
||
|
||
Return Respuesta
|
||
End Function
|
||
|
||
|
||
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(CveUsuario, CveEmpresa)
|
||
If UsuarioActual IsNot Nothing Then
|
||
HttpContext.Current.Session("UsuarioSIG") = UsuarioActual
|
||
'CreaObjetoEmpresa(UsuarioActual)
|
||
End If
|
||
ObjUsuarios.Dispose()
|
||
|
||
Return UsuarioActual
|
||
End Function
|
||
|
||
Private Function Parametros(Cadena As String) As Hashtable
|
||
Cadena = Decripta(Cadena)
|
||
Dim P1() As String = Cadena.Split("&"c)
|
||
Dim Tmp As String
|
||
Dim P2() As String
|
||
|
||
Dim URLParametros As New Hashtable
|
||
|
||
For Each Tmp In P1
|
||
P2 = Tmp.Replace("%26%", "&").Split("="c)
|
||
URLParametros.Add(P2(0).ToString(), P2(1))
|
||
Next
|
||
Return URLParametros
|
||
End Function
|
||
|
||
|
||
End Class
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|