Imports System.Data Imports Extensiones Partial Class Contabilidad2_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 DtConceptosconta As DataTable Get Return CType(ViewState("DtConceptosconta"), DataTable) End Get Set(value As DataTable) ViewState("DtConceptosconta") = 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 #Region "Contabilidadnew" Private Property CveProveedor As Integer Get Return ViewState("CveProveedor").ToString.ToEntero() End Get Set(value As Integer) ViewState("CveProveedor") = value End Set End Property Private Property CveCliente As Integer Get Return ViewState("CveCliente").ToString.ToEntero() End Get Set(value As Integer) ViewState("CveCliente") = value End Set End Property Private Property CveClasificacion As Integer Get Return ViewState("CveClasificacion").ToString.ToEntero() End Get Set(value As Integer) ViewState("CveClasificacion") = value End Set End Property Private Property CveBancoCuenta As Integer Get Return ViewState("CveBancoCuenta").ToString.ToEntero() End Get Set(value As Integer) ViewState("CveBancoCuenta") = value End Set End Property Private Property CveAlmacen As Integer Get Return ViewState("CveAlmacen").ToString.ToEntero() End Get Set(value As Integer) ViewState("CveAlmacen") = value End Set End Property #End Region #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 DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) DdlAlmacen.DataBind() CargaMonedas() CargaAgrupadorSAT() CargaDatos() Using objconta As New ClsContabilidad objconta.GetConta_ConceptosContables(1) DtConceptosconta = objconta.DtResultados End Using DdlConcepto.DataSource = DtConceptosconta DdlConcepto.DataBind() DdlConcepto.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Else ' Alert("Este módulo requiere el uso de Contabilidad.", TipoMensaje.MsgAdvertencia) ' MEECuenta.Enabled = False 'End If End If End Sub Private Sub CargaMonedas() 'Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) Dim ObJConta As New ClsContabilidad 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) Dim ObjConta As New ClsContabilidad If ObjConta.GetAgrupadoresSAT(UsuarioActual.CveEmpresa) 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) Dim ObjConta As New ClsContabilidad If ObjConta.GetCuentas(-1, "-1", -1, UsuarioActual.CveEmpresa) Then DtDatos = ObjConta.DtResultados End If ObjConta.Dispose() '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 Then Mascara = DtDatos.Rows(0)("Codigo").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 = "CveCuenta" ArbolCuentas.padre = "CvePadre" ArbolCuentas.titulo = "CtaCodigo" 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("CveCuenta = {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) TxtCuenta.Text = Trim(dr("CuentaFormato").ToString.Replace("-", "").ToString) 'Tcuenta.Text = Trim(dr("CuentaFormato").ToString.Replace("-", "").ToString) Tsubcuenta.Text = dr("CuentaFormato").ToString() DTcuenta.SelectedValue = dr("Tipo").ToString() DcuentaMayor.SelectedValue = dr("CtaMayor").ToString LblSubCuenta.Text = dr("Nombre").ToString End If TxtCuenta.Enabled = True 'Tcuenta.Enabled = True nuevacuenta.Visible = True updatos.Visible = True updatos.Update() End Sub Private Sub limpiavalorescontables() DdlConcepto.SelectedValueExist(-1) onconceptochange() CveProveedor = -1 DdlProveedores.SelectedText = "" DdlProveedores.SelectedValue = CveProveedor CveCliente = -1 DdlClientesWS.SelectedText = "" DdlClientesWS.SelectedValue = CveCliente Dim PorcentajeImpuesto As Decimal = -1 DdlClasificacion.SelectedValueExist(PorcentajeImpuesto) CveClasificacion = -1 DdlClasificacion.SelectedValueExist(CveClasificacion) CveBancoCuenta = -1 CveAlmacen = -1 DdlAlmacen.SelectedValueExist(CveAlmacen) End Sub Protected Sub editar_Click(sender As Object, e As EventArgs) Handles ArbolCuentas.editclick LimpiarCampos() limpiavalorescontables() 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) TxtCuenta.Text = dr("CuentaFormato").ToString.Replace("-", "").ToString 'Tcuenta.Text = dr("CuentaFormato").ToString.Replace("-", "").ToString Tnombre.Text = dr("Nombre").ToString() DTcuenta.SelectedValue = dr("Tipo").ToString() DcuentaMayor.SelectedValue = dr("CtaMayor").ToString DdlMoneda.SelectedValue = dr("CveMoneda").ToString Using objconta As New ClsContabilidad objconta.GetConta_CuentasDataContabilidad(IDSelected, UsuarioActual.CveEmpresa) If objconta.DtResultados.Rows.Count > 0 Then Dim rowcc As DataRow = objconta.DtResultados.Rows(0) DdlConcepto.SelectedValueExist(rowcc("CveConceptoAdmin").ToString().ToEntero()) onconceptochange() CveProveedor = rowcc("CveProveedor").ToString().ToEntero() DdlProveedores.SelectedText = rowcc("Proveedor").ToString().ToEntero() DdlProveedores.SelectedValue = CveProveedor CveCliente = rowcc("CveCliente").ToString().ToEntero() DdlClientesWS.SelectedText = rowcc("Cliente").ToString().ToEntero() DdlClientesWS.SelectedValue = CveCliente Dim PorcentajeImpuesto As Decimal = rowcc("PorcentajeImpuesto").ToString().ToDecimal() * 100 TxtPorcentaje.Text = (PorcentajeImpuesto) CveClasificacion = rowcc("CveClasificacion").ToString().ToEntero() DdlClasificacion.SelectedValueExist(CveClasificacion) CveBancoCuenta = rowcc("CveBancoCuenta").ToString().ToEntero() CveAlmacen = rowcc("CveAlmacen").ToString().ToEntero() DdlAlmacen.SelectedValueExist(CveAlmacen) End If End Using If dr("CveAgrupadorSAT").ToString.ToEntero = 0 Then DdlAgrupadorSAT.SelectedValue = -1 Else DdlAgrupadorSAT.SelectedValueExist(dr("CveAgrupadorSAT").ToString) End If TxtDigAgrup.Text = dr("DigAgrup").ToString TxtNomIngles.Text = dr("NomIdioma").ToString Dim Hijos As Integer = DtDatos.FiltraParametros(String.Format("CvePadre = {0}", IDSelected)).Rows.Count If Hijos = 0 Then BtnEliminar.Visible = True dt = getNodospadreHijos(dr("CvePadre").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 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) Dim ObjConta As New ClsContabilidad Dim CveConceptoAdmin As Integer = DdlConcepto.SelectedValue.ToEntero() Dim CveProveedor As Integer = DdlProveedores.SelectedValue.ToEntero() Dim CveCliente As Integer = DdlClientesWS.SelectedValue.ToEntero() Dim CveClasificacion As Integer = DdlClasificacion.SelectedValue.ToEntero() Dim PorcentajeImpuesto As Decimal = TxtPorcentaje.Text.ToDecimal() / 100 Dim CveBancoCuenta As Integer = -1 Dim CveAlmacen As Integer = DdlAlmacen.SelectedValue.ToEntero() If ObjConta.UpdateCuenta(IDSelected.ToEntero, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, TxtDigAgrup.Text.ToString.ToEntero, DdlAgrupadorSAT.SelectedValue.ToEntero, TxtNomIngles.Text.ToString, CveConceptoAdmin:=CveConceptoAdmin, CveProveedor:=CveProveedor, CveCliente:=CveCliente, CveClasificacion:=CveClasificacion, PorcentajeImpuesto:=PorcentajeImpuesto, CveBancoCuenta:=CveBancoCuenta, CveAlmacen:=CveAlmacen) Then Dim codigo As String = DtDatos.FiltroPrimeroValor("Codigo", $"CveCuenta={IDSelected}") If UsuarioActual.Empresa.TipoContabilizacion <> 1 Then Using ObjConta2 As New ClsContPAQi(UsuarioActual.Empresa) If ObjConta2.GetCuentas(-1, "-1", -1) Then Dim Id As Integer = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"Codigo='{codigo}'").ToEntero Dim IdAgrupador As Integer If ObjConta2.GetAgrupadoresSAT() Then IdAgrupador = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"CodigoNombre='{DdlAgrupadorSAT.SelectedItem.Text}'").ToEntero End If If Id > 0 Then If ObjConta2.UpdateCuenta(Id, Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, IdAgrupador, SubCuentaDe:=Tsubcuenta.Text.Trim) > 0 Then End If End If End If End Using End If Dim customerRow As Data.DataRow customerRow = DtDatos.Select(String.Format("CveCuenta = {0}", IDSelected))(0) customerRow("Nombre") = Tnombre.Text DtDatos.AcceptChanges() CargaDatos() ArbolCuentas.DataSource = DtDatos 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() 'RegistraScript("$get('BtnCambiaAgrupadorSAT').click();") updatos.Update() Alert("La cuenta se guardo correctamente") End If ObjConta.Dispose() 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 TxtCuenta.Text.Trim = "" Then Alert("Ingrese 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 ObjConta As New ClsContabilidad Dim ObjConta2 As New ClsContPAQi(UsuarioActual.Empresa) Dim CuentaEfectivo As Integer = 0 Dim Afectable As Integer = 1 'If(DcuentaMayor.SelectedValue <> 2, 0, 1) ' cuando sea tipo 2, va a ser afectable Tcuenta.Text.Replace("-", "") Dim idnew As Integer = ObjConta.AddCuenta( IDSelected, TxtCuenta.Text.Replace("-", ""), Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, DdlMoneda.SelectedValue.ToEntero, TxtDigAgrup.Text.ToEntero, DdlAgrupadorSAT.SelectedValue.ToEntero, TxtNomIngles.Text.ToString) If idnew > 0 Then Dim codigoPadre As String = DtDatos.FiltroPrimeroValor("Codigo", $"CveCuenta={IDSelected}") 'Tsubcuenta.Text If ObjConta2.GetCuentas(-1, "-1", -1) Then Dim IdPadre As Integer = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"Codigo='{codigoPadre}'").ToEntero Dim IdAgrupador As Integer If ObjConta2.GetAgrupadoresSAT() Then IdAgrupador = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"CodigoNombre='{DdlAgrupadorSAT.SelectedItem.Text}'").ToEntero End If If IdPadre > 0 Then Dim idnew2 As Integer = ObjConta2.AddCuenta(TxtCuenta.Text.Replace("-", ""), Tnombre.Text, DTcuenta.SelectedValue.ToString, DcuentaMayor.SelectedValue.ToString.ToEntero, CuentaEfectivo, DdlMoneda.SelectedValue.ToEntero, TxtDigAgrup.Text.ToEntero, TxtNomIngles.Text.Trim, Afectable, IdPadre, IdAgrupador) If idnew2 > 0 Then If ObjConta.UpdateCuentaCompaq(idnew, idnew2, UsuarioActual.CveEmpresa) Then End If End If End If End If Dim dr As DataRow = DtDatos.NewRow dr("CveCuenta") = idnew dr("CuentaFormato") = TxtCuenta.Text 'dr("CuentaFormato") = Tcuenta.Text dr("Nombre") = Tnombre.Text dr("CtaCodigo") = String.Format("{0} - {1}", TxtCuenta.Text, Tnombre.Text) 'dr("CtaCodigo") = String.Format("{0} - {1}", Tcuenta.Text, Tnombre.Text) dr("Tipo") = DTcuenta.SelectedValue.ToString dr("CtaMayor") = DcuentaMayor.SelectedValue.ToString dr("CvePadre") = IDSelected dr("Codigo") = Tnombre.Text dr("CveMoneda") = 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}", TxtCuenta.Text, Tnombre.Text)) '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() ObjConta2.Dispose() End Sub Private Sub LimpiarCampos() TxtCuenta.Text = "" 'Tcuenta.Text = "" Tnombre.Text = "" DTcuenta.SelectedValue = "-1" DcuentaMayor.SelectedValue = "-1" DdlAgrupadorSAT.SelectedValue = "-1" Tsubcuenta.Text = "" TxtDigAgrup.Text = "" Guardar.Visible = False nuevacuenta.Visible = False TxtCuenta.Enabled = 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) Dim ObjConta As New ClsContabilidad Dim ObjConta2 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("CveCuenta = {0}", IDSelected))(0) customerRow("CvePadre") = "-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)) LimpiarCampos() upcuentas.Update() Alert("La Cuenta ha sido eliminada", TipoMensaje.MsgInformacion) Dim codigo As String = DtDatos.FiltroPrimeroValor("Codigo", $"CveCuenta={IDSelected}") If ObjConta2.GetCuentas(-1, "-1", -1) Then Dim Id As Integer = ObjConta2.DtResultados.FiltroPrimeroValor("Id", $"Codigo='{codigo}'").ToEntero If Id > 0 Then If ObjConta2.RemoveCuenta(Id) Then End If End If End If Else Alert("La Cuenta no pudo ser eliminada", TipoMensaje.MsgError) ' ObjConta.RollBack() End If ObjConta.Dispose() ObjConta2.Dispose() End Sub 'Protected Sub BtnCambiaAgrupadorSAT_Click(sender As Object, e As EventArgs) ' CargaAgrupadorSAT() 'End Sub Protected Sub DdlConcepto_SelectedIndexChanged(sender As Object, e As EventArgs) onconceptochange() End Sub Private Sub onconceptochange(Optional CveCuenta As Integer = -1) PnlOpcion1.Visible = False pnlOpcion2.Visible = False pnlOpcion3.Visible = False pnlOpcion4.Visible = False pnlOpcion5.Visible = False pnlOpcion6.Visible = False Dim CveConceptoContable As Integer = DdlConcepto.SelectedValue.ToEntero() Dim row As DataRow = Nothing Dim CveTipoSaldo As Integer = 0 Dim CveParejaContable As Integer = 0 If CveConceptoContable > 0 Then row = DtConceptosconta.FiltroPrimero(String.Format("CveConceptoContable={0}", CveConceptoContable)) CveTipoSaldo = row("CveTipoSaldo").ToString.ToEntero() CveParejaContable = row("CveParejaContable").ToString().ToEntero() End If If Not IsNothing(row) Then Select Case CveTipoSaldo Case 1 PnlOpcion1.Visible = True Case 2 pnlOpcion2.Visible = True Case 3 pnlOpcion3.Visible = True If DdlClasificacion.Items.Count < 2 Then DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa, UsoClasificacion:=1) DdlClasificacion.DataBind() End If Case 4 pnlOpcion4.Visible = True Case 5 pnlOpcion5.Visible = True Case 6 pnlOpcion6.Visible = True End Select End If End Sub End Class