Imports Extensiones Partial Class Inventarios_PrestamosdeProveedor Inherits ClsPaginas Private Sub Inventarios_PrestamosdeProveedor_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then CargaCombos() CargaDatos() End If End Sub Private Sub CargaCombos() RVFechaEntrega.MaximumValue = Now.ToShortDateString ddlProveedor.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") If ddlProveedor.UsaWebService Then ddlProveedor.Attributes.Add("data-metodo", "getproveedores") Else ddlProveedor.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) ddlProveedor.DataBind() ddlProveedor.SelectedValue = "-1" ddlProveedor.SelectedText = "Seleccione el Proveedor" End If DdlAlmacenOrigen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1) DdlAlmacenOrigen.DataBind() End Sub Private Sub CargaDatos() Dim tCveProveedor As Integer = -1 Dim tFolio As Integer = -1 If ddlProveedor.SelectedValue.ToEntero > 0 Then tCveProveedor = ddlProveedor.SelectedValue.ToEntero If TxtFolioEntrega.Text <> "" Then tFolio = TxtFolioEntrega.Text.ToEntero Dim ObjInv As New ClsInventarios If ObjInv.PrestamosdeProveedorGet(tCveProveedor, tFolio, UsuarioActual.CveEmpresa) Then GvD.DataSource = ObjInv.DtResultados Dim Dr As Data.DataRow = ObjInv.DtResultados.FiltroPrimero("") If Dr IsNot Nothing Then HdnCveProveedor.Value = Dr("CveProveedor") End If End If ObjInv.Dispose() GvD.DataBind() UppEntrega.Update() End Sub Protected Sub GvD_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvD.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'Cuando es titulo If e.Row.DBCampo("PS").ToString.Trim = "" Then e.Row.CssClass = "Totales" e.Row.FCCheckBox("Chk").Visible = False e.Row.FCTextBox("TxtCantidad").Visible = False e.Row.Cells(2).Text = String.Format("Folio: {0} ", e.Row.DBCampo("FolioSalida"), e.Row.DBCampo("CveMovimientoSalida")) e.Row.Cells(3).Text = String.Format("{0}", e.Row.DBCampo("FechaMovto").ToString.ToDate.ToShortDateString) e.Row.Cells(5).Text = String.Format("Proveedor: {0} ", e.Row.DBCampo("RazonSocial")) Else If TxtFolioEntrega.Text <> "" Then e.Row.FCCheckBox("Chk").Visible = True e.Row.FCTextBox("TxtCantidad").Enabled = True End If e.Row.FCTextBox("TxtCantidad").Visible = True e.Row.FCTextBox("TxtCantidad").Attributes.Add("onkeyup", String.Format("ValidaCantidad(this,{0});", e.Row.DBCampo("Cantidad"))) End If ''FUNCIONALIDAD PISTOLA DE CODIGOS 'If UsuarioActual.Empresa.Funcionalidad(132) = "1" And e.Row.DBCampo("CodigoBarras").Trim <> "" Then ' e.Row.FCTextBox("TxtCantidad").Enabled = False 'End If End If End Sub Protected Sub BtnRecibir_Click(sender As Object, e As EventArgs) If GvD.Rows.Count > 0 Then 'Valida Movimientos Dim ValidaMovtos = 0.0 For Each gvr As GridViewRow In GvD.Rows If gvr.FCCheckBox("Chk").Checked AndAlso gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then ValidaMovtos += gvr.FCTextBox("TxtCantidad").Text.ToDecimal If gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then Dim SerieLote As String = "-1" Dim Lote As String = "-1" Dim Batch As String = "-1" If gvr.DataKey("SerieLote") <> "" Then SerieLote = gvr.DataKey("SerieLote") If gvr.DataKey("Lote") <> "" Then Lote = gvr.DataKey("Lote") If gvr.DataKey("Batch") <> "" Then Batch = gvr.DataKey("Batch") Dim Valido = ValidaExistencia(gvr.FCTextBox("TxtCantidad").Text.ToDecimal, gvr.DataKey("CvePS").ToEntero, gvr.DataKey("CveUM").ToEntero, SerieLote, Lote, Batch) If Not Valido Then Alert("No hay existencia del producto a devolver.", TipoMensaje.MsgAdvertencia) Exit Sub End If End If End If Next If Not ValidaMovtos > 0 Then Alert("No hay movimientos que realizar. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjInventario As New ClsInventarios Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) Dim CveMovimientoEntrada As Integer = 0 Dim Folio = 0 Dim ErrorMovInv As Boolean = False Dim TextoError = "" 'REGISTRA LA SALIDA Y ENTRADA (TRASPASO) Dim Fecha As Date = TxtFechaEntrega.Text.ToDate Dim CveMovimientoSalida As Integer Dim tCveProveedor As Integer = HdnCveProveedor.Value.ToEntero Dim CvePS As Integer = 0 'AGREGAMOS LA SALIDA CveMovimientoSalida = ObjInventario.AddMovimiento(DdlAlmacenOrigen.SelectedValue.ToEntero, 29, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservacionesEntrega.Text.Trim, CveProveedor:=tCveProveedor) Folio = ObjInventario.Folio If CveMovimientoSalida <= 0 Then TextoError = "No se pudo generar el movimiento de salida correctamente" ErrorMovInv = True Else Dim CveMovimientoDetalleEntrada As Integer = 0 For Each gvr As GridViewRow In GvD.Rows If gvr.FCCheckBox("Chk").Checked AndAlso gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal > 0 Then CveMovimientoDetalleEntrada = gvr.DataKey("CveMovimientoDetalle").ToString.ToEntero CvePS = gvr.DataKey("CvePS").ToString.ToEntero If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal, gvr.DataKey("CveUM").ToString.ToEntero, gvr.DataKey("CvePS").ToString.ToEntero, 0, -1, CveMovimientoDetalleEntrada:=CveMovimientoDetalleEntrada, SerieLote:=gvr.DataKey("SerieLote").ToString, Lote:=gvr.DataKey("Lote").ToString, Batch:=gvr.DataKey("Batch").ToString) Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de salida" Exit For End If End If Next 'faltan las prepólizas If Not ErrorMovInv AndAlso ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inv/PrestamodeProvedor", 53, 0, 0, 1, Fecha, $" {TxtObservacionesEntrega.Text}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3) Dim tValorInventario As Decimal = ObjInventario.DtResultados.SUM("Total", "").ToDecimal.RoundSQL() Dim idCtaContable As Integer = 0 Dim IdCtaContableOtro As Integer = UsuarioActual.Empresa.IdCuentaOtrosIngresos Dim TipoMovtoAlmacen As Boolean = False Dim drA2 As Data.DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", DdlAlmacenOrigen.SelectedValue)) If drA2 IsNot Nothing Then idCtaContable = drA2("IdCtaContable").ToString.ToEntero Dim OrigenMov As Integer = GlobalDTInvConceptos.FiltroPrimeroValor("Origen", "CveConcepto = 29").ToEntero If OrigenMov = 1 Then TipoMovtoAlmacen = False Else TipoMovtoAlmacen = True Dim CveConceptoContable As Integer = 69 Dim CveClasifCosto As Integer = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveClasificacion", String.Format("CvePS ={0} ", CvePS)) IdCtaContableOtro = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {CveClasifCosto}").ToEntero If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, TipoMovtoAlmacen, tValorInventario, TxtObservacionesEntrega.Text.Trim, 68, TxtObservacionesEntrega.Text.Trim, Fecha, idCtaContable, -1, CveMovimientoAlmacen:=CveMovimientoSalida, ImporteMX:=tValorInventario) Then ErrorMovInv = True Else If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovtoAlmacen, tValorInventario, TxtObservacionesEntrega.Text.Trim, CveConceptoContable, TxtObservacionesEntrega.Text.Trim, Fecha, IdCtaContableOtro, -1, CveMovimientoAlmacen:=CveMovimientoSalida, CveClasificacion:=CveClasifCosto, ImporteMX:=tValorInventario) Then ErrorMovInv = True End If End If Else ErrorMovInv = True End If End If If Not ErrorMovInv Then ObjInventario.Commit() TxtRecibio.Text = "" TxtFechaEntrega.Text = Now.ToShortDateString TxtObservacionesEntrega.Text = "" HdnCveProveedor.Value = "" Dim Mensaje As StringBuilder = New StringBuilder Mensaje.AppendFormat("Se realizo correctamente la recepción.
Folio de Salida: {0}", Folio, CveMovimientoSalida) Mensaje.AppendFormat("
Imprimir Reporte", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida))) 'onclick='ImprimirTraslado()' Alert(Mensaje.ToString, TipoMensaje.MsgInformacion) GvD.DataBind() CargaDatos() UPDatosAlmacen.Update() Else ObjInventario.RollBack() Alert(TextoError, TipoMensaje.MsgError) End If ObjInventario.Dispose() ' CargaEntrega() Else Alert("No hay movimientos por devolver", TipoMensaje.MsgAdvertencia) End If End Sub Private Function ValidaExistencia(Cantidad As Double, CvePS As Integer, CveUnidadMedida As Integer, Optional SerieLote As String = "-1", Optional Lote As String = "-1", Optional Batch As String = "-1") As Boolean Dim Retorno = True Dim Inv As New ClsInventarios Dim Existencia As Double = Inv.GetExistenciasPS(CvePS, CveUnidadMedida, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFechaEntrega.Text.ToDate.ToString("yyyy/MM/dd 23:59"), SerieLote:=SerieLote, Lote:=Lote, Batch:=Batch) Inv.Dispose() '- DtMovimientos.SUM("Cantidad", $"CvePS = {CvePS} AND CveUM = {CveUnidadMedida} {If(SerieLote <> "-1", $" AND SerieLote = '{SerieLote}'", "")}") If Existencia - Cantidad < 0 Then If Existencia < 0 Then Alert("No hay existencia del producto", TipoMensaje.MsgAdvertencia) Else Alert(String.Format("Solo hay en existencia: {0}", Existencia), TipoMensaje.MsgAdvertencia) End If Retorno = False End If Return Retorno End Function Private Sub BtnCargaPendientes_Click(sender As Object, e As EventArgs) Handles BtnCargaPendientes.Click CargaDatos() End Sub End Class