227 lines
11 KiB
VB.net
227 lines
11 KiB
VB.net
Imports System.Data
|
|
Imports Extensiones
|
|
Partial Class AC_RegRecaudado
|
|
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
|
|
'carga clientes
|
|
|
|
DdlCliente.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa)
|
|
DdlCliente.DataBind()
|
|
|
|
CargaCuenta()
|
|
CargaPresupuestos()
|
|
End If
|
|
End Sub
|
|
Private Sub CargaCuenta()
|
|
DdlCuenta.Items.Clear()
|
|
Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
|
|
'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
|
|
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 ObjContaAC As ClsContPAQi = Nothing
|
|
ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa)
|
|
ObjContaAC.IniciaTransacSQL()
|
|
Dim TotalRecaudar = Math.Round(TxtImporte.Text.ToDouble, 2)
|
|
Dim ErrorAC As Boolean = False
|
|
Dim Fecha As Date = TxtFecha.Text.ToDate
|
|
Dim ObjIE As New ClsBancos
|
|
Dim ObjCliente As New ClsClientes(ObjIE.IniciaTransacSQL())
|
|
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
|
|
Dim Titulo As String = TxtConcepto.Text
|
|
|
|
'If ChkRecaudar.Checked Then
|
|
' Titulo = "Devengado-Recaudado"
|
|
'End If
|
|
|
|
|
|
'Dim Total As Double = GvAC.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCTextBox("TxtImporte").Text.ToDouble)
|
|
Dim IDPoliza As Integer = ObjContaAC.AddPoliza(4, Titulo, TotalRecaudar, TotalRecaudar, UsuarioActual.CveUsuario, Fecha)
|
|
Dim NumPoliza = ObjContaAC.Folio.ToString
|
|
Dim CvePrePoliza = -1
|
|
Dim CveIE = -1
|
|
|
|
If IDPoliza > 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("IdCuentaPorEjecutar").ToString.ToEntero, True, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
'registro movimeinto a la cuenta 815
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, False, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
|
|
''CUENTA CLIENTE
|
|
|
|
Dim CtaCliente, CveCliente As Integer
|
|
CveCliente = DdlCliente.SelectedValue.ToEntero
|
|
|
|
If ObjCliente.GetClientes(CveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, -1) Then
|
|
CtaCliente = ObjCliente.IdCtaContClientes
|
|
End If
|
|
|
|
|
|
Dim CuentaAbono As Integer
|
|
If CtaCliente <= 0 Then
|
|
|
|
If ObjContaAC.GetCuentas(-1, "011220000000000000", -1) Then
|
|
Dim drCuenta As DataRow = ObjContaAC.DtResultados.FiltroPrimero("")
|
|
If drCuenta IsNot Nothing Then
|
|
|
|
CuentaAbono = drCuenta("Id").ToString.ToEntero
|
|
Dim FolioProveedor = ObjContaAC.GetFolioProveedores("011220000000000000").ToString
|
|
CtaCliente = ObjContaAC.AddCuenta(String.Format("01122{0}000000000", FolioProveedor.PadLeft(4, "0"c)), DdlCliente.SelectedItem.Text, "A", 2, 0, 1, 0, "", 1, CuentaAbono)
|
|
ObjCliente.UpdateClienteIdCuenta(CveCliente, CtaCliente)
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
'CARGO la deuda del cliente
|
|
If ObjContaAC.AddMovimiento(IDPoliza, CtaCliente, False, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
'abono,
|
|
If Not ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaMatriz").ToString.ToEntero, True, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
If ChkRecaudar.Checked AndAlso Not ErrorAC 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, TxtConcepto.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
|
|
If CvePrePoliza > 0 Then
|
|
|
|
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, 2, Fecha, Folio, UsuarioActual.Empresa.Empresa, TxtImporte.Text.Trim.ToDouble, 1, 1, "", "", False, True, IDPoliza, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
|
|
Dim IdCtaConCuentaBancaria As Integer = 0
|
|
|
|
Dim drcb As DataRow = GlobalDTBancosCuentas(-1, DdlCuenta.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("")
|
|
If drcb IsNot Nothing Then
|
|
IdCtaConCuentaBancaria = drcb("IdCtaContable").ToString.ToEntero
|
|
End If
|
|
|
|
If CveIE > 0 AndAlso IdCtaConCuentaBancaria > 0 Then
|
|
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
'registro movimeinto a la cuenta 815
|
|
If ObjContaAC.AddMovimiento(IDPoliza, dr("IdCuentaRecaudado").ToString.ToEntero, False, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
'registro movimiento a donde se donde
|
|
If ObjContaAC.AddMovimiento(IDPoliza, CtaCliente, True, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
'descuento a la cuenta bancaria
|
|
If Not ObjContaAC.AddMovimiento(IDPoliza, IdCtaConCuentaBancaria, False, TotalRecaudar, "", CboPresupuesto.SelectedItem.Text, 0, Fecha, "") Then
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
'Detalles de PrePoliza
|
|
If Not ErrorAC Then
|
|
If ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, TxtImporte.Text.ToDecimal, TxtImporte.Text.ToDecimal, 30, "", "", 0, CveIE, CveCliente:=CveCliente) Then
|
|
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, TxtImporte.Text.ToDecimal, TxtImporte.Text.ToDecimal, 4, "", "", 0, CveIE, CveCliente:=CveCliente) Then
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
End If
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
|
|
|
|
End If
|
|
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
Else
|
|
ErrorAC = True
|
|
End If
|
|
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
|
|
ObjContaAC.AjustaPoliza(IDPoliza)
|
|
ObjContaAC.Commit()
|
|
ObjIE.Commit()
|
|
Alert("El Movimiento se realizó correctamente", TipoMensaje.MsgInformacion, "document.location.href=""/AC/RegRecaudado.aspx"";")
|
|
Else
|
|
Alert("Ocurrió un error al devengar", TipoMensaje.MsgError)
|
|
ObjContaAC.RollBack()
|
|
ObjIE.RollBack()
|
|
End If
|
|
ObjContaAC.Dispose()
|
|
ObjIE.Dispose()
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub ChkRecaudar_CheckedChanged(sender As Object, e As EventArgs) Handles ChkRecaudar.CheckedChanged
|
|
TrCuentaBancaria.Visible = ChkRecaudar.Checked
|
|
End Sub
|
|
End Class
|