683 lines
32 KiB
VB.net
683 lines
32 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
Imports System.Activities.Statements
|
|
|
|
Partial Class AC_RegPEAmpRed
|
|
Inherits ClsPaginas
|
|
|
|
#Region "PROPIEDADES"
|
|
Private Property DtPresupuestos As DataTable
|
|
Get
|
|
DtPresupuestos = DirectCast(ViewState("DtPresupuestos"), DataTable)
|
|
End Get
|
|
|
|
Set(ByVal value As DataTable)
|
|
ViewState("DtPresupuestos") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtDetalle As DataTable
|
|
Get
|
|
DtDetalle = DirectCast(ViewState("DtDetalle"), DataTable)
|
|
End Get
|
|
|
|
Set(ByVal value As DataTable)
|
|
ViewState("DtDetalle") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property StrCuentaSaldo As String
|
|
Get
|
|
StrCuentaSaldo = ViewState("StrCuentaSaldo").ToString
|
|
End Get
|
|
|
|
Set(ByVal value As String)
|
|
ViewState("StrCuentaSaldo") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
#End Region
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
StrCuentaSaldo = "IdCuentaPorEjercer"
|
|
CargaEjercicios()
|
|
GvD.Columns(7).Visible = False
|
|
CreaDTDetalles()
|
|
CargaPresupuestos()
|
|
CargaCombosPE()
|
|
TxtFecha.Text = NowADS().ToShortDateString
|
|
End If
|
|
End Sub
|
|
Private Sub CargaPresupuestos()
|
|
Dim AC As New ClsAC
|
|
If AC.GetPresupuestoEgresos(-1, True, DdlEjercicio.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, True) Then
|
|
DtPresupuestos = AC.DtResultados.Copy
|
|
Else
|
|
Alert("Ocurrio un error al cargar los Presupuestos. Por favor vuelva a cargar la pagina", TipoMensaje.MsgError)
|
|
End If
|
|
AC.Dispose()
|
|
LtEjercicio.Text = DdlEjercicio.SelectedValue
|
|
UPTotales.Update()
|
|
UPComandos.Update()
|
|
UpEncabezado.Update()
|
|
LlenaDtDetalles()
|
|
End Sub
|
|
Private Sub CargaEjercicios()
|
|
Dim ClsConta As New ClsContPAQi(UsuarioActual.Empresa)
|
|
If ClsConta.GetEjercicios() Then
|
|
DdlEjercicio.DataSource = ClsConta.DtResultados
|
|
Else
|
|
DdlEjercicio.DataSource = Nothing
|
|
End If
|
|
ClsConta.Dispose()
|
|
DdlEjercicio.DataBind()
|
|
|
|
DdlEjercicio.SelectedValueExist(UsuarioActual.Empresa.EjercicioActual.ToString)
|
|
|
|
|
|
End Sub
|
|
Protected Sub DdlEjercicio_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
CargaPresupuestos()
|
|
CargaProgramaOperativo()
|
|
End Sub
|
|
|
|
Private Sub CreaDTDetalles()
|
|
DtDetalle = New DataTable
|
|
DtDetalle.Columns.Add("Meta", GetType(String))
|
|
DtDetalle.Columns.Add("UnidadAdministrativa", GetType(String))
|
|
DtDetalle.Columns.Add("FuenteFinanciamiento", GetType(String))
|
|
DtDetalle.Columns.Add("ClasificadorOG", GetType(String))
|
|
DtDetalle.Columns.Add("TipoGasto", GetType(String))
|
|
DtDetalle.Columns.Add("Saldo", GetType(Double))
|
|
|
|
DtDetalle.Columns.Add("IdCuentaPorEjercer", GetType(Integer))
|
|
DtDetalle.Columns.Add("IdCuentaModificaciones", GetType(Integer))
|
|
DtDetalle.Columns.Add("IdCuentaComprometido", GetType(Integer))
|
|
|
|
End Sub
|
|
Private Sub LlenaDtDetalles()
|
|
Dim ContPaq As New ClsContPAQi(UsuarioActual.Empresa)
|
|
DtDetalle.Rows.Clear()
|
|
Dim totalsaldo As Double
|
|
|
|
Select Case DdlMomentos.SelectedValue
|
|
Case "1" : StrCuentaSaldo = "IdCuentaComprometido"
|
|
Case Else : StrCuentaSaldo = "IdCuentaPorEjercer"
|
|
End Select
|
|
|
|
For Each drp As DataRow In DtPresupuestos.Rows
|
|
Dim drt As DataRow = DtDetalle.NewRow
|
|
drt("Meta") = drp("ProgramaOperativo")
|
|
drt("UnidadAdministrativa") = drp("UnidadAdministrativa")
|
|
drt("FuenteFinanciamiento") = drp("FuenteFinanciamiento")
|
|
drt("ClasificadorOG") = drp("ClasificadorOGRep")
|
|
drt("TipoGasto") = drp("TipoGasto")
|
|
drt("Saldo") = ContPaq.GetSaldoCuenta(drp(StrCuentaSaldo).ToString.ToEntero, 0, DdlEjercicio.SelectedValue.ToEntero)
|
|
|
|
drt("IdCuentaPorEjercer") = drp("IdCuentaPorEjercer")
|
|
drt("IdCuentaModificaciones") = drp("IdCuentaModificaciones")
|
|
drt("IdCuentaComprometido") = drp("IdCuentaComprometido")
|
|
totalsaldo += drt("saldo").ToString.ToDouble
|
|
|
|
DtDetalle.Rows.Add(drt)
|
|
Next
|
|
|
|
LbTotalSaldo.Text = totalsaldo.ToString.FormatoNumero
|
|
ContPaq.Dispose()
|
|
CargaDatosDetalles()
|
|
End Sub
|
|
Protected Sub CargaDatosDetalles()
|
|
GvD.DataSource = DtDetalle
|
|
GvD.DataBind()
|
|
UPPDetalle.Update()
|
|
End Sub
|
|
|
|
Protected Sub BtnGuardar_click(sender As Object, e As EventArgs)
|
|
Dim Total As Decimal = 0
|
|
Dim Accion As Integer = DdlAccion.SelectedValue.ToString.ToEntero
|
|
Dim IDPoliza As Integer
|
|
Dim Conta As New ClsContPAQi(UsuarioActual.Empresa)
|
|
Dim TieneError As Boolean = False
|
|
Dim NoHaceNada As Boolean = False
|
|
Dim TransferenciaError As Boolean = False
|
|
'Dim Concepto As String
|
|
Dim ampliacion As Decimal
|
|
Dim reduccion As Decimal
|
|
Conta.IniciaTransacSQL()
|
|
|
|
If Accion = 0 Then
|
|
For Each gvr As GridViewRow In GvD.Rows
|
|
If Accion = -1 Then Total += gvr.FCTextBox("TxtReduccion").Text.ToDecimal Else Total += gvr.FCTextBox("TxtAmpliacion").Text.ToDecimal
|
|
ampliacion += gvr.FCTextBox("TxtAmpliacion").Text.ToDecimal
|
|
reduccion += gvr.FCTextBox("TxtReduccion").Text.ToDecimal
|
|
Next
|
|
If Math.Abs(ampliacion - reduccion) > 0.001 Then Total = -1
|
|
Else
|
|
For Each gvr As GridViewRow In GvD.Rows
|
|
If Accion = -1 Then Total += gvr.FCTextBox("TxtReduccion").Text.ToDecimal Else Total += gvr.FCTextBox("TxtAmpliacion").Text.ToDecimal
|
|
Next
|
|
End If
|
|
|
|
If Total > 0 Then
|
|
'Select Case Accion
|
|
' Case 1
|
|
' Concepto = "Modificado - Ampliación"
|
|
' Case -1
|
|
' Concepto = "Modificado - Reduccción" : Total = 0
|
|
' Case Else
|
|
' Concepto = "Modificado - Transferencia"
|
|
'End Select
|
|
Total = If(Accion = -1, 0, Total)
|
|
Dim Fecha As Date = TxtFecha.Text.ToDate
|
|
IDPoliza = Conta.AddPoliza(4, TxtConcepto.Text, Total, Total, UsuarioActual.CveUsuario, Fecha)
|
|
|
|
Dim Importe As Double
|
|
If IDPoliza > 0 Then
|
|
For Each gvr As GridViewRow In GvD.Rows
|
|
|
|
If DdlAccion.SelectedValue = "0" Then
|
|
If gvr.FCTextBox("TxtReduccion").Text.ToDouble > 0 Then
|
|
Importe = gvr.FCTextBox("TxtReduccion").Text.ToDecimal
|
|
Accion = -1
|
|
Else
|
|
Importe = gvr.FCTextBox("TxtAmpliacion").Text.ToDecimal
|
|
Accion = 1
|
|
End If
|
|
Else
|
|
If Accion = -1 Then Importe = gvr.FCTextBox("TxtReduccion").Text.ToDecimal() Else Importe = gvr.FCTextBox("TxtAmpliacion").Text.ToDecimal()
|
|
End If
|
|
|
|
If Importe > 0 Then
|
|
If Conta.AddMovimiento(IDPoliza, gvr.DataKey("IdCuentaPorEjercer").ToString.ToEntero, False, Importe * Accion, "", "", 0, Fecha, "") Then
|
|
'actualizo el idcuenta del presupuesto
|
|
If Not Conta.AddMovimiento(IDPoliza, gvr.DataKey("IdCuentaModificaciones").ToString.ToEntero, True, Importe * Accion, "", "", 0, Fecha, "") Then TieneError = True : Exit For
|
|
|
|
'solo en transferencias
|
|
If DdlMomentos.SelectedValue.ToEntero >= 1 AndAlso Not Conta.AddMovimiento(IDPoliza, gvr.DataKey("IdCuentaComprometido").ToString.ToEntero, False, Importe * Accion, "", "", 0, Fecha, "") Then TieneError = True : Exit For
|
|
If DdlMomentos.SelectedValue.ToEntero >= 1 AndAlso Not Conta.AddMovimiento(IDPoliza, gvr.DataKey("IdCuentaPorEjercer").ToString.ToEntero, True, Importe * Accion, "", "", 0, Fecha, "") Then TieneError = True : Exit For
|
|
|
|
Else
|
|
TieneError = True
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
NoHaceNada = True
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
|
|
Conta.AjustaPoliza(IDPoliza)
|
|
|
|
Conta.Commit()
|
|
LbTotalAmpliacion.Text = "0.00"
|
|
LbTotalReduccion.Text = "0.00"
|
|
LbTotalSaldoFinal.Text = "0.00"
|
|
TxtConcepto.Text = ""
|
|
TxtFecha.Text = "__/__/____"
|
|
GvD.DataBind()
|
|
CargaPresupuestos()
|
|
UPPDetalle.Update()
|
|
UPTotales.Update()
|
|
Alert(String.Format("Registros agregados con exito<br/><br/><a href='/Contabilidad/RegPoliza.aspx?IdPoliza={0}' class='Texto' target='_blank'>Ver Poliza</a>", IDPoliza), TipoMensaje.MsgInformacion)
|
|
Else
|
|
Conta.RollBack()
|
|
If Total = -1 Then
|
|
Alert(String.Format("El total de ampliaciones y reducciones debe ser igual ({0}-{1})", ampliacion, reduccion), TipoMensaje.MsgAdvertencia)
|
|
Else
|
|
Alert(If(NoHaceNada, "No se encontraron registros", "Error poliza"), TipoMensaje.MsgError)
|
|
End If
|
|
End If
|
|
Conta.Dispose()
|
|
|
|
End Sub
|
|
|
|
Protected Sub TipoModificacion(sender As Object, e As EventArgs)
|
|
|
|
End Sub
|
|
|
|
Protected Sub GvD_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvD.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
|
|
Select Case DdlAccion.SelectedValue
|
|
Case "1"
|
|
e.Row.FCTextBox("TxtAmpliacion").Attributes.Add("onkeyup", String.Format("CalculaSaldo({0},this,'{1}','A','');", e.Row.DBCampo("Saldo"), e.Row.FCLabel("LBSF").ClientID))
|
|
Case "-1"
|
|
e.Row.FCTextBox("TxtReduccion").Attributes.Add("onkeyup", String.Format("CalculaSaldo({0},this,'{1}','R','');", e.Row.DBCampo("Saldo"), e.Row.FCLabel("LBSF").ClientID))
|
|
Case "0"
|
|
e.Row.FCTextBox("TxtAmpliacion").Attributes.Add("onkeyup", String.Format("CalculaSaldo({0},this,'{1}','A','{2}');", e.Row.DBCampo("Saldo"), e.Row.FCLabel("LBSF").ClientID, e.Row.FCTextBox("TxtReduccion").ClientID))
|
|
e.Row.FCTextBox("TxtReduccion").Attributes.Add("onkeyup", String.Format("CalculaSaldo({0},this,'{1}','R','{2}');", e.Row.DBCampo("Saldo"), e.Row.FCLabel("LBSF").ClientID, e.Row.FCTextBox("TxtAmpliacion").ClientID))
|
|
End Select
|
|
|
|
If e.Row.DBCampo("Saldo").ToDouble < 0 Then
|
|
e.Row.FCRangeValidator("RVR").MaximumValue = "0"
|
|
e.Row.FCLiteral("Saldo").Text = "0.00"
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
|
|
|
|
#Region "P R E S U P U E S T O - E G R E S O S"
|
|
|
|
#Region "COMBOS PRESUPUESTO EGRESOS"
|
|
Private Sub CargaCombosPE()
|
|
CargaProgramaOperativo()
|
|
CargaFuenteFinanciamiento()
|
|
CargaTipoGasto()
|
|
CargaUnidadAdministrativa()
|
|
CargaClasificacionOG()
|
|
End Sub
|
|
Private Sub CargaProgramaOperativo()
|
|
CboProgramaOperativo.Items.Clear()
|
|
CboProgramaOperativo.DataSource = GlobalDTAC_ProgramaOperativo(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("Ejercicio = {0} AND Bloqueado = 1", DdlEjercicio.SelectedValue.ToEntero))
|
|
CboProgramaOperativo.DataBind()
|
|
CboProgramaOperativo.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
|
|
Private Sub CargaFuenteFinanciamiento()
|
|
CboFuenteFinanciamiento.DataSource = GlobalDTAC_FuentesFinanciamiento(UsuarioActual.CveEmpresa)
|
|
CboFuenteFinanciamiento.DataBind()
|
|
CboFuenteFinanciamiento.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
|
|
Private Sub CargaTipoGasto()
|
|
CboTipoGasto.DataSource = GlobalDTAC_TipoGasto
|
|
CboTipoGasto.DataBind()
|
|
CboTipoGasto.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
|
|
Private Sub CargaUnidadAdministrativa()
|
|
CboUnidadAdministrativa.DataSource = GlobalDTAC_UnidadesAdministrativas(UsuarioActual.CveEmpresa)
|
|
CboUnidadAdministrativa.DataBind()
|
|
CboUnidadAdministrativa.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
|
|
Private Sub CargaClasificacionOG()
|
|
Dim Filtro As New StringBuilder
|
|
Filtro.AppendFormat("Afectable = {0}", "True")
|
|
CboClasificacionOG.DataSource = GlobalDTACClasificadorObjetoGasto(UsuarioActual.CveEmpresa).FiltraParametros(Filtro.ToString, "CodigoClasificacion") 'GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(Filtro.ToString, "CodigoClasificacion")
|
|
CboClasificacionOG.DataBind()
|
|
CboClasificacionOG.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
Protected Sub BtnAgregarPE_Click(sender As Object, e As EventArgs)
|
|
|
|
GenerarCuentasPE()
|
|
|
|
'Dim objAC As New ClsAC()
|
|
|
|
'Dim CveProgramaOperativo As Integer = CboProgramaOperativo.SelectedValue.ToString.ToEntero
|
|
'Dim CveFuenteFinanciamiento As Integer = CboFuenteFinanciamiento.SelectedValue.ToString.ToEntero
|
|
'Dim CveTipoGasto As Integer = CboTipoGasto.SelectedValue.ToString.ToEntero
|
|
'Dim CveUnidadAdministrativa As Integer = CboUnidadAdministrativa.SelectedValue.ToString.ToEntero
|
|
'Dim CveClasificacionOG As Integer = CboClasificacionOG.SelectedValue.ToString.ToEntero
|
|
'Dim TieneError = False
|
|
'Dim DrPresupuesto As DataRow = Nothing
|
|
|
|
'Dim CvePresupuestoEgreso = objAC.AddPresupuestoEgresos(UsuarioActual.Empresa.EjercicioActual, CveProgramaOperativo, CveFuenteFinanciamiento, CveTipoGasto, CveUnidadAdministrativa, CveClasificacionOG, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1)
|
|
|
|
'If objAC.GetPresupuestoEgresos(CvePresupuestoEgreso, True, UsuarioActual.Empresa.EjercicioActual, UsuarioActual.CveEmpresa) Then
|
|
' If Not objAC.DtResultados.Rows.Count <> 1 Then
|
|
' DrPresupuesto = objAC.DtResultados.Rows(0)
|
|
' Else
|
|
' TieneError = True
|
|
' End If
|
|
'Else
|
|
' TieneError = True
|
|
'End If
|
|
|
|
'objAC.Dispose()
|
|
|
|
'If CvePresupuestoEgreso > 0 AndAlso Not TieneError AndAlso DrPresupuesto IsNot Nothing Then
|
|
' If GenerarCuentasPE(DrPresupuesto) Then
|
|
|
|
' Else
|
|
' Alert("Ocurrio un error al agregar el Presupuesto de Egreso, Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
|
' End If
|
|
'Else
|
|
' Alert("Ocurrio un error al agregar el Presupuesto de Egreso, Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
|
'End If
|
|
|
|
End Sub
|
|
|
|
Private Function GenerarCuentasPE() As Boolean
|
|
Dim Conta As New ClsContPAQi(UsuarioActual.Empresa)
|
|
Conta.IniciaTransacSQL()
|
|
Dim ObjAC As New ClsAC
|
|
ObjAC.IniciaTransacSQL()
|
|
|
|
|
|
Dim CveProgramaOperativo As Integer = CboProgramaOperativo.SelectedValue.ToString.ToEntero
|
|
Dim CveFuenteFinanciamiento As Integer = CboFuenteFinanciamiento.SelectedValue.ToString.ToEntero
|
|
Dim CveTipoGasto As Integer = CboTipoGasto.SelectedValue.ToString.ToEntero
|
|
Dim CveUnidadAdministrativa As Integer = CboUnidadAdministrativa.SelectedValue.ToString.ToEntero
|
|
Dim CveClasificacionOG As Integer = CboClasificacionOG.SelectedValue.ToString.ToEntero
|
|
Dim TieneError As Boolean = False
|
|
Dim DrPresupuesto As DataRow = Nothing
|
|
|
|
Dim CvePresupuestoEgreso = ObjAC.AddPresupuestoEgresos(DdlEjercicio.SelectedValue.ToEntero, CveProgramaOperativo, CveFuenteFinanciamiento, CveTipoGasto, CveUnidadAdministrativa, CveClasificacionOG, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1)
|
|
|
|
If CvePresupuestoEgreso > 0 Then
|
|
If ObjAC.GetPresupuestoEgresos(CvePresupuestoEgreso, True, DdlEjercicio.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
If Not ObjAC.DtResultados.Rows.Count <> 1 Then
|
|
DrPresupuesto = ObjAC.DtResultados.Rows(0)
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
|
|
'registro las cuentas prespuestales por cada movimiento, si existe la ignoro
|
|
Dim dtCuentas As DataTable = Nothing
|
|
'Dim IDPoliza As Integer
|
|
Dim IdCuentaAprobado, IdCuentaPorEjercer, IdCuentaModificaciones, IdCuentaComprometido, IdCuentaDevengado, IdCuentaEjercido, IdCuentaPagado, IdCuentaMatriz, IdCuentaMatrizAbono As Integer
|
|
Dim Codigo As String
|
|
|
|
Dim IdCuentaAprobadoPadre, IdCuentaPorEjercerPadre, IdCuentaModificacionesPadre, IdCuentaComprometidoPadre, IdCuentaDevengadoPadre, IdCuentaEjercidoPadre, IdCuentaPagadoPadre, IdCuentaMatrizPadre As Integer
|
|
|
|
'hay que registrar una poliza de cargo en 821, aprobado contra Ley de egresos, luego registrar o de por ejercer
|
|
|
|
If Conta.GetCuentas(-1, "-1", -1) Then
|
|
dtCuentas = Conta.DtResultados
|
|
End If
|
|
|
|
Dim drPadre As DataRow
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'PRESUPUESTO DE EGRESOS APROBADO'")
|
|
IdCuentaAprobadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'PRESUPUESTO DE EGRESOS POR EJERCER'")
|
|
IdCuentaPorEjercerPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'MODIFICACIONES AL PRESUPUESTO DE EGRESOS APROBADO'")
|
|
IdCuentaModificacionesPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'PRESUPUESTO DE EGRESOS COMPROMETIDO'")
|
|
IdCuentaComprometidoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'PRESUPUESTO DE EGRESOS DEVENGADO'")
|
|
IdCuentaDevengadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'PRESUPUESTO DE EGRESOS EJERCIDO'")
|
|
IdCuentaEjercidoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
drPadre = dtCuentas.FiltroPrimero("Nombre = 'PRESUPUESTO DE EGRESOS PAGADO'")
|
|
IdCuentaPagadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
|
|
|
Dim Total As Double = 0
|
|
Dim Fecha As Date = String.Format("01/01/{0}", UsuarioActual.Empresa.EjercicioActual).ToDate
|
|
|
|
|
|
'EMPIEZA REGISTRO DE CUENTAS CONTABLES
|
|
Codigo = String.Format("{0}{1}{2}{3}", DrPresupuesto("CodigoUnidadAdministrativa").ToString.PadLeft(4, "0"c), DrPresupuesto("CodigoFuenteFinanciamiento").ToString.PadLeft(2, "0"c), DrPresupuesto("CveTipoGasto").ToString.PadLeft(2, "0"c), DrPresupuesto("CodigoCOG")).PadLeft(5, "0"c)
|
|
|
|
IdCuentaAprobado = FNCIDCuenta(dtCuentas, String.Format("00821{0}", Codigo))
|
|
If IdCuentaAprobado = 0 Then
|
|
IdCuentaAprobado = Conta.AddCuenta(String.Format("00821{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaAprobadoPadre)
|
|
If IdCuentaAprobado > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaAprobado, String.Format("00821{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
IdCuentaPorEjercer = FNCIDCuenta(dtCuentas, String.Format("00822{0}", Codigo))
|
|
If IdCuentaPorEjercer = 0 Then
|
|
IdCuentaPorEjercer = Conta.AddCuenta(String.Format("00822{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaPorEjercerPadre)
|
|
If IdCuentaPorEjercer > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaPorEjercer, String.Format("00822{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
IdCuentaModificaciones = FNCIDCuenta(dtCuentas, String.Format("00823{0}", Codigo))
|
|
If IdCuentaModificaciones = 0 Then
|
|
IdCuentaModificaciones = Conta.AddCuenta(String.Format("00823{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaModificacionesPadre)
|
|
If IdCuentaModificaciones > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaModificaciones, String.Format("00823{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
IdCuentaComprometido = FNCIDCuenta(dtCuentas, String.Format("00824{0}", Codigo))
|
|
If IdCuentaComprometido = 0 Then
|
|
IdCuentaComprometido = Conta.AddCuenta(String.Format("00824{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaComprometidoPadre)
|
|
If IdCuentaComprometido > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaComprometido, String.Format("00824{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
IdCuentaDevengado = FNCIDCuenta(dtCuentas, String.Format("00825{0}", Codigo))
|
|
If IdCuentaDevengado = 0 Then
|
|
IdCuentaDevengado = Conta.AddCuenta(String.Format("00825{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaDevengadoPadre)
|
|
If IdCuentaDevengado > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaDevengado, String.Format("00825{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
IdCuentaEjercido = FNCIDCuenta(dtCuentas, String.Format("00826{0}", Codigo))
|
|
If IdCuentaEjercido = 0 Then
|
|
IdCuentaEjercido = Conta.AddCuenta(String.Format("00826{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaEjercidoPadre)
|
|
If IdCuentaEjercido > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaEjercido, String.Format("00826{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
IdCuentaPagado = FNCIDCuenta(dtCuentas, String.Format("00827{0}", Codigo))
|
|
If IdCuentaPagado = 0 Then
|
|
IdCuentaPagado = Conta.AddCuenta(String.Format("00827{0}", Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "L", 2, 0, 1, 0, "", 1, IdCuentaPagadoPadre)
|
|
If IdCuentaAprobado > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaPagado, String.Format("00827{0}", Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
|
|
If Not TieneError Then
|
|
'falta generar y gaurdar la cuenta contable y vincularla
|
|
Dim filtro As New StringBuilder
|
|
filtro.AppendFormat("Partida = {0} and TipoGasto = {1}", DrPresupuesto("CodigoCOG").ToString.Substring(0, 4), DrPresupuesto("CveTipoGasto").ToString)
|
|
|
|
Dim RegistroMatriz As DataRow = GlobalDTAC_MatrizEgresos.FiltroPrimero(filtro.ToString)
|
|
filtro.Clear()
|
|
If RegistroMatriz Is Nothing Then
|
|
Dim CCOG As String = DrPresupuesto("CodigoCOG").ToString.Substring(0, 3)
|
|
If CCOG = "161" Then CCOG = "159" ' ajuste manual, porque no hay conversion de estas cuentas
|
|
RegistroMatriz = GlobalDTAC_MatrizEgresos.FiltroPrimero(String.Format("Partida = {0}0 and TipoGasto = {1}", CCOG, DrPresupuesto("CveTipoGasto").ToString))
|
|
End If
|
|
If RegistroMatriz IsNot Nothing AndAlso FnCuentaCargo(RegistroMatriz("CuentaCargo").ToString).ToEntero > 0 Then
|
|
IdCuentaMatrizPadre = FnCuentaCargo(RegistroMatriz("CuentaCargo").ToString).ToEntero
|
|
|
|
Dim CuentaCargo As Integer = dtCuentas.FiltroPrimero(String.Format("Codigo = '{0}'", String.Format("0{0}0000000000000", IdCuentaMatrizPadre)))("Id").ToString.ToEntero
|
|
|
|
IdCuentaMatriz = FNCIDCuenta(dtCuentas, String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo))
|
|
If IdCuentaMatriz = 0 Then
|
|
IdCuentaMatriz = Conta.AddCuenta(String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "G", 2, 0, 1, 0, "", 1, CuentaCargo)
|
|
If IdCuentaMatriz > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaMatriz, String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
|
|
IdCuentaMatrizAbono = 0
|
|
'si el COG, es de la 1000, se le ingresa la cuenta abono
|
|
If DrPresupuesto("CodigoCOG").ToString.Substring(0, 1) = "1" Then
|
|
|
|
IdCuentaMatrizPadre = FnCuentaCargo(RegistroMatriz("CuentaAbono").ToString.Substring(0, 4)).ToEntero
|
|
|
|
Dim CuentaAbono As Integer = dtCuentas.FiltroPrimero(String.Format("Codigo = '{0}'", String.Format("0{0}0000000000000", IdCuentaMatrizPadre)))("Id").ToString.ToEntero
|
|
|
|
IdCuentaMatrizAbono = FNCIDCuenta(dtCuentas, String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo))
|
|
If IdCuentaMatrizAbono = 0 Then
|
|
IdCuentaMatrizAbono = Conta.AddCuenta(String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo), DrPresupuesto("Clasificacion").ToString.ToUpper, "G", 2, 0, 1, 0, "", 1, CuentaAbono)
|
|
If IdCuentaMatrizAbono > 0 Then
|
|
FNCAddCuenta(dtCuentas, IdCuentaMatriz, String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo))
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
'Total = DrPresupuesto("Total").ToString.ToDouble
|
|
'If Total > 0 Then
|
|
' If Conta.AddMovimiento(123456, IDPoliza, IdCuentaAprobado, True, Total, "", "", 0, Fecha, "") Then
|
|
' 'actualizo el idcuenta del presupuesto
|
|
' If Not Conta.AddMovimiento(123456, IDPoliza, IdCuentaPorEjercer, False, Total, "", "", 0, Fecha, "") Then
|
|
' TieneError = True
|
|
' End If
|
|
|
|
' Else
|
|
' TieneError = True
|
|
' End If
|
|
'End If
|
|
|
|
If Not ObjAC.UpdateCuentasPresupuestoEgresos(IdCuentaAprobado, IdCuentaPorEjercer, IdCuentaModificaciones, IdCuentaComprometido, IdCuentaDevengado, IdCuentaEjercido, IdCuentaPagado, IdCuentaMatriz, IdCuentaMatrizAbono, DrPresupuesto("CvePresupuestoEgreso").ToString.ToEntero) Then
|
|
TieneError = True
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
|
|
|
|
'If Not TieneError Then
|
|
' If Not ObjAC.UpdateEjercicios(UsuarioActual.Empresa.EjercicioActual, -1, IDPoliza, UsuarioActual.CveEmpresa) Then
|
|
' TieneError = True
|
|
' End If
|
|
'End If
|
|
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
|
|
If Not TieneError Then
|
|
ObjAC.Commit()
|
|
Conta.Commit()
|
|
CargaPresupuestos()
|
|
Alert("El Presupuesto de Egreso se genero Correctamente", TipoMensaje.MsgInformacion)
|
|
RegistraScript("$('#DivAddPE').modal('hide');")
|
|
'RegistraScript("$get('DivAddPE').style.display='none';")
|
|
Else
|
|
Conta.RollBack()
|
|
ObjAC.RollBack()
|
|
Alert("Ocurrio un error al agregar el Presupuesto de Egreso, Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
Conta.Dispose()
|
|
ObjAC.Dispose()
|
|
|
|
Return Not TieneError
|
|
End Function
|
|
|
|
Private Function FNCIDCuenta(dt As DataTable, codigo As String) As Integer
|
|
Dim Retorno As Integer = 0
|
|
Dim dr As DataRow
|
|
dr = dt.FiltroPrimero(String.Format("Codigo ='{0}'", codigo))
|
|
If dr IsNot Nothing Then
|
|
|
|
Retorno = dr("Id").ToString.ToEntero
|
|
End If
|
|
|
|
Return Retorno
|
|
End Function
|
|
Private Function FNCAddCuenta(dt As DataTable, id As Integer, codigo As String) As Integer
|
|
' se crea una coleccion para grabar las claves y las cuentas que se van insertando, por si se comparten, no marque error de que ya esta registrada y esta en la transaccion todavia
|
|
Dim Retorno As Integer = 0
|
|
Dim dr As DataRow = dt.NewRow
|
|
|
|
dr("Codigo") = codigo
|
|
dr("Id") = id
|
|
|
|
dt.Rows.Add(dr)
|
|
dt.AcceptChanges()
|
|
Return Retorno
|
|
End Function
|
|
Private Function FnCuentaCargo(CC As String) As String
|
|
Return CC.Replace("-1", "").Replace("-2", "").Replace("-3", "").Replace("-4", "").Replace("-5", "").Replace("-6", "").Replace("-7", "").Replace("-8", "").Replace("-9", "")
|
|
End Function
|
|
|
|
Private Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
|
|
CargaPresupuestos()
|
|
End Sub
|
|
|
|
Private Sub DdlAccion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAccion.SelectedIndexChanged
|
|
|
|
If DdlAccion.SelectedValue = "0" Then 'TRANSFERENCIA
|
|
GvD.Columns(6).Visible = True 'TxtAmpliacion
|
|
GvD.Columns(7).Visible = True 'TxtReduccion
|
|
LbTotalAmpliacion.Visible = True
|
|
LbTotalReduccion.Visible = True
|
|
LblAgregar.Visible = True
|
|
TrMomentos.Visible = True
|
|
ElseIf DdlAccion.SelectedValue = "-1" Then 'REDUCCION
|
|
GvD.Columns(6).Visible = False 'TxtAmpliacion
|
|
GvD.Columns(7).Visible = True 'TxtReduccion
|
|
LbTotalAmpliacion.Visible = False
|
|
LbTotalReduccion.Visible = True
|
|
LblAgregar.Visible = False
|
|
TrMomentos.Visible = True
|
|
|
|
Else 'AMPLIACION
|
|
GvD.Columns(6).Visible = True 'TxtAmpliacion
|
|
GvD.Columns(7).Visible = False 'TxtReduccion
|
|
LbTotalAmpliacion.Visible = True
|
|
LbTotalReduccion.Visible = False
|
|
LblAgregar.Visible = True
|
|
TrMomentos.Visible = False
|
|
End If
|
|
|
|
CargaPresupuestos()
|
|
|
|
UPFiltros.Update()
|
|
UPPDetalle.Update()
|
|
UPTotales.Update()
|
|
End Sub
|
|
|
|
Private Sub DdlMomentos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlMomentos.SelectedIndexChanged
|
|
CargaPresupuestos()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
End Class
|