251 lines
11 KiB
VB.net
251 lines
11 KiB
VB.net
Imports System.Data
|
|
Imports Extensiones
|
|
Partial Class AC_RegDevengadoIngresos
|
|
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
|
|
#End Region
|
|
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
CargaCuenta()
|
|
CargaPresupuestos()
|
|
TxtImporte.Attributes.Add("onkeyup", String.Format("LimitaImporte(this);"))
|
|
End If
|
|
End Sub
|
|
Private Sub CargaCuenta()
|
|
DdlCuenta.Items.Clear()
|
|
Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario)
|
|
'If CveMoneda > 0 Then
|
|
' dt = dt.FiltraParametros(String.Format("CveMoneda = {0}", CveMoneda))
|
|
|
|
'End If
|
|
DdlCuenta.DataSource = dt
|
|
DdlCuenta.DataBind()
|
|
DdlCuenta.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
Private Sub CargaPresupuestos()
|
|
Dim AC As New ClsAC
|
|
If AC.GetPresupuestoIngresos(-1, UsuarioActual.Empresa.EjercicioActual, True, UsuarioActual.CveEmpresa) Then
|
|
DtPresupuestos = AC.DtResultados.Copy
|
|
End If
|
|
AC.Dispose()
|
|
CboPresupuesto.DataSource = DtPresupuestos
|
|
CboPresupuesto.DataBind()
|
|
End Sub
|
|
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
|
|
Dim ErrorMovimientos = False
|
|
|
|
If TxtImporte.Text.ToDouble <= 0 Then
|
|
Alert("El total de la compra debe ser mayor a: 0.00", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
If UsuarioActual.Empresa.UsaAC Then
|
|
Dim TotalRecaudar = Math.Round(TxtImporte.Text.ToDouble, 2)
|
|
|
|
If Not RegistraDevengado() Then
|
|
If ChkDevengar.Checked Then
|
|
If RegistraRecaudado() Then
|
|
ErrorMovimientos = True
|
|
End If
|
|
End If
|
|
Else
|
|
ErrorMovimientos = True
|
|
End If
|
|
|
|
If Not ErrorMovimientos Then
|
|
Alert("Movimiento registrado con exito", TipoMensaje.MsgInformacion)
|
|
Limpiar()
|
|
Else
|
|
Alert("Ocurrio un error al registrar el movimiento", TipoMensaje.MsgError)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub Limpiar()
|
|
CboPresupuesto.SelectedValue = -1
|
|
TxtImporte.Text = ""
|
|
TxtFecha.Text = "__/__/____"
|
|
ChkDevengar.Checked = False
|
|
End Sub
|
|
Private Function RegistraDevengado() As Boolean
|
|
Dim ObjContaAC As ClsContPAQi = Nothing
|
|
ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa)
|
|
ObjContaAC.IniciaTransacSQL()
|
|
Dim TotalDevengar = Math.Round(TxtImporte.Text.ToDouble, 2)
|
|
Dim ErrorAC As Boolean = False
|
|
'Dim Total As Double = GvAC.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCTextBox("TxtImporte").Text.ToDouble)
|
|
Dim IDPoliza As Integer = ObjContaAC.AddPoliza(4, "Devengado", TotalDevengar * 2, TotalDevengar * 2, UsuarioActual.CveUsuario, TxtFecha.Text.ToDate)
|
|
|
|
If IDPoliza > 0 Then
|
|
Dim dr As DataRow = DtPresupuestos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", CboPresupuesto.SelectedValue))
|
|
|
|
If dr IsNot Nothing Then
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, False, TotalDevengar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaPorEjecutar").ToString.ToEntero, True, TotalDevengar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
|
|
'AFECTAR MATRIZ INGRESOS
|
|
Dim RegistroMatriz As DataRow = GlobalDTAC_MatrizIngresos.FiltroPrimero(String.Format("CodigoRubroIngreso = {0} ", dr("CodigoRubroIngreso").ToString))
|
|
If RegistroMatriz IsNot Nothing AndAlso RegistroMatriz("CuentaCargo").ToString.ToEntero > 0 Then
|
|
Dim DtCuentas As DataTable = Nothing
|
|
If ObjContaAC.GetCuentas(-1, "-1", -1) Then
|
|
DtCuentas = ObjContaAC.DtResultados
|
|
End If
|
|
Dim CuentaCargo As Integer = DtCuentas.FiltraParametros(String.Format("Codigo = '{0}'", RegistroMatriz("CuentaCargo").ToString)).Rows(0)("Id").ToString.ToEntero
|
|
Dim CuentaAbono As Integer = DtCuentas.FiltraParametros(String.Format("Codigo = '{0}'", RegistroMatriz("CuentaAbono").ToString)).Rows(0)("Id").ToString.ToEntero
|
|
If ObjContaAC.AddMovimiento(IDPoliza, CuentaCargo, False, TotalDevengar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
'actualizo el idcuenta del presupuesto
|
|
If Not ObjContaAC.AddMovimiento(IDPoliza, CuentaAbono, True, TotalDevengar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
'TERMINA AFECTAR MATRIZ INGRESOS
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
If Not ErrorAC Then
|
|
ObjContaAC.Commit()
|
|
Else
|
|
Alert("Ocurrio un error al devengar", TipoMensaje.MsgError)
|
|
ObjContaAC.RollBack()
|
|
End If
|
|
ObjContaAC.Dispose()
|
|
|
|
Return ErrorAC
|
|
End Function
|
|
|
|
Private Function RegistraRecaudado() As Boolean
|
|
Dim TotalRecaudar = Math.Round(TxtImporte.Text.ToDouble, 2)
|
|
Dim ErrorAC As Boolean = False
|
|
|
|
'registra el movimiento en bancos
|
|
Dim ObjContaAC As ClsContPAQi = Nothing
|
|
ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa)
|
|
Dim ObjIE As New ClsBancos
|
|
ObjContaAC.IniciaTransacSQL()
|
|
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
|
|
|
|
|
|
Dim IDPoliza As Integer = ObjContaAC.AddPoliza(4, "Recaudado", TotalRecaudar * 2, TotalRecaudar * 2, UsuarioActual.CveUsuario, TxtFecha.Text.ToDate)
|
|
Dim CvePrePoliza = -1
|
|
Dim NumPoliza = ObjContaAC.Folio.ToString
|
|
Dim CveIE = -1
|
|
|
|
If IDPoliza > 0 Then
|
|
Dim Folio As String = ObjIE.GetNextFolio(DdlCuenta.SelectedValue.ToEntero, 2).ToString
|
|
CvePrePoliza = ObjMov.AddPrePolizas("Vta", 11, TxtImporte.Text.Trim.ToDouble, TxtImporte.Text.Trim.ToDouble, 1, TxtFecha.Text.ToDate, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
|
|
If CvePrePoliza > 0 Then
|
|
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, 2, TxtFecha.Text.Trim.ToDate, Folio, UsuarioActual.Empresa.Empresa, TxtImporte.Text.Trim.ToDouble, 1, 1, "", "", False, True, IDPoliza, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
Dim IdCuentaContable As Integer = DdlCuenta.SelectedValue.ToEntero
|
|
|
|
If CveIE > 0 Then
|
|
Dim dr As DataRow = DtPresupuestos.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", CboPresupuesto.SelectedValue))
|
|
|
|
If dr IsNot Nothing Then
|
|
'registro movimiento a la cuenta 814
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaRecaudado").ToString.ToEntero, False, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
'registro movimeinto a la cuenta 815
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
'registro movimiento a donde se donde
|
|
If Not ObjContaAC.AddMovimiento(IDPoliza, IdCuentaContable, False, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
'descuento a la cuenta bancaria
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Now, "") Then
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
End If
|
|
|
|
'Detalles de PrePoliza
|
|
If Not ErrorAC Then
|
|
If ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtImporte.Text.ToDouble, "", 30, "", Now, 0, -1, CveIE) Then
|
|
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtImporte.Text.ToDouble, "", 4, "", Now, 0, -1, CveIE) Then
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
End If
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
'Actualiza la CvePrePoliza
|
|
If Not ErrorAC Then
|
|
If Not ObjIE.UpdateIEPrePoliza(TxtFecha.Text.ToDate, NumPoliza, IDPoliza, CvePrePoliza, CveIE, -1) Then
|
|
ErrorAC = True
|
|
End If
|
|
End If
|
|
|
|
If Not ErrorAC Then
|
|
Alert("El movimiento se registró correctamente.", TipoMensaje.MsgInformacion)
|
|
ObjIE.Commit()
|
|
ObjContaAC.Commit()
|
|
Else
|
|
Alert("Ocurrió un error al registrar el movimiento.", TipoMensaje.MsgError)
|
|
ObjContaAC.RollBack()
|
|
ObjIE.RollBack()
|
|
End If
|
|
ObjContaAC.Dispose()
|
|
ObjIE.Dispose()
|
|
|
|
Return ErrorAC
|
|
End Function
|
|
|
|
|
|
Protected Sub ChkDevengar_CheckedChanged(sender As Object, e As EventArgs) Handles ChkDevengar.CheckedChanged
|
|
TrCuenta.Visible = ChkDevengar.Checked
|
|
End Sub
|
|
|
|
Protected Sub CboPresupuesto_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
|
|
Dim importe As Double
|
|
If ObjConta.GetACSaldosIngresos(UsuarioActual.Empresa.EjercicioActual, 2) Then
|
|
importe = ObjConta.DtResultados.FiltroPrimero(String.Format("CvePresupuestoIngreso = {0}", CboPresupuesto.SelectedValue.ToString))("PorDevengar").ToString.ToDouble
|
|
End If
|
|
RegistraScript(String.Format("AsignarImporte({0});", importe))
|
|
TxtImporte.Text = "0"
|
|
End Sub
|
|
End Class
|