Files
SIG/Ventas/ClientesAbonar.aspx.vb
2020-08-04 13:14:18 -07:00

3093 lines
191 KiB
VB.net

Imports Extensiones
Imports System.Data
Imports System.Linq
Partial Class Ventas_ClientesAbonar
Inherits ClsPaginas
#Region "Propiedades"
Private ReadOnly Property CveCliente As Integer
Get
Return ViewState("CveCliente").ToString.ToEntero
End Get
End Property
Private Property CveMoneda As Integer
Get
Return ViewState("CveMoneda").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMoneda") = value
End Set
End Property
Private Property CveMonedaPago As Integer
Get
Return ViewState("CveMonedaPago").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMonedaPago") = 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 CveSubProyecto As Integer
Get
Return ViewState("CveSubProyecto").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveSubProyecto") = value
End Set
End Property
Private Property CveClienteSucursal As Integer
Get
Return If(IsNothing(ViewState("CveClienteSucursal")), -1, ViewState("CveClienteSucursal").ToString.ToEntero)
End Get
Set(value As Integer)
ViewState("CveClienteSucursal") = value
End Set
End Property
Private Property DTFuenteRecaudacion As DataTable
Get
Return CType(ViewState("DTFuenteRecaudacion"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTFuenteRecaudacion") = value
End Set
End Property
Private Property IdCuentaBancaria As Integer
Get
Return ViewState("IdCuentaBancaria").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuentaBancaria") = 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 CveCuentaBancaria As Integer
Get
Return ViewState("CveCuentaBancaria").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuentaBancaria") = value
End Set
End Property
Private Property CveCuentaBancariaComplementaria As Integer
Get
Return ViewState("CveCuentaBancariaComplementaria").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuentaBancariaComplementaria") = value
End Set
End Property
Private Property NombreComercial As String
Get
Return ViewState("NombreComercial").ToString
End Get
Set(value As String)
ViewState("NombreComercial") = value
End Set
End Property
Private Property IdCuentaCliente As Integer
Get
Return ViewState("IdCuentaCliente").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuentaCliente") = 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 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 Property IdCtaAnticipo As Integer
Get
Return ViewState("IdCtaAnticipo").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCtaAnticipo") = value
End Set
End Property
Private Property IdCtaContMonedaExtranjeraAnticipo As Integer
Get
Return ViewState("IdCtaContMonedaExtranjeraAnticipo").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCtaContMonedaExtranjeraAnticipo") = value
End Set
End Property
Private Property IdCtaContMonedaComplementariaAnticipo As Integer
Get
Return ViewState("IdCtaContMonedaComplementariaAnticipo").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCtaContMonedaComplementariaAnticipo") = value
End Set
End Property
Private Property CveCuentaCliente As Integer
Get
Return ViewState("CveCuentaCliente").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuentaCliente") = value
End Set
End Property
Private ReadOnly Property CveCuentaMonedaExtranjera As Integer
Get
Return ViewState("CveCuentaMonedaExtranjera").ToString.ToEntero
End Get
End Property
Private ReadOnly Property CveCuentaComplementaria As Integer
Get
Return ViewState("CveCuentaComplementaria").ToString.ToEntero
End Get
End Property
Private ReadOnly Property CveCuentaRetIVA As Integer
Get
Return ViewState("CveCuentaRetIVA").ToString.ToEntero
End Get
End Property
Private ReadOnly Property CveCuentaRetISR As Integer
Get
Return ViewState("CveCuentaRetISR").ToString.ToEntero
End Get
End Property
Private Property Mail As String
Get
If ViewState("Mail") Is Nothing Then
Return ""
Else
Return ViewState("Mail").ToString
End If
End Get
Set(value As String)
ViewState("Mail") = value
End Set
End Property
Private Property CveIESustitucion As Integer
Get
Return ViewState("CveIESustitucion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveIESustitucion") = value
End Set
End Property
Private Property CFDIRelacionadoSustitucion As String
Get
If ViewState("CFDIRelacionadoSustitucion") Is Nothing Then
Return "-1"
Else
Return ViewState("CFDIRelacionadoSustitucion").ToString
End If
End Get
Set(value As String)
ViewState("CFDIRelacionadoSustitucion") = value
End Set
End Property
Private Property FechaCorteIE As DateTime
Get
Return ViewState("FechaCorteIE").ToString.ToDateTime
End Get
Set(value As DateTime)
ViewState("FechaCorteIE") = value
End Set
End Property
Private Property IDPoliza As Integer
Get
Return ViewState("IDPoliza").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IDPoliza") = value
End Set
End Property
Private Property FolioIECancelado As String
Get
If ViewState("FolioIECancelado") Is Nothing Then
Return "-1"
Else
Return ViewState("FolioIECancelado").ToString
End If
End Get
Set(value As String)
ViewState("FolioIECancelado") = value
End Set
End Property
Private Property ComplementoSustitucionGenerado As Boolean
Get
Return CBool(ViewState("ComplementoSustitucionGenerado"))
End Get
Set(value As Boolean)
ViewState("ComplementoSustitucionGenerado") = value
End Set
End Property
Private Property Fecha As Date
Get
Return ViewState("Fecha").ToString.ToDate
End Get
Set(value As Date)
ViewState("Fecha") = 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
CveMonedaPago = -1
If Request("CveCliente") IsNot Nothing AndAlso Request("CveCliente").ToString.ToEntero > 0 Then
ViewState("CveCliente") = Request("CveCliente").ToString.ToEntero
'ViewState("CveUsuario") = IfNultl(Request("CveUsuario"), "-1").ToStrirowComisionesng.ToEntero
ViewState("CveMonedaFiltro") = IfNull(Request("CveMoneda"), "-1").ToString.ToEntero
ViewState("CveMoneda") = IfNull(Request("CveMoneda"), "-1").ToString.ToEntero
ViewState("FechaI") = IfNull(Request("FechaI"), "-1").ToString.ToEntero
ViewState("FechaE") = IfNull(Request("FechaE"), "-1").ToString.ToEntero
ViewState("CveSubProyecto") = IfNull(Request("CveSubProyecto"), "-1").ToString.ToEntero
ViewState("CveClienteSucursal") = IfNull(Request("CveClienteSucursal"), "-1").ToString.ToEntero
ViewState("IdCtaAnticipo") = 0
ViewState("IdCtaContMonedaExtranjeraAnticipo") = 0
ViewState("IdCtaContMonedaComplementariaAnticipo") = 0
ViewState("CveIESustitucion") = IfNull(Request("CveIESustitucion"), "-1").ToString.ToEntero
DdlProveedorIntermediario.setEsWebService(True)
DdlProveedorIntermediario.Attributes.Add("data-metodo", "getproveedores")
FechaCorteIE = DateTime.Now
If CveIESustitucion > 0 Then
CargaIESustituir()
End If
Dim dia As Integer = If(UsuarioActual.CveEmpresa = 13, Now.Day - 1, Now.Day)
Fecha = (dia.ToString + "/" + Now.Month.ToString + "/" + Now.Year.ToString).ToDate
If CargaCliente(CveCliente, CveMonedaFiltro) Then
IdCuentaBancaria = 0
CveCuentaBancaria = 0
TxtOtrosImportes.Attributes.Add("onKeyUp", String.Format("FnSuma(this,{0},{1});", "TxtTotal", 0))
If CveMoneda > 0 Then LbTipoMoneda.Text = String.Format("Pago en {0}", GlobalDTMonedas.FiltraParametros(String.Format("CveMoneda = {0}", CveMoneda)).Rows(0)("Moneda"))
If CveMoneda = 2 Then
ChkPagarPesos.Visible = True
TxtTC.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
TxtTCDolaresDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
DivTCDolaresDolares.Visible = True
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
ElseIf CveMoneda = 1 Then
ChkPagarDolares.Visible = True
TxtTCDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
ElseIf CveMoneda = -1 Then
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
TxtTCDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
TxtTC.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
End If
If UsuarioActual.TienePermisoProceso(209) Or UsuarioActual.TienePermisoProceso(204) Then
HlSaldarCuentasIncobrables.Visible = True
End If
End If
If CveMonedaFiltro = -1 Then
ChkPagarPesos.Visible = False
ChkPagarDolares.Visible = False
End If
RegistraScript($"TipoCambioActual = {GlobalTipoCambio(Fecha).FormatoNumero(4)}")
End If
RVTxtFechaDocumento.MaximumValue = Now.ToString("dd/MM/yyyy")
End If
If (CveMonedaFiltro = 2 And ChkPagarPesos.Checked) Then
RegistraScript("document.getElementById('DivTC').style.display = 'block';")
End If
End Sub
Private Sub CargaTipoTransaccion()
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Ing' AND Estatus = 1 ")
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1"))
RecargaCuentasDepositos()
End Sub
Private Sub CargaCuentas()
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
DdlCuenta.DataSource = dt
DdlCuenta.DataBind()
DdlCuenta.Items.Insert(0, New ListItem("Seleccione cuenta", "-1"))
End Sub
Private Function CargaCliente(tCveCliente As Integer, tCveMoneda As Integer) As Boolean
Dim Retorno As Boolean = False
Dim ObjCliente As New ClsClientes()
If ObjCliente.GetClientes(tCveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
Retorno = True
CargaCuentas()
CargaTipoTransaccion()
TxtFechaDocumento.Text = IIf(CveIESustitucion > 0, FechaCorteIE.ToShortDateString, Now.ToShortDateString).ToString
TxtAboneA.Enabled = False
LbEncabezado.Text = String.Format("<a href='/Ventas/Clientes.aspx?CveCliente={0}' target='_blank' class='Texto'>{1}</a>", CveCliente, ObjCliente.NombreComercial)
TxtAboneA.Text = ObjCliente.NombreComercial
NombreComercial = ObjCliente.NombreComercial
TxtImporte.Attributes.Add("disabled", "disabled")
If DdlTipoTransaccion.SelectedValue = "1" Then RFVFolio.Enabled = True Else RFVFolio.Enabled = False
ViewState("CtaCliente") = ObjCliente.IdCtaContClientes
ViewState("IdCuentaCliente") = ObjCliente.IdCtaContClientes
ViewState("IdCtaContMonedaExtranjera") = ObjCliente.IdCtaContMonedaExtranjera
ViewState("IdCtaContComplementaria") = ObjCliente.IdCtaContComplementaria
ViewState("IdCtaContRetIVA") = ObjCliente.IdCtaContRetIVA
ViewState("IdCtaContRetISR") = ObjCliente.IdCtaContRetISR
ViewState("CveCuentaCliente") = ObjCliente.CveCuentaClientes
ViewState("CveCuentaMonedaExtranjera") = ObjCliente.CveCuentaMonedaExtranjera
ViewState("CveCuentaComplementaria") = ObjCliente.CveCuentaComplementaria
ViewState("CveCuentaRetIVA") = ObjCliente.CveCuentaRetIVA
ViewState("CveCuentaRetISR") = ObjCliente.CveCuentaRetISR
ViewState("IdCtaAnticipo") = ObjCliente.IdCtaContAnticipos
ViewState("IdCtaContMonedaExtranjeraAnticipo") = ObjCliente.IdCtaMonedaExtranjeraAnticipos
ViewState("IdCtaContMonedaComplementariaAnticipo") = ObjCliente.IdCtaContCompAnticipos
Mail = String.Format("{0};{1}", ObjCliente.CobranzaCorreo, ObjCliente.NotificarA)
If Request("FechaI") IsNot Nothing Then ViewState("FechaI") = Request("FechaI") Else ViewState("FechaI") = "-1"
If Request("FechaF") IsNot Nothing Then ViewState("FechaF") = Request("FechaF") Else ViewState("FechaF") = "-1"
CargaDatos(tCveMoneda)
Else
Alert("El Cliente Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia)
End If
End If
ObjCliente.Dispose()
Return Retorno
End Function
Private Sub CargaDatos(pCveMoneda As Integer)
Dim Mov As New ClsMovimientos
Dim FechaI As String = IfNull(Request("FechaI"), "-1")
Dim FechaF As String = IfNull(Request("FechaF"), "-1")
Dim FechaCorte As Date = IIf(CveIESustitucion > 0, (FechaCorteIE.ToDate).ToShortDateString, DateTime.Now.AddYears(1).ToShortDateString).ToString.ToDate
Dim SumDescuentoProntoPago As Double = 0.0
If Mov.GetCxCClienteDetalle(ViewState("CveCliente").ToString.ToEntero, FechaI, FechaF, pCveMoneda, CveSubProyecto, UsuarioActual.CveEmpresa, CveClienteSucursal, FechaCorte:=FechaCorte, CveIESustitucion:=CveIESustitucion) Then
Dim TmpCxCAux As DataTable
TmpCxCAux = Mov.DtResultados.FiltraParametros("Saldo > 0", "Fecha,SerieFolio")
SumDescuentoProntoPago = TmpCxCAux.SUM("DescuentoProntoPago")
GvCxC.DataSource = Mov.DtResultados.FiltraParametros("Saldo > 0", "Fecha,SerieFolio")
GvCxC.DataBind()
CveMoneda = pCveMoneda
End If
TxtImporte.Text = ""
TxtObservaciones.Text = ""
If SumDescuentoProntoPago > 0.0 Then
GvCxC.Columns(14).Visible = True 'MOSTRAR DESCUENTO PRONTO PAGO
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
GvCxC.Columns(15).Visible = True 'HABILITAR NC
End If
End If
Mov.Dispose()
UPVentas.Update()
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("CveCuenta = " & DdlCuenta.SelectedValue)
Dim moneda As Integer = 0
If DdlCuenta.SelectedValue > 0 Then
moneda = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero}").ToEntero
End If
CveMonedaPago = moneda
If dr IsNot Nothing Then
If ChkPagarPesos.Checked Then
CveMoneda = 2
RegistraScript("document.getElementById('DivTC').style.display = 'block';")
RegistraScript("CambiaPesosDolares();")
TxtTC.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,1,{0});", moneda))
ElseIf ChkPagarPesos.Checked = False Then
CveMoneda = dr("CveMoneda").ToString.ToEntero
RegistraScript("document.getElementById('DivTC').style.display = 'none';")
RegistraScript("CambiaDolaresPesos();")
TxtTC.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,1,{0});", moneda))
End If
If ChkPagarDolares.Checked Then
CveMoneda = 1
TxtTCDolares.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,1,{0});", moneda))
End If
IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero
IdCuentaBancariaComplementaria = dr("IdCtaContableComplementaria").ToString.ToEntero
CveCuentaBancaria = dr("IdCtaContableSIG").ToString.ToEntero
CveCuentaBancariaComplementaria = dr("IdCtaContableComplementariaSIG").ToString.ToEntero
ValidaCuentaDePagoFormaDePago()
End If
CargaDatos(CveMoneda)
' si no tiene CveMoneda, o es -1, cuando cambia de cuenta filtra las facturas
If IfNull(Request("CveMoneda"), "-1").ToString.ToEntero = -1 Then
CargaDatos(-1)
moneda = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero}").ToEntero
If moneda = 1 Then
'DivTC.Visible = True
DivTCDolares.Visible = False
TxtTC.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,-1,{0});", moneda))
ElseIf moneda = 2 Then
'DivTC.Visible = False
RegistraScript("document.getElementById('DivTC').style.display = 'none';")
DivTCDolares.Visible = True
TxtTCDolares.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,-1,{0});", moneda))
End If
End If
If HdnTipoTransaccion.Value = "Ing" AndAlso UsuarioActual.Empresa.Funcionalidad(505) <> "1" Then
If UsuarioActual.CveEmpresa = 119 Then
Dim ObjFolios As New ClsGralFolios
If ObjFolios.GetFolios("RMF", UsuarioActual.CveEmpresa) Then
Dim DT As DataTable = ObjFolios.DtResultados.FiltraParametros(String.Format(" Estado = 'Activo'"))
If DT.Rows.Count > 0 Then
TxtFolio.Text = DT.Rows(0)("FActual").ToString.ToEntero
End If
ObjFolios.Dispose()
End If
Else
Dim Folio As Long
Dim Banco As New ClsBancos
Folio = Banco.GetNextFolio(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero)
Banco.Dispose()
TxtFolio.Text = Folio.ToString
End If
Else
TxtFolio.Text = ""
End If
End Sub
Protected Sub DdlTipoTransaccion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoTransaccion.SelectedIndexChanged
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
End If
RecargaCuentasDepositos()
'CargaCuentas()
ValidaCuentaDePagoFormaDePago()
End Sub
Protected Sub GvCxC_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxC.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim moneda As Integer = 0
If e.Row.RowIndex = 0 Then
e.Row.Cells(0).ColumnSpan = 5
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(1).Visible = False
e.Row.Cells(2).Visible = False
e.Row.Cells(3).Visible = False
e.Row.Cells(4).Visible = False
e.Row.BackColor = Drawing.Color.LightGray
End If
If e.Row.RowIndex = 1 Then
e.Row.Cells(0).Width = Unit.Pixel(25)
e.Row.Cells(1).Width = Unit.Pixel(90)
e.Row.Cells(2).Width = Unit.Pixel(70)
e.Row.Cells(3).Width = Unit.Pixel(70)
e.Row.Cells(6).Width = Unit.Pixel(50)
e.Row.Cells(7).Width = Unit.Pixel(70)
e.Row.Cells(8).Width = Unit.Pixel(50)
e.Row.Cells(9).Width = Unit.Pixel(90)
e.Row.Cells(10).Width = Unit.Pixel(80)
e.Row.Cells(11).Width = Unit.Pixel(60)
End If
' e.Row.Cells(2).HorizontalAlign = HorizontalAlign.Right
' e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Right
' e.Row.Cells(4).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(9).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(10).HorizontalAlign = HorizontalAlign.Right
If e.Row.DBCampo("Saldo").ToDecimal < 0 Then e.Row.Cells(11).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("DiasVencidos").ToDecimal > 0 AndAlso CType(sender, GridView).ID = "GvCxC" Then e.Row.Cells(5).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("Original").ToDecimal = 0 Then DirectCast(e.Row.FindControl("LtlSaldoOriginal"), Literal).Text = ""
If e.Row.DBCampo("Abonado").ToDecimal = 0 Then DirectCast(e.Row.FindControl("LtlAbonado"), Literal).Text = ""
If e.Row.DBCampo("Saldo").ToDecimal = 0 Then DirectCast(e.Row.FindControl("LtlSaldo"), Literal).Text = ""
Select Case RblTipoPago.SelectedValue
Case "1"
If DdlCuenta.SelectedValue > 0 Then
moneda = CveMonedaPago
ElseIf RblTipoPago.SelectedValue = "1" Then
e.Row.FCCheckBox("Chk").Enabled = False
e.Row.FCTextBox("TxtAbonar").Enabled = False
End If
Case "3"
moneda = CveMonedaPago
End Select
If e.Row.DBCampo("DescuentoProntoPago").ToDecimal() > 0 Then
e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1}); FnCambia({2},this,{1},0,{3},{4}); FnSeleccionaNC({5},{6},{0});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo"), e.Row.FCCheckBox("Chk").ClientID, CveMonedaFiltro, moneda, e.Row.FCCheckBox("Chk").ClientID, e.Row.FCCheckBox("ChkGenerarNC").ClientID))
Else
e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1}); FnCambia({2},this,{1},0,{3},{4});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo"), e.Row.FCCheckBox("Chk").ClientID, CveMonedaFiltro, moneda))
End If
If Not UsuarioActual.Empresa.Funcionalidad(536) = "1" Then
If e.Row.DBCampo("TipoDocto") = "Rem" Then
e.Row.FCCheckBox("Chk").Visible = False ' que no se pueda pagar si es remisión
e.Row.Cells(0).ToolTip = "El documento es remisión y no se puede realizar el pago"
End If
End If
If e.Row.DBCampo("CveVenta").ToEntero > 0 Then
e.Row.FCLiteral("LtlAux").Text = String.Format("<a class=""Texto thickbox"" href=""/Contabilidad/PopUpAuxiliar.aspx?Tipo=CxCClientes&CveCliente={0}&CveVenta={1}&TB_iframe=true&height=370&width=900"" />Ir</a>", e.Row.DBCampo("CveCliente").ToEntero, e.Row.DBCampo("CveVenta").ToEntero)
e.Row.FCTextBox("TxtAbonar").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},1,{2},{3});", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), CveMonedaFiltro, moneda))
If UsuarioActual.Empresa.Funcionalidad(157).ToDecimal <> 0 Then
e.Row.FCTextBox("TxtComision").Attributes.Add("onblur", String.Format("FnLimites({0},this,{1},{2},2);", e.Row.FCCheckBox("Chk").ClientID, -UsuarioActual.Empresa.Funcionalidad(157), UsuarioActual.Empresa.Funcionalidad(157).ToString.ToDecimal))
e.Row.FCRangeValidator("RVComision").MinimumValue = -UsuarioActual.Empresa.Funcionalidad(157).ToString.ToDecimal
e.Row.FCRangeValidator("RVComision").MaximumValue = UsuarioActual.Empresa.Funcionalidad(157).ToString.ToDecimal
e.Row.FCRangeValidator("RVComision").Enabled = True
Else
e.Row.FCTextBox("TxtComision").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1},2,{2},{3});", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo"), CveMonedaFiltro, moneda))
e.Row.FCRangeValidator("RVComision").MinimumValue = 0.00
e.Row.FCRangeValidator("RVComision").MaximumValue = e.Row.DBCampo("Saldo")
End If
If e.Row.DBCampo("DescuentoProntoPago").ToDecimal() > 0 AndAlso e.Row.DBCampo("DiasVencidos").ToEntero() <= 0 Then
e.Row.FCCheckBox("ChkGenerarNC").Visible = True
e.Row.FCCheckBox("ChkGenerarNC").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1}); FnCambia({2},this,{1},0,{3},{4}); FnEditarImporte({2}, {0});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo").ToDecimal - e.Row.DBCampo("DescuentoProntoPago").ToDecimal, e.Row.FCCheckBox("ChkGenerarNC").ClientID, CveMonedaFiltro, moneda))
End If
Else
e.Row.FCTextBox("TxtAbonar").Visible = False
e.Row.FCTextBox("TxtComision").Visible = False
e.Row.FCCheckBox("Chk").Visible = False
End If
End If
End Sub
Protected Sub BtnIEGuardar_Click(sender As Object, e As EventArgs) Handles BtnIEGuardar.Click
If Not TxtImporte.Text.ToDecimal > 0 Then
Alert("Debe de llevar un Importe", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not (TxtFolio.Text.Trim <> "" Or RblTipoPago.SelectedValue = "2" Or RblTipoPago.SelectedValue = "3") Then
Alert("Debe de llevar un Folio", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim Cuenta As String = ""
Dim CuentaDeposito As String = ""
Dim seleccion As Integer = 0
For Each gvr As GridViewRow In GvCxC.Rows
If gvr.FCCheckBox("Chk").Checked Then
seleccion += 1
End If
Next
If seleccion = 0 Then
Alert("No ha seleccionado ninguna factura para abonar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim CvePrePoliza As Integer = 0
Dim IDPoliza As Integer = 0
Dim FolioPoliza As String = ""
Dim CveIE As Integer = -1
Dim CveVentasPago As New List(Of Integer)
Dim SeriesPago As New List(Of String)
Dim MsgError As String = ""
Dim NCGeneradas As New List(Of Modelos.Factura.MMensajeFactura)
Dim ListaFacturasGenerarNC As New List(Of Modelos.Factura)
Dim ImporteSeleccionado As Decimal = 0
'02-05-2018 MANDAMOS CANCELAR EL COMPLEMENTO A SUSTITUIR
Dim ErrorCancelarIE As Boolean = False
If CveIESustitucion > 0 Then
ErrorCancelarIE = CancelarIE()
If ErrorCancelarIE Then
Exit Sub
End If
End If
Dim ObjIE As New ClsBancos()
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
Dim ObjVentasSaldos As New ClsVentas(ObjIE.IniciaTransacSQL)
Dim ObjEvento As New ClsOIEventos(ObjIE.IniciaTransacSQL)
Dim ObjConta As ClsContPAQi = Nothing
Try
Dim filesgral As List(Of Archivo) = Anexo.getfiles().Archivos
Dim filemove As String = ""
Dim Comprobante As String = ""
ComplementoSustitucionGenerado = False
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}", TxtAboneA.Text, TxtObservaciones.Text)
If DdlCuenta.SelectedValue > 0 Then
CveMoneda = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero}").ToEntero
Else
CveMoneda = If(Request("CveMoneda").ToString.ToEntero > 0, Request("CveMoneda").ToString.ToEntero, 1)
End If
CvePrePoliza = ObjMov.AddPrePolizas("Ventas/ClientesAbonar", 11, TxtImporte.Text.Trim.ToDecimal, TxtImporte.Text.Trim.ToDecimal, CveMoneda, TxtFechaDocumento.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If RblTipoPago.SelectedValue = "1" Then
Dim CveCuentaDeposito As Integer = 0
Dim TipoCambio As Decimal = 0
If DdlCuentaDeposito.Items.Count > 0 Then
CveCuentaDeposito = DdlCuentaDeposito.SelectedValue.ToEntero
End If
If CveMoneda = 2 Then
If TxtTCDolares.Visible Then
TipoCambio = TxtTCDolares.Text.ToDecimal
Else
TipoCambio = If(CveMonedaFiltro = -1, TxtTCDolares.Text.ToDecimal, TxtTCDolaresDolares.Text.ToDecimal) 'GlobalTipoCambio(TxtFechaDocumento.Text).ToString.ToDecimal
End If
Else
If TxtTC.Visible Then
TipoCambio = TxtTC.Text.ToDecimal
End If
End If
Dim CveProvIntermediario As Integer
If ChkProveedorIntermediario.Checked Then
CveProvIntermediario = If(DdlProveedorIntermediario.SelectedValue.ToEntero <= 0, -1, DdlProveedorIntermediario.SelectedValue.ToEntero)
End If
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaDocumento.Text.Trim.ToDate, TxtFolio.Text.Trim, TxtAboneA.Text.Trim, TxtImporte.Text.ToDecimal, GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", "CveCuenta = " & DdlCuenta.SelectedValue).ToEntero, TipoCambio, TxtObservaciones.Text.Trim, "", True, True, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCuentaDeposito:=CveCuentaDeposito, CveIESustitucion:=CveIESustitucion, CveProveedorIntermediario:=CveProvIntermediario)
Else
If RblTipoPago.SelectedValue.Contiene("3") Then
CveIE = DdlIngreso.SelectedValue.ToEntero
If CveMonedaPago = 2 And Not ChkPagarPesos.Checked Then CveMoneda = 2
If ChkPagarDolares.Checked Then CveMoneda = 2
If ChkPagarPesos.Checked Then CveMoneda = 1
End If
End If
If CveIE > 0 OrElse RblTipoPago.SelectedValue.Contiene("2", "3") Then
'Guardar archivo
If filemove <> "" Then
filemove.FilesMove(CveIE.ToString, String.Format("Empresas\{0}\IE", UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta))
End If
'inserto los movimientos de la conta para abonar al saldo
If CvePrePoliza > 0 Then
Dim PorcentajePago As Decimal = 100
Dim CvePlantillaPoliza As Integer = 11
Dim alertaContabilizacion As String = "Se enviaron correctamente las siguientes pólizas:<br><br>"
Dim idCuentaContabilizacion As Long = 1
Dim CveCuentaContabilizacion As Long = 1
Dim dtConceptos As DataTable = Nothing
Dim tipoCambioVenta As Decimal
Dim tipoCambioPago As Decimal
Dim tipoCambioVentaValuacion As Decimal = 1
Dim TipoCambioGeneral As Decimal = 1
Dim CuentasContablesInvalidas As New StringBuilder
Dim CuentasContablesInvalidasSIG As New StringBuilder
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 Fecha As String = String.Format("{0}/{1}/{2}", tFecha.Year, tFecha.Month, tFecha.Day)
Dim drr As DataRow = ObjIE.DtResultados.FiltroPrimero("Fecha < #" & Fecha & "#", "Fecha DESC")
If drr IsNot Nothing Then
FechaUltimaFluctuacion = drr("Fecha").ToString.ToDate
TipoCambioFluctuacion = drr("TipoCambio").ToString.ToDecimal
End If
End If
End If
If ObjMov.GetPlantillaConceptos(UsuarioActual.CveEmpresa, CvePlantillaPoliza) Then
dtConceptos = ObjMov.DtResultados
End If
'inserto las ventas que voy a pagar
For Each gvr As GridViewRow In GvCxC.Rows
If gvr.FCCheckBox("Chk").Checked Then
Dim ObjFactura As Modelos.Factura = Nothing
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
ObjFactura = New Modelos.Factura(UsuarioActual, gvr.DataKey("CveVenta").ToEntero(), UsuarioActual.CveEmpresa)
End If
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
tipoCambioVenta = 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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
tipoCambioVentaValuacion = 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 = 2 Then 'Si la venta viene en Dolares y se va a pagar en DOLARES
tipoCambioPago = If(CveMonedaFiltro = -1, TxtTCDolares.Text.ToDecimal, TxtTCDolaresDolares.Text.ToDecimal)
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
tipoCambioVentaValuacion = 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
tipoCambioVenta = 1
PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal
End If
'PARA EMITIR COMPLEMENTO PAGO
CveVentasPago.Add(gvr.DataKey("CveVenta").ToEntero)
SeriesPago.Add(gvr.DataKey("SerieFolio"))
Dim tipoCambioVentaDiferenciaCambiaria As Double = 1
Dim EsAnticipoEspecial As Boolean = False
If gvr.DataKey("TipoDocto") = "Ant" AndAlso UsuarioActual.CveEmpresa.Contiene(1, 119) Then EsAnticipoEspecial = True
If dtConceptos IsNot Nothing Then
For Each Row As DataRow In dtConceptos.Rows
Dim ConceptoContable = Row("CveConcepto").ToString.ToEntero
Dim TipoMovimiento As Boolean = If(Row("TipoMovto").ToString = "True", True, False)
Dim ImporteMovimiento As Decimal = 0
Dim importeMX As Decimal
Dim FechaMovimiento As Date = TxtFechaDocumento.Text
Dim IdCtaContable As Integer = 0
Dim CveCuenta As Integer = 0
Dim ConceptoMovimiento As String = ObjMov.ObtenerConceptoEmpresa(UsuarioActual.CveEmpresa, ConceptoContable, NombreComercial, gvr.DataKey("SerieFolio").ToString, TxtFolio.Text.Trim)
Dim Referencia As String = gvr.DataKey("SerieFolio").ToString
Dim CveSubProyecto As Integer = gvr.DataKey("CveSubProyecto").ToEntero
Dim CveSubProyectoContabilizar As Integer = -1
Dim PorcentajeImpuesto As Decimal = 0
Select Case ConceptoContable
Case 2 'Pago Cliente
'If gvr.DataKey("CveMoneda").ToEntero > 1 Then ConceptoContable = 292
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 * tipoCambioVentaValuacion
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
importeMX = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
importeMX = ImporteMovimiento * tipoCambioVentaValuacion
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = tipoCambioVentaValuacion
CveSubProyectoContabilizar = CveSubProyecto
If gvr.DataKey("CveMoneda").ToEntero = 1 Then
IdCtaContable = If(EsAnticipoEspecial, IdCtaAnticipo, IdCuentaCliente)
ConceptoContable = If(EsAnticipoEspecial, 3, ConceptoContable)
CveCuenta = If(EsAnticipoEspecial, -1, CveCuentaCliente)
Else
ConceptoMovimiento += $" TC:{tipoCambioVentaValuacion} ${ImporteMovimiento.FormatoNumero(2)}"
IdCtaContable = If(EsAnticipoEspecial, IdCtaContMonedaComplementariaAnticipo, IdCtaContComplementaria)
CveCuenta = If(EsAnticipoEspecial, -1, CveCuentaComplementaria)
If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then
importeMX = ImporteMovimiento
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, Referencia, If(gvr.DataKey("TipoDocto") = "Ant" AndAlso UsuarioActual.CveEmpresa = 119, 226, 207), ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, gvr.FCHyperLink("HplF2").Text.ToEntero, -1, CveSubProyectoContabilizar, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=Math.Round(ImporteMovimiento * tipoCambioVentaValuacion - ImporteMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=ImporteMovimiento, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioVentaValuacion) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
IdCtaContable = If(EsAnticipoEspecial, IdCtaContMonedaExtranjeraAnticipo, IdCtaContMonedaExtranjera)
CveCuenta = If(EsAnticipoEspecial, -1, CveCuentaMonedaExtranjera)
ConceptoContable = If(EsAnticipoEspecial, 3, ConceptoContable)
End If
If EsAnticipoEspecial Then
If ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, ImporteMovimiento, Referencia, 2, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, gvr.FCHyperLink("HplF2").Text.ToEntero, -1, CveSubProyectoContabilizar, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=importeMX, CveCuenta:=CveCuenta, TipoCambio:=TipoCambioGeneral, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=False) Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, Referencia, 95, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, gvr.FCHyperLink("HplF2").Text.ToEntero, -1, CveSubProyectoContabilizar, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=importeMX, CveCuenta:=CveCuenta, TipoCambio:=TipoCambioGeneral, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=PorcentajeImpuesto, Contabilizable:=False) Then
MsgError = "No se pudo insertar la póliza"
End If
Else
MsgError = "No se pudo insertar la póliza"
End If
End If
Case 8 'Ret IVA x Trasladar
If EsAnticipoEspecial Then Exit Select
If gvr.DataKey("CveTipoRetencion").ToEntero = 4 Then
Exit Select
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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioVenta
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = tipoCambioVenta
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetIVA <> 0 Then
IdCtaContable = IdCtaContRetIVA
Else
If 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
'Conta SIG
If CveCuentaRetIVA <> 0 Then
CveCuenta = CveCuentaRetIVA
Else
If ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjMov.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero
End If
End If
End If
Case 313 'Ret Iva Servicios
If EsAnticipoEspecial Then Exit Select
If gvr.DataKey("CveTipoRetencion").ToEntero = 4 Then
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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetIVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioVenta
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = tipoCambioVenta
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
'OBTENER CUENTAS
If ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
'Conta ContPAQ
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero
End If
End If
End If
Case 9 'Ret ISR x Trasladar
If EsAnticipoEspecial Then Exit Select
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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetISR").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = gvr.DataKey("RetISR").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento * tipoCambioVenta
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = tipoCambioVenta
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetISR <> 0 Then
IdCtaContable = IdCtaContRetISR
Else
If 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
'Conta SIG
If CveCuentaRetISR <> 0 Then
CveCuenta = CveCuentaRetISR
Else
If ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjMov.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero
End If
End If
End If
Case 13 'Iva por Trasladar
If EsAnticipoEspecial Then Exit Select
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IVA").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("IVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IVA").ToDecimal * PorcentajePago).RoundSQL() ' se ajusta por la parcialidad de pago, afecta en el redondeo
importeMX = ImporteMovimiento * tipoCambioVenta
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL()
TipoCambioGeneral = tipoCambioVenta
CveSubProyectoContabilizar = CveSubProyecto
PorcentajeImpuesto = gvr.DataKey("PorcentajeIVA").ToDecimal
Dim IdCtaIVAXTrasladar As Integer = 0
Dim CveCuentaIVAxTrasladar As Integer = 0
If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows.Count > 0 Then
IdCtaIVAXTrasladar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("IdCtaIVAXTrasladar").ToString.ToEntero
CveCuentaIVAxTrasladar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("CveCuentaIVAXTrasladar").ToString.ToEntero
End If
IdCtaContable = If(IdCtaIVAXTrasladar > 0, IdCtaIVAXTrasladar, UsuarioActual.Empresa.IdCuentaIVAxTrasladar)
CveCuenta = If(CveCuentaIVAxTrasladar > 0, CveCuentaIVAxTrasladar, UsuarioActual.Empresa.CveCuentaIVAxTrasladar)
If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
Case 62 'Ret IVA Trasladado
If EsAnticipoEspecial Then Exit Select
If gvr.DataKey("CveTipoRetencion").ToEntero = 4 Then
Exit Select
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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{tipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetIVA <> 0 Then
IdCtaContable = IdCtaContRetIVA
Else
If 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
'Conta SIG
If CveCuentaRetIVA <> 0 Then
CveCuenta = CveCuentaRetIVA
Else
If ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjMov.DtResultados.Rows(0)("IdCuentaRetIVACirculacionSIG").ToString.ToEntero
End If
End If
End If
Case 314 'Ret Iva Servicios Traslado
If EsAnticipoEspecial Then Exit Select
If gvr.DataKey("CveTipoRetencion").ToEntero = 4 Then
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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetIVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{tipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
'OBTENER CUENTAS
If ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
'Conta ContPAQ
IdCtaContable = ObjMov.DtResultados.Rows(0)("IdCtaContable").ToString.ToEntero
End If
End If
End If
Case 63 'Ret ISR Trasladado
If EsAnticipoEspecial Then Exit Select
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
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("RetISR").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2, MidpointRounding.AwayFromZero)
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{tipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
'Conta ContPAQ
If IdCtaContRetISR <> 0 Then
IdCtaContable = IdCtaContRetISR
Else
If 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
'Conta SIG
If CveCuentaRetISR <> 0 Then
CveCuenta = CveCuentaRetISR
Else
If ObjMov.GetRetCuenta(ConceptoContable, UsuarioActual.CveEmpresa) Then
If ObjMov.DtResultados.Rows.Count > 0 Then
CveCuenta = ObjMov.DtResultados.Rows(0)("IdCuentaRetISRCirculacionSIG").ToString.ToEntero
End If
End If
End If
Case 61 'Iva Trasladado
If EsAnticipoEspecial Then Exit Select
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IVA").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IVA").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("IVA").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IVA").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
CveSubProyectoContabilizar = CveSubProyecto
PorcentajeImpuesto = gvr.DataKey("PorcentajeIVA").ToDecimal
Dim IdCtaIVATrasladado As Integer = 0
Dim CveCuentaIVATrasladado As Integer = 0
If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows.Count > 0 Then
IdCtaIVATrasladado = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("IdCtaIVATrasladado").ToString.ToEntero
CveCuentaIVATrasladado = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("CveCuentaIVATrasladado").ToString.ToEntero
End If
IdCtaContable = If(IdCtaIVATrasladado > 0, IdCtaIVATrasladado, UsuarioActual.Empresa.IdCuentaIVATrasladado)
CveCuenta = If(CveCuentaIVATrasladado > 0, CveCuentaIVATrasladado, UsuarioActual.Empresa.CveCuentaIVATrasladado)
If tipoCambioPago > 1 Then ConceptoMovimiento += $" TC:{tipoCambioPago} ${ImporteMovimiento.FormatoNumero(2)}"
Case 38 'IEPS por trasladar
If EsAnticipoEspecial Then Exit Select
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IEPS").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IEPS").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("IEPS").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento * tipoCambioVenta
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IEPS").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * tipoCambioVenta
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
TipoCambioGeneral = tipoCambioVenta
CveSubProyectoContabilizar = CveSubProyecto
IdCtaContable = UsuarioActual.Empresa.IdCuentaIEPSxTrasladar
CveCuenta = UsuarioActual.Empresa.CveCuentaIEPSxTrasladar
Case 39 'IEPS Trasladado
If EsAnticipoEspecial Then Exit Select
If CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = gvr.DataKey("IEPS").ToDecimal * PorcentajePago
importeMX = ImporteMovimiento
ElseIf CveMoneda = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IEPS").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
ImporteMovimiento = (gvr.DataKey("IEPS").ToDecimal * PorcentajePago)
importeMX = ImporteMovimiento
ElseIf CveMoneda = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then
tipoCambioVenta = gvr.DataKey("TipoCambio").ToDecimal
ImporteMovimiento = (gvr.DataKey("IEPS").ToDecimal * PorcentajePago).RoundSQL
importeMX = ImporteMovimiento * If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
End If
ImporteMovimiento = ImporteMovimiento.RoundSQL
importeMX = importeMX.RoundSQL
TipoCambioGeneral = If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
CveSubProyectoContabilizar = CveSubProyecto
IdCtaContable = UsuarioActual.Empresa.IdCuentaIEPSTrasladado
CveCuenta = UsuarioActual.Empresa.CveCuentaIEPSTrasladado
Case 64 'Ganancia
If CveMoneda <> 1 OrElse gvr.DataKey("CveMoneda").ToEntero <> 1 Then
Dim CveMonedaVenta As Integer = gvr.DataKey("CveMoneda").ToEntero
Dim tImporteVenta, tImportePago As Decimal
Dim Diferencia As Decimal = 0
ImporteMovimiento = 0
tipoCambioVentaDiferenciaCambiaria = If(gvr.DataKey("Fecha").ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, gvr.DataKey("TipoCambio").ToDecimal)
If CveMonedaVenta = 1 And CveMoneda <> 1 Then
'factura pesos, pago en dolares
tImporteVenta = gvr.FCTextBox("TxtAbonar").Text.ToDecimal.RoundSQL
tImportePago = (((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioVenta / tipoCambioPago).RoundSQL * tipoCambioPago).RoundSQL
ElseIf CveMonedaVenta <> 1 And CveMoneda <> 1 Then
'factura dolares, pago en dolares
tImporteVenta = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioVentaValuacion).RoundSQL
tImportePago = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioPago).RoundSQL
ElseIf CveMonedaVenta <> 1 And CveMoneda = 1 Then
'factura dolares, pago en pesos
tImporteVenta = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioVentaValuacion).RoundSQL
tImportePago = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioPago).RoundSQL
End If
If tImporteVenta <> tImportePago Then
If tImporteVenta < tImportePago Then
ConceptoContable = 64
IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria
TipoMovimiento = True
'CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria
Else
ConceptoContable = 65
IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria
TipoMovimiento = False
' CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria
End If
Diferencia = tImporteVenta - tImportePago
End If
' si tiene funcionalidad para que tome el TC de pago, que solo afecta a los impuestos
If FuncionalidadFluctuacionImpuestos Then
Dim TCImpuestos As Decimal = tipoCambioPago
Diferencia -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
Diferencia += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetIVA
Diferencia += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
Diferencia -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IEPS
Diferencia = Math.Round(Diferencia, 2)
End If
ImporteMovimiento = Math.Abs(Diferencia)
importeMX = ImporteMovimiento
'Dim Diferencia As Decimal = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioVentaValuacion) - ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioPago) 'Añadimos la diferencia de perdida en la venta
'Diferencia -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
'Diferencia += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetIVA
'Diferencia += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
'Diferencia -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((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
CveSubProyectoContabilizar = CveSubProyecto
Else
ImporteMovimiento = 0
End If
'Case 65 'Perdida
' If CveMoneda <> 1 OrElse gvr.DataKey("CveMoneda").ToEntero <> 1 Then
' IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria
' CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria
' tipoCambioVentaDiferenciaCambiaria = If(gvr.DataKey("Fecha").ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, gvr.DataKey("TipoCambio").ToDecimal)
' Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, tipoCambioPago, tipoCambioVenta)
' Dim Diferencia As Decimal = ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioVentaValuacion) - ((gvr.FCTextBox("TxtAbonar").Text.ToDecimal) * tipoCambioPago) 'Añadimos la diferencia de perdida en la venta
' Diferencia -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
' Diferencia += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetIVA
' Diferencia += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
' Diferencia -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioVenta) - ((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
' '' 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 * tipoCambioVentaDiferenciaCambiaria) - (gvr.FCTextBox("TxtAbonar").Text.ToDecimal * tipoCambioPago) 'Añadimos la diferencia de perdida en la venta
' ' ImporteMovimiento -= ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IVA
' ' ImporteMovimiento += ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos)
' ' ImporteMovimiento += ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el RetISR
' ' ImporteMovimiento -= ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioVentaDiferenciaCambiaria) - ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * TCImpuestos) 'Añadimos la diferencia de ganancia en el IEPS
' ' ImporteMovimiento = Math.Abs(Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero))
' ' importeMX = ImporteMovimiento
' ' 'ElseIf tipoCambioPago > tipoCambioVenta AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then
' ' ' ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal - (Math.Abs(Math.Round(gvr.FCTextBox("TxtAbonar").Text.ToDecimal / tipoCambioPago, 2)) * tipoCambioPago)
' ' ' 'ImporteMovimiento -= Math.Abs(Math.Round(((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("IVA").ToDecimal * PorcentajePago) * tipoCambioVenta))) 'Añadimos la diferencia de ganancia en el IVA
' ' ' 'ImporteMovimiento += Math.Abs(Math.Round(((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) * tipoCambioVenta))) 'Añadimos la diferencia de ganancia en el RetIVA
' ' ' 'ImporteMovimiento += Math.Abs(Math.Round(((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("RetISR").ToDecimal * PorcentajePago) * tipoCambioVenta))) 'Añadimos la diferencia de ganancia en el RetISR
' ' ' 'ImporteMovimiento -= Math.Abs(Math.Round(((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * TCImpuestos) - ((gvr.DataKey("IEPS").ToDecimal * PorcentajePago) * tipoCambioVenta))) 'Añadimos la diferencia de ganancia en el IEPS
' ' ' ImporteMovimiento = ImporteMovimiento
' ' ' importeMX = ImporteMovimiento
' 'End If
' CveSubProyectoContabilizar = CveSubProyecto
' Else
' ImporteMovimiento = 0
' End If
Case 78 'Otros Ingresos
If ChkAjusteOI.Checked Then
ImporteMovimiento = gvr.FCTextBox("TxtComision").Text.ToDecimal
importeMX = Math.Round(ImporteMovimiento * tipoCambioPago, 2)
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
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 = False
ImporteMovimiento = ImporteMovimiento * -1
importeMX = importeMX * -1
Else
TipoMovimiento = True
End If
ImporteMovimiento = Math.Round(ImporteMovimiento, 2, MidpointRounding.AwayFromZero)
importeMX = Math.Round(importeMX, 2)
TipoCambioGeneral = tipoCambioPago
CveSubProyectoContabilizar = CveSubProyecto
IdCtaContable = UsuarioActual.Empresa.IdCuentaOtrosIngresos
If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
End If
'Case 92
' If RblTipoPago.SelectedValue = "3" Then ' cuando es ingreso por comprobar
' ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
' importeMX = Math.Round(ImporteMovimiento * tipoCambioPago, 2)
' CveSubProyectoContabilizar = CveSubProyecto
' If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
' 'si la factura es en dólares y trae complementaria, el importemn debe ser igual al importe
' If gvr.DataKey("CveMoneda").ToEntero <> 1 AndAlso (IdCtaContComplementaria > 0 Or UsuarioActual.CveEmpresa = 119) Then
' importeMX = ImporteMovimiento
' IdCtaContable = IdCtaContMonedaExtranjera
' Else
' IdCtaContable = IdCuentaCliente
' CveCuenta = CveCuentaCliente
' End If
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteMovimiento, Referencia, ConceptoContable, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE:=DdlIngreso.SelectedValue.ToEntero, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveCliente:=CveCliente, ImporteMX:=importeMX, CveCuenta:=CveCuenta, CveSubProyecto:=CveSubProyectoContabilizar) Then
' MsgError = "No se pudo insertar la póliza"
' End If
' If gvr.DataKey("CveMoneda").ToEntero = 2 Then
' IdCtaContable = IdCtaContComplementaria
' CveCuenta = CveCuentaComplementaria
' If ImporteMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsuarioActual.CveEmpresa = 119) Then
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, 0, TxtObservaciones.Text, 227, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE:=DdlIngreso.SelectedValue.ToEntero, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveCliente:=CveCliente, ImporteMX:=ImporteMovimiento * tipoCambioPago - ImporteMovimiento, CveCuenta:=CveCuenta, ImporteME:=ImporteMovimiento, TipoCambio:=tipoCambioPago) Then
' MsgError = "No se pudo insertar la póliza"
' End If
' importeMX = ImporteMovimiento
' IdCtaContable = IdCtaContMonedaExtranjera
' CveCuenta = CveCuentaMonedaExtranjera
' End If
' End If
' End If
' ImporteMovimiento = 0
Case 134 'Pago Intermediario
If RblTipoPago.SelectedValue = "2" Then
ImporteMovimiento = gvr.FCTextBox("TxtAbonar").Text.ToDecimal - gvr.FCTextBox("TxtComision").Text.ToDecimal
importeMX = Math.Round(ImporteMovimiento * tipoCambioPago, 2)
CveSubProyectoContabilizar = CveSubProyecto
If tipoCambioVenta > 1 Then ConceptoMovimiento += $" TC:{tipoCambioVenta} ${ImporteMovimiento.FormatoNumero(2)}"
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteMovimiento, ConceptoMovimiento, ConceptoContable, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, -1, gvr.FCHyperLink("HplF2").Text.ToEntero, -1, CveSubProyectoContabilizar, CveProveedor:=DdlProveedorPagoInt.SelectedValue.ToEntero, ImporteMX:=importeMX, CveCuenta:=CveCuenta) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
ImporteMovimiento = 0
Case 30
ImporteMovimiento = 0
Case Else
ImporteMovimiento = 0
End Select
If ImporteMovimiento <> 0 AndAlso MsgError = "" Then
'Conta ContPAQ
If (IdCtaContable < 1 Or IdCuentaBancaria < 1) Then
CuentasContablesInvalidas.Append("<br>" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString)
idCuentaContabilizacion = 0
End If
'Conta SIG
If (CveCuenta < 1 Or CveCuentaBancaria < 1) Then
CuentasContablesInvalidasSIG.Append("<br>" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString)
CveCuentaContabilizacion = 0
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, ImporteMovimiento, Referencia, ConceptoContable, ConceptoMovimiento, FechaMovimiento, IdCtaContable, -1, CveIE, gvr.FCHyperLink("HplF2").Text.ToEntero, -1, CveSubProyectoContabilizar, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=importeMX, CveCuenta:=CveCuenta, TipoCambio:=TipoCambioGeneral, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=PorcentajeImpuesto) Then
MsgError = "No se pudo insertar la póliza"
Exit For
End If
End If
Next
End If
If gvr.FCCheckBox("ChkGenerarNC").Checked AndAlso ObjFactura IsNot Nothing Then
ObjFactura.DescuentoProntoPago = gvr.DataKey("DescuentoProntoPago").ToDecimal()
ListaFacturasGenerarNC.Add(ObjFactura)
End If
End If
Next
If RblTipoPago.SelectedValue = "1" Then
If tipoCambioPago > 1 AndAlso CveMoneda = 2 Then
If IdCuentaBancariaComplementaria > 0 OrElse CveCuentaBancariaComplementaria > 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, False, TxtImporte.Text.ToDecimal, ObjIE.Folio, 30, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), TxtFechaDocumento.Text, IdCuentaBancaria, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=TxtImporte.Text.Trim.ToDecimal, CveCuenta:=CveCuentaBancaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
End If
If MsgError = "" AndAlso Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, If(CveMoneda = 1 AndAlso TxtTC.Visible, TxtImporte.Text.ToDecimal / TxtTC.Text.ToDecimal, TxtImporte.Text.ToDecimal), TxtObservaciones.Text, 204, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), TxtFechaDocumento.Text, IdCuentaBancariaComplementaria, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=If(CveMoneda = 2, (TxtImporte.Text.Trim.ToDecimal * tipoCambioPago) - TxtImporte.Text.Trim.ToDecimal, TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal, 0), CveCuenta:=CveCuentaBancariaComplementaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) 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, False, TxtImporte.Text.ToDecimal, ObjIE.Folio, 30, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), TxtFechaDocumento.Text, IdCuentaBancaria, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal * tipoCambioPago, TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 2, TxtImporte.Text.ToDecimal, 0), CveCuenta:=CveCuentaBancaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
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 = TxtTCDolaresDolares.Text.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtImporte.Text.ToDecimal, ObjIE.Folio, 30, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), TxtFechaDocumento.Text, IdCuentaBancaria, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal * tipoCambioPago, TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 2, TxtImporte.Text.ToDecimal, 0), CveCuenta:=CveCuentaBancaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
End If
If RblTipoPago.SelectedValue = "3" Then
If CveMonedaPago = 2 Then
'rmf faltan las cuentas
If IdCtaContMonedaComplementariaAnticipo > 0 Then
If CveMonedaPago = 2 AndAlso CveMonedaFiltro = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
tipoCambioPago = TxtTCDolares.Text.ToDecimal
ElseIf CveMonedaPago = 2 AndAlso CveMonedaFiltro = 2 Then
tipoCambioPago = TxtTCDolaresDolares.Text.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtImporte.Text.ToDecimal, TxtObservaciones.Text, 92, TxtObservaciones.Text + If(TxtTC.Visible, $" TC:{TxtTC.Text}", If(CveMoneda = 2, $" TC:{tipoCambioVenta}", "")), TxtFechaDocumento.Text, IdCtaContMonedaExtranjeraAnticipo, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=TxtImporte.Text.Trim.ToDecimal, CveCuenta:=CveCuentaBancaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, If(CveMoneda = 1 AndAlso TxtTC.Visible, TxtImporte.Text.ToDecimal / TxtTC.Text.ToDecimal, TxtImporte.Text.ToDecimal), TxtObservaciones.Text, 227, TxtObservaciones.Text + If(TxtTC.Visible, $" TC:{TxtTC.Text}", If(CveMoneda = 2, $" TC:{tipoCambioVenta}", "")), TxtFechaDocumento.Text, IdCtaContMonedaComplementariaAnticipo, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=If(CveMoneda = 2, (TxtImporte.Text.Trim.ToDecimal * tipoCambioPago) - TxtImporte.Text.Trim.ToDecimal, TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal, 0), CveCuenta:=CveCuentaBancariaComplementaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) 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, False, TxtImporte.Text.ToDecimal, TxtObservaciones.Text, 92, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), TxtFechaDocumento.Text, IdCtaContMonedaExtranjeraAnticipo, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal * tipoCambioPago, TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 2, TxtImporte.Text.ToDecimal, 0), CveCuenta:=CveCuentaBancaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
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 = TxtTCDolaresDolares.Text.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtImporte.Text.ToDecimal, TxtObservaciones.Text, 92, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), TxtFechaDocumento.Text, IdCtaAnticipo, -1, CveIE, -1, -1, -1, ViewState("CveCliente").ToString.ToEntero, ImporteMX:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal * tipoCambioPago, TxtImporte.Text.Trim.ToDecimal), ImporteME:=If(CveMoneda = 2, TxtImporte.Text.ToDecimal, 0), CveCuenta:=CveCuentaBancaria, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
End If
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
If MsgError = "" AndAlso ObjMov.ValidacionPrePolizaCuadre(CvePrePoliza, 3) Then
If ObjMov.ValorPolizaDescuadre > 0 Then
MsgError = ObjMov.MensajePolizaDescuadre + " La diferencia es de: " + ObjMov.ValorDiferencia
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) Then
IDPoliza = ObjMov.ContaIdPoliza
FolioPoliza = ObjMov.ContaFolio
Else
Alert("Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico")
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))
End If
End If
Else
MsgError = "No se pudo insertar la póliza"
End If
Else
MsgError = "No se insertó el encabezado"
End If
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
If MsgError = "" Then
If ListaFacturasGenerarNC.Count > 0 Then
For Each Fac As Modelos.Factura In ListaFacturasGenerarNC
Dim ListaNC As New List(Of Modelos.Factura)
ListaNC.Add(Fac)
Dim Resp As Modelos.Factura.MMensajeFactura = GenerarNC(ObjIE.IniciaTransacSQL(), ObjConta, ListaNC)
If Resp.CveVenta > 0 Then
NCGeneradas.Add(Resp)
Else
MsgError = "No se pudo generar la nota de crédito"
Exit For
End If
Next
If MsgError = "" Then
If NCGeneradas.Count <> ListaFacturasGenerarNC.Count Then
MsgError = "No se generaron las notas de crédito seleccionadas"
End If
End If
End If
End If
End If
Dim ErrorAC As Boolean = False
If MsgError = "" Then
If UsuarioActual.Empresa.UsaAC Then
Dim Fecha As Date = TxtFechaDocumento.Text.Trim.ToDate
ObjConta = New ClsContPAQi(UsuarioActual.Empresa)
ObjConta.IniciaTransacSQL()
Dim Facturas As New StringBuilder
IDPoliza = ObjConta.AddPoliza(1, String.Format("Recaudado: {0}, {1}", TxtAboneA.Text, TxtObservaciones.Text), TxtImporte.Text.ToDecimal, TxtImporte.Text.ToDecimal, UsuarioActual.CveUsuario, Fecha)
FolioPoliza = ObjConta.Folio.ToString
Dim ConceptoRenglon As String
If IDPoliza > 0 Then
Dim PorcentajePago As Double = 1
Dim Total As Double
Dim ObjVentas As New ClsVentas
Dim ImporteOP = 0.0
Dim IdCuentaOP = -1
For Each gvr As GridViewRow In GvCxC.Rows
If gvr.FCCheckBox("Chk").Checked Then
If gvr.DataKey("Original").ToDecimal > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1
If ObjVentas.GetPresupuestosVentas(gvr.DataKey("CveVenta").ToEntero) Then
For Each drt As DataRow In ObjVentas.DtResultados.Rows
Total = drt("TotalPresupuesto").ToString.ToDecimal * PorcentajePago
ConceptoRenglon = String.Format("{0} {1}", gvr.DataKey("SerieFolio"), drt("FuenteRecaudacionRubroIngreso").ToString)
If Total > 0 Then
If Not ObjConta.AddMovimiento(IDPoliza, drt("IdCuentaDevengado").ToString.ToEntero, False, Total, "", ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For : Exit For
If Not ObjConta.AddMovimiento(IDPoliza, drt("IdCuentaRecaudado").ToString.ToEntero, True, Total, "", ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For : Exit For
End If
Next
If ErrorAC Then Exit For
Facturas.AppendFormat(" {0}", gvr.DataKey("SerieFolio"))
End If
End If
Next
ObjVentas.Dispose()
'AFECTAR MATRIZ EGRESOS
ConceptoRenglon = String.Format("Recaudado: {0} - F.{1}", TxtAboneA.Text, Facturas.ToString)
If ObjConta.AddMovimiento(IDPoliza, IdCuentaBancaria, False, TxtImporte.Text.ToDecimal, "", ConceptoRenglon, 0, Fecha, "") Then
If TxtImporte.Text.ToDecimal - ImporteOP > 0 Then
If Not ObjConta.AddMovimiento(IDPoliza, ViewState("CtaCliente").ToString.ToEntero, True, TxtImporte.Text.ToDecimal - ImporteOP, "", ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True
End If
Else
ErrorAC = True
End If
Else
ErrorAC = True
End If
ErrorAC = Not ObjConta.AjustaPoliza(IDPoliza)
ErrorAC = Not ObjIE.UpdateIEPrePoliza(Fecha, FolioPoliza.ToString, IDPoliza, CvePrePoliza, CveIE, 0)
End If
End If
If ErrorAC Then
MsgError = "Error al Agregar la Póliza de Armonización Contable"
End If
'BITACORA
If MsgError = "" Then
If CveIESustitucion > 0 And ComplementoSustitucionGenerado Then
If Not ObjEvento.AddEventoBitacora($"Complemento de pago Cancelado por sustitución con Folio <a href='/Bancos/IE.aspx?CveIE={CveIE}' target='_blank' class='Texto'>{TxtFolio.Text}</a>", "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=CveIESustitucion) Then
MsgError = "Ocurrió un error al agregar la bitacora"
End If
If Not ObjEvento.AddEventoBitacora($"Complemento de pago Generado por Sustitución de <a href='/Bancos/IE.aspx?CveIE={CveIESustitucion}' target='_blank' class='Texto'>{FolioIECancelado}</a>", "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=CveIE) Then
MsgError = "Ocurrió un error al agregar la bitacora"
End If
End If
End If
Catch ex As Exception
MsgError = "Ocurrió un error al guardar el movimiento"
OnError("Ocurrió un error al guardar el movimiento", ex)
End Try
If MsgError = "" Then
ObjIE.Commit()
If ObjConta IsNot Nothing Then ObjConta.Commit()
Dim StrMsg As New StringBuilder
StrMsg.AppendFormat("Abono Registrado Correctamente. Folio <b><a href='/Bancos/IE.aspx?CveIE={0}' target='_blank' class='Texto'>{1}</a></b> <br/>", CveIE, ObjIE.Folio)
If IDPoliza > 0 Then StrMsg.AppendFormat("Poliza: <a href='/Contabilidad/RegPoliza.aspx?IdPoliza={0}' target='_blank' class='Texto'>{1}</a> <br/>", IDPoliza, FolioPoliza)
Dim TextoComplementoPago = EmitirComplementoPago(CveIE, CveVentasPago, SeriesPago)
For Each NC In NCGeneradas
StrMsg.AppendFormat("Nota de crédito generada correctamente.<br/><br/> Folio: <a href='/Ventas/Ventas.aspx?CveVenta={0}' target='_blank' class='Texto'>{1}</a><br/>", NC.CveVenta, NC.SerieFolio)
Next
Alert($"{StrMsg.ToString}<br/><br/>{TextoComplementoPago}", TipoMensaje.MsgInformacion, If(ChkSeguirRegistrando.Checked, "location.href =""#""", "location.href =""/Bancos/RepCxCCliente.aspx"""))
Else
If ObjConta IsNot Nothing Then ObjConta.RollBack()
ObjIE.RollBack()
Alert(MsgError, TipoMensaje.MsgAdvertencia)
End If
ObjIE.Dispose()
ObjVentasSaldos.Dispose()
ObjMov.Dispose()
If ObjConta IsNot Nothing Then ObjConta.Dispose()
ObjEvento.Dispose()
LimpiaCampos()
UPVentas.Update()
End Sub
#Region " N O T A - D E - C R E D I T O"
Private Function GenerarNC(SqlTransaccion As SqlClient.SqlTransaction, ObjConta As ClsContPAQi, ListaVentasGenerarNC As List(Of Modelos.Factura)) As Modelos.Factura.MMensajeFactura
Dim ObjFacturaDevolucion = New Modelos.Factura(UsuarioActual)
ObjFacturaDevolucion.TipoMensajeRespuesta = Modelos.TipoMensajeRespuesta.HTML
ObjFacturaDevolucion.CveUsuario = UsuarioActual.CveUsuario
ObjFacturaDevolucion.UsuarioCreo = UsuarioActual.Usuario
Dim CveSubProyecto As Integer = Me.CveSubProyecto
Dim CveMoneda As Integer = Me.CveMoneda
Dim CveCliente As Integer = Me.CveCliente
If CveSubProyecto <= 0 Then
CveSubProyecto = ListaVentasGenerarNC(0).CveSubProyecto
End If
If CveMoneda <= 0 Then
CveMoneda = ListaVentasGenerarNC(0).CveMoneda
End If
If CveCliente <= 0 Then
CveCliente = ListaVentasGenerarNC(0).CveCliente
End If
Dim Folio As Integer = -1
Dim Serie As String = "-1"
'Dim ObjFolios As New ClsGralFolios()
'If ObjFolios.GetFolios("Egs", UsuarioActual.CveEmpresa) Then
' Dim DT As DataTable = ObjFolios.DtResultados.FiltraParametros(String.Format(" Estado = 'Activo' AND CveSubProyecto = {0}", Me.CveSubProyecto))
' If DT.Rows.Count > 0 Then
' Serie = DT.Rows(0)("Serie").ToString()
' Folio = DT.Rows(0)("FActual").ToString()
' End If
' DT.Dispose()
'End If
'ObjFolios.Dispose()
ObjFacturaDevolucion.CveEmpresa = UsuarioActual.CveEmpresa
ObjFacturaDevolucion.TipoCambio = If(Me.CveMoneda = 1, 1, GlobalTipoCambio(Now).FormatoNumero(4).ToDecimal())
ObjFacturaDevolucion.ConvertirPesos = False
ObjFacturaDevolucion.CveMoneda = CveMoneda
ObjFacturaDevolucion.Moneda = GlobalDTMonedas.FiltroPrimeroValor("Moneda", $"CveMoneda = {CveMoneda}")
ObjFacturaDevolucion.MonedaSAT = GlobalDTMonedas.FiltroPrimeroValor("AbreviaturaSAT", $"CveMoneda = {CveMoneda}")
ObjFacturaDevolucion.Serie = Serie
ObjFacturaDevolucion.Folio = Folio
ObjFacturaDevolucion.Fecha = Now
ObjFacturaDevolucion.CvePrePoliza = -1
ObjFacturaDevolucion.CveMetodoPago = 0
ObjFacturaDevolucion.CondicionesPago = 0 ' 0 - Contado, 1 - Credito (CHECAR)
ObjFacturaDevolucion.FormaPago = 0
ObjFacturaDevolucion.TipoDocto = "Egs"
ObjFacturaDevolucion.Fecha = Now
ObjFacturaDevolucion.Version = "3.3"
ObjFacturaDevolucion.CveMetodoPago33 = 1
ObjFacturaDevolucion.MetodoPago33 = "Pago en una sola exhibición"
ObjFacturaDevolucion.ClaveMetodoPagoSAT = "PUE"
ObjFacturaDevolucion.CveFormaPago33 = 21
ObjFacturaDevolucion.FormaPago33 = "Aplicación de anticipos"
ObjFacturaDevolucion.FormaPagoSAT33 = "30"
ObjFacturaDevolucion.MetodoPago = ""
ObjFacturaDevolucion.ClaveMetodoPagoSAT = GlobalDTMetodosPago.FiltroPrimeroValor("ClaveSAT", $"CveMetodoPago = {ObjFacturaDevolucion.CveMetodoPago33}")
ObjFacturaDevolucion.CveSubProyecto = CveSubProyecto
ObjFacturaDevolucion.SetSubProyecto()
ObjFacturaDevolucion.CveCliente = CveCliente
ObjFacturaDevolucion.SetCliente()
Dim ObjCliente As New ClsClientes
If ObjCliente.GetClientes(ObjFacturaDevolucion.CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1, TipoCliente:=-1) Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
ObjFacturaDevolucion.CveUsoCFDI = ObjCliente.CveUsoCFDI
ObjFacturaDevolucion.UsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("Descripcion", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI))
ObjFacturaDevolucion.ClaveUsoCFDI = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", String.Format("CveUsoCFDI = {0}", ObjCliente.CveUsoCFDI))
ObjFacturaDevolucion.DtDetalle = CreaDTDetalleNC()
CargaImpuestos(ObjFacturaDevolucion, ListaVentasGenerarNC, ObjCliente.DesglosaIEPS, ObjCliente.RetIVA, ObjCliente.RetISR)
End If
End If
If ObjCliente.GetSucursales(CveCliente) Then
If ObjCliente.DtResultados.Rows.Count > 0 Then
ObjFacturaDevolucion.CveClienteSucursal = If(String.IsNullOrEmpty(ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "Estatus = 'Activo'")), -1, ObjCliente.DtResultados.FiltroPrimeroValor("CveClienteSucursal", "Estatus = 'Activo'").ToEntero())
Else
ObjFacturaDevolucion.CveClienteSucursal = -1
End If
End If
ObjCliente.Dispose()
ObjFacturaDevolucion.CveTipoRelacion = 7
ObjFacturaDevolucion.TipoRelacion = "07"
Dim Fol As New List(Of String)
For Each Fac In ListaVentasGenerarNC
Fol.Add(Fac.FolioFiscal)
Next
ObjFacturaDevolucion.UUIDRelacionados = Fol
Select Case ObjFacturaDevolucion.TipoDocto
Case "Ing"
ObjFacturaDevolucion.TipoDocumento = "Factura"
Case "REM"
ObjFacturaDevolucion.TipoDocumento = "Remision"
Case "Cot"
ObjFacturaDevolucion.TipoDocumento = "Cotizacion"
Case "Egs"
ObjFacturaDevolucion.TipoDocumento = "Nota de Crédito"
Case "Dev"
ObjFacturaDevolucion.TipoDocumento = "Nota de Devolución"
Case Else
ObjFacturaDevolucion.TipoDocumento = ""
End Select
ObjFacturaDevolucion.FechaPago = Now
ObjFacturaDevolucion.CveCorte = -1
ObjFacturaDevolucion.CveMesa = -1
ObjFacturaDevolucion.NumeroPersonas = 0
ObjFacturaDevolucion.CveContrato = -1
ObjFacturaDevolucion.DescripcionContrato = ""
ObjFacturaDevolucion.CveClienteSucursal = -1
ObjFacturaDevolucion.Entrega = ""
ObjFacturaDevolucion.CveAlmacen = -1
Dim DtVentasNC = InicializaDTVentasNC()
Dim TotalImporte As Decimal = ObjFacturaDevolucion.DtDetalle.SUMD("TotalImporte")
Dim ImporteIVA As Decimal = ObjFacturaDevolucion.DtDetalle.SUMD("ImporteIVA")
Dim ImporteRetIVA As Decimal = ObjFacturaDevolucion.DtDetalle.SUMD("ImporteRetIVA")
Dim ImporteRetISR As Decimal = ObjFacturaDevolucion.DtDetalle.SUMD("ImporteRetISR")
Dim ImporteIEPS As Decimal = ObjFacturaDevolucion.DtDetalle.SUMD("ImporteIEPS")
Dim Descuento As Decimal = ObjFacturaDevolucion.DtDetalle.SUMD("Descuento")
Dim Amortizacion As Decimal = 0
Dim Total As Decimal = (TotalImporte + ImporteIVA + ImporteIEPS) - (ImporteRetIVA + ImporteRetISR + Descuento + Amortizacion)
'DETALLES
ObjFacturaDevolucion.SubTotal = TotalImporte
ObjFacturaDevolucion.Descuento = Descuento
ObjFacturaDevolucion.Amortizacion = Amortizacion
ObjFacturaDevolucion.IVA = ImporteIVA
ObjFacturaDevolucion.RetIVA = ImporteRetIVA
ObjFacturaDevolucion.RetISR = ImporteRetISR
ObjFacturaDevolucion.IEPS = ImporteIEPS
ObjFacturaDevolucion.Total = Total
ObjFacturaDevolucion.TotalOtrosConceptos = 0
For Each Fac In ListaVentasGenerarNC
Dim Drt = DtVentasNC.NewRow
Drt("CveVenta") = Fac.CveVenta
Drt("Importe") = Fac.DescuentoProntoPago
Drt("FolioFiscal") = Fac.FolioFiscal
DtVentasNC.Rows.Add(Drt)
Next
DtVentasNC.AcceptChanges()
ObjFacturaDevolucion.DtVentasNC = DtVentasNC
Dim Resp = ObjFacturaDevolucion.EmitirFactura(False, Transac:=SqlTransaccion, ObjContPaqTransac:=ObjConta)
ObjFacturaDevolucion.Dispose()
Return Resp
End Function
Private Sub AgregaTempDTNC(ByRef TmpDT As DataTable, CvePS As Integer, PS As String, Codigo As String, CodigoPS As String, CveTipoPS As Integer, CveTipoInvPS As Integer, CveUM As Integer, UM As String,
CveClasificacion As Integer, Clasificacion As String, CveProyecto As Integer, CveSubProyecto As Integer,
Obs As String, Cantidad As Double, PU As Double, PorcentajeIVA As Double, ImporteIVA As Double, PorcentajeRetIVA As Double, ImporteRetIVA As Double,
PorcentajeRetISR As Double, ImporteRetISR As Double, PorcentajeIEPS As Double, ImporteIEPS As Double, TipoDescuento As Integer, Descuento As Double,
Total As Double, Serie As String, TiempoEntrega As String, CvePresupuestoIngreso As Integer, EntregaDirecta As Integer, SATClaveProdServ As String,
SATClaveUM As String, CveContratoDetalle As Integer, CveVentaDetalle As Integer, CveMovimientoDetallePedido As Integer, CveOrdenCompraDetalle As Integer,
CveVentaDetalleRemision As Integer, CveVentaDetalleCotizacion As Integer)
Dim Row As DataRow = Nothing
Row = TmpDT.NewRow()
Row("Consec") = TmpDT.Rows.Count + 1
Row("Orden") = TmpDT.Rows.Count + 1
Row("CvePS") = CvePS
Row("PS") = PS
Row("Codigo") = Codigo
Row("CodigoPS") = CodigoPS
Row("CveTipoPS") = CveTipoPS
Row("CveTipoInvPS") = CveTipoInvPS
Row("CveUM") = CveUM
Row("UM") = UM
Row("CveClasificacion") = CveClasificacion
Row("Clasificacion") = Clasificacion
Row("CveProyecto") = CveProyecto
Row("Proyecto") = ""
Row("CveSubProyecto") = CveSubProyecto
Row("SubProyecto") = ""
Row("Obs") = Obs
Row("Cantidad") = Cantidad
Row("PU") = Math.Round(PU, 6)
Row("PorcentajeIVA") = PorcentajeIVA
Row("IVA") = PorcentajeIVA
Row("ImporteIVA") = Math.Round(ImporteIVA, 2)
Row("PorcentajeRetIVA") = PorcentajeRetIVA
Row("ImporteRetIVA") = Math.Round(ImporteRetIVA, 2)
Row("PorcentajeRetISR") = PorcentajeRetISR
Row("ImporteRetISR") = Math.Round(ImporteRetISR, 2)
Row("PorcentajeIEPS") = PorcentajeIEPS
Row("ImporteIEPS") = Math.Round(ImporteIEPS, 2)
Row("IEPS") = Math.Round(ImporteIEPS, 2)
Row("TipoDescuento") = TipoDescuento
Row("Descuento") = Math.Round(Descuento, 2)
Row("Total") = Math.Round(Total, 2)
Row("TotalImporte") = Math.Round(Total, 2)
Row("Serie") = Serie
Row("TiempoEntrega") = TiempoEntrega
Row("CvePresupuestoIngreso") = CvePresupuestoIngreso
Row("EntregaDirecta") = EntregaDirecta
Row("SATClaveProdServ") = SATClaveProdServ
Row("SATClaveUM") = SATClaveUM
'Contratos
Row("CveContratoDetalle") = CveContratoDetalle
Row("CveVentaDetalle") = CveVentaDetalle
Row("CveMovimientoDetallePedido") = CveMovimientoDetallePedido
Row("CveOrdenCompraDetalle") = CveOrdenCompraDetalle
Row("CveVentaDetalleRemision") = CveVentaDetalleRemision
Row("CveVentaDetalleCotizacion") = CveVentaDetalleCotizacion
TmpDT.Rows.Add(Row)
End Sub
Private Sub CargaImpuestos(ByRef ObjFacturaDevolucion As Modelos.Factura, ListaVentasGenerarNC As List(Of Modelos.Factura), ClienteDesglosaIEPS As Boolean, ClienteRetIVA As Decimal, ClienteRetISR As Decimal)
Dim DtImpuestos As New DataTable
DtImpuestos.Columns.Add("ImportePU", GetType(Decimal))
DtImpuestos.Columns.Add("ImporteTotal", GetType(Decimal))
DtImpuestos.Columns.Add("PorcentajeIVA", GetType(Decimal))
DtImpuestos.Columns.Add("ImporteIVA", GetType(Decimal))
DtImpuestos.Columns.Add("PorcentajeRetIVA", GetType(Decimal))
DtImpuestos.Columns.Add("ImporteRetIVA", GetType(Decimal))
DtImpuestos.Columns.Add("PorcentajeRetISR", GetType(Decimal))
DtImpuestos.Columns.Add("ImporteRetISR", GetType(Decimal))
DtImpuestos.Columns.Add("PorcentajeIEPS", GetType(Decimal))
DtImpuestos.Columns.Add("ImporteIEPS", GetType(Decimal))
DtImpuestos.Columns.Add("CveSubProyecto", GetType(Integer))
DtImpuestos.AcceptChanges()
Dim AcumuladoNC As Decimal = 0
For Each Fac In ListaVentasGenerarNC
DtImpuestos.Merge(CargaDtImpuestosNC(Fac.CveVenta, Fac.DescuentoProntoPago), True, MissingSchemaAction.Ignore)
Next
DtImpuestos = CargaTotalesImpuestos(DtImpuestos)
Dim DrSubProyecto As DataRow = GlobalDTSubProyectos(-1, ObjFacturaDevolucion.CveSubProyecto).Rows(0)
Dim Cantidad As Decimal = 1
Dim CveProyecto As Integer = DrSubProyecto("CveProyecto").ToString().ToEntero()
Dim CveSubProyecto = DrSubProyecto("CveSubProyecto").ToString.ToEntero
Dim SubProyecto = DrSubProyecto("SubProyecto").ToString
Dim Proyecto = DrSubProyecto("Proyecto").ToString
Dim CveSATNC = "84111506"
Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, SATClavePS:=CveSATNC, AplicaParaVenta:=1).FiltroPrimero("")
For Each Dr As DataRow In DtImpuestos.Rows
AgregaTempDTNC(ObjFacturaDevolucion.DtDetalle, DrPS("CvePS").ToString.ToEntero, DrPS("PS").ToString, DrPS("Codigo").ToString, DrPS("PSCodigo").ToString, DrPS("CveTipoPS").ToString.ToEntero, DrPS("Inv_CveMetodoInventario").ToString.ToEntero,
DrPS("CveUM").ToString.ToEntero, DrPS("UnidadMedida").ToString, DrPS("CveClasificacion").ToString.ToEntero, DrPS("Clasificacion").ToString, CveProyecto, CveSubProyecto,
"", Cantidad, Dr("ImportePU").ToString.ToDecimal, Dr("PorcentajeIVA").ToString.ToDecimal, Dr("ImporteIVA").ToString.ToDecimal, Dr("PorcentajeRetIVA").ToString.ToDecimal, Dr("ImporteRetIVA").ToString.ToDecimal,
Dr("PorcentajeRetISR").ToString.ToDecimal, Dr("ImporteRetISR").ToString.ToDecimal, Dr("PorcentajeIEPS").ToString.ToDecimal, Dr("ImporteIEPS").ToString.ToDecimal, -1, 0.0, Dr("ImporteTotal").ToString.ToDecimal, "", "", -1, -1,
DrPS("SATClavePS").ToString, DrPS("SATClaveUnidadMedida").ToString, -1, -1, -1, -1, -1, -1)
Next
End Sub
Private Function CargaDtImpuestosNC(CveVentaNC As Integer, Importe As Decimal) As DataTable
Dim Total As Decimal = 0, SubTotal As Decimal = 0, Saldo As Decimal = 0
Dim TmpDT As DataTable = Nothing
Dim ObjVentas As New ClsVentas
If ObjVentas.GetVentaDetalle(CveVentaNC) Then
TmpDT = ObjVentas.DtResultados
TmpDT.Columns.Add("EntregaDirecta", GetType(Integer))
TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer))
End If
If ObjVentas.GetVenta(CveVentaNC, UsuarioActual.CveEmpresa) Then
If ObjVentas.DtResultados.Rows.Count > 0 Then
Total = ObjVentas.DtResultados()(0)("Total").ToString.ToDecimal
SubTotal = ObjVentas.DtResultados()(0)("SubTotal").ToString.ToDecimal
End If
End If
ObjVentas.Dispose()
Dim DtImpuestosLocal = TmpDT.FiltraParametros("", "", {"PorcentajeIVA", "PorcentajeRetIVA", "PorcentajeRetISR", "PorcentajeIEPS", "CveSubProyecto"}).Copy
DtImpuestosLocal.Columns.Add("ImportePU", GetType(Decimal))
DtImpuestosLocal.Columns.Add("ImporteTotal", GetType(Decimal))
DtImpuestosLocal.Columns.Add("ImporteIVA", GetType(Decimal))
DtImpuestosLocal.Columns.Add("ImporteRetIVA", GetType(Decimal))
DtImpuestosLocal.Columns.Add("ImporteRetISR", GetType(Decimal))
DtImpuestosLocal.Columns.Add("ImporteIEPS", GetType(Decimal))
Dim ImporteReferencia As Decimal = Total
Dim Porcentaje As Decimal = ((Importe * 100) / ImporteReferencia) / 100
Dim FiltroStr As String = ""
Dim ImporteTotalConcepto As Decimal = 0
For Each Dr As DataRow In DtImpuestosLocal.Rows
FiltroStr = String.Format("ISNULL(PorcentajeIVA,0) = {0} AND ISNULL(PorcentajeRetIVA,0) = {1} AND ISNULL(PorcentajeRetISR,0) = {2} AND ISNULL(PorcentajeIEPS,0) = {3} AND ISNULL(CveSubProyecto,0) = {4} ", Dr("PorcentajeIVA").ToString.ToDecimal, Dr("PorcentajeRetIVA").ToString.ToDecimal, Dr("PorcentajeRetISR").ToString.ToDecimal, Dr("PorcentajeIEPS").ToString.ToDecimal, Dr("CveSubProyecto"))
ImporteTotalConcepto = Porcentaje * (TmpDT.SUMD("TotalImporte", FiltroStr) - TmpDT.SUMD("Descuento", FiltroStr))
Dr("ImportePU") = ImporteTotalConcepto.RoundSQL(6)
Dr("ImporteTotal") = ImporteTotalConcepto.RoundSQL(2)
Dr("ImporteIVA") = (ImporteTotalConcepto * Dr("PorcentajeIVA").ToString().ToDecimal()).RoundSQL(2)
Dr("ImporteRetIVA") = (ImporteTotalConcepto * Dr("PorcentajeRetIVA").ToString().ToDecimal()).RoundSQL(2)
Dr("ImporteRetISR") = (ImporteTotalConcepto * Dr("PorcentajeRetISR").ToString().ToDecimal()).RoundSQL(2)
Dr("ImporteIEPS") = (ImporteTotalConcepto * Dr("PorcentajeIEPS").ToString().ToDecimal()).RoundSQL(2)
'Dr("ImporteIVA") = Math.Round(Porcentaje * TmpDT.SUM("ImporteIVA", FiltroStr), 2)
'Dr("ImporteRetIVA") = Math.Round(Porcentaje * TmpDT.SUM("ImporteRetIVA", FiltroStr), 2)
'Dr("ImporteRetISR") = Math.Round(Porcentaje * TmpDT.SUM("ImporteRetISR", FiltroStr), 2)
'Dr("ImporteIEPS") = Math.Round(Porcentaje * TmpDT.SUM("ImporteIEPS", FiltroStr), 2)
'(Dr("ImporteTotal").ToString.ToDecimal - Dr("ImporteIVA").ToString.ToDecimal - Dr("ImporteRetIVA").ToString.ToDecimal - Dr("ImporteRetISR").ToString.ToDecimal - Dr("ImporteIEPS").ToString.ToDecimal)
Next
'codigo para ajuste de centavo, si el importe total no cuadra con los totales
Dim difTmp As Decimal = Importe - (DtImpuestosLocal.SUMD("ImporteTotal") + DtImpuestosLocal.SUMD("ImporteIVA") + DtImpuestosLocal.SUMD("ImporteIEPS") - DtImpuestosLocal.SUMD("ImporteRetIVA") - DtImpuestosLocal.SUMD("ImporteRetISR"))
If Math.Abs(difTmp) >= 0.01 Then
'asusto la diferencia en el último concepto
Dim ImporteAjustado As Decimal = DtImpuestosLocal.Rows(DtImpuestosLocal.Rows.Count - 1)("ImporteTotal").ToString.ToDecimal + difTmp
DtImpuestosLocal.Rows(DtImpuestosLocal.Rows.Count - 1)("ImporteTotal") = ImporteAjustado
DtImpuestosLocal.Rows(DtImpuestosLocal.Rows.Count - 1)("ImportePU") = ImporteAjustado
End If
'CARGA FACTURA A LA CUAL SE APLICA LA NC
'CargaNCDT(CveVentaNC, Importe.ToDecimal)
Return DtImpuestosLocal
End Function
Private Function CargaTotalesImpuestos(DtImpuestos As DataTable) As DataTable
Dim query = From dr In DtImpuestos
Group By PorcentajeIVA = dr("PorcentajeIVA").ToString.ToDecimal,
PorcentajeRetIVA = dr("PorcentajeRetIVA").ToString.ToDecimal,
PorcentajeRetISR = dr("PorcentajeRetISR").ToString.ToDecimal,
PorcentajeIEPS = dr("PorcentajeIEPS").ToString.ToDecimal
Into x = Group
Select ImportePU = x.Sum(Function(s) s("ImportePU").ToString.ToDecimal),
ImporteTotal = x.Sum(Function(s) s("ImporteTotal").ToString.ToDecimal),
ImporteIVA = x.Sum(Function(s) Math.Round(s("ImporteIVA").ToString.ToDecimal, 2)), ' Math.Round(s("ImporteIVA").ToString.ToDecimal, 2)) * (1 + PorcentajeIEPS) * PorcentajeIVA,
ImporteRetIVA = x.Sum(Function(s) Math.Round(s("ImporteRetIVA").ToString.ToDecimal, 2)),' Math.Round(s("ImportePU").ToString.ToDecimal, 2)) * PorcentajeRetIVA,
ImporteRetISR = x.Sum(Function(s) Math.Round(s("ImporteRetISR").ToString.ToDecimal, 2)),' Math.Round(s("ImportePU").ToString.ToDecimal, 2)) * PorcentajeRetISR,
ImporteIEPS = x.Sum(Function(s) Math.Round(s("ImporteIEPS").ToString.ToDecimal, 2)), 'Math.Round(s("ImportePU").ToString.ToDecimal, 2)) * PorcentajeIEPS,
PorcentajeIVA = PorcentajeIVA,
PorcentajeRetIVA = PorcentajeRetIVA,
PorcentajeRetISR = PorcentajeRetISR,
PorcentajeIEPS = PorcentajeIEPS
Return query.QueryToDataTable(False)
End Function
Protected Function CreaDTDetalleNC() As DataTable
Dim TmpDT = New DataTable
TmpDT.Columns.Add("CveVenta", GetType(Integer))
TmpDT.Columns.Add("Consec", GetType(Integer))
TmpDT.Columns.Add("Cantidad", GetType(Decimal))
TmpDT.Columns.Add("Codigo", GetType(String))
TmpDT.Columns.Add("CveUM", GetType(Integer))
TmpDT.Columns.Add("UM", GetType(String))
TmpDT.Columns.Add("SATClaveUM", GetType(String))
TmpDT.Columns.Add("CveClasificacion", GetType(Integer))
TmpDT.Columns.Add("Clasificacion", GetType(String))
TmpDT.Columns.Add("CvePS", GetType(Integer))
TmpDT.Columns.Add("PS", GetType(String))
TmpDT.Columns.Add("CodigoPS", GetType(String))
TmpDT.Columns.Add("SATClaveProdServ", GetType(String))
TmpDT.Columns.Add("NoIdentificacion", GetType(String))
TmpDT.Columns.Add("CveTipoPS", GetType(Integer))
TmpDT.Columns.Add("CveTipoInvPS", GetType(Integer))
TmpDT.Columns.Add("Serie", GetType(String))
TmpDT.Columns.Add("CuentaPredial", GetType(String))
TmpDT.Columns.Add("Obs", GetType(String))
TmpDT.Columns.Add("TiempoEntrega", GetType(String))
TmpDT.Columns.Add("PU", GetType(Decimal))
TmpDT.Columns.Add("IVA", GetType(Decimal))
TmpDT.Columns.Add("ImporteIVA", GetType(Decimal))
TmpDT.Columns.Add("PorcentajeIVA", GetType(Decimal))
TmpDT.Columns.Add("ImporteRetIVA", GetType(Decimal))
TmpDT.Columns.Add("ImporteRetISR", GetType(Decimal))
TmpDT.Columns.Add("PorcentajeRetIVA", GetType(Decimal))
TmpDT.Columns.Add("PorcentajeRetISR", GetType(Decimal))
TmpDT.Columns.Add("ImporteIEPS", GetType(Decimal))
TmpDT.Columns.Add("IEPS", GetType(Decimal))
TmpDT.Columns.Add("PorcentajeIEPS", GetType(Decimal))
TmpDT.Columns.Add("Descuento", GetType(Decimal))
TmpDT.Columns.Add("TipoDescuento", GetType(Integer))
TmpDT.Columns.Add("TotalImporte", GetType(Decimal))
TmpDT.Columns.Add("Total", GetType(Decimal))
'Para uso del módulo contable
TmpDT.Columns.Add("AsientoContableVentas", GetType(Integer))
TmpDT.Columns.Add("IdCtaContVentas", GetType(Integer))
TmpDT.Columns.Add("AplicaParaConcepto", GetType(Boolean))
TmpDT.Columns.Add("CveProyecto", GetType(Integer))
TmpDT.Columns.Add("Proyecto", GetType(String))
TmpDT.Columns.Add("CveSubProyecto", GetType(Integer))
TmpDT.Columns.Add("SubProyecto", GetType(String))
TmpDT.Columns.Add("CveVentaDetallePadre", GetType(Integer))
'TipoDescuento: 1 = Descuento * PU; 2 = Descuento por Total del concepto
TmpDT.Columns.Add("CvePresupuestoIngreso", GetType(Integer))
TmpDT.Columns.Add("CveFuenteRecaudacion", GetType(Integer))
'Contratos
TmpDT.Columns.Add("CveContratoDetalle", GetType(Integer))
'Remisiones a Facturas
TmpDT.Columns.Add("CveVentaDetalle", GetType(Integer))
TmpDT.Columns.Add("CveVentaDetalleRemision", GetType(Integer))
TmpDT.Columns.Add("CveVentaDetalleCotizacion", GetType(Integer))
'Pedido2 a Facturas
TmpDT.Columns.Add("CveVentaDetallePedido2", GetType(Integer))
TmpDT.Columns.Add("Origen", GetType(Integer))
'Ordenes Servicio
TmpDT.Columns.Add("CveOS", GetType(Integer))
TmpDT.Columns.Add("CveOSDetalle", GetType(Integer))
TmpDT.Columns.Add("SeFacturara", GetType(Integer))
TmpDT.Columns.Add("Folio", GetType(Integer))
TmpDT.Columns.Add("Estatus", GetType(String))
'Ordenamiento
TmpDT.Columns.Add("Orden", GetType(Integer))
TmpDT.Columns.Add("TipoDocto", GetType(String))
'OC
TmpDT.Columns.Add("CveOrdenCompraDetalle", GetType(Integer))
TmpDT.Columns.Add("EntregaDirecta", GetType(Integer))
TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer))
TmpDT.Columns.Add("CantidadFacturadaRem", GetType(Decimal))
TmpDT.Columns.Add("CantidadFacturadaCot", GetType(Decimal))
TmpDT.Columns.Add("CantidadFacturadaPed2", GetType(Decimal))
TmpDT.Columns.Add("CantidadInventario", GetType(Decimal))
TmpDT.Columns.Add("ClaveSATFraccionArancelaria", GetType(String))
TmpDT.Columns.Add("ClaveSATUnidadAduana", GetType(String))
TmpDT.Columns.Add("ClaveSATFraccionArancelariaDescripcion", GetType(String))
TmpDT.Columns.Add("ClaveSATUnidadAduanaDescripcion", GetType(String))
TmpDT.Columns.Add("CveTamaño", GetType(Integer))
TmpDT.Columns.Add("EsCargo", GetType(Boolean))
Return TmpDT
End Function
Private Function InicializaDTVentasNC() As DataTable
Dim DtVentasNC = New DataTable
DtVentasNC.Columns.Add("CveVenta", GetType(Integer))
DtVentasNC.Columns.Add("Importe", GetType(Decimal))
DtVentasNC.Columns.Add("FolioFiscal", GetType(String))
DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "TC", .DataType = GetType(Decimal), .DefaultValue = 1})
DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "TCCambioValuacion", .DataType = GetType(Decimal), .DefaultValue = 1})
DtVentasNC.Columns.Add(New DataColumn With {.ColumnName = "CveEstatusFactura", .DataType = GetType(Integer), .DefaultValue = -1})
Return DtVentasNC
End Function
#End Region
Private Sub LimpiaCampos()
TxtFolio.Text = ""
TxtObservaciones.Text = ""
TxtImporte.Text = ""
TxtTotal.Text = ""
TxtFechaDocumento.Text = Now.ToShortDateString
DdlCuenta.SelectedValue = "-1"
DdlTipoTransaccion.SelectedValue = "-1"
CveIESustitucion = "-1"
CFDIRelacionadoSustitucion = "-1"
FechaCorteIE = DateTime.Now.ToDate
IDPoliza = -1
FolioIECancelado = ""
Anexo.Text = ""
If UsuarioActual.Empresa.UsaAC Then
TxtOtrosImportes.Text = ""
UpDatos.Update()
CargaDatos(-1)
Else
UpDatos.Update()
CargaDatos(If(Request("CveMoneda") IsNot Nothing AndAlso Request("CveMoneda").ToString.ToEntero > 0, Request("CveMoneda").ToString.ToEntero, -1))
End If
End Sub
Private Sub RblTipoPago_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RblTipoPago.SelectedIndexChanged
Select Case RblTipoPago.SelectedValue
Case "1"
DdlProveedorPagoInt.Items.Clear()
DivDatosBancarios.Visible = True
TxtFolio.Enabled = True
divAbonese.Visible = True
divIntermediario.Visible = False
PanelIngresos.Visible = False
Case "3"
' Ingresos por comprobar
DdlProveedorPagoInt.Items.Clear()
DivDatosBancarios.Visible = False
PanelIngresos.Visible = True
TxtFolio.Enabled = True
divAbonese.Visible = True
divIntermediario.Visible = False
'filtro primero por los de la moneda
CargaIngresos(CveMonedaFiltro)
If ChkPagarDolares.Checked Then
CveMonedaPago = 2
CveMoneda = 1
TxtTCDolares.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,1,{0});", 2))
Else
CveMonedaPago = 1
End If
CargaDatos(CveMoneda)
Case Else
divAbonese.Visible = False
Dim ObjProveedores As New ClsCompProveedores
ObjProveedores.GetProveedorProsepago(UsuarioActual.CveEmpresa)
divIntermediario.Visible = True
DdlProveedorPagoInt.DataSource = ObjProveedores.DtResultados
ObjProveedores.Dispose()
DdlProveedorPagoInt.DataBind()
DivDatosBancarios.Visible = False
TxtFolio.Enabled = False
PanelIngresos.Visible = False
End Select
CargaDatos(CveMoneda)
UpDatos.Update()
End Sub
Private Sub CargaIngresos(tCveMoneda As Integer)
Dim Deudores As New ClsMovimientos
If Deudores.GetIngresosSaldosDetalle(CveCliente, tCveMoneda, UsuarioActual.CveEmpresa) Then
DdlIngreso.DataSource = Deudores.DtResultados.FiltraParametros("CveCliente > 0 AND Saldo > 0 AND CveIE > 0")
End If
Deudores.Dispose()
DdlIngreso.DataBind()
DdlIngreso.Items.Insert(0, New ListItem("Seleccione", "-1"))
End Sub
Protected Sub ChkAjusteOI_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ChkAjusteOI.CheckedChanged
If ChkAjusteOI.Checked Then
TxtOtrosImportes.Visible = True
TxtTotal.Visible = True
GvCxC.Columns(13).Visible = True
Else
TxtOtrosImportes.Visible = False
TxtTotal.Visible = False
GvCxC.Columns(13).Visible = False
TxtOtrosImportes.Text = ""
TxtTotal.Text = ""
RegistraScript("$get('TxtImporte').value = FormatoNumero(SumaValores(), 2);")
End If
UpDatos.Update()
UPVentas.Update()
End Sub
#Region " PAGAR CON PESOS "
Protected Sub ChkPagarPesos_CheckedChanged(sender As Object, e As EventArgs)
If ChkPagarPesos.Checked Then
DivTCDolaresDolares.Visible = False
RegistraScript("$get('DivTC').style.display = 'block';")
CargaCuentas()
If RblTipoPago.SelectedValue = "3" Then
CargaIngresos(1)
End If
TxtTC.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
Else
DivTCDolaresDolares.Visible = True
'RegistraScript("document.getElementById('DivTC').style.display = 'none';")
CargaCuentas()
TxtTCDolaresDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
End If
UpDatos.Update()
CargaDatos(2)
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
CargaCuentas()
If RblTipoPago.SelectedValue = "3" Then
CargaIngresos(2)
RegistraScript("CambiaDolaresPesos();")
End If
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
TxtTCDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
Else
DivTCDolares.Visible = False
CargaCuentas()
TxtFechaDocumento.Attributes.Remove("onchange")
End If
UpDatos.Update()
CargaDatos(1)
RegistraScript("CambiaDolaresPesos();")
End Sub
#End Region
#Region " CUENTAS DEPOSITOS"
Private Sub CargaCuentasDepositos()
DdlCuentaDeposito.Items.Clear()
If DdlTipoTransaccion.SelectedValue > 0 Then ' transferencias y layout
trCuentaDeposito.Visible = False
Dim Dep As New ClsGenerales
If Dep.GetCuentasDepositos(CveCliente:=CveCliente) Then
If DdlTipoTransaccion.SelectedValue = "9" Then
DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros("EstatusPagoElectronico = 'True' AND Estatus ='True'")
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 Cliente no tiene ninguna cuenta deposito registrada ante el sistema BBVA BANCOMER", TipoMensaje.MsgAdvertencia)
End If
Else
DdlCuentaDeposito.DataSource = Dep.DtResultados.FiltraParametros("Estatus ='True'")
If Dep.DtResultados.Rows.Count >= 1 Then
trCuentaDeposito.Visible = True
DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione una cuenta", "-1"))
End If
End If
End If
Dep.Dispose()
DdlCuentaDeposito.DataBind()
Else
trCuentaDeposito.Visible = False
DdlCuentaDeposito.Items.Clear()
End If
UpCuentaDeposito.Update()
UpDatos.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
CargaCuentasDepositos()
End Sub
Protected Sub DdlCuentaDeposito_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim Dep As New ClsGenerales
If Dep.GetCuentasDepositos(CveCliente:=CveCliente, CveCuentaDeposito:=DdlCuentaDeposito.SelectedValue.ToEntero) AndAlso Dep.DtResultados.Rows.Count = 1 Then
If Dep.DtResultados.Rows(0)("TieneCIE").ToString.ToEntero = 1 Then
TrReferenciaCIE.Visible = True
TxtReferenciaCIE.Text = Dep.DtResultados.Rows(0)("Referencia").ToString
Else
TrReferenciaCIE.Visible = False
End If
End If
Dep.Dispose()
UpCuentaDeposito.Update()
End Sub
#End Region
#Region " COMPLEMENTOS PAGO "
Private Function EmitirComplementoPago(CveIE As Integer, CveVentas As List(Of Integer), Series As List(Of String)) As String
If Not UsuarioActual.Empresa.FacturaProduccion Then
Return ""
End If
If Not ChkComplementoPago.Checked Then
Return ""
End If
Dim Retorno As New StringBuilder
'For i = 0 To CveVentas.Count - 1
Dim ObjBancos As New ClsBancos
ObjBancos.IniciaTransacSQL()
If ObjBancos.GeneraTimbrePago(CveIE, -1, UsuarioActual, CveCliente, CFDIRelacionado:=CFDIRelacionadoSustitucion, EsRegeneracion:=If(CveIESustitucion > 0, True, False)) Then
ObjBancos.Commit()
ComplementoSustitucionGenerado = True
PDFReciboDePagos(-1, -1, ObjBancos.CveComplementoPago, False)
Dim LigaDescargaXML = $"../Empresas/{UsuarioActual.CveEmpresa}/XML/Pag/{ObjBancos.ComplementoSerieFolio}.xml"
Dim LigaDescargaPDF = $"../Empresas/{UsuarioActual.CveEmpresa}/PDF/Pag/{ObjBancos.ComplementoSerieFolio}.pdf"
Retorno.AppendFormat(" Complemento de pago <strong>{0}</strong> <br>", ObjBancos.ComplementoSerieFolio)
Retorno.AppendFormat("<a class=""texto"" style='color:#337ab7' href=""/Compras/PopUpVerFactura.aspx?P={0}"" target=""_blank"">XML &nbsp;<i class=""fa fa-file""></i></i></a>&nbsp;&nbsp;", Encripta(String.Format("OP=CompP&EXT=xml&SerieFolio={0}&CveComplementoPago={1}&CveIE={2}", ObjBancos.ComplementoSerieFolio, ObjBancos.CveComplementoPago, CveIE)))
Retorno.AppendFormat("<a class=""texto"" style='color:#337ab7' href=""/Compras/PopUpVerFactura.aspx?P={0}"" target=""_blank"">PDF &nbsp;<i class=""fa fa-ad-pdf""></i></i></i></a>&nbsp;", Encripta(String.Format("OP=CompP&EXT=pdf&SerieFolio={0}&CveComplementoPago={1}&CveIE={2}", ObjBancos.ComplementoSerieFolio, ObjBancos.CveComplementoPago, CveIE)))
Dim ResultadoMail As Integer
Dim ObjMail As New ClsSisMail()
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = $"{UsuarioActual.Empresa.Ruta}\XML\Pag\{ObjBancos.ComplementoSerieFolio}.xml"})
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = $"{UsuarioActual.Empresa.Ruta}\PDF\Pag\{ObjBancos.ComplementoSerieFolio}.pdf"})
'Dim Mail As String = "demo@adsistemas.mx"
Dim Asunto As String = "Envío de complemento de pago"
Dim Cuerpo As String = "Complemento de Pago"
If ObjMail.SendMail(UsuarioActual.Empresa, Mail, Asunto, Cuerpo, "", LSRutasMail) Then
ResultadoMail = 1
Else
ResultadoMail = 3
Alert("No se pudo enviar el correo", TipoMensaje.MsgAdvertencia)
End If
Else
ComplementoSustitucionGenerado = False
Retorno.AppendFormat($" Complemento de pago <b>NO</b> generado . {ObjBancos.Mensaje}")
ObjBancos.RollBack()
End If
ObjBancos.Dispose()
' Next
Return Retorno.ToString
End Function
#End Region
#Region "SALDAR CUENTAS"
Private Sub BtnSaldarCuentasIncobrables_Click(sender As Object, e As EventArgs) Handles BtnSaldarCuentasIncobrables.Click
Dim ObjConta As New ClsContabilidad
ObjConta.IniciaTransacSQL()
Dim CvePrePoliza As Integer = 0
Dim MsgError As String = ""
Dim ObjIE As New ClsBancos
Dim FechaUltimaFluctuacion As Date = MinFecha
Dim TipoCambioFluctuacion As Decimal = 1
If ObjIE.GetFluctuacionesBitacora(UsuarioActual.CveEmpresa) Then
If ObjIE.DtResultados.Rows.Count > 0 Then
Dim tFecha As Date = TxtFechaIncobrable.Text.ToDate
Dim Fecha As String = String.Format("{0}/{1}/{2}", tFecha.Year, tFecha.Month, tFecha.Day)
Dim drr As DataRow = ObjIE.DtResultados.FiltroPrimero("Fecha < #" & Fecha & "#", "Fecha DESC")
If drr IsNot Nothing Then
FechaUltimaFluctuacion = drr("Fecha").ToString.ToDate
TipoCambioFluctuacion = drr("TipoCambio").ToString.ToDecimal
End If
End If
End If
ObjIE.Dispose()
CvePrePoliza = ObjConta.AddPrePolizas("Bancos/ClientesAbonar/SaldarI", 47, 0, 0, 1, TxtFechaIncobrable.Text.ToDate, TxtObsSaldarIncobrable.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
For Each gr As GridViewRow In GvCxC.Rows
If gr.FCCheckBox("Chk").Checked Then
Dim IdCtaContable As Integer = IdCuentaCliente
Dim CveCuenta As Integer = 0
Dim PorcentajePago As Decimal = gr.DataKey("Saldo").ToDecimal / gr.DataKey("Original").ToDecimal
Dim Saldo As Decimal = gr.DataKey("Saldo").ToDecimal
Dim SubTotal As Decimal = PorcentajePago * gr.DataKey("SubTotal").ToDecimal.RoundSQL
Dim IVA As Decimal = PorcentajePago * gr.DataKey("IVA").ToDecimal.RoundSQL
Dim IEPS As Decimal = PorcentajePago * gr.DataKey("IEPS").ToDecimal.RoundSQL
Dim TCVenta As Decimal = gr.DataKey("TipoCambio").ToDecimal
Dim FechaVenta As Date = gr.DataKey("Fecha").ToDate
Dim tCveMoneda As Integer = gr.DataKey("CveMoneda").ToEntero
Dim TCPago As Decimal = GlobalTipoCambio(TxtFechaIncobrable.Text.ToDate).FormatoNumero(4)
Dim CveConceptoDeduccion As Integer = DdlTipoDeduccion.SelectedValue.ToEntero
'si la fecha del documento es anterior a su ultima fluctuación. toma el Tc de la fluctuacion
If tCveMoneda = 2 Then
If FechaVenta < FechaUltimaFluctuacion Then
TCVenta = TipoCambioFluctuacion
End If
End If
'condicionante
Dim ClienteMovto As Boolean = True
Dim SubtotalMovto As Boolean = False
Dim CveConceptoCliente As Integer = 2
Dim ImpuestosMovto As Boolean = False
Dim IdCuentaContableNoDeducible As Integer = 0
Dim CveSubProyecto As Integer = gr.DataKey("CveSubProyecto").ToEntero
Dim ConceptoPartida As String = TxtObsSaldarIncobrable.Text.Trim & " " & gr.DataKey("SerieFolio").ToString
If CveConceptoDeduccion = 255 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(266).ToEntero
If CveConceptoDeduccion = 211 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(559).ToEntero
If CveConceptoDeduccion = 263 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(537).ToEntero
If CveConceptoDeduccion = 252 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.Funcionalidad(581).ToEntero
If CveConceptoDeduccion = 78 Then IdCuentaContableNoDeducible = UsuarioActual.Empresa.IdCuentaOtrosIngresos
If UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 122) Then
ClienteMovto = False : Saldo = Saldo * -1
ImpuestosMovto = True : IVA = IVA * -1
CveConceptoCliente = 1
'falta cuenta incobrable
IdCuentaContableNoDeducible = 3114
End If
Dim UsaComplementaria As Boolean = False
If UsuarioActual.CveEmpresa = 119 Then
UsaComplementaria = True
End If
If MsgError = "" Then
If tCveMoneda = 2 Then
IdCtaContable = IdCtaContMonedaExtranjera
Else
IdCtaContable = IdCuentaCliente
End If
If UsaComplementaria AndAlso tCveMoneda = 2 Then
'normal
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, Saldo, gr.DataKey("SerieFolio").ToString, CveConceptoCliente, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=If(CveMonedaFiltro = 1, Saldo, Saldo), CveCuenta:=CveCuenta, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
'complementaria
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, 0, gr.DataKey("SerieFolio").ToString, 207, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=IdCtaContComplementaria, CveIE:=-1, IdSegmentoNegocio:=-1, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=If(CveMonedaFiltro = 1, Saldo, (Saldo * TCVenta) - Saldo), ImporteME:=Saldo, CveCuenta:=CveCuenta, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
Else
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ClienteMovto, Saldo, gr.DataKey("SerieFolio").ToString, CveConceptoCliente, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable:=IdCtaContable, CveIE:=-1, IdSegmentoNegocio:=-1, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=If(CveMonedaFiltro = 1, Saldo, Saldo * TCVenta), CveCuenta:=CveCuenta, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
'fluctuación.
If tCveMoneda = 2 Then
Dim ImporteFluctuacion As Decimal = 0
ImporteFluctuacion = Saldo * (TCPago - TCVenta)
If TCPago > TCVenta 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, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=Math.Abs(ImporteFluctuacion), CveCuenta:=CveCuenta, TipoCambio:=TCVenta, 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, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=Math.Abs(ImporteFluctuacion), CveCuenta:=CveCuenta, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
End If
'cuando hay pago en dólares, se ajusta el concepto de subtotal,
SubTotal = (Saldo * TCVenta) + ImporteFluctuacion - (IVA * TCVenta) - (IEPS * TCVenta)
End If
' iva
Dim PorcentajeImpuesto As Decimal = gr.DataKey("PorcentajeIVA").ToDecimal
Dim IdCtaIVAXTrasladar As Integer = 0
Dim CveCuentaIVAxTrasladar As Integer = 0
If GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows.Count > 0 Then
IdCtaIVAXTrasladar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("IdCtaIVAXTrasladar").ToString.ToEntero
CveCuentaIVAxTrasladar = GlobalDTClasificacionPorcentaje(UsuarioActual.CveEmpresa, PorcentajeIVA:=PorcentajeImpuesto).Rows(0)("CveCuentaIVAxTrasladar").ToString.ToEntero
End If
IdCtaContable = If(IdCtaIVAXTrasladar > 0, IdCtaIVAXTrasladar, UsuarioActual.Empresa.IdCuentaIVAxTrasladar)
CveCuenta = If(CveCuentaIVAxTrasladar > 0, CveCuentaIVAxTrasladar, UsuarioActual.Empresa.CveCuentaIVAxTrasladar)
If IVA > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ImpuestosMovto, IVA, gr.DataKey("SerieFolio").ToString, 13, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable, -1, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=If(CveMonedaFiltro = 1, IVA, IVA * TCVenta), CveCuenta:=CveCuenta, PorcentajeImpuesto:=PorcentajeImpuesto, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
IdCtaContable = UsuarioActual.Empresa.IdCuentaIEPSxTrasladar
CveCuenta = UsuarioActual.Empresa.CveCuentaIEPSxTrasladar
If IEPS > 0 AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, ImpuestosMovto, IEPS, gr.DataKey("SerieFolio").ToString, 38, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCtaContable, -1, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=If(CveMonedaFiltro = 1, IEPS, IEPS * TCVenta), CveCuenta:=CveCuenta, PorcentajeImpuesto:=PorcentajeImpuesto, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
'al gasto,Subtotal
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, SubtotalMovto, SubTotal, gr.DataKey("SerieFolio").ToString, CveConceptoDeduccion, ConceptoPartida, TxtFechaIncobrable.Text.ToDate, IdCuentaContableNoDeducible, -1, CveCliente:=gr.DataKey("CveCliente").ToEntero, CveVenta:=gr.DataKey("CveVenta").ToEntero, ImporteMX:=SubTotal, CveSubProyecto:=CveSubProyecto, CveCuenta:=-1, TipoCambio:=TCVenta, TipoCambioPago:=TCPago) Then
MsgError = "Ocurrio un error al saldar el movimiento"
End If
If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 5) Then
If ObjConta.ValorPolizaDescuadre > 0 Then
MsgError = ObjConta.MensajePolizaDescuadre + " " + ObjConta.ValorDiferencia
GuardaLogAD($"Ventas/ClientesAbonar | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas")
Exit For
End If
End If
End If
End If
Next
If MsgError = "" Then
'ObjConta.RollBack()
ObjConta.Commit()
CargaDatos(CveMonedaFiltro)
RegistraScript("$('#ModalSaldarCuentaIncobrable').modal('hide')")
Alert(String.Format("Los movimientos se saldaron correctamente. <br/> <a href='/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={0}'>Ver PrePóliza</a>", CvePrePoliza), TipoMensaje.MsgInformacion)
Else
ObjConta.RollBack()
Alert(MsgError, TipoMensaje.MsgError)
End If
BtnSaldarCuentasIncobrables.Visible = False
ObjConta.Dispose()
End Sub
Private Sub ValidaCuentaDePagoFormaDePago()
If Not (DdlTipoTransaccion.SelectedValue.ToEntero > 0 And DdlCuenta.SelectedValue.ToEntero > 0) Then
Exit Sub
End If
Dim DTTipoTransacciones As DataTable = GlobalDTTipoTransacciones.FiltraParametros($"CveTipoTransaccion={DdlTipoTransaccion.SelectedValue}")
Dim DTCuentas As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros($"CveCuenta={DdlCuenta.SelectedValue}")
Dim ClaveFormaPagoSAT As String = ""
Dim Cuentapago As String = ""
Dim CuentaBeneficiario As String = ""
If DTTipoTransacciones.Rows.Count > 0 Then
ClaveFormaPagoSAT = DTTipoTransacciones.Rows(0)("ClaveFormaPagoSAT").ToString
Else
Alert("La forma de pago no tiene una forma de pago SAT", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If DTCuentas.Rows.Count > 0 Then
CuentaBeneficiario = DTCuentas.Rows(0)("NumCuenta").ToString
Else
Alert("No se pudo encontrar la cuenta", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim Mensaje As String = ""
Cuentapago = ""
Select Case ClaveFormaPagoSAT.ToString
Case "01"
' no tiene restricciones
Case "02"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(11, 18) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
End If
Case "03"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(10, 16, 18) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 18)) Then
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
End If
Case "04"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(16) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
End If
Case "05"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(10, 11, 15, 16, 18, 50) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
End If
Case "06"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(10) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
CuentaBeneficiario = ""
Case "28"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(16) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
End If
Case "29"
If Cuentapago <> "" AndAlso Not Cuentapago.Length.Contiene(15, 16) Then
Mensaje = "La cuenta ordenante no cumple con el formato esperado."
End If
If CuentaBeneficiario <> "" AndAlso Not (CuentaBeneficiario.Length.Contiene(10, 11, 15, 16, 18, 50)) Then
Mensaje = $"{Mensaje} La Cuenta Beneficiario no cumple con el formato esperado."
End If
Case Else
End Select
LblValidaCeuntaTipoTransaccion.Text = Mensaje
If Not Mensaje.Length = 0 Then
'Alert(Mensaje, TipoMensaje.MsgAdvertencia)
LblValidaCeuntaTipoTransaccion.Visible = True
Else
LblValidaCeuntaTipoTransaccion.Visible = False
End If
UpGuardar.Update()
End Sub
#End Region
#Region "COMPLEMENTO DE PAGO - ELIMINAR POR SUSTITUCION"
Protected Sub CargaIESustituir()
Dim ObjIE As New ClsBancos()
If ObjIE.GetBancosIE(CveIESustitucion, UsuarioActual.CveEmpresa) Then
If ObjIE.DtResultados.Rows.Count > 0 Then
FechaCorteIE = ObjIE.FechaDocumento
CveMoneda = ObjIE.CveMoneda
CveMonedaFiltro = CveMoneda
IDPoliza = ObjIE.IDPoliza
FolioIECancelado = ObjIE.Folio
End If
End If
ObjIE.Dispose()
UpDatos.Update()
End Sub
Function CancelarIE() As Boolean
Dim ErrorCancelar = False
If Not IsDate(TxtFechaDocumento.Text.ToDate) Then
Alert("El campo fecha cancelación es incorrecto. Por favor verifique y vuelva a intentar")
Return True
End If
Dim Banc As New ClsBancos
Banc.IniciaTransacSQL()
Dim ObjAC As ClsContPAQi = Nothing
If UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.UsaContabilidad Then
ObjAC = New ClsContPAQi(UsuarioActual.Empresa)
ObjAC.IniciaTransacSQL()
End If
Dim IdPolizaNueva = -1
Dim FolioPolizaNueva = -1
Try
'CANCELA IE CONTABILIZADO
If IDPoliza > 0 Then
If ObjAC Is Nothing Then
ErrorCancelar = True
End If
If Not ErrorCancelar Then
Dim dt As DataTable
If ObjAC.GetPoliza(IDPoliza, -1, -1, -1, -1) AndAlso ObjAC.DtResultados.Rows.Count > 0 Then
dt = ObjAC.DtResultados
' MES ANTERIOR, MOVIMIENTOS CONTRARIOS (NEGATIVOS)
If dt.Rows(0)("FechaPol").ToString.ToDate.Month < TxtFechaDocumento.Text.ToDate.Month Or dt.Rows(0)("FechaPol").ToString.ToDate.Year < TxtFechaDocumento.Text.ToDate.Year Then
IdPolizaNueva = ObjAC.AddPoliza(3, String.Format("Cancelacion: {0}", dt.Rows(0)("Concepto").ToString), 0, 0, UsuarioActual.CveUsuario, TxtFechaDocumento.Text.ToDate)
If IdPolizaNueva > 0 Then
FolioPolizaNueva = ObjAC.Folio
'CREA POLIZA NEGATIVA
For Each dr As DataRow In dt.Rows
If Not ObjAC.AddMovimiento(IdPolizaNueva, dr("IdCuenta").ToString.ToEntero, dr("TipoMovto").ToString = "True", dr("Importe").ToString.ToDecimal * -1, dr("Referencia").ToString, String.Format("Cancelacion: {0}", dt.Rows(0)("Concepto").ToString), dr("IdSegNeg").ToString.ToEntero, TxtFechaDocumento.Text.ToDate, "") Then
ErrorCancelar = True : Exit For
End If
Next
'AJUSTA POLIZA
If Not ErrorCancelar Then
If Not ObjAC.AjustaPoliza(IdPolizaNueva) Then
ErrorCancelar = True
End If
End If
'CANCELA IE
If Not ErrorCancelar Then
If Not Banc.CancelarBancos_IE(UsuarioActual.CveUsuario, CveIESustitucion, True, IdPolizaNueva, FolioPolizaNueva, TxtFechaDocumento.Text.ToDate) Then
ErrorCancelar = True
End If
End If
Else
ErrorCancelar = True
End If
Else
'LIMPIA POLIZA PONIENDO IMPORTE EN CEROS
For Each dr As DataRow In dt.Rows
If Not ObjAC.UpdateMovimiento(dr("Id").ToString.ToEntero, dr("IdCuenta").ToString.ToEntero, dr("TipoMovto").ToString = "1", 0, dr("Referencia").ToString, dr("Concepto").ToString, dr("IdSegNeg").ToString.ToEntero, dr("Fecha").ToString.ToDate) Then
ErrorCancelar = True : Exit For
End If
Next
'AJUSTA POLIZA
If Not ErrorCancelar Then
If Not ObjAC.AjustaPoliza(IDPoliza) Then
ErrorCancelar = True
End If
End If
'CANCELA IE
If Not ErrorCancelar Then
If Not Banc.CancelarBancos_IE(UsuarioActual.CveUsuario, CveIESustitucion, False, IdPolizaNueva, FolioPolizaNueva, TxtFechaDocumento.Text.ToDate) Then
ErrorCancelar = True
End If
End If
End If
End If
End If
Else
If FechaCorteIE.Month < TxtFechaDocumento.Text.ToDate.Month Or FechaCorteIE.Year < TxtFechaDocumento.Text.ToDate.Year Then
'CANCELA IE MES ANTERIOR
If Not Banc.CancelarBancos_IE(UsuarioActual.CveUsuario, CveIESustitucion, True, IdPolizaNueva, FolioPolizaNueva, TxtFechaDocumento.Text.ToDate) Then
ErrorCancelar = True
End If
Else
'CANCELA IE MES ACTUAL
If Not Banc.CancelarBancos_IE(UsuarioActual.CveUsuario, CveIESustitucion, False, IdPolizaNueva, FolioPolizaNueva, TxtFechaDocumento.Text.ToDate) Then
ErrorCancelar = True
End If
End If
End If
If Not ErrorCancelar Then
If Banc.GetComplementoPagos(-1, CveIESustitucion, -1, UsuarioActual.CveEmpresa) Then
Dim CveComplementoPago As Integer = -1
If Banc.DtResultados.Rows.Count > 0 Then
'OBTENEMOS EL UUID DEL COMPLEMENTO A CANCELAR POR SUSTITUCION
CFDIRelacionadoSustitucion = Banc.DtResultados.Rows(0)("FolioFiscal")
CveComplementoPago = Banc.DtResultados(0)("CveComplementoPago").ToString().ToEntero
End If
'ACTUALIZA FOLIOS CANCELADOS
If Banc.DtResultados.FiltraParametros("", DistinctColumns:={"CveComplementoPago", "SerieFolio", "Fecha", "CveIE"}).Rows.Count > 0 Then
If Not Banc.GetFoliosCancelados(UsuarioActual.CveEmpresa) Then
ErrorCancelar = True
Else
Dim FolioCancelado = $"{FolioIECancelado}_C_{Banc.DtResultados(0)("Cantidad").ToString().ToEntero + 1}"
If Not Banc.UpdateFolioCancelado(CveIESustitucion.ToEntero, Folio:=FolioCancelado) Then
ErrorCancelar = True
End If
End If
End If
'ACTUALIZA ESTATUS DE COMPLEMENTO DE PAGO A CANCELADO = 2
If Not ErrorCancelar And CveComplementoPago > 0 Then
If Not Banc.UpdateComplementoPagoCancelado(CveComplementoPago, 2, UsuarioActual.Empresa.CvePAC, UsuarioActual.CveEmpresa, DateTime.Now) Then
ErrorCancelar = True
End If
End If
End If
End If
Catch ex As Exception
ErrorCancelar = True
OnError("Ocurrió un error al cancelar el IE", ex)
End Try
If Not ErrorCancelar Then
Banc.Commit()
If ObjAC IsNot Nothing Then ObjAC.Commit()
Dim Msg As New StringBuilder
Msg.Append("El movimiento bancario quedó cancelado exitosamente.")
If IdPolizaNueva > 0 Then Msg.AppendFormat("<br/><br/><a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Ver Póliza de cancelación</a>", IdPolizaNueva)
Alert(Msg.ToString, TipoMensaje.MsgInformacion)
Else
Banc.RollBack()
If ObjAC IsNot Nothing Then ObjAC.RollBack()
Alert("El movimiento bancario no se pudo cancelar. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
If ObjAC IsNot Nothing Then ObjAC.Dispose()
Banc.Dispose()
Return ErrorCancelar
End Function
Private Sub BtnVincularIntermediario_Click(sender As Object, e As EventArgs) Handles BtnVincularIntermediario.Click
RegistraScript("$('#ModalVincularIntermediario').modal('hide')", "hidemodal")
End Sub
#End Region
Protected Sub BtnCambiaTipoMoneda_Click(sender As Object, e As EventArgs)
CambiaTipoMoneda()
End Sub
Private Sub CambiaTipoMoneda()
Dim dia As Integer = If(UsuarioActual.CveEmpresa = 13, TxtFechaDocumento.Text.ToDate.Day - 1, TxtFechaDocumento.Text.ToDate.Day)
Fecha = (dia.ToString + "/" + TxtFechaDocumento.Text.ToDate.Month.ToString + "/" + TxtFechaDocumento.Text.ToDate.Year.ToString).ToDate
If TxtTC.Visible Then
TxtTC.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
End If
If DivTCDolares.Visible Then
TxtTCDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
End If
If DivTCDolaresDolares.Visible Then
TxtTCDolaresDolares.Text = GlobalTipoCambio(Fecha).FormatoNumero(4)
End If
Dim moneda As Integer = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero}").ToEntero
If CveMonedaFiltro = -1 Then
RegistraScript(String.Format("FnCambia(0,0,0,0,-1,{0});", moneda))
Else
RegistraScript(String.Format("FnCambia(0,0,0,0,1,{0});", moneda))
End If
UpDatos.Update()
End Sub
Private Sub DdlIngreso_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlIngreso.SelectedIndexChanged
'saco la moneda de la selección
If DdlIngreso.SelectedValue.ToEntero > 0 Then
Dim Banco As New ClsBancos
If Banco.GetBancosIE(DdlIngreso.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
CveMonedaPago = Banco.CveMoneda
End If
IdCuentaBancariaComplementaria = 0
CveCuentaBancariaComplementaria = 0
Banco.Dispose()
Else
CveMonedaPago = -1
End If
If CveMonedaPago = 1 Then
'DivTC.Visible = True
DivTCDolares.Visible = False
TxtTC.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,-1,{0});", CveMonedaPago))
ElseIf CveMonedaPago = 2 Then
'DivTC.Visible = False
RegistraScript("document.getElementById('DivTC').style.display = 'none';")
DivTCDolares.Visible = True
TxtTCDolares.Attributes.Add("onkeyup", String.Format("FnCambia(0,0,0,0,-1,{0});", CveMonedaPago))
End If
CargaDatos(CveMoneda)
End Sub
End Class