diff --git a/Inventarios/TraspasoAlmacen.aspx b/Inventarios/TraspasoAlmacen.aspx index eaf48f3d2..205a68a17 100644 --- a/Inventarios/TraspasoAlmacen.aspx +++ b/Inventarios/TraspasoAlmacen.aspx @@ -443,6 +443,7 @@ + @@ -456,7 +457,7 @@ - + diff --git a/Inventarios/TraspasoAlmacen.aspx.vb b/Inventarios/TraspasoAlmacen.aspx.vb index 35736ad6d..11fe12c31 100644 --- a/Inventarios/TraspasoAlmacen.aspx.vb +++ b/Inventarios/TraspasoAlmacen.aspx.vb @@ -526,19 +526,73 @@ Partial Class Inventarios_TraspasoAlmacen DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CveProducto).FiltroPrimero("") ' Estado = -1 - If Cantidad > 0 AndAlso DrPS("VentaMinima").ToString.ToDecimal > 0 Then - 'verifico que la cantidad sea multiplo de venta minima, es decir ventaminima =5, solo puede vender 5,10,15... - If Cantidad Mod DrPS("VentaMinima").ToString.ToDecimal <> 0 Then - Alert(String.Format("El producto se vende solo en cantidades de {0:#,###.####}", DrPS("VentaMinima"))) - Exit Sub + If DrPS IsNot Nothing Then + + If Cantidad > 0 AndAlso DrPS("VentaMinima").ToString.ToDecimal > 0 Then + 'verifico que la cantidad sea multiplo de venta minima, es decir ventaminima =5, solo puede vender 5,10,15... + If Cantidad Mod DrPS("VentaMinima").ToString.ToDecimal <> 0 Then + Alert(String.Format("El producto se vende solo en cantidades de {0:#,###.####}", DrPS("VentaMinima"))) + Exit Sub + End If End If - End If - Dim Valido = ValidaExistencia(Cantidad, CveProducto, DdlUnidad.SelectedValue.ToEntero, DdlSeccionAlmacen.SelectedValue.ToEntero, If(TxtnSerie.Visible, TxtnSerie.Text, "-1"), If(TxtnLote.Visible, TxtnLote.Text, "-1"), If(TxtnFechaCaducidad.Visible, TxtnFechaCaducidad.Text.ToDate, MinFecha)) + 'codigo provisional. + Dim CveSubP As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacenOrigen.selectedvalue.toentero).FiltroPrimeroValor("CveSubProyecto", "").ToEntero + + + If DrPS("AplicaCaducidad").ToString = "True" AndAlso ChkSugiereFechaCaducidad.checked And CveSubP.Contiene(10276) Then + + Dim ObjInventarios As New ClsInventarios + If ObjInventarios.GetExistenciasCaducidad(CveProducto, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.selectedvalue) Then + Dim dtt As DataTable = ObjInventarios.DtResultados + + If Cantidad > dtt.SUMD("Cantidad") Then + Alert("No se cuenta con la cantidad requerida") + Else + 'recorro las existencias para tomar la cantidad + Dim i As Decimal = 0 + Dim CantidadRestante As Decimal = Cantidad + For Each drr As DataRow In dtt.Rows + If drr("Cantidad").ToString.ToDecimal < CantidadRestante Then + i = drr("Cantidad").ToString.ToDecimal + Else + i = CantidadRestante + End If + AgregarPS(i, CveProducto, DdlUnidad.SelectedValue.ToEntero, TxtnObservaciones.Text, CveSeccionAlmacen:=DdlSeccionAlmacen.SelectedValue.ToEntero, SeccionAlmacen:=DdlSeccionAlmacen.SelectedItem.Text, Lote:=drr("Lote").ToString, FechaCaducidad:=drr("FechaCaducidad").ToString.ToDate, CveSeccionAlmacenDestino:=DdlSeccionAlmacenDestino.SelectedValue.ToEntero, Limpia:=FuncionalidadSinSerie) + CantidadRestante -= i + If CantidadRestante <= 0 Then Exit For + Next + End If + + End If + + ObjInventarios.Dispose() + + Else + + 'codigo temporal + Dim tLote As String + Dim tCaducidad As Date + + tLote = If(TxtnLote.Visible, TxtnLote.Text, "-1") + tCaducidad = If(TxtnFechaCaducidad.Visible, TxtnFechaCaducidad.Text.ToDate, MinFecha) + + If CveSubP <> 10276 Then + tLote = "-1" + tCaducidad = MinFecha + End If + + + Dim Valido = ValidaExistencia(Cantidad, CveProducto, DdlUnidad.SelectedValue.ToEntero, DdlSeccionAlmacen.SelectedValue.ToEntero, If(TxtnSerie.Visible, TxtnSerie.Text, "-1"), tLote, tCaducidad) + + If Valido Then + AgregarPS(Cantidad, CveProducto, DdlUnidad.SelectedValue.ToEntero, TxtnObservaciones.Text, CveSeccionAlmacen:=DdlSeccionAlmacen.SelectedValue.ToEntero, SeccionAlmacen:=DdlSeccionAlmacen.SelectedItem.Text, Serie:=If(TxtnSerie.Visible, TxtnSerie.Text, ""), Lote:=If(tLote = "-1", "", tLote), FechaCaducidad:=tCaducidad, CveSeccionAlmacenDestino:=DdlSeccionAlmacenDestino.SelectedValue.ToEntero, Limpia:=FuncionalidadSinSerie) + End If + + End If + + End If - If Valido Then - AgregarPS(Cantidad, CveProducto, DdlUnidad.SelectedValue.ToEntero, TxtnObservaciones.Text, CveSeccionAlmacen:=DdlSeccionAlmacen.SelectedValue.ToEntero, SeccionAlmacen:=DdlSeccionAlmacen.SelectedItem.Text, Serie:=If(TxtnSerie.Visible, TxtnSerie.Text, ""), Lote:=If(TxtnLote.Visible, TxtnLote.Text, ""), FechaCaducidad:=If(TxtnFechaCaducidad.Visible, TxtnFechaCaducidad.Text.ToDate, MinFecha), CveSeccionAlmacenDestino:=DdlSeccionAlmacenDestino.SelectedValue.ToEntero, Limpia:=FuncionalidadSinSerie) - End If End If End Sub @@ -550,26 +604,39 @@ Partial Class Inventarios_TraspasoAlmacen Dim Inv As New ClsInventarios Dim Existencia As Decimal = Inv.GetExistenciasPS(CvePS, CveUnidadMedida, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), PendientePorSurtir:=1) - 'la primera vez valida, que la existencia global, cumpla, considerando lo pendiente por surtir - 'las segunda consulta, que tenga existencia, ya con los parametros especificos - If FechaCaducidad > MinFecha OrElse Serie <> "" OrElse Lote <> "" Then - ExistenciaEspecificada = Inv.GetExistenciasPS(CvePS, CveUnidadMedida, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), CveSeccionAlmacen:=CveSeccionAlmacen, Serie:=Serie, Lote:=Lote, FechaCaducidad:=FechaCaducidad, PendientePorSurtir:=-1) - Else - ExistenciaEspecificada = Existencia - End If - Inv.Dispose() - If Existencia - Cantidad - CantidadEnGrid < 0 OrElse ExistenciaEspecificada - Cantidad - CantidadEnGrid < 0 Then - If Existencia < 0 OrElse ExistenciaEspecificada < 0 Then - Alert("No hay existencia del producto", TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") + If Existencia > 0 Then + 'la primera vez valida, que la existencia global, cumpla, considerando lo pendiente por surtir + 'las segunda consulta, que tenga existencia, ya con los parametros especificos + If (FechaCaducidad > MinFecha OrElse Serie <> "" OrElse Lote <> "") Then + ExistenciaEspecificada = Inv.GetExistenciasPS(CvePS, CveUnidadMedida, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), CveSeccionAlmacen:=CveSeccionAlmacen, Serie:=Serie, Lote:=Lote, FechaCaducidad:=FechaCaducidad, PendientePorSurtir:=-1) + Dim StrB As New stringbuilder + StrB.appendformat("CvePS = {0} AND CveUM = {1} ", CvePS, CveUnidadMedida) + If Serie <> "" Then StrB.appendformat(" AND Serie = '{0}' ", Serie) + If Lote <> "" Then StrB.appendformat(" AND Lote = '{0}' ", Lote) + If FechaCaducidad.ToDate > MinFecha Then StrB.appendformat(" AND FechaCaducidad = '{0}' ", FechaCaducidad.ToShortDateString) + Dim CantidadEspecificaEnGrid As Decimal = DtMovimientos.SUMD("Cantidad", StrB.tostring) + + If ExistenciaEspecificada - Cantidad - CantidadEspecificaEnGrid < 0 Then + Alert(String.Format("Solo hay en existencia: {0:#,###.##}", ExistenciaEspecificada), TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") + Retorno = False + End If Else - Alert(String.Format("Solo hay en existencia: {0}", Existencia), TipoMensaje.MsgAdvertencia) - RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") + ExistenciaEspecificada = Existencia + If Existencia - Cantidad - CantidadEnGrid < 0 Then + Alert(String.Format("Solo hay en existencia: {0:#,###.##}", ExistenciaEspecificada), TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") + Retorno = False + End If End If - Retorno = False + Else + Alert("No hay existencia del producto", TipoMensaje.MsgAdvertencia) + RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") End If + Inv.Dispose() + Return Retorno End Function Private Sub AgregarPS(Cantidad As Double, CvePS As Integer, CveUnidadMedida As Integer, Optional Observaciones As String = "", Optional CveSeccionAlmacen As Integer = -1, Optional SeccionAlmacen As String = "", Optional Serie As String = "", Optional Lote As String = "", Optional FechaCaducidad As Date = MinFecha, Optional Limpia As Boolean = True, Optional CveSeccionAlmacenDestino As Integer = -1) @@ -1482,6 +1549,13 @@ Partial Class Inventarios_TraspasoAlmacen ' CargaGvDatos() 'End Sub + Protected Sub ChkSugiereFechaCaducidad_CheckedChanged(sender As Object, e As EventArgs) + + TxtnFechaCaducidad.visible = Not ChkSugiereFechaCaducidad.checked + TxtnLote.visible = Not ChkSugiereFechaCaducidad.checked + + End Sub + #End Region