Files
SIG/Bancos/ProveedoresAbonar.aspx.vb

2988 lines
192 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 ViewState("CveUsuarioProgramo").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 ReadOnly Property CtaAcreedor As Integer
Get
Return ViewState("CtaAcreedor").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaAcreedorExtranjera As Integer
Get
Return ViewState("IdCtaAcreedorExtranjera").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 ReadOnly Property IdCtaContAcreedorComplementaria As Integer
Get
Return ViewState("IdCtaContAcreedorComplementaria").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContRetIVA As Integer
Get
Return ViewState("IdCtaContRetIVA").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContRetISR As Integer
Get
Return ViewState("IdCtaContRetISR").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContRetIVAAcreditable As Integer
Get
Return ViewState("IdCtaContRetIVAAcreditable").ToString.ToEntero
End Get
End Property
Private ReadOnly Property IdCtaContRetISRAcreditable As Integer
Get
Return ViewState("IdCtaContRetISRAcreditable").ToString.ToEntero
End Get
End Property
Private Property EmpresaPrueba As Boolean
Get
Return CBool(ViewState("EmpresaPrueba"))
End Get
Set(value As Boolean)
ViewState("EmpresaPrueba") = value
End Set
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 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
EmpresaPrueba = True
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
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(-4)
'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(pCveProveedor, Serie, tCveMoneda, FechaVencimientoInicio:=FechaVencimientoInicio, FechaVencimientoFin:=FechaVencimientoFin, CveUsuarioRegistro:=CveUsuarioRegistro, CveUsuarioProgramo:=CveUsuarioPrograma) Then
If Mov.GetCxPProveedor(CveProveedor, FechaI, FechaF, CveUsuarioProgramo, CveUsuarioRegistro, CveUsuarioResponsable, CveClasificacionProveedor, tCveMoneda, CveEstatus, CveProveedorSucursal, CveAplicaNC, "-1", "-1", CodigoProgramacion) 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"))
'e.Row.FCTextBox("TxtAbonar").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},1,'{2}');", e.Row.FCCheckBox("Chk").ClientID, If(UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0, e.Row.DBCampo("ImporteAlmacen"), e.Row.DBCampo("Saldo")), If(UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0, "El importe no debe exceder el importe de entrada a almacen", "El Importe no debe de exceder el saldo")))
'e.Row.FCTextBox("TxtComision").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},2,'{2}');", e.Row.FCCheckBox("Chk").ClientID, If(UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0, e.Row.DBCampo("ImporteAlmacen"), e.Row.DBCampo("Saldo")), If(UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0, "El importe no debe exceder el importe de entrada a almacen", "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("Original").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()
'veririco 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
'529
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
Dim HuboError As Boolean = False
Dim ObjCompra As New ClsCompras
Dim ObjEventos As New ClsOIEventos(ObjCompra.IniciaTransacSQL())
If ObjCompra.UpdateEstatus(Valida.EsValida, gvr.DataKey("CveFactura").ToEntero) Then
If ObjCompra.CancelarCompra(gvr.DataKey("CveCompra").ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
MsgValidadas.AppendFormat("Factura Cancelada: {0} - {1}<br>", gvr.DataKey("SerieFolio"), gvr.DataKey("Descripcion"))
If Not ObjEventos.AddEventoBitacora("La compra se ha detectado como cancelada ante el SAT", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra:=gvr.DataKey("CveCompra").ToEntero) Then
HuboError = True
End If
Else
HuboError = True
End If
Else
HuboError = True
End If
If Not HuboError Then ObjCompra.Commit() Else ObjCompra.RollBack()
ObjCompra.Dispose()
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.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, GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", "CveCuenta = " & DdlCuenta.SelectedValue).ToEntero, 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
If EmpresaPrueba Then
Dim PorcentajePago As Decimal = 100
Dim CvePlantillaPoliza As Integer = 2
Dim alertaContabilizacion As String = "Se enviaron correctamente las siguientes pólizas:<br><br>"
Dim idCuentaContabilizacion As Long = 1
Dim CuentasContablesInvalidas As New StringBuilder
Dim CuentasContablesInvalidasSIG As New StringBuilder
Dim ConceptoContable As Integer
Dim TipoMovimiento As Boolean
Dim ImporteMovimiento As Decimal
Dim importeMX As Decimal
Dim FechaMovimiento As Date = TxtFechaDocumento.Text.ToDate
Dim IdCtaContable As Integer = 0
Dim ConceptoMovimiento As String
Dim Referencia As String
Dim tipoCambioCompra As Decimal
Dim TipoCambioPago As Decimal = 0
Dim TipoCambioGeneral As Decimal = 0
Dim tipoCambioCompraValuacion As Decimal = 1
Dim UsaComplementariaBancos As Boolean = If(UsuarioActual.CveEmpresa.Contiene(119, 158), True, False)
Dim UsaComplementariaProveedores As Boolean = If(UsuarioActual.CveEmpresa.Contiene(119, 158), True, False)
Dim FuncionalidadFluctuacionImpuestos As Boolean = If(UsuarioActual.Empresa.Funcionalidad(159) = "1", True, False)
Dim TipoCambioFluctuacion As Decimal = 1
Dim FechaUltimaFluctuacion As Date = MinFecha
If ObjIE.GetFluctuacionesBitacora(UsuarioActual.CveEmpresa) Then
If ObjIE.DtResultados.Rows.Count > 0 Then
Dim tFecha As Date = TxtFechaDocumento.Text.ToDate
Dim FechaC As String = String.Format("{0}/{1}/{2}", tFecha.Year, tFecha.Month, tFecha.Day)
Dim drr As DataRow = ObjIE.DtResultados.FiltroPrimero("Fecha < #" & FechaC & "#", "Fecha DESC")
If drr IsNot Nothing Then
FechaUltimaFluctuacion = drr("Fecha").ToString.ToDate
TipoCambioFluctuacion = drr("TipoCambio").ToString.ToDecimal
End If
End If
End If
Dim DttPlantilla As DataTable = Nothing
If ObjMov.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPoliza) Then
DttPlantilla = ObjMov.DtResultados
End If
Dim TipoContabilidad As Integer = UsuarioActual.Empresa.TipoContabilidad
'inserto las compras que voy a pagar
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
Dim EsImportacion As Boolean = False
'Tipos de cambio
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then 'Si la venta viene en Pesos y se va a pagar en Pesos
TipoCambioPago = 1
tipoCambioCompra = 1
PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then 'Si la venta viene en Dolares y se va a pagar en Pesos
TipoCambioPago = TxtTC.Text.ToDecimal
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
tipoCambioCompraValuacion = If(gvr.DataKey("Fecha").ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, gvr.DataKey("TipoCambio").ToDecimal)
PorcentajePago = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) / gvr.DataKey("Original").ToDecimal).RoundSQL
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then 'Si la venta viene en Dolares y se va a pagar en DOLARES
'TipoCambioPago = 'GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).ToString.ToDecimal
TipoCambioPago = TxtTCDolaresDolares.Text.ToDecimal
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
tipoCambioCompraValuacion = If(gvr.DataKey("Fecha").ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, gvr.DataKey("TipoCambio").ToDecimal)
PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
TipoCambioPago = TxtTCDolares.Text.ToDecimal
tipoCambioCompra = 1
PorcentajePago = (gvr.FCTextBox("TxtAbonar").Text.ToDecimal) / gvr.DataKey("Original").ToDecimal
End If
CveSubProyecto = gvr.DataKey("CveSubProyecto").ToEntero
'If ObjMov.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPoliza) Then
If DttPlantilla IsNot Nothing AndAlso DttPlantilla.Rows.Count > 0 Then
For Each Row As DataRow In DttPlantilla.Rows
ConceptoContable = Row("CveConcepto").ToString.ToEntero
TipoMovimiento = If(Row("TipoMovto").ToString = "True", True, False)
ImporteMovimiento = 0
IdCtaContable = 0
ConceptoMovimiento = $"{HplProveedor.Text} F:{gvr.DataKey("SerieFolio")}"
Referencia = gvr.DataKey("SerieFolio").ToString
Dim PorcentajeImpuesto As Decimal = 0
Select Case ConceptoContable
Case 17 'Pago Proveedores
If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then ConceptoContable = 308 'cuando es acreedor
If CveMoneda <> 1 Then
Select Case ConceptoContable
Case 17
ConceptoContable = 312
Case 308
ConceptoContable = 309
Case Else
End Select
End If
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
importeMX = gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioCompraValuacion
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
importeMX = gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioCompraValuacion
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompraValuacion
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
TipoCambioGeneral = tipoCambioCompraValuacion
ConceptoMovimiento = $"{HplProveedor.Text} F:{gvr.DataKey("SerieFolio")}"
'cuando son dolares, y tienen complementaria, se hace el registro
If gvr.DataKey("CveMoneda").ToEntero = 1 Then
If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then
IdCtaContable = CtaAcreedor
Else
IdCtaContable = CtaProveedor
End If
Else
Dim CveConceptoComplementaria As Integer = 206
If gvr.DataKey("CveTipoConcepto").ToEntero = 2 Then CveConceptoComplementaria = 310
ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}"
IdCtaContable = IdCtaContComplementaria
If ImporteMovimiento <> 0 AndAlso (UsaComplementariaProveedores Or IdCtaContable > 0) Then 'Cuando tiene complementaria lo dividimos en dos
importeMX = ImporteMovimiento
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0.00D, Referencia, CveConceptoComplementaria, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=Math.Round(ImporteMovimiento * tipoCambioCompraValuacion - ImporteMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioCompraValuacion) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
IdCtaContable = IdCtaProveedorExtranjera
End If
Case 15 'Ret IVA X Acreditar Honorarios/Serv. Prof.
If gvr.DataKey("CveRetIVAConcepto").ToEntero > 0 Then
Dim Funcionalidad As Integer = 0
If gvr.DataKey("CveRetIVAConcepto").ToEntero = 1 Then
Funcionalidad = 307
ConceptoContable = 15
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 2 Then
Funcionalidad = 309
ConceptoContable = 183
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 3 Then
Funcionalidad = 311
ConceptoContable = 185
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 4 Then
Funcionalidad = 313
ConceptoContable = 248
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 5 Then
Funcionalidad = 578
ConceptoContable = 285
End If
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioCompra
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
TipoCambioGeneral = tipoCambioCompra
If tipoCambioCompra > 1 Then ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetIVA > 0 Then
IdCtaContable = IdCtaContRetIVA
ElseIf UsuarioActual.Empresa.Funcionalidad(Funcionalidad).ToEntero > 0 Then
IdCtaContable = UsuarioActual.Empresa.Funcionalidad(Funcionalidad).ToEntero
Else
If ImporteMovimiento <> 0 AndAlso TipoContabilidad <> 1 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero
End If
End If
End If
End If
Case 22 'Ret IVA Acreditable Honorarios/Serv. Prof.
If gvr.DataKey("CveRetIVAConcepto").ToEntero > 0 Then
Dim Funcionalidad As Integer = 0
If gvr.DataKey("CveRetIVAConcepto").ToEntero = 1 Then
Funcionalidad = 308
ConceptoContable = 22
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 2 Then
Funcionalidad = 310
ConceptoContable = 184
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 3 Then
Funcionalidad = 312
ConceptoContable = 186
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 4 Then
Funcionalidad = 314
ConceptoContable = 249
ElseIf gvr.DataKey("CveRetIVAConcepto").ToEntero = 5 Then
Funcionalidad = 578
ConceptoContable = 286
End If
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
If TipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{TipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetIVAAcreditable > 0 Then
IdCtaContable = IdCtaContRetIVAAcreditable
ElseIf UsuarioActual.Empresa.Funcionalidad(Funcionalidad).ToEntero > 0 Then
IdCtaContable = UsuarioActual.Empresa.Funcionalidad(Funcionalidad).ToEntero
Else
If ImporteMovimiento <> 0 AndAlso TipoContabilidad <> 1 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaRetIVACirculacion").ToString.ToEntero
End If
End If
End If
End If
Case 16 'Ret ISR X Acreditar
If gvr.DataKey("CveRetISRConcepto").ToEntero > 0 Then
Dim funcionalidad As Integer = 0
If gvr.DataKey("CveRetISRConcepto").ToEntero = 1 Then
funcionalidad = 315
ConceptoContable = 16
ElseIf gvr.DataKey("CveRetISRConcepto").ToEntero = 2 Then
funcionalidad = 317
ConceptoContable = 243
End If
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("RetISR").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioCompra
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = tipoCambioCompra
If tipoCambioCompra > 1 Then ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetISR > 0 Then
IdCtaContable = IdCtaContRetISR
ElseIf UsuarioActual.Empresa.Funcionalidad(funcionalidad).ToEntero > 0 Then
IdCtaContable = UsuarioActual.Empresa.Funcionalidad(funcionalidad).ToEntero
Else
If ImporteMovimiento <> 0 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero
End If
End If
End If
End If
Case 23 'Ret ISR Acreditable
If gvr.DataKey("CveRetISRConcepto").ToEntero > 0 Then
Dim funcionalidad As Integer = 0
If gvr.DataKey("CveRetISRConcepto").ToEntero = 1 Then
funcionalidad = 316
ConceptoContable = 23
ElseIf gvr.DataKey("CveRetISRConcepto").ToEntero = 2 Then
funcionalidad = 318
ConceptoContable = 244
End If
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("RetISR").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioCompra, TipoCambioPago)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioCompra, TipoCambioPago)
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = TipoCambioPago
If TipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{TipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetISRAcreditable > 0 Then
IdCtaContable = IdCtaContRetISRAcreditable
ElseIf UsuarioActual.Empresa.Funcionalidad(funcionalidad).ToEntero > 0 Then
IdCtaContable = UsuarioActual.Empresa.Funcionalidad(funcionalidad).ToEntero
Else
If ImporteMovimiento <> 0 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaRetISRCirculacion").ToString.ToEntero
End If
End If
End If
End If
Case 14 'Iva X Acreditar
Dim TotalImporte As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then
'funcionalidad que toma el 100% del pago para acreditamiento de iva
If TotalImporte = gvr.DataKey("Saldo").ToDecimal Then
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2)
If tipoCambioCompra > 1 Then ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}"
Else
ImporteMovimiento = 0
importeMX = 0
End If
Else
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal * PorcentajePago
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
If tipoCambioCompra > 1 Then ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}"
End If
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
PorcentajeImpuesto = gvr.DataKey("PorcentajeIVA").ToDecimal
Dim IdCtaIVAXAcreditar As Integer = 0
Dim IdCtaIVAAcreditable As Integer = 0
If gvr.DataKey("EsImportacion").ToString.contiene("1", "True") Then
ConceptoContable = 287
End If
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
IdCtaContable = If(IdCtaIVAXAcreditar > 0, IdCtaIVAXAcreditar, 0)
If ImporteMovimiento <> 0 AndAlso TipoContabilidad <> 1 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaIVAxAcreditar").ToString.ToEntero
End If
End If
Case 19 'Iva Acreditado
Dim TotalImporte As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
If UsuarioActual.Empresa.Funcionalidad(521) = "1" Then
'funcionalidad que toma el 100% del pago para acreditamiento de iva
If TotalImporte = gvr.DataKey("Saldo").ToDecimal Then
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IVADeducible").ToDecimal
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("IVADeducible").ToDecimal
importeMX = gvr.DataKey("IVADeducible").ToDecimal * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IVADeducible").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("IVADeducible").ToDecimal
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
If TipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{TipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
Else
ImporteMovimiento = 0
importeMX = 0
End If
Else
ImporteMovimiento = gvr.DataKey("IVADeducible").ToDecimal * PorcentajePago
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
If TipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{TipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
End If
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
If gvr.DataKey("EsImportacion").ToString.contiene("1", "True") Then
ConceptoContable = 288
End If
PorcentajeImpuesto = gvr.DataKey("PorcentajeIVA").ToDecimal
Dim IdCtaIVAXAcreditar As Integer = 0
Dim IdCtaIVAAcreditable As Integer = 0
Dim IdCtaContableNoIVA 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
IdCtaContableNoIVA = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("IdCtaIVANoAcreditable").ToString.ToEntero
End If
IdCtaContable = If(IdCtaIVAAcreditable > 0, IdCtaIVAAcreditable, 0)
'se registra el iva no acreditable
If gvr.DataKey("IVANoDeducible").ToDecimal > 0 Then
Dim ImporteNOIVA As Decimal = gvr.DataKey("IVANoDeducible").ToDecimal * PorcentajePago
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteNOIVA, Referencia, 280, ConceptoMovimiento, FechaMovimiento, IdCtaContableNoIVA, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=ImporteNOIVA, ImporteME:=If(TipoCambioPago = 1, 0, ImporteMovimiento), TipoCambio:=TipoCambioGeneral, CveSubProyecto:=CveSubProyecto, PorcentajeImpuesto:=PorcentajeImpuesto) Then
MsgError = "No se pudo insertar la póliza"
Exit For
End If
End If
If ImporteMovimiento <> 0 AndAlso TipoContabilidad <> 1 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) And Not IdCtaContable > 0 Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaIVAAcreditable").ToString.ToEntero
End If
End If
Case 25 'IEPS X Acreditar
Dim TotalImporte As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
ImporteMovimiento = gvr.DataKey("IEPSPorPagar").ToDecimal * PorcentajePago
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * tipoCambioCompra
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = tipoCambioCompra
If tipoCambioCompra > 1 Then ConceptoMovimiento += $" TC:{tipoCambioCompra} ${ImporteMovimiento.FormatoNumero(2)}"
If ImporteMovimiento <> 0 AndAlso TipoContabilidad <> 1 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaIEPSxAcreditar").ToString.ToEntero
End If
End If
Case 26 'IEPS Acreditable
Dim TotalImporte As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
ImporteMovimiento = gvr.DataKey("IEPSPorPagar").ToDecimal * PorcentajePago
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
importeMX = ImporteMovimiento * tipoCambioCompra
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioCompra = gvr.DataKey("TipoCambio").ToDecimal
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
If ImporteMovimiento <> 0 AndAlso TipoContabilidad <> 1 AndAlso ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCuentaIEPSAcreditable").ToString.ToEntero
End If
End If
Case 64 'Ganancia
If CveMoneda <> 1 OrElse gvr.DataKey("CveMoneda").ToEntero <> 1 Then
IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria
'tipoCambioVentaDiferenciaCambiaria = If(gvr.DataKey("Fecha").ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, gvr.DataKey("TipoCambio").ToDecimal)
Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
Dim Diferencia As Decimal = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioCompraValuacion) - ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * TipoCambioPago) 'Añadimos la diferencia de perdida en la venta
Diferencia -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
Diferencia += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetIVA
Diferencia += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
Diferencia -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IEPS
Diferencia = Math.Round(Diferencia, 2)
'' se considera, las diferencias, y no el tipo de cambio, por el caso de las fluctuaciones
'' si tiene funcionalidad de flucturación con ivas, tomar tipocambioventa
If Diferencia > 0 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = Math.Abs(Diferencia)
importeMX = ImporteMovimiento
End If
'' si tiene funcionalidad de flucturación con ivas, tomar tipocambioventa
'If tipoCambioPago > tipoCambioVentaDiferenciaCambiaria AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
' ImporteMovimiento = (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioPago) - (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioVentaDiferenciaCambiaria) 'Añadimos la diferencia de ganancia en la venta
' ImporteMovimiento -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) 'Añadimos la diferencia de ganancia en el IVA
' ImporteMovimiento += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) 'Añadimos la diferencia de ganancia en el RetIVA
' ImporteMovimiento += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) 'Añadimos la diferencia de ganancia en el RetISR
' ImporteMovimiento -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) 'Añadimos la diferencia de ganancia en el IEPS
' ImporteMovimiento = Math.Abs(Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero))
' importeMX = ImporteMovimiento
'End If
'Dim TotalImporte As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
''Dim IVA As Decimal = If(TotalImporte = gvr.DataKey("Saldo").ToDecimal, gvr.DataKey("IVAPorPagar").ToDecimal, gvr.DataKey("IVA").ToDecimal * PorcentajePago)
'Dim IVA As Decimal = If(TotalImporte = gvr.DataKey("Saldo").ToDecimal AndAlso Math.Abs(Math.Round(gvr.DataKey("IVAPorPagar").ToDecimal - (gvr.DataKey("IVA").ToDecimal * PorcentajePago), 2)) <= 0.02, gvr.DataKey("IVAPorPagar").ToDecimal, gvr.DataKey("IVA").ToDecimal * PorcentajePago)
'Dim IEPS As Decimal = If(TotalImporte = gvr.DataKey("Saldo").ToDecimal AndAlso Math.Abs(Math.Round(gvr.DataKey("IEPSPorPagar").ToDecimal - (gvr.DataKey("IEPS").ToDecimal * PorcentajePago), 2)) <= 0.02, gvr.DataKey("IEPSPorPagar").ToDecimal, gvr.DataKey("IEPS").ToDecimal * PorcentajePago) 'If(TotalImporte = gvr.DataKey("Saldo").ToDecimal, gvr.DataKey("IEPSPorPagar").ToDecimal, gvr.DataKey("IEPS").ToDecimal * PorcentajePago)
'IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria
'Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompraValuacion)
'TipoCambioGeneral = TCImpuestos
'''' si tiene funcionalidad de flucturación con ivas, tomar tipocambioCompra
'If TipoCambioPago < tipoCambioCompra AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
' ImporteMovimiento = (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * TipoCambioPago) - (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioCompra) 'Añadimos la diferencia de ganancia en la venta
' ImporteMovimiento -= (IVA * TCImpuestos) - (IVA * tipoCambioCompra) 'Añadimos la diferencia de ganancia en el IVA
' ImporteMovimiento += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioCompra) 'Añadimos la diferencia de ganancia en el RetIVA
' ImporteMovimiento += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioCompra) 'Añadimos la diferencia de ganancia en el RetISR
' ImporteMovimiento -= (IEPS * TCImpuestos) - (IEPS * tipoCambioCompra) 'Añadimos la diferencia de ganancia en el IEPS
' ImporteMovimiento = Math.Abs(Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero))
' importeMX = ImporteMovimiento
'End If
Else
ImporteMovimiento = 0
End If
Case 65 'Perdida
If CveMoneda <> 1 OrElse gvr.DataKey("CveMoneda").ToEntero <> 1 Then
IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria
'tipoCambioVentaDiferenciaCambiaria = If(gvr.DataKey("Fecha").ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, gvr.DataKey("TipoCambio").ToDecimal)
Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompra)
Dim Diferencia As Decimal = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioCompraValuacion) - ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * TipoCambioPago) 'Añadimos la diferencia de perdida en la venta
Diferencia -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
Diferencia += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetIVA
Diferencia += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
Diferencia -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IEPS
Diferencia = Math.Round(Diferencia, 2)
'si la diferencia es negativa es pérdida, si es positiva es ganancia
If Diferencia < 0 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = Math.Abs(Diferencia)
importeMX = ImporteMovimiento
End If
'Dim TotalImporte As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
'Dim IVA As Decimal = If(TotalImporte = gvr.DataKey("Saldo").ToDecimal AndAlso Math.Abs(Math.Round(gvr.DataKey("IVAPorPagar").ToDecimal - (gvr.DataKey("IVA").ToDecimal * PorcentajePago), 2)) <= 0.02, gvr.DataKey("IVAPorPagar").ToDecimal, gvr.DataKey("IVA").ToDecimal * PorcentajePago)
'Dim IEPS As Decimal = If(TotalImporte = gvr.DataKey("Saldo").ToDecimal AndAlso Math.Abs(Math.Round(gvr.DataKey("IEPSPorPagar").ToDecimal - (gvr.DataKey("IEPS").ToDecimal * PorcentajePago), 2)) <= 0.02, gvr.DataKey("IEPSPorPagar").ToDecimal, gvr.DataKey("IEPS").ToDecimal * PorcentajePago) 'If(TotalImporte = gvr.DataKey("Saldo").ToDecimal, gvr.DataKey("IEPSPorPagar").ToDecimal, gvr.DataKey("IEPS").ToDecimal * PorcentajePago)
'IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria
'Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, TipoCambioPago, tipoCambioCompraValuacion)
'' si tiene funcionalidad de flucturación con ivas, tomar tipocambioCompra
'If TipoCambioPago > tipoCambioCompra AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
' ImporteMovimiento = (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioCompra) - (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * TipoCambioPago) 'Añadimos la diferencia de ganancia en la venta
' ImporteMovimiento -= (IVA * tipoCambioCompra) - (IVA * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
' ImporteMovimiento += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetIVA
' ImporteMovimiento += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioCompra) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
' ImporteMovimiento -= (IEPS * tipoCambioCompra) - (IEPS * TCImpuestos) 'Añadimos la diferencia de ganancia en el IEPS
' ImporteMovimiento = Math.Abs(Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero))
' importeMX = ImporteMovimiento
'End If
Else
ImporteMovimiento = 0
End If
Case 255 'Otros egresos
If DdlOtrosPagos.SelectedValue = "2" Then
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.FCTextBox("TxtComision").Text.ToDecimal
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = gvr.FCTextBox("TxtComision").Text.ToDecimal
importeMX = ImporteMovimiento * TipoCambioPago
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.FCTextBox("TxtComision").Text.ToDecimal
importeMX = ImporteMovimiento '* TipoCambioPago
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = gvr.FCTextBox("TxtComision").Text.ToDecimal
importeMX = ImporteMovimiento * TipoCambioPago
End If
If gvr.FCTextBox("TxtComision").Text.ToDecimal < 0 Then
TipoMovimiento = True
ImporteMovimiento = ImporteMovimiento * -1
importeMX = importeMX * -1
IdCtaContable = UsuarioActual.Empresa.IdCuentaOtrosIngresos
Else
TipoMovimiento = False
IdCtaContable = UsuarioActual.Empresa.Funcionalidad(266).ToEntero()
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = TipoCambioPago
End If
Case 42 'Acreedores
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
IdCtaContable = ObjCreditos.DtResultados.Rows(0)("IdCtaContableTarjeta").ToString.ToEntero
Else
IdCtaContable = IdCuenta
End If
Dim Importe42 As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
ImporteMovimiento = Importe42
importeMX = If(CveMoneda = 2, If(DivTC.Visible, Importe42 / TxtTC.Text.ToDecimal * TipoCambioPago, Importe42 * TipoCambioPago), Importe42)
TipoCambioGeneral = TipoCambioPago
End If
Case 30
'Conta ContPAQ
If IdCuenta < 1 Then
CuentasContablesInvalidas.Append("<br>" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString)
idCuentaContabilizacion = 0
End If
ImporteMovimiento = 0
Case Else
ImporteMovimiento = 0
End Select
If MsgError <> "" Then
Exit For
End If
If ImporteMovimiento <> 0 Then
'Conta ContPAQ
If IdCtaContable = 0 Then
CuentasContablesInvalidas.Append("<br>" & GlobalDTContaConceptosContables(-1).FiltroPrimeroValor("ConceptoContable", String.Format("CveConceptoContable = {0}", ConceptoContable)))
idCuentaContabilizacion = 0
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteMovimiento, Referencia, ConceptoContable, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, CveSubProyecto:=CveSubProyecto, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=importeMX, ImporteME:=If(TipoCambioPago = 1, 0, ImporteMovimiento), TipoCambio:=TipoCambioGeneral, PorcentajeImpuesto:=PorcentajeImpuesto) Then
MsgError = "No se pudo insertar la póliza"
Exit For
End If
End If
Next
'Unificacion de PrePolizas
If MsgError = "" AndAlso UsuarioActual.Empresa.Funcionalidad(219) = "1" Then
If Not ObjMov.PrePolizaUnificacion(CvePrePoliza, gvr.DataKey("CvePrePoliza").ToEntero) Then
MsgError = "No se pudo unificar la prepoliza"
Alert("No se pudo unificar la prepoliza", TipoMensaje.MsgError)
End If
End If
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
End If
Next
ConceptoMovimiento = $"{TxtPagueseA.Text.Trim} - {TxtObservaciones.Text} {If(TipoCambioPago > 1, $" TC:{TipoCambioPago}", "")}"
Referencia = $"{HdnTipoTransaccionAbreviatura.Value}: {TxtFolio.Text.Trim}"
If (Not DivTarjeta.Visible Or DdlTarjeta.SelectedValue.ToEntero = -1) Then
If TipoCambioPago > 1 AndAlso CveMoneda = 2 Then
If UsaComplementariaBancos Or (IdCuentaBancariaComplementaria > 0) Then
If CveMoneda = 2 AndAlso CveMonedaFiltro = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
TipoCambioPago = TxtTCDolares.Text.ToDecimal
ElseIf CveMoneda = 2 AndAlso CveMonedaFiltro = 2 Then
TipoCambioPago = TxtTCDolaresDolares.Text.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtImporte.Text.ToDecimal, Referencia, 30, ConceptoMovimiento, TxtFechaDocumento.Text.ToDate, IdCuenta, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=TxtImporte.Text.ToDecimal, ImporteME:=If(TipoCambioPago = 1, 0, TxtImporte.Text.ToDecimal), TipoCambio:=TipoCambioPago, CveSubProyecto:=CveSubProyecto) Then
MsgError = "No se pudo insertar la póliza"
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, If(CveMoneda = 1 AndAlso TxtTC.Visible, TxtImporte.Text.ToDecimal / TxtTC.Text.ToDecimal, TxtImporte.Text.ToDecimal), Referencia, 204, ConceptoMovimiento, TxtFechaDocumento.Text.ToDate, IdCuentaBancariaComplementaria, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=If(CveMoneda = 2, Math.Round((TxtImporte.Text.Trim.ToDecimal * TipoCambioPago) - TxtImporte.Text.Trim.ToDecimal, 2, MidpointRounding.AwayFromZero), TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 1, 0, TxtImporte.Text.ToDecimal), TipoCambio:=TipoCambioPago, CveSubProyecto:=CveSubProyecto) Then
MsgError = "No se pudo insertar la póliza"
End If
Else
If CveMoneda = 2 AndAlso CveMonedaFiltro = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
TipoCambioPago = TxtTCDolares.Text.ToDecimal
ElseIf CveMoneda = 2 AndAlso CveMonedaFiltro = 2 Then
TipoCambioPago = TxtTCDolaresDolares.Text.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtImporte.Text.ToDecimal, Referencia, 30, ConceptoMovimiento, TxtFechaDocumento.Text.ToDate, IdCuenta, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=If(CveMoneda = 2, Math.Round(TxtImporte.Text.Trim.ToDecimal * TipoCambioPago, 2, MidpointRounding.AwayFromZero), TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(DivTC.Visible, If(TxtTC.Text.ToDecimal > 0, TxtImporte.Text.ToDecimal / TxtTC.Text.ToDecimal, 0), 0), TipoCambio:=TipoCambioPago, 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 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
Else
If CveMoneda = 2 AndAlso CveMonedaFiltro = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
TipoCambioPago = TxtTCDolares.Text.ToDecimal
ElseIf CveMoneda = 2 AndAlso CveMonedaFiltro = 2 Then
TipoCambioPago = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).ToString.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtImporte.Text.ToDecimal, Referencia, 30, ConceptoMovimiento, TxtFechaDocumento.Text.ToDate, IdCuenta, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=If(CveMoneda = 2, Math.Round(TxtImporte.Text.Trim.ToDecimal * TipoCambioPago, 2, MidpointRounding.AwayFromZero), TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(DivTC.Visible, If(TxtTC.Text.ToDecimal > 0, TxtImporte.Text.ToDecimal / TxtTC.Text.ToDecimal, 0), 0), TipoCambio:=TipoCambioPago, CveSubProyecto:=CveSubProyecto) Then
MsgError = "No se pudo insertar la póliza"
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 idCuentaContabilizacion > 0 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
Else
Alert(String.Format("No se puede contabilizar la Prepoliza debido a que las siguientes cuentas son invalidas: {0}", CuentasContablesInvalidas), TipoMensaje.MsgAdvertencia)
MsgError = "No se puede contabilizar la Prepoliza"
End If
End If
Else 'Empresa Prueba
'Movimientos de Bancos
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, ImporteSeleccionado, TxtFolio.Text.Trim, 30, TxtObservaciones.Text, Now, 0, -1, CveIE, CveProveedor:=CveProveedor, ImporteMX:=If(CveMoneda = 2, ImporteSeleccionado * TipoCambio, ImporteSeleccionado)) Then
MsgError = "no se pudo insertar el detalle de la poliza"
End If
Dim PorcentajePago As Decimal = 100
'inserto las compras que voy a pagar
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
If TipoPago = 3 Then 'cuando es pago con crediproveedores
' CveConceptoCompra = 50 ' prestamo documentos por pagar
'debo de actualizar el estatus dela compra a pagada
Dim ObjCreditos As New ClsBancos
If ObjCreditos.GetCreditos(-1, -1, -1, CveProveedor, 1, UsuarioActual.CveEmpresa) Then
Dim DTCreditos As DataTable = ObjCreditos.DtResultados.FiltraParametros(String.Format("CveCompra = {0}", gvr.DataKey("CveCompra")))
If DTCreditos.Rows.Count > 0 Then
'actualizo el estatus
Dim drC As DataRow = DTCreditos.Rows(0)
Dim Estatus As Integer = 103
' Estatus = If(drE("Estatus").ToString = "P", 103, Estatus)
If Not ObjCreditos.UpdateCreditosDetalle(drC("CveCreditoDetalle").ToString.ToEntero, drC("FechaVencimiento").ToString.ToDate, drC("CreditoValor").ToString.ToDouble, -1, -1.0, -1.0, -1.0, -1.0, Estatus) Then
' ErrorCredito = True
End If
End If
End If
ObjCreditos.Dispose()
End If
'Saco el porcentaje de pago
If gvr.DataKey("Original").ToDouble > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1
Dim CveConceptoContablePago As Integer = 17
If gvr.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
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.FCTextBox("TxtAbonar").Text.ToDecimal, TxtObservaciones.Text, CveConceptoContablePago, "", Now, 0, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.FCTextBox("TxtAbonar").Text.ToDecimal) Then
MsgError = "Detalle"
Exit For
Else
'IVA. siempre se registra aunque sea cero
If MsgError = "" Then
Dim IdCtaIVAXAcreditar As Integer = 0
Dim IdCtaIVAAcreditable As Integer = 0
Dim PorcentajeImpuesto As Decimal = gvr.DataKey("PorcentajeIVA").ToDecimal
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
'Agrego el IVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 14, TxtObservaciones.Text, Now, IdCtaIVAXAcreditar, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 19, TxtObservaciones.Text, Now, IdCtaIVAAcreditable, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
End If
End If
If MsgError = "" AndAlso gvr.DataKey("RetIVA").ToDouble > 0 Then
'Agrego el RetIVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.DataKey("RetIVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 22, TxtObservaciones.Text, Now, 0, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
End If
End If
'If MsgError = "" AndAlso gvr.DataKey("RetISR").ToDouble > 0 Then
' 'Agrego el RetIVA
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.DataKey("RetISR").ToDecimal * PorcentajePago, TxtObservaciones.Text, 23, TxtObservaciones.Text, Now, 0, -1, CveIE, CveCompra:=gvr.DataKey("CveCompra").ToEntero, CveProveedor:=CveProveedor, ImporteMX:=gvr.DataKey("RetISR").ToDecimal * PorcentajePago) Then
' MsgError = "Detalle"
' End If
'End If
'DESPROGRAMA LO PROGRAMADO DESPUES DE HACERLE UN PAGO
If DdlTipoTransaccion.SelectedValue <> "9" Then 'SI ES LAYOUT SE DESPROGRAMA EN BANCOS/PAGOELECTRONICO
If gvr.DataKey("ImporteProgramo").ToDouble > 0 Then
ObjComp.ProgramarCompra(gvr.DataKey("CveCompra").ToEntero, 0, UsuarioActual.CveUsuario, -1)
End If
End If
End If
End If
End If
Next
End If 'Empresa Prueba
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
If UsuarioActual.Empresa.UsaContabilidad Then
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("Original").ToDouble > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDouble / gvr.DataKey("Original").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
End If
If Not TieneError Then
ObjIE.Commit()
If ObjConta IsNot Nothing Then ObjConta.Commit()
Anexo.Text = "[]"
'RMF. comentado para verificar proceso.
''actualizo el notificar A del proveedor
'If UsuarioActual.Empresa.Funcionalidad(142) = "1" Then
' Dim Prov As New ClsCompProveedores
' Prov.UpdateProveedorNotificarA(CveProveedor, TxtNotificarA.Text.Trim)
' Prov.Dispose()
'End If
'IMPRIME CHEQUE
'GeneraChequePDF(CveIE, UsuarioActual.Empresa, IDPoliza)
Dim Msg As New StringBuilder
'Dim Archivo As New System.IO.FileInfo(String.Format("{0}Formatos/CHQ-{1}.rdlc", UsuarioActual.Empresa.Ruta, DdlCuenta.SelectedValue.ToEntero))
'If Archivo.Exists Then
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() '(CveProveedor, CveMoneda, FechaI, FechaF, CveUsuarioRegistro, CveUsuarioProgramo, Serie)
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) ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.SelectedValue = TipoPago.ToString
ElseIf TipoPago = 2 Then
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs' AND CveTipoTransaccion IN (1, 2) ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.SelectedValue = TipoPago.ToString
RecargaCuentasDepositos()
ElseIf TipoPago = 3 Then
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs' AND CveTipoTransaccion IN (1, 2) ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.SelectedValue = TipoPago.ToString
RecargaCuentasDepositos()
Else
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'")
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)
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) 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) 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) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
Dim PorcentajePago As Decimal = gr.DataKey("Saldo").ToDecimal / gr.DataKey("Original").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) 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 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))) 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 = "" AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, Saldo, gr.DataKey("SerieFolio").ToString, 78, 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) Then
MsgError = "Ocurrio un error al saldar el movimiento"
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) 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) 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