Mejora en consulta
This commit is contained in:
@@ -25,12 +25,15 @@ Public Class E72 : Implements IHttpHandler, IRequiresSessionState
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function contratoexistencia(ByVal context As HttpContext) As String
|
||||
|
||||
|
||||
|
||||
Dim retorno As String = ""
|
||||
Dim ObjInv As New ClsInventarios
|
||||
Try
|
||||
|
||||
|
||||
Dim retorno As String = ""
|
||||
Dim ObjInv As New ClsInventarios
|
||||
Dim DtMovimientos As DataTable = CreaDT()
|
||||
ObjInv.GetRepEntradasSalidasXContrato(72, -1, MinFecha, Date.Now, -1, -1, 17, -1, -1, 3, -1, 1158)
|
||||
Dim DtRepEntradasSalidasXContrato As DataTable = ObjInv.DtResultados.FiltraParametros("CvePS > 0")
|
||||
|
||||
@@ -38,34 +41,73 @@ Public Class E72 : Implements IHttpHandler, IRequiresSessionState
|
||||
Dim DtApartados As DataTable = ObjInv.DtResultados.FiltraParametros("CvePS > 0", "", {"CvePS", "Cantidad"})
|
||||
Dim asd As Integer = DtApartados.Rows.Count
|
||||
|
||||
Dim DTapartado = From row In DtApartados.AsEnumerable
|
||||
Group row By CvePS = row.Field(Of Integer)("CvePS") Into CvePSGroup = Group
|
||||
Select New With {
|
||||
Key CvePS,
|
||||
.Cantidad = CvePSGroup.Sum(Function(r) r.Field(Of Decimal)("Cantidad"))
|
||||
}
|
||||
For Each tempApartados As DataRow In DtApartados.Rows
|
||||
For Each tempEntradasSalidas As DataRow In DtRepEntradasSalidasXContrato.Rows
|
||||
Dim dr As DataRow = DtMovimientos.NewRow
|
||||
If tempEntradasSalidas("CvePS").ToString.ToEntero = tempApartados("CvePS").ToString.ToEntero Then
|
||||
dr("Codigo") = tempEntradasSalidas("Codigo")
|
||||
dr("Existencia") = tempEntradasSalidas("SaldoFCant")
|
||||
dr("Cantidad") = tempApartados("Cantidad")
|
||||
dr("Precio") = tempEntradasSalidas("PrecioVenta")
|
||||
Else
|
||||
dr("Codigo") = tempEntradasSalidas("Codigo")
|
||||
dr("Existencia") = tempEntradasSalidas("SaldoFCant")
|
||||
dr("Cantidad") = 0
|
||||
dr("Precio") = tempEntradasSalidas("PrecioVenta")
|
||||
End If
|
||||
DtMovimientos.Rows.Add(dr)
|
||||
|
||||
Dim DtTemp = From entradas In DtRepEntradasSalidasXContrato
|
||||
Join apartados In DTapartado
|
||||
On entradas.Field(Of Integer)("CvePS") Equals apartados.CvePS
|
||||
Select New With {
|
||||
.Codigo = entradas.Field(Of String)("Codigo"),
|
||||
.Existencia = entradas.Field(Of Double)("SaldoFCant"),
|
||||
.AlmacenAlt = apartados.Cantidad,
|
||||
.Precio = entradas.Field(Of Double)("PrecioVenta")
|
||||
}
|
||||
Next
|
||||
Next
|
||||
|
||||
Dim dtExistencias = From row In DtMovimientos.FiltraParametros("", "", {"Codigo", "Existencia", "Cantidad", "Precio"})
|
||||
Group row By Codigo = row.Field(Of String)("Codigo"), Existencia = row.Field(Of Double)("Existencia"), Precio = row.Field(Of Double)("Precio") Into CodigoGroup = Group
|
||||
Select New With {
|
||||
.Codigo = Codigo,
|
||||
.Existencia = Existencia,
|
||||
.Cantidad = CodigoGroup.Sum(Function(r) r.Field(Of Double)("Cantidad")),
|
||||
.Precio = Precio}
|
||||
|
||||
'Dim LINQEntradasSalidas = From row In DtRepEntradasSalidasXContrato.AsEnumerable
|
||||
' Select New With {
|
||||
' .CvePS = row.Field(Of Integer)("CvePS"),
|
||||
' .Existencia = row.Field(Of Double)("SaldoFCant"),
|
||||
' .Cantidad = 0,
|
||||
' .Precio = row.Field(Of Double)("PrecioVenta"),
|
||||
' .Codigo = row.Field(Of String)("Codigo")}
|
||||
|
||||
|
||||
'Dim DtTemp = From LINQEntradasSalida In LINQEntradasSalidas.AsEnumerable
|
||||
' Group Join LINQapartados In LINQapartado.AsEnumerable
|
||||
' On LINQEntradasSalida.CvePS Equals LINQapartados.CvePS Into Group
|
||||
' From unido In Group.DefaultIfEmpty
|
||||
' Where unido IsNot Nothing
|
||||
' Order By LINQEntradasSalida.CvePS
|
||||
' Select New With {.Codigo = LINQEntradasSalida.Codigo,
|
||||
' .Existencia = LINQEntradasSalida.Existencia,
|
||||
' .Precio = LINQEntradasSalida.Precio}
|
||||
|
||||
retorno = JsonConvert.SerializeObject(DtTemp).ToString
|
||||
'Dim Dtnum As Integer = DtMovimientos.su
|
||||
|
||||
retorno = JsonConvert.SerializeObject(dtExistencias).ToString
|
||||
context.Response.Write(retorno)
|
||||
ObjInv.Dispose()
|
||||
Return retorno
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
|
||||
ObjInv.Dispose()
|
||||
Return retorno
|
||||
End Function
|
||||
|
||||
Private Function CreaDT()
|
||||
Dim DtMovimientos As DataTable = New DataTable("Productos")
|
||||
With DtMovimientos.Columns
|
||||
.Add("Codigo", Type.GetType("System.String"))
|
||||
.Add("Existencia", Type.GetType("System.Double"))
|
||||
.Add("Cantidad", Type.GetType("System.Double"))
|
||||
.Add("Precio", Type.GetType("System.Double"))
|
||||
End With
|
||||
Return DtMovimientos
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user