Imports System.Data Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class Contabilidad_CatCuentas Inherits ClsPaginas #Region "Propiedades" Private Property DtDatos As DataTable Get Return CType(ViewState("DtDatos"), DataTable) End Get Set(value As DataTable) ViewState("DtDatos") = value End Set End Property Private Property IDSelected As Integer Get Return ViewState("idsel").ToString.ToEntero End Get Set(value As Integer) ViewState("idsel") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then 'inicio() 'RegistraScript("$('#Tsubcuenta').mask('00000-0000-0000-00000');") If UsuarioActual.Empresa.UsaContabilidad Then CargaMonedas() CargaAgrupadorSAT() CargaDatos() Else Alert("Este módulo requiere el uso de Contabilidad.", TipoMensaje.MsgAdvertencia) MEECuenta.Enabled = False LnkPdf.Visible = False End If End If End Sub Private Sub CargaMonedas() Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) If ObjConta.GetMonedas() Then DdlMoneda.DataSource = ObjConta.DtResultados End If ObjConta.Dispose() DdlMoneda.DataBind() End Sub Private Sub CargaAgrupadorSAT() Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) If ObjConta.GetAgrupadoresSAT() Then DdlAgrupadorSAT.DataSource = ObjConta.DtResultados End If ObjConta.Dispose() DdlAgrupadorSAT.DataBind() DdlAgrupadorSAT.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Private Sub CargaDatos() Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) If ObjConta.GetCuentas(-1, "-1", -1) Then DtDatos = ObjConta.DtResultados End If 'para obtener la mascara, tomo el primer dato y reemplazo los numeros por cero Dim Mascara As String = "####-####-###" If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 AndAlso DtDatos.FiltraParametros("CtaInicial>0").Rows.Count > 0 Then Mascara = DtDatos.FiltraParametros("CtaInicial>0").Rows(0)("CuentaFormato").ToString.Replace("1", "0").Replace("2", "0").Replace("3", "0").Replace("4", "0").Replace("5", "0").Replace("6", "0").Replace("7", "0").Replace("8", "0").Replace("9", "0") End If MEECuenta.Mask = Mascara.Replace("0", "9") MEECuenta.AutoComplete = True MEECuenta.AutoCompleteValue = Mascara ArbolCuentas.DataSource = DtDatos ArbolCuentas.nivel = "CtaInicial" ArbolCuentas.nodoid = "id" ArbolCuentas.padre = "IdPadre" ArbolCuentas.titulo = "CtaCodigo" updatos.Update() ObjConta.Dispose() End Sub 'Private Function getNodosHijos(nodo As Integer) As DataTable ' Return DtDatos.FiltraParametros(String.Format("IdPadre = {0}", nodo)) 'End Function Private Function getNodospadreHijos(nodo As Integer) As DataTable Return DtDatos.FiltraParametros(String.Format("Id = {0}", nodo)) End Function Protected Sub agregar_Click(sender As Object, e As EventArgs) Handles ArbolCuentas.addclick LimpiarCampos() Dim dt As New DataTable 'IDSelected = HdnID.Value.ToEntero() "ul" + itempadre.Cve; Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem) IDSelected = obj.Cve 'obj.FindControl(String.Format("ul{0}", obj.Cve)) 'obj.Controls.Add(New TextBox()) dt = getNodospadreHijos(IDSelected) If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then Dim dr As DataRow = dt.Rows(0) Tsubcuenta.Text = dr("CuentaFormato").ToString() DTcuenta.SelectedValue = dr("Tipo").ToString() DcuentaMayor.SelectedValue = dr("CtaMayor").ToString LblSubCuenta.Text = dr("Nombre").ToString End If Tcuenta.Enabled = True nuevacuenta.Visible = True updatos.Visible = True updatos.Update() End Sub Protected Sub editar_Click(sender As Object, e As EventArgs) Handles ArbolCuentas.editclick LimpiarCampos() Dim dt As DataTable Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem) IDSelected = obj.Cve dt = getNodospadreHijos(IDSelected) If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then Dim dr As DataRow = dt.Rows(0) Tcuenta.Text = dr("CuentaFormato").ToString.Replace("-", "") Tnombre.Text = dr("Nombre").ToString() DTcuenta.SelectedValue = dr("Tipo").ToString() DcuentaMayor.SelectedValue = dr("CtaMayor").ToString DdlMoneda.SelectedValueExist(dr("IdMoneda").ToString) If dr("IdAgrupadorSAT").ToString.ToEntero = 0 Then DdlAgrupadorSAT.SelectedValue = -1 Else DdlAgrupadorSAT.SelectedValue = dr("IdAgrupadorSAT").ToString End If TxtDigAgrup.Text = dr("DigAgrup").ToString TxtNomIngles.Text = dr("NomIdioma").ToString Dim Hijos As Integer = DtDatos.FiltraParametros(String.Format("IdPadre = {0}", IDSelected)).Rows.Count If Hijos = 0 Then BtnEliminar.Visible = True dt = getNodospadreHijos(dr("IdPadre").ToString.ToEntero) If dt.Rows.Count > 0 Then Dim drt As DataRow = dt.Rows(0) Tsubcuenta.Text = drt("Codigo").ToString LblSubCuenta.Text = drt("Nombre").ToString HdnSubCuentaDe.Value = drt("Codigo").ToString Guardar.OnClientClick = $"ValidaGuardar('{drt("Codigo").ToString}');" Guardar.Attributes.Add("data-toggle", "confirmation") Guardar.Attributes.Add("data-popout", "true") Guardar.Attributes.Add("data-original-title", "confirmar") Guardar.Attributes.Add("data-btn-ok-label", "Guardar") Guardar.Attributes.Add("data-html", "true") End If End If Guardar.Visible = True updatos.Visible = True updatos.Update() End Sub Protected Sub Guardar_Click(sender As Object, e As EventArgs) Handles Guardar.Click If Tnombre.Text.Trim = "" Then Alert("Ingrese nombre de la cuenta", TipoMensaje.MsgError) : Exit Sub Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) If ObjConta.UpdateCuenta(IDSelected.ToEntero, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, DdlAgrupadorSAT.SelectedValue.ToEntero, SubCuentaDe:=Tsubcuenta.Text.Trim) > 0 Then End If ObjConta.Dispose() Dim customerRow As Data.DataRow customerRow = DtDatos.Select(String.Format("Id = {0}", IDSelected))(0) customerRow("Nombre") = Tnombre.Text DtDatos.AcceptChanges() CargaDatos() ArbolCuentas.DataSource = DtDatos ArbolCuentas.DataBind() Dim item As CheckBox = DirectCast(ArbolCuentas.FindControl(String.Format("chk{0}", IDSelected)), CheckBox) item.Text = String.Format("{0} - {1}", customerRow("CuentaFormato").ToString, Tnombre.Text) 'updatos.Visible = False 'Guardar.Visible = False LimpiarCampos() updatos.Update() Alert("La cuenta se guardo correctamente") End Sub Protected Sub nuevacuenta_Click(sender As Object, e As EventArgs) Handles nuevacuenta.Click If Tnombre.Text.Trim = "" Then Alert("Ingrese nombre de la cuenta", TipoMensaje.MsgError) : Exit Sub If Tcuenta.Text.Trim = "" Then Alert("Ingrese la cuenta", TipoMensaje.MsgError) : Exit Sub Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) Dim CuentaEfectivo As Integer = 0 ' [IPP] VIEJO | COMENTADO 9/MARZO/2018 'Dim Afectable As Integer = If(DcuentaMayor.SelectedValue <> 2, 0, 1) ' cuando sea tipo 2, va a ser afectable Dim Afectable = 1 Dim idnew = ObjConta.AddCuenta(Tcuenta.Text.Replace("-", ""), Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, CuentaEfectivo, DdlMoneda.SelectedValue.ToEntero, TxtDigAgrup.Text.ToEntero, TxtNomIngles.Text.Trim, Afectable, IDSelected.ToEntero, DdlAgrupadorSAT.SelectedValue.ToEntero) If idnew > 0 Then Dim dr As DataRow = DtDatos.NewRow dr("id") = idnew dr("CuentaFormato") = Tcuenta.Text dr("Nombre") = Tnombre.Text dr("CtaCodigo") = String.Format("{0} - {1}", Tcuenta.Text, Tnombre.Text) dr("Tipo") = DTcuenta.SelectedValue.ToString dr("CtaMayor") = DcuentaMayor.SelectedValue.ToString dr("IdPadre") = IDSelected dr("Codigo") = Tnombre.Text dr("IdMoneda") = DdlMoneda.SelectedValue.ToEntero dr("DigAgrup") = TxtDigAgrup.Text.Trim.ToEntero dr("NomIdioma") = TxtNomIngles.Text.Trim DtDatos.Rows.Add(dr) ArbolCuentas.DataSource = DtDatos '.Attributes.Add("data-hijos","0"); Dim item As ADServerControl.DragableItem = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", IDSelected)), ADServerControl.DragableItem) item.Attributes.Item("data-hijos") = item.Attributes.Item("data-hijos").ToEntero + 1 Dim objul As ADServerControl.DragableUL = DirectCast(ArbolCuentas.FindControl(String.Format("ul{0}", IDSelected)), ADServerControl.DragableUL) If (IsNothing(objul)) Then objul = New ADServerControl.DragableUL objul.ID = String.Format("ul{0}", item.Cve) item.Controls.Add(objul) End If ArbolCuentas.additem(objul, idnew, IDSelected, String.Format("{0} - {1}", Tcuenta.Text, Tnombre.Text)) 'updatos.Visible = False 'nuevacuenta.Visible = False LimpiarCampos() updatos.Update() CargaDatos() Alert("La cuenta se guardo correctamente") End If ObjConta.Dispose() End Sub Private Sub LimpiarCampos() Tcuenta.Text = "" Tnombre.Text = "" DTcuenta.SelectedValue = "-1" DcuentaMayor.SelectedValue = "-1" DdlAgrupadorSAT.SelectedValue = "-1" Tsubcuenta.Text = "" Guardar.Visible = False nuevacuenta.Visible = False Tcuenta.Enabled = False BtnEliminar.Visible = False End Sub Protected Sub borrar_Click(sender As Object, e As EventArgs) Handles borrar.Click End Sub Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) ObjConta.IniciaTransacSQL() If ObjConta.RemoveCuenta(IDSelected.ToEntero) Then ObjConta.Commit() Dim customerRow As Data.DataRow customerRow = DtDatos.Select(String.Format("Id = {0}", IDSelected))(0) customerRow("IdPadre") = "-5" DtDatos.AcceptChanges() ArbolCuentas.DataSource = DtDatos Dim item As ADServerControl.DragableItem = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", IDSelected)), ADServerControl.DragableItem) Dim padre As ADServerControl.DragableItem = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", item.CvePadre)), ADServerControl.DragableItem) padre.Attributes.Item("data-hijos") = padre.Attributes.Item("data-hijos").ToEntero - 1 ArbolCuentas.Controls.Remove(item) RegistraScript(String.Format("$('#{0}').click();", editar.ClientID)) 'getNodospadreHijos(IDSelected).Rows(0).Delete() 'RegistraScript(String.Format("$('li#{0}').remove();", IDSelected)) LimpiarCampos() upcuentas.Update() Alert("La Cuenta ha sido eliminada", TipoMensaje.MsgInformacion) Else Alert("La Cuenta no pudo ser eliminada", TipoMensaje.MsgError) ObjConta.RollBack() End If ObjConta.Dispose() End Sub Private Sub LnkPdf_Click(sender As Object, e As EventArgs) Handles LnkPdf.Click Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) Dim params As New List(Of ReportParameter) params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) If Imagen.Exists Then params.Add(New ReportParameter("LogoPath", logouri)) Else params.Add(New ReportParameter("LogoPath", "")) End If ImprimirPDF("Empresas/Grales/Formatos/CatCuentas.rdlc", DtDatos.FiltraParametros("", "Orden ASC"), params, String.Format("Catalogo Cuentas-{0}", Now.ToDateTime.ToShortDateString)) End Sub End Class