Files
SIG/Contabilidad2/CatContaEjercicios.aspx.vb
2020-04-01 14:52:30 -07:00

114 lines
5.1 KiB
VB.net

Imports System.Data
Imports System.Linq
Imports Extensiones
Partial Class Contabilidad2_CatContaEjercicios
Inherits ClsPaginas
Private Property CveEjercicio() As Integer 'Guardamos el ID de registro para saber cual registro Editar
Get
Return If(IsNothing(ViewState("CveEjercicio")), -1, CInt(ViewState("CveEjercicio")))
End Get
Set
ViewState("CveEjercicio") = Value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
CargaDatos()
End If
End Sub
Private Sub CargaDatos()
Dim ObjConta As New ClsContabilidad
If ObjConta.GetContaEjercicio(UsuarioActual.CveEmpresa) Then
GvDatos.DataSource = ObjConta.DtResultados
End If
If ObjConta.GetCuentas(-1, "-1", -1, UsuarioActual.CveEmpresa) Then
DdlCuentas.DataSource = ObjConta.DtResultados
End If
ObjConta.Dispose()
GvDatos.DataBind()
DdlCuentas.DataBind()
DdlCuentas.Items.Insert(0, New ListItem("seleccione", "-1"))
End Sub
Protected Sub BtnAgregarMotivoD_Click(sender As Object, e As EventArgs) Handles BtnAgregarMotivoD.Click
TxtEjercicio.Text = ""
ChkEstatus.Checked = 0
DdlPeriodoActual.SelectedValue = 0
UpModalModulos.Update()
RegistraScript("$('#ModalCat').modal();")
End Sub
Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click
Dim ObjConta As New ClsContabilidad
Dim errorString As String = ""
If LbAgregar.Text = "Agregar" Then
If Not ObjConta.AddContaEjercicio(DateTime.Today, UsuarioActual.CvePersonal, UsuarioActual.CveEmpresa, Ejercicio:=TxtEjercicio.Text,
PeriodoActual:=DdlPeriodoActual.SelectedValue.ToEntero, CveCuentaCierre:=DdlCuentas.SelectedValue.ToEntero, Estatus:=ChkEstatus.Checked) Then
errorString = "Error al agregar"
End If
ElseIf LbAgregar.Text = "Actualizar" Then
If Not ObjConta.UpdateContaEjercicio(CveEjercicio, Ejercicio:=TxtEjercicio.Text, PeriodoActual:=DdlPeriodoActual.SelectedValue.ToEntero,
CveCuentaCierre:=DdlCuentas.SelectedValue.ToEntero, Estatus:=ChkEstatus.Checked) Then
errorString = "Error al actualizar"
End If
End If
ObjConta.Dispose()
RegistraScript("$('#ModalCat').modal('hide');")
CargaDatos()
UpDatos.Update()
If errorString.Length > 0 Then
Alert(errorString)
Else
If LbAgregar.Text = "Agregar" Then
Alert("Agregado correctamente")
ElseIf LbAgregar.Text = "Actualizar" Then
Alert("Actualizado correctamente")
End If
End If
End Sub
Protected Sub ActualizaModulo(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
CveEjercicio = GvRow.DataKey("CveEjercicio").ToEntero
TxtEjercicio.Text = GvRow.DataKey("Ejercicio")
ChkEstatus.Checked = GvRow.DataKey("Estatus")
DdlPeriodoActual.SelectedValue = GvRow.DataKey("PeriodoActualNumero")
DdlCuentas.SelectedValue = GvRow.DataKey("CveCuentaCierre")
LbAgregar.Text = "Actualizar"
UpModalModulos.Update()
RegistraScript("$('#ModalCat').modal();")
End Sub
Protected Sub EliminarRow(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim ObjConta As New ClsContabilidad
If ObjConta.RemoveContaEjercicio(GvRow.DataKey("CveEjercicio").ToEntero) Then
Alert("eliminado correctamente")
End If
ObjConta.Dispose()
CargaDatos()
UpDatos.Update()
End Sub
Protected Sub PolizaCierre(sender As Object, e As EventArgs)
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
Dim ObjConta As New ClsContabilidad
Dim FechaI As String = $"01/01/{DateTime.Now.Year}"
Dim FechaF As String = $"{DateTime.DaysInMonth(DateTime.Now.Year, 12)}/12/{DateTime.Now.Year}"
Dim CvePrePolizaCierre As Integer = -1
CvePrePolizaCierre = ObjConta.CierreEjercicio(UsuarioActual.CveEmpresa, GvRow.DataKey("Ejercicio").ToEntero, GvRow.DataKey("CveCuentaCierre").ToEntero, FechaI, FechaF, UsuarioActual.CvePersonal)
If CvePrePolizaCierre > 0 Then
If ObjConta.UpdateContaEjercicio(CveEjercicio, Ejercicio:=GvRow.DataKey("Ejercicio").ToEntero, PeriodoActual:=GvRow.DataKey("PeriodoActualNumero").ToEntero,
CveCuentaCierre:=GvRow.DataKey("CveCuentaCierre").ToEntero, CvePrePoliza:=CvePrePolizaCierre, Estatus:=GvRow.DataKey("Estatus")) Then
Alert("Cierre de ejercicio correcto")
End If
End If
ObjConta.Dispose()
End Sub
End Class