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.
")
If CvePrePolizaNueva > 0 Then
GeneraChequePDF(CveIE, UsuarioActual.Empresa, -1, False)
Str.AppendFormat("