Option Explicit On Option Strict On Imports System.Data Imports System.Drawing Imports Microsoft.Reporting.WebForms Imports Extensiones Partial Class RepCuadreContaAdmonDetalle Inherits ClsPaginas Private Shared missing As Object = System.Reflection.Missing.Value #Region "PROPIEDADES" #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then If Request("GPO") IsNot Nothing AndAlso Request("GPO").ToEntero() > 0 Then DdlGrupo.SelectedValue = Request("GPO").ToString End If If Request("FechaI") IsNot Nothing AndAlso Request("FechaI").ToString() <> "" Then txtFechaI.Text = Request("FechaI").ToString() End If If Request("FechaF") IsNot Nothing AndAlso Request("FechaF").ToString() <> "" Then txtFechaF.Text = Request("FechaF").ToString End If If Request("GPO") IsNot Nothing Then CargaDatos() End If End If End Sub #Region " C A R G A - D A T O S " Public Sub CargaDatos() Dim ObjContpaq As New ClsContPAQi(UsuarioActual.Empresa) Dim FechaI As Date = If(txtFechaI.Text = "", MinFecha, txtFechaI.Text.ToDate) Dim FechaF As Date = If(txtFechaF.Text = "", MaxFecha, txtFechaF.Text.ToDate) If ObjContpaq.GetReporteCuadreContaAdmon(UsuarioActual.CveEmpresa, FuncionalidadGrupoGet(DdlGrupo.SelectedValue.ToEntero), DdlGrupo.SelectedValue.ToEntero, 2, FechaI, FechaF) Then GvDatos.DataSource = ObjContpaq.DtResultados GvDatos.DataBind() UPDatos.Update() Else Alert("Ocurrio un error al obtener el reporte", TipoMensaje.MsgError) End If ObjContpaq.Dispose() End Sub Private Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click CargaDatos() End Sub Private Function FuncionalidadGrupoGet(Grupo As Integer) As Integer Select Case Grupo Case 1 'Clientes Return 211 Case 2 'Proveedores Return 201 Case 3 'Bancos Return 209 Case 4 'Caja Chica Return 218 Case 5 'Deudores Return 205 Case 6 'Acreedores Return 202 Case 7 'Ant Clientes Return 212 Case 8 'Ant Proveedores Return 204 Case 9 'IVA x Acreditar Return UsuarioActual.Empresa.IdCuentaIVAxAcreditar Case 10 'IVA Acreditado Return UsuarioActual.Empresa.IdCuentaIVAAcreditable Case 11 'IVA x Trasladar Return UsuarioActual.Empresa.IdCuentaIVAxTrasladar Case 12 'IVA Trasladado Return UsuarioActual.Empresa.IdCuentaIVATrasladado Case 13 'Ingresos Return 222 Case 14 'Gastos Return 216 End Select Return 0 End Function #End Region #Region "O R D E N A M I E N T O" Private Sub OrdenaDatos() If (GvDatos.Rows.Count > 0) Then GvDatos.UseAccessibleHeader = True GvDatos.HeaderRow.TableSection = TableRowSection.TableHeader RegistraScript("OrdenarGV();") End If End Sub #End Region #Region "G V - D A T O S " Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Cells(0).BackColor = ColorTranslator.FromHtml("#e9e9e9") e.Row.Cells(1).BackColor = ColorTranslator.FromHtml("#e9e9e9") e.Row.Cells(2).BackColor = ColorTranslator.FromHtml("#e9e9e9") e.Row.Cells(3).BackColor = ColorTranslator.FromHtml("#e9e9e9") e.Row.Cells(4).BackColor = ColorTranslator.FromHtml("#ffffff") e.Row.Cells(5).BackColor = ColorTranslator.FromHtml("#ffffff") e.Row.Cells(6).BackColor = ColorTranslator.FromHtml("#ffffff") e.Row.Cells(7).BackColor = ColorTranslator.FromHtml("#ffffff") e.Row.Cells(8).BackColor = ColorTranslator.FromHtml("#fafafa") e.Row.Cells(9).BackColor = ColorTranslator.FromHtml("#fafafa") If e.Row.DataKey("IdPoliza").ToEntero > 0 Then Dim LigaConta As String = $"/Contabilidad/RegPoliza.aspx?IdPoliza={e.Row.DataKey("IdPoliza")}" e.Row.FCLiteral("LtlCargoConta").Text = "" & e.Row.FCLiteral("LtlCargoConta").Text & "" e.Row.FCLiteral("LtlAbonoConta").Text = "" & e.Row.FCLiteral("LtlAbonoConta").Text & "" End If If e.Row.DataKey("CvePrePoliza").ToEntero > 0 Then Dim LigaPrePoliza As String = $"/Contabilidad/RegPrePoliza.aspx?CvePrePoliza={e.Row.DataKey("CvePrePoliza")}&Tipo=1" e.Row.FCLiteral("LtlCargoAdmon").Text = " " & e.Row.FCLiteral("LtlCargoAdmon").Text & " " e.Row.FCLiteral("LtlAbonoAdmon").Text = " " & e.Row.FCLiteral("LtlAbonoAdmon").Text & " " End If If e.Row.DataKey("CveIE").ToEntero > 0 AndAlso Not DdlGrupo.SelectedValue.Contiene("13", "14") Then Dim LigaReferencia As String = $"/Bancos/IE.aspx?CveIE={e.Row.DataKey("CveIE")}" e.Row.FCLiteral("LtlLigaReferencia").Text = " Ir " ElseIf e.Row.DataKey("CveVenta").ToEntero > 0 Then Dim LigaReferencia As String = $"/Ventas/Ventas.aspx?CveVenta={e.Row.DataKey("CveVenta")}" e.Row.FCLiteral("LtlLigaReferencia").Text = " Ir " ElseIf e.Row.DataKey("CveCompra").ToEntero > 0 Then Dim LigaReferencia As String = $"/Compras/Compras.aspx?CveCompra={e.Row.DataKey("CveCompra")}" e.Row.FCLiteral("LtlLigaReferencia").Text = " Ir " End If End If End Sub Protected Sub GvDatos_DataBound(sender As Object, e As EventArgs) Handles GvDatos.DataBound CrearVinculoContableAdmon() End Sub Private Sub GvDatos_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowCreated If (e.Row.RowType = DataControlRowType.Header) Then Dim HeaderGrid As GridView = CType(sender, GridView) Dim HeaderGridRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert) Dim HeaderCell As TableCell = New TableCell() HeaderCell.Text = "Contable" HeaderCell.ColumnSpan = 4 HeaderCell.BackColor = ColorTranslator.FromHtml("#F08886") HeaderCell.ForeColor = Color.White HeaderGridRow.Cells.Add(HeaderCell) HeaderCell = New TableCell() HeaderCell.Text = "Administrativo" HeaderCell.ColumnSpan = 4 HeaderCell.BackColor = ColorTranslator.FromHtml("#44b6ae") HeaderCell.ForeColor = Color.White HeaderGridRow.Cells.Add(HeaderCell) HeaderCell = New TableCell() HeaderCell.Text = "Acciones" HeaderCell.ColumnSpan = 2 HeaderCell.BackColor = ColorTranslator.FromHtml("#3598dc") HeaderCell.ForeColor = Color.White HeaderGridRow.Cells.Add(HeaderCell) GvDatos.Controls(0).Controls.AddAt(0, HeaderGridRow) End If End Sub #End Region #Region "CARGA COMBOS FILTRO" #End Region #Region "DDLS SELECTED INDEX CHANGED" #End Region #Region "PDF" #End Region #Region "Metodos Generales" Private Sub CrearVinculoContableAdmon() Dim contador = 0 For Each row As GridViewRow In GvDatos.Rows If row.DataKey("IdPolizaPrePoliza") <> "" AndAlso row.DataKey("IdPoliza") = "" Then 'Las PrePolizas contabilizadas no vinculadas contador += 1 row.FCTextBox("TxtVinculo").Text = contador.ToString row.FCTextBox("TxtVinculo").Enabled = False For Each row2 As GridViewRow In GvDatos.Rows If row.DataKey("IdPolizaPrePoliza") = row2.DataKey("IdPoliza") And (row.FCLiteral("LtlCargoConta").Text <> "" AndAlso (row.FCLiteral("LtlCargoConta").Text = row2.FCLiteral("LtlCargoAdmon").Text) Or (row.FCLiteral("LtlAbonoConta").Text <> "" AndAlso row.FCLiteral("LtlAbonoConta").Text = row2.FCLiteral("LtlAbonoAdmon").Text)) And row2.FCTextBox("TxtVinculo").Text = "" Then 'row2 son las polizas que queremos identificar row2.FCTextBox("TxtVinculo").Text = contador.ToString Exit For End If Next End If Next End Sub Private Sub VincularPolizas() Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) Dim Contador As Integer = 0 'Hay que agregarle el metodo de vinculacion y que la vinculacion ponga automaticamente la cuenta contable del movimientopoliza en la prepolizadetalle For Each row As GridViewRow In GvDatos.Rows If row.DataKey("IdPolizaPrePoliza") <> "" AndAlso row.FCTextBox("TxtVinculo").Text.Trim <> "" Then For Each row2 As GridViewRow In GvDatos.Rows If row.FCTextBox("TxtVinculo").Text = row2.FCTextBox("TxtVinculo").Text AndAlso row2.FCTextBox("TxtVinculo").Enabled Then If ObjConta.VincularPolizaPrepoliza(row2.DataKey("Id").ToEntero, row.DataKey("CvePrePolizaDetalle").ToEntero) Then Contador += 1 End If End If Next End If Next Alert("Se vincularon correctamente " & Contador & " pólizas.") CargaDatos() ObjConta.Dispose() End Sub Private Function VerificarVinculacion() As Boolean Dim valida = True For Each row As GridViewRow In GvDatos.Rows Dim ContadorSimilitud As Integer = 0 If Not row.FCTextBox("TxtVinculo").Enabled Then For Each row2 As GridViewRow In GvDatos.Rows If row.FCTextBox("TxtVinculo").Text = row2.FCTextBox("TxtVinculo").Text AndAlso row2.FCTextBox("TxtVinculo").Enabled Then ContadorSimilitud += 1 If ContadorSimilitud > 1 Then row2.FCTextBox("TxtVinculo").BorderColor = Color.Red valida = False End If End If Next End If Next If valida = False Then Alert("Los movimientos no se pudieron vincular debido a que algunos de ellos estan repetidos.
Los movimientos repetidos estan marcados en rojo.", TipoMensaje.MsgError) End If Return valida End Function Private Sub BtnVincular_Click(sender As Object, e As EventArgs) Handles BtnVincular.Click If VerificarVinculacion() Then VincularPolizas() End If End Sub #End Region End Class