Option Explicit On Option Strict On Imports Extensiones Imports System.Data Partial Class Bancos_DepositosCaja Inherits ClsPaginas Private Property FacturasCheckadas As Integer Get Return ViewState("FacturasCheckadas").ToString.ToEntero End Get Set(value As Integer) ViewState("FacturasCheckadas") = value End Set End Property Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not IsPostBack Then FacturasCheckadas = 0 TxtFecha.Text = Now.ToShortDateString txtFechaI.Text = Now.AddDays(-1).ToShortDateString txtFechaF.Text = Now.ToShortDateString TxtComision.Attributes.Add("onKeyUp", "txtSuma(event);") CargaCuentas() End If End Sub Private Sub CargaCuentas() DdlCuentaDeposito.DataSource = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(" CveTipoCuenta <> 1", "", {"CveCuenta", "NumCuentaMoneda"}) DdlCuentaDeposito.DataBind() DdlCajaChica.DataSource = GlobalDTBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(" CveTipoCuenta = 1", "", {"CveCuenta", "NumCuentaMoneda"}) DdlCajaChica.DataBind() DdlSubProyectos.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa) DdlSubProyectos.DataBind() DdlSubProyectos.Items.Insert(0, New ListItem("Todos", "-1")) DdlSubProyectoDeposito.DataSource = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa) DdlSubProyectoDeposito.DataBind() DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) DdlClasificacion.DataBind() End Sub Private Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click CargaDatos() End Sub Private Sub CargaDatos() Dim ObjBancos As New ClsBancos Dim FechaI, FechaF As String FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1") FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1") ObjBancos.GetPagosCajaChica(FechaI, FechaF, UsuarioActual.CveEmpresa, DdlCajaChica.SelectedValue.ToEntero, DdlTipoPago.SelectedValue.ToEntero, CveSubProyecto:=DdlSubProyectos.SelectedValue.ToEntero) GvFacturas.DataSource = ObjBancos.DtResultados ObjBancos.Dispose() UpGvFacturas.Update() GvFacturas.DataBind() lblValorTotal.Text = "00.00" divLabelTotal.Visible = True DivComision.Visible = True End Sub Private Sub BtnDepositar_Click(sender As Object, e As EventArgs) Handles BtnDepositar.Click Dim TotalImporte As Decimal = 0 Dim TotalImportePrePoliza As Decimal For Each Gvr As GridViewRow In GvFacturas.Rows If Gvr.FCCheckBox("ChkFactura").Checked Then TotalImporte += Gvr.DataKey("Importe").ToDecimal Next If TotalImporte = 0 Then Alert("Seleccion una factura para realizar el deposito", TipoMensaje.MsgAdvertencia) Exit Sub End If TotalImportePrePoliza = TotalImporte If TxtComision.Text.ToEntero > 0 Then TotalImporte = TotalImporte - TxtComision.Text.ToEntero If DdlSubProyectoDeposito.SelectedValue.ToEntero = -1 Or DdlClasificacion.SelectedValue.ToEntero = -1 Then Alert("Debes Seleccionar un Subproyecto y una Clasificación", TipoMensaje.MsgAdvertencia) Exit Sub End If End If Dim OcurrioError As Boolean = False Dim ObjContabilidad As New ClsContabilidad() Dim ObjBancos As New ClsBancos(ObjContabilidad.IniciaTransacSQL()) Dim CveIEOrigen As Integer 'CajaChica Dim CveIEDestino As Integer 'Banco Dim NuevaCvePrePoliza As Integer Dim FolioIE As Long = -1 Dim CveMoneda As Integer = 1 Dim TipoCambio As Decimal = 1 Dim Fecha As Date = TxtFecha.Text.ToDate Dim IdCuentaBancariaOrigen As Integer = 0 Dim IdCuentaBancariaDestino As Integer = 0 Dim CveCuentaBancariaOrigen As Integer = 0 Dim CveCuentaBancariaDestino As Integer = 0 Dim drOrigen As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveCuenta:=DdlCajaChica.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("") Dim drDestino As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveCuenta:=DdlCuentaDeposito.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("") Dim CveSubProyecto As Integer = 0 Dim CveClasificacion As Integer = 0 Dim documentos As String = "Los Depósitos se realizaron exitósamente

" Dim imprimirFolios As String = "" If drOrigen IsNot Nothing Then CveMoneda = drOrigen("CveMoneda").ToString.ToEntero IdCuentaBancariaOrigen = drOrigen("IdCtaContable").ToString.ToEntero CveCuentaBancariaOrigen = drOrigen("IdCtaContableSIG").ToString.ToEntero End If If drDestino IsNot Nothing Then CveMoneda = drDestino("CveMoneda").ToString.ToEntero IdCuentaBancariaDestino = drDestino("IdCtaContable").ToString.ToEntero CveCuentaBancariaDestino = drDestino("IdCtaContableSIG").ToString.ToEntero End If NuevaCvePrePoliza = ObjContabilidad.AddPrePolizas("Vta", 13, TotalImportePrePoliza, TotalImportePrePoliza, CveMoneda, Fecha, "Depósito Bancario", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) 'Salida de Caja Chica FolioIE = ObjBancos.GetNextFolio(DdlCajaChica.SelectedValue.ToEntero, 2) If Not FolioIE > 0 Then OcurrioError = True End If CveIEOrigen = ObjBancos.AddBancos_IE(DdlCajaChica.SelectedValue.ToEntero, 2, Fecha, FolioIE.ToString, "Depósito Bancario", TotalImporte, CveMoneda, 1, "Depósito Bancario", "", False, False, -1, NuevaCvePrePoliza, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If TxtComision.Text.ToEntero > 0 Then CveSubProyecto = DdlSubProyectoDeposito.SelectedValue.ToEntero CveClasificacion = DdlClasificacion.SelectedValue.ToEntero If ObjContabilidad.AddPrePolizasDetalle(NuevaCvePrePoliza, True, TotalImporte, "Depósito Bancario", 30, "Depósito Bancario", Fecha, IdCuentaBancariaOrigen, -1, CveIE:=CveIEOrigen, ImporteMX:=TotalImporte * TipoCambio, CveCuenta:=CveCuentaBancariaOrigen) Then If Not ObjContabilidad.AddPrePolizasDetalle(NuevaCvePrePoliza, True, TxtComision.Text.ToEntero, "Comisión", 78, "Depósito Bancario", Fecha, IdCuentaBancariaOrigen, -1, CveClasificacion:=CveClasificacion, CveSubProyecto:=CveSubProyecto, ImporteMX:=TxtComision.Text.ToEntero * TipoCambio, CveCuenta:=CveCuentaBancariaOrigen) Then OcurrioError = True End If Else OcurrioError = True End If Else If Not ObjContabilidad.AddPrePolizasDetalle(NuevaCvePrePoliza, True, TotalImporte, "Depósito Bancario", 30, "Depósito Bancario", Fecha, IdCuentaBancariaOrigen, -1, CveIE:=CveIEOrigen, ImporteMX:=TotalImporte * TipoCambio, CveCuenta:=CveCuentaBancariaOrigen) Then OcurrioError = True End If End If For Each Gvr As GridViewRow In GvFacturas.Rows If Gvr.FCCheckBox("ChkFactura").Checked Then 'Datos de las Nuevas PrePolizas 'Entrada a Bancos Dim Importe As Double = Gvr.DataKey("Importe").ToDouble Dim SerieFolio As String = Gvr.DataKey("SerieFolio").ToString 'Datos de las Prepolizas A Cancelar Dim CveIE As Integer = Gvr.DataKey("CveIE").ToEntero Dim CveVenta As Integer = Gvr.DataKey("CveVenta").ToEntero Dim CvePrePoliza As Integer = Gvr.DataKey("CvePrePoliza").ToEntero FolioIE = ObjBancos.GetNextFolio(DdlCuentaDeposito.SelectedValue.ToEntero, 8) If Not FolioIE > 0 Then OcurrioError = True End If CveIEDestino = ObjBancos.AddBancos_IE(DdlCuentaDeposito.SelectedValue.ToEntero, 8, Fecha, FolioIE.ToString, "Depósito Bancario", Importe, CveMoneda, 1, "Depósito Bancario", "", False, False, -1, NuevaCvePrePoliza, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If Not ObjContabilidad.AddPrePolizasDetalle(NuevaCvePrePoliza, False, Importe.ToDecimal, SerieFolio, 30, "Depósito Bancario", Fecha, IdCuentaBancariaDestino, -1, CveIE:=CveIEDestino, ImporteMX:=Importe.ToDecimal * TipoCambio, CveCuenta:=CveCuentaBancariaDestino) Then OcurrioError = True End If 'Asignamos la cuenta Deposito If Not ObjBancos.UpdateBancos_IECuentaDeposito(CveIEDestino, CveIE) Then OcurrioError = True End If Dim StrEncript As String = Encripta($"OP=DC&CveIE={CveIEDestino}&CuentaCaja={DdlCajaChica.SelectedItem.Text}&CuentaDepo={DdlCuentaDeposito.SelectedItem.Text}") documentos += String.Format("Documento {1}     ", CveIEDestino.ToString, SerieFolio) documentos += String.Format("Imprimir {1}

", StrEncript, SerieFolio) End If Next If OcurrioError Then ObjContabilidad.RollBack() Alert("Ocurrio un error al realizar los depositos", TipoMensaje.MsgError) Else ObjContabilidad.Commit() CargaDatos() Alert(documentos.ToString) End If ObjContabilidad.Dispose() End Sub Private Sub ObtenerTotalImporta() Dim Total As Double = 0 For Each Gvr As GridViewRow In GvFacturas.Rows If Gvr.FCCheckBox("ChkFactura").Checked Then Total += Gvr.DataKey("Importe").ToDouble End If Next lblValorTotal.Text = Total.ToString("N") UpGvFacturas.Update() End Sub Public Sub ChkFactura_Click(sender As Object, e As EventArgs) 'ObtenerTotalImporta() End Sub Protected Sub GvFacturas_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvFacturas.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.FCCheckBox("ChkFactura").Attributes.Add("onclick", String.Format("FnSuma(this,{0});", e.Row.DBCampo("Importe"))) End If End Sub End Class