Files
SIG/Bancos/Creditos.aspx.vb

1625 lines
74 KiB
VB.net

Option Strict On
Option Explicit On
Imports System.Data
Imports Extensiones
Partial Class Bancos_Creditos
Inherits ClsPaginas
#Region "Propiedades"
Private Property CveCredito As Integer
Get
Return ViewState("CveCredito").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCredito") = value
End Set
End Property
Private Property CveCuentaTarjeta As Integer
Get
Return ViewState("CveCuentaTarjeta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuentaTarjeta") = value
End Set
End Property
Private Property CveCompra As Integer
Get
Return ViewState("CveCompra").ToString.ToEntero
End Get
Set(value As Integer)
End Set
End Property
Private Property CveLineaCredito As Integer
Get
Return ViewState("CveLineaCredito").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveLineaCredito") = value
End Set
End Property
Private Property CveIE As Integer
Get
Return ViewState("CveIE").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveIE") = value
End Set
End Property
Private Property TotalCompra As Double
Get
Return ViewState("TotalCompra").ToString.ToDouble
End Get
Set(value As Double)
ViewState("TotalCompra") = value
End Set
End Property
Private Property CveTipoCredito As Integer
Get
Return ViewState("CveTipoCredito").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveTipoCredito") = value
End Set
End Property
Private Property DTAmortizacion As DataTable
Get
Return CType(ViewState("DTAmortizacion"), DataTable)
End Get
Set(value As DataTable)
ViewState("DTAmortizacion") = value
End Set
End Property
Private Property DtCuentasBancarias As DataTable
Get
Return CType(ViewState("DtCuentasBancarias"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtCuentasBancarias") = value
End Set
End Property
Private Property DtAF As DataTable
Get
Return CType(ViewState("DtAF"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtAF") = value
End Set
End Property
Private Property DtIE As DataTable
Get
Return CType(ViewState("DtIE"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtIE") = value
End Set
End Property
Private Property RegeneraTablaAmortizacion As Boolean
Get
Return CBool(ViewState("RegeneraTablaAmortizacion").ToString)
End Get
Set(value As Boolean)
ViewState("RegeneraTablaAmortizacion") = 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
InicializaValores()
If Request("CveCredito") IsNot Nothing AndAlso IsNumeric(Request("CveCredito")) AndAlso Request("CveCredito").ToEntero > 0 Then
ViewState("CveCredito") = Request("CveCredito")
BtnGuardar.Text = "Actualizar"
CargaCredito()
Else
ViewState("CveCredito") = -1
CreaDtAF()
CreaDtIE()
If Request("CveTipoCredito") IsNot Nothing AndAlso IsNumeric(Request("CveTipoCredito")) AndAlso Request("CveTipoCredito").ToEntero > 0 Then
CveTipoCredito = Request("CveTipoCredito").ToString.ToEntero
DdlTipoCredito.SelectedValue = CveTipoCredito.ToString
DdlTipoCredito_SelectedIndexChanged(DdlTipoCredito, EventArgs.Empty)
UpTipoCredito.Visible = False
Else
DdlTipoCredito_SelectedIndexChanged(DdlTipoCredito, EventArgs.Empty)
End If
'Carga CtaContable
CargaCuentasContables()
' BtnEliminar.Enabled = False
End If
CreaDTAmortizacion()
End If
End Sub
#Region " INICIALIZA VALORES "
Private Sub InicializaValores()
ViewState("CveCompra") = -1
ViewState("TotalCompra") = -1
ViewState("CveIE") = -1
ViewState("CveTipoCredito") = -1
ViewState("CveLineaCredito") = -1
ViewState("CveCuentaTarjeta") = -1
RegeneraTablaAmortizacion = False
'Fecha Default
TxtFechaInicio.Text = DateTime.Now().ToString("dd/MM/yyyy")
'Carga Proveedores | Entidad Financiera
DdlProveedores.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa)
DdlProveedores.DataBind()
'DDL PARA GENERAR PREPOLIZA
DdlAcreedorPrePoliza.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa)
DdlAcreedorPrePoliza.DataBind()
'Carga Tipo Moneda
DdlTipoMoneda.DataSource = GlobalDTMonedas
DdlTipoMoneda.DataBind()
DdlCSTipoMoneda.DataSource = GlobalDTMonedas
DdlCSTipoMoneda.DataBind()
'Carga CuentasBancarias para CuentaCredito y CuentaDeposito
DtCuentasBancarias = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
CargaCuentasDeposito()
End Sub
#End Region
#Region " TIPOS DE CRÉDITOS - MODALIDADES "
Protected Sub DdlTipoCredito_SelectedIndexChanged(sender As Object, e As EventArgs)
If DdlTipoCredito.SelectedValue.ToEntero > 2 Then
UpCreditosSimples.Visible = False
UpCuentaCredito.Visible = False
UpCompra.Visible = False
trEntidadFinanciera.Visible = True
UpCreditosComplejos.Visible = True
UpActivoFijo.Visible = True
BtnGuardar.Enabled = True
TrPagueseA.Visible = True
TxtPagueseA.Text = If(DdlProveedores.SelectedValue.ToEntero > 0, DdlProveedores.SelectedItem.Text, "")
'TableVinculaAnticipo.Visible = True
''Genera Anticipo --- Viejo
'UpPreguntaAnticipo.Visible = True
'LbTituloCuentaDeposito.Text = "Pago Anticipo"
'LtAnticipo.Text = "Aplica anticipo"
Else
UpCreditosSimples.Visible = True
UpCuentaCredito.Visible = True
trEntidadFinanciera.Visible = False
UpCreditosComplejos.Visible = False
UpActivoFijo.Visible = False
BtnGuardar.Enabled = True
TrPagueseA.Visible = False
DdlCSTipoMoneda.Enabled = False
CargaCuentasBancarias()
UpVinculaAnticipo.Visible = False
'CADENA PRODUCTIVA
If DdlTipoCredito.SelectedValue.ToEntero = 1 Then
UpCompra.Visible = True
'UpPagoAnticipo.Visible = False
TrCadenaProductiva.Visible = True
TrRevolvente1.Visible = False
TrRevolvente2.Visible = False
Else
'REVOLVENTE
UpCompra.Visible = False
'UpPagoAnticipo.Visible = True
TrCadenaProductiva.Visible = False
TrRevolvente1.Visible = True
TrRevolvente2.Visible = True
'GENERA DEPOSITO SOLO REVOLVENTE
UpGeneraDeposito.Visible = True
End If
End If
LbTitulo.Text = String.Format("Crédito: {0}", DdlTipoCredito.SelectedItem.Text)
UpRegistro.Update()
End Sub
#End Region
#Region "C A R G A - D A T O S - CREDITOS"
Public Sub CargaCredito()
Dim ObjCreditos As New ClsBancos
If ObjCreditos.GetCreditos(CveCredito, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then
If ObjCreditos.DtResultados.Rows.Count > 0 Then
CveTipoCredito = ObjCreditos.DtResultados.Rows(0)("CveTipoCredito").ToString.ToEntero
CveCuentaTarjeta = ObjCreditos.DtResultados.Rows(0)("CveCuentaTarjeta").ToString.ToEntero
End If
End If
ObjCreditos.Dispose()
DdlTipoCredito.SelectedValue = CveTipoCredito.ToString
DdlTipoCredito_SelectedIndexChanged(DdlTipoCredito, EventArgs.Empty)
UpTipoCredito.Visible = False
UpGeneraDeposito.Visible = False
Select Case CveTipoCredito.ToString.ToEntero
Case 1, 2
'CREDITOS SIMPLES: CREDIPROVEDORES, REVOLVENTE
CargaCreditoSencillo()
BtnEliminar.Visible = True
Case 3, 4, 5
'CREDITOS COMPLEJOS: DOCUMENTOS, ARRENDAMIENTO PURO, ARRENDAMIENTO FINANCIERO
CargaCreditoComplejo()
Case Else
End Select
'Carga CtaContable
End Sub
Private Sub CargaCreditoSencillo()
Dim ObjCreditos As New ClsBancos
If ObjCreditos.GetCreditos(CveCredito, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then
If ObjCreditos.DtResultados.Rows.Count = 1 Then
Dim dr As DataRow = ObjCreditos.DtResultados(0)
DdlProveedores.SelectedValue = dr("CveProveedor").ToString
RBLClasificacionContable.SelectedValue = dr("ClasificacionContable").ToString
TxtCSFechaVencimiento.Text = dr("FechaVencimiento").ToString
TxtCSFechaInicio.Text = dr("FechaInicio").ToString
DdlCSTipoMoneda.SelectedValue = dr("CveMoneda").ToString
TxtCSTasa.Text = dr("Tasa").ToString.FormatoNumero
TxtCSSobreTasa.Text = dr("SobreTasa").ToString.FormatoNumero
TxtCSReferencia.Text = dr("Referencia").ToString
TxtCSObservaciones.Text = dr("Observaciones").ToString
TxtCSPlazo.Text = dr("Plazo").ToString
DdlCuentaCredito.SelectedValue = dr("CveCuenta").ToString
DdlCuentaCredito_SelectedIndexChanged(DdlCuentaCredito, EventArgs.Empty)
CargaCuentasContables()
DdlCtaContable.SelectedValueExist(dr("IdCtaContable").ToString)
'CARGA CREDITO DETALLE
If ObjCreditos.GetCreditosDetalle(dr("CveCredito").ToString.ToEntero, -1) Then
If ObjCreditos.DtResultados.Rows.Count = 1 Then
Dim DT = ObjCreditos.DtResultados.Rows(0)
If DT("Estatus").ToString.Contiene("1", "101", "102") Then
trPagar.Visible = True
HLPagar.NavigateUrl = String.Format("/Bancos/IE.aspx?Opcion=EGSCREDITO&CveCredito={0}&CveCreditoDetalle={1}", CveCredito, DT("CveCreditoDetalle").ToString)
End If
If CveTipoCredito = 2 Then
Dim TotalCredi = 0
'TxtCSPeriodos.Text = ObjCreditos.DtResultados.Rows.Count.ToString
'TxtCSFechaInicio.Text = ObjCreditos.DtResultados.FiltraParametros("Periodo = 1").Rows(0)("Fecha").ToString
For index = 1 To ObjCreditos.DtResultados.Rows.Count
TotalCredi += ObjCreditos.DtResultados.Rows(index - 1)("Capital").ToString.ToEntero
Next
TxtCSTotalCredito.Text = TotalCredi.ToString.FormatoNumero
End If
End If
End If
If CveTipoCredito = 1 Then
HdnCveCompra.Value = dr("CveCompra").ToString
VinculaCompra()
End If
If dr("CveIE").ToString.ToEntero > 0 AndAlso ObjCreditos.GetBancosIE(dr("CveIE").ToString.ToEntero, UsuarioActual.CveEmpresa) Then
If ObjCreditos.DtResultados.Rows.Count = 1 Then
TxtFechaDeposito.Text = ObjCreditos.DtResultados.Rows(0)("FechaDocumento").ToString
DdlCuentaDeposito.SelectedValue = ObjCreditos.DtResultados.Rows(0)("CveCuenta").ToString
DdlCuentaDeposito_SelectedIndexChanged(DdlCuentaDeposito, EventArgs.Empty)
End If
End If
''Bloquear datos que no se pueden editar
TxtFechaDeposito.Enabled = False
DdlCuentaDeposito.Enabled = False
Else
Alert("Ocurrio un error al cargar el crédito. Por favor recargue la página.", TipoMensaje.MsgError)
End If
End If
ObjCreditos.Dispose()
End Sub
Private Sub CargaCreditoComplejo()
Dim ObjCreditos As New ClsBancos
Dim ObjPrepoliza As New ClsContabilidad
If ObjCreditos.GetCreditos(CveCredito, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then
If ObjCreditos.DtResultados.Rows.Count > 0 Then
Dim dr As DataRow = ObjCreditos.DtResultados(0)
DdlProveedores.SelectedValue = dr("CveProveedor").ToString
RBLClasificacionContable.SelectedValue = dr("ClasificacionContable").ToString
CargaCuentasContables()
DdlCtaContable.SelectedValue = dr("IdCtaContable").ToString
'HdnCveAF.Value = dr("CveAF").ToString
'VincularAF()
TxtReferencia.Text = dr("Referencia").ToString
TxtObservaciones.Text = dr("Observaciones").ToString
TxtPlazo.Text = dr("Plazo").ToString
TxtIVA.Text = (dr("PorIVA").ToString.ToDouble * 100).ToString
TxtTasa.Text = dr("Tasa").ToString.FormatoNumero(4)
TxtSobreTasa.Text = dr("SobreTasa").ToString.FormatoNumero
TxtFechaInicio.Text = dr("FechaInicio").ToString
TxtTotalCredito.Text = dr("CreditoValor").ToString.FormatoNumero
TxtVehiculoValor.Text = dr("CreditoValor").ToString.FormatoNumero
TxtVehiculoAnticipo.Text = dr("CreditoAnticipo").ToString.FormatoNumero
TxtComisionValor.Text = dr("ComisionApertura").ToString.FormatoNumero
TxtComisionAnticipo.Text = dr("ComisionAnticipo").ToString.FormatoNumero
TxtSeguroValor.Text = dr("SeguroValor").ToString.FormatoNumero
TxtSeguroAnticipo.Text = dr("SeguroAnticipo").ToString.FormatoNumero
TxtOtrosGastosValor.Text = dr("OtrosGastos").ToString.FormatoNumero
TxtOtrosGastosAnticipo.Text = dr("OtrosGastosAnticipo").ToString.FormatoNumero
TxtFondoGarantia.Text = dr("FondoGarantia").ToString.FormatoNumero
LbFondoGarantía.Text = dr("FondoGarantia").ToString.FormatoNumero
TxtSeguroMensual.Text = dr("Seguro").ToString.FormatoNumero
ChkTipoInteres.Checked = Boolean.Parse(dr("TipoInteres").ToString)
' TxtPagueseA.Text = dr("PagueseA").ToString
'TxtFechaPago.Text = ObjCreditos.DtResultados(0)("FechaDocumento").ToString
RegistraScript("Sumador(1);")
If TxtFondoGarantia.Text.ToDecimal > 0 Then
HLAplicarGarantia.Visible = True
End If
If ObjCreditos.CveCompraFactura > 0 Then
UpFacturaCompra.Visible = True
LbFacturaProveedor.Text = ObjCreditos.FacturaProveedor
LbFacturaSerieFolio.Text = ObjCreditos.FacturaSerieFolio
LbFacturaDescripcion.Text = ObjCreditos.FacturaDescripcion
LbFacturaFecha.Text = ObjCreditos.FacturaFecha.ToShortDateString
HLFacturaCompra.NavigateUrl = $"/Compras/Compras.aspx?CveCompra={ObjCreditos.CveCompraFactura}"
End If
If ObjCreditos.CvePrePoliza > 0 Then
UpSaldo.Visible = True
LbFacturaFecha.Text = ObjCreditos.FacturaFecha.ToShortDateString
HLSaldoPrePoliza.NavigateUrl = $"/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={ObjCreditos.CvePrePoliza}"
LbSaldo.Text = $"Saldo <b>Acreedor</b> "
If ObjPrepoliza.GetPrePolizasDetalle(ObjCreditos.CvePrePoliza, UsuarioActual.CveEmpresa) AndAlso ObjPrepoliza.DtResultados.Rows.Count > 0 Then
LbSaldoAcreedor.Text = ObjPrepoliza.DtResultados.FiltraParametros("CveConceptoContable = 42").Rows(0)("Importe").ToString.FormatoNumero
LbSaldoDocxPagar.Text = ObjPrepoliza.DtResultados.FiltraParametros("CveConceptoContable = 50").Rows(0)("Importe").ToString.FormatoNumero
End If
Else
HLAplicarSaldo.Visible = True
End If
If ObjCreditos.GetActivosFijosCreditos(CveCredito, -1) Then
DtAF = ObjCreditos.DtResultados
DtAF.Columns.Add("Estatus", GetType(Integer))
GvAF.DataSource = DtAF
GvAF.DataBind()
End If
If ObjCreditos.GetAnticiposCreditos(CveCredito, -1) Then
DtIE = ObjCreditos.DtResultados
DtIE.Columns.Add("Estatus", GetType(Integer))
GvIE.DataSource = DtIE
GvIE.DataBind()
If DtIE.Rows.Count > 0 Then
DivVinculaAnticipo.Visible = True
RBLAnticipo.SelectedValue = "1"
End If
End If
''CARGA PAGO ANTICIPO - VIEJO
'If dr("CveIE").ToString.ToEntero > 0 AndAlso ObjCreditos.GetBancosIE(dr("CveIE").ToString, UsuarioActual.CveEmpresa) Then
' If ObjCreditos.DtResultados.Rows.Count = 1 Then
' TxtFechaDeposito.Text = ObjCreditos.DtResultados.Rows(0)("FechaDocumento").ToString
' DdlCuentaDeposito.SelectedValue = ObjCreditos.DtResultados.Rows(0)("CveCuenta").ToString
' DdlCuentaDeposito_SelectedIndexChanged(DdlCuentaDeposito, EventArgs.Empty)
' End If
'Else
' UpPagoAnticipo.Visible = False
'End If
If dr("AplicaAnticipo").ToString = "True" Then
RBLAnticipo.SelectedValue = "1"
RBLAnticipo_SelectedIndexChanged(RBLAnticipo, EventArgs.Empty)
End If
'CARGA ANTICIPOS
If dr("CveIE").ToString.ToEntero > 0 AndAlso ObjPrepoliza.GetPrePolizasDetalle(-1, UsuarioActual.CveEmpresa, CveIE:=dr("CveIE").ToString.ToEntero) Then
If ObjPrepoliza.DtResultados.Rows.Count > 0 Then
TxtVehiculoAnticipo.Text = ObjPrepoliza.DtResultados.FiltraParametros("CveConceptoContable = 53").Rows(0)("Importe").ToString.FormatoNumero
TxtComisionAnticipo.Text = ObjPrepoliza.DtResultados.FiltraParametros("CveConceptoContable = 54").Rows(0)("Importe").ToString.FormatoNumero
TxtSeguroAnticipo.Text = ObjPrepoliza.DtResultados.FiltraParametros("CveConceptoContable = 55").Rows(0)("Importe").ToString.FormatoNumero
Dim dtt As DataTable = ObjPrepoliza.DtResultados.FiltraParametros("CveConceptoContable = 58")
If dtt.Rows.Count > 0 Then
TxtFondoGarantia.Text = dtt.Rows(0)("Importe").ToString.FormatoNumero
End If
End If
End If
'CARGA CREDITO DETALLE
If ObjCreditos.GetCreditosDetalle(CveCredito, -1) Then
If ObjCreditos.DtResultados.Rows.Count > 0 Then
TxtMensualidad.Text = ObjCreditos.DtResultados.Rows(0)("Mensualidad").ToString.FormatoNumero
DTAmortizacion = ObjCreditos.DtResultados
GvTA.DataSource = DTAmortizacion
GvAplicarGarantia.DataSource = ObjCreditos.DtResultados.FiltraParametros("Estatus = 1")
If DTAmortizacion.MAX("CveIE").ToEntero > 0 Then
BtnGenerar.Enabled = False
End If
If ObjCreditos.DtResultados.SUM("ImporteGarantia") > 0 Then
LbFondoGarantía.Text = (LbFondoGarantía.Text.ToDouble - ObjCreditos.DtResultados.SUM("ImporteGarantia")).FormatoNumero
GvTA.Columns(9).Visible = True
GvTA.Columns(10).Visible = True
End If
End If
GvTA.DataBind()
RowTA.Visible = True
UpGVDocumentos.Update()
GvAplicarGarantia.DataBind()
UpAplicarGarantia.Update()
End If
End If
End If
ObjCreditos.Dispose()
ObjPrepoliza.Dispose()
End Sub
#End Region
#Region " RBLS "
Protected Sub RBLAnticipo_SelectedIndexChanged(sender As Object, e As EventArgs)
If RBLAnticipo.SelectedValue.ToEntero > 0 Then
DivVinculaAnticipo.Visible = True
TdBuscaAnticipo.Visible = True
Else
DivVinculaAnticipo.Visible = False
TdBuscaAnticipo.Visible = False
DdlCuentaDeposito.SelectedValue = "-1"
DdlCuentaDeposito_SelectedIndexChanged(DdlCuentaDeposito, EventArgs.Empty)
End If
UpVinculaAnticipo.Update()
UpRegistro.Update()
RegistraScript("Sumador(1);")
End Sub
Private Sub RBLClasificacionContable_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RBLClasificacionContable.SelectedIndexChanged
CargaCuentasContables()
End Sub
#End Region
#Region " CARGA COMBOS | D D L S - C U E N T A S (BANCARIAS-DEPOSITO)"
Private Sub CargaCuentasContables()
If Not (UsuarioActual.Empresa.UsaContabilidad Or UsuarioActual.Empresa.UsaAC) Then
Exit Sub
End If
DdlCtaContable.Items.Clear()
Dim IdCuentaPadre As Integer = If(RBLClasificacionContable.SelectedValue.ToEntero = 1, UsuarioActual.Empresa.Funcionalidad(203).ToEntero, UsuarioActual.Empresa.Funcionalidad(202).ToEntero)
If IdCuentaPadre > 0 Then
Dim ObjContabilidad As New ClsContPAQi(UsuarioActual.Empresa)
If ObjContabilidad.GetCuentasRecursiva(IdCuentaPadre, 1) Then
DdlCtaContable.DataSource = ObjContabilidad.DtResultados
DdlCtaContable.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlCtaContable.DataBind()
UpCtaContable.Update()
Else
Alert("No se cargaron las Cuentas Contables. Por favor recargue la página", TipoMensaje.MsgAdvertencia)
End If
ObjContabilidad.Dispose()
End If
End Sub
Private Sub CargaCuentasBancarias()
DdlCuentaCredito.Items.Clear()
DdlCuentaCredito.DataSource = DtCuentasBancarias.FiltraParametros(String.Format("CveTipoCuenta = {0} OR UsaTarjeta = 1", If(DdlTipoCredito.SelectedValue.ToEntero = 1, 7, 6)))
DdlCuentaCredito.DataBind()
DdlCuentaCredito.Items.Insert(0, New ListItem("Seleccione", "-1"))
End Sub
Protected Sub DdlCuentaCredito_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim ObjCreditos As New ClsBancos
Dim DtTemp As New DataTable
If DdlCuentaCredito.SelectedValue = "-1" Then
LtCCBanco.Text = ""
LtCCCuenta.Text = ""
LtCCLimiteCredito.Text = ""
'LtCCSaldo.Text = ""
Else
If ObjCreditos.GetLineasCreditos(UsuarioActual.CveEmpresa) Then
DtTemp = ObjCreditos.DtResultados.FiltraParametros(String.Format("CveCuenta = {0}", DdlCuentaCredito.SelectedValue.ToString.ToEntero))
If DtTemp.Rows.Count = 1 Then
LtCCBanco.Text = DtTemp(0)("Banco").ToString
LtCCCuenta.Text = DtTemp(0)("NumCuenta").ToString
LtCCLimiteCredito.Text = DtTemp(0)("LimiteCredito").ToString.FormatoNumero
HdnCveProveedor.Value = DtTemp(0)("CveProveedor").ToString
'LtCCSaldo.Text = DtTemp(0)("Saldo").ToString.FormatoNumero
DdlCSTipoMoneda.SelectedValue = DtTemp(0)("CveMoneda").ToString
If DtTemp(0)("UsaTarjeta").ToString = "True" Then
CargaTarjetas()
Else
trTarjetas.Visible = False
End If
Else
Alert("Ocurrio un error al carga la Linea de Crédito. Por favor intente nuevamente", TipoMensaje.MsgError)
End If
Else
Alert("Ocurrio un error al carga la Linea de Crédito. Por favor intente nuevamente", TipoMensaje.MsgError)
End If
End If
End Sub
Private Sub CargaTarjetas()
Dim ObjCreditos As New ClsBancos
ObjCreditos.GetTarjetasCreditos(DdlCuentaCredito.SelectedValue.ToEntero)
DdlTarjetaCredito.DataSource = ObjCreditos.DtResultados
DdlTarjetaCredito.DataBind()
UpCuentaCredito.Update()
trTarjetas.Visible = True
DdlTarjetaCredito.SelectedValueExist(CveCuentaTarjeta)
ObjCreditos.Dispose()
End Sub
Protected Sub CargaCuentasDeposito()
DdlCuentaDeposito.Items.Clear()
DdlCuentaDeposito.DataSource = DtCuentasBancarias.FiltraParametros("CveTipoCuenta <> 7 And CveTipoCuenta <> 6")
DdlCuentaDeposito.DataBind()
DdlCuentaDeposito.Items.Insert(0, New ListItem("Seleccione", "-1"))
End Sub
Protected Sub DdlCuentaDeposito_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim DtTemp As New DataTable
If DdlCuentaDeposito.SelectedValue.ToString = "-1" Then
LtBancoDeposito.Text = ""
LtTipoCuentaDeposito.Text = ""
LtCuentaDeposito.Text = ""
Else
DtTemp = DtCuentasBancarias.FiltraParametros(String.Format("CveCuenta = {0}", DdlCuentaDeposito.SelectedValue.ToString.ToEntero))
If DtTemp.Rows.Count = 1 Then
LtBancoDeposito.Text = DtTemp.Rows(0)("Banco").ToString
LtTipoCuentaDeposito.Text = DtTemp.Rows(0)("TipoCuenta").ToString
LtCuentaDeposito.Text = DtTemp.Rows(0)("NumCuenta").ToString
End If
End If
End Sub
Protected Sub DdlProveedores_SelectedIndexChanged(sender As Object, e As EventArgs)
If DivVinculaAnticipo.Visible = True Then
TxtPagueseA.Text = DdlProveedores.SelectedItem.Text
'UpPagoAnticipo.Update()
End If
End Sub
#End Region
#Region "G U A R D A R - U P D A T E"
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
If CveCredito > 0 Then
If DdlTipoCredito.SelectedValue.ToEntero > 2 Then
UpdateCreditoComplejo()
Else
UpdateCreditoSimple()
End If
Else
If DdlTipoCredito.SelectedValue.ToEntero > 2 Then
GuardaCreditoComplejo()
Else
GuardaCreditoSimple()
End If
End If
End Sub
Private Sub GuardaCreditoSimple()
If DdlTipoCredito.SelectedValue.ToEntero > 1 AndAlso TxtCSTotalCredito.Text.ToString.ToDouble <= 0 Then
Alert("El total del credito debe ser mayor a 0", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjCredito As New ClsBancos
Dim ObjMov As New ClsContabilidad(ObjCredito.IniciaTransacSQL())
Dim ErrorCredito = False
Dim Folio As String = ""
Dim CvePrePoliza As Integer = 0
If CveCredito = -1 Then
Dim TipoCreditoTemp = DdlTipoCredito.SelectedValue.ToEntero
'Credito Revolvente -- ADD IE
If TipoCreditoTemp = 2 AndAlso DdlCuentaDeposito.SelectedValue.ToEntero > 0 Then
Folio = ObjCredito.GetNextFolio(DdlCuentaDeposito.SelectedValue.ToString.ToEntero, 8).ToString
If Folio <> "" Then
CvePrePoliza = ObjMov.AddPrePolizas("Creditos", 2, 0, 0, 1, TxtFechaDeposito.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
CveIE = ObjCredito.AddBancos_IE(DdlCuentaDeposito.SelectedValue.ToString.ToEntero, 8, TxtFechaDeposito.Text.ToDate, Folio, LtBancoDeposito.Text, TxtCSTotalCredito.Text.ToString.ToDouble, 1, 1, "Credito Revolvente", "", True, False, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CveIE < 0 Then
ErrorCredito = True
End If
'If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtCSTotalCredito.Text.ToString.ToDouble, "Crédito", 50, "", Now, 0, -1, CveIE, ImporteMX:=TxtCSTotalCredito.Text.ToString.ToDouble) Then
' ErrorCredito = True
'End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtCSTotalCredito.Text.ToDecimal, "Crédito", 30, "", Now, 0, -1, CveIE, ImporteMX:=TxtCSTotalCredito.Text.ToDecimal) Then
ErrorCredito = True
End If
Else
ErrorCredito = True
End If
End If
'Credito Generico
If Not ErrorCredito Then
Dim CveProveedor As Integer = -1
If HdnCveProveedor.Value.ToEntero > 0 Then
CveProveedor = HdnCveProveedor.Value.ToEntero
End If
CveIE = ObjCredito.AddBancos_IE(DdlCuentaCredito.SelectedValue.ToString.ToEntero, 2, TxtFechaDeposito.Text.ToDate, Folio, LtBancoDeposito.Text, TxtCSTotalCredito.Text.ToString.ToDouble, 1, 1, "Credito Revolvente", "", True, False, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CveIE < 0 Then
ErrorCredito = True
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtCSTotalCredito.Text.ToDecimal, "Crédito", 30, "", Now, 0, -1, CveIE, ImporteMX:=TxtCSTotalCredito.Text.ToDecimal) Then
ErrorCredito = True
End If
If ObjCredito.AddCreditos(TipoCreditoTemp, TxtCSReferencia.Text, TxtCSObservaciones.Text, DdlCuentaCredito.SelectedValue.ToEntero, HdnCveCompra.Value.ToEntero, -1, DdlCSTipoMoneda.SelectedValue.ToEntero, TxtCSFechaInicio.Text.Trim.ToDate, TxtCSFechaVencimiento.Text.Trim.ToDate, TxtCSTasa.Text.Trim.ToDouble, TxtCSSobreTasa.Text.Trim.ToDouble, -1, TxtCSPlazo.Text.ToEntero, CveIE, If(TipoCreditoTemp = 2, TxtCSTotalCredito.Text.ToEntero, TotalCompra), -1, -1, -1, CveProveedor, RBLClasificacionContable.SelectedValue.ToEntero, DdlCtaContable.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCuentaTarjeta:=DdlTarjetaCredito.SelectedValue.ToEntero, AplicaAnticipo:=If(RBLAnticipo.SelectedValue.ToEntero = 1, True, False)) > 0 Then
'Dim Fecha = If(TipoCreditoTemp = 2, TxtCSFechaDeposito.Text.ToDate, TxtCSFechaVencimiento.Text.ToDate)
'For i = 1 To If(TipoCreditoTemp = 2, TxtCSPeriodos.Text.Trim.ToEntero, 1)
'DateAdd("d", TxtPlazo.Text.ToEntero, Fecha)
If Not ObjCredito.AddCreditosDetalle(ObjCredito.CveCredito, TxtCSFechaVencimiento.Text.ToDate, If(TipoCreditoTemp = 2, TxtCSTotalCredito.Text.ToString.ToEntero, TotalCompra), 0.0, 0.0, 0.0, 0.0, 0.0, If(TipoCreditoTemp = 1, 101, 1)) Then
ErrorCredito = True
'Exit For
End If
'Next
Else
ErrorCredito = True
End If
End If
End If
If Not ErrorCredito Then
ObjCredito.Commit()
', TipoMensaje.MsgInformacion, String.Format("document.location.href=""/Bancos/CatCreditos.aspx?CveLineaCredito={0}"";", CveLineaCredito)
Alert("El nuevo Registro se guardó correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Bancos/RepCreditos.aspx"";")
Else
ObjCredito.RollBack()
End If
ObjCredito.Dispose()
ObjMov.Dispose()
End Sub
Private Sub UpdateCreditoSimple()
If DdlTipoCredito.SelectedValue.ToEntero > 1 AndAlso TxtCSTotalCredito.Text.ToString.ToDouble <= 0 Then
Alert("El total del credito debe ser mayor a 0", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjCredito As New ClsBancos
ObjCredito.IniciaTransacSQL()
Dim ErrorCredito = False
If CveCredito > 0 Then
Dim TipoCreditoTemp = DdlTipoCredito.SelectedValue.ToEntero
If ObjCredito.UpdateCreditos(CveCredito, TipoCreditoTemp, TxtCSReferencia.Text, TxtCSObservaciones.Text, DdlCuentaCredito.SelectedValue.ToEntero, HdnCveCompra.Value.ToEntero, -1, DdlCSTipoMoneda.SelectedValue.ToEntero, TxtCSFechaInicio.Text.Trim.ToDate, TxtCSFechaVencimiento.Text.Trim.ToDate, TxtCSTasa.Text.Trim.ToDouble, TxtCSSobreTasa.Text.Trim.ToDouble, -1, TxtCSPlazo.Text.ToEntero, CveIE, If(TipoCreditoTemp = 2, TxtCSTotalCredito.Text.ToEntero, TotalCompra), -1, -1, -1, -1, RBLClasificacionContable.SelectedValue.ToEntero, DdlCtaContable.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCuentaTarjeta:=DdlTarjetaCredito.SelectedValue.ToEntero, AplicaAnticipo:=If(RBLAnticipo.SelectedValue.ToEntero = 1, True, False)) Then
If Not ObjCredito.UpdateCreditosDetalle(ObjCredito.CveCredito, TxtCSFechaVencimiento.Text.ToDate, If(TipoCreditoTemp = 2, TxtCSTotalCredito.Text.ToString.ToEntero, TotalCompra), 0.0, 0.0, 0.0, 0.0, 0.0, If(TipoCreditoTemp = 1, 101, 1)) Then
ErrorCredito = True
End If
Else
ErrorCredito = True
End If
End If
If Not ErrorCredito Then
ObjCredito.Commit()
Alert("El Crédito se Actualizo correctamente.", TipoMensaje.MsgInformacion)
Else
ObjCredito.RollBack()
End If
ObjCredito.Dispose()
End Sub
Private Sub GuardaCreditoComplejo()
Dim TotalAnticipo = TxtVehiculoAnticipo.Text.ToDouble + TxtComisionAnticipo.Text.ToDouble + TxtSeguroAnticipo.Text.ToDouble
If TxtTotalCredito.Text.ToString.ToDouble <= 0 Then
Alert("El total del credito debe ser mayor a 0", TipoMensaje.MsgAdvertencia)
Exit Sub
'ElseIf TotalAnticipo > 0 AndAlso DdlCuentaDeposito.SelectedValue.ToEntero < 0 Then
' Alert("Se tiene que especificar de donde se pago el anticipo.", TipoMensaje.MsgAdvertencia)
' Exit Sub
End If
Dim ObjCredito As New ClsBancos
Dim ObjMov As New ClsContabilidad(ObjCredito.IniciaTransacSQL())
Dim ErrorCredito = False
Dim folio = ""
Dim CveIE = -1
Dim CvePrePoliza = 0
Dim CveMoneda As Integer = 1
Dim FechaVencimiento = DateAdd("m", TxtPlazo.Text.ToDouble, TxtFechaInicio.Text.ToDate)
FechaVencimiento = DateSerial(Year(FechaVencimiento), Month(FechaVencimiento) + 1, 0)
'If (DdlTipoCredito.SelectedValue.ToEntero = 3 Or DdlTipoCredito.SelectedValue.ToEntero = 5) AndAlso HdnCveAF.Value.ToEntero > -1 Then
' Alert("Debe seleccionar un ActivoFijo")
'End If
If CveCredito = -1 Then
''Genera ANTICIPO -- Forma Antigua
'Dim CvePrePoliza As Integer
''Insertar IE -- ANTICIPO
'If TotalAnticipo > 0 Then
' folio = ObjCredito.GetNextFolio(DdlCuentaDeposito.SelectedValue.ToString.ToEntero, 8).ToString
' If folio <> "" Then
' CvePrePoliza = ObjMov.AddPrePolizas("Banc", 2, TotalAnticipo, TotalAnticipo, 1, TxtFechaDeposito.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
' CveIE = ObjCredito.AddBancos_IE(DdlCuentaDeposito.SelectedValue.ToString.ToEntero, 8, TxtFechaDeposito.Text.ToDate, folio, TxtPagueseA.Text, TotalAnticipo, CveMoneda, 1, TxtReferencia.Text.Trim, "", True, False, 0, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
' If CveIE < 0 Then
' ErrorCredito = True
' End If
' Else
' ErrorCredito = True
' End If
'End If
'Insertar en Creditos
If Not ErrorCredito Then
CveCredito = ObjCredito.AddCreditos(DdlTipoCredito.SelectedValue.ToEntero, TxtReferencia.Text, TxtObservaciones.Text, -1, -1, -1, DdlTipoMoneda.SelectedValue.ToEntero, TxtFechaInicio.Text.ToString.ToDate, FechaVencimiento, TxtTasa.Text.Trim.ToDouble, TxtSobreTasa.Text.Trim.ToDouble, TxtIVA.Text.ToDouble / 100,
TxtPlazo.Text.Trim.ToEntero, CveIE, TxtVehiculoValor.Text.ToString.ToDouble, TxtComisionValor.Text.ToString.ToDouble, TxtSeguroMensual.Text.ToString.ToDouble, TxtOtrosGastosValor.Text.ToString.ToDouble,
DdlProveedores.SelectedValue.ToEntero, RBLClasificacionContable.SelectedValue.ToEntero, DdlCtaContable.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, AplicaAnticipo:=If(RBLAnticipo.SelectedValue.ToEntero = 1, True, False),
CreditoAnticipo:=TxtVehiculoAnticipo.Text.ToDouble, ComisionAnticipo:=TxtComisionAnticipo.Text.ToDouble, SeguroAnticipo:=TxtSeguroAnticipo.Text.ToDouble, OtrosGastosAnticipo:=TxtOtrosGastosAnticipo.Text.ToDouble, FondoGarantia:=TxtFondoGarantia.Text.ToDouble, SeguroValor:=TxtSeguroValor.Text.ToDouble, TipoInteres:=ChkTipoInteres.Checked)
If CveCredito > 0 Then
For Each gvr As GridViewRow In GvTA.Rows
If Not ObjCredito.AddCreditosDetalle(CveCredito, gvr.FCTextBox("TxtFecha").Text.ToDate, gvr.FCTextBox("TxtCapital").Text.ToDouble, gvr.FCTextBox("TxtIntereses").Text.ToDouble,
gvr.FCTextBox("TxtSeguro").Text.ToDouble, gvr.FCTextBox("TxtIVACapital").Text.ToDouble,
gvr.FCTextBox("TxtIVAIntereses").Text.ToDouble, gvr.FCTextBox("TxtIVASeguro").Text.ToDouble, 1) Then
ErrorCredito = True
Exit For
End If
Next
Else
ErrorCredito = True
End If
End If
'INSERTA AF
If Not ErrorCredito Then
For Each dr As DataRow In DtAF.Rows
If Not ObjCredito.AddActivosFijosCreditos(CveCredito, dr("CveActivoFijo").ToString.ToEntero) Then
ErrorCredito = True
Exit For
End If
Next
End If
'INSERTA ANTICIPOS - IE
If Not ErrorCredito Then
For Each dr As DataRow In DtIE.Rows
If Not ObjCredito.AddAnticiposCreditos(CveCredito, dr("CveIE").ToString.ToEntero) Then
ErrorCredito = True
Exit For
End If
Next
End If
''Genera ANTICIPO -- Forma Antigua
''Insertar en Prepoliza
'If Not ErrorCredito AndAlso CveIE > 0 Then
' If CvePrePoliza > 0 Then
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtVehiculoAnticipo.Text.ToDouble, "Enganche", 53, "", Now, 0, -1, CveIE) Then
' ErrorCredito = True
' End If
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtComisionAnticipo.Text.ToDouble, "Comisión", 54, "", Now, 0, -1, CveIE) Then
' ErrorCredito = True
' End If
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtSeguroAnticipo.Text.ToDouble, "Seguro", 55, "", Now, 0, -1, CveIE) Then
' ErrorCredito = True
' End If
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtFondoGarantia.Text.ToDouble, "Fondo en Garantía", 58, "", Now, 0, -1, CveIE) Then
' ErrorCredito = True
' End If
' If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TotalAnticipo, "Banco", 30, "", Now, 0, -1, CveIE) Then
' ErrorCredito = True
' End If
' Else
' ErrorCredito = True
' End If
'End If
Else
''UPDATE
'If ObjCredito.UpdateCreditos(-1, -1, HdnCveAF.Value.ToEntero, FechaVencimiento, TxtTasa.Text.Trim.ToDouble, TxtSobreTasa.Text.Trim.ToDouble, "-1", 2, TxtPlazo.Text.Trim.ToEntero, CveCredito) Then
' Alert("Los Cambios se Guardaron Correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Bancos/RepCreditos.aspx"";")
' ObjCredito.Commit()
' ObjCredito.Dispose()
' Exit Sub
'Else
' ErrorCredito = True
'End If
End If
If Not ErrorCredito Then
ObjCredito.Commit()
', TipoMensaje.MsgInformacion, "document.location.href=""/Bancos/RepCreditos.aspx"";"
Alert("El nuevo Registro se guardó correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Bancos/RepCreditos.aspx"";")
Else
ObjCredito.RollBack()
Alert("Ocurrio un error al registrar el Crédito.", TipoMensaje.MsgError)
End If
ObjCredito.Dispose()
End Sub
Private Sub UpdateCreditoComplejo()
Dim TotalAnticipo = TxtVehiculoAnticipo.Text.ToDouble + TxtComisionAnticipo.Text.ToDouble + TxtSeguroAnticipo.Text.ToDouble
Dim TotalAnticipoVinculado = 0.0
If TxtTotalCredito.Text.ToString.ToDouble <= 0 Then
Alert("El total del credito debe ser mayor a 0", TipoMensaje.MsgAdvertencia)
Exit Sub
'ElseIf TotalAnticipo > 0 AndAlso DdlCuentaDeposito.SelectedValue.ToEntero < 0 Then
' Alert("Se tiene que especificar de donde se pagó el anticipo.", TipoMensaje.MsgAdvertencia)
' Exit Sub
End If
'RMF. Créditos sin desglosar el interes, y lo ingresa todo en capital, ignorar condición
If Not UsuarioActual.CveEmpresa.Contiene(4, 7, 11, 12, 126) Then
Dim TotalDetalle As Double = GvTA.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCTextBox("TxtCapital").Text.ToDouble + gvr.FCTextBox("TxtSeguro").Text.ToDouble)
If TotalDetalle > TxtTotalCredito.Text.ToString.ToDouble + 1 Or TotalDetalle < TxtTotalCredito.Text.ToString.ToDouble - 1 Then
Alert($"El total de capital (más seguro financiado) no cuadra con el total a financiar, favor de corregir la información(${TotalDetalle.FormatoNumero})", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
'VALIDA ANTICIPOS VINCULADOS
For Each dr As DataRow In DtIE.FiltraParametros("Estatus IN (0,1) Or Estatus Is null").Rows
TotalAnticipoVinculado += dr("Importe").ToString.ToDouble
Next
If TotalAnticipoVinculado > TotalAnticipo Then
Alert("El anticipo vinculado no puede exceder el anticipo especificado.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjCredito As New ClsBancos
ObjCredito.IniciaTransacSQL()
Dim ErrorCredito = False
'Dim CveIE = -1
Dim CveMoneda As Integer = 1
Dim FechaVencimiento = DateAdd("m", TxtPlazo.Text.ToDouble, TxtFechaInicio.Text.ToDate)
FechaVencimiento = DateSerial(Year(FechaVencimiento), Month(FechaVencimiento) + 1, 0)
If CveCredito > 0 Then
If ObjCredito.UpdateCreditos(CveCredito, DdlTipoCredito.SelectedValue.ToEntero, TxtReferencia.Text, TxtObservaciones.Text, -1, -1, -1, DdlTipoMoneda.SelectedValue.ToEntero, TxtFechaInicio.Text.ToString.ToDate, FechaVencimiento, TxtTasa.Text.Trim.ToDouble, TxtSobreTasa.Text.Trim.ToDouble, TxtIVA.Text.ToDouble / 100,
TxtPlazo.Text.Trim.ToEntero, -1, TxtVehiculoValor.Text.ToString.ToDouble, TxtComisionValor.Text.ToString.ToDouble, TxtSeguroMensual.Text.ToString.ToDouble, TxtOtrosGastosValor.Text.ToString.ToDouble,
DdlProveedores.SelectedValue.ToEntero, RBLClasificacionContable.SelectedValue.ToEntero, DdlCtaContable.SelectedValue.ToEntero, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, AplicaAnticipo:=If(RBLAnticipo.SelectedValue.ToEntero = 1, True, False),
CreditoAnticipo:=TxtVehiculoAnticipo.Text.ToDouble, ComisionAnticipo:=TxtComisionAnticipo.Text.ToDouble, SeguroAnticipo:=TxtSeguroAnticipo.Text.ToDouble, OtrosGastosAnticipo:=TxtOtrosGastosAnticipo.Text.ToDouble, FondoGarantia:=TxtFondoGarantia.Text.ToDouble, SeguroValor:=TxtSeguroValor.Text.ToDouble, TipoInteres:=ChkTipoInteres.Checked) Then
If RegeneraTablaAmortizacion Then
If ObjCredito.RemoveCreditosDetalleALL(CveCredito) Then
For Each gvr As GridViewRow In GvTA.Rows
If Not ObjCredito.AddCreditosDetalle(CveCredito, gvr.FCTextBox("TxtFecha").Text.ToString.ToDate, gvr.FCTextBox("TxtCapital").Text.ToString.ToDouble, gvr.FCTextBox("TxtIntereses").Text.ToString.ToDouble,
gvr.FCTextBox("TxtSeguro").Text.ToString.ToDouble, gvr.FCTextBox("TxtIVACapital").Text.ToString.ToDouble,
gvr.FCTextBox("TxtIVAIntereses").Text.ToString.ToDouble, gvr.FCTextBox("TxtIVASeguro").Text.ToString.ToDouble, 1) Then
ErrorCredito = True
Exit For
End If
Next
Else
ErrorCredito = True
End If
Else
For Each gvr As GridViewRow In GvTA.Rows
If Not ObjCredito.UpdateCreditosDetalle(gvr.DataKey("CveCreditoDetalle").ToString.ToEntero, gvr.FCTextBox("TxtFecha").Text.ToString.ToDate, gvr.FCTextBox("TxtCapital").Text.ToString.ToDouble, gvr.FCTextBox("TxtIntereses").Text.ToString.ToDouble,
gvr.FCTextBox("TxtSeguro").Text.ToString.ToDouble, gvr.FCTextBox("TxtIVACapital").Text.ToString.ToDouble,
gvr.FCTextBox("TxtIVAIntereses").Text.ToString.ToDouble, gvr.FCTextBox("TxtIVASeguro").Text.ToString.ToDouble, -1) Then
ErrorCredito = True
Exit For
End If
Next
End If
Else
ErrorCredito = True
End If
'INSERTA AF
If Not ErrorCredito Then
For Each dr As DataRow In DtAF.FiltraParametros("Estatus IN (1,2)").Rows
If dr("Estatus").ToString.ToEntero = 1 Then
If Not ObjCredito.AddActivosFijosCreditos(CveCredito, dr("CveActivoFijo").ToString.ToEntero) Then
ErrorCredito = True
Exit For
End If
Else
If Not ObjCredito.RemoveActivosFijosCreditos(CveCredito, dr("CveActivoFijo").ToString.ToEntero) Then
ErrorCredito = True
Exit For
End If
End If
Next
End If
'INSERTA ANTICIPOS - IE
If Not ErrorCredito Then
For Each dr As DataRow In DtIE.FiltraParametros("Estatus IN (1,2)").Rows
If dr("Estatus").ToString.ToEntero = 1 Then
If Not ObjCredito.AddAnticiposCreditos(CveCredito, dr("CveIE").ToString.ToEntero) Then
ErrorCredito = True
Exit For
End If
Else
If Not ObjCredito.RemoveAnticiposCreditos(CveCredito, dr("CveIE").ToString.ToEntero) Then
ErrorCredito = True
Exit For
End If
End If
Next
End If
End If
If Not ErrorCredito Then
ObjCredito.Commit()
', TipoMensaje.MsgInformacion, "document.location.href=""/Bancos/RepCreditos.aspx"";"
Alert("El Crédito se Actualizo correctamente.", TipoMensaje.MsgInformacion)
Else
ObjCredito.RollBack()
Alert("Ocurrio un error al Actualizar el Crédito.", TipoMensaje.MsgError)
End If
ObjCredito.Dispose()
End Sub
#End Region
#Region " ELIMINAR "
Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click
Dim Cred As New ClsBancos
If Cred.RemoveCreditos(CveCredito) Then
Alert("Movimiento Eliminado", TipoMensaje.MsgInformacion)
End If
Cred.Dispose()
End Sub
#End Region
#Region "G E N E R A - T A B L A - A M O R T I Z A C I O N"
Protected Sub BtnGenerar_Click(sender As Object, e As EventArgs) Handles BtnGenerar.Click
GenerarTabla()
End Sub
Private Sub CreaDTAmortizacion()
If DTAmortizacion Is Nothing Then
DTAmortizacion = New DataTable
DTAmortizacion.Columns.Add("Periodo", GetType(Integer))
DTAmortizacion.Columns.Add("Fecha", GetType(Date))
DTAmortizacion.Columns.Add("Capital", GetType(Double))
DTAmortizacion.Columns.Add("Intereses", GetType(Double))
DTAmortizacion.Columns.Add("Seguro", GetType(Double))
DTAmortizacion.Columns.Add("IVACapital", GetType(Double))
DTAmortizacion.Columns.Add("IVAIntereses", GetType(Double))
DTAmortizacion.Columns.Add("IVASeguro", GetType(Double))
DTAmortizacion.Columns.Add("IVA", GetType(Double))
DTAmortizacion.Columns.Add("Mensualidad", GetType(Double))
DTAmortizacion.Columns.Add("SaldoInsoluto", GetType(Double))
DTAmortizacion.Columns.Add("FechaPago", GetType(Date))
DTAmortizacion.Columns.Add("CveCreditoDetalle", GetType(Integer))
DTAmortizacion.Columns.Add("Estatus", GetType(Integer)) 'solo para el get
DTAmortizacion.Columns.Add("CveIE", GetType(Integer)) 'solo para el get
DTAmortizacion.Columns.Add("CveCompra", GetType(Integer)) 'solo para el get
DTAmortizacion.Columns.Add("CveCompraInteres", GetType(Integer)) 'solo para el get
DTAmortizacion.Columns.Add("MensualidadOriginal", GetType(Double)) 'solo para el get - agregadas el 20 Mayo 2017, ya lo traia get pero no el generar
DTAmortizacion.Columns.Add("ImporteGarantia", GetType(Double)) 'solo para el get - agregadas el 20 Mayo 2017, ya lo traia get pero no el generar
DTAmortizacion.Columns.Add("ImportePago", GetType(Double))
End If
End Sub
Protected Sub GenerarTabla()
If TxtTotalCredito.Text.ToString.ToDouble <= 0 Then
Alert("El total del credito debe ser mayor a 0", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim Tasa As Double = 0
If TxtMensualidad.Text.ToDouble <= 0 Then
Dim Mensualidad = Pmt((TxtTasa.Text.ToDouble / 100) / 12, TxtPlazo.Text.ToDouble, TxtTotalCredito.Text.ToDouble) * -1
TxtMensualidad.Text = Mensualidad.ToString.FormatoNumero
End If
Try
Tasa = Rate(TxtPlazo.Text.ToEntero, -1 * (TxtMensualidad.Text.ToDouble), TxtTotalCredito.Text.ToDouble)
Catch ex As Exception
Alert("La tasa no se puede calcular con los datos proporcionados. Por favor corrija los datos", TipoMensaje.MsgAdvertencia)
End Try
TxtTasa.ToolTip = Tasa.ToString
'UpRegistro.Update()
'TASA 0 PARA ARRENDAMIENTO PURO
Tasa = If(CveTipoCredito = 4, 0, Tasa)
Dim Row As DataRow = Nothing
DTAmortizacion.Rows.Clear()
For i = 1 To TxtPlazo.Text.ToEntero
Row = DTAmortizacion.NewRow()
'Datos en comun
Row("Periodo") = DTAmortizacion.Rows.Count + 1
Row("Fecha") = TxtFechaInicio.Text.ToDate.AddMonths(i - 1)
Row("Mensualidad") = TxtMensualidad.Text.ToDouble
Row("Seguro") = TxtSeguroMensual.Text.ToDouble
If CveTipoCredito = 4 Or DdlTipoCredito.SelectedValue.ToEntero = 4 Then
Row("Intereses") = 0.0
Row("Capital") = TxtMensualidad.Text.ToDouble / ((TxtIVA.Text.ToDouble / 100) + 1)
Else
Row("Intereses") = IPmt(Tasa, i.ToString.ToDouble, TxtPlazo.Text.ToDouble, TxtTotalCredito.Text.ToDouble) * -1
Row("Capital") = PPmt(Tasa, i, TxtPlazo.Text.ToDouble, TxtTotalCredito.Text.ToDouble) * -1 'TxtMensualidad.Text.ToDouble - Row("Intereses").ToString.ToDouble
' Row("IVA") = 0.0
End If
Row("SaldoInsoluto") = If(i > 1, DTAmortizacion(i - 2)("SaldoInsoluto").ToString.ToDouble, TxtTotalCredito.Text.ToDouble) - If(i > 1, DTAmortizacion(i - 2)("Capital").ToString.ToDouble, 0)
Row("IVACapital") = Row("Capital").ToString.ToDouble * TxtIVA.Text.ToDouble / 100
Row("IVAIntereses") = Row("Intereses").ToString.ToDouble * TxtIVA.Text.ToDouble / 100
Row("IVASeguro") = Row("Seguro").ToString.ToDouble * TxtIVA.Text.ToDouble / 100
Row("ImportePago") = 0
DTAmortizacion.Rows.Add(Row)
Next
RegeneraTablaAmortizacion = True
GvTA.DataSource = DTAmortizacion
GvTA.DataBind()
RowTA.Visible = True
UpGVDocumentos.Update()
BtnGuardar.Enabled = True
UpGuardar.Update()
End Sub
Protected Sub GvTA_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvTA.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCTextBox("TxtCapital").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CTabla({0}, 1);", e.Row.RowIndex))
e.Row.FCTextBox("TxtIntereses").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CTabla({0},2);", e.Row.RowIndex))
e.Row.FCTextBox("TxtSeguro").Attributes.Add("onkeyup", String.Format("FormatoMoneda(this);CTabla({0},3);", e.Row.RowIndex))
If CveCredito > 0 Then
If e.Row.DBCampo("Estatus").ToEntero = 1 Or e.Row.DBCampo("Estatus").ToEntero = 4 Or e.Row.DBCampo("Estatus").ToEntero = 101 Or e.Row.DBCampo("Estatus").ToEntero = 102 Then
e.Row.FCHyperLink("HLAccion").NavigateUrl = String.Format("/Bancos/IE.aspx?Opcion=EGSCREDITO&CveCredito={0}&CveCreditoDetalle={1}", CveCredito, e.Row.DBCampo("CveCreditoDetalle"))
e.Row.FCHyperLink("HLAccion").Text = "<img src='/Imagenes/Money_Add.png' alt='Pagar periodo' />"
ElseIf e.Row.DBCampo("Estatus").ToEntero = 2 Or e.Row.DBCampo("Estatus").ToEntero = 103 Then
BtnGenerar.Enabled = False
Else
'e.Row.FCHyperLink("HLAccion").NavigateUrl = "#"
e.Row.FCHyperLink("HLAccion").Text = ""
End If
Else
GvTA.Columns(10).Visible = False
End If
End If
If e.Row.RowType = DataControlRowType.Footer Then
If GvTA.DataSource IsNot Nothing Then
e.Row.FCLabel("LblTot2").Text = DirectCast(GvTA.DataSource, DataTable).SUM("Capital").FormatoNumero
e.Row.FCLabel("LblTot3").Text = DirectCast(GvTA.DataSource, DataTable).SUM("Intereses").FormatoNumero
e.Row.FCLabel("LblTot4").Text = DirectCast(GvTA.DataSource, DataTable).SUM("Seguro").FormatoNumero
e.Row.FCLabel("LblTot5").Text = DirectCast(GvTA.DataSource, DataTable).SUM("IVACapital").FormatoNumero
e.Row.FCLabel("LblTot6").Text = DirectCast(GvTA.DataSource, DataTable).SUM("IVAIntereses").FormatoNumero
e.Row.FCLabel("LblTot7").Text = DirectCast(GvTA.DataSource, DataTable).SUM("IVASeguro").FormatoNumero
End If
End If
End Sub
#End Region
#Region "V I N C U L A - A F"
Private Sub CreaDtAF()
DtAF = New DataTable
DtAF.Columns.Add("CveCredito", GetType(Integer))
DtAF.Columns.Add("CveActivoFijo", GetType(Integer))
DtAF.Columns.Add("IdCtaContable", GetType(Integer))
DtAF.Columns.Add("Codigo", GetType(String))
DtAF.Columns.Add("Descripcion", GetType(String))
DtAF.Columns.Add("TipoActivoFijo", GetType(String))
DtAF.Columns.Add("Estatus", GetType(Integer))
DtAF.Columns.Add("valorCompra", GetType(Double))
End Sub
Protected Sub ImgAF_Click(sender As Object, e As ImageClickEventArgs)
RegistraScript(String.Format("AbrirVentana('/AF/PopUpBuscarAF.aspx?Tipo=C',750,500,'N');", "aa"))
End Sub
Protected Sub BtnVincularAF_Click(sender As Object, e As EventArgs)
VinculaAF()
End Sub
Private Sub CargarAF()
'If HdnCveAF.Value <> "-1" AndAlso IsNumeric(HdnCveAF.Value) AndAlso HdnCveAF.Value.ToEntero > 0 Then
' Dim ObjAF As New ClsAF
' If ObjAF.GetActivosFijos(HdnCveAF.Value.ToString.ToEntero, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "") Then
' If DtAF Is Nothing Then
' DtAF = ObjAF.DtResultados.Clone
' End If
' Dim RowAF2 = ObjAF.DtResultados.Rows(0)
' TxtAF.Text = RowAF2("CodDesc").ToString
' LtCodigoAF.Text = RowAF2("Codigo").ToString
' LtDescripcionAF.Text = RowAF2("Descripcion").ToString
' LtFechaAF.Text = RowAF2("FechaCompra").ToString.Substring(1, 10)
' LtValorCompraAF.Text = RowAF2("ValorCompra").ToString.FormatoNumero
' BtnConfimaAF.Visible = True
' End If
' ObjAF.Dispose()
'Else
'End If
End Sub
Protected Sub BtnConfimaAF_Click(sender As Object, e As EventArgs)
VinculaAF()
End Sub
Private Sub VinculaAF()
Dim RowAF As DataRow
Dim ObjAF As New ClsAF
If ObjAF.GetActivosFijos(HdnCveAF.Value.ToString.ToEntero, UsuarioActual.CveEmpresa, "-1", "-1", -1, -1, "-1", -1, -1, -1, -1, -1, "", -1) AndAlso ObjAF.DtResultados.Rows(0) IsNot Nothing Then
RowAF = ObjAF.DtResultados.Rows(0)
Else
Alert("Ocurrió un error al vincular el Activo Fijo. Por favor vuelva a intentar.", TipoMensaje.MsgError)
Exit Sub
End If
ObjAF.Dispose()
Dim Repetido = False
'Valida si ya esta vinculado el AF
For Each dr As DataRow In DtAF.Rows
If dr("CveActivoFijo").ToString = RowAF("CveActivoFijo").ToString Then
Repetido = True
Exit For
End If
Next
If Repetido Then
'Valida si esta escondido
For Each dr As DataRow In DtAF.FiltraParametros("Estatus IN (2,3)").Rows
If dr("CveActivoFijo").ToString = RowAF("CveActivoFijo").ToString Then
dr("Estatus") = If(dr("Estatus").ToString.ToEntero = 2, 0, 1)
Repetido = False
Exit For
End If
Next
If Repetido Then
Alert("El Activo Fijo que intenta vincular ya se encuentra vinculado.", TipoMensaje.MsgAdvertencia)
End If
Else
'DtAF.ImportRow(RowAF)
Dim Row As DataRow = Nothing
Row = DtAF.NewRow()
Row("CveCredito") = -1
Row("CveActivoFijo") = RowAF("CveActivoFijo")
Row("IdCtaContable") = RowAF("Cuenta")
Row("Codigo") = RowAF("Codigo")
Row("Descripcion") = RowAF("Descripcion")
Row("TipoActivoFijo") = RowAF("TipoActivoFijo")
Row("valorCompra") = RowAF("valorCompra")
Row("Estatus") = 1
DtAF.Rows.Add(Row)
End If
''Limpia
'TxtAF.Text = ""
'LtCodigoAF.Text = ""
'LtDescripcionAF.Text = ""
'LtFechaAF.Text = ""
'LtValorCompraAF.Text = ""
GvAF.DataSource = DtAF.FiltraParametros("Estatus IN (0,1) OR Estatus is null")
GvAF.DataBind()
UpActivoFijo.Update()
'BtnConfimaAF.Visible = False
End Sub
Protected Sub GvAF_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvAF.RowDeleting
Dim DbRow As DataRow = Nothing
DbRow = DtAF.Rows(e.RowIndex)
DbRow("Estatus") = If(DbRow("Estatus").ToString.ToEntero = 0, 2, -1)
'Elimina el agrega en el momento
If DbRow("Estatus").ToString.ToEntero = -1 Then
DtAF.Rows.Remove(DbRow)
End If
GvAF.DataSource = DtAF.FiltraParametros("Estatus IN (0,1) OR Estatus is null")
GvAF.DataBind()
End Sub
#End Region
#Region " V I N C U L A - A N T I C I P O - I E"
Private Sub CreaDtIE()
DtIE = New DataTable
DtIE.Columns.Add("CveCredito", GetType(Integer))
DtIE.Columns.Add("CveIE", GetType(Integer))
DtIE.Columns.Add("CveCuenta", GetType(Integer))
DtIE.Columns.Add("NumCuenta", GetType(String))
DtIE.Columns.Add("Folio", GetType(Integer))
DtIE.Columns.Add("FechaDocumento", GetType(String))
DtIE.Columns.Add("Importe", GetType(Double))
DtIE.Columns.Add("Moneda", GetType(String))
DtIE.Columns.Add("Estatus", GetType(Integer))
End Sub
Protected Sub ImgAnticipo_Click(sender As Object, e As ImageClickEventArgs)
RegistraScript(String.Format("AbrirVentana('/Bancos/PopUpBuscarIE.aspx?OPCION=Creditos',750,500,'N');", "aa"))
End Sub
Protected Sub BtnVincularIE_Click(sender As Object, e As EventArgs)
VinculaIE()
End Sub
Private Sub CargaIE()
If HdnCveIE.Value <> "-1" AndAlso IsNumeric(HdnCveIE.Value) AndAlso HdnCveIE.Value.ToEntero > 0 Then
Dim ObjBancosIE As New ClsBancos
If ObjBancosIE.GetBancosIE(HdnCveIE.Value.ToString.ToEntero, UsuarioActual.CveEmpresa) Then
If DtIE Is Nothing Then
DtIE = ObjBancosIE.DtResultados.Clone
End If
Dim RowIE = ObjBancosIE.DtResultados.Rows(0)
LtBancoIE.Text = RowIE("Banco").ToString
LtCuentaIE.Text = RowIE("NumCuenta").ToString
LtFolioIE.Text = RowIE("Folio").ToString
LtFechaIE.Text = RowIE("FechaDocumento").ToString.Substring(1, 10)
LtImporteIE.Text = RowIE("Importe").ToString.FormatoNumero
LtMonedaIE.Text = RowIE("Moneda").ToString.FormatoNumero
BtnConfirmaIE.Visible = True
End If
ObjBancosIE.Dispose()
Else
End If
End Sub
Protected Sub BtnConfirmaIE_Click(sender As Object, e As EventArgs)
VinculaIE()
End Sub
Private Sub VinculaIE()
Dim RowIE As DataRow = Nothing
Dim ObjBancosIE As New ClsBancos
If ObjBancosIE.GetBancosIE(HdnCveIE.Value.ToString.ToEntero, UsuarioActual.CveEmpresa) AndAlso ObjBancosIE.DtResultados.Rows IsNot Nothing Then
RowIE = ObjBancosIE.DtResultados.Rows(0)
End If
ObjBancosIE.Dispose()
Dim Repetido = False
Dim TotalAnticipoVinculado = 0.0
Dim TotalAnticipo = TxtVehiculoAnticipo.Text.ToDouble + TxtComisionAnticipo.Text.ToDouble + TxtSeguroAnticipo.Text.ToDouble
For Each dr As DataRow In DtIE.FiltraParametros("Estatus IN (0,1) OR Estatus is null").Rows
TotalAnticipoVinculado += dr("Importe").ToString.ToDouble
Next
TotalAnticipoVinculado += RowIE("Importe").ToString.ToDouble
If TotalAnticipoVinculado > TotalAnticipo Then
Alert("El anticipo vinculado no puede exceder el anticipo especificado.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'Valida si ya esta vinculado el Anticipo
For Each dr As DataRow In DtIE.Rows
If dr("CveIE").ToString = RowIE("CveIE").ToString Then
Repetido = True
Exit For
End If
Next
If Repetido Then
'Valida si esta escondido
For Each dr As DataRow In DtIE.FiltraParametros("Estatus IN (2,3)").Rows
If dr("CveIE").ToString = RowIE("CveIE").ToString Then
dr("Estatus") = If(dr("Estatus").ToString.ToEntero = 2, 0, 1)
Repetido = False
Exit For
End If
Next
If Repetido Then
Alert("El Anticipo que intenta vincular ya se encuentra vinculado.", TipoMensaje.MsgAdvertencia)
End If
Else
'DtIE.ImportRow(RowIE)
Dim Row As DataRow = Nothing
Row = DtIE.NewRow()
Row("CveCredito") = -1
Row("CveIE") = RowIE("CveIE")
Row("CveCuenta") = RowIE("CveCuenta")
Row("NumCuenta") = RowIE("NumCuenta")
Row("Folio") = RowIE("Folio")
Row("FechaDocumento") = RowIE("FechaDocumento")
Row("Importe") = RowIE("Importe")
Row("Moneda") = RowIE("Moneda")
Row("Estatus") = 1
DtIE.Rows.Add(Row)
End If
'Limpia
LtBancoIE.Text = ""
LtCuentaIE.Text = ""
LtFolioIE.Text = ""
LtFechaIE.Text = ""
LtImporteIE.Text = ""
LtMonedaIE.Text = ""
GvIE.DataSource = DtIE.FiltraParametros("Estatus IN (0,1) OR Estatus is null")
GvIE.DataBind()
BtnConfirmaIE.Visible = False
RegistraScript("Sumador(1);")
End Sub
Protected Sub GvIE_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvIE.RowDeleting
Dim DbRow As DataRow = Nothing
DbRow = DtIE.Rows(e.RowIndex)
DbRow("Estatus") = If(DbRow("Estatus").ToString.ToEntero = 0, 2, -1)
'Elimina el agrega en el momento
If DbRow("Estatus").ToString.ToEntero = -1 Then
DtIE.Rows.Remove(DbRow)
End If
GvIE.DataSource = DtIE.FiltraParametros("Estatus IN (0,1) OR Estatus is null")
GvIE.DataBind()
End Sub
#End Region
#Region "V I N C U L A - C O M P R A"
Protected Sub ImgBtnBuscarOC_Click(sender As Object, e As ImageClickEventArgs) Handles ImgBtnBuscarCompra.Click
RegistraScript(String.Format("AbrirVentana('/Compras/PopUpBuscarFolioC.aspx?opt=Fact',750,500,'N');", "aa"))
End Sub
Protected Sub BtnBuscarCompra_Click(sender As Object, e As EventArgs) Handles BtnBuscarCompra.Click
VinculaCompra()
End Sub
Private Sub VinculaCompra()
If HdnCveCompra.Value <> "-1" AndAlso IsNumeric(HdnCveCompra.Value) AndAlso HdnCveCompra.Value.ToEntero > 0 Then
Dim ObjCompras As New ClsCompras
If ObjCompras.GetCompras(HdnCveCompra.Value.ToEntero, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then
LtlProveedor.Text = ObjCompras.DtResultados.Rows(0)("RazonSocial").ToString
LtlFecha.Text = ObjCompras.DtResultados.Rows(0)("Fecha").ToString.ToDate.ToShortDateString
LtlSerieFolio.Text = If(ObjCompras.DtResultados.Rows(0)("RazonSocial").ToString.Length > 0, ObjCompras.DtResultados.Rows(0)("Serie").ToString & "-" & ObjCompras.DtResultados.Rows(0)("Folio").ToString, ObjCompras.DtResultados.Rows(0)("Folio").ToString)
CveCompra = HdnCveCompra.Value.ToEntero
TotalCompra = ObjCompras.DtResultados.Rows(0)("Total").ToString.ToDouble
End If
ObjCompras.Dispose()
Else
End If
End Sub
#End Region
#Region " APLICAR GARANTIA "
Protected Sub GvAplicarGarantia_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCTextBox("TxtPago").Attributes.Add("onkeyup", String.Format("ValidaCantidad({0},{1});", e.Row.FCTextBox("TxtPago").ClientID, e.Row.DBCampo("Mensualidad")))
End If
End Sub
Protected Sub BtnAplicarGarantia_Click(sender As Object, e As EventArgs)
Dim ImporteVinculado = 0.0
For Each Gvr As GridViewRow In GvAplicarGarantia.Rows
If Gvr.FCTextBox("TxtPago").Text.ToDecimal > 0 Then
ImporteVinculado += Gvr.FCTextBox("TxtPago").Text.ToDouble
End If
Next
If ImporteVinculado > LbFondoGarantía.Text.ToDouble Then
Alert("El importe a aplicar de garantia debe ser menor o igual al fondo en garantía. Rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjBancos As New ClsBancos
ObjBancos.IniciaTransacSQL()
Dim TieneError = False
For Each Gvr As GridViewRow In GvAplicarGarantia.Rows
If Gvr.FCTextBox("TxtPago").Text.ToDecimal > 0 Then
If Not ObjBancos.AplicarGarantiaCreditos(Gvr.DataKey("CveCreditoDetalle").ToString.ToEntero, Gvr.FCTextBox("TxtPago").Text.ToDouble) Then
TieneError = True
Exit For
End If
End If
Next
If Not TieneError Then
ObjBancos.Commit()
Alert("Se aplico correctamente el fondo de garantía al crédito")
Else
ObjBancos.RollBack()
Alert("Ocurrió un error al aplicar el fondo de garantia al crédito. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ObjBancos.Dispose()
End Sub
#End Region
#Region " APLICAR SALDO "
Protected Sub BtnAplicarSaldo_Click(sender As Object, e As EventArgs)
'If Not DdlCtaContable.SelectedValue.ToEntero > 0 Then
' Alert("Es necesario indicar la cuenta contable del crédito en la sección de <b>""Entidad Financiera""</b>. ", TipoMensaje.MsgAdvertencia)
' Exit Sub
'End If
Dim ObjContabilidad As New ClsContabilidad()
Dim ObjProveedor As New ClsCompProveedores(ObjContabilidad.IniciaTransacSQL())
Dim ObjBancos As New ClsBancos(ObjContabilidad.IniciaTransacSQL())
Dim ErrorPrePoliza = False
Dim CvePrePoliza = 0
'GENERA PREPOLIZA
If ObjContabilidad.GetPlantillaConceptos(UsuarioActual.CveEmpresa, 69) AndAlso ObjContabilidad.DtResultados.Rows.Count > 0 Then
Dim DtPlantilla = ObjContabilidad.DtResultados
Dim importeMovimiento = 0.0D
Dim ConceptoContable = 0
Dim TipoMovimiento = False
Dim IdCtaContable = 0
Dim Concepto = ""
Dim Referencia = $"Crédito: {TxtReferencia.Text}"
Dim FechaMovimiento = Now.ToDate
CvePrePoliza = ObjContabilidad.AddPrePolizas("Creditos/RegistrodeRegistro", 69, TxtCSTotalCredito.Text.ToDouble, TxtCSTotalCredito.Text.ToDouble, DdlCSTipoMoneda.SelectedValue.ToEntero, FechaMovimiento, $"Crédito: {TxtReferencia.Text}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
Dim ImporteDocXPagar = TxtTotalCredito.Text.ToDecimal
Dim CveActivoFijo = -1
Dim CveProveedor = -1
Dim CveCreditoPrePoliza = -1
If CvePrePoliza > 0 Then
For Each Row As DataRow In DtPlantilla.Rows
ConceptoContable = Row("CveConcepto").ToString.ToEntero
TipoMovimiento = If(Row("TipoMovto").ToString = "True", True, False)
IdCtaContable = 0
importeMovimiento = 0
Concepto = $"Crédito: {TxtReferencia.Text}"
CveActivoFijo = -1
CveProveedor = -1
CveCreditoPrePoliza = -1
Select Case ConceptoContable
Case 50
importeMovimiento = ImporteDocXPagar
IdCtaContable = DdlCtaContable.SelectedValue.ToEntero
CveCreditoPrePoliza = CveCredito
CveProveedor = DdlProveedores.SelectedValue.ToEntero
Case 42
importeMovimiento = ImporteDocXPagar
If ObjProveedor.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, DdlAcreedorPrePoliza.SelectedValue.ToEntero, "-1", "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa) AndAlso ObjProveedor.DtResultados.Rows.Count > 0 Then
IdCtaContable = ObjProveedor.IdCtaContAcreedor
CveProveedor = ObjProveedor.CveProveedor
End If
End Select
If importeMovimiento <> 0 Then
If Not ObjContabilidad.AddPrePolizasDetalle(CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, ConceptoContable, Concepto, FechaMovimiento, IdCtaContable, -1, ImporteMX:=importeMovimiento, CveProveedor:=CveProveedor, CveCredito:=CveCreditoPrePoliza) Then
ErrorPrePoliza = True
End If
End If
Next
Else
ErrorPrePoliza = True
End If
Else
ErrorPrePoliza = True
End If
If Not ErrorPrePoliza Then
If Not ObjBancos.UpdateCreditosPrePoliza(CveCredito, CvePrePoliza) Then
ErrorPrePoliza = True
End If
End If
If ErrorPrePoliza Then
ObjContabilidad.RollBack()
Alert("Ocurrió un error al aplicar el saldo. Por favor vuelva a intentar.", TipoMensaje.MsgError)
Else
ObjContabilidad.Commit()
Alert("El saldo se aplicó correctamente.", TipoMensaje.MsgInformacion, "document.location.href=""/Bancos/RepCreditos.aspx"";")
End If
End Sub
#End Region
End Class