Files
SIG/Bancos/Reembolsos.aspx.vb
2020-07-16 15:23:10 -07:00

1199 lines
61 KiB
VB.net

Option Explicit On
Option Strict On
Imports Extensiones
Imports System.Data
Partial Class Bancos_Reembolsos
Inherits ClsPaginas
#Region "Propiedades"
Private ReadOnly Property CveCajaChica As Integer
Get
Return ViewState("CveCajaChica").ToString.ToEntero
End Get
End Property
Private ReadOnly Property CvePersonal As Integer
Get
Return ViewState("CvePersonal").ToString.ToEntero
End Get
End Property
Private Property CveMoneda As Integer
Get
Return ViewState("CveMoneda").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveMoneda") = value
End Set
End Property
Private Property IdCuentaBancaria As Integer
Get
Return ViewState("IdCuentaBancaria").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuentaBancaria") = value
End Set
End Property
Private Property Beneficiario As String
Get
Return ViewState("Beneficiario").ToString
End Get
Set(value As String)
ViewState("Beneficiario") = value
End Set
End Property
Private Property IdCuentaBeneficiario As Integer
Get
Return ViewState("IdCuentaBeneficiario").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("IdCuentaBeneficiario") = value
End Set
End Property
Private Property DtCheques As DataTable
Get
Return CType(ViewState("DtCheques"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtCheques") = value
End Set
End Property
Private Property CveIE As Integer
Get
Return ViewState("CveIE").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveIE") = 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
TxtImporte.Attributes.Add("disabled", "disabled")
TxtAboneA.Enabled = False
IdCuentaBeneficiario = -1
ViewState("CveMoneda") = 1
'Cargar Filtros
Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
dt = dt.FiltraParametros(String.Format("CveTipoCuenta = 1")) 'caja chica = 1
DdlCajaChica.DataSource = dt
DdlCajaChica.DataBind()
Dim ObjPersonal As New ClsRH
ObjPersonal.GetPersonal(-1, UsuarioActual.CveEmpresa)
DdlPersonal.DataSource = ObjPersonal.DtResultados
ObjPersonal.Dispose()
DdlPersonal.DataBind()
CargaTipoTransaccion()
'CargaCuentasDiferencia()
'TableDiferencia.Visible = False
End If
End Sub
#Region " FILTROS "
Protected Sub DdlTipoPago_SelectedIndexChanged(sender As Object, e As EventArgs)
PnlCheques.Visible = False
PnlChequeInfo.Visible = False
TableExpedirCheque.Visible = False
BtnIEGuardar.Enabled = False
LtTituloPago.Text = ""
If DdlTipoPago.SelectedValue = "1" Then
DdlPersonal.Visible = True
DdlPersonal.SelectedValue = "-2"
LtTituloPago.Text = "Funcionario/Empleado:"
Else
DdlPersonal.Visible = False
DdlPersonal.SelectedValue = "-2"
End If
If DdlTipoPago.SelectedValue = "2" Then
DdlCajaChica.Visible = True
DdlCajaChica.SelectedValue = "-2"
LtTituloPago.Text = "Caja Chica:"
Else
DdlCajaChica.Visible = False
DdlCajaChica.SelectedValue = "-2"
End If
ViewState("CveCajaChica") = -2
ViewState("CvePersonal") = -2
LimpiaDatos()
GvChequesFYE.Visible = False
UpChequesFYE.Update()
GvCxP.Visible = False
UpGuardar.Update()
UPCompras.Update()
'CargaCxP()
End Sub
Protected Sub DdlPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonal.SelectedIndexChanged
ViewState("CvePersonal") = DdlPersonal.SelectedValue
Dim ObjPersonal As New ClsRH
ObjPersonal.GetPersonal(CvePersonal, UsuarioActual.CveEmpresa)
If ObjPersonal.DtResultados.Rows.Count = 1 Then
IdCuentaBeneficiario = ObjPersonal.DtResultados.Rows(0)("IdCtaContPersonal").ToString.ToEntero
Beneficiario = ObjPersonal.DtResultados.Rows(0)("Nombre").ToString
End If
ObjPersonal.Dispose()
'LimpiaDatos()
'CargaCxP()
End Sub
Protected Sub DdlCajaChica_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCajaChica.SelectedIndexChanged
ViewState("CveCajaChica") = DdlCajaChica.SelectedValue
Dim dt = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveCuenta = {0}", CveCajaChica))
If dt.Rows.Count = 1 Then
IdCuentaBeneficiario = dt.Rows(0)("IdCtaContable").ToString.ToEntero
Beneficiario = dt.Rows(0)("NumCuentaMoneda").ToString
End If
'LimpiaDatos()
'CargaCxP()
End Sub
#End Region
#Region " CARGA DATOS "
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
If DdlCajaChica.SelectedIndex > 0 Or DdlPersonal.SelectedIndex > 0 Then
LimpiaDatos()
CargaCxP()
If UsuarioActual.TienePermisoProceso(113) Then CargaReporteChequesFYE()
Else
Alert("Seleccione un Funcionario/Empleado o una Cuenta", TipoMensaje.MsgAdvertencia)
End If
End Sub
Private Sub CargaDatos(tCveIE As Integer)
Dim ObjIE As New ClsBancos()
If ObjIE.GetBancosIE(tCveIE, UsuarioActual.CveEmpresa) Then
If ObjIE.DtResultados.Rows.Count > 0 Then
LtChequeFecha.Text = ObjIE.FechaDocumento.ToShortDateString
HlCheque.Text = ObjIE.Folio
HlCheque.NavigateUrl = String.Format("/Bancos/IE.aspx?CveIE={0}", tCveIE)
HdnCheque.Value = tCveIE.ToString
LtChequeImporte.Text = ObjIE.Importe.FormatoNumero
Dim IndexCheque = If(UsuarioActual.TienePermisoProceso(113), DDlCheques.SelectedIndex - 1, DDlCheques.SelectedIndex)
TxtChequeSaldo.Text = DtCheques.Rows(DDlCheques.SelectedIndex - 1)("Saldo").ToString.FormatoNumero
'DdlTipoTransaccion.SelectedValue = ObjIE.CveTipoTransaccion.ToString
'DdlTipoTransaccion_SelectedIndexChanged(DdlTipoTransaccion, EventArgs.Empty)
'DdlTipoTransaccion.Enabled = False
'DdlCuenta.SelectedValue = ObjIE.CveCuenta.ToString
'DdlCuenta.Enabled = False
'TxtObservaciones.Text = ObjIE.Observaciones
'ChkAbonoCuenta.Checked = ObjIE.EsAbonoEnCuenta
''saco el tipo de transaccion
'Dim dr As DataRow = GlobalDTTipoTransacciones.FiltroPrimero(String.Format("CveTipoTransaccion = {0}", ObjIE.CveTipoTransaccion)) 'Egs o Ing
'If dr IsNot Nothing Then
' If dr("Tipo").ToString = "Egs" Then
' LblPagueseA.Text = "Beneficiario"
' Else
' LblPagueseA.Text = "Pagador"
' End If
'End If
Else
Alert("El Documento solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia)
End If
End If
ObjIE.Dispose()
End Sub
Private Sub CargaTipoTransaccion()
DdlTipoTransaccion.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'") 'Ing
DdlTipoTransaccion.DataBind()
DdlTipoTransaccion.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1"))
'DdlTipoTransaccionDiferencia.DataSource = GlobalDTTipoTransacciones.FiltraParametros("Tipo = 'Egs'") 'Ing
'DdlTipoTransaccionDiferencia.DataBind()
'DdlTipoTransaccionDiferencia.Items.Insert(0, New ListItem("Seleccione Tipo Movimiento", "-1"))
End Sub
Private Sub CargaCuentas()
DdlCuenta.Items.Clear()
DdlCuenta.SelectedIndex = -1
Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
dt = dt.FiltraParametros(String.Format("CveMoneda = {0} ", 1))
DdlCuenta.DataSource = dt
DdlCuenta.DataBind()
DdlCuenta.Items.Insert(0, New ListItem("Seleccione cuenta", "-1"))
End Sub
#End Region
#Region " SELECTED INDEX CHANGED "
Protected Sub DdlCuenta_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuenta.SelectedIndexChanged
'recargo la moneda con la que se va a pagar
Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("CveCuenta = " & DdlCuenta.SelectedValue)
If dr IsNot Nothing Then
CveMoneda = dr("CveMoneda").ToString.ToEntero
IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero
End If
If HdnTipoTransaccion.Value = "Egs" Then
Dim Folio As Long
Dim Banco As New ClsBancos
Folio = Banco.GetNextFolio(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero)
Banco.Dispose()
TxtFolio.Text = Folio.ToString
Else
TxtFolio.Text = ""
End If
End Sub
Protected Sub DdlTipoTransaccion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoTransaccion.SelectedIndexChanged
Dim dr As DataRow = GlobalDTTipoTransacciones.FiltroPrimero(String.Format("CveTipoTransaccion = {0}", DdlTipoTransaccion.SelectedValue))
If dr IsNot Nothing Then
HdnTipoTransaccion.Value = dr("Tipo").ToString
End If
CargaCuentas()
End Sub
Protected Sub DDlCheques_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDlCheques.SelectedIndexChanged
If DDlCheques.SelectedValue.ToEntero > 0 Then
PnlChequeInfo.Visible = True
If UsuarioActual.TienePermisoProceso(113) Then TrChequeExcedente.Visible = True
CargaDatos(DDlCheques.SelectedValue.ToEntero)
LimpiaDatos()
TableExpedirCheque.Visible = False
BtnIEGuardar.Enabled = True
Else
HlCheque.Text = ""
HlCheque.NavigateUrl = ""
HdnCheque.Value = "-1"
If UsuarioActual.TienePermisoProceso(113) Then TableExpedirCheque.Visible = True
LimpiaDatos()
ChkChequeExcedente.Checked = False
PnlChequeInfo.Visible = False
'If UsuarioActual.TienePermisoProceso(113) Or True Then BtnIEGuardar.Enabled = False Else
BtnIEGuardar.Enabled = UsuarioActual.TienePermisoProceso(113) Or True
End If
UpGuardar.Update()
End Sub
#End Region
#Region " BTN GUARDAR "
Protected Sub BtnIEGuardar_Click(sender As Object, e As EventArgs) Handles BtnIEGuardar.Click
If UsuarioActual.Empresa.UsaAC Then
If IdCuentaBeneficiario <= 0 Then
Alert("El beneficiario no tiene vinculada una cuenta contable. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
GuardaNOAC()
'POR SEPARADO
'If UsuarioActual.Empresa.UsaAC Then
' GuardarAC()
'Else
' GuardaNOAC()
'End If
End Sub
Private Sub GuardaNOAC()
If HdnCheque.Value.ToEntero > 0 And ChkChequeExcedente.Checked And TxtImporte.Text.ToDecimal = 0 Then
Alert("El importe del cheque excedente debe ser mayor a cero", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If TxtImporte.Text.ToDecimal > 0 Or TxtImporteVinculado.Text.ToDecimal > 0 Then
'Objetos
Dim ObjIE As New ClsBancos()
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa)
ObjAC.IniciaTransacSQL()
Dim MsgError As String = ""
Dim CveIERegistrado As Integer = 0
Dim CvePersonal As Integer = 0
Dim CvePrePolizaVieja As Integer = 0
Dim CvePrePolizaNueva As Integer = 0
Dim GeneroCheque As Boolean = False
Dim Folio = TxtFolio.Text
CveIE = -1
''AC
Dim IDPolizaVieja = -1
Dim FolioPolizaVieja As String = "-1"
Dim IDPolizaNueva = -1
Dim FolioPolizaNueva As String = "-1"
Dim ErrorAC As Boolean = False
Dim Fecha As Date = TxtFechaDocumento.Text.ToDate
Dim Comp As New ClsCompras(ObjIE.IniciaTransacSQL)
Dim TipoPol As String = "TRAN"
If DdlTipoTransaccion.SelectedValue = "1" Then TipoPol = "CHQ"
Dim ConceptoRenglon As String = ""
If HdnCheque.Value.ToEntero > 0 Then
Dim FechaPrePoliza As Date = "01/01/0001".ToDate
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
If gvr.DataKey("FechaCompra").ToDate > FechaPrePoliza Then
FechaPrePoliza = gvr.DataKey("FechaCompra").ToDate
End If
End If
Next
'Dim FchasCompras = HdnFechasComprasVinculadas.Value.ToString.Split(","c)
'For index = 0 To FchasCompras.Length - 1
' If FchasCompras(index).ToDate > FechaPrePoliza Then
' FechaPrePoliza = FchasCompras(index).ToDate
' End If
'Next
If LtChequeFecha.Text.ToDate > FechaPrePoliza Then
FechaPrePoliza = LtChequeFecha.Text.ToDate
End If
CvePrePolizaVieja = ObjMov.AddPrePolizas("Banc", 9, TxtImporteVinculado.Text.ToDecimal, TxtImporteVinculado.Text.ToDecimal, CveMoneda, FechaPrePoliza, "Comprobación: " & TxtObservaciones.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
CveIE = DDlCheques.SelectedValue.ToEntero
CveIERegistrado = CveIE
Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("CveCuenta = " & DdlCuenta.SelectedValue)
If DdlPersonal.Visible AndAlso DdlPersonal.SelectedValue.ToEntero > 0 Then CvePersonal = DdlPersonal.SelectedValue.ToEntero
If dr IsNot Nothing Then
CveMoneda = dr("CveMoneda").ToString.ToEntero
IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero
End If
''AC - Poliza Vieja
If UsuarioActual.Empresa.UsaAC Then
IDPolizaVieja = ObjAC.AddPoliza(3, String.Format("Comprobación: {0}", Beneficiario), TxtImporteVinculado.Text.ToDouble, TxtImporteVinculado.Text.ToDouble, UsuarioActual.CveUsuario, Fecha)
FolioPolizaVieja = ObjAC.Folio.ToString
End If
If ChkChequeExcedente.Checked Then
CvePrePolizaNueva = ObjMov.AddPrePolizas("Banc", 9, TxtImporte.Text.ToDecimal, TxtImporte.Text.ToDecimal, CveMoneda, TxtFechaDocumento.Text.ToDate, "Comprobación: " & TxtObservaciones.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaDocumento.Text.ToDate, TxtFolio.Text.Trim, TxtAboneA.Text, TxtImporte.Text.ToDecimal, CveMoneda, 0.0, TxtObservaciones.Text, "", ChkAbonoCuenta.Checked, True, -1, CvePrePolizaNueva, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
GeneroCheque = True
''AC - Poliza Nueva
If UsuarioActual.Empresa.UsaAC Then
If DdlTipoTransaccion.SelectedValue = "1" Then
IDPolizaNueva = ObjAC.AddPoliza(2, String.Format("Comprobación: {0}", Beneficiario), TxtImporte.Text.ToDouble, TxtImporte.Text.ToDouble, UsuarioActual.CveUsuario, Fecha, TxtFolio.Text, "CHQ")
Else
IDPolizaNueva = ObjAC.AddPoliza(2, String.Format("Comprobación: {0}", Beneficiario), TxtImporte.Text.ToDouble, TxtImporte.Text.ToDouble, UsuarioActual.CveUsuario, Fecha)
End If
FolioPolizaNueva = ObjAC.Folio.ToString
End If
End If
Else
CvePrePolizaNueva = ObjMov.AddPrePolizas("Banc", 9, TxtImporte.Text.ToDecimal, TxtImporte.Text.ToDecimal, CveMoneda, TxtFechaDocumento.Text.ToDate, "Comprobación: " & TxtObservaciones.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaDocumento.Text.ToDate, TxtFolio.Text.Trim, TxtAboneA.Text, TxtImporte.Text.ToDecimal, CveMoneda, 0.0, TxtObservaciones.Text, "", ChkAbonoCuenta.Checked, True, -1, CvePrePolizaNueva, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
GeneroCheque = True
''AC - Poliza Nueva
If UsuarioActual.Empresa.UsaAC Then
If DdlTipoTransaccion.SelectedValue = "1" Then
IDPolizaNueva = ObjAC.AddPoliza(2, String.Format("Comprobación: {0}", Beneficiario), TxtImporte.Text.ToDouble, TxtImporte.Text.ToDouble, UsuarioActual.CveUsuario, Fecha, TxtFolio.Text, "CHQ")
Else
IDPolizaNueva = ObjAC.AddPoliza(2, String.Format("Comprobación: {0}", Beneficiario), TxtImporte.Text.ToDouble, TxtImporte.Text.ToDouble, UsuarioActual.CveUsuario, Fecha)
End If
FolioPolizaNueva = ObjAC.Folio.ToString
End If
End If
If CveIE > 0 Then
'inserto los movimientos de la conta para abonar al saldo
If (TxtImporte.Text.ToDecimal > 0 And CvePrePolizaNueva > 0) Or (TxtImporteVinculado.Text.ToDecimal > 0 And HdnCheque.Value.ToEntero > 0 And CvePrePolizaVieja > 0) Then
Dim SaldoCheque = TxtChequeSaldo.Text.ToDecimal
Dim SaldoActual As Decimal = 0
Dim SaldoAbonado As Decimal = 0
Dim PorcentajePago As Decimal = 1
'AC
Dim Total As Double
Dim ImporteExcedido As Decimal = 0
'inserto las compras que voy a pagar
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
'Saco el porcentaje de pago
If gvr.DataKey("Original").ToDecimal > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1
SaldoActual = gvr.FCTextBox("TxtAbonar").Text.ToDecimal
SaldoAbonado = If(SaldoActual > SaldoCheque, SaldoCheque, SaldoActual)
'CHEQUE VINCULADO
If gvr.DataKey("Original").ToDecimal > 0 Then PorcentajePago = SaldoAbonado / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1
If CveIERegistrado > 0 AndAlso SaldoCheque > 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaVieja, True, SaldoAbonado, " ", 29, " ", gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIERegistrado, CvePersonal:=CvePersonal, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=SaldoAbonado) Then
MsgError = "Detalle"
Exit For
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaVieja, False, SaldoAbonado, " ", 17, " ", gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIERegistrado, CvePersonal:=CvePersonal, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=SaldoAbonado) Then
MsgError = "Detalle"
Exit For
End If
If MsgError = "" AndAlso gvr.DataKey("IVA").ToDecimal > 0 Then
'Agrego el IVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaVieja, False, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 14, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
Exit For
End If
'Agrego el IVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaVieja, True, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 19, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
Exit For
End If
End If
'AC
If UsuarioActual.Empresa.UsaAC Then
If IDPolizaVieja > 0 Then
If Comp.GetPresupuestosCompras(gvr.DataKey("CveCompra").ToEntero) Then
For Each dr As DataRow In Comp.DtResultados.Rows
Total = dr("TotalPresupuesto").ToString.ToDouble * PorcentajePago
If Total > 0 Then
ConceptoRenglon = String.Format("GE F: {0} - {1} ", dr("SerieFolio"), dr("FuenteFinanciamientoRubroEgreso"))
'EJERCIDO
If Not ObjAC.AddMovimiento(IDPolizaVieja, dr("IdCuentaEjercido").ToString.ToEntero, False, Total, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
If Not ObjAC.AddMovimiento(IDPolizaVieja, dr("IdCuentaDevengado").ToString.ToEntero, True, Total, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
'PAGADO
If Not ObjAC.AddMovimiento(IDPolizaVieja, dr("IdCuentaPagado").ToString.ToEntero, False, Total, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
If Not ObjAC.AddMovimiento(IDPolizaVieja, dr("IdCuentaEjercido").ToString.ToEntero, True, Total, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
End If
Next
If ErrorAC Then
Exit For
End If
'AFECTAR MATRIZ EGRESOS
Total = gvr.FCTextBox("TxtAbonar").Text.ToDouble
If Not ObjAC.AddMovimiento(IDPolizaVieja, gvr.DataKey("IdCtaContProveedores").ToEntero, False, Total, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
Else
ErrorAC = True
Exit For
End If
Else
ErrorAC = True
Exit For
End If
End If
End If
'CHEQUE EXPEDIDO
SaldoActual = SaldoActual - SaldoAbonado
If gvr.DataKey("Original").ToDecimal > 0 Then PorcentajePago = SaldoActual / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1
If SaldoActual > 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, True, SaldoActual, TxtObservaciones.Text, 17, "", gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=SaldoActual) Then
MsgError = "Detalle"
Exit For
Else
ImporteExcedido += (gvr.DataKey("SubTotal").ToDecimal - gvr.DataKey("Descuento").ToDecimal) * PorcentajePago + gvr.DataKey("IVA").ToDecimal * PorcentajePago
'If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, False, gvr.DataKey("SubTotal").ToDecimal * PorcentajePago, TxtObservaciones.Text, 30, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero) Then
' MsgError = "no se pudo insertar el detalle de la poliza"
'End If
'*********IVA. siempre se registra aunque sea cero PREGUNTAR POR EL CONCEPTO DE IVA EN Conta_Conceptos
If MsgError = "" AndAlso gvr.DataKey("IVA").ToDecimal > 0 Then
'Agrego el IVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, False, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 14, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
Exit For
End If
'Agrego el IVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, True, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 19, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
Exit For
End If
End If
If MsgError = "" AndAlso gvr.DataKey("RetIVA").ToDecimal > 0 Then
'Agrego el RetIVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, True, gvr.DataKey("RetIVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 15, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
Exit For
End If
End If
If MsgError = "" AndAlso gvr.DataKey("RetISR").ToDecimal > 0 Then
'Agrego el RetISR
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, True, gvr.DataKey("RetISR").ToDecimal * PorcentajePago, TxtObservaciones.Text, 16, TxtObservaciones.Text, gvr.FCLiteral("LtlFecha").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("RetISR").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
Exit For
End If
End If
End If
'AC
If UsuarioActual.Empresa.UsaAC Then
If IDPolizaNueva > 0 Then
If Comp.GetPresupuestosCompras(gvr.DataKey("CveCompra").ToEntero) Then
For Each dr As DataRow In Comp.DtResultados.Rows
Total = dr("TotalPresupuesto").ToString.ToDouble * PorcentajePago
If Total > 0 Then
ConceptoRenglon = String.Format("GE F: {0} - {1} ", dr("SerieFolio"), dr("FuenteFinanciamientoRubroEgreso"))
'EJERCIDO
If Not ObjAC.AddMovimiento(IDPolizaNueva, dr("IdCuentaEjercido").ToString.ToEntero, False, Total, FolioPolizaNueva, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
If Not ObjAC.AddMovimiento(IDPolizaNueva, dr("IdCuentaDevengado").ToString.ToEntero, True, Total, FolioPolizaNueva, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
'PAGADO
If Not ObjAC.AddMovimiento(IDPolizaNueva, dr("IdCuentaPagado").ToString.ToEntero, False, Total, FolioPolizaNueva, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
If Not ObjAC.AddMovimiento(IDPolizaNueva, dr("IdCuentaEjercido").ToString.ToEntero, True, Total, FolioPolizaNueva, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
End If
Next
If ErrorAC Then
Exit For
End If
'AFECTAR MATRIZ EGRESOS
Total = gvr.FCTextBox("TxtAbonar").Text.ToDouble
If Not ObjAC.AddMovimiento(IDPolizaNueva, gvr.DataKey("IdCtaContProveedores").ToEntero, False, Total, FolioPolizaNueva, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
Else
ErrorAC = True
Exit For
End If
Else
ErrorAC = True
Exit For
End If
End If
End If
SaldoCheque = SaldoCheque - gvr.FCTextBox("TxtAbonar").Text.ToDecimal 'Saldo completo del concepto
SaldoCheque = If(SaldoCheque < 0, 0, SaldoCheque) 'Cuando ya se completo el cheque igualamos a cero siempre para no afectar siguientes movtos
End If
Next
If ImporteExcedido > 0 And MsgError.Trim = "" Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePolizaNueva, False, ImporteExcedido, TxtObservaciones.Text, 30, TxtObservaciones.Text, TxtFechaDocumento.Text.ToDate, 0, -1, CveIE:=CveIE, ImporteMX:=ImporteExcedido) Then
MsgError = "no se pudo insertar el detalle de la poliza"
End If
End If
Else
MsgError = "No se pudo insertar la póliza"
End If
Else
MsgError = "No se insertó el encabezado"
End If
If MsgError.Trim = "" AndAlso UsuarioActual.Empresa.UsaAC Then
'Poliza VIEJA
If Not ErrorAC And IDPolizaVieja > 0 Then
ConceptoRenglon = String.Format("Comprobación: {0}", Beneficiario)
If Not ObjAC.AddMovimiento(IDPolizaVieja, IdCuentaBeneficiario, True, TxtImporteVinculado.Text.ToDouble, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True
'registro el movimiento en bancos y su comprobacion
If GeneroCheque Then
If Not ObjAC.AddMovimiento(IDPolizaVieja, IdCuentaBeneficiario, False, TxtImporteVinculado.Text.ToDouble, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True
If Not ObjAC.AddMovimiento(IDPolizaVieja, IdCuentaBancaria, True, TxtImporteVinculado.Text.ToDouble, FolioPolizaVieja, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True
End If
End If
If Not ErrorAC And IDPolizaVieja > 0 Then
If ObjIE.UpdateIEPrePoliza(Fecha, FolioPolizaVieja, IDPolizaVieja, CvePrePolizaVieja, -1, -1) Then
If Not ObjAC.AjustaPoliza(IDPolizaVieja) Then ErrorAC = True
Else
ErrorAC = True
End If
End If
'Poliza NUEVA
If Not ErrorAC And IDPolizaNueva > 0 Then
ConceptoRenglon = String.Format("Comprobación: {0}", Beneficiario)
If Not ObjAC.AddMovimiento(IDPolizaNueva, IdCuentaBancaria, True, TxtImporte.Text.ToDouble, FolioPolizaNueva, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True
End If
If Not ErrorAC And IDPolizaNueva > 0 Then
If ObjIE.UpdateIEPrePoliza(Fecha, FolioPolizaNueva, IDPolizaNueva, CvePrePolizaNueva, -1, -1) Then
If Not ObjAC.AjustaPoliza(IDPolizaNueva) Then ErrorAC = True
Else
ErrorAC = True
End If
End If
If Not ErrorAC Then
'PENDIENTE
'GeneraChequePDF(CveIE, UsuarioActual.Empresa, IDPoliza)
ObjIE.Commit()
ObjAC.Commit()
UPCompras.Update()
CargaCxP()
Dim Str As New StringBuilder
Str.Append("Abono Registrado Correctamente. <br/>")
If CvePrePolizaNueva > 0 Then
GeneraChequePDF(CveIE, UsuarioActual.Empresa, -1, False)
Str.AppendFormat("<br/><li> <a class='Texto' target='_blank' href=/Bancos/IE.aspx?CveIE={0}>Ver Movimiento</a></li> ", CveIE, Folio)
Str.AppendFormat("<li><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Cheque</a></li>", Encripta(String.Format("OP=IE&CVEIE={0}", CveIE)))
End If
If IDPolizaVieja > 0 Then Str.AppendFormat("<br/> Poliza del cheque vinculado: <a class='Texto' target='_blank' href=/Contabilidad/RegPoliza.aspx?IdPoliza={0}>{1}</a> ", IDPolizaVieja, FolioPolizaVieja)
If IDPolizaNueva > 0 Then Str.AppendFormat("<br/> Poliza del cheque expedido: <a class='Texto' target='_blank' href=/Contabilidad/RegPoliza.aspx?IdPoliza={0}>{1}</a> ", IDPolizaNueva, FolioPolizaNueva)
Alert(Str.ToString, TipoMensaje.MsgInformacion)
LimpiaDatos()
PnlChequeInfo.Visible = False
Else
ObjIE.RollBack()
ObjAC.RollBack()
Alert("Error al Agregar la Póliza de Armonización Contable.", TipoMensaje.MsgError)
End If
ObjAC.Dispose()
ObjIE.Dispose()
ElseIf MsgError.Trim = "" Then
ObjIE.Commit()
ObjAC.Commit()
UPCompras.Update()
CargaCxP()
If CvePrePolizaNueva > 0 Then
Dim Str As New StringBuilder
Str.Append("Abono Registrado Correctamente. <br/>")
GeneraChequePDF(CveIE, UsuarioActual.Empresa, -1, False)
If CvePrePolizaNueva > 0 Then
Str.AppendFormat("<br/>Cheque: <a class='Texto' target='_blank' href=/Bancos/IE.aspx?CveIE={0}>{1}</a> ", CveIE, Folio)
'Str.AppendFormat("<br/><a class='Texto' href='#' onclick='fnimprimir();'>Imprimir Cheque</a> ")
Str.AppendFormat("<li><a class=""Texto"" target='_blank' href=""/Empresas/{0}/PDF/Chq-{1}.pdf?{2}"">Imprimir Cheque</a></li>", UsuarioActual.CveEmpresa, CveIE, Now.Ticks)
End If
Alert(Str.ToString, TipoMensaje.MsgInformacion)
Else
Alert("Abono Registrado Correctamente.", TipoMensaje.MsgInformacion)
End If
LimpiaDatos()
PnlChequeInfo.Visible = False
Else
Alert("Ocurrió un error al guardar el movimiento", TipoMensaje.MsgError)
ObjIE.RollBack()
ObjAC.RollBack()
ObjAC.Dispose()
ObjIE.Dispose()
End If
Else
Alert("El Importe debe de ser mayor a $0.00", TipoMensaje.MsgAdvertencia)
End If
End Sub
'ELIMINAR 28/06/2018
Private Sub GuardarAC_eliminar()
If TxtImporte.Text.ToDouble > 0 Then
Dim ObjIE As New ClsBancos()
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
Dim MsgError As String = ""
Dim CveIERegistrado As Integer = 0
Dim CvePersonal As Integer = 0
Dim CvePrePoliza As Integer = 0
Dim CveIE As Integer
CvePrePoliza = ObjMov.AddPrePolizas("Banc", 2, TxtImporte.Text.ToDouble, TxtImporte.Text.ToDouble, CveMoneda, TxtFechaDocumento.Text.ToDate, "Comprobación: " & TxtObservaciones.Text.Trim, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If DDlCheques.SelectedValue.ToEntero > 0 Then
CveIE = DDlCheques.SelectedValue.ToEntero
CveIERegistrado = DDlCheques.SelectedValue.ToEntero
Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero("CveCuenta = " & DdlCuenta.SelectedValue)
If DdlPersonal.Visible AndAlso DdlPersonal.SelectedValue.ToEntero > 0 Then CvePersonal = DdlPersonal.SelectedValue.ToEntero
If dr IsNot Nothing Then
CveMoneda = dr("CveMoneda").ToString.ToEntero
IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero
End If
Else
CveIE = ObjIE.AddBancos_IE(DdlCuenta.SelectedValue.ToEntero, DdlTipoTransaccion.SelectedValue.ToEntero, TxtFechaDocumento.Text.ToDate, TxtFolio.Text.Trim, TxtAboneA.Text, TxtImporte.Text.ToDouble, CveMoneda, 0.0, TxtObservaciones.Text, "", ChkAbonoCuenta.Checked, True, -1, CvePrePoliza, "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
End If
If CveIE > 0 Then
'inserto los movimientos de la conta para abonar al saldo
If CvePrePoliza > 0 Then
Dim PorcentajePago As Decimal = 100
'inserto las compras que voy a pagar
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
'Saco el porcentaje de pago
If gvr.DataKey("Original").ToDouble > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDecimal / gvr.DataKey("Original").ToDecimal Else PorcentajePago = 1
If CveIERegistrado > 0 Then
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.FCTextBox("TxtAbonar").Text.ToDecimal, " ", 29, " ", gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CvePersonal:=CvePersonal, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.FCTextBox("TxtAbonar").Text.ToDecimal) Then
MsgError = "Detalle"
End If
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.FCTextBox("TxtAbonar").Text.ToDecimal, " ", 17, " ", gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CvePersonal:=CvePersonal, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.FCTextBox("TxtAbonar").Text.ToDecimal) Then
MsgError = "Detalle"
End If
Else
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.FCTextBox("TxtAbonar").Text.ToDecimal, TxtObservaciones.Text, 17, "", gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.FCTextBox("TxtAbonar").Text.ToDecimal) Then
MsgError = "Detalle"
Exit For
Else
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.DataKey("SubTotal").ToDecimal * PorcentajePago, TxtObservaciones.Text, 6, TxtObservaciones.Text, gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("SubTotal").ToDecimal * PorcentajePago) Then
MsgError = "no se pudo insertar el detalle de la poliza"
End If
'*********IVA. siempre se registra aunque sea cero PREGUNTAR POR EL CONCEPTO DE IVA EN Conta_Conceptos
If MsgError = "" AndAlso gvr.DataKey("IVA").ToDouble > 0 Then
'Agrego el IVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, False, gvr.DataKey("IVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 13, TxtObservaciones.Text, gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("IVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
End If
End If
If MsgError = "" AndAlso gvr.DataKey("RetIVA").ToDouble > 0 Then
'Agrego el RetIVA
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.DataKey("RetIVA").ToDecimal * PorcentajePago, TxtObservaciones.Text, 15, TxtObservaciones.Text, gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("RetIVA").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
End If
End If
If MsgError = "" AndAlso gvr.DataKey("RetISR").ToDouble > 0 Then
'Agrego el RetISR
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, True, gvr.DataKey("RetISR").ToDecimal * PorcentajePago, TxtObservaciones.Text, 16, TxtObservaciones.Text, gvr.FCLiteral("LtlFechaVenci").Text.ToDate, 0, -1, CveIE:=CveIE, CveCompra:=gvr.FCHyperLink("HplF2").Text.ToEntero, CveProveedor:=gvr.FCHyperLink("HLProv").Text.ToEntero, ImporteMX:=gvr.DataKey("RetISR").ToDecimal * PorcentajePago) Then
MsgError = "Detalle"
End If
End If
End If
End If
End If
Next
Else
MsgError = "No se pudo insertar la póliza"
End If
Else
MsgError = "No se insertó el encabezado"
End If
If MsgError.Trim = "" Then
'se agregan las pólizas de Armonización Contable
If UsuarioActual.Empresa.UsaAC Then
Dim Fecha As Date = TxtFechaDocumento.Text.Trim.ToDate
Dim ErrorAC As Boolean = False
Dim ObjAC As New ClsContPAQi(UsuarioActual.Empresa)
ObjAC.IniciaTransacSQL()
Dim Comp As New ClsCompras(ObjIE.IniciaTransacSQL)
Dim FolioPoliza As String
Dim TipoPol As String = "TRAN"
If DdlTipoTransaccion.SelectedValue = "1" Then TipoPol = "CHQ"
Dim IDPoliza As Integer = ObjAC.AddPoliza(2, String.Format("Pagado: {0}, {1}", TxtAboneA.Text, TxtObservaciones.Text), TxtImporte.Text.ToDouble, TxtImporte.Text.ToDouble, UsuarioActual.CveUsuario, Fecha, TxtFolio.Text, TipoPol)
FolioPoliza = ObjAC.Folio.ToString
Dim ConceptoRenglon As String = ""
If IDPoliza > 0 Then
Dim Total As Double
Dim PorcentajePago As Double = 100
Dim Referencia As String = TxtFolio.Text.Trim
For Each gvr As GridViewRow In GvCxP.Rows
If gvr.FCCheckBox("Chk").Checked Then
'obtengo su poliza para ver que presupuestos afecto
If gvr.DataKey("Original").ToDouble > 0 Then PorcentajePago = gvr.FCTextBox("TxtAbonar").Text.ToDouble / gvr.DataKey("Original").ToDouble Else PorcentajePago = 1
If Comp.GetPresupuestosCompras(gvr.DataKey("CveCompra").ToEntero) Then
' dtAC.Merge(Comp.DtResultados)
For Each dr As DataRow In Comp.DtResultados.Rows
Total = dr("TotalPresupuesto").ToString.ToDouble * PorcentajePago
If Total > 0 Then
'EJERCIDO
ConceptoRenglon = String.Format("GE F: {0} - {1} ", dr("SerieFolio"), dr("FuenteFinanciamientoRubroEgreso"))
If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaEjercido").ToString.ToEntero, False, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaDevengado").ToString.ToEntero, True, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
'PAGADO
ConceptoRenglon = String.Format("GP F: {0} - {1} ", dr("SerieFolio"), dr("FuenteFinanciamientoRubroEgreso"))
If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaPagado").ToString.ToEntero, False, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
'actualizo el idcuenta del presupuesto
If Not ObjAC.AddMovimiento(IDPoliza, dr("IdCuentaEjercido").ToString.ToEntero, True, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
End If
Next
'AFECTAR MATRIZ EGRESOS
Total = gvr.FCTextBox("TxtAbonar").Text.ToDouble
If Not ObjAC.AddMovimiento(IDPoliza, gvr.DataKey("IdCtaContProveedores").ToEntero, False, Total, Referencia, ConceptoRenglon, 0, Fecha, "") Then ErrorAC = True : Exit For
End If
End If
Next
ConceptoRenglon = String.Format("Pagado: {0}", TxtAboneA.Text)
If Not ObjAC.AddMovimiento(IDPoliza, IdCuentaBancaria, True, TxtImporte.Text.ToDouble, Referencia, ConceptoRenglon, 0, Fecha, "") Then
ErrorAC = True
End If
Else
ErrorAC = True
End If
If Not ErrorAC Then
ObjAC.AjustaPoliza(IDPoliza)
ObjIE.UpdateIEPrePoliza(Fecha, FolioPoliza.ToString, IDPoliza, CvePrePoliza, CveIE, 0)
ObjIE.Commit()
ObjAC.Commit()
UPCompras.Update()
LimpiaDatos()
CargaCxP()
GeneraChequePDF(CveIE, UsuarioActual.Empresa, IDPoliza)
'Alert(String.Format("Abono Registrado Correctamente.<br/><br/> Poliza: <a href='/Contabilidad/RegPoliza.aspx?IdPoliza={0}' target='_blank' class='Texto'>{1}</a>", IDPoliza, FolioPoliza))
Else
ObjIE.RollBack()
ObjAC.RollBack()
Alert("Error al Agregar la Póliza de Armonización Contable.", TipoMensaje.MsgError)
End If
ObjAC.Dispose()
Else
ObjIE.Commit()
UPCompras.Update()
LimpiaDatos()
CargaCxP()
Alert("Abono Registrado Correctamente.", TipoMensaje.MsgInformacion)
End If
Else
Alert("Ocurrió un error al guardar el movimiento", TipoMensaje.MsgError)
ObjIE.RollBack()
End If
Else
Alert("El Importe debe de ser mayor a $0.00", TipoMensaje.MsgAdvertencia)
End If
End Sub
Protected Sub LimpiaDatos()
TxtFolio.Text = ""
TxtObservaciones.Text = ""
TxtImporte.Text = ""
TxtImporteVinculado.Text = ""
TxtFechaDocumento.Text = Date.Now.ToShortDateString
'DdlCuenta.SelectedValue = "-1"
DdlTipoTransaccion.SelectedValue = "-1"
DdlTipoTransaccionDiferencia_SelectedIndexChanged(DdlTipoTransaccion, EventArgs.Empty)
UpDatos.Update()
For Each gvr As GridViewRow In GvCxP.Rows
gvr.FCCheckBox("Chk").Checked = False
gvr.FCTextBox("TxtAbonar").Text = ""
Next
UPCompras.Update()
End Sub
#End Region
#Region " REPORTE CHEQUES FYE "
Private Sub CargaReporteChequesFYE()
If DdlPersonal.SelectedIndex > 0 Then
GvChequesFYE.Visible = True
Dim ObjMovtos As New ClsMovimientos
Dim DtChequesFYE As DataTable = Nothing
If ObjMovtos.GetChequesFYE(UsuarioActual.CveEmpresa) Then
DtChequesFYE = ObjMovtos.DtResultados
Else
Alert("Ocurrió un error al cargar el reporte de cheques de Funcionarios/Empleados. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ObjMovtos.Dispose()
If DtChequesFYE.Rows.Count > 0 Then
GvChequesFYE.DataSource = DtChequesFYE
GvChequesFYE.DataBind()
UpChequesFYE.Update()
End If
Else
GvChequesFYE.Visible = False
End If
End Sub
Protected Sub GvChequesFYE_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCHyperLink("HLFYE").NavigateUrl = String.Format("/RH/Personal.aspx?CvePersonal={0}", e.Row.DBCampo("CvePersonal"))
e.Row.FCHyperLink("HLCheque").NavigateUrl = String.Format("/Bancos/IE.aspx?CveIE={0}", e.Row.DBCampo("CveIE"))
End If
End Sub
#End Region
#Region " TABLA CxP "
Protected Sub CargaCxP()
Dim ObjMovtos As New ClsMovimientos
GvCxP.Visible = True
ObjMovtos.GetCxPPersonalCajaChica(UsuarioActual.CveEmpresa, CvePersonal, CveCajaChica, "-1")
GvCxP.DataSource = ObjMovtos.DtResultados.FiltraParametros("Saldo > 0")
'Limpia Ddl Cheques
DDlCheques.Items.Clear()
'cargo si tiene cheques pendientes sin amortizar
If CvePersonal > 0 Then
ObjMovtos.GetEgresosSinComprobarPersonalDetalle(CvePersonal, UsuarioActual.CveEmpresa)
CargaCuentas()
PnlCheques.Visible = True
If UsuarioActual.TienePermisoProceso(113) Then TableExpedirCheque.Visible = True
End If
If CveCajaChica > 0 Then
ObjMovtos.GetCajaChicaDetalle(CveCajaChica, UsuarioActual.CveEmpresa)
PnlCheques.Visible = True
If UsuarioActual.TienePermisoProceso(113) Then TableExpedirCheque.Visible = True
DdlCuenta.Items.Clear()
DdlCuenta.Items.Add(New ListItem(DdlCajaChica.SelectedItem.Text, DdlCajaChica.SelectedValue))
End If
DtCheques = ObjMovtos.DtResultados.FiltraParametros("CveIE > 0", "FechaDocumento, FolioFecha")
If DtCheques.Rows.Count > 0 Then
DDlCheques.DataSource = DtCheques
End If
ObjMovtos.Dispose()
GvCxP.DataBind()
DDlCheques.DataBind()
If UsuarioActual.TienePermisoProceso(113) Then
DDlCheques.Items.Insert(0, New ListItem("Expedir Cheque", "-1"))
Else
DDlCheques.Items.Insert(0, New ListItem("Seleccione", "-1"))
End If
DDlCheques_SelectedIndexChanged(DDlCheques, EventArgs.Empty)
If GvCxP.Rows.Count > 0 Then
TxtFechaDocumento.Text = Now.ToShortDateString
'BtnIEGuardar.Enabled = True
If Not DdlPersonal.SelectedValue = "-2" Then
TxtAboneA.Text = DdlPersonal.SelectedItem.ToString
End If
If Not DdlCajaChica.SelectedValue = "-2" Then
TxtAboneA.Text = DdlCajaChica.SelectedItem.ToString
End If
Else
TxtAboneA.Text = ""
'BtnIEGuardar.Enabled = False
End If
UpDatos.Update()
'UpGuardar.Update()
UPCompras.Update()
UPPChq.Update()
End Sub
Protected Sub GvCxP_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxP.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 0 Then
e.Row.BackColor = Drawing.Color.LightGray
e.Row.FCTextBox("TxtAbonar").Visible = False
e.Row.FCCheckBox("Chk").Visible = False
End If
If e.Row.RowIndex = 1 Then
e.Row.Cells(0).Width = Unit.Pixel(20)
e.Row.Cells(1).Width = Unit.Pixel(70)
e.Row.Cells(2).Width = Unit.Pixel(250)
e.Row.Cells(3).Width = Unit.Pixel(70)
e.Row.Cells(4).Width = Unit.Pixel(80)
e.Row.Cells(5).Width = Unit.Pixel(40)
e.Row.Cells(6).Width = Unit.Pixel(80)
e.Row.Cells(7).Width = Unit.Pixel(70)
e.Row.Cells(8).Width = Unit.Pixel(70)
e.Row.Cells(9).Width = Unit.Pixel(80)
End If
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Right
e.Row.Cells(8).HorizontalAlign = HorizontalAlign.Right
If e.Row.DBCampo("Saldo").ToDouble < 0 Then e.Row.Cells(7).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("DiasVencidos").ToDouble > 0 AndAlso CType(sender, GridView).ID = "GvCxP" Then e.Row.Cells(5).ForeColor = Drawing.Color.Red
If e.Row.DBCampo("Original").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldoOriginal"), Literal).Text = ""
If e.Row.DBCampo("Abonado").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlAbonado"), Literal).Text = ""
If e.Row.DBCampo("Saldo").ToDouble = 0 Then DirectCast(e.Row.FindControl("LtlSaldo"), Literal).Text = ""
'If TxtNumeroReembolso.Text = "" Then e.Row.FCCheckBox("Chk").Enabled = False
e.Row.FCCheckBox("Chk").Attributes.Add("onclick", String.Format("FnSuma(this,{0},{1});", e.Row.FCTextBox("TxtAbonar").ClientID, e.Row.DBCampo("Saldo")))
e.Row.FCTextBox("TxtAbonar").Attributes.Add("onblur", String.Format("FnCambia({0},this,{1});", e.Row.FCCheckBox("Chk").ClientID, e.Row.DBCampo("Saldo")))
End If
End Sub
#End Region
#Region " APLICA DIFERENCIA "
Protected Sub ChkChequeExcedente_CheckedChanged(sender As Object, e As EventArgs)
If ChkChequeExcedente.Checked Then
If UsuarioActual.TienePermisoProceso(113) Then TableExpedirCheque.Visible = True
Else
LimpiaDatos()
TxtImporteVinculado.Text = ""
TableExpedirCheque.Visible = False
End If
End Sub
Protected Sub BtnDiferencia_Click(sender As Object, e As EventArgs)
TxtImporteVinculado.Text = HdnSaldo.Value
If HdnSaldoDiferencia.Value.ToDouble > 0 AndAlso ChkChequeExcedente.Checked Then
TxtImporte.Text = HdnSaldoDiferencia.Value
End If
End Sub
Protected Sub DdlCuentaDiferencia_SelectedIndexChanged(sender As Object, e As EventArgs) 'Handles DdlCuentaDiferencia.SelectedIndexChanged
'recargo la moneda con la que se va a pagar
'Dim dr As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario).FiltroPrimero("CveCuenta = " & DdlCuentaDiferencia.SelectedValue)
'If dr IsNot Nothing Then
' CveMoneda = dr("CveMoneda").ToString.ToEntero
' IdCuentaBancaria = dr("IdCtaContable").ToString.ToEntero
'End If
'If HdnTipoTransaccion.Value = "Egs" Then
' Dim Folio As Long
' Dim Banco As New ClsBancos
' Folio = Banco.GetNextFolio(DdlCuentaDiferencia.SelectedValue.ToEntero, DdlTipoTransaccionDiferencia.SelectedValue.ToEntero)
' Banco.Dispose()
' TxtFolioDiferencia.Text = Folio.ToString
'Else
' TxtFolioDiferencia.Text = ""
'End If
End Sub
Protected Sub DdlTipoTransaccionDiferencia_SelectedIndexChanged(sender As Object, e As EventArgs) 'Handles DdlTipoTransaccionDiferencia.SelectedIndexChanged
'Dim dr As DataRow = GlobalDTTipoTransacciones.FiltroPrimero(String.Format("CveTipoTransaccion = {0}", DdlTipoTransaccionDiferencia.SelectedValue))
'If dr IsNot Nothing Then
' HdnTipoTransaccionDiferencia.Value = dr("Tipo").ToString
'End If
'CargaCuentasDiferencia()
End Sub
Private Sub CargaCuentasDiferencia()
'DdlCuentaDiferencia.Items.Clear()
'Dim dt As DataTable = GlobalDTBancosCuentas(UsuarioActual.CveUsuario)
'dt = dt.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = {1}", 1, DdlTipoTransaccion.SelectedValue))
'DdlCuentaDiferencia.DataSource = dt
'DdlCuentaDiferencia.DataBind()
'DdlCuentaDiferencia.Items.Insert(0, New ListItem("Seleccione cuenta", "-1"))
End Sub
#End Region
#Region " EXPORTAR - PDF - EXCEL "
Protected Sub ImgExcel_Click(sender As Object, e As ImageClickEventArgs)
GvCxP.Columns(0).Visible = False
GvCxP.Columns(9).Visible = False
GvCxP.ExportToExcel("Reembolsos - Comprobaciones ")
GvCxP.Columns(0).Visible = True
GvCxP.Columns(9).Visible = True
End Sub
#End Region
Protected Sub BtnImprimirCheque_Click(sender As Object, e As EventArgs)
GeneraChequePDF(CveIE, UsuarioActual.Empresa)
End Sub
End Class