From fe3bc2cf61049e36f47ed08e8ec192d12478a787 Mon Sep 17 00:00:00 2001 From: Julian Moreno Date: Wed, 1 Apr 2020 20:32:43 -0700 Subject: [PATCH] Error null referenceexception --- Compras/Compras.aspx.vb | 172 +++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 81 deletions(-) diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index f2811f6ab..5446d7afd 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -1295,80 +1295,83 @@ Partial Class Compras_Compras ViewState("CveFactura") = Request("CveFactura").ToEntero Dim RFC As String = CargaFactura(CveFactura) - DdlProveedor.Visible = False - HplProveedor.Visible = True - GvInv.Visible = True - CargaProveedor(-1, RFC) + If RFC.Trim <> String.Empty Then + DdlProveedor.Visible = False + HplProveedor.Visible = True + GvInv.Visible = True + CargaProveedor(-1, RFC) - If Not DdlTipoComprobante.SelectedValue = "NC" Then - If UsuarioActual.Empresa.Funcionalidad(128) = "1" And Not UsuarioActual.TienePermisoProceso(213) Then - If TmpDT.MAX("CvePS").ToEntero > 0 Then - BtnGuardar.Enabled = False - RegistraScript("$('#ImgBtnBuscarOC').click()") - End If - End If - End If - - If DdlTipoComprobante.SelectedValue = "NC" Then - paneldevolucion.Visible = True - Pnlalmaceninventarios.Visible = False - cargaddldevoluciones(CveProveedor, TxtSubTotal.Text.ToDouble) - InicializaAplicaNCFact() - DivReembolso.Visible = False - RBLPago.Items(2).Enabled = False - - End If - - - - If UsuarioActual.Empresa.UsaAC Then - CambiaEjercicioAC() - End If - - ' ''Fecha limite para ingreso de facturas - ''Dim DtEmpresa As DataTable = GlobalDTEmpresas(UsuarioActual.CveEmpresa) - ''If DtEmpresa.Rows.Count > 0 Then - '' Dim FechaLimite = DateSerial(DtEmpresa.Rows(0)("EjercicioActual").ToString.ToEntero, DtEmpresa.Rows(0)("PeriodoActual").ToString.ToEntero, DtEmpresa.Rows(0)("DiasPermitidos").ToString.ToEntero) - '' If Month(TxtFecha.Text.ToDate) < (Month(FechaLimite) - 1) Or (Month(TxtFecha.Text.ToDate) = (Month(FechaLimite) - 1) And Day(Date.Now) > Day(FechaLimite)) Then - '' Alert("La factura actual ya no aplica para ingresarse al sístema.", TipoMensaje.MsgAdvertencia) - '' BtnGuardar.Enabled = False - '' Else - '' Alert("En tiempo") - '' End If - ''Else - '' Alert("No se pudieron cargar los datos de la empresa", TipoMensaje.MsgAdvertencia) - ''End If - 'Carga Compra - - If UsuarioActual.Empresa.Funcionalidad(123).ToEntero > 0 And Not UsuarioActual.TienePermisoProceso(156) Then - If Not ValidaCierrePeriodo() Then - Alert("El periodo de la compra actual ya se encuentra cerrado. No podra registrar la compra.", TipoMensaje.MsgAdvertencia) - BtnGuardar.Visible = False - TxtOC.Enabled = False - ImgBtnBuscarOC.Enabled = False - CierrePeriodo = True - DivRestriccionAdvertencia.Visible = True - LtRestriccionAdvertencia.Text = "El periodo de la compra actual ya se encuentra cerrado." - End If - End If - - Dim HayDifIEPS As Boolean = False - For Each Gvr As GridViewRow In GvPS.Rows - If Gvr.DataKey("CvePS").ToEntero > 0 AndAlso Gvr.DataKey("IEPSPSPorcentaje").ToDouble > 0 Then - If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows.Count > 0 Then - Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows(0) - If DrPS IsNot Nothing Then - If DrPS("IEPSPorcentaje").ToString.ToDouble <> Gvr.DataKey("IEPSPSPorcentaje").ToDouble Then - HayDifIEPS = True - End If + If Not DdlTipoComprobante.SelectedValue = "NC" Then + If UsuarioActual.Empresa.Funcionalidad(128) = "1" And Not UsuarioActual.TienePermisoProceso(213) Then + If TmpDT.MAX("CvePS").ToEntero > 0 Then + BtnGuardar.Enabled = False + RegistraScript("$('#ImgBtnBuscarOC').click()") End If End If End If - Next - If HayDifIEPS Then Alert("El porcentaje de IEPS del producto no coincide con el especificado.", TipoMensaje.MsgAdvertencia) + If DdlTipoComprobante.SelectedValue = "NC" Then + paneldevolucion.Visible = True + Pnlalmaceninventarios.Visible = False + cargaddldevoluciones(CveProveedor, TxtSubTotal.Text.ToDouble) + InicializaAplicaNCFact() + DivReembolso.Visible = False + RBLPago.Items(2).Enabled = False - If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) + End If + + + + If UsuarioActual.Empresa.UsaAC Then + CambiaEjercicioAC() + End If + + ' ''Fecha limite para ingreso de facturas + ''Dim DtEmpresa As DataTable = GlobalDTEmpresas(UsuarioActual.CveEmpresa) + ''If DtEmpresa.Rows.Count > 0 Then + '' Dim FechaLimite = DateSerial(DtEmpresa.Rows(0)("EjercicioActual").ToString.ToEntero, DtEmpresa.Rows(0)("PeriodoActual").ToString.ToEntero, DtEmpresa.Rows(0)("DiasPermitidos").ToString.ToEntero) + '' If Month(TxtFecha.Text.ToDate) < (Month(FechaLimite) - 1) Or (Month(TxtFecha.Text.ToDate) = (Month(FechaLimite) - 1) And Day(Date.Now) > Day(FechaLimite)) Then + '' Alert("La factura actual ya no aplica para ingresarse al sístema.", TipoMensaje.MsgAdvertencia) + '' BtnGuardar.Enabled = False + '' Else + '' Alert("En tiempo") + '' End If + ''Else + '' Alert("No se pudieron cargar los datos de la empresa", TipoMensaje.MsgAdvertencia) + ''End If + 'Carga Compra + + If UsuarioActual.Empresa.Funcionalidad(123).ToEntero > 0 And Not UsuarioActual.TienePermisoProceso(156) Then + If Not ValidaCierrePeriodo() Then + Alert("El periodo de la compra actual ya se encuentra cerrado. No podra registrar la compra.", TipoMensaje.MsgAdvertencia) + BtnGuardar.Visible = False + TxtOC.Enabled = False + ImgBtnBuscarOC.Enabled = False + CierrePeriodo = True + DivRestriccionAdvertencia.Visible = True + LtRestriccionAdvertencia.Text = "El periodo de la compra actual ya se encuentra cerrado." + End If + End If + + Dim HayDifIEPS As Boolean = False + For Each Gvr As GridViewRow In GvPS.Rows + If Gvr.DataKey("CvePS").ToEntero > 0 AndAlso Gvr.DataKey("IEPSPSPorcentaje").ToDouble > 0 Then + If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows.Count > 0 Then + Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Gvr.DataKey("CvePS").ToEntero).Rows(0) + If DrPS IsNot Nothing Then + If DrPS("IEPSPorcentaje").ToString.ToDouble <> Gvr.DataKey("IEPSPSPorcentaje").ToDouble Then + HayDifIEPS = True + End If + End If + End If + End If + Next + + If HayDifIEPS Then Alert("El porcentaje de IEPS del producto no coincide con el especificado.", TipoMensaje.MsgAdvertencia) + + If UsuarioActual.Empresa.Funcionalidad(562).ToEntero > 0 Then CargaGastosServicios(UsuarioActual.Empresa.Funcionalidad(562).ToEntero) + + End If ElseIf Request("CveCompra") IsNot Nothing AndAlso IsNumeric(Request("CveCompra")) AndAlso Request("CveCompra").ToEntero > 0 Then @@ -1741,10 +1744,14 @@ Partial Class Compras_Compras XMLDoc.Load(Archivo) Catch ex As Exception + Try + Dim oReader = New StreamReader(Archivo, Encoding.GetEncoding("ISO-8859-1")) + XMLDoc.Load(oReader) + oReader.Dispose() + Catch ex As Exception + GuardaLog("Error al intentar leer el XML del SAT. Error:" & ex.ToString()) + End Try - Dim oReader = New StreamReader(Archivo, Encoding.GetEncoding("ISO-8859-1")) - XMLDoc.Load(oReader) - oReader.Dispose() End Try @@ -2083,19 +2090,22 @@ Partial Class Compras_Compras ObjeFacturas.Dispose() - Dim ObjSAT As New ClsSAT - Dim RFCRequest As String = Request("RFC").ToString - If ObjSAT.GetListado69B(2, UsuarioActual.CveEmpresa, RFCRequest) Then - If ObjSAT.DtResultados.Rows.Count > 0 Then - Dim Estatus As String = ObjSAT.DtResultados.Rows(0)("Situacion").ToString - BtnGuardar.Enabled = False - UpParametros.Update() + If RFC <> "" Then + Dim ObjSAT As New ClsSAT - Alert($"El RFC del proveedor se encuentra en estado {Estatus} en el Listado EFOS (69B) del SAT", TipoMensaje.MsgAdvertencia) - System.Threading.Thread.Sleep(5) + If ObjSAT.GetListado69B(2, UsuarioActual.CveEmpresa, RFC) Then + If ObjSAT.DtResultados.Rows.Count > 0 Then + Dim Estatus As String = ObjSAT.DtResultados.Rows(0)("Situacion").ToString + BtnGuardar.Enabled = False + UpParametros.Update() + + Alert($"El RFC del proveedor se encuentra en estado {Estatus} en el Listado EFOS (69B) del SAT", TipoMensaje.MsgAdvertencia) + System.Threading.Thread.Sleep(5) + End If End If + ObjSAT.Dispose() End If - ObjSAT.Dispose() + Return RFC