diff --git a/Compras/Compras.aspx.vb b/Compras/Compras.aspx.vb index 4a22ead1a..1fcc023fd 100644 --- a/Compras/Compras.aspx.vb +++ b/Compras/Compras.aspx.vb @@ -10,14 +10,16 @@ Imports System Imports System.IO Imports ADServerControl Imports System.Threading.Tasks +Imports System.Diagnostics + Partial Class Compras_Compras - Inherits ClsPaginas - - - + Inherits ClsPaginas + + + #Region "Propiedades" - - 'Local + + 'Local Private Property RequiereEvaluacion() As Boolean Get Return If(IsNothing(ViewState("RequiereEvaluacion")), False, CBool(ViewState("RequiereEvaluacion"))) @@ -754,9 +756,9 @@ Partial Class Compras_Compras Set(value As Boolean) ViewState("EsNoDeducible") = value End Set - End Property + End Property #End Region - + #Region "PROPIEDADES - AC NEW" Private Property DtPresupuestos As DataTable Get @@ -773,9 +775,9 @@ Partial Class Compras_Compras Set(value As Integer) ViewState("EjercicioAC") = value End Set - End Property + End Property #End Region - + #Region " PROPIEDADES REFACTURACION " Private Property DtRefacturacion As DataTable Get @@ -816,10 +818,10 @@ Partial Class Compras_Compras Set(value As ArrayList) ViewState("ClavesBorradas") = value End Set - End Property - + End Property + #End Region - + #Region " PROPIEDADES OC " Private Property TipoCambioOC As Decimal Get @@ -836,9 +838,9 @@ Partial Class Compras_Compras Set(value As Boolean) ViewState("PopUpOC") = value End Set - End Property + End Property #End Region - + #Region "PROPIEDADES ALMACEN" 'Charlie Private Property TotalAlmacen As Decimal Get @@ -856,12 +858,12 @@ Partial Class Compras_Compras Set(value As Decimal) ViewState("TotalFlete") = value End Set - End Property + End Property #End Region - + #Region "Propiedades" - - 'CFDi + + 'CFDi Private Property Serie As String Private Property Folio As String Private Property Fecha As String @@ -1000,10 +1002,10 @@ Partial Class Compras_Compras Set(value As Integer) ViewState("FleteImportacionOpcion") = value End Set - End Property - + End Property + #End Region - + #Region " PROPIEDADES DE TOTALES " Private Property SubTotalOriginal As Double Get @@ -1060,10 +1062,10 @@ Partial Class Compras_Compras Set(value As Boolean) ViewState("ActualizaTotales") = value End Set - End Property - + End Property + #End Region - + Dim DTConceptos As DataTable Private Property EmpresasOC As List(Of Integer) Get @@ -1585,8 +1587,8 @@ Partial Class Compras_Compras 'RegistraScript("ScrollVentanaAddProducto();") - End Sub - + End Sub + #Region "C A R G A S" Private Sub CargaOrdenCorte() Dim ObjCGame As New ClsCGame() @@ -1645,10 +1647,26 @@ Partial Class Compras_Compras If IO.File.Exists(Archivo) Then Dim Validada As Boolean = True - If Not UsuarioActual.Empresa.Funcionalidad(529) = "1" Then - 'verificacion doble, si no la han cancelado, ya tiene una validaci[on para que llegue aqui - Dim Valida As New ClsValidaCFDi(dr("UUID").ToString(), dr("RFCDe").ToString, dr("RFCPara").ToString(), dr("Total").ToString.ToDecimal) - + If Not UsuarioActual.Empresa.Funcionalidad(529) = "1" Then + 'verificacion doble, si no la han cancelado, ya tiene una validaci[on para que llegue aqui + + + + + Dim SWatch As New Stopwatch + SWatch.Start() + Dim ts As New TimeSpan + + + Dim Valida As New ClsValidaCFDi(dr("UUID").ToString(), dr("RFCDe").ToString, dr("RFCPara").ToString(), dr("Total").ToString.ToDecimal) + + SWatch.Stop() + + + If SWatch.ElapsedMilliseconds >= 5000 Then + Alert("Los servicios de validacion del SAT presentan lentitud en la respuesta.", TipoMensaje.MsgAdvertencia) + End If + If UsuarioActual.CveEmpresa < 2 Then Valida.EsValida = 1 End If @@ -3609,9 +3627,9 @@ Partial Class Compras_Compras 'TmpDT = DtPSTemp.Copy 'DtPSTemp.Dispose() - End Sub + End Sub #End Region - + #Region "Vinculacion De Servcios" Private Function isAdminObraGluyas() As Boolean Return (UsuarioActual.CveRol = 1047 And UsuarioActual.CveEmpresa = 66) @@ -3638,10 +3656,10 @@ Partial Class Compras_Compras dt.Dispose() End If - End Sub - + End Sub + #End Region - + #Region "BTN'S" Protected Sub BtnVincularServicios_Click(sender As Object, e As EventArgs) Handles BtnVincularServicios.Click Dim correcto As Boolean = True @@ -15656,9 +15674,9 @@ Partial Class Compras_Compras End If End If UPCondicionesPago.Update() - End Sub - - + End Sub + + #Region " ENVIA CORREO NOTICIACION - VENDEDOR " Private Sub MandaCorreoOCVendedores(CveCompra As Integer) @@ -15863,65 +15881,65 @@ Partial Class Compras_Compras Next - End Sub - - 'VIEJO - COMENTADO IPP 12 JULIO 2017 - 'Private Sub MandaCorreo(CveCompra As Integer) - ' Dim ObjOC As New ClsOC - ' Dim DTCorreos As New DataTable - ' Dim DTFolios As New DataTable - ' Dim strBody As New StringBuilder - - ' ObjOC.GetOrdenesCompraCorreo(CveCompra) - ' DTCorreos = ObjOC.DtResultados - - ' ObjOC.GetComprasOC(CveCompra) - ' DTFolios = ObjOC.DtResultados - - ' strBody.AppendFormat("Se ha vinculado la compra {0}-{1} a la siguiente OC", Serie, Folio) - ' strBody.Append(" ") - ' strBody.Append(" ") - ' strBody.Append(" ") - ' strBody.Append(" ") - - ' 'Cargo el detalle - ' strBody.Append("
") - ' strBody.Append("
") - ' strBody.Append(" Ordenes de compra ") - ' strBody.Append(" - ' - ' ") - - ' For Each row As DataRow In DTCorreos.Rows - ' Dim Asunto, Para, ArrayCC, Body As String - ' Asunto = "Vinculación de Factura" - ' Para = row("Correo").ToString - ' ArrayCC = "" - - ' For Each RowM As DataRow In DTFolios.Rows - ' strBody.AppendFormat("", RowM("Folio").ToString, RowM("Tipo")) - ' Next - - ' strBody.Append("
FolioTipo
{0}{1}
") - ' strBody.Append("
") - ' strBody.Append("
") - ' strBody.Append("") - - ' Body = strBody.ToString - - ' ObjOC.Dispose() - - ' Dim Mail As New ClsSisMail() - ' Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) - ' Next - - 'End Sub + End Sub + + 'VIEJO - COMENTADO IPP 12 JULIO 2017 + 'Private Sub MandaCorreo(CveCompra As Integer) + ' Dim ObjOC As New ClsOC + ' Dim DTCorreos As New DataTable + ' Dim DTFolios As New DataTable + ' Dim strBody As New StringBuilder + + ' ObjOC.GetOrdenesCompraCorreo(CveCompra) + ' DTCorreos = ObjOC.DtResultados + + ' ObjOC.GetComprasOC(CveCompra) + ' DTFolios = ObjOC.DtResultados + + ' strBody.AppendFormat("Se ha vinculado la compra {0}-{1} a la siguiente OC", Serie, Folio) + ' strBody.Append(" ") + ' strBody.Append(" ") + ' strBody.Append(" ") + ' strBody.Append(" ") + + ' 'Cargo el detalle + ' strBody.Append("
") + ' strBody.Append("
") + ' strBody.Append(" Ordenes de compra ") + ' strBody.Append(" + ' + ' ") + + ' For Each row As DataRow In DTCorreos.Rows + ' Dim Asunto, Para, ArrayCC, Body As String + ' Asunto = "Vinculación de Factura" + ' Para = row("Correo").ToString + ' ArrayCC = "" + + ' For Each RowM As DataRow In DTFolios.Rows + ' strBody.AppendFormat("", RowM("Folio").ToString, RowM("Tipo")) + ' Next + + ' strBody.Append("
FolioTipo
{0}{1}
") + ' strBody.Append("
") + ' strBody.Append("
") + ' strBody.Append("") + + ' Body = strBody.ToString + + ' ObjOC.Dispose() + + ' Dim Mail As New ClsSisMail() + ' Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) + ' Next + + 'End Sub #End Region - - - + + + #End Region - + #Region " CIERRE PERIODO " Private Function ValidaCierrePeriodo() As Boolean 'solo se permiten, mes actual, mes anterior <= #dias @@ -15937,9 +15955,9 @@ Partial Class Compras_Compras ' Return True 'End If 'Return False - End Function + End Function #End Region - + #Region " AGREGA POR SERIE/LOTE " Private Sub CreaDtDetalle() If DtDatosDetalle Is Nothing Then @@ -16046,9 +16064,9 @@ Partial Class Compras_Compras Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting DtDatosDetalle.Rows.Remove(DtDatosDetalle.Rows(e.RowIndex)) CargaSerie() - End Sub + End Sub #End Region - + #Region " TIPO CAMBIO " Protected Sub DdlMoneda_SelectedIndexChanged(sender As Object, e As EventArgs) CambiaMoneda() @@ -16094,9 +16112,9 @@ Partial Class Compras_Compras Protected Sub BtnCambiaFechaTC_Click(sender As Object, e As EventArgs) LblTC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.FormatoNumero(4) TxtTC.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString.FormatoNumero(4) - End Sub + End Sub #End Region - + #Region " CONVERTIR PESOS " Protected Sub BtnConvertirPesos_Click(sender As Object, e As EventArgs) Dim TipoCambioTemp = TxtConvertirPesos.Text.ToDouble @@ -16149,9 +16167,9 @@ Partial Class Compras_Compras DdlMoneda.Enabled = False RegistraScript("$('#ModalPesos').modal('hide');") - End Sub + End Sub #End Region - + #Region " TOTALES: VALIDA Y CALCULA " Private Sub AsignaValoresOriginales(SubTotal As Double, SubTotal2 As Double, IVA As Double, RetIVA As Double, RetISR As Double, Total As Double) SubTotalOriginal = SubTotal @@ -16369,9 +16387,9 @@ Partial Class Compras_Compras Next UpPS.Update() RegistraScript(String.Format("$('#{0}').modal('hide');", "divAddAcarreo")) - End Sub + End Sub #End Region - + #Region "Historial de Modificacion" Private Sub CargaGvBitacora() ' COMENTADO POR IPP PARA SUBIR 5 ABRIL 2017 @@ -16381,11 +16399,11 @@ Partial Class Compras_Compras GvBitacora.DataBind() End If ObjGral.Dispose() - End Sub + End Sub #End Region - + #Region " FLETES " - + Private Sub CargaFletes() If UsuarioActual.CveEmpresa <> 125 Or CveCompra > 0 Then @@ -16404,13 +16422,13 @@ Partial Class Compras_Compras UpFletes.Update() ObjVentas.Dispose() - End Sub - - + End Sub + + #End Region - + #Region "I M P R I M I R D E S G L O S E" - + Private Sub LnkExportaGv_Click(sender As Object, e As EventArgs) Handles LnkExportaGv.Click Dim dt As New DataTable dt.Columns.Add("Consecutivo", GetType(Integer)) @@ -16434,14 +16452,14 @@ Partial Class Compras_Compras dt.Rows.Add(Row) Next ExportToExcel(dt, "Desglose") - End Sub - + End Sub + #End Region - - - 'DE AQUI PARA ABAJO SE ESTAN REORDENANDO REGIONES --- FAVOR DE SI SE MUEVE UNA COSITA O SE HACE UNA NUEVA FUNCION/METODO AGRUPARLO EN LA REGION CORRECTA O GENERAR UNA EN CASO DE NO EXISTIR - - + + + 'DE AQUI PARA ABAJO SE ESTAN REORDENANDO REGIONES --- FAVOR DE SI SE MUEVE UNA COSITA O SE HACE UNA NUEVA FUNCION/METODO AGRUPARLO EN LA REGION CORRECTA O GENERAR UNA EN CASO DE NO EXISTIR + + #Region " MODAL ADD PS - AGREGAR Y EDITAR PS (PARTIDA-CONCEPTO) " Private Sub HabilitaEdicionManualAgregar() If Not (CveCompra > 0 Or CveFactura > 0 Or OCVinculada) Then @@ -17149,9 +17167,9 @@ Partial Class Compras_Compras AddPS2(AplicaCalculaTotales) CargaGvInv() - End Sub + End Sub #End Region - + #Region " RECLASIFICA PARTIDAS - CLASIFICACION - SUBPROYECTO " Private Sub CargaClasificaciones() If UsuarioActual.Empresa.UsaAC Then @@ -17323,10 +17341,10 @@ Partial Class Compras_Compras Alert("Los tipos de gastos han sido cambiados correctamente", TipoMensaje.MsgInformacion) - End Sub - + End Sub + #End Region - + #Region " PS ALIAS " Protected Sub DdlPSAlias_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPSAlias2.selectedindexchange If Not DdlPSAlias2.SelectedValue = "" Then @@ -17396,9 +17414,9 @@ Partial Class Compras_Compras GlobalDTProductosServiciosEquivalencias(-1, -1) = ObjPS.DtResultados End If ObjPS.Dispose() - End Sub + End Sub #End Region - + #Region " UM: ALIAS - EQUIVALENCIAS " Private Sub CargarUMAlias() DdlUMAlias.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) @@ -17564,12 +17582,12 @@ Partial Class Compras_Compras ObjPS.Dispose() OjbUM.Dispose() - End Sub - + End Sub + #End Region - + #Region " COMPLEMENTOS PAGO " - + Private Sub CargaComplementosPago() Dim ObjCompras As New ClsCompras @@ -17597,11 +17615,11 @@ Partial Class Compras_Compras e.Row.Cells(3).Text = String.Format("", Encripta(String.Format("OP=Fact&EXT=xml&CveFactura={0}&RFC={1}", e.Row.DBCampo("CveFactura"), e.Row.DBCampo(("RFCde").ToString.Replace("&", "%26%"))))) e.Row.Cells(4).Text = String.Format("", Encripta(String.Format("OP=Fact&EXT=pdf&CveFactura={0}&RFC={1}", e.Row.DBCampo("CveFactura"), e.Row.DBCampo("RFCde").ToString.Replace("&", "%26%")))) End If - End Sub + End Sub #End Region - + #Region " OTROS GASTOS " - + Protected Sub LnkAddOtrosGastos_Click(sender As Object, e As EventArgs) DdlOrdenCorte.SelectedIndex = 0 DdlOrdenCorte.SelectedValueExist(CveOrdenCorte) @@ -17612,18 +17630,18 @@ Partial Class Compras_Compras Protected Sub BtnAddOtrosGastos_Click(sender As Object, e As EventArgs) CveOrdenCorte = DdlOrdenCorte.SelectedValue.ToEntero() RegistraScript("$('#DivOtrosGastos').modal('hide');") - End Sub - + End Sub + #End Region - - '#Region " DROPDOWN IVA " - ' 'Protected Sub DdlIVA_SelectedIndexChanged(sender As Object, e As EventArgs) - ' ' CalculaTotales(True) - ' 'End Sub - '#End Region - + + '#Region " DROPDOWN IVA " + ' 'Protected Sub DdlIVA_SelectedIndexChanged(sender As Object, e As EventArgs) + ' ' CalculaTotales(True) + ' 'End Sub + '#End Region + #Region " APLICA NC " - + Private Sub InicializaAplicaNCFact() HLAplicaNCFact.Visible = True LblTotalNC.Text = TxtTotal.Text.FormatoNumero @@ -17651,10 +17669,10 @@ Partial Class Compras_Compras e.Row.FCCheckBox("ChkFacturaNC").Attributes.Add("onclick", $"FnCambiaFacturaNC({e.Row.DBCampo("Saldo").ToDouble},{e.Row.FCTextBox("TxtImporte").ClientID},{TxtTotal.Text.ToDouble},{LblAplicado.ClientID}, this);") End If End If - End Sub - + End Sub + #End Region - + #Region " DEVOLUCION DE ALMACEN - DEVOLUCION AL PROVEEDOR " Private Sub InicializaDevolucionAlmacen() If Not GvInv.Rows.Count > 0 Or LblCompraEstatus.Text = "CANCELADA" Then @@ -17845,9 +17863,9 @@ Partial Class Compras_Compras End Sub Protected Sub BtnNCConfirmacion_Click(sender As Object, e As EventArgs) GuardaAnticipos(Nothing, Nothing) - End Sub + End Sub #End Region - + #Region " INVENTARIO: MOVIMIENTOS DE LA COMPRA " Private Sub InventarioMov() Dim ObjVentas As New ClsInventarios @@ -17885,11 +17903,11 @@ Partial Class Compras_Compras If e.Row.RowType = DataControlRowType.DataRow Then e.Row.FCLiteral("LtlImporte").Text = "$" + FormatNumber(e.Row.FCLiteral("LtlImporte").Text.ToDouble, 2, , , TriState.True) End If - End Sub - - + End Sub + + #End Region - + #Region " REGENERA PREPOLIZA " Protected Sub BtnRegenerarPrePolizaAlmacen_Click(sender As Object, e As EventArgs) 'RegeneraPrePoliza() @@ -18154,9 +18172,9 @@ Partial Class Compras_Compras ObjConta.Dispose() - End Sub + End Sub #End Region - + #Region " ACTUALIZAR TIPO CAMBIO PREPOLIZA " Private Sub InicializaActualizarTC() If CveCompra > 0 And DdlMoneda.SelectedValue.ToEntero = 2 And CvePrePoliza > 0 Then @@ -18197,16 +18215,16 @@ Partial Class Compras_Compras End If ObjContabilidad.Dispose() - End Sub + End Sub #End Region - + #Region "PAQUETERIAS GUIAS" Protected Sub LnkAgregarGuia_Click(sender As Object, e As EventArgs) '' 25/05/2018 - Se agrega Link a Modulo Paqueterias Guias RegistraScript(String.Format("AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveCompra={0}',800,620);", CveCompra)) - End Sub + End Sub #End Region - + #Region "DEDUCCIONES IEPS / OTROS IMPUESTOS" Protected Sub CargaProductos(Ddl As DropDownList, CvePS As Integer) Ddl.DataSource = TmpDT @@ -18261,11 +18279,11 @@ Partial Class Compras_Compras Alert("Debe seleccionar al menos un impuesto", TipoMensaje.MsgAdvertencia) End If - End Sub + End Sub #End Region - + #Region "C R E D I T O S" - + Private Sub ChkCreditoMultiple_CheckedChanged(sender As Object, e As EventArgs) Handles ChkCreditoMultiple.CheckedChanged If ChkCreditoMultiple.Checked Then @@ -18346,9 +18364,9 @@ Partial Class Compras_Compras UpGvCreditos.Update() - End Sub + End Sub #End Region - + #Region "FLETES / IMPORTACIONES" Private Sub CargaFolio() Dim ObjFolios As New ClsGralFolios @@ -18642,10 +18660,10 @@ Partial Class Compras_Compras Protected Sub DdlFleteImportacion_SelectedIndexChanged1(sender As Object, e As EventArgs) CambiaTipo() UpModalFletesImportaciones.Update() - End Sub - + End Sub + #End Region - + Private Function AjustarPrePolizaVinculacionOC(ByRef OC As ClsOC, ByRef OCBitacora As ClsOIEventos, ByRef ObjInventarios As ClsInventarios, ByRef ObjConta As ClsContabilidad, ByRef ObjAC As ClsContPAQi) As Boolean 'VARIABLES @@ -18884,8 +18902,8 @@ Partial Class Compras_Compras Return Retorno - End Function - + End Function + #Region "A G R E G A R - P R O D U C T O S S E R V I C I O S" Private Sub CargaDatosAgregarPS() DdlClasificacionPS.Items.Clear() @@ -18939,27 +18957,27 @@ Partial Class Compras_Compras If ObjPS.GetPSSimplificado(-1) Then Application("GlobalDTPSSimplificado") = ObjPS.DtResultados.AsEnumerable() ObjPS.Dispose() - End Sub - + End Sub + #End Region - + #Region "TIPO DE COMPRA" - + Protected Sub DdlTipoCompra_SelectedIndexChanged(sender As Object, e As EventArgs) - End Sub - + End Sub + #End Region - - + + Protected Sub BtnFacturaNC_Click(sender As Object, e As EventArgs) If ChkNCInvNC.Checked Then CargaNCINV() Else RegistraScript("$('#FacturaNC').modal('hide');", "FacturaNC") End If - End Sub - + End Sub + #Region "ES NO DEDUCIBLE" Protected Sub ChkEsNoDeducible_CheckedChanged1(sender As Object, e As EventArgs) If ChkEsNoDeducible.Checked Then @@ -18992,9 +19010,9 @@ Partial Class Compras_Compras 'TmpDT.AcceptChanges() AddPS2(EsNoDeducible:=EsNoDeducible) UpPS.Update() - End Sub + End Sub #End Region - + Public Sub LnkDesVincularComplemento_Click(sender As Object, e As EventArgs) Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)