--Validaciones posteriores al guardar venta

This commit is contained in:
2024-11-22 21:05:24 -07:00
parent 06c85ad5d6
commit f9932906a8

View File

@@ -10638,6 +10638,8 @@ Partial Class Ventas
If ObjFactura.CveCliente > 0 Or CveEmpresaCRM > 0 Then If ObjFactura.CveCliente > 0 Or CveEmpresaCRM > 0 Then
If TmpDT.Rows.Count > 0 Then If TmpDT.Rows.Count > 0 Then
BtnEmitirImprimir.Enabled = False
Dim ObjVentas As New ClsVentas() Dim ObjVentas As New ClsVentas()
Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL())
Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL()) Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL())
@@ -11088,469 +11090,482 @@ Partial Class Ventas
BtnEmitirImprimir.Visible = False BtnEmitirImprimir.Visible = False
ObjFactura.DtDetalle = TmpDT 'actualiza por cambios de pedimentos.
ObjFactura.Timbre = PreParaTimbre(ObjFactura)
'LIMPIA LOS ANTICIPOS RELACIONADOS QUE YA SE APLICARON
If ListaAnticiposAplicados IsNot Nothing Then
ListaAnticiposAplicados.Clear()
End If
If ListaDevolucionesAplicadas IsNot Nothing Then
ListaDevolucionesAplicadas.Clear()
End If
'ENVIAR POLIZA VIRTUAL
If ErrorList.Count = 0 Then
If UsuarioActual.Empresa.Funcionalidad(576) = "1" AndAlso EsProduccion Then
GeneraPolizaVentaWS(ObjFactura)
End If
End If
'Try
' 'RMF, cuando es pedido, se manda autorización.
' If ObjFactura.TipoDocto.Contiene("PA") Then
' Dim Titulo As String = "Solicitud de autorización" 'usuarios de crédito y cobranza
' Dim Msg As String = String.Format("{0} - Folio {1} ", DdlSubProyectoDatos.SelectedItem.Text, TxtFolio.Text)
' 'If UsuarioActual.CveEmpresa = 119 Then
' ' ClsSisNotificaciones.SendNotificacionERP(1715, Titulo, Msg, 1)
' ' ClsSisNotificaciones.SendNotificacionERP(1815, Titulo, Msg, 1)
' ' ClsSisNotificaciones.SendNotificacionERP(1830, Titulo, Msg, 1)
' 'End If
' End If
'Catch ex As Exception
' OnError("Ocurrió un error al mandar las notificaciones de autorización", ex)
'End Try
Try Try
Dim DirectoriArchivoXML As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto) ' System.IO.Path.Combine() 'MENSAJE PRINCIPAL
If Not Directory.Exists(DirectoriArchivoXML) Then MensajeAlert.AppendFormat(String.Format("<br/>La {0}: <b>{1}</b> se generó correctamente.<br/><br/>", ObjFactura.TipoDocumento, ObjFactura.SerieFolio))
Directory.CreateDirectory(DirectoriArchivoXML)
ObjFactura.DtDetalle = TmpDT 'actualiza por cambios de pedimentos.
ObjFactura.Timbre = PreParaTimbre(ObjFactura)
'Throw New Exception("Prueba error")
'LIMPIA LOS ANTICIPOS RELACIONADOS QUE YA SE APLICARON
If ListaAnticiposAplicados IsNot Nothing Then
ListaAnticiposAplicados.Clear()
End If End If
Catch ex As Exception
OnError("Ocurrió un error al generar el directorio de xml", ex)
End Try
Dim SeTimbro As Boolean = False If ListaDevolucionesAplicadas IsNot Nothing Then
Dim SeTimbroNC As Boolean = False ListaDevolucionesAplicadas.Clear()
Dim EstatusSMS As Integer = 0 End If
Dim MsgErrorTimbrado As String = ""
Dim MsgCancelacionRefacturacion As Modelos.Factura.MCancelacionVentaMensaje = Nothing 'ENVIAR POLIZA VIRTUAL
If ErrorList.Count = 0 Then
'TIMBRADO Y CASO ESPECIAL NOTA DE CREDITO If UsuarioActual.Empresa.Funcionalidad(576) = "1" AndAlso EsProduccion Then
If (TipoDoctoDevolucion = "" OrElse Not TipoDoctoDevolucion.Contiene("Rem", "RNC", "Cot", "Ped", "DPe", "PA", "Ped")) Then GeneraPolizaVentaWS(ObjFactura)
Dim DebeTimbrar As Boolean = True
If UsuarioActual.CveEmpresa.Contiene(1, 72, 80) Then
'si tiene anticipos seleccionados y el total es cero, que no se timbre(previo empresa72)
If LblAmortizacion.Text.ToDouble > 0 And TxtTotal.Text.ToDouble <= 0 Then
DebeTimbrar = False
End If End If
End If End If
'Si es AMORTIZACIÓN ANTICIPO SOBRE FACTURA EN CERO no debe timbrar 'Try
If DdlTipoAmortizacionAnticipo.SelectedValue = "3" Then ' 'RMF, cuando es pedido, se manda autorización.
DebeTimbrar = False ' If ObjFactura.TipoDocto.Contiene("PA") Then
End If
If UsuarioActual.TienePermisoProceso(335) Then ' Dim Titulo As String = "Solicitud de autorización" 'usuarios de crédito y cobranza
DebeTimbrar = False ' Dim Msg As String = String.Format("{0} - Folio {1} ", DdlSubProyectoDatos.SelectedItem.Text, TxtFolio.Text)
End If ' 'If UsuarioActual.CveEmpresa = 119 Then
' ' ClsSisNotificaciones.SendNotificacionERP(1715, Titulo, Msg, 1)
' ' ClsSisNotificaciones.SendNotificacionERP(1815, Titulo, Msg, 1)
' ' ClsSisNotificaciones.SendNotificacionERP(1830, Titulo, Msg, 1)
' 'End If
If DebeTimbrar AndAlso ObjFactura.TipoDocto.Contiene("Ing", "Egs", "Ant", "Dev") Then ' End If
If UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso (UsuarioActual.Empresa.FacturaProduccion OrElse UsuarioActual.CveEmpresa = 1) Then 'Catch ex As Exception
' OnError("Ocurrió un error al mandar las notificaciones de autorización", ex)
'End Try
'FACTURA INGRESO/EGRESO
Dim FM As New Modelos.FemsaFactura
Dim TmpDT7Eleven As New DataTable
Dim TmpDTComplementosTimbrado As New DataTable
Dim ObjTimbrado As New Timbrado
Try
If AplicaFEMSA Then
PrepararTimbrado(FM, TmpDT7Eleven, TmpDTComplementosTimbrado)
End If
If ChkEmitirCartaPorte.Checked AndAlso CveTimbreCartaPorte > 0 Then Try
Dim RespCartaPorte As Timbres.MMensajeCartaPorte = Timbres.PreParaCartaPorteFactura(CveTimbreCartaPorte, UsuarioActual) Dim DirectoriArchivoXML As String = String.Format("{0}{1}", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto) ' System.IO.Path.Combine()
If Not RespCartaPorte.TieneError Then If Not Directory.Exists(DirectoriArchivoXML) Then
ObjFactura.Timbre.Complementos.CartaPorte = RespCartaPorte.CartaPorte Directory.CreateDirectory(DirectoriArchivoXML)
Else End If
DebeTimbrar = False Catch ex As Exception
Alert(RespCartaPorte.Mensaje, TipoMensaje.MsgAdvertencia) OnError("Ocurrió un error al generar el directorio de xml", ex)
End If End Try
End If
If DebeTimbrar Then Dim SeTimbro As Boolean = False
SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura) Dim SeTimbroNC As Boolean = False
End If Dim EstatusSMS As Integer = 0
Catch ex As Exception Dim MsgErrorTimbrado As String = ""
OnError("Ocurrió un error al generar el timbrado", ex)
End Try
Dim FolioFiscalFactura As String = ObjTimbrado.UUID Dim MsgCancelacionRefacturacion As Modelos.Factura.MCancelacionVentaMensaje = Nothing
MsgErrorTimbrado = ObjTimbrado.MensajeErrorCFDI
ObjTimbrado = Nothing
'NOTA DE CREDITO - REFACTURADA - CASO ESPECIAL, TIMBRADO E IMPRESION 'TIMBRADO Y CASO ESPECIAL NOTA DE CREDITO
If DebeTimbrar AndAlso SeTimbro AndAlso ListaNotasCreditoGeneradas IsNot Nothing AndAlso ListaNotasCreditoGeneradas.Count > 0 Then If (TipoDoctoDevolucion = "" OrElse Not TipoDoctoDevolucion.Contiene("Rem", "RNC", "Cot", "Ped", "DPe", "PA", "Ped")) Then
Dim DebeTimbrar As Boolean = True
If UsuarioActual.CveEmpresa.Contiene(1, 72, 80) Then
'si tiene anticipos seleccionados y el total es cero, que no se timbre(previo empresa72)
If LblAmortizacion.Text.ToDouble > 0 And TxtTotal.Text.ToDouble <= 0 Then
DebeTimbrar = False
End If
End If
'Si es AMORTIZACIÓN ANTICIPO SOBRE FACTURA EN CERO no debe timbrar
If DdlTipoAmortizacionAnticipo.SelectedValue = "3" Then
DebeTimbrar = False
End If
If UsuarioActual.TienePermisoProceso(335) Then
DebeTimbrar = False
End If
If DebeTimbrar AndAlso ObjFactura.TipoDocto.Contiene("Ing", "Egs", "Ant", "Dev") Then
If UsuarioActual.Empresa.TipoFacturacion = "CFDi" AndAlso (UsuarioActual.Empresa.FacturaProduccion OrElse UsuarioActual.CveEmpresa = 1) Then
'FACTURA INGRESO/EGRESO
Dim FM As New Modelos.FemsaFactura
Dim TmpDT7Eleven As New DataTable
Dim TmpDTComplementosTimbrado As New DataTable
Dim ObjTimbrado As New Timbrado
Try Try
For Each NCGenerada As Modelos.Factura In ListaNotasCreditoGeneradas If AplicaFEMSA Then
If NCGenerada.Timbre IsNot Nothing Then PrepararTimbrado(FM, TmpDT7Eleven, TmpDTComplementosTimbrado)
NCGenerada.Timbre.CFDIRelacionados.UUID.Clear() End If
NCGenerada.Timbre.CFDIRelacionados.UUID.Add(FolioFiscalFactura)
Dim ObjTimbradoNC As New Timbrado If ChkEmitirCartaPorte.Checked AndAlso CveTimbreCartaPorte > 0 Then
Dim TimbroNC As Boolean = ObjTimbradoNC.TimbrarFactura(UsuarioActual, NCGenerada) Dim RespCartaPorte As Timbres.MMensajeCartaPorte = Timbres.PreParaCartaPorteFactura(CveTimbreCartaPorte, UsuarioActual)
If Not RespCartaPorte.TieneError Then
If Not TimbroNC Then ObjFactura.Timbre.Complementos.CartaPorte = RespCartaPorte.CartaPorte
Alert(ObjTimbradoNC.MensajeErrorCFDI, TipoMensaje.MsgError) Else
End If DebeTimbrar = False
ObjTimbradoNC = Nothing Alert(RespCartaPorte.Mensaje, TipoMensaje.MsgAdvertencia)
End If End If
Next End If
If DebeTimbrar Then
SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura)
End If
Catch ex As Exception Catch ex As Exception
OnError("Ocurrió un error al timbrar la NC.", ex) OnError("Ocurrió un error al generar el timbrado", ex)
End Try
Dim FolioFiscalFactura As String = ObjTimbrado.UUID
MsgErrorTimbrado = ObjTimbrado.MensajeErrorCFDI
ObjTimbrado = Nothing
'NOTA DE CREDITO - REFACTURADA - CASO ESPECIAL, TIMBRADO E IMPRESION
If DebeTimbrar AndAlso SeTimbro AndAlso ListaNotasCreditoGeneradas IsNot Nothing AndAlso ListaNotasCreditoGeneradas.Count > 0 Then
Try
For Each NCGenerada As Modelos.Factura In ListaNotasCreditoGeneradas
If NCGenerada.Timbre IsNot Nothing Then
NCGenerada.Timbre.CFDIRelacionados.UUID.Clear()
NCGenerada.Timbre.CFDIRelacionados.UUID.Add(FolioFiscalFactura)
Dim ObjTimbradoNC As New Timbrado
Dim TimbroNC As Boolean = ObjTimbradoNC.TimbrarFactura(UsuarioActual, NCGenerada)
If Not TimbroNC Then
Alert(ObjTimbradoNC.MensajeErrorCFDI, TipoMensaje.MsgError)
End If
ObjTimbradoNC = Nothing
End If
Next
Catch ex As Exception
OnError("Ocurrió un error al timbrar la NC.", ex)
End Try
End If
'If SeTimbro AndAlso ObjFactura.TipoDocto.Contiene("Ing") Then
' EstatusSMS = EnviarSMSTimbrado(ObjEventos)
' End If
'If Not SeTimbro Then
' Alert(MsgErrorTimbrado, TipoMensaje.MsgError)
'End If
'CANCELAR FACTURA ANTERIOR
Try
If SeTimbro AndAlso (Me.CveDevolucion > 0 AndAlso Me.NuevaFactura = 1) Then
If Me.ObjFacturaNC IsNot Nothing AndAlso Me.ObjFacturaNC.CveEstatusFactura <> 5 Then
Me.ObjFacturaNC.CveEstatusRefacturacion = 2 'MARCAR COMO REFACTURADA
MsgCancelacionRefacturacion = Me.ObjFacturaNC.CancelarPorRefacturacion(Me.ObjFacturaNC.CveMotivoCancelacion, Me.ObjFacturaNC.MotivoCancelacion, FolioFiscalFactura)
End If
End If
Catch ex As Exception
OnError("Ocurrió un error al cancelar la factura anterior.", ex)
End Try End Try
End If End If
'If SeTimbro AndAlso ObjFactura.TipoDocto.Contiene("Ing") Then
' EstatusSMS = EnviarSMSTimbrado(ObjEventos)
' End If
'If Not SeTimbro Then
' Alert(MsgErrorTimbrado, TipoMensaje.MsgError)
'End If
'CANCELAR FACTURA ANTERIOR
Try
If SeTimbro AndAlso (Me.CveDevolucion > 0 AndAlso Me.NuevaFactura = 1) Then
If Me.ObjFacturaNC IsNot Nothing AndAlso Me.ObjFacturaNC.CveEstatusFactura <> 5 Then
Me.ObjFacturaNC.CveEstatusRefacturacion = 2 'MARCAR COMO REFACTURADA
MsgCancelacionRefacturacion = Me.ObjFacturaNC.CancelarPorRefacturacion(Me.ObjFacturaNC.CveMotivoCancelacion, Me.ObjFacturaNC.MotivoCancelacion, FolioFiscalFactura)
End If
End If
Catch ex As Exception
OnError("Ocurrió un error al cancelar la factura anterior.", ex)
End Try
End If End If
End If End If
End If 'VERIFICAR 100% AVANCE A IMPORTE Y CANTIDAD
Try
If ObjFactura.TipoDocto.Contiene("Ing", "Ant") AndAlso CveContrato > 0 Then
If ObjContr.GetContratos(CveContrato, UsuarioActual.CveEmpresa) Then
'VERIFICAR 100% AVANCE A IMPORTE Y CANTIDAD If ObjContr.DtResultados.Rows.Count > 0 Then
Try
If ObjFactura.TipoDocto.Contiene("Ing", "Ant") AndAlso CveContrato > 0 Then
If ObjContr.GetContratos(CveContrato, UsuarioActual.CveEmpresa) Then
If ObjContr.DtResultados.Rows.Count > 0 Then
'SI ES FLEXIBLE QUE NOTIFIQUE EL MONTO MAXIMO, SI NO LO ES QUE NOTIFIQUE EL PORCENTAJE ALCANZADO... FLEXIBLE = 2, NO FLEXIBLE = 1 'SI ES FLEXIBLE QUE NOTIFIQUE EL MONTO MAXIMO, SI NO LO ES QUE NOTIFIQUE EL PORCENTAJE ALCANZADO... FLEXIBLE = 2, NO FLEXIBLE = 1
If ObjContr.DtResultados.Rows(0)("ModalidadDetalle").ToString() = "1" Then If ObjContr.DtResultados.Rows(0)("ModalidadDetalle").ToString() = "1" Then
Dim PorcentajeAvance As Double = ObjContr.DtResultados.Rows(0)("ContratoAvance").ToString().ToDouble Dim PorcentajeAvance As Double = ObjContr.DtResultados.Rows(0)("ContratoAvance").ToString().ToDouble
If PorcentajeAvance >= 100 Then If PorcentajeAvance >= 100 Then
EnviarNotificacionAvance(ObjContr.DtResultados.Rows(0)("NumeroContrato").ToString(), ObjContr.DtResultados.Rows(0)("DescripcionContrato").ToString(), ObjContr.DtResultados.Rows(0)("ContratoTipo").ToString(), ObjContr.DtResultados.Rows(0)("NombreComercial").ToString(), ObjContr.DtResultados.Rows(0)("CorreoVendedor").ToString()) EnviarNotificacionAvance(ObjContr.DtResultados.Rows(0)("NumeroContrato").ToString(), ObjContr.DtResultados.Rows(0)("DescripcionContrato").ToString(), ObjContr.DtResultados.Rows(0)("ContratoTipo").ToString(), ObjContr.DtResultados.Rows(0)("NombreComercial").ToString(), ObjContr.DtResultados.Rows(0)("CorreoVendedor").ToString())
End If
Else
Dim MontoMaximo As Double = ObjContr.DtResultados.Rows(0)("ImporteMax").ToString().ToDouble
Dim Avance As Double = ObjContr.DtResultados.Rows(0)("Avance").ToString().ToDouble
Dim PorcentajeAvance As Double = (Avance / MontoMaximo) * 100
If PorcentajeAvance >= 100 And MontoMaximo > 0 Then
EnviarNotificacionAvance(ObjContr.DtResultados.Rows(0)("NumeroContrato").ToString(), ObjContr.DtResultados.Rows(0)("DescripcionContrato").ToString(), ObjContr.DtResultados.Rows(0)("ContratoTipo").ToString(), ObjContr.DtResultados.Rows(0)("NombreComercial").ToString(), ObjContr.DtResultados.Rows(0)("CorreoVendedor").ToString(), MontoMaximo)
End If
End If End If
Else
Dim MontoMaximo As Double = ObjContr.DtResultados.Rows(0)("ImporteMax").ToString().ToDouble
Dim Avance As Double = ObjContr.DtResultados.Rows(0)("Avance").ToString().ToDouble
Dim PorcentajeAvance As Double = (Avance / MontoMaximo) * 100
If PorcentajeAvance >= 100 And MontoMaximo > 0 Then
EnviarNotificacionAvance(ObjContr.DtResultados.Rows(0)("NumeroContrato").ToString(), ObjContr.DtResultados.Rows(0)("DescripcionContrato").ToString(), ObjContr.DtResultados.Rows(0)("ContratoTipo").ToString(), ObjContr.DtResultados.Rows(0)("NombreComercial").ToString(), ObjContr.DtResultados.Rows(0)("CorreoVendedor").ToString(), MontoMaximo)
End If
End If End If
End If End If
End If End If
End If
Catch ex As Exception
OnError("Ocurrió un error al notificar el avance.", ex)
End Try
'MENSAJE PRINCIPAL
MensajeAlert.AppendFormat(String.Format("<br/>La {0}: <b>{1}</b> se generó correctamente.<br/><br/>", ObjFactura.TipoDocumento, ObjFactura.SerieFolio))
' DESCARGA XML - SI SE TIMBRA MANDA CORREO CON FACTURA
If SeTimbro Then
If Not UsuarioActual.TienePermisoProceso(380) Then
Dim ArchivoXML As String = String.Format("{0}/XML/{1}/{2}.xml", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
If File.Exists(ArchivoXML) Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar XML</a></li></ul>", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", ObjFactura.SerieFolio, ObjFactura.TipoDocto)))
End If
End If
'MANDA CORREO
Try
Dim Factura As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False, VerificaAlmacen:=False)
'SE SE VA UTILIZAR LA DESCARGA AUTOMATICA, NO GENERAR PDF A TRAVEZ DE UN THREAD
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
GeneraPDFFactura(ChkEnviarFactura.Checked, Factura, UsuarioActual, "", UsarDescargaDesdePopUpVerFactura:=False)
Else
Dim capturedContext = HttpContext.Current
Dim strURLHOST As String = String.Format("{0}://{1}:{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)
Dim Hilo As New System.Threading.Thread(Sub() GeneraPDFFactura(ChkEnviarFactura.Checked, Factura, UsuarioActual, strURLHOST, UsarDescargaDesdePopUpVerFactura:=True))
Hilo.Start()
End If
Catch ex As Exception Catch ex As Exception
OnError("Ocurrió un error al enviar el PDF", ex) OnError("Ocurrió un error al notificar el avance.", ex)
End Try End Try
Else
'ERROR DE NO TIMBRADO
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Egs", "Dev") Then ' DESCARGA XML - SI SE TIMBRA MANDA CORREO CON FACTURA
Dim StrEr As String = $"<br/><div id = 'DivTipoCambioAdvertencia' class='alert alert-warning' style='padding: 5px; margin-bottom: 5px; padding-right: 25px;'><strong style = 'font-size: 20px; margin-right: 25px;' > Comprobante no emitido : </strong> {MsgErrorTimbrado}<br/>Por favor inténtelo de nuevo a través del botón Emitir.</div>" If SeTimbro Then
MensajeAlert.Append(StrEr) If Not UsuarioActual.TienePermisoProceso(380) Then
End If Dim ArchivoXML As String = String.Format("{0}/XML/{1}/{2}.xml", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio)
'PARA PRUEBAS, GENERAR PDF AUNQUE NO ESTE TIMBRADA If File.Exists(ArchivoXML) Then
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar XML</a></li></ul>", Encripta(String.Format("OP=FactVta&CVEVENTA={0}&EXT={1}&SERIEFOLIO={2}&TIPODOCTO={3}", CveVenta, "XML", ObjFactura.SerieFolio, ObjFactura.TipoDocto)))
End If
End If
'MANDA CORREO
Try Try
Dim Factura As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False, VerificaAlmacen:=False) Dim Factura As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False, VerificaAlmacen:=False)
GeneraPDFFactura(ChkEnviarFactura.Checked, Factura, UsuarioActual, "", UsarDescargaDesdePopUpVerFactura:=False) 'SE SE VA UTILIZAR LA DESCARGA AUTOMATICA, NO GENERAR PDF A TRAVEZ DE UN THREAD
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
GeneraPDFFactura(ChkEnviarFactura.Checked, Factura, UsuarioActual, "", UsarDescargaDesdePopUpVerFactura:=False)
Else
Dim capturedContext = HttpContext.Current
Dim strURLHOST As String = String.Format("{0}://{1}:{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)
Dim Hilo As New System.Threading.Thread(Sub() GeneraPDFFactura(ChkEnviarFactura.Checked, Factura, UsuarioActual, strURLHOST, UsarDescargaDesdePopUpVerFactura:=True))
Hilo.Start()
End If
Catch ex As Exception Catch ex As Exception
OnError("Ocurrió un error al enviar el PDF", ex) OnError("Ocurrió un error al enviar el PDF", ex)
End Try End Try
Else
'ERROR DE NO TIMBRADO
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Egs", "Dev") Then
Dim StrEr As String = $"<br/><div id = 'DivTipoCambioAdvertencia' class='alert alert-warning' style='padding: 5px; margin-bottom: 5px; padding-right: 25px;'><strong style = 'font-size: 20px; margin-right: 25px;' > Comprobante no emitido : </strong> {MsgErrorTimbrado}<br/>Por favor inténtelo de nuevo a través del botón Emitir.</div>"
MensajeAlert.Append(StrEr)
End If
'PARA PRUEBAS, GENERAR PDF AUNQUE NO ESTE TIMBRADA
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
Try
Dim Factura As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False, VerificaAlmacen:=False)
GeneraPDFFactura(ChkEnviarFactura.Checked, Factura, UsuarioActual, "", UsarDescargaDesdePopUpVerFactura:=False)
Catch ex As Exception
OnError("Ocurrió un error al enviar el PDF", ex)
End Try
End If
End If End If
End If
'DESCARGA PDF 'DESCARGA PDF
If Not UsuarioActual.TienePermisoProceso(380) Then If Not UsuarioActual.TienePermisoProceso(380) Then
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Ant", "Egs", "Dev", "Ped") Then If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Ant", "Egs", "Dev", "Ped") Then
'If Not ImprimeAlert Then 'If Not ImprimeAlert Then
Dim ArchivoIngPyMe As New System.IO.FileInfo(String.Format("{0}Formatos/Factura.mrt", UsuarioActual.Empresa.Ruta)) Dim ArchivoIngPyMe As New System.IO.FileInfo(String.Format("{0}Formatos/Factura.mrt", UsuarioActual.Empresa.Ruta))
Dim ArchivoIng As New System.IO.FileInfo(String.Format("{0}Formatos/Factura.rdlc", UsuarioActual.Empresa.Ruta)) Dim ArchivoIng As New System.IO.FileInfo(String.Format("{0}Formatos/Factura.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoRem As New System.IO.FileInfo(String.Format("{0}Formatos/Remision.rdlc", UsuarioActual.Empresa.Ruta)) Dim ArchivoRem As New System.IO.FileInfo(String.Format("{0}Formatos/Remision.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoEgs As New System.IO.FileInfo(String.Format("{0}Formatos/NotaCredito.rdlc", UsuarioActual.Empresa.Ruta)) Dim ArchivoEgs As New System.IO.FileInfo(String.Format("{0}Formatos/NotaCredito.rdlc", UsuarioActual.Empresa.Ruta))
If ArchivoIng.Exists Or ArchivoRem.Exists Or ArchivoIngPyMe.Exists Or ArchivoEgs.Exists Then If ArchivoIng.Exists Or ArchivoRem.Exists Or ArchivoIngPyMe.Exists Or ArchivoEgs.Exists Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", CveVenta)))
Else
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
End If
End If
End If
'CRM
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
Dim ArchivoCotRdlc As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoCotMrt As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.mrt", UsuarioActual.Empresa.Ruta))
If ArchivoCotRdlc.Exists Or ArchivoCotMrt.Exists Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", CveVenta)))
If ChkEnviarFacturaCRM.Checked AndAlso CorreoContactoCRM.Trim.Length > 0 Then
Try
Dim pdfCRM As Byte() = Nothing
'If CveVenta > 0 Then
' ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False)
'End If
pdfCRM = PdfFactura(ObjFactura)
If pdfCRM IsNot Nothing Then
Dim SerieFolioCRM As String = ObjFactura.SerieFolio
Dim TipoDoctoCRM As String = ObjFactura.TipoDocto
GeneraPDFCotizacion(True, CorreoContactoCRM:=CorreoContactoCRM, pdfCRM:=pdfCRM, SerieFolioCRM:=SerieFolioCRM, TipoDoctoCRM:=TipoDoctoCRM)
End If
Catch ex As Exception
OnError("Ocurrió un error al enviar el PDF", ex)
End Try
End If
Else
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
End If
End If
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
Dim ArchivoCotRdlc As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoCotMrt As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.mrt", UsuarioActual.Empresa.Ruta))
If ArchivoCotRdlc.Exists Or ArchivoCotMrt.Exists Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", CveVenta))) MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", CveVenta)))
Else Else
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ") MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
End If End If
End If End If
End If
'CRM 'ERROR DE NO TIMBRADO NC
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then If Not IsNothing(ObjNC) AndAlso ObjNC.Count > 0 AndAlso Not SeTimbroNC Then
MensajeAlert.AppendFormat("<br/>La NC <b>#{0}</b> no se pudo timbrar.</b> Por favor intentelo de nuevo a traves del boton Emitir.", CType(ObjNC(0), Modelos.Factura).SerieFolio)
Dim ArchivoCotRdlc As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoCotMrt As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.mrt", UsuarioActual.Empresa.Ruta))
If ArchivoCotRdlc.Exists Or ArchivoCotMrt.Exists Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", CveVenta)))
If ChkEnviarFacturaCRM.Checked AndAlso CorreoContactoCRM.Trim.Length > 0 Then
Try
Dim pdfCRM As Byte() = Nothing
'If CveVenta > 0 Then
' ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False)
'End If
pdfCRM = PdfFactura(ObjFactura)
If pdfCRM IsNot Nothing Then
Dim SerieFolioCRM As String = ObjFactura.SerieFolio
Dim TipoDoctoCRM As String = ObjFactura.TipoDocto
GeneraPDFCotizacion(True, CorreoContactoCRM:=CorreoContactoCRM, pdfCRM:=pdfCRM, SerieFolioCRM:=SerieFolioCRM, TipoDoctoCRM:=TipoDoctoCRM)
End If
Catch ex As Exception
OnError("Ocurrió un error al enviar el PDF", ex)
End Try
End If
Else
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
End If End If
End If
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then 'NOTIFICACION DE SMS
Select Case EstatusSMS
Case 1
MensajeAlert.AppendFormat("<br/><b>Notificación SMS:</b> enviado con éxito al cliente al celular: <b>{0}</b>", ObjFactura.Cliente.CobranzaTelefono)
Case 2
MensajeAlert.AppendFormat("<br/><b>Notificación SMS:</b> sin enviar. Ocurrió un error en el envío, por favor verifique la información del cliente.")
Case 3
MensajeAlert.AppendFormat("<br/><b>Notificación SMS:</b> sin enviar. No se pudo cargar el celular del cliente, por favor verifique la información del cliente.")
End Select
Dim ArchivoCotRdlc As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoCotMrt As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.mrt", UsuarioActual.Empresa.Ruta))
If ArchivoCotRdlc.Exists Or ArchivoCotMrt.Exists Then If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1&GUARDAR=1", CveVenta))) RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1", CveVenta))}'", "Imprimir")
Else
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
End If End If
End If
'DESCARGAR PDF DE CICOVISA
'If UsuarioActual.CveEmpresa = 72 And CveCliente = 70381 Then
' If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem") Then
' MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar Formato CICOVISA</a></li></ul><br/>", Encripta(String.Format("OP=CIC&CVEVENTA={0}", CveVenta)))
' End If
'End If
'ERROR DE NO TIMBRADO NC If Not UsuarioActual.TienePermisoProceso(380) Then
If Not IsNothing(ObjNC) AndAlso ObjNC.Count > 0 AndAlso Not SeTimbroNC Then If DdlTipoComprobante.SelectedValue = "Cot" Then
MensajeAlert.AppendFormat("<br/>La NC <b>#{0}</b> no se pudo timbrar.</b> Por favor intentelo de nuevo a traves del boton Emitir.", CType(ObjNC(0), Modelos.Factura).SerieFolio)
End If
'NOTIFICACION DE SMS If Not CveEmpresaCRM > 0 Then
Select Case EstatusSMS 'EN EMPRESA DE ACUMULADORES NO DESCARGAR EL PDF
Case 1 If UsuarioActual.Empresa.Funcionalidad(531) <> "1" Then
MensajeAlert.AppendFormat("<br/><b>Notificación SMS:</b> enviado con éxito al cliente al celular: <b>{0}</b>", ObjFactura.Cliente.CobranzaTelefono) If CveVenta > 0 Then MensajeAlert = New StringBuilder
Case 2
MensajeAlert.AppendFormat("<br/><b>Notificación SMS:</b> sin enviar. Ocurrió un error en el envío, por favor verifique la información del cliente.")
Case 3
MensajeAlert.AppendFormat("<br/><b>Notificación SMS:</b> sin enviar. No se pudo cargar el celular del cliente, por favor verifique la información del cliente.")
End Select
Dim ArchivoCotizacion As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoCotizacionMrt As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.mrt", UsuarioActual.Empresa.Ruta))
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then If Opcion = "Cot" And UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1", CveVenta))}'", "Imprimir") MensajeAlert.AppendFormat("<b><a class='Texto' href=""Ventas.aspx?CveVenta={0}"">Facturar</a></b><br/><br/>", CveVenta)
End If End If
'DESCARGAR PDF DE CICOVISA If ArchivoCotizacion.Exists Or ArchivoCotizacionMrt.Exists Then
'If UsuarioActual.CveEmpresa = 72 And CveCliente = 70381 Then MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=0&GUARDAR=1", CveVenta)))
' If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem") Then Else
' MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar Formato CICOVISA</a></li></ul><br/>", Encripta(String.Format("OP=CIC&CVEVENTA={0}", CveVenta))) MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
' End If End If
'End If
If Not UsuarioActual.TienePermisoProceso(380) Then
If DdlTipoComprobante.SelectedValue = "Cot" Then
If Not CveEmpresaCRM > 0 Then
'EN EMPRESA DE ACUMULADORES NO DESCARGAR EL PDF
If UsuarioActual.Empresa.Funcionalidad(531) <> "1" Then
If CveVenta > 0 Then MensajeAlert = New StringBuilder
Dim ArchivoCotizacion As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.rdlc", UsuarioActual.Empresa.Ruta))
Dim ArchivoCotizacionMrt As New System.IO.FileInfo(String.Format("{0}Formatos/Cotizacion.mrt", UsuarioActual.Empresa.Ruta))
If Opcion = "Cot" And UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
MensajeAlert.AppendFormat("<b><a class='Texto' href=""Ventas.aspx?CveVenta={0}"">Facturar</a></b><br/><br/>", CveVenta)
End If
If ArchivoCotizacion.Exists Or ArchivoCotizacionMrt.Exists Then
MensajeAlert.AppendFormat("<ul><li><a class=""Texto"" href=""/Compras/PopUpVerFactura.aspx?P={0}"">Descargar PDF</a></li></ul><br/>", Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=0&GUARDAR=1", CveVenta)))
Else
MensajeAlert.Append("Ocurrió un error al generar el PDF. Por favor vuelva a entrar a la factura para imprimir el PDF. ")
End If End If
GeneraPDFCotizacion(ChkEnviarFactura.Checked) ' MANDA CORREO
End If End If
GeneraPDFCotizacion(ChkEnviarFactura.Checked) ' MANDA CORREO
End If End If
End If End If
End If
'ENVIAR NOTIFICACION DE SMS 'ENVIAR NOTIFICACION DE SMS
If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then If UsuarioActual.Empresa.Funcionalidad(578) = "1" Then
If DdlTipoComprobante.SelectedValue.Contiene("Ped") Then If DdlTipoComprobante.SelectedValue.Contiene("Ped") Then
Dim CorreoDestino As String Dim CorreoDestino As String
CorreoDestino = UsuarioActual.Empresa.Funcionalidad(199).ListaBusquedaValor("Almacén") CorreoDestino = UsuarioActual.Empresa.Funcionalidad(199).ListaBusquedaValor("Almacén")
If RBLTipoVenta.SelectedValue.Contiene("1", "2") Then If RBLTipoVenta.SelectedValue.Contiene("1", "2") Then
Dim ListMateriales As New List(Of GenericaCantidadProducto) Dim ListMateriales As New List(Of GenericaCantidadProducto)
Dim DetalleTable As String = "" Dim DetalleTable As String = ""
For Each dRow As DataRow In TmpDT.Rows For Each dRow As DataRow In TmpDT.Rows
ListMateriales.Add(New GenericaCantidadProducto With {.Cantidad = dRow("Cantidad").ToString.ToEntero, .Producto = dRow("PS").ToString}) ListMateriales.Add(New GenericaCantidadProducto With {.Cantidad = dRow("Cantidad").ToString.ToEntero, .Producto = dRow("PS").ToString})
Next Next
EnviaNotificacionSMS(3, UsuarioActual.Empresa, CveVenta, TxtFolio.Text, TxtFechaOS.Text.ToDateTime, If(DdlSucursalCliente.Visible, DdlSucursalCliente.SelectedItem.Text, LblCliente.Text), DdlMedico.SelectedItem.Text, DdlProcedimiento.SelectedItem.Text, "", DdlVendedor.SelectedItem.Text, "", ListMateriales, CorreoDestino) EnviaNotificacionSMS(3, UsuarioActual.Empresa, CveVenta, TxtFolio.Text, TxtFechaOS.Text.ToDateTime, If(DdlSucursalCliente.Visible, DdlSucursalCliente.SelectedItem.Text, LblCliente.Text), DdlMedico.SelectedItem.Text, DdlProcedimiento.SelectedItem.Text, "", DdlVendedor.SelectedItem.Text, "", ListMateriales, CorreoDestino)
Else Else
EnviaNotificacionSMS(4, UsuarioActual.Empresa, CveVenta, TxtFolio.Text, TxtFechaOS.Text.ToDateTime, If(DdlSucursalCliente.Visible, DdlSucursalCliente.SelectedItem.Text, LblCliente.Text), DdlMedico.SelectedItem.Text, DdlProcedimiento.SelectedItem.Text, "", DdlVendedor.SelectedItem.Text, "", Nothing, CorreoDestino) EnviaNotificacionSMS(4, UsuarioActual.Empresa, CveVenta, TxtFolio.Text, TxtFechaOS.Text.ToDateTime, If(DdlSucursalCliente.Visible, DdlSucursalCliente.SelectedItem.Text, LblCliente.Text), DdlMedico.SelectedItem.Text, DdlProcedimiento.SelectedItem.Text, "", DdlVendedor.SelectedItem.Text, "", Nothing, CorreoDestino)
End If End If
'cirugía en el mismo día o si es despues de las 9 y requiere técnico, 'jefe de técnicos 'cirugía en el mismo día o si es despues de las 9 y requiere técnico, 'jefe de técnicos
If TxtFechaOS.Text.ToDate.ToShortDateString = NowADS.ToShortDateString OrElse (NowADS.Hour > 21 And NowADS.AddDays(1).ToShortDateString = TxtFechaOS.Text.ToDate.ToShortDateString AndAlso ChkRequiereTecnicoModal.Checked) Then If TxtFechaOS.Text.ToDate.ToShortDateString = NowADS.ToShortDateString OrElse (NowADS.Hour > 21 And NowADS.AddDays(1).ToShortDateString = TxtFechaOS.Text.ToDate.ToShortDateString AndAlso ChkRequiereTecnicoModal.Checked) Then
CorreoDestino = UsuarioActual.Empresa.Funcionalidad(199).ListaBusquedaValor("JefeTécnicos") CorreoDestino = UsuarioActual.Empresa.Funcionalidad(199).ListaBusquedaValor("JefeTécnicos")
EnviaNotificacionSMS(5, UsuarioActual.Empresa, CveVenta, TxtFolio.Text, TxtFechaOS.Text.ToDateTime, If(DdlSucursalCliente.Visible, DdlSucursalCliente.SelectedItem.Text, LblCliente.Text), DdlMedico.SelectedItem.Text, DdlProcedimiento.SelectedItem.Text, "", DdlVendedor.SelectedItem.Text, "", Nothing, CorreoDestino) EnviaNotificacionSMS(5, UsuarioActual.Empresa, CveVenta, TxtFolio.Text, TxtFechaOS.Text.ToDateTime, If(DdlSucursalCliente.Visible, DdlSucursalCliente.SelectedItem.Text, LblCliente.Text), DdlMedico.SelectedItem.Text, DdlProcedimiento.SelectedItem.Text, "", DdlVendedor.SelectedItem.Text, "", Nothing, CorreoDestino)
End If
End If End If
End If End If
End If
'MOVIMIENTO DE ALMACEN 'MOVIMIENTO DE ALMACEN
If ObjFactura.Inv_CveMovimiento > 0 Then If ObjFactura.Inv_CveMovimiento > 0 Then
MensajeAlert.AppendFormat("<br/><br/><b><a target='_blank' class='Texto' href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"">Movimiento de Almacén</a></b><br/>", ObjFactura.Inv_CveMovimiento) MensajeAlert.AppendFormat("<br/><br/><b><a target='_blank' class='Texto' href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"">Movimiento de Almacén</a></b><br/>", ObjFactura.Inv_CveMovimiento)
End If End If
If TieneAnticipo AndAlso DdlTipoAmortizacionAnticipo.SelectedValue = "2" Then If TieneAnticipo AndAlso DdlTipoAmortizacionAnticipo.SelectedValue = "2" Then
MensajeAlert.AppendFormat("<br/><br/><b> Se generó una Nota de crédito Folio: {0} amortizando el anticipo </b><br/>", ObjFacturaDevolucion.Folio) MensajeAlert.AppendFormat("<br/><br/><b> Se generó una Nota de crédito Folio: {0} amortizando el anticipo </b><br/>", ObjFacturaDevolucion.Folio)
End If End If
If RBLPago.SelectedValue.ToEntero() = 2 And TxtCambio.Text.ToDecimal > 0 Then If RBLPago.SelectedValue.ToEntero() = 2 And TxtCambio.Text.ToDecimal > 0 Then
MensajeAlert.AppendFormat("<br/><br/>Su cambio es de <b>${0}</b><br/>", TxtCambio.Text.ToDecimal.FormatoNumero(2)) MensajeAlert.AppendFormat("<br/><br/>Su cambio es de <b>${0}</b><br/>", TxtCambio.Text.ToDecimal.FormatoNumero(2))
End If End If
If CveVentaNCProntoPago > 0 Then If CveVentaNCProntoPago > 0 Then
MensajeAlert.AppendFormat(String.Format("<br/>La nota de crédito <b>{0}</b> por descuento pronto pago se generó correctamente.<br/><br/>", SerieFolioNCProntoPago)) MensajeAlert.AppendFormat(String.Format("<br/>La nota de crédito <b>{0}</b> por descuento pronto pago se generó correctamente.<br/><br/>", SerieFolioNCProntoPago))
End If End If
If MsgCancelacionRefacturacion IsNot Nothing Then If MsgCancelacionRefacturacion IsNot Nothing Then
If Not MsgCancelacionRefacturacion.HuboError Then If Not MsgCancelacionRefacturacion.HuboError Then
If MsgCancelacionRefacturacion.CveEstatus = 5 Then If MsgCancelacionRefacturacion.CveEstatus = 5 Then
MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> fue cancelado. <b><a target='_blank' class='Texto' href=""/Compras/PopUpVerFactura.aspx?P={1}"">Descargar Acuse</a></b>", Me.ObjFacturaNC.SerieFolio, Encripta(String.Format("OP=CAN&CVEVTA={0}", Me.ObjFacturaNC.CveVenta))) MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> fue cancelado. <b><a target='_blank' class='Texto' href=""/Compras/PopUpVerFactura.aspx?P={1}"">Descargar Acuse</a></b>", Me.ObjFacturaNC.SerieFolio, Encripta(String.Format("OP=CAN&CVEVTA={0}", Me.ObjFacturaNC.CveVenta)))
MensajeAlert.AppendFormat("&nbsp;<a target='_self' class='Texto' href=""javascript:BtnEnviarMailCancelacion({0});"">Enviar Acuse</a>.<br/><br/>", Me.ObjFacturaNC.CveVenta) MensajeAlert.AppendFormat("&nbsp;<a target='_self' class='Texto' href=""javascript:BtnEnviarMailCancelacion({0});"">Enviar Acuse</a>.<br/><br/>", Me.ObjFacturaNC.CveVenta)
ElseIf MsgCancelacionRefacturacion.CveEstatus = 20 Then ElseIf MsgCancelacionRefacturacion.CveEstatus = 20 Then
MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> esta en proceso de cancelación. <b><a target='_blank' class='Texto' href=""/Compras/PopUpVerFactura.aspx?P={1}"">Descargar Acuse</a></b>", Me.ObjFacturaNC.SerieFolio, Encripta(String.Format("OP=CAN&CVEVTA={0}", Me.ObjFacturaNC.CveVenta))) MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> esta en proceso de cancelación. <b><a target='_blank' class='Texto' href=""/Compras/PopUpVerFactura.aspx?P={1}"">Descargar Acuse</a></b>", Me.ObjFacturaNC.SerieFolio, Encripta(String.Format("OP=CAN&CVEVTA={0}", Me.ObjFacturaNC.CveVenta)))
MensajeAlert.AppendFormat("&nbsp;<a target='_self' class='Texto' href=""javascript:BtnEnviarMailCancelacion({0});"">Enviar Acuse</a>.<br/><br/>", Me.ObjFacturaNC.CveVenta) MensajeAlert.AppendFormat("&nbsp;<a target='_self' class='Texto' href=""javascript:BtnEnviarMailCancelacion({0});"">Enviar Acuse</a>.<br/><br/>", Me.ObjFacturaNC.CveVenta)
Else
MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> no fue cancelado. Intente mas tarde cancelar el documento <b><a target='_blank' class='Texto' href=""/Ventas/RepCancelacionesPorRespuesta.aspx?CveVenta={1}"">Ver en el reporte</a></b>", Me.ObjFacturaNC.SerieFolio, Me.ObjFacturaNC.CveVenta)
End If
Else Else
MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> no fue cancelado. Intente mas tarde cancelar el documento <b><a target='_blank' class='Texto' href=""/Ventas/RepCancelacionesPorRespuesta.aspx?CveVenta={1}"">Ver en el reporte</a></b>", Me.ObjFacturaNC.SerieFolio, Me.ObjFacturaNC.CveVenta) MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> no fue cancelado. Intente mas tarde cancelar el documento <b><a target='_blank' class='Texto' href=""/Ventas/RepCancelacionesPorRespuesta.aspx?CveVenta={1}"">Ver en el reporte</a></b>", Me.ObjFacturaNC.SerieFolio, Me.ObjFacturaNC.CveVenta)
End If End If
Else
MensajeAlert.AppendFormat("<br/>El folio <b>{0}</b> no fue cancelado. Intente mas tarde cancelar el documento <b><a target='_blank' class='Texto' href=""/Ventas/RepCancelacionesPorRespuesta.aspx?CveVenta={1}"">Ver en el reporte</a></b>", Me.ObjFacturaNC.SerieFolio, Me.ObjFacturaNC.CveVenta)
End If
End If
'MUESTA ALERT OK
' si es elrol 1165-Ventas,EMp:80, o la empresa 119, recarga ventas, para seguir registrando-.
'Dim Liga = If(UsuarioActual.CveRol = 1165 Or UsuarioActual.CveEmpresa = 119, "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";", If(CveEmpresaCRM > 0, $"document.location.href=""/CRM/EmpresaCRM.aspx?CveEmpresaCRM={CveEmpresaCRM}"";", $"document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";"))
'Alert(MensajeAlert.ToString(), TipoMensaje.MsgInformacion, Liga)
Dim Liga As String = ""
Dim Liga2 As String = ""
If Request("CveCliente") IsNot Nothing AndAlso Request("CveCliente").ToEntero > 0 Then
Liga = $"document.location.href=""/Ventas/Ventas.aspx?CveCliente={Request("CveCliente")}"";"
Else
Liga = "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";"
End If
If CveEmpresaCRM > 0 Then
Liga2 = $"document.location.href=""/CRM/EmpresaCRM.aspx?CveEmpresaCRM={CveEmpresaCRM}"";"
Else
Liga2 = $"document.location.href=""/Ventas/Clientes.aspx?CveCliente={CveCliente}"";"
End If
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
Liga = $"document.location.href=""/CRM/Acercamiento.aspx?CveAcercamiento={CveAcercamientoCRM}&OPTAB=COT"";"
Alert(MensajeAlert.ToString(), TipoMensaje.MsgInformacion, Liga, TextoConfirmacion:="Aceptar", TextoSegundoBoton:=Nothing, JSBtn2:=Nothing, ShowCloseButton:=False)
Else
'SI TIENE MODULO DE COBRANZA, NO MARDAR AL CLIENTE, DEBE SEGUIR REGISTRANDO
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
Alert(MensajeAlert.ToString(), TipoMensaje.MsgInformacion, Liga, TextoConfirmacion:="Seguir Registrando", ShowCloseButton:=False)
Else
Alert(MensajeAlert.ToString(), TipoMensaje.MsgDosBotones, Liga, TextoConfirmacion:="Seguir Registrando", TextoSegundoBoton:="Ir al Cliente", JSBtn2:=Liga2, ShowCloseButton:=False)
End If End If
End If 'MUESTA ALERT OK
' si es elrol 1165-Ventas,EMp:80, o la empresa 119, recarga ventas, para seguir registrando-.
'Dim Liga = If(UsuarioActual.CveRol = 1165 Or UsuarioActual.CveEmpresa = 119, "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";", If(CveEmpresaCRM > 0, $"document.location.href=""/CRM/EmpresaCRM.aspx?CveEmpresaCRM={CveEmpresaCRM}"";", $"document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";"))
'Alert(MensajeAlert.ToString(), TipoMensaje.MsgInformacion, Liga)
MensajeAlert.Clear() Dim Liga As String = ""
Dim Liga2 As String = ""
Try If Request("CveCliente") IsNot Nothing AndAlso Request("CveCliente").ToEntero > 0 Then
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then Liga = $"document.location.href=""/Ventas/Ventas.aspx?CveCliente={Request("CveCliente")}"";"
If ObjFactura.TipoDocto.Contiene("Ing", "Cot") AndAlso ObjFactura.CondicionesPago = 1 Then Else
ImpresionDirectaPDF() Liga = "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";"
End If
If CveEmpresaCRM > 0 Then
Liga2 = $"document.location.href=""/CRM/EmpresaCRM.aspx?CveEmpresaCRM={CveEmpresaCRM}"";"
Else
Liga2 = $"document.location.href=""/Ventas/Clientes.aspx?CveCliente={CveCliente}"";"
End If
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
Liga = $"document.location.href=""/CRM/Acercamiento.aspx?CveAcercamiento={CveAcercamientoCRM}&OPTAB=COT"";"
Alert(MensajeAlert.ToString(), TipoMensaje.MsgInformacion, Liga, TextoConfirmacion:="Aceptar", TextoSegundoBoton:=Nothing, JSBtn2:=Nothing, ShowCloseButton:=False)
Else
'SI TIENE MODULO DE COBRANZA, NO MARDAR AL CLIENTE, DEBE SEGUIR REGISTRANDO
If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
Alert(MensajeAlert.ToString(), TipoMensaje.MsgInformacion, Liga, TextoConfirmacion:="Seguir Registrando", ShowCloseButton:=False)
Else
Alert(MensajeAlert.ToString(), TipoMensaje.MsgDosBotones, Liga, TextoConfirmacion:="Seguir Registrando", TextoSegundoBoton:="Ir al Cliente", JSBtn2:=Liga2, ShowCloseButton:=False)
End If End If
End If End If
'LIMPIA CONDICIONES DE PAGO - CONTADO MensajeAlert.Clear()
RBLPago.SelectedValue = "1"
LimpiaEscondeContado() Try
BtnEmitirImprimir.Visible = False If UsuarioActual.Empresa.Funcionalidad(109) = "1" Then
ObjFactura = Nothing If ObjFactura.TipoDocto.Contiene("Ing", "Cot") AndAlso ObjFactura.CondicionesPago = 1 Then
ImpresionDirectaPDF()
End If
End If
'LIMPIA CONDICIONES DE PAGO - CONTADO
RBLPago.SelectedValue = "1"
LimpiaEscondeContado()
BtnEmitirImprimir.Visible = False
ObjFactura = Nothing
Catch ex As Exception
OnError("Ocurrió un error al limpiar los datos", ex)
End Try
Catch ex As Exception Catch ex As Exception
OnError("Ocurrió un error al limpiar los datos", ex) Dim Liga = "document.location.href=""/Ventas/Ventas.aspx?CveVenta=-1"";"
Alert(MensajeAlert.ToString() + "<br/> Ocurrió un error posterior a la generación de la venta", TipoMensaje.MsgError, Liga, TextoConfirmacion:="Aceptar", ShowCloseButton:=False)
BtnEmitirImprimir.Visible = False
GuardaLog(ex.ToString())
End Try End Try
Else Else
ObjVentas.RollBack() ObjVentas.RollBack()
BtnEmitirImprimir.Enabled = True
For Each ErrorItem As String In ErrorList For Each ErrorItem As String In ErrorList
Alert(ErrorItem, TipoMensaje.MsgAdvertencia) Alert(ErrorItem, TipoMensaje.MsgAdvertencia)
Next Next
@@ -11574,9 +11589,12 @@ Partial Class Ventas
TmpDT = TmpDTError.Copy TmpDT = TmpDTError.Copy
CalculaTotalesVenta(RecalcularTotalOriginal:=False) CalculaTotalesVenta(RecalcularTotalOriginal:=False)
UpFacturar.Update()
Else Else
ObjVentas.RollBack() ObjVentas.RollBack()
BtnEmitirImprimir.Enabled = True
For Each ErrorItem As String In ErrorList For Each ErrorItem As String In ErrorList
Alert(ErrorItem, TipoMensaje.MsgAdvertencia) Alert(ErrorItem, TipoMensaje.MsgAdvertencia)
Next Next
@@ -11599,6 +11617,8 @@ Partial Class Ventas
CalculaTotalesVenta(RecalcularTotalOriginal:=False) CalculaTotalesVenta(RecalcularTotalOriginal:=False)
GuardaLog("2.0- Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar. SeGuardoPrePoliza: " + If(SeGuardoPrePoliza, "Si", "No") + " TipoDocto: " + ObjFactura.TipoDocto) GuardaLog("2.0- Ocurrió un error al procesar los datos. Por favor rectifique y vuelta a intentar. SeGuardoPrePoliza: " + If(SeGuardoPrePoliza, "Si", "No") + " TipoDocto: " + ObjFactura.TipoDocto)
UpFacturar.Update()
End If End If
ObjFactura = Nothing ObjFactura = Nothing
ListaNotasCreditoGeneradas = Nothing ListaNotasCreditoGeneradas = Nothing