Commit inicial Ventas Productivo
This commit is contained in:
337
AC/CatPresupuestoIngresos.aspx.vb
Normal file
337
AC/CatPresupuestoIngresos.aspx.vb
Normal file
@@ -0,0 +1,337 @@
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System.Data
|
||||
Imports Extensiones
|
||||
Imports Microsoft.Reporting.WebForms
|
||||
|
||||
Partial Class AC_CatPresupuestoIngresos
|
||||
Inherits ClsPaginas
|
||||
|
||||
#Region " PROPIEDADES "
|
||||
Private Property DtPresupuestoIngresos As DataTable
|
||||
Get
|
||||
Return CType(ViewState("DtPresupuestoIngresos"), DataTable)
|
||||
End Get
|
||||
Set(value As DataTable)
|
||||
ViewState("DtPresupuestoIngresos") = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property pTotal As String
|
||||
Get
|
||||
Return CType(ViewState("pTotal"), String)
|
||||
End Get
|
||||
Set(value As String)
|
||||
ViewState("pTotal") = 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
|
||||
SetValues()
|
||||
CargaDatos()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
#Region " VALORES INICIALES "
|
||||
Private Sub SetValues()
|
||||
CargaEjercicios()
|
||||
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
|
||||
#End Region
|
||||
|
||||
|
||||
#Region " CARGA DATOS "
|
||||
|
||||
Protected Sub consultar_Click(sender As Object, e As EventArgs)
|
||||
BtnCongelarPrespuesto.Visible = False
|
||||
BtnPresupuesto.Visible = False
|
||||
CargaDatos()
|
||||
End Sub
|
||||
Private Sub CargaDatos()
|
||||
Dim AC As New ClsAC
|
||||
Dim Ejercicio As Integer = DdlEjercicio.SelectedValue.ToString.ToEntero
|
||||
Dim EsProyecto As Boolean = CBool(DdlProyecto.SelectedValue.ToString)
|
||||
Gv.DataBind()
|
||||
|
||||
|
||||
If AC.GetPresupuestoIngresos(-1, Ejercicio, EsProyecto, UsuarioActual.CveEmpresa) Then
|
||||
|
||||
DtPresupuestoIngresos = AC.DtResultados
|
||||
Gv.DataSource = AC.DtResultados
|
||||
Gv.DataBind()
|
||||
|
||||
'debe de haber datos para habilitar los botones
|
||||
If AC.DtResultados.Rows.Count > 0 Then
|
||||
If EsProyecto Then
|
||||
If AC.DtResultados.Rows(0)("Bloqueado").ToString = "0" Then
|
||||
'Ejercicio = UsuarioActual.Empresa.EjercicioActual AndAlso
|
||||
BtnCongelarPrespuesto.Visible = True
|
||||
End If
|
||||
Else
|
||||
'si es anteproyecto
|
||||
If AC.DtResultados.Rows(0)("Bloqueado").ToString = "0" Then
|
||||
'AndAlso Ejercicio >= UsuarioActual.Empresa.EjercicioActual
|
||||
BtnPresupuesto.Visible = True
|
||||
End If
|
||||
' If Ejercicio = UsuarioActual.Empresa.EjercicioActual Then
|
||||
End If
|
||||
Dim Total As Double = Gv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("Total").ToDouble)
|
||||
LbTotales.Text = Total.ToString.FormatoNumero
|
||||
pTotal = Total.ToString.FormatoNumero
|
||||
End If
|
||||
End If
|
||||
|
||||
UpTotales.Update()
|
||||
UPDatos.Update()
|
||||
|
||||
AC.Dispose()
|
||||
End Sub
|
||||
Private Sub CargaGrid(Orden As String)
|
||||
If Orden <> String.Empty Then
|
||||
Dim DV As New DataView(CType(ViewState("DT_AC_PresupuestosIngresos"), DataTable), "", Orden, DataViewRowState.CurrentRows)
|
||||
Gv.DataSource = DV.ToTable()
|
||||
DV.Dispose()
|
||||
Else
|
||||
Gv.DataSource = CType(ViewState("DT_AC_PresupuestosIngresos"), DataTable)
|
||||
End If
|
||||
Gv.DataBind()
|
||||
UPDatos.Update()
|
||||
End Sub
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
#Region " FUNCIONES "
|
||||
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
|
||||
#End Region
|
||||
|
||||
|
||||
Protected Sub BtnCongelarPrespuesto_Click(sender As Object, e As EventArgs)
|
||||
Dim Conta As New ClsContPAQi(UsuarioActual.Empresa)
|
||||
Conta.IniciaTransacSQL()
|
||||
Dim AC As New ClsAC
|
||||
AC.IniciaTransacSQL()
|
||||
'registro las cuentas prespuestales por cada movimiento, si existe la ignoro
|
||||
Dim dtCuentas As DataTable = Nothing
|
||||
Dim IDPoliza As Integer
|
||||
Dim IdCuentaEstimado, IdCuentaPorEjecutar, IdCuentaModificado, IdCuentaDevengado, IdCuentaRecaudado, IdCuentaMatriz As Integer
|
||||
Dim Codigo As String
|
||||
Dim TieneError As Boolean = False
|
||||
Dim IdCuentaEstimadoPadre, IdCuentaPorEjecutarPadre, IdCuentaModificadoPadre, IdCuentaDevengadoPadre, IdCuentaRecaudadoPadre, 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 = 'LEY DE INGRESOS ESTIMADA'")
|
||||
IdCuentaEstimadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
||||
|
||||
drPadre = dtCuentas.FiltroPrimero("Nombre = 'LEY DE INGRESOS POR EJECUTAR'")
|
||||
IdCuentaPorEjecutarPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
||||
|
||||
drPadre = dtCuentas.FiltroPrimero("Nombre = 'MODIFICACIONES A LA LEY DE INGRESOS ESTIMADA'")
|
||||
IdCuentaModificadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
||||
|
||||
drPadre = dtCuentas.FiltroPrimero("Nombre = 'LEY DE INGRESOS DEVENGADA'")
|
||||
IdCuentaDevengadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
||||
|
||||
drPadre = dtCuentas.FiltroPrimero("Nombre = 'LEY DE INGRESOS RECAUDADA'")
|
||||
IdCuentaRecaudadoPadre = If(drPadre IsNot Nothing, drPadre("Id").ToString.ToEntero, 0)
|
||||
|
||||
Dim Total As Double = Gv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("Total").ToDouble)
|
||||
|
||||
IDPoliza = Conta.AddPoliza(4, String.Format("POLIZA INICIAL - PRESUPUESTO DE INGRESOS ESTIMADO {0}", DdlEjercicio.SelectedValue), Total, Total, UsuarioActual.CveUsuario, String.Format("01/01/{0}", DdlEjercicio.SelectedValue).ToDate)
|
||||
If IDPoliza > 0 Then
|
||||
|
||||
For Each gvr As GridViewRow In Gv.Rows
|
||||
|
||||
'Codigo = String.Format("{0}-{1}", gvr.DataKey("CvePresupuestoIngreso"), gvr.DataKey("CodigoRubroIngreso"))
|
||||
Codigo = String.Format("{0}{1}00000", gvr.DataKey("CodigoRubroIngreso").PadLeft(4, "0"c), gvr.DataKey("CveFuenteRecaudacion").PadLeft(4, "0"c)).PadLeft(5, "0"c)
|
||||
'Registro las cuentas afectables
|
||||
IdCuentaEstimado = FNCIDCuenta(dtCuentas, String.Format("00811{0}", Codigo))
|
||||
If IdCuentaEstimado = 0 Then IdCuentaEstimado = Conta.AddCuenta(String.Format("00811{0}", Codigo), gvr.DataKey("FuenteRecaudacion"), "K", 2, 0, 1, 0, "", 1, IdCuentaEstimadoPadre) : FNCAddCuenta(dtCuentas, IdCuentaEstimado, String.Format("00811{0}", Codigo))
|
||||
|
||||
IdCuentaPorEjecutar = FNCIDCuenta(dtCuentas, String.Format("00812{0}", Codigo))
|
||||
If IdCuentaPorEjecutar = 0 Then IdCuentaPorEjecutar = Conta.AddCuenta(String.Format("00812{0}", Codigo), gvr.DataKey("FuenteRecaudacion"), "K", 2, 0, 1, 0, "", 1, IdCuentaPorEjecutarPadre) : FNCAddCuenta(dtCuentas, IdCuentaPorEjecutar, String.Format("00812{0}", Codigo))
|
||||
|
||||
IdCuentaModificado = FNCIDCuenta(dtCuentas, String.Format("00813{0}", Codigo))
|
||||
If IdCuentaModificado = 0 Then IdCuentaModificado = Conta.AddCuenta(String.Format("00813{0}", Codigo), gvr.DataKey("FuenteRecaudacion"), "K", 2, 0, 1, 0, "", 1, IdCuentaModificadoPadre) : FNCAddCuenta(dtCuentas, IdCuentaModificado, String.Format("00813{0}", Codigo))
|
||||
|
||||
IdCuentaDevengado = FNCIDCuenta(dtCuentas, String.Format("00814{0}", Codigo))
|
||||
If IdCuentaDevengado = 0 Then IdCuentaDevengado = Conta.AddCuenta(String.Format("00814{0}", Codigo), gvr.DataKey("FuenteRecaudacion"), "K", 2, 0, 1, 0, "", 1, IdCuentaDevengadoPadre) : FNCAddCuenta(dtCuentas, IdCuentaDevengado, String.Format("00814{0}", Codigo))
|
||||
|
||||
IdCuentaRecaudado = FNCIDCuenta(dtCuentas, String.Format("00815{0}", Codigo))
|
||||
If IdCuentaRecaudado = 0 Then IdCuentaRecaudado = Conta.AddCuenta(String.Format("00815{0}", Codigo), gvr.DataKey("FuenteRecaudacion"), "K", 2, 0, 1, 0, "", 1, IdCuentaRecaudadoPadre) : FNCAddCuenta(dtCuentas, IdCuentaRecaudado, String.Format("00815{0}", Codigo))
|
||||
|
||||
'falta generar y gaurdar la cuenta contable y vincularla
|
||||
Dim filtro As New StringBuilder
|
||||
filtro.AppendFormat("CodigoRubroIngreso = {0} and Caracteristicas = 1", gvr.DataKey("CodigoRubroIngreso"))
|
||||
|
||||
Dim RegistroMatriz As DataRow = GlobalDTAC_MatrizIngresos.FiltroPrimero(filtro.ToString)
|
||||
filtro.Clear()
|
||||
If RegistroMatriz Is Nothing Then
|
||||
RegistroMatriz = GlobalDTAC_MatrizIngresos.FiltroPrimero(String.Format("(CodigoRubroIngreso = {0} and Caracteristicas = 1) OR (CodigoRubroIngreso = {0})", gvr.DataKey("CodigoRubroIngreso")), "Caracteristicas")
|
||||
|
||||
If RegistroMatriz Is Nothing Then
|
||||
TieneError = True
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
|
||||
If RegistroMatriz IsNot Nothing AndAlso RegistroMatriz("CuentaCargo").ToString.ToEntero > 0 Then
|
||||
IdCuentaMatrizPadre = RegistroMatriz("CuentaAbono").ToString.ToEntero
|
||||
|
||||
Dim CuentaAbono 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), gvr.DataKey("FuenteRecaudacion").ToUpper, "H", 2, 0, 1, 0, "", 1, CuentaAbono) : FNCAddCuenta(dtCuentas, IdCuentaMatriz, String.Format("0{0}{1}", IdCuentaMatrizPadre, Codigo))
|
||||
|
||||
End If
|
||||
|
||||
Total = gvr.DataKey("Total").ToDouble
|
||||
If Conta.AddMovimiento(IDPoliza, IdCuentaEstimado, False, Total, "", "", 0, String.Format("01/01/{0}", DdlEjercicio.SelectedValue).ToDate, "") Then
|
||||
'actualizo el idcuenta del presupuesto
|
||||
If Not Conta.AddMovimiento(IDPoliza, IdCuentaPorEjecutar, True, Total, "", "", 0, String.Format("01/01/{0}", DdlEjercicio.SelectedValue).ToDate, "") Then
|
||||
TieneError = True
|
||||
Exit For
|
||||
End If
|
||||
If Not AC.UpdateCuentasPresupuestoIngresos(IdCuentaEstimado, IdCuentaPorEjecutar, IdCuentaModificado, IdCuentaDevengado, IdCuentaRecaudado, IdCuentaMatriz, gvr.DataKey("CvePresupuestoIngreso").ToEntero) Then
|
||||
TieneError = True
|
||||
Exit For
|
||||
|
||||
End If
|
||||
Else
|
||||
TieneError = True
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Else
|
||||
TieneError = True
|
||||
End If
|
||||
|
||||
If Not TieneError Then
|
||||
'actualizo las cuentas de cadapresupuesto
|
||||
AC.Commit()
|
||||
Conta.Commit()
|
||||
Alert("Presupuesto se ha aprobado con exito", TipoMensaje.MsgInformacion)
|
||||
BtnCongelarPrespuesto.Visible = False
|
||||
Else
|
||||
Conta.RollBack()
|
||||
AC.RollBack()
|
||||
Alert("Ocurrió un error al aprobar el Presupuesto. Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
||||
End If
|
||||
|
||||
Conta.Dispose()
|
||||
AC.Dispose()
|
||||
|
||||
CargaDatos()
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnPresupuesto_Click(sender As Object, e As EventArgs)
|
||||
Dim AC As New ClsAC
|
||||
AC.IniciaTransacSQL()
|
||||
Dim TieneError As Boolean = False
|
||||
|
||||
For Each gvr As GridViewRow In Gv.Rows
|
||||
|
||||
Dim Total As Double = gvr.DataKey("Total").ToDouble
|
||||
Dim Enero As Double = gvr.DataKey("Enero").ToDouble
|
||||
Dim Febrero As Double = gvr.DataKey("Febrero").ToDouble
|
||||
Dim Marzo As Double = gvr.DataKey("Marzo").ToDouble
|
||||
Dim Abril As Double = gvr.DataKey("Abril").ToDouble
|
||||
Dim Mayo As Double = gvr.DataKey("Mayo").ToDouble
|
||||
Dim Junio As Double = gvr.DataKey("Junio").ToDouble
|
||||
Dim Julio As Double = gvr.DataKey("Julio").ToDouble
|
||||
Dim Agosto As Double = gvr.DataKey("Agosto").ToDouble
|
||||
Dim Septiembre As Double = gvr.DataKey("Septiembre").ToDouble
|
||||
Dim Octubre As Double = gvr.DataKey("Octubre").ToDouble
|
||||
Dim Noviembre As Double = gvr.DataKey("Noviembre").ToDouble
|
||||
Dim Diciembre As Double = gvr.DataKey("Diciembre").ToDouble
|
||||
|
||||
Dim Ejercicio As Integer = 2015
|
||||
Dim CveFuenteRecaudacion As Integer = gvr.DataKey("CveFuenteRecaudacion").ToEntero
|
||||
Dim CveRubroIngreso As Integer = gvr.DataKey("CveRubroIngreso").ToEntero
|
||||
Dim CvePresupuestoIngresos As Integer = gvr.DataKey("CvePresupuestoIngreso").ToEntero
|
||||
|
||||
If Not AC.ProyectoPresupuestoIngresos(Ejercicio, CveFuenteRecaudacion, CveRubroIngreso, Total, Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CvePresupuestoIngresos) Then
|
||||
TieneError = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If Not TieneError Then
|
||||
AC.Commit()
|
||||
Alert("Movimientos Guardados", TipoMensaje.MsgInformacion)
|
||||
BtnPresupuesto.Visible = False
|
||||
Else
|
||||
AC.RollBack()
|
||||
End If
|
||||
|
||||
AC.Dispose()
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
#Region " EXCEL "
|
||||
Protected Sub LBPdf_Click(sender As Object, e As EventArgs)
|
||||
ImprimirReporte()
|
||||
End Sub
|
||||
Protected Sub LBExcel_Click(sender As Object, e As EventArgs)
|
||||
ImprimirReporte("Excel")
|
||||
End Sub
|
||||
Private Sub ImprimirReporte(Optional Formato As String = "PDF")
|
||||
'parametros a enviar al reporte
|
||||
Dim params As New List(Of ReportParameter)
|
||||
params.Add(New ReportParameter("pEmp", UsuarioActual.Empresa.Empresa))
|
||||
params.Add(New ReportParameter("pImg", New Uri(Server.MapPath(String.Format("~/Empresas/{0}/Logo.png", UsuarioActual.CveEmpresa))).AbsoluteUri))
|
||||
params.Add(New ReportParameter("pEjercicio", DdlEjercicio.SelectedValue.ToString))
|
||||
'params.Add(New ReportParameter("pTotal", pTotal))
|
||||
ImprimirPDF("AC/Reportes/RepCatPresupuestoIngresos.rdlc", DtPresupuestoIngresos, params, "PresupuestoIngresos", Formato)
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user