Mejora en consulta
This commit is contained in:
@@ -25,12 +25,15 @@ Public Class E72 : Implements IHttpHandler, IRequiresSessionState
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
Private Function contratoexistencia(ByVal context As HttpContext) As String
|
Private Function contratoexistencia(ByVal context As HttpContext) As String
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Dim retorno As String = ""
|
||||||
|
Dim ObjInv As New ClsInventarios
|
||||||
Try
|
Try
|
||||||
|
Dim DtMovimientos As DataTable = CreaDT()
|
||||||
|
|
||||||
Dim retorno As String = ""
|
|
||||||
Dim ObjInv As New ClsInventarios
|
|
||||||
ObjInv.GetRepEntradasSalidasXContrato(72, -1, MinFecha, Date.Now, -1, -1, 17, -1, -1, 3, -1, 1158)
|
ObjInv.GetRepEntradasSalidasXContrato(72, -1, MinFecha, Date.Now, -1, -1, 17, -1, -1, 3, -1, 1158)
|
||||||
Dim DtRepEntradasSalidasXContrato As DataTable = ObjInv.DtResultados.FiltraParametros("CvePS > 0")
|
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 DtApartados As DataTable = ObjInv.DtResultados.FiltraParametros("CvePS > 0", "", {"CvePS", "Cantidad"})
|
||||||
Dim asd As Integer = DtApartados.Rows.Count
|
Dim asd As Integer = DtApartados.Rows.Count
|
||||||
|
|
||||||
Dim DTapartado = From row In DtApartados.AsEnumerable
|
For Each tempApartados As DataRow In DtApartados.Rows
|
||||||
Group row By CvePS = row.Field(Of Integer)("CvePS") Into CvePSGroup = Group
|
For Each tempEntradasSalidas As DataRow In DtRepEntradasSalidasXContrato.Rows
|
||||||
Select New With {
|
Dim dr As DataRow = DtMovimientos.NewRow
|
||||||
Key CvePS,
|
If tempEntradasSalidas("CvePS").ToString.ToEntero = tempApartados("CvePS").ToString.ToEntero Then
|
||||||
.Cantidad = CvePSGroup.Sum(Function(r) r.Field(Of Decimal)("Cantidad"))
|
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
|
Next
|
||||||
Join apartados In DTapartado
|
Next
|
||||||
On entradas.Field(Of Integer)("CvePS") Equals apartados.CvePS
|
|
||||||
Select New With {
|
Dim dtExistencias = From row In DtMovimientos.FiltraParametros("", "", {"Codigo", "Existencia", "Cantidad", "Precio"})
|
||||||
.Codigo = entradas.Field(Of String)("Codigo"),
|
Group row By Codigo = row.Field(Of String)("Codigo"), Existencia = row.Field(Of Double)("Existencia"), Precio = row.Field(Of Double)("Precio") Into CodigoGroup = Group
|
||||||
.Existencia = entradas.Field(Of Double)("SaldoFCant"),
|
Select New With {
|
||||||
.AlmacenAlt = apartados.Cantidad,
|
.Codigo = Codigo,
|
||||||
.Precio = entradas.Field(Of Double)("PrecioVenta")
|
.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)
|
context.Response.Write(retorno)
|
||||||
ObjInv.Dispose()
|
|
||||||
Return retorno
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
|
||||||
End Try
|
End Try
|
||||||
|
ObjInv.Dispose()
|
||||||
|
Return retorno
|
||||||
End Function
|
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
|
End Class
|
||||||
Reference in New Issue
Block a user