--merge Ventas
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1886,6 +1890,18 @@ Partial Class Ventas
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private Property CveAcercamiento As Integer
|
||||
Get
|
||||
If ViewState("CveAcercamiento") Is Nothing Then
|
||||
ViewState("CveAcercamiento") = -1
|
||||
End If
|
||||
Return ViewState("CveAcercamiento").ToString().ToEntero()
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
ViewState("CveAcercamiento") = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Private Property CveEmpresaCRM As Integer
|
||||
Get
|
||||
Return ViewState("CveEmpresaCRM").ToString().ToEntero()
|
||||
@@ -1895,6 +1911,7 @@ Partial Class Ventas
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
Private Property CveAcercamientoCRM As Integer
|
||||
Get
|
||||
Return ViewState("CveAcercamientoCRM").ToString().ToEntero()
|
||||
@@ -1904,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)
|
||||
@@ -2315,7 +2346,7 @@ Partial Class Ventas
|
||||
|
||||
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||
|
||||
If UsuarioActual.CveEmpresa.Contiene(141, 152, 153, 160, 161, 162) Then System.Threading.Thread.Sleep(2000)
|
||||
If UsuarioActual.CveEmpresa.Contiene(141, 152, 153, 160, 161, 162) Then System.Threading.Thread.Sleep(2000)
|
||||
If Not IsPostBack Then
|
||||
|
||||
If IfNull(Request("Opcionx"), "").ToString = "Saldar" And UsuarioActual.CveUsuario = 100 Then
|
||||
@@ -2648,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
|
||||
@@ -9785,7 +9825,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
|
||||
@@ -10066,7 +10120,48 @@ Partial Class Ventas
|
||||
End If
|
||||
End If
|
||||
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
|
||||
'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))
|
||||
@@ -10102,17 +10197,12 @@ Partial Class Ventas
|
||||
End Select
|
||||
|
||||
|
||||
'AUTO DESCARGAR PDF
|
||||
If UsuarioActual.CveEmpresa.Contiene(72) Then
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Ant") Then
|
||||
RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1", CveVenta))}'", "Imprimir")
|
||||
End If
|
||||
End If
|
||||
|
||||
If DdlTipoComprobante.SelectedValue.Contiene("Cot") AndAlso CveEmpresaCRM > 0 AndAlso CveAcercamientoCRM > 0 Then
|
||||
RegistraScript($"window.location.href = '/Compras/PopUpVerFactura.aspx?P={Encripta(String.Format("OP=VTA&CVEVENTA={0}&PAG=1", CveVenta))}'", "Imprimir")
|
||||
End If
|
||||
|
||||
|
||||
'DESCARGAR PDF DE CICOVISA
|
||||
'If UsuarioActual.CveEmpresa = 72 And CveCliente = 70381 Then
|
||||
' If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem") Then
|
||||
@@ -10121,8 +10211,8 @@ Partial Class Ventas
|
||||
'End If
|
||||
|
||||
If DdlTipoComprobante.SelectedValue = "Cot" Then
|
||||
If Not CveEmpresaCRM > 0 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
|
||||
@@ -10140,6 +10230,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
|
||||
@@ -10214,6 +10306,7 @@ Partial Class Ventas
|
||||
Alert(MensajeAlert.ToString(), TipoMensaje.MsgDosBotones, Liga, TextoConfirmacion:="Seguir Registrando", TextoSegundoBoton:="Ir al Cliente", JSBtn2:=Liga2, ShowCloseButton:=False)
|
||||
End If
|
||||
|
||||
|
||||
MensajeAlert.Clear()
|
||||
|
||||
Try
|
||||
@@ -10284,6 +10377,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
|
||||
@@ -15671,7 +15791,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
|
||||
@@ -15703,7 +15823,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
|
||||
@@ -15728,39 +15848,56 @@ Partial Class Ventas
|
||||
End If
|
||||
|
||||
End Sub
|
||||
Private Sub GeneraPDFCotizacion(EnviaCorreo As Boolean)
|
||||
Dim pdf As Byte() = Nothing
|
||||
Private Sub GeneraPDFCotizacion(EnviaCorreo As Boolean, Optional CorreoContactoCRM As String = "", Optional pdfCRM As Byte() = Nothing,
|
||||
Optional SerieFolioCRM As String = "", Optional TipoDoctoCRM As String = "")
|
||||
|
||||
Dim pdf As Byte() = Nothing
|
||||
'GUARDA PDF
|
||||
Dim LocalSerieFolio As String = String.Empty
|
||||
Dim LocalTipoDocto As String = String.Empty
|
||||
|
||||
|
||||
|
||||
'TIMBRADO NUEVO
|
||||
Try
|
||||
If CveVenta > 0 Then
|
||||
ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False)
|
||||
End If
|
||||
|
||||
pdf = PdfFactura(ObjFactura)
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió un error al generar el PDF", ex)
|
||||
End Try
|
||||
If CorreoContactoCRM.Trim.Length > 0 Then
|
||||
pdf = pdfCRM
|
||||
LocalSerieFolio = SerieFolioCRM
|
||||
LocalTipoDocto = TipoDoctoCRM
|
||||
Else
|
||||
Try
|
||||
If CveVenta > 0 Then
|
||||
ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=False)
|
||||
End If
|
||||
|
||||
pdf = PdfFactura(ObjFactura)
|
||||
|
||||
LocalSerieFolio = ObjFactura.SerieFolio
|
||||
LocalTipoDocto = ObjFactura.TipoDocto
|
||||
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió un error al generar el PDF", ex)
|
||||
End Try
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LocalSerieFolio = ObjFactura.SerieFolio
|
||||
LocalTipoDocto = ObjFactura.TipoDocto
|
||||
|
||||
'MANDA CORREO
|
||||
If EnviaCorreo Then
|
||||
Dim ArchivoAdjunto As String = ""
|
||||
Dim ArchivoXML = ""
|
||||
Dim ArchivoPDF = String.Format("{0}PDF\{1}\{2}.pdf", UsuarioActual.Empresa.Ruta, LocalTipoDocto, LocalSerieFolio)
|
||||
|
||||
If Adjunto <> "" Then
|
||||
ArchivoAdjunto = String.Format("{0}Ventas\{1}", UsuarioActual.Empresa.Ruta, Adjunto)
|
||||
End If
|
||||
|
||||
Try
|
||||
' BytesPdfCotizacion(CveVenta)
|
||||
Dim Hilo As New System.Threading.Thread(Sub() MandaMails(UsuarioActual, CveVenta, DdlTipoComprobante.SelectedValue.ToString(), LocalSerieFolio, ChkEnviarFactura.Checked, ArchivoXML, ArchivoPDF, ArchivoAdjunto))
|
||||
Dim Hilo As New System.Threading.Thread(Sub() MandaMails(UsuarioActual, CveVenta, DdlTipoComprobante.SelectedValue.ToString(), LocalSerieFolio, ChkEnviarFactura.Checked, ArchivoXML, ArchivoPDF, ArchivoAdjunto, CorreoContactoCRM:=CorreoContactoCRM))
|
||||
Hilo.Start()
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió error al mandar Mail", ex)
|
||||
@@ -16093,8 +16230,8 @@ Partial Class Ventas
|
||||
|
||||
For Each gvr As GridViewRow In GVAnticipos.Rows
|
||||
If gvr.FCCheckBox("Chk" & gvr.RowIndex).Checked Then
|
||||
|
||||
|
||||
|
||||
|
||||
Dim FechaUltimaFluctuacion As Date = MinFecha
|
||||
Dim TipoCambioFluctuacion As Decimal = 1
|
||||
Dim tFecha As Date = Now
|
||||
@@ -20568,7 +20705,7 @@ Partial Class Ventas
|
||||
Dim DtCostos As DataTable = Nothing
|
||||
Dim DtCostosDistinct As DataTable = Nothing
|
||||
Dim IdCtaContable As Integer = 0
|
||||
|
||||
|
||||
Dim ValorInventario As Decimal = 0D
|
||||
Dim TotalCostoAcumulado As Decimal = 0D
|
||||
Dim Cont As Integer = 1
|
||||
@@ -21006,11 +21143,22 @@ 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 CorreoContactoCRM As String = "")
|
||||
|
||||
Dim ObjMail As New ClsSisMail()
|
||||
Dim ResultadoMail As Integer = 0
|
||||
|
||||
|
||||
|
||||
Dim CorreoDestino As String = ""
|
||||
|
||||
If CorreoContactoCRM.Trim.Length > 0 Then
|
||||
CorreoDestino = CorreoContactoCRM
|
||||
ViewState("MailCC") = ""
|
||||
End If
|
||||
|
||||
|
||||
|
||||
Try
|
||||
|
||||
Dim Asunto As String = String.Empty
|
||||
@@ -21062,7 +21210,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
|
||||
@@ -21071,10 +21219,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