Imports System.Data Imports Extensiones Partial Class Contabilidad2_CatCuentasAsignaciones Inherits ClsPaginas Private Property CveConceptoAsignacion() As Integer 'Guardamos el ID de registro para saber cual registro Editar Get Return If(IsNothing(ViewState("CveConceptoAsignacion")), -1, CInt(ViewState("CveConceptoAsignacion"))) End Get Set ViewState("CveConceptoAsignacion") = Value End Set End Property Public Property OpAgregar As Boolean Get If ViewState("OpAgregar") Is Nothing Then ViewState("OpAgregar") = False End If Return Boolean.Parse(ViewState("OpAgregar").ToString) End Get Set(value As Boolean) ViewState("OpAgregar") = value End Set End Property Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then HttpContext.Current.Application("GlobalDTContaConceptosContables") = Nothing DdlConceptos.DataSource = GlobalDTContaConceptosContables(-1) DdlConceptos.DataBind() DdlConceptos.Items.Insert(0, New ListItem("Todos", "-1")) CargaDatosModal() End If End Sub Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) CargaDatosSistema() End Sub 'Private Sub CargaDatos() ' Dim ObjConta As New ClsContabilidad ' If ObjConta.GetCuentasAsignaciones(UsuarioActual.CveEmpresa) Then ' GvDatos.DataSource = ObjConta.DtResultados ' End If ' ObjConta.Dispose() ' GvDatos.DataBind() 'End Sub Private Sub CargaDatosSistema() Dim ObjConta As New ClsContabilidad If ObjConta.GetCuentasAsignacionesSistema(UsuarioActual.CveEmpresa, DdlTipo.SelectedValue.ToEntero, DdlOpcion.SelectedValue.ToEntero, DdlConceptos.SelectedValue.ToEntero) Then GvDatos.DataSource = ObjConta.DtResultados End If GvDatos.Columns(4).Visible = ObjConta.DtResultados.MAX("CveSubProyecto").ToEntero > 0 GvDatos.Columns(5).Visible = ObjConta.DtResultados.MAX("PorcentajeIVA").ToDecimal > 0 GvDatos.Columns(6).Visible = ObjConta.DtResultados.MAX("TipoGasto") <> "" If ObjConta.GetCuentasGlobales(UsuarioActual.CveEmpresa) Then GvGlobal.DataSource = ObjConta.DtResultados End If ObjConta.Dispose() GvDatos.DataBind() GvGlobal.DataBind() UpDatos.Update() End Sub Private Sub CargaDatosModal() DdlConceptoNomina.DataSource = GlobalDTNomConceptos(UsuarioActual.CveEmpresa) DdlConceptoNomina.DataBind() If UsuarioActual.Empresa.TipoContabilidad = 2 Then Dim Con As New ClsContPAQi(UsuarioActual.Empresa) Con.SincronizaCuentas(UsuarioActual.CveEmpresa) Con.Dispose() End If Dim ObjConta As New ClsContabilidad If ObjConta.GetConta_ConceptosContables() Then DdlCconceptosContables.DataSource = ObjConta.DtResultados.FiltraParametros("EsSistema = True ") DdlConceptoGlobal.DataSource = ObjConta.DtResultados.FiltraParametros(" EsSistema = True AND EsGlobal = True") End If If ObjConta.GetCuentas(-1, "-1", 1, UsuarioActual.CveEmpresa) Then DdlCuenta.DataSource = ObjConta.DtResultados DdlCuentaGlobal.DataSource = ObjConta.DtResultados End If ObjConta.Dispose() DdlProveedor.setEsWebService(True) 'GlobalDTCompProveedores(UsuarioActual.CveEmpresa) DdlClientes.setEsWebService(True) DdlPersonal.setEsWebService(True) DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) DdlAlmacen.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa) DdlActivoFijo.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa) DdlSubProyectos.DataSource = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa, Estatus:=-1) DdlSubProyectos.Items.Insert(0, New ListItem("-", "0")) Dim ObjBancos As New ClsBancos If ObjBancos.GetBancosCuentas(-1, CveEmpresa:=UsuarioActual.CveEmpresa) Then DdlCuentaBancaria.DataSource = ObjBancos.DtResultados.FiltraParametros("CveEmpresa = " & UsuarioActual.CveEmpresa) End If ObjBancos.Dispose() DdlCuentaBancaria.DataBind() DdlCconceptosContables.DataBind() DdlConceptoGlobal.DataBind() DdlCuenta.DataBind() DdlCuentaGlobal.DataBind() DdlProveedor.DataBind() 'DdlPersonal.DataBind() DdlClasificacion.DataBind() DdlAlmacen.DataBind() DdlSubProyectos.DataBind() DdlCuentaBancaria.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlConceptoNomina.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlCconceptosContables.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlCuenta.Items.Insert(0, New ListItem("Seleccione", "-1")) 'DdlProveedor.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlClasificacion.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlAlmacen.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Protected Sub ActualizaModulo(sender As Object, e As EventArgs) OpAgregar = False LimpiarDatos() Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) Dim Dr As DataRow = GlobalDTContaConceptosContables(GvRow.DataKey("CveConceptoContable").ToEntero).FiltroPrimero("") Dim CveConceptoContable As Integer = GvRow.DataKey("CveConceptoContable").ToString.ToEntero HdnCveCuentaAsignacion.Value = GvRow.DataKey("CveCuentaAsignacion").ToString If Dr IsNot Nothing Then DdlCconceptosContables.Enabled = False DdlSubProyectos.Enabled = False DdlClasificacion.Enabled = False DdlPersonal.Enabled = False RecargaConcepto(CveConceptoContable) CveConceptoAsignacion = GvRow.DataKey("CveCuentaAsignacion").ToEntero DdlCconceptosContables.SelectedValueExist(GvRow.DataKey("CveConceptoContable")) DdlCuenta.SelectedValueExist(GvRow.DataKey("CveCuenta")) DdlConceptoNomina.SelectedValueExist(GvRow.DataKey("CveConceptoNomina").ToEntero) If GvRow.DataKey("CveProveedor").ToEntero > 0 Then DdlProveedor.ddl.Items.Clear() DdlProveedor.ddl.ClearSelection() Dim NomProv As String = GlobalDTCompProveedores(UsuarioActual.CveEmpresa, CveProveedor:=GvRow.DataKey("CveProveedor").ToEntero).FiltroPrimeroValor("NombreComercial") DdlProveedor.ddl.Items.Add(New ListItem(NomProv, GvRow.DataKey("CveProveedor"))) DdlProveedor.SelectedValue = GvRow.DataKey("CveProveedor") End If DdlClasificacion.SelectedValueExist(GvRow.DataKey("CveClasificacion")) DdlAlmacen.SelectedValueExist(GvRow.DataKey("CveAlmacen")) TxtPorcentajeIVA.Text = GvRow.DataKey("PorcentajeIVA") DdlCuentaBancaria.SelectedValueExist(GvRow.DataKey("CveBancoCuenta")) DdlSubProyectos.SelectedValueExist(GvRow.DataKey("CveSubProyecto").ToEntero) DdlTipoGasto.SelectedValueExist(GvRow.DataKey("CveTipoGasto").ToEntero) DdlActivoFijo.SelectedValueExist(GvRow.DataKey("CveActivoFijo").ToEntero) DdlActivoFijo.Enabled = False Dim CveCliente As Integer = GvRow.DataKey("CveCliente").ToEntero Dim CvePersonal As Integer = GvRow.DataKey("CvePersonal").ToEntero DdlColectivas.SelectedValueExist(GvRow.DataKey("CveColectiva").ToEntero) If CveCliente > 0 Then Dim drp As String = GlobalDTCliente(UsuarioActual.CveEmpresa, CveCliente:=CveCliente).FiltroPrimeroValor("Nombre") DdlClientes.ddl.Items.Insert(0, New ListItem(drp, CveCliente.ToString)) DdlClientes.SelectedValue = CveCliente.ToString DdlClientes.SelectedText = drp End If If CvePersonal > 0 Then Dim drp As String = GlobalDTRHPersonal(UsuarioActual.CveEmpresa, CvePersonal:=CvePersonal).FiltroPrimeroValor("NombreCompleto") DdlPersonal.ddl.Items.Insert(0, New ListItem(drp, CvePersonal.ToString)) DdlPersonal.SelectedValue = CvePersonal.ToString DdlPersonal.SelectedText = drp End If If GvRow.DataKey("CveCredito").ToEntero > 0 Then DdlCreditos.Items.Clear() DdlCreditos.ClearSelection() Dim ObjCreditos As New ClsBancos If ObjCreditos.GetCreditos(-1, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then DdlCreditos.DataSource = ObjCreditos.DtResultados.FiltraParametros("", DistinctColumns:={"CveCredito", "Referencia"}) End If ObjCreditos.Dispose() DdlCreditos.DataBind() DdlCreditos.SelectedValue = GvRow.DataKey("CveCredito") End If LbAgregar.Text = "Actualizar" UpModalModulos.Update() RegistraScript("$('#ModalCat').modal();") End If End Sub Private Sub RecargaConcepto(CveConceptoContable As Integer) Dim Dr As DataRow = GlobalDTContaConceptosContables(CveConceptoContable).FiltroPrimero("") If Dr IsNot Nothing Then divCliente.Visible = Boolean.Parse(Dr("AplicaCliente").ToString) divProveedor.Visible = Boolean.Parse(Dr("AplicaProveedor").ToString) divPersonal.Visible = Boolean.Parse(Dr("AplicaPersonal").ToString) divPorcentajeIVA.Visible = Boolean.Parse(Dr("AplicaImpuesto").ToString) divClasificacion.Visible = Boolean.Parse(Dr("AplicaClasificacion").ToString) divBancos.Visible = Boolean.Parse(Dr("AplicaBancos").ToString) divAlmacen.Visible = Boolean.Parse(Dr("AplicaAlmacen").ToString) divSubProyectos.Visible = Boolean.Parse(Dr("AplicaSubProyecto").ToString) divActivoFijo.Visible = Boolean.Parse(Dr("AplicaActivoFijo").ToString) divCredito.Visible = Boolean.Parse(Dr("AplicaCredito").ToString) divColectivas.Visible = Boolean.Parse(Dr("AplicaColectiva").ToString) DdlActivoFijo.Enabled = False If Dr("AplicaActivoFijo").ToString = "True" Then DdlActivoFijo.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa) DdlActivoFijo.DataBind() ' DdlActivoFijo.SelectedValueExist(GvRow.DataKey("CveActivoFijo")) If OpAgregar Then DdlActivoFijo.Enabled = True Else DdlActivoFijo.Enabled = False End If End If divConceptoNomina.Visible = Dr("AplicaNomina").ToString = "True" If CveConceptoContable = 51 Then divTipoGasto.Visible = True DdlTipoGasto.Items.Clear() DdlTipoGasto.DataSource = GlobalDTTiposGastos(UsuarioActual.CveEmpresa) DdlTipoGasto.DataBind() DdlTipoGasto.Items.Add(New ListItem("-", "-1")) End If If Dr("CveTipoSaldo").ToString = "1" Then divRegeneraCuenta.Visible = True End If If Dr("AplicaCredito").ToString = "True" Then Dim ObjCreditos As New ClsBancos If ObjCreditos.GetCreditos(-1, -1, -1, -1, -1, UsuarioActual.CveEmpresa) Then DdlCreditos.DataSource = ObjCreditos.DtResultados.FiltraParametros("", DistinctColumns:={"CveCredito", "Referencia"}) End If ObjCreditos.Dispose() DdlCreditos.DataBind() If OpAgregar Then DdlCreditos.Enabled = True Else DdlCreditos.Enabled = False End If End If If Dr("AplicaColectiva").ToString = "True" Then Dim ObjG As New ClsGenerales If ObjG.GetColectivas(UsuarioActual.CveEmpresa, CveConceptoContable:=DdlCconceptosContables.SelectedValue.ToEntero) Then DdlColectivas.DataSource = ObjG.DtResultados End If ObjG.Dispose() DdlColectivas.DataBind() DdlColectivas.Items.Insert(0, New ListItem("-", "-1")) If OpAgregar Then DdlColectivas.Enabled = True Else DdlColectivas.Enabled = False End If End If End If 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.RemoveCuentasAsignaciones(GvRow.DataKey("CveCuentaAsignacion").ToEntero) Then Alert("se elimino correctamente") End If CargaDatosSistema() UpDatos.Update() ObjConta.Dispose() End Sub Protected Sub BtnAgregarGlobal_Click(sender As Object, e As EventArgs) Handles BtnAgregarGlobal.Click UppModalGlobal.Update() RegistraScript("$('#ModalGlobal').modal();") End Sub Protected Sub EliminarRowGlobal(sender As Object, e As EventArgs) Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow) Dim ObjConta As New ClsContabilidad If ObjConta.RemoveCuentasGlobales(GvRow.DataKey("CveConceptoContable").ToEntero, GvRow.DataKey("CveEmpresa").ToEntero) Then Alert("se elimino correctamente") End If CargaDatosSistema() UpDatos.Update() ObjConta.Dispose() End Sub Protected Sub BtnAgregarAsignacion_Click(sender As Object, e As EventArgs) Handles BtnAgregarAsignacion.Click OpAgregar = True LimpiarDatos() DdlCconceptosContables.Enabled = True DdlSubProyectos.Enabled = True DdlClasificacion.Enabled = True DdlPersonal.Enabled = True LbAgregar.Text = "Agregar" UpModalModulos.Update() RegistraScript("$('#ModalCat').modal();") End Sub Private Sub LimpiarDatos() CveConceptoAsignacion = -1 DdlCconceptosContables.SelectedValue = "-1" DdlCuenta.SelectedValue = "-1" DdlProveedor.SelectedValue = "-1" DdlClasificacion.SelectedValue = "-1" DdlAlmacen.SelectedValue = "-1" DdlConceptoNomina.SelectedValue = "-1" DdlCuentaBancaria.SelectedValueExist("-1") TxtPorcentajeIVA.Text = "" DdlClientes.ddl.DataSource = "" DdlClientes.ddl.DataBind() DdlClientes.setEsWebService(True) DdlPersonal.ddl.DataSource = "" DdlPersonal.ddl.DataBind() DdlPersonal.setEsWebService(True) HdnCveCuentaAsignacion.Value = "" If OpAgregar Then divCliente.Visible = False divProveedor.Visible = False divPersonal.Visible = False divPorcentajeIVA.Visible = False divClasificacion.Visible = False divBancos.Visible = False divAlmacen.Visible = False divSubProyectos.Visible = False divActivoFijo.Visible = False End If End Sub Protected Sub LbAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click Dim ObjConta As New ClsContabilidad ObjConta.IniciaTransacSQL() Dim ErrorString As String = "" If HdnCveCuentaAsignacion.Value.ToEntero <= 0 Then If Not ObjConta.AddCuentasAsignaciones(DdlCconceptosContables.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlCuenta.SelectedValue.ToEntero, DdlProveedor.SelectedValue.ToEntero, DdlClientes.SelectedValue.ToEntero, DdlPersonal.SelectedValue.ToEntero, DdlClasificacion.SelectedValue.ToEntero, DdlAlmacen.SelectedValue.ToEntero, TxtPorcentajeIVA.Text.ToDecimal, CveBancoCuenta:=DdlCuentaBancaria.SelectedValue.ToEntero(), CveConceptoNomina:=DdlConceptoNomina.SelectedValue.ToEntero(), CveSubProyecto:=DdlSubProyectos.SelectedValue.ToEntero, CveActivoFijo:=DdlActivoFijo.SelectedValue.ToEntero, CveColectiva:=DdlColectivas.SelectedValue.ToEntero, CveTipoGasto:=DdlTipoGasto.SelectedValue.ToEntero, CveCredito:=DdlCreditos.SelectedValue.ToEntero, RegeneraCuenta:=chkRegeneraCuenta.Checked) Then ErrorString = "Error al agregar" End If ElseIf HdnCveCuentaAsignacion.Value.ToEntero > 0 Then If Not ObjConta.UpdateCuentasAsignaciones(CveConceptoAsignacion, DdlCconceptosContables.SelectedValue.ToEntero, DdlCuenta.SelectedValue.ToEntero, DdlProveedor.SelectedValue.ToEntero, DdlClientes.SelectedValue.ToEntero, DdlPersonal.SelectedValue.ToEntero, DdlClasificacion.SelectedValue.ToEntero, DdlAlmacen.SelectedValue.ToEntero, TxtPorcentajeIVA.Text.ToDecimal, CveBancoCuenta:=DdlCuentaBancaria.SelectedValue.ToEntero(), CveConceptoNomina:=DdlConceptoNomina.SelectedValue.ToEntero(), CveSubProyecto:=DdlSubProyectos.SelectedValue.ToEntero, CveActivoFijo:=DdlActivoFijo.SelectedValue.ToEntero, CveColectiva:=DdlColectivas.SelectedValue.ToEntero, CveTipoGasto:=DdlTipoGasto.SelectedValue.ToEntero, CveCredito:=DdlCreditos.SelectedValue.ToEntero, RegeneraCuenta:=chkRegeneraCuenta.Checked) Then ErrorString = "Error al actualizar" End If End If If Not ChkSeguirRegistrando.Checked Then RegistraScript("$('#ModalCat').modal('hide');") If ErrorString.Length > 0 Then ObjConta.RollBack() Alert(ErrorString) Else ObjConta.Commit() Alert("Agregado correctamente") End If ObjConta.Dispose() CargaDatosSistema() UpDatos.Update() End Sub Protected Sub LBAgregaGlobal_Click(sender As Object, e As EventArgs) Dim ErrorString As String = "" Dim ObjConta As New ClsContabilidad If Not ObjConta.AddCuentasGlobales(DdlConceptoGlobal.SelectedValue.ToEntero, DdlCuentaGlobal.SelectedValue.ToEntero, DdlTipoGlobal.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then ErrorString = "Error al agregar" End If ObjConta.Dispose() If ErrorString.Length > 0 Then Alert(ErrorString) Else Alert("Agregado correctamente") End If CargaDatosSistema() UpDatos.Update() End Sub Private Sub DdlCconceptosContables_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCconceptosContables.SelectedIndexChanged RecargaConcepto(DdlCconceptosContables.SelectedValue.ToEntero) End Sub Private Sub DdlTipoGlobal_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoGlobal.SelectedIndexChanged Dim Afectables As Integer = 1 If DdlTipoGlobal.SelectedValue = "2" Then 'cuando es detallado, que de la opción de seleccionar una de mayor y/o no afectable Afectables = -1 End If Dim ObjConta As New ClsContabilidad If ObjConta.GetCuentas(-1, "-1", Afectables, UsuarioActual.CveEmpresa) Then DdlCuentaGlobal.DataSource = ObjConta.DtResultados.FiltraParametros("", Orderby:="Codigo") End If ObjConta.Dispose() DdlCuentaGlobal.DataBind() End Sub End Class