CRM Mejoras
This commit is contained in:
@@ -512,6 +512,9 @@
|
||||
<td width="95px"><b>Empresa:</b> </td>
|
||||
<td width="200px">
|
||||
<asp:Label ID="LblEmpresaCRM" runat="server" Text="Cliente"></asp:Label></td>
|
||||
<td width="135px" runat="server" id="Td5"><b>Enviar Mail:</b></td>
|
||||
<td width="85px">
|
||||
<asp:CheckBox ID="ChkEnviarFacturaCRM" runat="server" /></td>
|
||||
</tr>
|
||||
<tr align="left" runat="server" id="trCRM2" visible="false">
|
||||
<td><b>RFC:</b> </td>
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.Diagnostics
|
||||
Imports System.Globalization
|
||||
Imports System.IO
|
||||
Imports System.Net.Http
|
||||
Imports System.Security.Cryptography.X509Certificates
|
||||
Imports System.Xml
|
||||
Imports ADSNetLibrary.SIGAPI.Models.CRM.Request
|
||||
Imports ADSNetLibrary.SIGAPI.Services.CRM
|
||||
Imports ADSTimbrado
|
||||
Imports Extensiones
|
||||
Imports Microsoft.Owin.Security.Provider
|
||||
Imports Microsoft.Reporting.WebForms
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
@@ -1917,6 +1921,20 @@ Partial Class Ventas
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
Private Property CorreoContactoCRM As String
|
||||
Get
|
||||
If ViewState("CorreoContactoCRM") Is Nothing Then
|
||||
ViewState("CorreoContactoCRM") = ""
|
||||
End If
|
||||
Return ViewState("CorreoContactoCRM").ToString()
|
||||
End Get
|
||||
Set(value As String)
|
||||
ViewState("CorreoContactoCRM") = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
Private Property DtPedidos2 As DataTable
|
||||
Get
|
||||
Return CType(ViewState("DtPedidos2"), DataTable)
|
||||
@@ -2661,6 +2679,15 @@ Partial Class Ventas
|
||||
|
||||
If Request("CveAcercamientoCRM") IsNot Nothing AndAlso IsNumeric(Request("CveAcercamientoCRM")) AndAlso Request("CveAcercamientoCRM").ToEntero() > 0 Then
|
||||
ViewState("CveAcercamientoCRM") = Request("CveAcercamientoCRM")
|
||||
|
||||
Dim cRMService As ICRMService = New CRMService(System.Configuration.ConfigurationManager.ConnectionStrings("Conexion").ConnectionString)
|
||||
Dim AcercamientoModel As RequestAcercamiento = New RequestAcercamiento(UsuarioActual.CveEmpresa, CveAcercamientoCRM)
|
||||
Dim objAcercamiento = cRMService.GetAceracamientoCRM(AcercamientoModel)
|
||||
|
||||
If objAcercamiento.Result.Count > 0 Then
|
||||
CorreoContactoCRM = objAcercamiento.Result(0).CorreoContacto
|
||||
End If
|
||||
|
||||
Else
|
||||
ViewState("CveAcercamientoCRM") = -1
|
||||
End If
|
||||
@@ -9804,7 +9831,21 @@ Partial Class Ventas
|
||||
End If
|
||||
End If
|
||||
|
||||
'Paso CRM actualizar importe de acercamiento y guardar en bitacora
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
|
||||
|
||||
If Not (CRMActualizaImporteBitacora(CveAcercamientoCRM, ObjFactura.SubTotal, ObjFactura.SerieFolio, ObjVentas.IniciaTransacSQL)) Then
|
||||
ErrorList.Add("Error al actualizar datos Acercamiento/Oportunidad CRM.")
|
||||
End If
|
||||
End If
|
||||
|
||||
If ObjFactura.CveVenta > 0 AndAlso ErrorList.Count = 0 AndAlso (SeGuardoPrePoliza Or ObjFactura.TipoDocto.Contiene("Ped", "Cot", "DPe", "PeC", "PA", "Pd2")) Then
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ObjVentas.Commit()
|
||||
|
||||
'ENVIAR POLIZA VIRTUAL
|
||||
@@ -10085,6 +10126,7 @@ Partial Class Ventas
|
||||
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))
|
||||
@@ -10092,6 +10134,25 @@ Partial Class Ventas
|
||||
|
||||
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
|
||||
'MANDA CORREO
|
||||
Dim strURLHOST = String.Format("{0}://{1}:{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port)
|
||||
Dim Factura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False, CargaDTDetalle:=False, CargaDatosCliente:=False, CargaDatosRelacionados:=False)
|
||||
Dim Hilo As New System.Threading.Thread(Sub() GeneraPDFFactura(True, Factura, UsuarioActual, strURLHOST, CorreoCRM:=CorreoContactoCRM))
|
||||
Hilo.Start()
|
||||
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
|
||||
@@ -10139,7 +10200,6 @@ Partial Class Ventas
|
||||
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
|
||||
@@ -10157,6 +10217,8 @@ Partial Class Ventas
|
||||
End If
|
||||
|
||||
GeneraPDFCotizacion(ChkEnviarFactura.Checked) ' MANDA CORREO
|
||||
Else
|
||||
'Enviar pore correo cot CRM
|
||||
End If
|
||||
ElseIf DdlTipoComprobante.SelectedValue = "Rem" Then
|
||||
If UsuarioActual.CveEmpresa.Contiene(81, 109) Then
|
||||
@@ -10307,6 +10369,33 @@ Partial Class Ventas
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Function CRMActualizaImporteBitacora(CveAcercamientoCRMActualizar As Integer, ImporteCRM As Decimal, SerieFolioVenta As String, ByRef ObjTRansaccion As SqlTransaction) As Boolean
|
||||
|
||||
Dim cRMService As ICRMService = New CRMService(System.Configuration.ConfigurationManager.ConnectionStrings("Conexion").ConnectionString)
|
||||
Dim AcercamientoModel As RequestAcercamiento = New RequestAcercamiento(UsuarioActual.CveEmpresa, CveAcercamientoCRMActualizar)
|
||||
Dim objAcercamiento = cRMService.GetAceracamientoCRM(AcercamientoModel)
|
||||
Dim ImporteAcercamiento As Decimal = objAcercamiento.Result(0).Importe.ToDecimal
|
||||
Dim CveEtapaProcesoCRM As Integer = objAcercamiento.Result(0).CveEtapaProcesoActual.ToEntero
|
||||
Dim CveTipoProcesoCRM As Integer = objAcercamiento.Result(0).CveTipoProceso.ToEntero
|
||||
|
||||
Dim Respuesta As Boolean = False
|
||||
Dim ObjCRM As New ClsCRM(ObjTRansaccion)
|
||||
Dim ObjEventoBitacora As New ClsOIEventos(ObjTRansaccion)
|
||||
|
||||
If objAcercamiento.Result.Count > 0 Then
|
||||
If ObjCRM.UpdateAcercamientoCotizacion(CveAcercamientoCRMActualizar, ImporteCRM, UsuarioActual.CveEmpresa) Then
|
||||
If ObjEventoBitacora.AddEventoBitacora($"Se actualiza Importe de {ImporteAcercamiento.ToString("###,###,###.00") } a {ImporteCRM.ToString("###,###,###.00")} por cotización {SerieFolioVenta}", "",
|
||||
UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveAcercamientoCRM:=CveAcercamientoCRMActualizar, CveEtapaProcesoCRM:=CveEtapaProcesoCRM,
|
||||
CveTipoProcesoCRM:=CveTipoProcesoCRM) Then
|
||||
Respuesta = True
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
Return Respuesta
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub CreaObjetosVentaAmortizacion(ObjVentas As ClsVentas, FolioFiscalRelacionado As String, CveAnticipoPadre As Integer,
|
||||
Optional CveVentasPadre As Integer = -1, Optional NCDescuento As Boolean = False)
|
||||
ObjFacturaDevolucion = New Modelos.Factura
|
||||
@@ -15694,7 +15783,7 @@ Partial Class Ventas
|
||||
#End Region
|
||||
|
||||
#Region "¡ P D F R E P O R T V I E W E R !"
|
||||
Private Sub GeneraPDFFactura(EnviaCorreo As Boolean, Factura As Modelos.Factura, UsuarioActual As Usuario, strURLHOST As String)
|
||||
Private Sub GeneraPDFFactura(EnviaCorreo As Boolean, Factura As Modelos.Factura, UsuarioActual As Usuario, strURLHOST As String, Optional CorreoCRM As String = "")
|
||||
'GUARDA PDF
|
||||
Dim LocalSerieFolio As String = String.Empty
|
||||
Dim LocalTipoDocto As String = String.Empty
|
||||
@@ -15726,7 +15815,7 @@ Partial Class Ventas
|
||||
Dim FIXML As New FileInfo(ArchivoXML)
|
||||
Dim FIPDF As New FileInfo(ArchivoPDF)
|
||||
If FIXML.Exists AndAlso FIPDF.Exists Then
|
||||
MandaMails(UsuarioActual, CveVenta, Factura.TipoDocto, LocalSerieFolio, EnviaCorreo, ArchivoXML, ArchivoPDF, ArchivoAdjunto)
|
||||
MandaMails(UsuarioActual, CveVenta, Factura.TipoDocto, LocalSerieFolio, EnviaCorreo, ArchivoXML, ArchivoPDF, ArchivoAdjunto, CorreoCRM)
|
||||
Else
|
||||
ErrorCorreo = True
|
||||
End If
|
||||
@@ -20921,11 +21010,13 @@ Partial Class Ventas
|
||||
#End Region
|
||||
|
||||
#Region " MANDA CORREO "
|
||||
Private Sub MandaMails(UsuarioActual As Usuario, CveVenta As Integer, TipoDocto As String, SerieFolio As String, EnviarFactura As Boolean, XML As String, PDF As String, Adjunto As String)
|
||||
Private Sub MandaMails(UsuarioActual As Usuario, CveVenta As Integer, TipoDocto As String, SerieFolio As String, EnviarFactura As Boolean, XML As String, PDF As String, Adjunto As String, Optional CorreoCRM As String = "")
|
||||
|
||||
Dim ObjMail As New ClsSisMail()
|
||||
Dim ResultadoMail As Integer = 0
|
||||
|
||||
Dim CorreoDestino As String = If(CorreoCRM.Trim.Length > 0, CorreoCRM, Mail)
|
||||
|
||||
Try
|
||||
|
||||
Dim Asunto As String = String.Empty
|
||||
@@ -20977,7 +21068,7 @@ Partial Class Ventas
|
||||
Dim DisplayName As String = ""
|
||||
If UsuarioActual.CveEmpresa = 119 Then DisplayName = "Facturación Agroquímicos JAM"
|
||||
|
||||
If ObjMail.SendMail(EmpresaActual, Mail, Asunto, Cuerpo, MailCC, LSRutasMail, Displayname:=DisplayName) Then
|
||||
If ObjMail.SendMail(EmpresaActual, CorreoDestino, Asunto, Cuerpo, MailCC, LSRutasMail, Displayname:=DisplayName) Then
|
||||
ResultadoMail = 1
|
||||
Else
|
||||
ResultadoMail = 3
|
||||
@@ -20986,10 +21077,10 @@ Partial Class Ventas
|
||||
|
||||
'CASO ESPECIAL
|
||||
If CveUsuarioActual = 1446 Then ' Flora
|
||||
Dim str As String = "Flora Envio: Correo:" & Mail & " - CorreosCC: " & MailCC & " RM:" & ResultadoMail.ToString()
|
||||
Dim str As String = "Flora Envio: Correo:" & CorreoDestino & " - CorreosCC: " & MailCC & " RM:" & ResultadoMail.ToString()
|
||||
str.GuardaLog()
|
||||
ElseIf CveUsuarioActual = 1513 Then ' Flora
|
||||
Dim str As String = "Flora Envio (secundario): Correo:" & Mail & " - CorreosCC: " & MailCC & " RM:" & ResultadoMail.ToString()
|
||||
Dim str As String = "Flora Envio (secundario): Correo:" & CorreoDestino & " - CorreosCC: " & MailCC & " RM:" & ResultadoMail.ToString()
|
||||
str.GuardaLog()
|
||||
End If
|
||||
|
||||
|
||||
Reference in New Issue
Block a user