Imports System.ComponentModel Public Class frmValidarIngreso Private _CodigoInversion As String = String.Empty Private _IngresoID As Integer = 0 Private _NombreManIF As String Private _CodManIF As String Private _CodEmpr As String Private _FechaVencimiento As Date Private _Correlativo As Integer Private _CodIF As String Private _Capital As Double Private _IngresoBruto As Double Private _ISR As Double Private _IngresoNeto As Double Private _IngresoLiquidoProgramado As Double Private vBD_SAP As String Private vTransId As String Private vEstadoDelIngreso As String Private _CapitalRecibido As Double = 0 Private _IngresoBrutoRecibido As Double = 0 Private _ISRRecibido As Double = 0 Private _IngresoNetoRecibido As Double = 0 Private _IngresoLiquidoRecibido As Double = 0 'VARIACIONES EN LOS INGRESOS RECIBIDOS Private _CapitalRecibidoDif As Double = 0 Private _IngresoBrutoRecibidoDif As Double = 0 Private _ISRRecibidoDif As Double = 0 Private _IngresoNetoRecibidoDif As Double = 0 Private _IngresoLiquidoRecibidoDif As Double = 0 Private _CodBanco As String = String.Empty Private _FormaDePago As String = String.Empty Private _CuentaBancaria As String = String.Empty Private CargandoBancos As Boolean Private Transaccion As String Public WriteOnly Property CodigoInversion As String Set(value As String) _CodigoInversion = value End Set End Property Public WriteOnly Property IngresoID As String Set(value As String) _IngresoID = value End Set End Property Private Sub frmIngresosDetalle_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'TODO: esta línea de código carga datos en la tabla 'InversionesDataSet1.BAN0' Puede moverla o quitarla según sea necesario. Me.BAN0TableAdapter.Fill(Me.InversionesDataSet1.BAN0) 'TODO: esta línea de código carga datos en la tabla 'InversionesDataSet1.FPAG' Puede moverla o quitarla según sea necesario. Me.FPAGTableAdapter.Fill(Me.InversionesDataSet1.FPAG) cbxFormaDePago.SelectedIndex = -1 cbxBanco.SelectedIndex = -1 If _CodigoInversion.ToString.Length > 0 Then CargarIngresoDetalle() Else PrepararNuevo() End If End Sub Private Sub CargarCuentasBancarias() If Not (_CodEmpr Is Nothing Or _CodBanco Is Nothing) Then CargandoBancos = True Me.cbxCuentaBanco.DataSource = BancosDAO.CuentasBancarias(_CodEmpr, _CodBanco) Me.cbxCuentaBanco.DisplayMember = "NumCuenta" Me.cbxCuentaBanco.ValueMember = "NumCuenta" Me.cbxCuentaBanco.SelectedIndex = -1 CargandoBancos = False End If End Sub Private Sub PrepararNuevo() Dim oIngresoDetalleCE As New IngresoDetalleCE Me.Transaccion = "N" End Sub Private Sub CargarIngresoDetalle() Dim oIngresoDetalleCE As New IngresoDetalleCE oIngresoDetalleCE = IngresosDAO.DetalleDeIngreso(_CodigoInversion, _IngresoID) _CodIF = oIngresoDetalleCE.CodigoInstrumentoFinanciero _NombreManIF = oIngresoDetalleCE.NombreManualIF _CodManIF = oIngresoDetalleCE.CodigoManualIF _CodEmpr = oIngresoDetalleCE.CodigoEmpresa _FechaVencimiento = oIngresoDetalleCE.FechaVencimiento _Correlativo = oIngresoDetalleCE.IngresoId _Capital = oIngresoDetalleCE.MontoCapitalProyectado _IngresoBruto = oIngresoDetalleCE.MontoIngresoBrutoProyectado _ISR = oIngresoDetalleCE.MontoISRProyectado _IngresoNeto = oIngresoDetalleCE.MontoIngresoNetoProyectado vBD_SAP = oIngresoDetalleCE.SAP_BD vEstadoDelIngreso = oIngresoDetalleCE.EstadoDelIngreso _IngresoLiquidoProgramado = _IngresoNeto Me.txtNombreManIF.Text = _NombreManIF Me.txtCodManIF.Text = _CodManIF Me.txtEmpresa.Text = _CodEmpr Me.dtpFechaVencimiento.Value = _FechaVencimiento Me.txtIngresoID.Text = _Correlativo.ToString Me.txtCodInversion.Text = _CodigoInversion Me.txtCapitalProgramado.Text = _Capital.ToString(Configuraciones.CodigoTXTMontos) Me.txtIngresoBrutoProgramado.Text = _IngresoBruto.ToString(Configuraciones.CodigoTXTMontos) Me.txtISRProgramado.Text = _ISR.ToString(Configuraciones.CodigoTXTMontos) Me.txtIngresoNetoProgramado.Text = _IngresoNeto.ToString(Configuraciones.CodigoTXTMontos) Me.txtIngresoLiquidoProgramado.Text = _IngresoLiquidoProgramado.ToString(Configuraciones.CodigoTXTMontos) If vEstadoDelIngreso = "R" Then CargarIngresoRecibido() Me.cbxFormaDePago.Enabled = False Me.cbxBanco.Enabled = False Me.cbxCuentaBanco.Enabled = False Me.dtpFechaIngreso.Enabled = False Me.btnRegistrarIngreso.Enabled = False Me.txtCapitalRecibido.ReadOnly = True Me.txtIngresoBrutoRecibido.ReadOnly = True Me.txtISRRecibido.ReadOnly = True Me.txtIngresoNetoRecibido.ReadOnly = True Me.txtIngresoLiquidoRecibido.ReadOnly = True Me.txtComentarios.ReadOnly = True Me.lblCopiarCapital.Enabled = False Me.lblCopiarIngresoBruto.Enabled = False Me.lblCopiarISR.Enabled = False Me.lblCopiarIngresoNeto.Enabled = False Me.lblCopiarLiquido.Enabled = False End If If vEstadoDelIngreso = "P" Then Me.btnConciliarIngreso.Enabled = False End If End Sub Private Sub CargarIngresoRecibido() Dim oRegistroIngresoCE As RegistroIngresoCE Dim vValidado As String Dim vConciliado As String oRegistroIngresoCE = IngresosDAO.DetalleIngresoRecibido(_CodigoInversion, _Correlativo) If Not oRegistroIngresoCE Is Nothing Then Me.cbxFormaDePago.SelectedValue = oRegistroIngresoCE.FormaDePago Me.cbxBanco.SelectedValue = oRegistroIngresoCE.CodigoBanco Me.cbxCuentaBanco.SelectedValue = oRegistroIngresoCE.CuentaBancaria Me.dtpFechaIngreso.Value = oRegistroIngresoCE.FechaDelIngreso Me.txtCapitalRecibido.Text = oRegistroIngresoCE.MontoCapital.ToString(Configuraciones.CodigoTXTMontos) Me.txtIngresoBrutoRecibido.Text = oRegistroIngresoCE.MontoIngresoBruto.ToString(Configuraciones.CodigoTXTMontos) Me.txtISRRecibido.Text = oRegistroIngresoCE.MontoISR.ToString(Configuraciones.CodigoTXTMontos) Me.txtIngresoNetoRecibido.Text = oRegistroIngresoCE.MontoIngresoNeto.ToString(Configuraciones.CodigoTXTMontos) Me.txtIngresoLiquidoRecibido.Text = oRegistroIngresoCE.MontoIngresoLiquido.ToString(Configuraciones.CodigoTXTMontos) vValidado = oRegistroIngresoCE.Validado vConciliado = oRegistroIngresoCE.Conciliado If vValidado = "S" Then Me.btnValidarIngreso.Enabled = False If vConciliado = "S" Then Me.btnConciliarIngreso.Enabled = False End If End Sub Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click Me.Close() End Sub Private Sub btnValidar_Click(sender As Object, e As EventArgs) End Sub 'PARTIDA DE INGRESOS EN SAP Private Sub CrearPartidaIngresos() Dim vResultado As Integer Dim oPartidaIngresos As New InvSAP.PartidaIngresoRecibido oPartidaIngresos.CodigoInversion = _CodigoInversion oPartidaIngresos.IngresoID = _IngresoID oPartidaIngresos.TransId = vTransId oPartidaIngresos.IngresoBruto = _IngresoBruto oPartidaIngresos.ISR = _ISR oPartidaIngresos.IngresoNeto = _IngresoNeto oPartidaIngresos.BDSAP = vBD_SAP vResultado = oPartidaIngresos.Crear() If vResultado = 0 Then MsgBox("Partida de Ingresos Creada") Else MsgBox("Error al generar Partida de Ingresos", MsgBoxStyle.Critical) End If End Sub 'CAPITAL Private Sub txtCapitalRecibido_Validating(sender As Object, e As CancelEventArgs) Handles txtCapitalRecibido.Validating Dim errMsg As String = String.Empty If Not ValidaMonto(txtCapitalRecibido.Text, errMsg) Then e.Cancel = True txtCapitalRecibido.SelectAll() Me.ErrorProvider1.SetError(txtCapitalRecibido, errMsg) Else If txtCapitalRecibido.Text.Length > 0 Then _CapitalRecibido = txtCapitalRecibido.Text txtCapitalRecibido.Text = _CapitalRecibido.ToString(Configuraciones.CodigoTXTMontos) ControlCapitalDif() Else _CapitalRecibido = 0 End If End If End Sub Private Sub txtCapitalRecibido_Validated(sender As Object, e As EventArgs) Handles txtCapitalRecibido.Validated Me.ErrorProvider1.SetError(txtCapitalRecibido, "") End Sub Private Sub txtCapitalRecibido_MouseDown(sender As Object, e As MouseEventArgs) Handles txtCapitalRecibido.MouseDown txtCapitalRecibido.SelectAll() End Sub 'INGRESO BRUTO Private Sub txtIngresoBrutoRecibido_Validating(sender As Object, e As CancelEventArgs) Handles txtIngresoBrutoRecibido.Validating Dim errMsg As String = String.Empty If Not ValidaMonto(txtIngresoBrutoRecibido.Text, errMsg) Then e.Cancel = True txtIngresoBrutoRecibido.SelectAll() Me.ErrorProvider1.SetError(txtIngresoBrutoRecibido, errMsg) Else If txtIngresoBrutoRecibido.Text.Length > 0 Then _IngresoBrutoRecibido = txtIngresoBrutoRecibido.Text txtIngresoBrutoRecibido.Text = _IngresoBrutoRecibido.ToString(Configuraciones.CodigoTXTMontos) IngresoBrutoDif() Else _IngresoBrutoRecibido = 0 End If End If End Sub Private Sub txtIngresoBrutoRecibido_Validated(sender As Object, e As EventArgs) Handles txtIngresoBrutoRecibido.Validated Me.ErrorProvider1.SetError(txtIngresoBrutoRecibido, "") End Sub Private Sub txtIngresoBrutoRecibido_MouseDown(sender As Object, e As MouseEventArgs) Handles txtIngresoBrutoRecibido.MouseDown txtIngresoBrutoRecibido.SelectAll() End Sub 'ISR Private Sub txtISRRecibido_Validating(sender As Object, e As CancelEventArgs) Handles txtISRRecibido.Validating Dim errMsg As String = String.Empty If Not ValidaMonto(txtISRRecibido.Text, errMsg) Then e.Cancel = True txtISRRecibido.SelectAll() Me.ErrorProvider1.SetError(txtISRRecibido, errMsg) Else If txtISRRecibido.Text.Length > 0 Then _ISRRecibido = txtISRRecibido.Text txtISRRecibido.Text = _ISRRecibido.ToString(Configuraciones.CodigoTXTMontos) ISRDif() Else _ISRRecibido = 0 End If End If End Sub Private Sub txtISRRecibido_Validated(sender As Object, e As EventArgs) Handles txtISRRecibido.Validated Me.ErrorProvider1.SetError(txtISRRecibido, "") End Sub Private Sub txtISRRecibido_MouseDown(sender As Object, e As MouseEventArgs) Handles txtISRRecibido.MouseDown txtISRRecibido.SelectAll() End Sub 'INGRESO NETO Private Sub txtIngresoNetoRecibido_Validating(sender As Object, e As CancelEventArgs) Handles txtIngresoNetoRecibido.Validating Dim errMsg As String = String.Empty If Not ValidaMonto(txtIngresoNetoRecibido.Text, errMsg) Then e.Cancel = True txtIngresoNetoRecibido.SelectAll() Me.ErrorProvider1.SetError(txtIngresoNetoRecibido, errMsg) Else If txtIngresoNetoRecibido.Text.Length > 0 Then _IngresoNetoRecibido = txtIngresoNetoRecibido.Text txtIngresoNetoRecibido.Text = _IngresoNetoRecibido.ToString(Configuraciones.CodigoTXTMontos) IngresoNetoDif() Else _IngresoNetoRecibido = 0 End If End If End Sub Private Sub txtIngresoNetoRecibido_Validated(sender As Object, e As EventArgs) Handles txtIngresoNetoRecibido.Validated Me.ErrorProvider1.SetError(txtIngresoNetoRecibido, "") End Sub Private Sub txtIngresoNetoRecibido_MouseDown(sender As Object, e As MouseEventArgs) Handles txtIngresoNetoRecibido.MouseDown txtIngresoNetoRecibido.SelectAll() End Sub 'INGRESO LIQUIDO Private Sub txtIngresoLiquidoRecibido_Validating(sender As Object, e As CancelEventArgs) Handles txtIngresoLiquidoRecibido.Validating Dim errMsg As String = String.Empty If Not ValidaMonto(txtIngresoLiquidoRecibido.Text, errMsg) Then e.Cancel = True txtIngresoLiquidoRecibido.SelectAll() Me.ErrorProvider1.SetError(txtIngresoLiquidoRecibido, errMsg) Else If txtIngresoLiquidoRecibido.Text.Length > 0 Then _IngresoLiquidoRecibido = txtIngresoLiquidoRecibido.Text txtIngresoLiquidoRecibido.Text = _IngresoLiquidoRecibido.ToString(Configuraciones.CodigoTXTMontos) IngresoLiquidoDif() Else _IngresoLiquidoRecibido = 0 End If End If End Sub Private Sub txtIngresoLiquidoRecibido_Validated(sender As Object, e As EventArgs) Handles txtIngresoLiquidoRecibido.Validated Me.ErrorProvider1.SetError(txtIngresoLiquidoRecibido, "") End Sub Private Sub txtIngresoLiquidoRecibido_MouseDown(sender As Object, e As MouseEventArgs) Handles txtIngresoLiquidoRecibido.MouseDown txtIngresoLiquidoRecibido.SelectAll() End Sub Private Function ValidaMonto(ByVal pValorTXT As String, ByRef MensajeError As String) As Boolean Dim rValor As Double If pValorTXT.Length > 0 Then If Not Double.TryParse(pValorTXT, rValor) Then MensajeError = "Valor no válido." Return False Else Return True End If Else Return True End If End Function Private Sub cbxInstitucionFinanciera_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxBanco.SelectedIndexChanged _CodBanco = cbxBanco.SelectedValue CargarCuentasBancarias() End Sub Private Sub cbxCuentaBanco_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxCuentaBanco.SelectedIndexChanged If CargandoBancos = False Then _CuentaBancaria = cbxCuentaBanco.SelectedValue 'If CargandoBancos = False Then MsgBox(cbxCuentaBanco.SelectedValue.ToString) End Sub Private Sub cbxFormaDePago_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxFormaDePago.SelectedIndexChanged _FormaDePago = cbxFormaDePago.SelectedValue End Sub Private Function ValidacionesRegistrarIngreso() As Boolean Dim vDatosCorrectos As Boolean = True If _FormaDePago = String.Empty Then vDatosCorrectos = False ErrorProvider1.SetError(cbxFormaDePago, "Elegir Forma de Pago") Else ErrorProvider1.SetError(cbxFormaDePago, "") End If If _CodBanco = String.Empty Then vDatosCorrectos = False ErrorProvider1.SetError(cbxBanco, "Elegir Banco") Else ErrorProvider1.SetError(cbxBanco, "") End If If _CuentaBancaria = String.Empty Then vDatosCorrectos = False ErrorProvider1.SetError(cbxCuentaBanco, "Elegir Cuenta Bancaria") Else ErrorProvider1.SetError(cbxCuentaBanco, "") End If If _IngresoNetoRecibido = 0.000000 Then vDatosCorrectos = False ErrorProvider1.SetError(txtIngresoNetoRecibido, "Se necesita un Monto") Else ErrorProvider1.SetError(txtIngresoNetoRecibido, "") End If Return vDatosCorrectos End Function Private Sub btnRegistrarIngreso_Click(sender As Object, e As EventArgs) Handles btnRegistrarIngreso.Click If ValidacionesRegistrarIngreso() Then RegistrarIngreso() End Sub Private Sub RegistrarIngreso() Dim oRegistroIngreso As New RegistroIngresoCE Dim resultado As Integer vTransId = Utilidades.GenerarTransId oRegistroIngreso.CodigoEmpresa = _CodEmpr oRegistroIngreso.CodigoInstrumento = _CodIF oRegistroIngreso.CodigoBanco = _CodBanco oRegistroIngreso.CodigoInversion = _CodigoInversion oRegistroIngreso.IngresoID = _IngresoID oRegistroIngreso.FormaDePago = _FormaDePago oRegistroIngreso.CuentaBancaria = _CuentaBancaria oRegistroIngreso.FechaDelIngreso = dtpFechaIngreso.Value.Date oRegistroIngreso.FechaRegistro = Date.Now oRegistroIngreso.MontoCapital = _CapitalRecibido oRegistroIngreso.MontoIngresoBruto = _IngresoBrutoRecibido oRegistroIngreso.MontoISR = _ISRRecibido oRegistroIngreso.MontoIngresoNeto = _IngresoNetoRecibido oRegistroIngreso.MontoIngresoLiquido = _IngresoLiquidoRecibido oRegistroIngreso.TransId = vTransId resultado = IngresosDAO.RegistrarIngreso(oRegistroIngreso) If resultado = 1 Then MsgBox("Registrado") CrearPartidaIngresos() CargarIngresoDetalle() Else MsgBox("Algo paso mal") End If End Sub Private Sub lblCopiarCapital_Click(sender As Object, e As EventArgs) Handles lblCopiarCapital.Click Me.txtCapitalRecibido.Text = Me.txtCapitalProgramado.Text Me.txtCapitalRecibido.Focus() End Sub Private Sub lblCopiarIngresoBruto_Click(sender As Object, e As EventArgs) Handles lblCopiarIngresoBruto.Click Me.txtIngresoBrutoRecibido.Text = Me.txtIngresoBrutoProgramado.Text Me.txtIngresoBrutoRecibido.Focus() End Sub Private Sub lblCopiarISR_Click(sender As Object, e As EventArgs) Handles lblCopiarISR.Click Me.txtISRRecibido.Text = Me.txtISRProgramado.Text Me.txtISRRecibido.Focus() End Sub Private Sub lblCopiarIngresoNeto_Click(sender As Object, e As EventArgs) Handles lblCopiarIngresoNeto.Click Me.txtIngresoNetoRecibido.Text = Me.txtIngresoNetoProgramado.Text Me.txtIngresoNetoRecibido.Focus() End Sub Private Sub lblCopiarLiquido_Click(sender As Object, e As EventArgs) Handles lblCopiarLiquido.Click Me.txtIngresoLiquidoRecibido.Text = Me.txtIngresoLiquidoProgramado.Text Me.txtIngresoLiquidoRecibido.Focus() End Sub Private Sub txtIngresoNetoRecibido_TextChanged(sender As Object, e As EventArgs) Handles txtIngresoNetoRecibido.TextChanged End Sub Private Sub btnValidarIngreso_Click(sender As Object, e As EventArgs) Handles btnValidarIngreso.Click Dim vValidar As Integer vTransId = Utilidades.GenerarTransId vValidar = IngresosDAO.ValidarIngreso(_CodigoInversion, _IngresoID) If vValidar = 1 Then MsgBox("Ingreso Validado") CargarIngresoDetalle() Else MsgBox("Error al validar.", MsgBoxStyle.Critical) End If End Sub Private Sub btnConciliarIngreso_Click(sender As Object, e As EventArgs) Handles btnConciliarIngreso.Click Dim vConciliar As Integer vTransId = Utilidades.GenerarTransId vConciliar = IngresosDAO.ConciliarIngreso(_CodigoInversion, _IngresoID) If vConciliar = 1 Then MsgBox("Ingreso Conciliado") 'CrearPartidaIngresos() CargarIngresoDetalle() Else MsgBox("Error al Conciliar.", MsgBoxStyle.Critical) End If End Sub Private Sub ControlCapitalDif() If vEstadoDelIngreso = "P" Then _CapitalRecibidoDif = _Capital - _CapitalRecibido End If txtVariacionCapital.Text = _CapitalRecibidoDif.ToString(Configuraciones.CodigoTXTMontos) End Sub Private Sub IngresoBrutoDif() If vEstadoDelIngreso = "P" Then _IngresoBrutoRecibidoDif = _IngresoBruto - _IngresoBrutoRecibido End If txtVariacionIngresoBruto.Text = _IngresoBrutoRecibidoDif.ToString(Configuraciones.CodigoTXTMontos) End Sub Private Sub ISRDif() If vEstadoDelIngreso = "P" Then _ISRRecibidoDif = _ISR - _ISRRecibido End If txtVariacionISR.Text = _ISRRecibidoDif.ToString(Configuraciones.CodigoTXTMontos) End Sub Private Sub IngresoNetoDif() If vEstadoDelIngreso = "P" Then _IngresoNetoRecibidoDif = _IngresoNeto - _IngresoNetoRecibido End If txtVariacionIngresoNeto.Text = _IngresoNetoRecibidoDif.ToString(Configuraciones.CodigoTXTMontos) End Sub Private Sub IngresoLiquidoDif() If vEstadoDelIngreso = "P" Then _IngresoLiquidoRecibidoDif = _IngresoLiquidoProgramado - _IngresoLiquidoRecibido End If txtVariacionIngresoLiquido.Text = _IngresoLiquidoRecibidoDif.ToString(Configuraciones.CodigoTXTMontos) End Sub Private Sub txtCapitalRecibido_TextChanged(sender As Object, e As EventArgs) Handles txtCapitalRecibido.TextChanged End Sub End Class