289 lines
10 KiB
VB.net
289 lines
10 KiB
VB.net
Imports System.Data
|
|
Imports Extensiones
|
|
|
|
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
|
|
CargaMonedas()
|
|
CargaDatos()
|
|
CargaAgrupadorSAT()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaMonedas()
|
|
DdlMoneda.DataSource = GlobalDTMonedas
|
|
DdlMoneda.DataBind()
|
|
End Sub
|
|
|
|
Private Sub CargaAgrupadorSAT()
|
|
Dim ObjConta As New ClsContabilidad
|
|
|
|
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 ClsContabilidad
|
|
|
|
If ObjConta.GetCuentas(-1, "-1", -1, UsuarioActual.CveEmpresa) 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 Then
|
|
Mascara = "0000"
|
|
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"
|
|
|
|
ObjConta.Dispose()
|
|
End Sub
|
|
|
|
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
|
|
|
|
Dim dt As New DataTable
|
|
Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem)
|
|
|
|
LimpiarCampos()
|
|
|
|
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 = 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
|
|
|
|
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
|
|
Dim dt As DataTable
|
|
Dim obj As ADServerControl.DragableItem = DirectCast(sender, ADServerControl.DragableItem)
|
|
|
|
LimpiarCampos()
|
|
|
|
IDSelected = obj.Cve
|
|
dt = getNodospadreHijos(IDSelected)
|
|
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
Dim dr As DataRow = dt.Rows(0)
|
|
Dim drt As DataRow
|
|
Dim Hijos As Integer
|
|
|
|
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
|
|
|
|
If dr("CveAgrupadorSAT").ToString.ToEntero = 0 Then
|
|
DdlAgrupadorSAT.SelectedValue = -1
|
|
Else
|
|
DdlAgrupadorSAT.SelectedValue = dr("CveAgrupadorSAT").ToString
|
|
End If
|
|
|
|
TxtDigAgrup.Text = dr("DigAgrup").ToString
|
|
TxtNomIngles.Text = dr("NomIdioma").ToString
|
|
|
|
Hijos = 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
|
|
drt = 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
|
|
|
|
Dim ObjConta As New ClsContabilidad
|
|
Dim customerRow As Data.DataRow
|
|
Dim item As CheckBox
|
|
|
|
If Tnombre.Text.Trim = "" Then Alert("Se debe ingresar un nombre a la Cuenta.", TipoMensaje.MsgError) : Exit Sub
|
|
|
|
If Not 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) Then
|
|
Alert("Ocurrió un error al actualizar la Cuenta.", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
ObjConta.Dispose()
|
|
|
|
customerRow = DtDatos.Select(String.Format("CveCuenta = {0}", IDSelected))(0)
|
|
customerRow("Nombre") = Tnombre.Text
|
|
DtDatos.AcceptChanges()
|
|
|
|
CargaDatos()
|
|
ArbolCuentas.DataSource = DtDatos
|
|
|
|
item = DirectCast(ArbolCuentas.FindControl(String.Format("chk{0}", IDSelected)), CheckBox)
|
|
item.Text = String.Format("{0} - {1}", customerRow("CuentaFormato").ToString, Tnombre.Text)
|
|
LimpiarCampos()
|
|
UpDatos.Update()
|
|
|
|
Alert("La Cuenta se guardó correctamente.")
|
|
|
|
End Sub
|
|
Protected Sub nuevacuenta_Click(sender As Object, e As EventArgs) Handles nuevacuenta.Click
|
|
|
|
If Tnombre.Text.Trim = "" Then Alert("Se debe asignar un nombre a la Cuenta.", TipoMensaje.MsgError) : Exit Sub
|
|
If Tcuenta.Text.Trim = "" Then Alert("Se debe asignar una Cuenta", TipoMensaje.MsgError) : Exit Sub
|
|
|
|
Dim ObjConta As New ClsContabilidad
|
|
Dim CuentaEfectivo As Integer = 0
|
|
Dim Afectable As Integer = If(DcuentaMayor.SelectedValue <> 2, 0, 1) ' cuando sea tipo 2, va a ser afectable
|
|
|
|
Dim idnew = ObjConta.AddCuenta(IDSelected, Tcuenta.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 dr As DataRow = DtDatos.NewRow
|
|
Dim item As ADServerControl.DragableItem
|
|
Dim objul As ADServerControl.DragableUL
|
|
|
|
dr("CveCuenta") = 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("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
|
|
|
|
item = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", IDSelected)), ADServerControl.DragableItem)
|
|
objul = DirectCast(ArbolCuentas.FindControl(String.Format("ul{0}", IDSelected)), ADServerControl.DragableUL)
|
|
|
|
item.Attributes.Item("data-hijos") = item.Attributes.Item("data-hijos").ToEntero + 1
|
|
|
|
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))
|
|
|
|
LimpiarCampos()
|
|
|
|
UpDatos.Update()
|
|
CargaDatos()
|
|
|
|
Alert("La Cuenta se guardó correctamente.")
|
|
End If
|
|
|
|
ObjConta.Dispose()
|
|
End Sub
|
|
Private Sub LimpiarCampos()
|
|
Tcuenta.Text = ""
|
|
Tnombre.Text = ""
|
|
DTcuenta.SelectedValue = "-1"
|
|
DcuentaMayor.SelectedValue = "-1"
|
|
DdlAgrupadorSAT.SelectedValue = "-1"
|
|
DdlMoneda.SelectedValue = "1"
|
|
TxtDigAgrup.Text = ""
|
|
TxtNomIngles.Text = ""
|
|
Guardar.Visible = False
|
|
nuevacuenta.Visible = False
|
|
Tcuenta.Enabled = False
|
|
BtnEliminar.Visible = False
|
|
End Sub
|
|
|
|
Protected Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click
|
|
Dim customerRow As Data.DataRow
|
|
Dim item As ADServerControl.DragableItem
|
|
Dim padre As ADServerControl.DragableItem
|
|
Dim ObjConta As New ClsContabilidad
|
|
|
|
ObjConta.IniciaTransacSQL()
|
|
|
|
If ObjConta.RemoveCuenta(IDSelected.ToEntero) Then
|
|
|
|
customerRow = DtDatos.Select(String.Format("CveCuenta = {0}", IDSelected))(0)
|
|
customerRow("CvePadre") = "-5"
|
|
DtDatos.AcceptChanges()
|
|
|
|
ArbolCuentas.DataSource = DtDatos
|
|
item = DirectCast(ArbolCuentas.FindControl(String.Format("{0}", IDSelected)), ADServerControl.DragableItem)
|
|
padre = 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()
|
|
|
|
ObjConta.Commit()
|
|
Alert("La Cuenta ha sido eliminada", TipoMensaje.MsgInformacion)
|
|
Else
|
|
ObjConta.RollBack()
|
|
Alert("La Cuenta no pudo ser eliminada", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
ObjConta.Dispose()
|
|
End Sub
|
|
End Class |