'Option Explicit On
'Option Strict On
Imports System.Data
Imports ADSTimbrado
Imports Extensiones
Imports Org.BouncyCastle.Ocsp
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 IfNull(ViewState("CveMonedaFiltro"), "0").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMonedaFiltro") = value
End Set
End Property
Private Property FechaIngreso As Date
Get
Return ViewState("FechaIngreso").ToString.ToDate
End Get
Set(value As Date)
ViewState("FechaIngreso") = 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 DtIngresos As DataTable
Get
Return CType(ViewState("DtIngresos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtIngresos") = value
End Set
End Property
Private Property DtPrestamos As DataTable
Get
Return CType(ViewState("DtPrestamos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtPrestamos") = 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 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 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
DdlProveedorIntermediario.setEsWebService(True)
DdlProveedorIntermediario.Attributes.Add("data-metodo", "getproveedores")
DdlProveedorIntermediario.SelectedText = "Seleccione"
DdlProveedorIntermediario.SelectedValue = "-1"
FechaCorteIE = NowADS()
Dim dia As Integer = If(UsuarioActual.CveEmpresa = 13, NowADS().Day - 1, NowADS().Day)
Fecha = (dia.ToString + "/" + NowADS().Month.ToString + "/" + NowADS().Year.ToString).ToDate
'If UsuarioActual.Empresa.Funcionalidad(712) = "1" Then
' PorletIntermediario.Visible = True
'End If
If CargaCliente(CveCliente, CveMonedaFiltro) Then
TxtOtrosImportes.Attributes.Add("onKeyUp", String.Format("FnSuma(this,{0},{1},-1);", "TxtTotal", 0))
'TxtAnticipo.Attributes.Add("onKeyUp", String.Format("FnSuma(this,{0},{1},-1);", "null", 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 = NowADS().ToString("dd/MM/yyyy")
If UsuarioActual.CveEmpresa.Contiene(13, 83, 158) Then
LnkAccionesModalSeleccionLayout.Visible = True
End If
If UsuarioActual.CveEmpresa.Contiene(13, 1, 15) Then
DVImporteDeduccionesPago.Visible = True
End If
If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then
If Not UsuarioActual.TienePermisoProceso(404) Then
TxtFechaDocumento.Enabled = False
ImgCalendario.Visible = False
End If
End If
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
Dim CveTipoCuenta As Integer = -1
If UsuarioActual.CveEmpresa = 119 Then CveTipoCuenta = 2 'solo las cuentas de cheques
If UsuarioActual.CveEmpresa.Contiene(7, 11, 12, 122, 145) Then
dt = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa, CveTipoCuenta:=-1).FiltraParametros(" CveTipoCuenta in (1,2) ")
Else
dt = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa, CveTipoCuenta:=CveTipoCuenta)
End If
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 = NowADS().ToShortDateString.ToString
TxtAboneA.Enabled = False
LbEncabezado.Text = String.Format("{1}", 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
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"
If UsuarioActual.Empresa.Funcionalidad(590) = "1" Then
'Dim CveClasificacionCol1 As Integer = 21514
'Dim CveClasificacionCol2 As Integer = 21916
'Dim CveClasificacionCol3 As Integer = 21520
'Dim CveClasificacionCol4 As Integer = 21519
'Dim CveClasificacionCol5 As Integer = 21547
'Dim CveClasificacionCol6 As Integer = 21572
'Dim CveClasificacionCol7 As Integer = 21571
divAnticipo.Visible = True
divPrestamo.Visible = True
GvCxC.Columns(17).HeaderText = "Comisión
Venta" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol1).FiltroPrimeroValor("Clasificacion").Substring(0, 10)
GvCxC.Columns(18).HeaderText = "Gastos
Manejo" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol2).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(19).HeaderText = "Servicio
Inspección" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol3).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(20).HeaderText = "Seguro" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol4).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(21).HeaderText = "Aduana
Mex" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol5).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(22).HeaderText = "Diversos" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol6).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(23).HeaderText = "Aduana
USA" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol7).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(24).HeaderText = "Material
Empaque" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol7).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(25).HeaderText = "Semilla" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol7).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(26).HeaderText = "Fletes" 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacionCol7).FiltroPrimeroValor("Clasificacion").Substring(0, 12)
GvCxC.Columns(27).HeaderText = "Total
Gastos"
DvLiquidacion1.Visible = True
DvLiquidacion2.Visible = True
DtIngresos = CargaIngresos(2)
DtPrestamos = CargaPrestamos(1)
End If
If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then 'GDIaz
divAnticipo.Visible = True
TxtAnticipo.Attributes.Add("onKeyUp", "FnRecalcula(0,1);")
DivAntSubProyecto.Visible = True
DivAntSubProyectoTexto.visible = True
CargarCentrosDeCosto(Nothing, DdlSubProyectos, Nothing, Nothing, AplicaTodos:="")
End If
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").ToString
Dim FechaF As String = IfNull(Request("FechaF"), "-1").ToString
Dim FechaCorte As Date = NowADS().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) 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")
CveMoneda = pCveMoneda
End If
Mov.Dispose()
GvCxC.DataBind()
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
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.ToEntero > 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
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
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.BackColor = Drawing.Color.LightGray
e.Row.FCDropDownList("DdlTG").Visible = False
e.Row.FCTextBox("TxtLiqCol1").Visible = False
e.Row.FCTextBox("TxtLiqCol2").Visible = False
e.Row.FCTextBox("TxtLiqCol3").Visible = False
e.Row.FCTextBox("TxtLiqCol4").Visible = False
e.Row.FCTextBox("TxtLiqCol5").Visible = False
e.Row.FCTextBox("TxtLiqCol6").Visible = False
e.Row.FCTextBox("TxtLiqCol7").Visible = False
e.Row.FCTextBox("TxtLiqCol8").Visible = False
e.Row.FCTextBox("TxtLiqCol9").Visible = False
e.Row.FCTextBox("TxtLiqCol10").Visible = False
e.Row.FCTextBox("TxtLiqColT").Visible = False
e.Row.FCTextBox("TxtAmort").Visible = False
e.Row.FCTextBox("TxtAmort2").Visible = False
e.Row.FCDropDownList("DdlAnti").Visible = False
e.Row.FCDropDownList("DdlAnti2").Visible = False
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)
End If
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.ToEntero > 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},{5}); 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, e.Row.DBCampo("CveVenta")))
Else
e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1},{5}); FnCambia({2},this,{1},0,{3},{4},{5});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo"), e.Row.FCCheckBox("Chk").ClientID, CveMonedaFiltro, moneda, e.Row.DBCampo("CveVenta")))
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("Ir", 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).ToDecimal).ToString, UsuarioActual.Empresa.Funcionalidad(157).ToString.ToDecimal))
e.Row.FCRangeValidator("RVComision").MinimumValue = (-UsuarioActual.Empresa.Funcionalidad(157).ToDecimal).ToString
e.Row.FCRangeValidator("RVComision").MaximumValue = UsuarioActual.Empresa.Funcionalidad(157).ToString
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() <= 5 Then
e.Row.FCCheckBox("ChkGenerarNC").Visible = True
e.Row.FCCheckBox("ChkGenerarNC").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1},{5}); 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, e.Row.DBCampo("CveVenta")))
End If
If UsuarioActual.Empresa.Funcionalidad(590) = "1" Then '' si es empresa agrícola
e.Row.FCDropDownList("DdlTG").DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa)
e.Row.FCDropDownList("DdlTG").DataBind()
e.Row.FCTextBox("TxtLiqCol1").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol2").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol3").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol4").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol5").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol6").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol7").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol8").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol9").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqCol10").Attributes.Add("class", $"ClsSelLiq ClsSelLiqVenta{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtLiqColT").Attributes.Add("class", $"ClsSelLiqVentaTotal{e.Row.DBCampo("CveVenta")}")
e.Row.FCTextBox("TxtAmort").Attributes.Add("class", $"ClsSelLiqAnt")
e.Row.FCTextBox("TxtAmort2").Attributes.Add("class", $"ClsSelLiqAnt")
e.Row.FCTextBox("TxtLiqCol1").Attributes.Add("onkeyup", $"SumaLiq (this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol2").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol3").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol4").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol5").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol6").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol7").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol8").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol9").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtLiqCol10").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtAmort").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCTextBox("TxtAmort2").Attributes.Add("onkeyup", $"SumaLiq(this,{e.Row.DBCampo("CveVenta")},{CveMonedaFiltro},{ moneda})")
e.Row.FCDropDownList("DdlAnti").DataSource = DtIngresos
e.Row.FCDropDownList("DdlAnti").DataBind()
e.Row.FCDropDownList("DdlAnti").Items.Insert(0, New ListItem("-", "-1"))
e.Row.FCDropDownList("DdlAnti2").DataSource = DtIngresos
e.Row.FCDropDownList("DdlAnti2").DataBind()
e.Row.FCDropDownList("DdlAnti2").Items.Insert(0, New ListItem("-", "-1"))
End If
Else
e.Row.FCTextBox("TxtAbonar").Visible = False
e.Row.FCTextBox("TxtComision").Visible = False
e.Row.FCCheckBox("Chk").Visible = False
End If
If e.Row.DBCampo("CveVenta").ToEntero > 0 Then
If e.Row.DataKey("ClaveMetodoPagoSAT") = "PUE" Then
e.Row.FCLiteral("LtlComplemento").Text = ""
End If
Else
e.Row.FCLiteral("LtlComplemento").Visible = False
End If
End If
End Sub
Protected Sub BtnIEGuardar_Click(sender As Object, e As EventArgs) Handles BtnIEGuardar.Click
Dim FechaEmision As Date = MinFecha
If ChkComplementoPago.Checked AndAlso UsuarioActual.Empresa.Funcionalidad(382) = "1" Then
FechaEmision = TxtFechaEmision.Text.ToDate
If FechaEmision <= MinFecha Then
Alert("Fecha de Emisión no valida", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
If ChkComplementoPago.Checked Then
Dim objGral As New ClsGralFolios
Dim SalirDeMetodo As Boolean = False
If objGral.GetFolios("CP", UsuarioActual.CveEmpresa) Then
If Not objGral.DtResultados.Rows.Count > 0 Then
Alert("No se cuenta con folios para emitir complemento de pago", TipoMensaje.MsgAdvertencia)
SalirDeMetodo = True
End If
End If
objGral.Dispose()
If SalirDeMetodo Then
Exit Sub
End If
End If
'SI ES EMPRESA DE ACUMULADORES DEBE OBLIGAR A SUBIR UN ARCHIVO
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
Dim files As Extensiones.Files = Anexo.getfiles()
If files IsNot Nothing Then
If files.Archivos IsNot Nothing Then
If files.Archivos.Count = 0 Then
Alert("Debe anexar un archivo", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Else
Alert("Debe anexar un archivo", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Else
Alert("Debe anexar un archivo", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
If RblTipoPago.SelectedValue = "1" Then
Dim ValFechaDocumento As Boolean = False
Dim FoliosFechasValFechaDocumento As New StringBuilder
FoliosFechasValFechaDocumento.AppendLine("Se seleccionaron facturas con fecha de mes superior al mes del pago:
")
For Each gvRowVal As GridViewRow In GvCxC.Rows
If gvRowVal.FCCheckBox("Chk").Checked Then
Dim FechaFactura As Date = gvRowVal.DataKey("Fecha").ToDate
Dim FechaDocumento As Date = TxtFechaDocumento.Text.ToDate
Dim AnioFactura As Integer = FechaFactura.Year
Dim MesFactura As Integer = FechaFactura.Month
Dim AnioDocumento As Integer = FechaDocumento.Year
Dim MesDocumento As Integer = FechaDocumento.Month
If UsuarioActual.Empresa.UsaAC = False Then
If AnioFactura > AnioDocumento Then
FoliosFechasValFechaDocumento.AppendLine($"Folio: { gvRowVal.DataKey("SerieFolio") } fecha: {gvRowVal.DataKey("Fecha").ToDate.ToString("dd/MM/yyyy") }
")
ValFechaDocumento = True
ElseIf AnioFactura = AnioDocumento And MesFactura > MesDocumento Then
FoliosFechasValFechaDocumento.AppendLine($"Folio: { gvRowVal.DataKey("SerieFolio") } fecha: {gvRowVal.DataKey("Fecha").ToDate.ToString("dd/MM/yyyy") }
")
ValFechaDocumento = True
End If
End If
End If
Next
If ValFechaDocumento Then
Alert(FoliosFechasValFechaDocumento.ToString, TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
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
If TxtPrestamoImporte.Text.ToDecimal <> 0 AndAlso DdlPrestamo.SelectedValue = "-1" Then
Alert("Debe seleccionar un préstamo al especificar un valor.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'valida que no exceda lo seleccionado. con el valor del ie
If (RblTipoPago.SelectedValue = "3" AndAlso HdnIngresoImporte.Value.ToDecimal < TxtTotal.Text.ToDecimal) Then
Alert("Importe excedido para la aplicación", 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
'si hay liquidación-
If gvr.FCDropDownList("DdlAnti").SelectedValue = "-1" AndAlso gvr.FCTextBox("TxtAmort").Text.ToDecimal <> 0 Then
Alert("Importe de anticipo especificado y no seleccionado. F: " & gvr.DataKey("SerieFolio"), TipoMensaje.MsgAdvertencia)
Exit Sub
End If
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 RespuestaNotaCredrito)
Dim ListaFacturasGenerarNC As New List(Of Modelos.Factura)
Dim ObjFacturaAnt As Modelos.Factura = Nothing
Dim RespAnt As Modelos.Factura.MMensajeFactura = Nothing
Dim ImporteSeleccionado As Decimal = 0
'02-05-2018 MANDAMOS CANCELAR EL COMPLEMENTO A SUSTITUIR
Dim ErrorCancelarIE As Boolean = False
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.ToEntero > 0 Then
CveMoneda = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveMoneda", $"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCuenta = {DdlCuenta.SelectedValue.ToEntero}").ToEntero
Else
CveMoneda = IfNull(Request("CveMoneda"), "1").ToString.ToEntero
End If
CvePrePoliza = ObjMov.AddPrePolizas("Ventas/ClientesAbonar", 11, TxtImporte.Text.Trim.ToDecimal, TxtImporte.Text.Trim.ToDecimal, 1, 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,
CveProveedorIntermediario:=CveProvIntermediario, ImporteDeduccionesPago:=TxtImporteDeduccionesPago.Text.ToDecimal, FechaEmision:=FechaEmision)
Else
If RblTipoPago.SelectedValue.Contiene("3") Then 'ixc
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("{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase:=False)
End If
'inserto los movimientos de la conta para abonar al saldo
If CvePrePoliza > 0 Then
Dim CvePlantillaPoliza As Integer = 11
Dim alertaContabilizacion As String = "Se enviaron correctamente las siguientes pólizas:
"
Dim idCuentaContabilizacion As Long = 1
Dim CveCuentaContabilizacion As Long = 1
Dim dtConceptos As DataTable = Nothing
Dim tipoCambioPago As Decimal
Dim TipoCambioGeneral As Decimal = 1
Dim CveSubProyectoContabilizar As Integer = -1
Dim CveSubProyectoMaximo As Integer = -1
Dim CuentasContablesInvalidas 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
Dim tFecha As Date = TxtFechaDocumento.Text.ToDate
Dim UltimaFluctuacion As MTipoCambioFluctuacion = GlobalTipoCambioUltimaFluctuacion(tFecha)
Dim ImportePrestamo As Decimal = 0
Dim TCPrestamo As Decimal = 0
If CveSubProyectoMaximo <= 0 Then 'sino se seleccionó del combo, busca en el listado el primero
For Each Gvr As GridViewRow In GvCxC.Rows
If Gvr.FCCheckBox("Chk").Checked Then
CveSubProyectoMaximo = Gvr.DataKey("CveSubProyecto").ToEntero
Exit For
End If
Next
End If
If TxtPrestamoImporte.Text.ToDecimal <> 0 Then 'amortización del préstamo
ImportePrestamo = TxtPrestamoImporte.Text.ToDecimal
Dim tCveProv As Integer = DtPrestamos.FiltroPrimeroValor("CveProveedor", "CveIE=" & DdlPrestamo.SelectedValue).ToEntero
Dim tFechaIE As Date = DtPrestamos.FiltroPrimeroValor("FechaDocumento", "CveIE=" & DdlPrestamo.SelectedValue).ToDate
TCPrestamo = DtPrestamos.FiltroPrimeroValor("TipoCambio", "CveIE=" & DdlPrestamo.SelectedValue).ToDecimal
If CveMoneda = 1 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImportePrestamo, ImportePrestamo, 57, TxtFolio.Text, TxtObservaciones.Text, CveIE:=DdlPrestamo.SelectedValue.ToEntero, CveSubProyecto:=CveSubProyectoMaximo, TipoCambio:=tipoCambioPago, CveProveedor:=tCveProv) Then
MsgError = "No se pudo insertar la póliza"
End If
Else
If UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso UltimaFluctuacion IsNot Nothing Then
If tFechaIE <= UltimaFluctuacion.FechaFluctuacion Then
FechaUltimaFluctuacion = UltimaFluctuacion.FechaFluctuacion
TCPrestamo = UltimaFluctuacion.TCFluctuacion
End If
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImportePrestamo, ImportePrestamo, 349, TxtFolio.Text, TxtObservaciones.Text, CveIE:=DdlPrestamo.SelectedValue.ToEntero, CveSubProyecto:=CveSubProyectoMaximo, TipoCambio:=TCPrestamo, ImporteME:=ImportePrestamo, CveProveedor:=tCveProv) Then
MsgError = "No se pudo insertar la póliza"
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImportePrestamo, ((ImportePrestamo * TCPrestamo) - ImportePrestamo).RoundSQL, 350, TxtFolio.Text, TxtObservaciones.Text, CveIE:=DdlPrestamo.SelectedValue.ToEntero, CveSubProyecto:=CveSubProyectoMaximo, TipoCambio:=TCPrestamo, ImporteME:=ImportePrestamo, CveProveedor:=tCveProv) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
End If
If TxtPrestamoIntereses.Text.ToDecimal <> 0 AndAlso MsgError = "" Then
tipoCambioPago = If(TxtTCDolares.Visible, TxtTCDolares.Text.ToDecimal, TxtTCDolaresDolares.Text.ToDecimal)
Dim ImporteIntereses As Decimal = (TxtPrestamoIntereses.Text.ToDecimal * tipoCambioPago).RoundSQL
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteIntereses, ImporteIntereses, 51, TxtFolio.Text, TxtObservaciones.Text, CveIE:=DdlPrestamo.SelectedValue.ToEntero, CveSubProyecto:=CveSubProyectoMaximo, TipoCambio:=tipoCambioPago, CveClasificacion:=21927) Then
MsgError = "No se pudo insertar la póliza"
End If
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
Dim EsAnticipoEspecial As Boolean = False
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
ObjFactura = New Modelos.Factura(UsuarioActual, gvr.DataKey("CveVenta").ToEntero(), UsuarioActual.CveEmpresa, VerificaAlmacen:=False)
End If
Dim VentaActual As New Venta(UsuarioActual)
VentaActual.CveVenta = gvr.DataKey("CveVenta").ToEntero
VentaActual.Fecha = gvr.DataKey("Fecha").ToDate
VentaActual.CveCliente = gvr.DataKey("CveCliente").ToEntero
VentaActual.CveMoneda = gvr.DataKey("CveMoneda").ToEntero
VentaActual.TipoDocto = gvr.DataKey("TipoDocto")
VentaActual.SerieFolio = gvr.DataKey("SerieFolio")
VentaActual.ClienteNombre = NombreComercial
VentaActual.TC = gvr.DataKey("TipoCambio").ToDecimal
VentaActual.Total = gvr.DataKey("Original").ToDecimal
VentaActual.IVA = gvr.DataKey("IVA").ToDecimal
VentaActual.IEPS = gvr.DataKey("IEPS").ToDecimal
VentaActual.RetIVA = gvr.DataKey("RetIVA").ToDecimal
VentaActual.RetISR = gvr.DataKey("RetISR").ToDecimal
VentaActual.PorcentajeIVA = gvr.DataKey("PorcentajeIVA").ToDecimal
VentaActual.CveSubProyecto = gvr.DataKey("CveSubProyecto").ToEntero
'Importe de pago
Dim Pago As New VentaPago
Pago.TipoPago = "XXX"
Pago.Fecha = TxtFechaDocumento.Text.ToDate
Pago.CveIE = CveIE
Pago.CveMonedaPago = CveMoneda
Pago.ImportePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
Pago.ImportePagoVenta = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
Pago.Referencia = TxtFolio.Text
If RblTipoPago.SelectedValue = "3" Then
Pago.TipoPago = "I"
Pago.FechaDocumentoRelacionado = FechaIngreso
Pago.CveClientePago = CveCliente
End If
'Tipos de cambio
If Pago.CveMonedaPago = 1 AndAlso VentaActual.CveMoneda = 2 Then 'Si la venta viene en Dolares y se va a pagar en Pesos
Pago.TCPago = TxtTC.Text.ToDecimal
ElseIf Pago.CveMonedaPago = 2 AndAlso VentaActual.CveMoneda = 2 Then 'Si la venta viene en Dolares y se va a pagar en DOLARES
Pago.TCPago = If(TxtTCDolaresDolares.Visible, TxtTCDolaresDolares.Text.ToDecimal, TxtTCDolares.Text.ToDecimal)
ElseIf Pago.CveMonedaPago = 2 AndAlso VentaActual.CveMoneda = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
Pago.TCPago = TxtTCDolares.Text.ToDecimal
End If
tipoCambioPago = Pago.TCPago
If gvr.FCTextBox("TxtComision").Text.ToDecimal <> 0 Then Pago.OtroGastoIngreso = gvr.FCTextBox("TxtComision").Text.ToDecimal * If(Pago.CveMonedaPago = VentaActual.CveMoneda, 1, Pago.TCPago)
If UsuarioActual.Empresa.Funcionalidad(590) = "1" AndAlso MsgError = "" Then '' si es empresa agrícola
Dim FluctuacionAnticipo As Decimal = 0
Dim ImporteLiq1 As Decimal = gvr.FCTextBox("TxtLiqCol1").Text.ToDecimal
Dim ImporteLiq2 As Decimal = gvr.FCTextBox("TxtLiqCol2").Text.ToDecimal
Dim ImporteLiq3 As Decimal = gvr.FCTextBox("TxtLiqCol3").Text.ToDecimal
Dim ImporteLiq4 As Decimal = gvr.FCTextBox("TxtLiqCol4").Text.ToDecimal
Dim ImporteLiq5 As Decimal = gvr.FCTextBox("TxtLiqCol5").Text.ToDecimal
Dim ImporteLiq6 As Decimal = gvr.FCTextBox("TxtLiqCol6").Text.ToDecimal
Dim ImporteLiq7 As Decimal = gvr.FCTextBox("TxtLiqCol7").Text.ToDecimal
Dim ImporteLiq8 As Decimal = gvr.FCTextBox("TxtLiqCol8").Text.ToDecimal
Dim ImporteLiq9 As Decimal = gvr.FCTextBox("TxtLiqCol9").Text.ToDecimal
Dim ImporteLiq10 As Decimal = gvr.FCTextBox("TxtLiqCol10").Text.ToDecimal
Dim CveClasificacionCol1 As Integer = 21514 'comisiones sobre venta
Dim CveClasificacionCol2 As Integer = 21916 ' manejo
Dim CveClasificacionCol3 As Integer = 21917 'servicios de inspección
Dim CveClasificacionCol4 As Integer = 21918 ' seguro liquidación
Dim CveClasificacionCol5 As Integer = 21561 ' gastos aduanales mex
Dim CveClasificacionCol6 As Integer = 21920 ' diveros
Dim CveClasificacionCol7 As Integer = 21919 'gastos aduanales usa
Dim CveClasificacionCol8 As Integer = 21211 'material Empaque
Dim CveClasificacionCol9 As Integer = 21207 'Semilla
Dim CveClasificacionCol10 As Integer = 21541 'Flete
Dim CveSubProyectoLiquidacion As Integer = gvr.DataKey("CveSubProyecto").ToEntero
Dim CveConceptoLiquidacion As Integer = 51
Dim ConceptoPartida As String = gvr.DataKey("SerieFolio") & " " & gvr.FCDropDownList("DdlTG").SelectedItem.Text
If ImporteLiq1 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq1, ImporteLiq1 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol1, ImporteME:=If(CveMoneda > 1, ImporteLiq1, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq2 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq2, ImporteLiq2 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol2, ImporteME:=If(CveMoneda > 1, ImporteLiq2, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq3 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq3, ImporteLiq3 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol3, ImporteME:=If(CveMoneda > 1, ImporteLiq3, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq4 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq4, ImporteLiq4 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol4, ImporteME:=If(CveMoneda > 1, ImporteLiq4, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq5 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq5, ImporteLiq5 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol5, ImporteME:=If(CveMoneda > 1, ImporteLiq5, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq6 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq6, ImporteLiq6 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol6, ImporteME:=If(CveMoneda > 1, ImporteLiq6, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq7 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq7, ImporteLiq7 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol7, ImporteME:=If(CveMoneda > 1, ImporteLiq7, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq8 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq8, ImporteLiq8 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol8, ImporteME:=If(CveMoneda > 1, ImporteLiq8, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq9 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq9, ImporteLiq9 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol9, ImporteME:=If(CveMoneda > 1, ImporteLiq9, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If ImporteLiq10 <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteLiq10, ImporteLiq10 * tipoCambioPago, CveConceptoLiquidacion, gvr.DataKey("SerieFolio"), ConceptoPartida, CveIE:=CveIE, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoLiquidacion, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago, PorcentajeImpuesto:=0, CveClasificacion:=CveClasificacionCol10, ImporteME:=If(CveMoneda > 1, ImporteLiq10, 0), CveTipoGasto:=gvr.FCDropDownList("DdlTG").SelectedValue.ToEntero) Then
MsgError = "No se pudo insertar la póliza" : Exit For
End If
End If
If MsgError = "" AndAlso gvr.FCDropDownList("DdlAnti").SelectedValue.ToEntero > 0 Then
Dim TCP As Decimal = 0
Dim FolioPago As String = " "
If DtIngresos IsNot Nothing Then
TCP = DtIngresos.FiltroPrimeroValor("TipoCambio", String.Format("CveIE={0}", gvr.FCDropDownList("DdlAnti").SelectedValue)).ToDecimal
FolioPago = DtIngresos.FiltroPrimeroValor("Folio", String.Format("CveIE={0}", gvr.FCDropDownList("DdlAnti").SelectedValue))
Dim tTCPFecha As Date = DtIngresos.FiltroPrimeroValor("FechaDocumento", String.Format("CveIE={0}", gvr.FCDropDownList("DdlAnti").SelectedValue)).ToDate
'considera fluctuación
If UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso UltimaFluctuacion IsNot Nothing Then
If tTCPFecha <= UltimaFluctuacion.FechaFluctuacion Then
tTCPFecha = UltimaFluctuacion.FechaFluctuacion
TCP = UltimaFluctuacion.TCFluctuacion
End If
End If
End If
'se calcula la fluctuación de la aplicación del anticipo, para sumarla en el concepto de fluctuación más abajo
FluctuacionAnticipo = ((TCP - tipoCambioPago) * gvr.FCTextBox("TxtAmort").Text.ToDecimal).RoundSQL
MsgError = RegistraAmortizacionAnticipo(ObjMov, CvePrePoliza, gvr.FCDropDownList("DdlAnti").SelectedValue.ToEntero, gvr.FCTextBox("TxtAmort").Text.ToDecimal, TCP, gvr.DataKey("CveVenta").ToEntero, gvr.DataKey("SerieFolio").ToString, FolioPago)
End If
If MsgError = "" AndAlso gvr.FCDropDownList("DdlAnti2").SelectedValue.ToEntero > 0 Then
Dim TCP As Decimal = 0
Dim FolioPago As String = " "
If DtIngresos IsNot Nothing Then
TCP = DtIngresos.FiltroPrimeroValor("TipoCambio", String.Format("CveIE={0}", gvr.FCDropDownList("DdlAnti2").SelectedValue)).ToDecimal
FolioPago = DtIngresos.FiltroPrimeroValor("Folio", String.Format("CveIE={0}", gvr.FCDropDownList("DdlAnti2").SelectedValue))
Dim tTCPFecha As Date = DtIngresos.FiltroPrimeroValor("FechaDocumento", String.Format("CveIE={0}", gvr.FCDropDownList("DdlAnti2").SelectedValue)).ToDate
'considera fluctuación
If UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso UltimaFluctuacion IsNot Nothing Then
If tTCPFecha <= UltimaFluctuacion.FechaFluctuacion Then
tTCPFecha = UltimaFluctuacion.FechaFluctuacion
TCP = UltimaFluctuacion.TCFluctuacion
End If
End If
End If
'se calcula la fluctuación de la aplicación del anticipo, para sumarla en el concepto de fluctuación más abajo
FluctuacionAnticipo += ((TCP - tipoCambioPago) * gvr.FCTextBox("TxtAmort2").Text.ToDecimal).RoundSQL
MsgError = RegistraAmortizacionAnticipo(ObjMov, CvePrePoliza, gvr.FCDropDownList("DdlAnti2").SelectedValue.ToEntero, gvr.FCTextBox("TxtAmort2").Text.ToDecimal, TCP, gvr.DataKey("CveVenta").ToEntero, gvr.DataKey("SerieFolio").ToString, FolioPago)
End If
If ImportePrestamo <> 0 Then
If TCPrestamo > 0 Then
FluctuacionAnticipo += ((TCPrestamo - tipoCambioPago) * ImportePrestamo).RoundSQL
ImportePrestamo = 0
End If
End If
Pago.ImporteFluctuacionAdicional = FluctuacionAnticipo
End If
If MsgError = "" AndAlso AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjMov) Then
MsgError = "No se pudo insertar la póliza"
Exit For
End If
' Case 134 'Pago Intermediario
'If RblTipoPago.SelectedValue = "2" Then
' Dim ImporteMovimiento As Decimal = gvr.FCTextBox("TxtAbonar").Text.ToDecimal - gvr.FCTextBox("TxtComision").Text.ToDecimal
' Dim ImporteMN As Decimal = (ImporteMovimiento * tipoCambioPago).RoundSQL
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, ImporteMovimiento, ImporteMN, 134, VentaActual.SerieFolio, VentaActual.SerieFolio, 0, CveVenta:=gvr.DataKey("CveVenta").ToEntero, CveSubProyecto:=CveSubProyectoContabilizar, CveProveedor:=DdlProveedorPagoInt.SelectedValue.ToEntero) Then
' MsgError = "No se pudo insertar la póliza"
' End If
'End If
'PARA EMITIR COMPLEMENTO PAGO
CveVentasPago.Add(gvr.DataKey("CveVenta").ToEntero)
SeriesPago.Add(gvr.DataKey("SerieFolio"))
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" AndAlso MsgError = "" Then
CveSubProyectoContabilizar = CveSubProyectoMaximo
If CveMoneda = 2 Then
'If IdCuentaBancariaComplementaria > 0 Then
If CveMoneda = 2 AndAlso CveMonedaFiltro = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES
tipoCambioPago = TxtTCDolares.Text.ToDecimal
ElseIf CveMoneda = 2 AndAlso CveMonedaFiltro = 2 Then
tipoCambioPago = TxtTCDolaresDolares.Text.ToDecimal
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtImporte.Text.ToDecimal, TxtImporte.Text.Trim.ToDecimal, 30, ObjIE.Folio, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), CveIE:=CveIE, CveSubProyecto:=CveSubProyectoContabilizar, CveCliente:=ViewState("CveCliente").ToString.ToEntero, 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), If(CveMoneda = 2, (TxtImporte.Text.Trim.ToDecimal * tipoCambioPago) - TxtImporte.Text.Trim.ToDecimal, TxtImporte.Text.Trim.ToDecimal), 204, TxtObservaciones.Text, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), CveIE:=CveIE, CveSubProyecto:=CveSubProyectoContabilizar, CveCliente:=ViewState("CveCliente").ToString.ToEntero, ImporteME:=If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal, 0), 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, If(CveMoneda = 2, TxtImporte.Text.Trim.ToDecimal * tipoCambioPago, TxtImporte.Text.Trim.ToDecimal), 30, ObjIE.Folio, TxtObservaciones.Text + If(CveMoneda = 2, $" TC:{tipoCambioPago}", ""), CveIE:=CveIE, CveSubProyecto:=CveSubProyectoContabilizar, CveCliente:=ViewState("CveCliente").ToString.ToEntero, ImporteME:=If(CveMoneda = 2, TxtImporte.Text.ToDecimal, 0), TipoCambio:=tipoCambioPago, TipoCambioPago:=tipoCambioPago) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
End If
If UsuarioActual.Empresa.Funcionalidad(590) = "1" AndAlso MsgError = "" Then '' si es empresa agrícola
If TxtAnticipo.Text.ToDecimal <> 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtAnticipo.Text.ToDecimal, TxtAnticipo.Text.ToDecimal, 66, TxtFolio.Text, TxtObservaciones.Text, CveIE:=CveIE, CveSubProyecto:=CveSubProyectoContabilizar, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, PorcentajeImpuesto:=0, ImporteME:=If(CveMoneda > 1, TxtAnticipo.Text.ToDecimal, 0)) Then
MsgError = "No se pudo insertar la póliza"
End If
If CveMoneda > 1 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtAnticipo.Text.ToDecimal, ((TxtAnticipo.Text.ToDecimal * tipoCambioPago) - TxtAnticipo.Text.ToDecimal).RoundSQL, 226, TxtFolio.Text, TxtObservaciones.Text, CveIE:=CveIE, CveSubProyecto:=CveSubProyectoContabilizar, CveCliente:=ViewState("CveCliente").ToString.ToEntero, TipoCambio:=tipoCambioPago, PorcentajeImpuesto:=0, ImporteME:=If(CveMoneda > 1, TxtAnticipo.Text.ToDecimal, 0)) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
End If
End If
If UsuarioActual.Empresa.Funcionalidad(382) = "1" AndAlso TxtAnticipo.Text.ToDecimal > 0 AndAlso MsgError = "" Then '' si es empresa GDiaz
'generar un anticipo y registrarle el pago.
Dim tCveMoneda As Integer = 1
Dim tCveFormaPago As Integer = GlobalDTTipoTransacciones().FiltroPrimeroValor("CveFormaPago", $"CveTipoTransaccion={DdlTipoTransaccion.SelectedValue}").ToEntero
Dim tCvePS As Integer
Dim tCveUM As Integer = 0
Dim tCveSub As Integer = DdlSubProyectos.SelectedValue.ToEntero
ObjFacturaAnt = Modelos.Factura.CrearVentaNueva(UsuarioActual, tCveSub, CveCliente, tCveMoneda, "Ant")
ObjFacturaAnt.CveMoneda = tCveMoneda
ObjFacturaAnt.CveFormaPago = tCveFormaPago
ObjFacturaAnt.CveMetodoPago = 1
ObjFacturaAnt.ClaveMetodoPagoSAT = "PUE"
ObjFacturaAnt.ClaveFormaPagoSAT = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjFacturaAnt.CveFormaPago}")
ObjFacturaAnt.ClaveUsoCFDISAT = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", $"CveUsoCFDI = {ObjFacturaAnt.CveUsoCFDI}")
Dim drPS As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CodigoSATPS:="84111506").FiltroPrimero("PSCodigo LIKE '%ANTICIPO%' OR PSCodigo LIKE '%anticipo%' OR PSCodigo LIKE '%Anticipo%'")
Dim tPorIVA As Decimal = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=tCveSub).FiltroPrimeroValor("IVA").ToDecimal
Dim tPU As Decimal = (TxtAnticipo.Text.ToDecimal / (1 + tPorIVA)).RoundSQL(6)
If drPS IsNot Nothing Then
tCvePS = drPS("CvePS").ToString.ToEntero
tCveUM = drPS("CveUnidadMedida").ToString.ToEntero
End If
ObjFacturaAnt.AgregarPS(tCvePS, 1, tPU, 0, "", CveUM:=tCveUM, CveSubProyecto:=tCveSub, PorcentajeIVA:=tPorIVA)
ObjFacturaAnt.CalculaTotales()
RespAnt = ObjFacturaAnt.EmitirFactura(False, Transac:=ObjMov.IniciaTransacSQL(), Modulo:="Ventas/ClientesAbonarAnt", MostrarURL:=True)
RespAnt.Factura = ObjFacturaAnt
If RespAnt IsNot Nothing AndAlso RespAnt.Factura IsNot Nothing Then
Dim VentaActual As New Venta(UsuarioActual)
VentaActual.CveVenta = RespAnt.Factura.CveVenta
VentaActual.Fecha = RespAnt.Factura.Fecha
VentaActual.CveCliente = CveCliente
VentaActual.CveMoneda = tCveMoneda
VentaActual.TipoDocto = "Ant"
VentaActual.SerieFolio = RespAnt.Factura.SerieFolio
VentaActual.ClienteNombre = NombreComercial
VentaActual.TC = 1
VentaActual.Total = TxtAnticipo.Text.ToDecimal
VentaActual.IVA = (tPorIVA * tPU).RoundSQL(2)
VentaActual.PorcentajeIVA = tPorIVA
VentaActual.CveSubProyecto = tCveSub
'Importe de pago
Dim Pago As New VentaPago
Pago.TipoPago = "XXX"
Pago.Fecha = TxtFechaDocumento.Text.ToDate
Pago.CveIE = CveIE
Pago.CveMonedaPago = tCveMoneda
Pago.ImportePago = TxtAnticipo.Text.ToDecimal
Pago.ImportePagoVenta = TxtAnticipo.Text.ToDecimal
Pago.Referencia = TxtFolio.Text
Pago.TipoPago = "XXX"
'If RblTipoPago.SelectedValue = "3" Then
' Pago.TipoPago = "I"
' Pago.FechaDocumentoRelacionado = FechaIngreso
' Pago.CveClientePago = CveCliente
'End If
'MsgError = RespAnt.Mensajes.ToString
If MsgError = "" AndAlso AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjMov) Then
MsgError = "No se pudo insertar la póliza"
End If
End If
End If
If MsgError = "" AndAlso Not ObjMov.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, Opcion:=3) Then
MsgError = ObjMov.MensajePolizaDescuadre & " La diferencia es de: " & ObjMov.ValorDiferencia
'If ObjMov.ValorPolizaDescuadre > 0 Then
' MsgError = ObjMov.MensajePolizaDescuadre & " La diferencia es de: " & ObjMov.ValorDiferencia
'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" AndAlso MsgError = "" 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 RespuestaNotaCredrito = GenerarNC(ObjIE.IniciaTransacSQL(), ObjConta, ListaNC, ObjIE)
If Resp IsNot Nothing AndAlso Resp.Respuesta IsNot Nothing AndAlso Resp.Respuesta.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.TipoContabilidad = 2 AndAlso 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 As Decimal = 0
Dim IdCuentaOP As Integer = -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, 0, 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
If Not ErrorAC Then
ErrorAC = Not ObjConta.AjustaPoliza(IDPoliza)
End If
If Not ErrorAC Then
ErrorAC = Not ObjIE.UpdateIEPrePoliza(Fecha, FolioPoliza.ToString, IDPoliza, CvePrePoliza, CveIE, 0)
End If
End If
End If
If ErrorAC Then
MsgError = "Error al Agregar la Póliza de Armonización Contable"
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 {1}
", CveIE, ObjIE.Folio)
If UsuarioActual.TienePermisoProceso(354) Then 'visualizar la póliza al registros
StrMsg.AppendFormat("
Ver Póliza ", CvePrePoliza)
Dim TempParametros As String = Encripta(String.Format("OP=PREPO&CvePrePoliza={0}", CvePrePoliza))
StrMsg.Append($" Imprimir ")
End If
If IDPoliza > 0 Then StrMsg.AppendFormat("Poliza: {1}
", IDPoliza, FolioPoliza)
For Each RespuestaNotaCredito As RespuestaNotaCredrito In NCGeneradas
If RespuestaNotaCredito IsNot Nothing AndAlso RespuestaNotaCredito.Respuesta IsNot Nothing Then
Try
Dim ObjTimbradoNC As New Timbrado
Dim TimbroNC As Boolean = ObjTimbradoNC.TimbrarFactura(UsuarioActual, RespuestaNotaCredito.ObjFacturaNC)
If Not TimbroNC Then
Alert(ObjTimbradoNC.MensajeErrorCFDI, TipoMensaje.MsgError)
End If
ObjTimbradoNC = Nothing
Catch ex As Exception
OnError("Ocurrió un error al timbrar la NC.", ex)
End Try
StrMsg.AppendFormat("Nota de crédito generada correctamente.
Folio: {1}
", RespuestaNotaCredito.Respuesta.CveVenta, RespuestaNotaCredito.Respuesta.SerieFolio)
End If
Next
If ObjFacturaAnt IsNot Nothing Then
Dim MsgTimbrado As String = ""
Try
ObjFacturaAnt.PreparaTimbre()
MsgTimbrado = TimbrarFactura(ObjFacturaAnt, True)
StrMsg.AppendFormat("
Anticipo generado correctamente.
Folio: {1}
", ObjFacturaAnt.CveVenta, ObjFacturaAnt.SerieFolio)
If Not String.IsNullOrEmpty(MsgTimbrado) Then
Dim StrEr As String = $"