Files
SIG/Bancos/ProveedoresAbonar.aspx.vb

2092 lines
109 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Partial Class Bancos_ProveedoresAbonar
Inherits ClsPaginas
#Region "Propiedades"
'Configuración
Private Property CveProveedor As Integer
Get
Return ViewState("CveProveedor").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveProveedor") = value
End Set
End Property
Private Property FechaI As String
Get
Return ViewState("FechaI").ToString
End Get
Set(value As String)
ViewState("FechaI") = value
End Set
End Property
Private Property FechaF As String
Get
Return ViewState("FechaF").ToString
End Get
Set(value As String)
ViewState("FechaF") = value
End Set
End Property
Private Property CveUsuarioProgramo As Integer
Get
Return IfNull(ViewState("CveUsuarioProgramo"), "-1").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveUsuarioProgramo") = value
End Set
End Property
Private Property TipoPago As Integer
Get
Return ViewState("TipoPago").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("TipoPago") = value
End Set
End Property
Private Property CveUsuarioRegistro As Integer
Get
Return ViewState("CveUsuarioRegistro").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveUsuarioRegistro") = value
End Set
End Property
Private Property CveUsuarioResponsable As Integer
Get
Return ViewState("CveUsuarioResponsable").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveUsuarioResponsable") = value
End Set
End Property
Private Property CveClasificacionProveedor As Integer
Get
Return ViewState("CveClasificacionProveedor").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveClasificacionProveedor") = value
End Set
End Property
Private Property CveAplicaNC As Integer
Get
Return ViewState("CveAplicaNC").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveAplicaNC") = value
End Set
End Property
Private Property CveMoneda As Integer
Get
Return If(IsNothing(ViewState("CveMoneda")), -1, ViewState("CveMoneda").ToString.ToEntero)
End Get
Set(value As Integer)
ViewState("CveMoneda") = value
End Set
End Property
Private Property CveMonedaFiltro As Integer
Get
Return ViewState("CveMonedaFiltro").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMonedaFiltro") = value
End Set
End Property
Private Property CveEstatus As Integer
Get
Return ViewState("CveEstatus").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveEstatus") = value
End Set
End Property
Private Property Serie As String
Get
Return ViewState("Serie").ToString
End Get
Set(value As String)
ViewState("Serie") = value
End Set
End Property
Private ReadOnly Property CtaProveedor As Integer
Get
Return ViewState("CtaProveedor").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaProveedorExtranjera As Integer
Get
Return ViewState("IdCtaProveedorExtranjera").ToString.ToEntero
End Get
End Property
Private Property IdCuenta As Integer
Get
Return ViewState("IdCuenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuenta") = value
End Set
End Property
Private Property CveProveedorSucursal As Integer
Get
Return ViewState("CveProveedorSucursal").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveProveedorSucursal") = value
End Set
End Property
Private Property IdCuentaBancariaComplementaria As Integer
Get
Return ViewState("IdCuentaBancariaComplementaria").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuentaBancariaComplementaria") = value
End Set
End Property
Private Property PermiteModificarImporte As Boolean
Get
Return CType(ViewState("PermiteModificarImporte").ToString, Boolean)
End Get
Set(value As Boolean)
ViewState("PermiteModificarImporte") = value
End Set
End Property
Private ReadOnly Property IdCtaContMonedaExtranjera As Integer
Get
Return ViewState("IdCtaContMonedaExtranjera").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContComplementaria As Integer
Get
Return ViewState("IdCtaContComplementaria").ToString.ToEntero
End Get
End Property
Private Property ComprobanteIE As String
Get
Return ViewState("ComprobanteIE").ToString
End Get
Set(value As String)
ViewState("ComprobanteIE") = value
End Set
End Property
Private Property CodigoProgramacion As String
Get
Return ViewState("CodigoProgramacion").ToString
End Get
Set(value As String)
ViewState("CodigoProgramacion") = value
End Set
End Property
Private Property CveSubProyectoFiltro As Integer
Get
If ViewState("CveSubProyectoFiltro") Is Nothing Then
ViewState("CveSubProyectoFiltro") = -1
End If
Return ViewState("CveSubProyectoFiltro").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveSubProyectoFiltro") = value
End Set
End Property
Private Property DtDatos As DataTable
Get
Return DirectCast(ViewState("DtDatos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatos") = value
End Set
End Property
Private Property OriReferenciaCIE As String
Get
If ViewState("OriReferenciaCIE") Is Nothing Then
Return ""
Else
Return ViewState("OriReferenciaCIE").ToString
End If
End Get
Set(value As String)
ViewState("OriReferenciaCIE") = value
End Set
End Property
Private Property OriConceptoCIE As String
Get
If ViewState("OriConceptoCIE") Is Nothing Then
Return ""
Else
Return ViewState("OriConceptoCIE").ToString
End If
End Get
Set(value As String)
ViewState("OriConceptoCIE") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If Not UsuarioActual.Empresa.UsaAC Then
ViewState("IdCtaContMonedaExtranjera") = 0
ViewState("IdCtaContComplementaria") = 0
ViewState("IdCtaContRetIVA") = 0
ViewState("IdCtaContRetISR") = 0
End If
IdCuenta = 0
PermiteModificarImporte = True
TxtFechaIncobrable.Text = Now.ToShortDateString
If Request("CveProveedor") IsNot Nothing AndAlso Request("CveProveedor").ToString.ToEntero > 0 Then
CveProveedor = IfNull(Request("CveProveedor"), "-1").ToString.ToEntero
FechaI = IfNull(Request("FechaI"), "-1").ToString
FechaF = IfNull(Request("FechaF"), "-1").ToString
CveUsuarioProgramo = IfNull(Request("CveUsuarioProgramo"), "-1").ToString.ToEntero
TipoPago = IfNull(Request("TipoPago"), "-1").ToString.ToEntero
CveUsuarioRegistro = IfNull(Request("CveUsuarioRegistro"), "-1").ToString.ToEntero
CveUsuarioResponsable = IfNull(Request("CveUsuarioResponsable"), "-1").ToString.ToEntero
CveClasificacionProveedor = IfNull(Request("CveClasificacion"), "-1").ToString.ToEntero
CveMoneda = IfNull(Request("CveMoneda"), "-1").ToString.ToEntero
CveMonedaFiltro = IfNull(Request("CveMoneda"), "-1").ToString.ToEntero
CveEstatus = IfNull(Request("CveEstatus"), "-1").ToString.ToEntero
Serie = IfNull(Request("Serie"), "").ToString
CveAplicaNC = IfNull(Request("CveAplicaNC"), "-1").ToString.ToEntero
CveProveedorSucursal = IfNull(Request("CveProveedorSucursal"), "-1").ToString.ToEntero
CodigoProgramacion = IfNull(Request("CodigoProgramacion"), "-1").ToString
CveSubProyectoFiltro = IfNull(Request("CveSubProyecto"), -1).ToString.ToEntero
TxtOtrosImportes.Attributes.Add("onKeyUp", String.Format("FnSuma(this,{0},{1});", "TxtTotal", 0))
'proceso para que solo pague lo que este programada
If UsuarioActual.TienePermisoProceso(98) Then
PermiteModificarImporte = False
End If
Calendario.StartDate = Now.AddMonths(-8)
'proceso que restringue solo el pago de apartir del dia de hoy y como limite fin de mes
If UsuarioActual.TienePermisoProceso(105) Then
Calendario.StartDate = Now
Calendario.EndDate = Now.LastDayOfMonth
MEVCalendario.MinimumValue = Now.ToShortDateString
MEVCalendario.MaximumValue = Now.LastDayOfMonth.ToShortDateString
MEVCalendario.Enabled = True
End If
CargaProveedor(Request("CveProveedor").ToString.ToEntero)
End If
' If UsuarioActual.Empresa.Funcionalidad(142) = "1" Then
trNotificar.Visible = True
UpDatos.Visible = True
'End If
If UsuarioActual.Empresa.UsaAC Then
PnlAC.Visible = True
' Dim AC As New ClsAC
' If AC.GetPresupuestoEgresos(-1, True, usuarioactual.Empresa.EjercicioActual, UsuarioActual.CveEmpresa) Then
' 'DdlProgramaOperativo.DataSource = AC.DtResultados
' 'DdlProgramaOperativo.DataBind()
' GvAC.DataSource = AC.DtResultados
' GvAC.DataBind()
' End If
' AC.Dispose()
End If
'BANDERA DE SURTIDO
If UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Or UsuarioActual.Empresa.Funcionalidad(134).ToEntero > 0 Then
GvCxP.Columns(3).Visible = True
End If
If CveMoneda > 0 Then
LbTipoMoneda.Text = String.Format("Pago en {0}", GlobalDTMonedas.FiltraParametros(String.Format("CveMoneda = {0}", CveMoneda)).Rows(0)("Moneda"))
End If
If CveMoneda = 2 Then
ChkPagarPesos.Visible = True
TxtTC.Text = GlobalTipoCambio(Now).FormatoNumero(4)
TxtTCDolaresDolares.Text = GlobalTipoCambio(Now).FormatoNumero(4)
DivDolaresDolares.Visible = True
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
Else
ChkPagarDolares.Visible = True
TxtTCDolares.Text = GlobalTipoCambio(Now).FormatoNumero(4)
End If
RegistraScript($"TipoCambioActual = {GlobalTipoCambio(Now).FormatoNumero(4)}")
UpDatos.Update()
If UsuarioActual.TienePermisoProceso(215) Or UsuarioActual.TienePermisoProceso(204) Then
HlSaldarCuentasSinPagar.Visible = True
End If
If UsuarioActual.CveEmpresa.Contiene(119, 158) And CveUsuarioProgramo <> -1 Then
LnkPDFSolicitud.Visible = True
LnkExcelSolicitud.Visible = True
End If
End If
End Sub
Protected Sub BtnCambiaTipoMoneda_Click(sender As Object, e As EventArgs)
CambiaTipoMoneda()
End Sub
Private Sub CambiaTipoMoneda()
If DivTC.Visible Then
TxtTC.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
RegistraScript("CambiaPesosDolares();")
End If
If DivTCDolares.Visible Then
TxtTCDolares.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
RegistraScript("CambiaDolaresPesos();")
End If
If DivDolaresDolares.Visible Then
TxtTCDolaresDolares.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
End If
UpDatos.Update()
End Sub
#Region " CARGA DATOS "
Private Sub CargaDatos(Optional tCveMoneda As Integer = -1) 'pCveProveedor As Integer, tCveMoneda As Integer, FechaVencimientoInicio As String, FechaVencimientoFin As String, CveUsuarioRegistro As Integer, CveUsuarioPrograma As Integer, Serie As String)
If tCveMoneda = -1 Then tCveMoneda = CveMoneda
Dim Mov As New ClsMovimientos
TxtObservaciones.Text = ""
TxtImporte.Text = ""
TxtTotal.Text = ""
If Mov.GetCxPProveedor(CveProveedor, FechaI, FechaF, CveUsuarioProgramo, CveUsuarioRegistro, CveUsuarioResponsable, CveClasificacionProveedor, tCveMoneda, CveEstatus, CveProveedorSucursal, CveAplicaNC, "-1", "-1", CodigoProgramacion, CveSubProyecto:=CveSubProyectoFiltro) Then
DtDatos = Mov.DtResultados.FiltraParametros("Saldo > 0", "Fecha,SerieFolio")
GvCxP.DataSource = DtDatos
DtDatos.Columns.Add("Movimiento")
If DtDatos.Rows.Count > 0 Then
DVBusqueda.Visible = True
DtDatos.Rows(0)("Movimiento") = "FACTURA DE ACREEDOR"
End If
End If
Mov.Dispose()
GvCxP.DataBind()
UPCompras.Update()
UpBusqueda.Update()
End Sub
Private Sub CargaProveedor(tCveProveedor As Integer)
Dim ObjProveedor As New ClsCompProveedores()
If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, tCveProveedor, "-1", "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) Then
If ObjProveedor.DtResultados.Rows.Count > 0 Then
'Campos para Modificación
'GeneralesLblEncabezado
CargaTipoTransaccion()
CargaCuentas(DdlTipoTransaccion.SelectedValue.ToEntero)
TxtFechaDocumento.Text = Now.ToShortDateString
TxtPagueseA.Enabled = False
HplProveedor.Text = ObjProveedor.RazonSocial
HplProveedor.NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", tCveProveedor)
TxtPagueseA.Text = ObjProveedor.RazonSocial
TxtImporte.Attributes.Add("disabled", "disabled")
If DdlTipoTransaccion.SelectedValue = "1" Then RFVFolio.Enabled = True Else RFVFolio.Enabled = False
TxtNotificarA.Text = $"{ObjProveedor.NotificarA.Trim}"
If ObjProveedor.CorreoCobranza.Trim <> "" Then TxtNotificarA.Text = $"{TxtNotificarA.Text};{ObjProveedor.CorreoCobranza.Trim}"
ViewState("IdCtaContRetIVA") = ObjProveedor.IdCtaContRetIVA
ViewState("IdCtaContRetIVAAcreditable") = ObjProveedor.IdCtaContRetIVAAcreditable
ViewState("IdCtaContRetISR") = ObjProveedor.IdCtaContRetISR
ViewState("IdCtaContRetISRAcreditable") = ObjProveedor.IdCtaContRetISRAcreditable
'Sección de pago a proveedor
LtlNombreProveedor.Text = ObjProveedor.RazonSocial
LtlRFCProveedor.Text = ObjProveedor.RFC
ViewState("CtaProveedor") = ObjProveedor.IdCtaContProveedores
ViewState("IdCtaProveedorExtranjera") = ObjProveedor.IdCtaContProveedoresExtranjera
ViewState("CtaAcreedor") = ObjProveedor.IdCtaContAcreedor
ViewState("IdCtaAcreedorExtranjera") = ObjProveedor.IdCtaContAcreedorExtranjera
ViewState("IdCtaContComplementaria") = ObjProveedor.IdCtaContProveedoresComplementaria
ViewState("IdCtaAcreedorComplementaria") = ObjProveedor.IdCtaContAcreedorComplementaria
If Serie <> "" AndAlso Serie <> "-1" Then
Dim dr As DataRow = GlobalDTProveedorSucursales(CveProveedor, UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("Serie = '{0}'", Serie))
If dr IsNot Nothing Then
TxtObservaciones.Text = String.Format("Suc. {0}", dr("ProveedorSucursal"))
HdnObs.Value = TxtObservaciones.Text
End If
End If
CargaDatos() '(tCveProveedor, CveMoneda, FechaI, FechaF, CveUsuarioRegistro, CveUsuarioProgramo, Serie)
CargaCuentasDepositos()
'CUANDO VIENE PROGRAMADO LLENA EL TEXTO OBSERVACIONES
If CveUsuarioProgramo <> -1 Then RegistraScript("SumaValores();")
Else
Alert("El Proveedor Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia)
End If
End If
ObjProveedor.Dispose()
End Sub
#End Region
#Region " GV CXP "
Protected Sub GvCxP_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvCxP.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(9).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(10).HorizontalAlign = HorizontalAlign.Right
e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo")))
If e.Row.RowIndex = 0 Then
e.Row.FCHyperLink("HplF").Text = (CType(GvCxP.DataSource, DataTable).Rows.Count - 1).ToString
e.Row.BackColor = Drawing.Color.LightGray
End If
If e.Row.DBCampo("CveCompra") = "" Then
e.Row.FCTextBox("TxtAbonar").Visible = False
e.Row.FCCheckBox("Chk").Visible = False
e.Row.FCTextBox("TxtComision").Visible = False
Else
e.Row.FCTextBox("TxtAbonar").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},1,'{2}',1);", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), "El Importe no debe de exceder el saldo"))
e.Row.FCTextBox("TxtComision").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},2,'{2}',2);", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), "El Importe no debe de exceder el saldo"))
End If
If e.Row.DBCampo("Saldo").ToDouble < 0 Then e.Row.Cells(7).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("DiasVencidos").ToDouble > 0 AndAlso CType(sender, GridView).ID = "GvCxC" Then e.Row.Cells(4).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("TotalOriginal").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldoOriginal"), Literal).Text = ""
If e.Row.DBCampo("Abonado").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlAbonado"), Literal).Text = ""
If e.Row.DBCampo("Saldo").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldo"), Literal).Text = ""
If e.Row.DBCampo("Folio") = "N/D" Then
e.Row.FCLiteral("LtlFactura").Text = e.Row.DBCampo("Folio")
End If
If e.Row.DBCampo("CveCompra").ToEntero > 0 Then
Dim FiltroInv As String = ""
If UsuarioActual.Empresa.Funcionalidad(134).ToEntero > 0 Then ' valores 1 - permite pago proporcional, valor 2. paga solo si se recibio el 100%
'se bloquean las opciones
e.Row.FCCheckBox("Chk").Enabled = False
e.Row.FCTextBox("TxtAbonar").Enabled = False
Dim Str As New StringBuilder
Str.AppendFormat("Importe Almacen: ${0} ({1}%) <br/>", e.Row.DBCampo("ImporteAlmacen").FormatoNumero, e.Row.DBCampo("ImporteAlmacenPorcentaje"))
If e.Row.DBCampo("ImporteServicios").ToDouble > 0 Then Str.AppendFormat("Importe Servicios: ${0} ({1}%) <br/>", e.Row.DBCampo("ImporteServicios").FormatoNumero, e.Row.DBCampo("ImporteServiciosPorcentaje"))
If e.Row.DBCampo("ImporteDevolucion").ToDouble > 0 Then Str.AppendFormat("Importe Devuelto: ${0} ({1}%) <br/>", e.Row.DBCampo("ImporteDevolucion").FormatoNumero, e.Row.DBCampo("ImporteDevolucionPorcentaje"))
Str.AppendFormat(" <i> Importes <b> SIN</b> IVA</i>")
e.Row.FCLabel("LbEstatusInv").Attributes.Add("title", Str.ToString)
Dim PorcentajeAlmacen As Decimal = e.Row.DBCampo("ImporteAlmacenPorcentaje").ToString.ToDecimal + e.Row.DBCampo("ImporteServiciosPorcentaje").ToString.ToDecimal + e.Row.DBCampo("ImporteDevolucionPorcentaje").ToString.ToDecimal
Dim SaldoInv As Decimal = (e.Row.DBCampo("Saldo").ToString.ToDecimal * (PorcentajeAlmacen / 100))
If UsuarioActual.Empresa.Funcionalidad(134) = "1" Then 'cuando es proporcional
FiltroInv = $"FnCambia({e.Row.FCCheckBox("Chk").ClientID},this,{SaldoInv},1,'{"El importe no debe exceder lo recibido en almacén"}',1);"
ElseIf UsuarioActual.Empresa.Funcionalidad(134) = "2" Then
FiltroInv = "" 'queno considera lo proporcional
End If
If PorcentajeAlmacen = 0 Then ' sin recibir
e.Row.FCLabel("LbEstatusInv").Text = "<i Class='fa fa-flag-o' aria-hidden='true'></i>"
e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.Red
ElseIf PorcentajeAlmacen > 99.0 OrElse e.Row.DBCampo("ImporteAlmacen").ToDecimal >= e.Row.DBCampo("Saldo").ToString.ToDecimal Then 'recibido completo ' si tiene un porcentaje mayor ingresado, que este halla sido por OC, debe de permitirlo
' NOTA. si la factura tiene devoluciones, debera comparar el saldo de la factura con lo recibido en el almacen
e.Row.FCLabel("LbEstatusInv").Text = "<i Class='fa fa-flag' aria-hidden='true'></i>"
e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.Green
e.Row.FCCheckBox("Chk").Enabled = True
e.Row.FCTextBox("TxtAbonar").Enabled = True
Else ' parcial
e.Row.FCLabel("LbEstatusInv").Text = "<i Class='fa fa-flag-checkered' aria-hidden='true'></i>"
e.Row.FCLabel("LbEstatusInv").ForeColor = Drawing.Color.DarkOrange
If UsuarioActual.Empresa.Funcionalidad(134).ToEntero = 1 Then ' si es la opcion ,de pagar lo proporcional
e.Row.FCCheckBox("Chk").Enabled = True
e.Row.FCTextBox("TxtAbonar").Enabled = True
End If
End If
End If
e.Row.FCLiteral("LtlAux").Text = String.Format("<a Class=""Texto thickbox"" href=""/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxPProveedor&CveProveedor={0}&CveCompra={1}&TB_iframe=true&height=370&width=900"" />Ir</a>", e.Row.DBCampo("CveProveedor"), e.Row.DBCampo("CveCompra"))
e.Row.FCTextBox("TxtAbonar").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},1,'{2}',1);{3}", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), "El Importe no debe de exceder el saldo", FiltroInv))
If Not PermiteModificarImporte Then e.Row.FCTextBox("TxtAbonar").Enabled = False
If e.Row.DBCampo("CveCompraNC").ToEntero > 0 Then
e.Row.FCHyperLink("HplNC").Visible = True
e.Row.FCHyperLink("HplNC").ImageUrl = "/Imagenes/flag_green.png"
e.Row.FCHyperLink("HplNC").ToolTip = "Notas de Crédito Aplicadas"
End If
If e.Row.DBCampo("ImporteProgramo").ToDouble > 0 Then
e.Row.FCCheckBox("chk").Checked = True
e.Row.FCTextBox("TxtAbonar").Text = e.Row.DBCampo("ImporteProgramo").ToDouble.FormatoNumero()
' N O T A: si el importe programado es mayor al Saldo de la factura, se pone el saldo
If e.Row.DBCampo("ImporteProgramo").ToDouble > e.Row.DBCampo("Saldo").ToDouble Then
e.Row.FCTextBox("TxtAbonar").ToolTip = "El importe programado es mayor al saldo. El Importe visible es el saldo "
'e.Row.FCTextBox("TxtAbonar").BackColor = Drawing.Color.OrangeRed
e.Row.FCTextBox("TxtAbonar").CssClass = "bg-yellow-gold"
e.Row.FCTextBox("TxtAbonar").Text = e.Row.DBCampo("Saldo").FormatoNumero()
'se va acumulando el importe de cada renglon para sacar el pago del IE
TxtImporte.Text = (TxtImporte.Text.ToDouble + e.Row.DBCampo("Saldo").ToDouble).FormatoNumero()
Else
'se va acumulando el importe de cada renglon para sacar el pago del IE
TxtImporte.Text = (TxtImporte.Text.ToDouble + e.Row.DBCampo("ImporteProgramo").ToDouble).FormatoNumero()
End If
End If
'si está bloqueada y es refacturación, debe de permitirlo, sin importar lo que se halla ingresado
If e.Row.DBCampo("CveCompraRefacturacion").ToEntero > 0 AndAlso Not e.Row.FCCheckBox("Chk").Enabled Then
e.Row.FCCheckBox("Chk").Enabled = True
e.Row.FCTextBox("TxtAbonar").Enabled = True
End If
If UsuarioActual.Empresa.Funcionalidad(306) = "1" And e.Row.DBCampo("AplicaNotaCredito").ToString = "True" Then
e.Row.FCCheckBox("Chk").Enabled = False
End If
End If
End If
End Sub
#End Region
#Region " GUARDAR "
Protected Sub BtnIEGuardar_Click(sender As Object, e As EventArgs) Handles BtnIEGuardar.Click
Dim ValFechaDocumento As Boolean = False
Dim FoliosFechasValFechaDocumento As New StringBuilder
FoliosFechasValFechaDocumento.AppendLine("Se seleccionaron facturas con fecha de mes superior al mes del pago: <br/>")
For Each gvRowVal As GridViewRow In GvCxP.Rows
If gvRowVal.FCCheckBox("Chk").Checked Then
Dim FechaFactura As Date = gvRowVal.DataKey("Fecha").ToDate
Dim FechaDocumento As Date = TxtFechaDocumento.Text.ToDate
Dim AnioFactura As Integer = FechaFactura.Year
Dim MesFactura As Integer = FechaFactura.Month
Dim AnioDocumento As Integer = FechaDocumento.Year
Dim MesDocumento As Integer = FechaDocumento.Month
If UsuarioActual.Empresa.UsaAC = False Then
If AnioFactura > AnioDocumento Then
FoliosFechasValFechaDocumento.AppendLine($"Folio: { gvRowVal.DataKey("SerieFolio") } fecha: {gvRowVal.DataKey("Fecha").ToDate.ToString("dd/MM/yyyy") } <br/>")
ValFechaDocumento = True
ElseIf AnioFactura = AnioDocumento And MesFactura > MesDocumento Then
FoliosFechasValFechaDocumento.AppendLine($"Folio: { gvRowVal.DataKey("SerieFolio") } fecha: {gvRowVal.DataKey("Fecha").ToDate.ToString("dd/MM/yyyy") } <br/>")
ValFechaDocumento = True
End If
End If
End If
Next
If ValFechaDocumento Then
Alert(FoliosFechasValFechaDocumento.ToString, TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If DdlTipoTransaccion.SelectedValue.ToEntero < 0 Then
Alert("Seleccione un tipo de transacción", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If DdlCuenta.SelectedValue.ToEntero < 0 Then
Alert("Seleccione una cuenta bancaria", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If CveMoneda <= 0 Then
Alert("Seleccione la Moneda del pago", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim Dep As New ClsGenerales
If Dep.GetCuentasDepositos(CveProveedor:=CveProveedor) Then
Dim Row = Dep.DtResultados.FiltroPrimero(String.Format("CveCuentaDeposito = {0}", DdlCuentaDeposito.SelectedValue.ToEntero))
If Row IsNot Nothing AndAlso Row("Estatus").ToString = "False" Then
Alert("La cuenta depósito del proveedor esta inactiva.", TipoMensaje.MsgAdvertencia)
Dep.Dispose()
Exit Sub
End If
End If
Dep.Dispose()
'proceso que restringue solo el pago de apartir del dia de hoy y como limite fin de mes
If UsuarioActual.TienePermisoProceso(105) AndAlso (TxtFechaDocumento.Text.ToDate < Now.Date Or TxtFechaDocumento.Text.ToDate > Now.LastDayOfMonth) Then
Alert("Fecha No permitida", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ImporteSeleccionado As Decimal = 0
If Not UsuarioActual.Empresa.Funcionalidad(529) = "1" Then
Dim Validada As Boolean = False
Dim MsgValidadas As New StringBuilder
Dim Valida As New ClsValidaCFDi()
'verifico ante el SAT las compras que voy a pagar
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
ImporteSeleccionado += gvr.FCTextBox("TxtAbonar").Text.ToDecimal
If gvr.DataKey("UUID") <> "" Then
Valida.Verificar(gvr.DataKey("UUID"), gvr.DataKey("RFC"), UsuarioActual.Empresa.RFC, gvr.DataKey("TotalOriginal").ToDecimal)
If Not UsuarioActual.Empresa.FacturaProduccion OrElse UsuarioActual.CveEmpresa < 2 Then
Valida.EsValida = 1
End If
If Valida.EsValida <> 1 Then
Validada = False
If Valida.EsValida = 2 Then 'Cancelada
'estatus inventario, no surtida
If gvr.DataKey("EstatusInventario") = "1" Then
MsgValidadas.AppendFormat("Factura Cancelada: {0} - {1} , relacione su factura nueva para descontar saldo<br>", gvr.DataKey("SerieFolio"), gvr.DataKey("Descripcion"))
Else
MsgValidadas.AppendFormat("Factura Cancelada: {0} - {1} con movimientos de almacen, relacione su factura nueva para descontar saldo<br>", gvr.DataKey("SerieFolio"), gvr.DataKey("Descripcion"))
End If
Else
MsgValidadas.AppendFormat("Factura No se pudo Validar: {0} - {1}<br>", gvr.DataKey("SerieFolio"), gvr.DataKey("Descripcion"))
End If
End If
End If
End If
Next
Valida.Dispose()
'verificacion doble, si no la han cancelado, ya tiene una validaci[on para que llegue aqui
If MsgValidadas.Length > 0 Then
Alert(String.Format("<br>Las Facturas presentan la siguiente situación ante el SAT. <br>{0}", MsgValidadas.ToString), TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Else
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
ImporteSeleccionado += gvr.FCTextBox("TxtAbonar").Text.ToDecimal
End If
Next
End If
If ImporteSeleccionado <= 0 Then
Alert("Seleccione facturas", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjIE As New ClsBancos()
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
Dim ObjComp As New ClsCompras(ObjIE.IniciaTransacSQL)
Dim ObjConta As ClsContPAQi = Nothing
If UsuarioActual.Empresa.TipoContabilidad = 2 AndAlso UsuarioActual.Empresa.UsaContabilidad Then
ObjConta = New ClsContPAQi(UsuarioActual.Empresa)
ObjConta.IniciaTransacSQL()
End If
Dim MsgError As String = ""
Dim IDPoliza As Integer = 0
Dim FolioPoliza As Integer = 0
Dim CveCuentaDeposito As Integer = 0
Dim CveConceptoCompra As Integer = 6
Dim CvePrePoliza As Integer = 0
Dim CveSubProyecto As Integer = -1
If DdlCuentaDeposito.Items.Count > 0 Then
CveCuentaDeposito = DdlCuentaDeposito.SelectedValue.ToEntero
End If
'Saca moneda en que se va a pagar segun metodo de pago
If DdlCuenta.SelectedValue.ToEntero > 0 Then
CveMoneda = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero}").ToEntero
End If
If TxtImporte.Text.ToDouble > 0 Then
If TxtFolio.Text.Trim <> "" Then
Dim Fecha As Date = TxtFechaDocumento.Text.ToDate
Dim filesgral As List(Of Archivo) = Anexo.getfiles().Archivos
Dim filemove As String = ""
Dim Comprobante As String = ""
ComprobanteIE = ""
For Each fileItem As Archivo In filesgral
Comprobante = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "")
filemove = fileItem.filename
Next
Dim ConceptoPoliza As String = String.Format("{0} {1}", HplProveedor.Text, TxtObservaciones.Text)
Dim FolioFijo As Integer = 0
Dim TipoCambio As Decimal = 0
'cheque
If DdlTipoTransaccion.SelectedValue = "1" AndAlso UsuarioActual.CveEmpresa.Contiene(13, 83) Then FolioFijo = TxtFolio.Text.ToEntero
CvePrePoliza = ObjMov.AddPrePolizas("Bancos/ProveedoresAbonar", 2, ImporteSeleccionado, ImporteSeleccionado, 1, TxtFechaDocumento.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, FolioFijo:=FolioFijo, ReglaFolioPoliza:=ObjComp.ObtenerReglaFolio(DdlTipoTransaccion.SelectedValue, Nothing, UsuarioActual.CveEmpresa), CveTipoPoliza:=ObjMov.ObtenerTipoPoliza(DdlTipoTransaccion.SelectedValue, "-1", UsuarioActual.CveEmpresa))
If CveMoneda = 2 Then
If TxtTCDolares.Visible Then
TipoCambio = TxtTCDolares.Text.ToDecimal
Else
TipoCambio = TxtTCDolaresDolares.Text.ToDecimal
End If
Else
If TxtTC.Visible Then
TipoCambio = TxtTC.Text.ToDecimal
End If
End If
Dim CveIE As Integer = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaDocumento.Text.Trim.ToDate, TxtFolio.Text.Trim, TxtPagueseA.Text.Trim, TxtImporte.Text.ToDecimal, GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", "CveCuenta = " & DdlCuenta.SelectedValue).ToEntero, TipoCambio, TxtObservaciones.Text.Trim, TxtNotificarA.Text.Trim, ChkAbonoCuenta.Checked, True, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCuentaDeposito:=CveCuentaDeposito, Referencia:=If(TxtReferenciaCIE.Visible, TxtReferenciaCIE.Text, "-1"), CveCuentaTarjeta:=If(DivTarjeta.Visible, DdlTarjeta.SelectedValue.ToEntero, -1), ConceptoCIE:=TxtConceptoCIE.Text)
If CveIE > 0 Then
ComprobanteIE = $"{CveIE}.{Comprobante}"
If DdlCuentaDeposito.SelectedValue.ToEntero > 0 And DdlTipoTransaccion.SelectedValue = "17" Then
If TxtReferenciaCIE.Text <> OriReferenciaCIE Or TxtConceptoCIE.Text <> OriConceptoCIE Then
Dim ObjGrales As New ClsGenerales(ObjIE.IniciaTransacSQL)
If Not ObjGrales.UpdateCuentasDepositosEstatusPagoElectronicoGrupos(DdlCuentaDeposito.SelectedValue.ToEntero, -1, -1, "-1", TxtReferenciaCIE.Text.Trim, TxtConceptoCIE.Text.Trim) Then
MsgError = "Error al actualziar Cuanta Referencia y Concepto Deposito."
End If
End If
End If
'guardo el archivo
If filemove <> "" Then
filemove.FilesMove(CveIE.ToString, String.Format("{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase:=False)
End If
Anexo.Text = ""
'inserto los movimientos de la conta para abonar al saldo
If CvePrePoliza > 0 Then
Dim Pago As New CompraPago
Pago.Fecha = TxtFechaDocumento.Text.ToDate
Pago.CveIE = CveIE
Pago.CveMonedaPago = CveMoneda
'inserto las compras que voy a pagar
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
Dim CompraActual As New Compra
CompraActual.CveCompra = gvr.DataKey("CveCompra").ToEntero
CompraActual.CveTipoConceptoProveedor = gvr.DataKey("CveTipoConcepto").ToEntero
CompraActual.CveProveedor = gvr.DataKey("CveProveedor").ToEntero
CompraActual.CveMoneda = gvr.DataKey("CveMoneda").ToEntero
CompraActual.SerieFolio = gvr.DataKey("SerieFolio").ToString
CompraActual.ProveedorNombre = HplProveedor.Text
CompraActual.TC = gvr.DataKey("TipoCambioOriginal").ToDecimal
CompraActual.Total = gvr.DataKey("Total").ToDecimal
CompraActual.IVA = gvr.DataKey("IVA").ToDecimal
CompraActual.IVADeducible = gvr.DataKey("IVADeducible").ToDecimal
CompraActual.IEPS = gvr.DataKey("IEPS").ToDecimal
CompraActual.RetIVA = gvr.DataKey("RetIVA").ToDecimal
CompraActual.RetISR = gvr.DataKey("RetISR").ToDecimal
CompraActual.CveConceptoRetISR = gvr.DataKey("CveRetISRConcepto").ToEntero
CompraActual.CveConceptoRetIVA = gvr.DataKey("CveRetIVAConcepto").ToEntero
CompraActual.PorcentajeIVA = gvr.DataKey("PorcentajeIVA").ToDecimal
CompraActual.EsImportacion = gvr.DataKey("EsImportacion") = "1"
CompraActual.UsuarioActual = UsuarioActual
CompraActual.CveSubProyecto = gvr.DataKey("CveSubProyecto").ToEntero
CompraActual.IdCtaContableProv = If(CompraActual.CveMoneda >= 2, IdCtaContMonedaExtranjera, CtaProveedor)
CompraActual.IdCtaContableProvComplementaria = IdCtaContComplementaria
'Importe de pago
Pago.ImportePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
'Tipos de cambio
If Pago.CveMonedaPago = 1 AndAlso CompraActual.CveMoneda = 2 Then 'Si la venta viene en Dolares y se va a pagar en Pesos
Pago.TCPago = TxtTC.Text.ToDecimal
ElseIf Pago.CveMonedaPago = 2 AndAlso CompraActual.CveMoneda = 2 Then 'Si la venta viene en Dolares y se va a pagar en DOLARES
Pago.TCPago = TxtTCDolaresDolares.Text.ToDecimal
ElseIf Pago.CveMonedaPago = 2 AndAlso CompraActual.CveMoneda = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
Pago.TCPago = TxtTCDolares.Text.ToDecimal
End If
If gvr.FCTextBox("TxtComision").Text.ToDecimal <> 0 Then
Pago.OtroGastoIngreso = gvr.FCTextBox("TxtComision").Text.ToDecimal
Else
Pago.OtroGastoIngreso = 0
End If
If AplicaPrePolizaPagoCompra(CompraActual, Pago, CvePrePoliza, ObjMov) Then
MsgError = "No se pudo insertar la póliza"
End If
'DESPROGRAMA LO PROGRAMADO DESPUES DE HACERLE UN PAGO
' If DdlTipoTransaccion.SelectedValue <> "9" Then 'SI ES LAYOUT SE DESPROGRAMA EN BANCOS/PAGOELECTRONICO, se comentó, 2018.07.31 peticion marilú.
If MsgError = "" AndAlso gvr.DataKey("ImporteProgramo").ToDouble > 0 Then
ObjComp.ProgramarCompra(gvr.DataKey("CveCompra").ToEntero, 0, UsuarioActual.CveUsuario, -1)
End If
End If
Next
Dim UsaComplementariaBancos As Boolean = Not UsuarioActual.CveEmpresa.Contiene(7, 11, 122, 145)
Dim ConceptoMovimiento As String = $"{TxtPagueseA.Text.Trim} - {TxtObservaciones.Text} {If(Pago.TCPago > 1, $" TC:{Pago.TCPago}", "")}"
Dim Referencia As String = $"{HdnTipoTransaccionAbreviatura.Value}: {TxtFolio.Text.Trim}"
Dim tImporteMN As Decimal = TxtImporte.Text.ToDecimal
Pago.ImportePago = tImporteMN
If DivTarjeta.Visible AndAlso DdlTarjeta.SelectedValue.ToEntero > 0 Then
Dim ObjCreditos As New ClsBancos
ObjCreditos.GetTarjetasCreditos(DdlCuenta.SelectedValue.ToEntero, DdlTarjeta.SelectedValue.ToEntero)
If ObjCreditos.DtResultados.Rows.Count > 0 AndAlso (ObjCreditos.DtResultados.Rows(0)("IdCtaContableTarjeta").ToString.ToEntero > 0 Or ObjCreditos.DtResultados.Rows(0)("IdCtaContableTarjetaSIG").ToString.ToEntero > 0) Then
IdCuenta = ObjCreditos.DtResultados.Rows(0)("IdCtaContableTarjeta").ToString.ToEntero
End If
Dim Importe42 As Decimal = Pago.ImportePago + Pago.OtroGastoIngreso
tImporteMN = If(Pago.CveMonedaPago = 2, If(DivTC.Visible, Importe42 / TxtTC.Text.ToDecimal * Pago.TCPago, Importe42 * Pago.TCPago), Importe42)
If MsgError = "" AndAlso Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, Importe42, tImporteMN, 42, Referencia, ConceptoMovimiento, IdCuenta, CveIE:=CveIE, CveProveedor:=CveProveedor, TipoCambio:=Pago.TCPago, CveSubProyecto:=CveSubProyecto) Then
MsgError = "No se pudo insertar la póliza"
End If
Else
If Not UsaComplementariaBancos Then tImporteMN = (tImporteMN * Pago.TCPago).RoundSQL
If MsgError = "" AndAlso Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, Pago.ImportePago, tImporteMN, 30, Referencia, ConceptoMovimiento, IdCuenta, CveIE:=CveIE, CveProveedor:=CveProveedor, TipoCambio:=Pago.TCPago, CveSubProyecto:=CveSubProyecto) Then
MsgError = "No se pudo insertar la póliza"
End If
If Pago.CveMonedaPago = 2 AndAlso UsaComplementariaBancos Then
If MsgError = "" AndAlso Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, Pago.ImportePago, (Pago.ImportePago * Pago.TCPago - Pago.ImportePago).RoundSQL, 204, Referencia, ConceptoMovimiento, IdCuentaBancariaComplementaria, CveIE:=CveIE, CveProveedor:=CveProveedor, ImporteME:=Pago.ImportePago, TipoCambio:=Pago.TCPago, CveSubProyecto:=CveSubProyecto) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
If UsuarioActual.CveEmpresa.Contiene(119, 158) AndAlso CveMoneda = 2 AndAlso CveMonedaFiltro = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
'fluctuación.
Dim TCPago = TxtTCDolares.Text.ToDecimal
Dim ImporteFluctuacion As Decimal = 0 '((ImporteSeleccionado / TCPago) - TxtImporte.Text.ToDecimal)
Dim DtPrePoliza As DataTable = Nothing
If ObjMov.GetPrePolizasDetalle(CvePrePoliza, UsuarioActual.CveEmpresa) Then
DtPrePoliza = ObjMov.DtResultados.Copy
End If
Dim PagoProveedoresME = DtPrePoliza.SUMD("ImporteMN", "CveConceptoContable = 312 AND TipoMovto = 0")
Dim Bancos = DtPrePoliza.SUMD("ImporteMN", "CveConceptoContable = 30 AND TipoMovto = 1")
Dim BancosComplementaria = DtPrePoliza.SUMD("ImporteMN", "CveConceptoContable = 204 AND TipoMovto = 1")
DtPrePoliza.Dispose()
ImporteFluctuacion = PagoProveedoresME - (Bancos + BancosComplementaria)
If MsgError = "" AndAlso ImporteFluctuacion.RoundSQL() <> 0 Then
'SI EL PAGO DE PROVEEDORES ME ES MAYOR QUE BANCOS METER EL CONCEPTO DE GANANCIA
If ImporteFluctuacion > 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, Math.Abs(ImporteFluctuacion), Referencia, 64, ConceptoMovimiento, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=UsuarioActual.Empresa.IdCuentaGananciaCambiaria, CveIE:=-1, IdSegmentoNegocio:=-1, CveSubProyecto:=CveSubProyecto, CveProveedor:=Me.CveProveedor, CveCompra:=-1, ImporteMX:=Math.Abs(ImporteFluctuacion), TipoCambio:=TipoCambio, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
ElseIf ImporteFluctuacion < 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, Math.Abs(ImporteFluctuacion), Referencia, 65, ConceptoMovimiento, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=UsuarioActual.Empresa.IdCuentaPerdidaCambiaria, CveIE:=-1, IdSegmentoNegocio:=-1, CveSubProyecto:=CveSubProyecto, CveProveedor:=Me.CveProveedor, CveCompra:=-1, ImporteMX:=Math.Abs(ImporteFluctuacion), TipoCambio:=TipoCambio, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
End If
End If
End If
If MsgError = "" AndAlso ObjMov.ValidacionPrePolizaCuadre(CvePrePoliza, 5) Then
If ObjMov.ValorPolizaDescuadre > 0 Then
MsgError = ObjMov.MensajePolizaDescuadre + " " + ObjMov.ValorDiferencia
GuardaLogAD($"Bancos/ProveedoresAbonar | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas")
End If
End If
If MsgError = "" AndAlso UsuarioActual.Empresa.Funcionalidad(220) <> "" Then
If Not ObjMov.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then
MsgError = "No se pudo simplificar los movimientos"
Alert("No se pudo simplificar los movimientos", TipoMensaje.MsgError)
End If
End If
'Conta ContPAQ
If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso MsgError = "" Then
If ObjMov.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjConta) Then
' Alert(alertaContabilizacion, ModExtensiones.TipoMensaje.MsgInformacion)
IDPoliza = ObjMov.ContaIdPoliza
Else
Alert("Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico", TipoMensaje.MsgError)
MsgError = "Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico"
End If
End If
Else
MsgError = "No se pudo insertar la póliza"
End If
Else
MsgError = "No se insertó el encabezado"
End If
If MsgError = "" Then
'Alert("El Documento se guardó correctamente.", TipoMensaje.MsgInformacion, "window.close();")
Dim TieneError As Boolean = False
If UsuarioActual.Empresa.UsaAC Then
Dim Total As Double = TxtImporte.Text.ToDouble
If ChkACEjercer.Checked Then
Total = Total * 3
Else
Total = Total * 2
End If
Dim TipoChq As String = ""
If DdlTipoTransaccion.SelectedValue = "1" Then TipoChq = "CHQ"
'se multiplica por dos, porque se esta juntando el ejercido y el pagado al mismo tiempo
IDPoliza = ObjConta.AddPoliza(2, "Pagado " & TxtPagueseA.Text.Trim, Total, Total, UsuarioActual.CveUsuario, Fecha, TxtFolio.Text, TipoChq)
If IDPoliza > 0 Then
FolioPoliza = ObjConta.Folio
Dim ConceptoRenglon, Referencia As String
ConceptoRenglon = ""
Referencia = TxtFolio.Text
'NECESITO SACAR LAS PARTIDAS DE CADA PRESUPUESTO DE LAS FACTURAS PARA AFECTARLAS CON EL PAGO
Dim dtAC As New DataTable
dtAC.Columns.Add("PorcentajePago", Type.GetType("System.Double"))
Dim PorcentajePago As Double = 1
'Dim ComprasAC As New ClsCompras
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
'obtengo su poliza para ver que presupuestos afecto
If gvr.DataKey("TotalOriginal").ToDouble > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDouble / gvr.DataKey("TotalOriginal").ToDouble Else PorcentajePago = 1
If ObjComp.GetPresupuestosCompras(gvr.DataKey("CveCompra").ToEntero) Then
dtAC.Merge(ObjComp.DtResultados)
If Not gvr.DataKey("Fecha").ToString.ToDate.Year < Fecha.Year Then ' SI ES EJERCICIO ANTERIOR LA COMPRA QUE EL EJERCICIO DEL PAGO NO AGREGA MOVIMIENTOS PRESUPUESTALES
For Each dr As DataRow In ObjComp.DtResultados.Rows
Total = dr("TotalPresupuesto").ToString.ToDouble * PorcentajePago
If Total > 0 Then
'EJERCIDO
If ChkACEjercer.Checked Then
ConceptoRenglon = String.Format("GE {0} Fact:{1}", TxtPagueseA.Text.Trim, gvr.DataKey("SerieFolio"))
If ObjConta.AddMovimiento(IDPoliza, dr("IdCuentaEjercido").ToString.ToEntero, False, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then
'actualizo el idcuenta del presupuesto
If Not ObjConta.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then
TieneError = True : Exit For
End If
Else
TieneError = True : Exit For
End If
End If
'PAGADO
ConceptoRenglon = String.Format("GP {0} Fact:{1}", TxtPagueseA.Text.Trim, gvr.DataKey("SerieFolio"))
If ObjConta.AddMovimiento(IDPoliza, dr("IdCuentaPagado").ToString.ToEntero, False, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then
'actualizo el idcuenta del presupuesto
If Not ObjConta.AddMovimiento(IDPoliza, dr("IdCuentaEjercido").ToString.ToEntero, True, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then
TieneError = True : Exit For
End If
Else
TieneError = True : Exit For
End If
End If
Next
End If
'AFECTA PROVEEDOR
Total = gvr.FCTextBox("TxtAbonar").Text.ToDouble
If Not ObjConta.AddMovimiento(IDPoliza, CtaProveedor, False, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then
TieneError = True
Exit For
End If
End If
End If
Next
If Not TieneError Then
ConceptoRenglon = String.Format("GP {0} {1}", TxtPagueseA.Text.Trim, TxtObservaciones.Text)
Total = TxtImporte.Text.ToDouble
If Not ObjConta.AddMovimiento(IDPoliza, IdCuenta, True, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then
TieneError = True
End If
End If
Else
TieneError = True
End If
End If
If Not TieneError Then
'actualizar la conta del IE
ObjIE.UpdateIEPrePoliza(Fecha, FolioPoliza.ToString, IDPoliza, CvePrePoliza, CveIE, 0)
Else
IDPoliza = 0
End If
If Not TieneError Then
ObjIE.Commit()
If ObjConta IsNot Nothing Then ObjConta.Commit()
Anexo.Text = "[]"
Dim Msg As New StringBuilder
Msg.AppendFormat("<li> <a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir movimiento</a></li> ", Encripta(String.Format("OP=IECHEQUE&CVEIE={0}", CveIE)))
'End If
Msg.AppendFormat("<li><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Listado</a></li>", Encripta(String.Format("OP=ImprimeMov&CveIE={0}", CveIE)))
If IDPoliza > 0 Then Msg.AppendFormat("<li><a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Póliza</a></li>", IDPoliza)
Dim Mensaje As String = String.Format("<br />El Documento se generó correctamente.<br /><br /><br />Descargas:<ul>{0}</ul>", Msg.ToString)
'LIMPIA
TxtFolio.Text = ""
TxtObservaciones.Text = ""
TxtImporte.Text = ""
TxtTotal.Text = ""
TxtFechaDocumento.Text = Now.ToShortDateString
DdlSelectedValue(DdlCuenta, "-1")
DdlSelectedValue(DdlTipoTransaccion, "-1")
Anexo.Text = "[]"
UpDatos.Update()
'upanexo.Update()
CargaDatos()
Alert(Mensaje.ToString, TipoMensaje.MsgInformacion, If(ChkSeguirRegistrando.Checked And GvCxP.Rows.Count > 0, "location.href =""#""", "location.href =""RepProveedoresPagos.aspx"""))
'Notificación de Pago
If TxtNotificarA.Text.Trim <> "" AndAlso ChkEnviarCorreo.Checked Then
'NotificacionPago(CveIE, TxtNotificarA.Text.Trim)
EnviarCorreoNotificacion(CveIE, TxtNotificarA.Text.Trim, "", UsuarioActual, False)
End If
End If
Else
ObjIE.RollBack()
If ObjConta IsNot Nothing Then ObjConta.RollBack()
Alert(MsgError, TipoMensaje.MsgAdvertencia)
End If
ObjIE.Dispose()
ObjMov.Dispose()
ObjComp.Dispose()
If ObjConta IsNot Nothing Then ObjConta.Dispose()
Else
Alert("Debe de llevar un folio", TipoMensaje.MsgAdvertencia)
End If
Else
Alert("Debe de llevar un importe", TipoMensaje.MsgAdvertencia)
End If
End Sub
Private Sub DdlSelectedValue(Ddl As DropDownList, Valor As String)
If Ddl.Items.FindByValue(Valor) IsNot Nothing Then
Ddl.SelectedValue = Valor
Else
Ddl.SelectedIndex = 0
End If
End Sub
#End Region
#Region " TIPO TRANSACCION "
Private Sub CargaTipoTransaccion()
If TipoPago = 1 Then
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs' AND CveTipoTransaccion IN (1, 2) and Estatus = 1 ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.SelectedValue = TipoPago.ToString
ElseIf TipoPago = 2 Then
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs' AND CveTipoTransaccion IN (1, 2) and Estatus = 1 ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.SelectedValue = TipoPago.ToString
RecargaCuentasDepositos()
ElseIf TipoPago = 3 Then
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs' AND CveTipoTransaccion IN (1, 2) and Estatus = 1 ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.SelectedValue = TipoPago.ToString
RecargaCuentasDepositos()
Else
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs' and Estatus = 1")
DdlTipoTransaccion.DataBind()
End If
If DdlTipoTransaccion.Items.Count > 1 Then DdlTipoTransaccion.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1"))
End Sub
Protected Sub DdlTipoTransaccion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoTransaccion.SelectedIndexChanged
BtnIEGuardar.Enabled = True
'cuando es cheque
If DdlTipoTransaccion.SelectedValue = "1" Then
ChkAbonoCuenta.Visible = True
TxtPagueseA.Enabled = True
Else
ChkAbonoCuenta.Visible = False
TxtPagueseA.Enabled = False
End If
If DdlTipoTransaccion.SelectedValue.ToEntero.Contiene(9, 17) Then
ChkEnviarCorreo.Enabled = False
ChkEnviarCorreo.Checked = False
Else
ChkEnviarCorreo.Enabled = True
ChkEnviarCorreo.Checked = True
End If
CargaCuentas(DdlTipoTransaccion.SelectedValue.ToEntero)
RecargaCuentasDepositos()
UpGuardar.Update()
End Sub
#End Region
#Region " CUENTAS MOVTO "
Private Sub CargaCuentas(tTipoTransaccion As Integer)
DdlCuenta.Items.Clear()
Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
If ChkPagarPesos.Checked Then
dt = dt.FiltraParametros(String.Format("CveMoneda = {0}", 1))
RegistraScript("CambiaPesosDolares();")
ElseIf ChkPagarDolares.Checked Then
dt = dt.FiltraParametros(String.Format("CveMoneda = {0}", 2))
RegistraScript("CambiaDolaresPesos();")
Else
If CveMonedaFiltro > 0 Then
dt = dt.FiltraParametros(String.Format("CveMoneda = {0}", CveMonedaFiltro))
End If
End If
If TipoPago = 3 Then
dt = dt.FiltraParametros("CveTipoCuenta = 7")
End If
'cuando es layout
If tTipoTransaccion = 9 Then
dt = dt.FiltraParametros("UsaLayout = 1")
End If
If tTipoTransaccion = 17 Then
dt = dt.FiltraParametros("UsaLayoutGrupos = 1")
End If
DdlCuenta.DataSource = dt
DdlCuenta.DataBind()
DdlCuenta.Items.Insert(0, New ListItem("Seleccione cuenta", "-1"))
End Sub
Protected Sub DdlCuenta_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuenta.SelectedIndexChanged
'recargo la moneda con la que se va a pagar
Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta = {0}", DdlCuenta.SelectedValue))
If dr IsNot Nothing Then
If dr("CveMoneda").ToString.ToEntero >= 2 Then
DivDolaresDolares.Visible = True
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
BtnCambiaTipoMoneda_Click(Nothing, Nothing)
Else
DivDolaresDolares.Visible = False
TxtFechaDocumento.Attributes.Remove("onchange")
End If
UpDatos.Update()
If ChkPagarPesos.Checked Then
CveMoneda = 2
RegistraScript("CambiaPesosDolares();")
Else
CveMoneda = dr("CveMoneda").ToString.ToEntero
RegistraScript("CambiaDolaresPesos();")
End If
IdCuenta = dr("IdCtaContable").ToString.ToEntero
IdCuentaBancariaComplementaria = dr("IdCtaContableComplementaria").ToString.ToEntero
End If
' si no tiene CveMoneda, o es -1, cuando cambia de cuenta filtra las facturas
If IfNull(Request("CveMoneda"), "-1").ToString.ToEntero = -1 Then CargaDatos(CveMoneda)
If HdnTipoTransaccion.Value = "Egs" AndAlso UsuarioActual.Empresa.Funcionalidad(505) <> "1" Then
Dim Folio As Long
Dim Banco As New ClsBancos
Folio = Banco.GetNextFolio(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero)
Banco.Dispose()
TxtFolio.Text = Folio.ToString
Else
TxtFolio.Text = ""
End If
Dim IdCuentaBancaria As Integer
Dim dr2 As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("CveCuenta = " & DdlCuenta.SelectedValue)
If dr2 IsNot Nothing Then
IdCuentaBancaria = dr2("IdCtaContable").ToString.ToEntero
If dr("UsaTarjeta").ToString = "True" Then
CargaGridTarjetas()
Else
DivTarjeta.Visible = False
End If
End If
End Sub
Private Sub CargaGridTarjetas()
Dim ObjCreditos As New ClsBancos
ObjCreditos.GetTarjetasCreditos(DdlCuenta.SelectedValue.ToEntero)
DdlTarjeta.Items.Clear()
DdlTarjeta.DataSource = ObjCreditos.DtResultados
DdlTarjeta.DataBind()
DdlTarjeta.Items.Insert(0, New ListItem("Seleccione", "-1"))
ObjCreditos.Dispose()
DivTarjeta.Visible = True
End Sub
#End Region
#Region " CUENTAS DEPOSITOS"
Private Sub CargaCuentasDepositos()
DdlCuentaDeposito.Items.Clear()
' If DdlTipoTransaccion.SelectedValue.Contiene("2", "9") Then ' transferencias y layout
trCuentaDeposito.Visible = False
Dim Dep As New ClsGenerales
If Dep.GetCuentasDepositos(CveProveedor:=CveProveedor) Then
If Dep.DtResultados.FiltraParametros("Estatus ='True'").Rows.Count > 0 Then
If DdlTipoTransaccion.SelectedValue = "9" Then
If Dep.DtResultados.Rows.Count > 0 Then
DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros("EstatusPagoElectronico = 'True' AND Estatus ='True'")
DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione una cuenta", "-1"))
End If
If Dep.DtResultados.FiltraParametros("EstatusPagoElectronico = 'True' AND Estatus ='True'").Rows.Count > 0 Then
trCuentaDeposito.Visible = True
DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione una cuenta", "-1"))
Else
BtnIEGuardar.Enabled = False
Alert("El Beneficiario no tiene una cuenta activa en BBVA, dela de alta o seleccione otro método de pago", TipoMensaje.MsgAdvertencia)
End If
ElseIf DdlTipoTransaccion.SelectedValue = "17" Then
If Dep.DtResultados.Rows.Count > 0 Then
DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros(" Estatus ='True'")
DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione una cuenta", "-1"))
trCuentaDeposito.Visible = True
BtnIEGuardar.ToolTip = ""
Else
BtnIEGuardar.Enabled = False
BtnIEGuardar.ToolTip = "El proveedor no tiene cuentas deposito"
Alert("El proveedor no tiene cuentas deposito.", TipoMensaje.MsgAdvertencia)
End If
UpGuardar.Update()
Else
DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros("Estatus ='True'")
If Dep.DtResultados.Rows.Count > 0 Then
trCuentaDeposito.Visible = True
DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione una cuenta", "-1"))
End If
End If
DdlCuentaDeposito.DataBind()
'If DdlCuentaDeposito.Items.Count > 1 Then
' DdlCuentaDeposito.SelectedIndex = 1
'End If
Else
If DdlTipoTransaccion.SelectedValue.Contiene("9", "17") Then
BtnIEGuardar.Enabled = False
BtnIEGuardar.ToolTip = "El proveedor no tiene cuentas deposito"
Alert("El proveedor no tiene cuentas deposito.", TipoMensaje.MsgAdvertencia)
Else
trCuentaDeposito.Visible = True
BtnIEGuardar.Enabled = True
BtnIEGuardar.ToolTip = ""
End If
UpGuardar.Update()
End If
Else
If DdlTipoTransaccion.SelectedValue = "17" Then
BtnIEGuardar.Enabled = False
BtnIEGuardar.ToolTip = "El proveedor no tiene cuentas deposito"
Else
trCuentaDeposito.Visible = True
BtnIEGuardar.Enabled = True
BtnIEGuardar.ToolTip = ""
End If
UpGuardar.Update()
End If
Dep.Dispose()
'Else
' trCuentaDeposito.Visible = False
' DdlCuentaDeposito.Items.Clear()
'End If
'RecargaGlobalCuentasBancarias()
UpnCuentasPago.Update()
UpCuentaDeposito.Update()
End Sub
Private Sub RecargaCuentasDepositos()
Dim dr As DataRow = GlobalDTTipoTransacciones.FiltroPrimero(String.Format("CveTipoTransaccion = {0}", DdlTipoTransaccion.SelectedValue)) 'Egs o Ing
If dr IsNot Nothing Then
HdnTipoTransaccion.Value = dr("Tipo").ToString
HdnTipoTransaccionAbreviatura.Value = dr("Abreviatura").ToString
End If
'cuando es transferencia bancaria, debe de solicitar a que cuenta se va a depositar
CargaCuentasDepositos()
End Sub
Protected Sub DdlCuentaDeposito_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim Dep As New ClsGenerales
If Dep.GetCuentasDepositos(CveProveedor:=CveProveedor, CveCuentaDeposito:=DdlCuentaDeposito.SelectedValue.ToEntero) AndAlso Dep.DtResultados.Rows.Count = 1 Then
If Dep.DtResultados.Rows.Count > 0 Then
If Dep.DtResultados.Rows(0)("TieneCIE").ToString.ToEntero = 1 Then
TrReferenciaCIE.Visible = True
TxtReferenciaCIE.Text = Dep.DtResultados.Rows(0)("Referencia").ToString
TxtConceptoCIE.Text = Dep.DtResultados.Rows(0)("ConceptoCIE").ToString
OriReferenciaCIE = Dep.DtResultados.Rows(0)("Referencia").ToString
OriConceptoCIE = Dep.DtResultados.Rows(0)("ConceptoCIE").ToString
Else
TrReferenciaCIE.Visible = False
End If
If Boolean.Parse(Dep.DtResultados.Rows(0)("EstatusPagoElectronicoGrupos").ToString) = True AndAlso Dep.DtResultados.Rows(0)("CveSATBanco").ToString.ToEntero <= 0 Then
Alert("Es necesario establecer el banco de la cuenta deposito", TipoMensaje.MsgAdvertencia)
BtnIEGuardar.Enabled = False
Else
BtnIEGuardar.Enabled = True
End If
Else
TrReferenciaCIE.Visible = False
End If
Else
TrReferenciaCIE.Visible = False
End If
Dep.Dispose()
UpCuentaDeposito.Update()
UpGuardar.Update()
End Sub
#End Region
'ESTO NO DEBERIA ESTAR AQUI
Private Sub RecargaGlobalCuentasBancarias(Optional ByVal CveCuenta As Integer = -1)
If CveProveedor > 0 Then
Dim ObjCuentasBancos As New ClsGenerales
If ObjCuentasBancos.GetCuentasDepositos() Then
GlobalDTProveedoresCuentas(-1, True) = ObjCuentasBancos.DtResultados
End If
ObjCuentasBancos.Dispose()
End If
End Sub
Protected Sub DdllOtrosPagos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlOtrosPagos.SelectedIndexChanged
If DdlOtrosPagos.SelectedValue <> "-1" Then
DdlProsepago.Visible = False
TxtOtrosImportes.Visible = True
TxtTotal.Visible = True
GvCxP.Columns(12).Visible = True
Else
DdlProsepago.Visible = False
TxtOtrosImportes.Visible = False
TxtTotal.Visible = False
GvCxP.Columns(12).Visible = False
TxtOtrosImportes.Text = ""
TxtTotal.Text = ""
RegistraScript("$get('TxtImporte').value = FormatoNumero(SumaValores(), 2);")
End If
UpDatos.Update()
UPCompras.Update()
End Sub
#Region " PAGAR CON PESOS "
Protected Sub ChkPagarPesos_CheckedChanged(sender As Object, e As EventArgs)
If ChkPagarPesos.Checked Then
DivTC.Visible = True
DivDolaresDolares.Visible = False
CargaCuentas(DdlTipoTransaccion.SelectedValue.ToEntero)
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
TxtTC.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
Else
DivTC.Visible = False
DivDolaresDolares.Visible = True
CargaCuentas(DdlTipoTransaccion.SelectedValue.ToEntero)
TxtFechaDocumento.Attributes.Remove("onchange")
End If
UpDatos.Update()
RegistraScript("CambiaPesosDolares();")
End Sub
#End Region
#Region "PAGAR CON DOLARES"
Protected Sub ChkPagarDolares_CheckedChanged(sender As Object, e As EventArgs)
If ChkPagarDolares.Checked Then
DivTCDolares.Visible = True
DivDolaresDolares.Visible = False
CargaCuentas(DdlTipoTransaccion.SelectedValue.ToEntero)
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
TxtTCDolares.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
Else
DivTCDolares.Visible = False
DivDolaresDolares.Visible = False
CargaCuentas(DdlTipoTransaccion.SelectedValue.ToEntero)
TxtFechaDocumento.Attributes.Remove("onchange")
End If
UpDatos.Update()
RegistraScript("CambiaDolaresPesos();")
End Sub
#End Region
#Region " NOTIFICACION PAGO "
Private Sub EnviarCorreoNotificacion(CveIENotificar As Integer, CorreoNotificarA As String, CopiaPara As String, UsuarioActualNotificar As Usuario, MostarAlert As Boolean)
Try
Dim Hilo As New Threading.Thread(Sub() EnviarCorreoNotifiMandaCorreocacionHilo(CveIENotificar, CorreoNotificarA, CopiaPara, UsuarioActualNotificar))
'Dim Hilo As New Threading.Thread( EnviarCorreoNotifiMandaCorreocacionHilo(CveIENotificar, CorreoNotificarA, CopiaPara, UsuarioActualNotificar))
Hilo.Start()
If MostarAlert Then
Alert("El correo se envió correctamente", TipoMensaje.MsgInformacion)
End If
Catch ex As Exception
If MostarAlert Then
Alert("No se pudo enviar el correo electrónico.", TipoMensaje.MsgError)
End If
End Try
End Sub
Private Sub EnviarCorreoNotifiMandaCorreocacionHilo(CveIENotificar As Integer, CorreoNotificarA As String, CopiaPara As String, UsuarioActualNotificar As Usuario)
Try
Dim ObjBancos As New ClsBancos()
If ObjBancos.NotificacionPago(CveIENotificar, CorreoNotificarA, CopiaPara, UsuarioActualNotificar) Then
Alert("El correo se envió correctamente", TipoMensaje.MsgInformacion)
Else
Alert("No se pudo enviar el correo electrónico.", TipoMensaje.MsgError)
End If
ObjBancos.Dispose()
Catch ex As Exception
GuardaLog("Error al enviar notificación de pago ProveedoresAbonar --> " & ex.StackTrace.ToString)
End Try
End Sub
'Private Sub NotificacionPago(CveIE As Integer, CorreoNotificarA As String)
' If Not DdlTipoTransaccion.SelectedValue.ToEntero.Contiene(9, 17) Then
' Dim Body As String = GeneraCorreo(CveIE)
' Dim Comprobante = If(ComprobanteIE <> "", String.Format("{0}IE\{1}", UsuarioActual.Empresa.Ruta, ComprobanteIE), "") 'Archivo Adjunto
' Dim File As Byte() = Nothing
' If UsuarioActual.Empresa.Funcionalidad(545).ToEntero > 0 Then
' File = NewGeneraBytesCxP(CveProveedor, UsuarioActual.Nombre)
' End If
' Dim Hilo As New Threading.Thread(Sub() MandaCorreo(CorreoNotificarA, "Notificaciones de pago", Body, CveIE, Comprobante, File))
' Hilo.Start()
' End If
'End Sub
'Private Sub MandaCorreo(Para As String, Asunto As String, Body As String, CveIE As Integer, Comprobante As String, File As Byte())
' 'Dim Parametros As List(Of String) = DirectCast(Data, List(Of String))
' Dim Mail As New ClsSisMail()
' Para = If(Para IsNot Nothing, Para, "")
' Asunto = If(Asunto IsNot Nothing, Asunto, "")
' Body = If(Body IsNot Nothing, Body, "")
' Dim ListaArchivos As New List(Of ClsSisMail.ArchivoMail)
' If Comprobante IsNot Nothing AndAlso Comprobante <> "" Then
' ListaArchivos.Add(New ClsSisMail.ArchivoMail With {.Ruta = Comprobante})
' End If
' If File IsNot Nothing Then
' ListaArchivos.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = File, .NombreArchivo = "EstadoCuentaCxP.pdf"})
' End If
' If Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, Archivos:=ListaArchivos) Then
' Dim objIE As New ClsBancos
' objIE.UpdateBancos_IENotificaciones(1, "-1", "-1", CveIE)
' objIE.Dispose()
' End If
'End Sub
'Private Function GeneraCorreo(CveIE As Integer) As String
' Dim strBody As New StringBuilder
' Dim objIE As New ClsBancos
' If objIE.GetBancosIE(CveIE, UsuarioActual.CveEmpresa) Then
' strBody.Append("<html xmlns=""http://www.w3.org/1999/xhtml""> ")
' strBody.Append("<head> ")
' strBody.Append(" <style type=""text/css""> ")
' strBody.Append(" body ")
' strBody.Append(" { ")
' strBody.Append(" margin:0px; ")
' strBody.Append(" padding:0px 0px 0px 0px; ")
' strBody.Append(" font-family: Verdana, Arial, Helvetica, sans-serif; ")
' strBody.Append(" font-size: 10px; ")
' strBody.Append(" background-color:#F0F0F0; ")
' strBody.Append(" } ")
' strBody.Append(" a.Texto ")
' strBody.Append(" { ")
' strBody.Append(" font-size:11px; ")
' strBody.Append(" background-color:#F7F6F3; ")
' strBody.Append(" text-decoration:none; ")
' strBody.Append(" font-weight:bold; ")
' strBody.Append(" } ")
' strBody.Append(" .Texto ")
' strBody.Append(" { ")
' strBody.Append(" background-color:#F7F6F3; color:Black; font-family:Verdana; font-size:10px; text-align:center; vertical-align:middle; height:20px;")
' strBody.Append(" } ")
' strBody.Append(" .TextoAlterno ")
' strBody.Append(" { ")
' strBody.Append(" background-color:White; color:Black; font-family:Verdana; font-size:10px; text-align:center; ")
' strBody.Append(" vertical-align:middle; height:20px;")
' strBody.Append(" } ")
' strBody.Append(" .BarraIdentidad ")
' strBody.Append(" { ")
' strBody.Append(" color:#FFFFFF; ")
' strBody.Append(" background:#F0F0F0; ")
' strBody.Append(" font-weight:bold; ")
' strBody.Append(" font-size:19px; ")
' strBody.Append(" font-style:oblique; ")
' strBody.Append(" } ")
' strBody.Append(" .Titulos ")
' strBody.Append(" { ")
' strBody.Append(" background-color: Gray;")
' strBody.Append(" color:White; ")
' strBody.Append(" font-family:Verdana; font-size:12px; text-align:center; ")
' strBody.Append(" vertical-align:middle; font-weight:bold; height:30px; ")
' strBody.Append(" text-decoration:none; ")
' strBody.Append(" } ")
' strBody.Append(" .Verde {color: #00CC00;} ")
' strBody.Append(" .Negro {color: #000000;} ")
' strBody.Append(" .Rojo {color: #FF0000;} ")
' strBody.Append(" </style> ")
' strBody.Append("</head> ")
' strBody.Append("<body> ")
' strBody.AppendFormat("<div id='C_div' style='width: 600px'>")
' strBody.AppendFormat(" <fieldset>")
' strBody.AppendFormat(" <legend><b>{0}</b></legend>", UsuarioActual.Empresa.Empresa)
' strBody.AppendFormat(" <table class='TextoG' border='0' cellpadding='0' cellspacing='0' width='100%'>")
' strBody.AppendFormat(" <tr>")
' strBody.AppendFormat(" <td style='width:100px'>{0}</td>", UsuarioActual.Empresa.Direccion)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr>")
' strBody.AppendFormat(" <td>Col. {0}</td>", UsuarioActual.Empresa.Colonia)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr>")
' strBody.AppendFormat(" <td>{0}, {1}, C.P.{2}</td>", UsuarioActual.Empresa.Ciudad, UsuarioActual.Empresa.Estado, UsuarioActual.Empresa.CP)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr>")
' strBody.AppendFormat(" <td>RFC {0}</td>", UsuarioActual.Empresa.RFC)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" </table>")
' strBody.AppendFormat(" </fieldset>")
' strBody.AppendFormat("</div><br/><br/>")
' strBody.AppendFormat("<div style='width: 600px'>")
' strBody.AppendFormat(" <fieldset>")
' strBody.AppendFormat(" <legend><b> </b></legend>")
' strBody.AppendFormat(" <table class='TextoG' style='width:100%'>")
' If objIE.CveTipoTransaccion = 1 Then ' cuando es cheque
' strBody.Append(" <tr style=""height: 22px""> ")
' strBody.Append(" <td>Favor de pasar a nuestras oficinas por el cheque con la siguientes instrucciones.</td> ")
' strBody.Append(" </tr> ")
' End If
' If objIE.CveTipoTransaccion = 2 Then ' cuando es transf
' strBody.Append(" <tr style=""height: 22px""> ")
' strBody.Append(" <td>Notificación de transferencia de pago realizada.</td> ")
' strBody.Append(" </tr> ")
' End If
' strBody.Append(" <tr style=""height: 22px""> ")
' strBody.AppendFormat(" <td>&nbsp;</td> ")
' strBody.Append(" </tr> ")
' strBody.Append(" </table> ")
' strBody.AppendFormat(" </fieldset>")
' strBody.Append(" </div> ")
' strBody.AppendFormat("<div style='width: 600px'>")
' strBody.AppendFormat(" <table style='width:100%'>")
' strBody.AppendFormat(" <tr>")
' strBody.AppendFormat(" <td style='vertical-align: top'>")
' strBody.AppendFormat(" <fieldset>")
' strBody.AppendFormat(" <legend>Beneficiario:<b>{0}</b> </legend>", objIE.PagueseA)
' strBody.AppendFormat(" <table width='100%'>")
' strBody.AppendFormat(" <tr style='background-color: gray; color: White; font-family: Verdana; font-size: 10px; text-align: center; vertical-align: middle; font-weight: bold; height: 20px; text-decoration: none;'>")
' strBody.AppendFormat(" <th scope='col' style='width:150px;'></th>")
' strBody.AppendFormat(" <th scope='col' style='width:450px;'></th>")
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Movimiento:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>{0}</td>", objIE.TipoTransaccion)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Banco:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>{0}</td>", objIE.Banco)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Cuenta:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>{0}</td>", objIE.NumCuenta)
' strBody.AppendFormat(" </tr>")
' If objIE.CuentaDepositado.ToString <> "" Then
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Cuenta Destino:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>{0}</td>", objIE.CuentaDepositado)
' strBody.AppendFormat(" </tr>")
' End If
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Fecha:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>{0}</td>", objIE.FechaDocumento.ToString("dd/MM/yyyy"))
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Importe:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>$ {0} {1}</td>", objIE.Importe.FormatoNumero, objIE.Moneda)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>Observaciones:</td>")
' strBody.AppendFormat(" <td style='text-align: left'>{0}</td>", objIE.Observaciones)
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td colspan='2'>")
' strBody.AppendFormat(" <hr />")
' strBody.AppendFormat(" </td>")
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" </table>")
' strBody.AppendFormat(" </fieldset>")
' strBody.AppendFormat(" </td>")
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" </table>")
' strBody.AppendFormat("</div>")
' 'MOVIMIENTOS CHEQUE
' If objIE.GetBancosIEMovimientos(CveIE, UsuarioActual.CveEmpresa) Then
' Dim Textov33 As String = ""
' If UsuarioActual.Empresa.Funcionalidad(520) = "1" Then
' Textov33 = "Favor de emitir complemento de pago de los siguientes documentos"
' End If
' strBody.AppendFormat("<div style='width: 1000px'>")
' strBody.AppendFormat(" <table style='width:1000px'>")
' strBody.AppendFormat(" <tr>")
' strBody.AppendFormat(" <td style='vertical-align: top'>")
' strBody.AppendFormat(" <fieldset>")
' strBody.AppendFormat(" <legend><b>Documentos abonados o pagados <br/>{0}</b> </legend>", Textov33)
' strBody.AppendFormat(" <table width='1000px'>")
' strBody.AppendFormat(" <tr style='background-color: gray; color: White; font-family: Verdana; font-size: 10px; text-align: center; vertical-align: middle; font-weight: bold; height: 20px; text-decoration: none;'>")
' strBody.AppendFormat(" <th scope='col' style='width: 10%'>Fecha</th>")
' strBody.AppendFormat(" <th scope='col' style='width: 20%'>Factura</th>")
' strBody.AppendFormat(" <th scope='col' style='width: 20%'>Importe ($)</th>")
' strBody.AppendFormat(" <th scope='col' style='width: 40%'>Folio Fiscal</th>")
' strBody.AppendFormat(" <th scope='col' style='width: 15%'>NC Aplicadas</th>")
' strBody.AppendFormat(" </tr>")
' For Each dr As DataRow In objIE.DtResultados.FiltraParametros("CveConceptoContable IN (17) AND CveCompra > 0").Rows
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td>{0}</td>", dr("Fecha").ToString.ToDate.ToShortDateString())
' strBody.AppendFormat(" <td>{0}</td>", dr("SerieFolio").ToString)
' strBody.AppendFormat(" <td style='text-align: right'>$ {0}</td>", dr("Importe").ToString.FormatoNumero)
' strBody.AppendFormat(" <td>{0}</td>", dr("FolioFiscal"))
' strBody.AppendFormat(" <td>{0}</td>", dr("ImporteNC").ToString.FormatoNumero)
' strBody.AppendFormat(" </tr>")
' Next
' strBody.AppendFormat(" <tr class='Texto'>")
' strBody.AppendFormat(" <td colspan='5'>")
' strBody.AppendFormat(" <hr />")
' strBody.AppendFormat(" </td>")
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" </table>")
' strBody.AppendFormat(" </fieldset>")
' strBody.AppendFormat(" </td>")
' strBody.AppendFormat(" </tr>")
' strBody.AppendFormat(" </table>")
' strBody.AppendFormat("</div>")
' End If
' strBody.Append(" <div> Favor de no responder a este correo. </div> ")
' strBody.Append("</body></html>")
' End If
' objIE.Dispose()
' Return strBody.ToString
'End Function
#End Region
#Region "SALDAR CUENTAS"
Private Sub BtnSaldarCuentasSinPagar_Click(sender As Object, e As EventArgs) Handles BtnSaldarCuentasSinPagar.Click
Dim ObjConta As New ClsContabilidad
ObjConta.IniciaTransacSQL()
Dim CvePrePoliza As Integer = 0
Dim MsgError As String = ""
Dim FuncionalidadFluctuacionImpuestos As Boolean = If(UsuarioActual.Empresa.Funcionalidad(159) = "1", True, False)
Dim EsContabilizable As Boolean = If(UsuarioActual.CveEmpresa.Contiene(13, 83), False, True)
For Each gr As GridViewRow In GvCxP.Rows
If gr.FCCheckBox("Chk").Checked Then
Dim IdCtaContable As Integer = CtaProveedor
Dim Saldo As Decimal = gr.DataKey("Saldo").ToDecimal
Dim TCCompra As Decimal = gr.DataKey("TipoCambio").ToDecimal
Dim TCPago As Decimal = GlobalTipoCambio(TxtFechaIncobrable.Text.ToDate).ToDecimal
Dim CveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero
Dim FechaCompra As Date = gr.DataKey("Fecha").ToDate
Dim CveSubProyecto As Integer = gr.DataKey("CveSubProyecto").ToEntero
Dim UsaComplementariaProveedores As Boolean = If(UsuarioActual.CveEmpresa.Contiene(119, 158), True, False)
Dim CveConceptoContablePago As Integer = 17
If gr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContablePago = 308 'cuando es acreedor
If CveMoneda <> 1 Then
Select Case CveConceptoContablePago
Case 17
CveConceptoContablePago = 312
Case 308
CveConceptoContablePago = 309
Case Else
End Select
End If
Dim CveConceptoContableComplementaria As Integer = 206
If gr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoContableComplementaria = 310 'cuando es acreedor
Dim ConceptoPartida As String = String.Format("Saldar compra {0}", gr.DataKey("SerieFolio").ToString)
CvePrePoliza = ObjConta.AddPrePolizas("Bancos/ProveedoresAbonar/Saldar", 98, gr.DataKey("Saldo").ToDecimal, gr.DataKey("Saldo").ToDecimal, gr.DataKey("CveMoneda").ToEntero, TxtFechaIncobrable.Text.ToDate, ConceptoPartida, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CveMoneda > 1 AndAlso (IdCtaContComplementaria > 0 Or UsaComplementariaProveedores) Then
IdCtaContable = IdCtaContComplementaria
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, 0.00D, gr.DataKey("SerieFolio").ToString, CveConceptoContableComplementaria, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Math.Round(Saldo * TCCompra - Saldo, 2, MidpointRounding.AwayFromZero), ImporteME:=Saldo, TipoCambio:=TCCompra, Contabilizable:=EsContabilizable) Then
MsgError = "No se pudo insertar la póliza"
End If
IdCtaContable = IdCtaProveedorExtranjera
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, gr.DataKey("SerieFolio").ToString, CveConceptoContablePago, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Saldo, ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
Else
If CveMoneda > 1 Then
IdCtaContable = IdCtaProveedorExtranjera
End If
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Saldo, gr.DataKey("SerieFolio").ToString, CveConceptoContablePago, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=If(CveMoneda = 1, Saldo, Saldo * TCCompra), ImporteME:=If(CveMoneda > 1, Saldo, 0), TipoCambio:=TCCompra, Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
Dim PorcentajePago As Decimal = gr.DataKey("Saldo").ToDecimal / gr.DataKey("TotalOriginal").ToDecimal
If MsgError = "" AndAlso gr.DataKey("IVA").ToDecimal > 0 Then
Dim PorcentajeImpuesto As Decimal = gr.DataKey("PorcentajeIVA").ToDecimal
Dim IdCtaIVAXAcreditar As Integer = 0
Dim IdCtaIVAAcreditable As Integer = 0
If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows.Count > 0 Then
IdCtaIVAXAcreditar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("IdCtaIVAXAcreditar").ToString.ToEntero
IdCtaIVAAcreditable = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("IdCtaIVAAcreditable").ToString.ToEntero
End If
Dim IVA As Decimal = PorcentajePago * gr.DataKey("IVA").ToDecimal
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IVA, gr.DataKey("SerieFolio").ToString, 14, ConceptoPartida, Now, IdCtaContable:=IdCtaIVAXAcreditar, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=If(CveMoneda = 1, IVA, IVA * If(FuncionalidadFluctuacionImpuestos, TCPago, TCCompra)), PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
Saldo = Saldo - IVA
End If
If MsgError = "" AndAlso gr.DataKey("IEPS").ToDecimal > 0 Then
Dim IEPS As Decimal = PorcentajePago * gr.DataKey("IEPS").ToDecimal
If UsuarioActual.Empresa.TipoContabilidad = 2 AndAlso ObjConta.GetRetCuenta(25, UsuarioActual.CveEmpresa) Then
If ObjConta.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjConta.DtResultados.Rows(0)("IdCuentaIEPSxAcreditar").ToString.ToEntero
End If
End If
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, IEPS, gr.DataKey("SerieFolio").ToString, 25, ConceptoPartida, Now, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=If(CveMoneda = 1, IEPS, IEPS * If(FuncionalidadFluctuacionImpuestos, TCPago, TCCompra)), Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
Saldo = Saldo - IEPS
End If
' se manda al ot ingresos, los impuestos por acreditar
If MsgError = "" Then
Dim tcvecon As Integer = 78
If Saldo < 0 Then
tcvecon = 211
End If
If MsgError = "" AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Saldo, gr.DataKey("SerieFolio").ToString, tcvecon, ConceptoPartida, Now, IdCtaContable:=UsuarioActual.Empresa.IdCuentaOtrosIngresos, CveIE:=-1, IdSegmentoNegocio:=-1, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=If(CveMoneda = 1, Saldo, Saldo * TCPago), TipoCambio:=TCCompra, TipoCambioPago:=TCPago, CveSubProyecto:=CveSubProyecto, Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
'fluctuación.
If CveMoneda > 1 Then
Dim ImporteFluctuacion As Decimal = 0
ImporteFluctuacion = Saldo * (TCPago - TCCompra)
If CveSubProyecto <= 0 Then
MsgError = "No se pudo obtener el sub proyecto o centro de costo"
End If
If TCCompra > TCPago Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Math.Abs(ImporteFluctuacion), gr.DataKey("SerieFolio").ToString, 64, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=UsuarioActual.Empresa.IdCuentaGananciaCambiaria, CveIE:=-1, IdSegmentoNegocio:=-1, CveSubProyecto:=CveSubProyecto, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Math.Abs(ImporteFluctuacion), TipoCambio:=TCCompra, TipoCambioPago:=TCPago, Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
Else
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, Math.Abs(ImporteFluctuacion), gr.DataKey("SerieFolio").ToString, 65, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=UsuarioActual.Empresa.IdCuentaPerdidaCambiaria, CveIE:=-1, IdSegmentoNegocio:=-1, CveSubProyecto:=CveSubProyecto, CveProveedor:=gr.DataKey("CveProveedor").ToEntero, CveCompra:=gr.DataKey("CveCompra").ToEntero, ImporteMX:=Math.Abs(ImporteFluctuacion), TipoCambio:=TCCompra, TipoCambioPago:=TCPago, Contabilizable:=EsContabilizable) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
End If
If MsgError = "" AndAlso ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 5) Then
If ObjConta.ValorPolizaDescuadre > 0 Then
MsgError = ObjConta.MensajePolizaDescuadre + " " + ObjConta.ValorDiferencia
GuardaLogAD($"Bancos/ProveedoresAbonar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas")
Exit For
Else
If UsuarioActual.Empresa.Funcionalidad(200) = "1" AndAlso MsgError = "" Then
If ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa) Then
' Alert(alertaContabilizacion, ModExtensiones.TipoMensaje.MsgInformacion)
Else
'Alert("Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico", TipoMensaje.MsgError)
MsgError = "Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico"
End If
End If
End If
End If
End If
Next
If MsgError = "" Then
ObjConta.Commit()
CargaDatos(CveMoneda)
RegistraScript("$('#ModalSaldarCuentaSinPagar').modal('hide')")
Alert("Los movimientos se saldaron correctamente.")
Else
ObjConta.RollBack()
Alert(MsgError, TipoMensaje.MsgError)
End If
'BtnSaldar.Visible = False
ObjConta.Dispose()
End Sub
#End Region
#Region "GENERAR SOLICITUD"
Protected Sub LnkPDFSolicitud_Click(sender As Object, e As EventArgs)
GenerarPDFSolicitud("PDF")
End Sub
Protected Sub LnkExcelSolicitud_Click(sender As Object, e As EventArgs)
GenerarPDFSolicitud("EXCEL")
End Sub
Private Sub GenerarPDFSolicitud(Opcion As String)
If DtDatos.Rows.Count > 0 Then
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta))
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
Dim StrImporte As String = DtDatos.Rows(0)("Saldo").ToString.FormatoNumero
Dim params As New List(Of ReportParameter)
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToString))
params.Add(New ReportParameter("Sucursal", DtDatos.Rows(1)("SubProyecto").ToString))
params.Add(New ReportParameter("Importe", $"${StrImporte}"))
params.Add(New ReportParameter("RazonSocial", TxtPagueseA.Text))
params.Add(New ReportParameter("Fecha", TxtFechaDocumento.Text))
Dim Transferencia = "", Banco = "", CLABE = "", Cuenta = "", Correo = ""
If DdlTipoTransaccion.SelectedValue.Contiene("2", "8") Then Transferencia = "Si" Else Transferencia = "No"
If DdlCuentaDeposito.SelectedValue.ToEntero > 0 Then
Dim ObjGral As New ClsGenerales
If ObjGral.GetCuentasDepositos(CveProveedor:=CveProveedor, CveCuentaDeposito:=DdlCuentaDeposito.SelectedValue.ToEntero) Then
If ObjGral.DtResultados.Rows.Count > 0 Then
Banco = ObjGral.DtResultados.Rows(0)("BancoNombre").ToString
CLABE = ObjGral.DtResultados.Rows(0)("CLABE").ToString
Cuenta = ObjGral.DtResultados.Rows(0)("Cuenta").ToString
Correo = ObjGral.DtResultados.Rows(0)("Correo").ToString
End If
End If
ObjGral.Dispose()
End If
params.Add(New ReportParameter("Transferencia", Transferencia))
params.Add(New ReportParameter("Banco", Banco))
params.Add(New ReportParameter("CLABE", CLABE))
params.Add(New ReportParameter("Cuenta", Cuenta))
params.Add(New ReportParameter("Correo", Correo))
If Imagen.Exists Then
params.Add(New ReportParameter("LogoPath", logouri))
Else
params.Add(New ReportParameter("LogoPath", ""))
End If
Dim NombreArchivo As String = "SolicitudPago" ''String.Format("SolicitudPago{0}.pdf", TxtPagueseA.Text).Replace(" ", "")
ImprimirPDF("Empresas/Grales/Formatos/Solicitud.rdlc", DtDatos, params, NombreArchivo, Opcion)
Else
Alert("No se encontraron datos.", TipoMensaje.MsgAdvertencia)
End If
End Sub
#End Region
Private Sub RVTxtFechaDocumento_Init(sender As Object, e As EventArgs) Handles RVTxtFechaDocumento.Init
RVTxtFechaDocumento.MaximumValue = DateTime.Now.ToShortDateString
RVTxtFechaDocumentoMenor.MinimumValue = DateTime.Now.AddMonths(-12).ToShortDateString
RVTxtFechaDocumentoMenor.MaximumValue = DateTime.Now.ToShortDateString
Calendario.EndDate = DateTime.Now
End Sub
End Class