Files
SIG/Bancos/ConciliacionesBancarias.aspx.vb

685 lines
31 KiB
VB.net

Option Strict On
Option Explicit On
Imports System.Data
Imports Extensiones
Imports System.Xml
Imports Microsoft.Reporting.WebForms
Imports System.Globalization
Partial Class Bancos_ConciliacionesBancariasaspx
Inherits ClsPaginas
#Region "PROPIEDADES"
Private Property DtDatosEdoCuenta As DataTable
Get
Return CType(ViewState("DtDatosEdoCuenta"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatosEdoCuenta") = value
End Set
End Property
Private Property DtDatos As DataTable
Get
Return CType(ViewState("DtDatos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatos") = value
End Set
End Property
Private Property ModalidadConciliacion As String
Get
Return CType(ViewState("ModalidadConciliacion"), String)
End Get
Set(value As String)
ViewState("ModalidadConciliacion") = value
End Set
End Property
Private Property ModalidadDesconciliar As String
Get
Return CType(ViewState("ModalidadDesconciliar"), String)
End Get
Set(value As String)
ViewState("ModalidadDesconciliar") = value
End Set
End Property
Private Property CveIEDesconciliar As Integer
Get
Return CType(ViewState("CveIEDesconciliar"), Integer)
End Get
Set(value As Integer)
ViewState("CveIEDesconciliar") = value
End Set
End Property
Private Property Formato As String
Get
Return CType(ViewState("Formato"), String)
End Get
Set(value As String)
ViewState("Formato") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
InicializaValores()
End If
End Sub
#Region "INICIALIZA VALORES / CONSULTAS"
Private Sub InicializaValores()
'Cargar Cuentas
DdlCuenta.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
DdlCuenta.Items.Insert(0, New ListItem("Todos", "-1"))
DdlCuenta.DataBind()
txtFechaI.Text = NowADS().FirstDayOfMonth.ToShortDateString
txtFechaF.Text = NowADS().ToShortDateString
ModalidadConciliacion = ""
ModalidadDesconciliar = ""
CveIEDesconciliar = 0
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
Consulta()
ConsultaEdoConciliacion()
End Sub
Private Sub Consulta()
Dim ObjBancos As New ClsBancos
If ObjBancos.GetIEConciliacion(-1, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, DdlConciliado.SelectedValue.ToEntero,
DdlCuenta.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, ChkVerDuplicados.Checked) Then
GvDatos.DataSource = ObjBancos.DtResultados
DtDatos = ObjBancos.DtResultados
CargaTotales(ObjBancos.DtResultados)
End If
ObjBancos.Dispose()
GvDatos.DataBind()
UpDatos.Update()
CeFechaAplicado.StartDate = txtFechaI.Text.ToDate
CeFechaAplicado.EndDate = txtFechaF.Text.ToDate
CeFechaDesconciliado.StartDate = txtFechaI.Text.ToDate
CeFechaDesconciliado.EndDate = txtFechaF.Text.ToDate
If GvDatos.Rows.Count > 0 Then RegistraScript("CalculaSeleccionados();", "1")
End Sub
Private Sub ConsultaEdoConciliacion()
Dim ObjBancos As New ClsBancos
If ObjBancos.GetIEEstadoCuenta(-1, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, DdlConciliado.SelectedValue.ToEntero,
DdlCuenta.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, VerDuplicados:=ChkVerDuplicados.Checked, Tipo:=2) Then
GvEdoConciliacion.DataSource = ObjBancos.DtResultados
DtDatosEdoCuenta = ObjBancos.DtResultados
CargaTotalesEdoCuenta(ObjBancos.DtResultados)
End If
ObjBancos.Dispose()
GvEdoConciliacion.DataBind()
UpDatosEdoConciliacion.Update()
If GvEdoConciliacion.Rows.Count > 0 Then RegistraScript("CalculaSeleccionadosEdoCuenta();", "2")
End Sub
Private Sub CargaTotales(DtDatos As DataTable)
If DtDatos IsNot Nothing Then
If DtDatos.Rows.Count > 0 Then
LblConciliados.Text = DtDatos.SUM("Importe", "FueConciliado = 1 AND CveIE > 0").FormatoNumero
LblNoConciliados.Text = DtDatos.SUM("Importe", "FueConciliado = 0 AND CveIE > 0").FormatoNumero
LblTotal.Text = DtDatos.SUM("Importe", "CveIE > 0").FormatoNumero
LblCargos.Text = DtDatos.SUM("Cargo", "CveIE > 0").FormatoNumero
LblAbonos.Text = DtDatos.SUM("Abono", "CveIE > 0").FormatoNumero
End If
DivTotales.Visible = True
DivSeleccionado.Visible = True
Else
DivTotales.Visible = False
DivSeleccionado.Visible = False
End If
UpTotales.Update()
End Sub
Private Sub CargaTotalesEdoCuenta(DtDatos As DataTable)
If DtDatos IsNot Nothing Then
If DtDatos.Rows.Count > 0 Then
LblConciliadosEdoCuenta.Text = DtDatos.SUM("Importe", "FueConciliado = 1 AND CveIEEstadoCuenta > 0").FormatoNumero
LblNoConciliadosEdoCuenta.Text = DtDatos.SUM("Importe", "FueConciliado = 0 AND CveIEEstadoCuenta > 0").FormatoNumero
LblTotalEdoCuenta.Text = DtDatos.SUM("Importe", "CveIEEstadoCuenta > 0").FormatoNumero
LblCargosEdoCuenta.Text = DtDatos.SUM("Cargo", "CveIEEstadoCuenta > 0").FormatoNumero
LblAbonosEdoCuenta.Text = DtDatos.SUM("Abono", "CveIEEstadoCuenta > 0").FormatoNumero
End If
DivTotales.Visible = True
DivSeleccionadoEdoConciliacion.Visible = True
Else
DivTotales.Visible = False
DivSeleccionadoEdoConciliacion.Visible = False
End If
UpTotales.Update()
End Sub
#End Region
#Region "CONCILIACION"
Private Sub ConciliacionAutomatica()
If Not DtDatos.Rows.Count > 0 Then
Alert("Tiene que tener movimientos para conciliar", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not DtDatosEdoCuenta.Rows.Count > 0 Then
Alert("Tiene que tener movimientos cargados de excel para conciliar", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjBancos As New ClsBancos
Dim ObjOI As New ClsOIEventos(ObjBancos.IniciaTransacSQL())
Dim ErrorTrans As Boolean = False
Dim HuboConciliacion As Boolean = False
For Each Dr As DataRow In DtDatos.Rows
If Not CBool(Dr("FueConciliado").ToString) And Dr("CveIE").ToString.ToEntero > 0 Then
For Each DrE As DataRow In DtDatosEdoCuenta.Rows
If ((Dr("FechaDocumento").ToString.ToDate = DrE("FechaDocumento").ToString.ToDate And Dr("Importe").ToString.ToDouble = DrE("Importe").ToString.ToDouble And Dr("Tipo").ToString = DrE("Tipo").ToString And DdlCriterio.SelectedValue.ToEntero = 1) Or (Dr("Importe").ToString.ToDouble = DrE("Importe").ToString.ToDouble And Dr("Tipo").ToString = DrE("Tipo").ToString And DdlCriterio.SelectedValue.ToEntero = 2)) And Not CBool(DrE("Seleccionado").ToString) And Not CBool(DrE("FueConciliado").ToString) And Not CBool(Dr("Seleccionado").ToString) Then
Dim FechaConciliado As Date = TxtFechaAplicado.Text.ToDate 'If(Dr("FechaDocumento").ToString.ToDate < txtFechaI.Text.ToDate, TxtFechaAplicado.Text.ToDate, Dr("FechaDocumento").ToString.ToDate)
If Not ObjBancos.UpdateConciliacionBancaria(Dr("CveIE").ToString.ToEntero, FechaConciliado, -1, 1, 1, UsuarioActual.CveUsuario) Or
Not ObjBancos.UpdateConciliacionBancaria(Dr("CveIE").ToString.ToEntero, FechaConciliado, DrE("CveIEEstadoCuenta").ToString.ToEntero, 1, 2, UsuarioActual.CveUsuario) Then
ErrorTrans = True
Else
If Not ObjOI.AddEventoBitacora("El pago ha sido conciliado", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=Dr("CveIE").ToString.ToEntero) Then
ErrorTrans = True
Else
DrE("Seleccionado") = True
Dr("Seleccionado") = True
HuboConciliacion = True
End If
End If
End If
Next
End If
Next
If Not ErrorTrans Then
ObjBancos.Commit()
Consulta()
ConsultaEdoConciliacion()
If HuboConciliacion Then
Alert("Coinciliadas Correctamente")
Else
Alert("No hubo Conciliaciones Automaticas", TipoMensaje.MsgAdvertencia)
End If
Else
ObjBancos.RollBack()
For Each Dr As DataRow In DtDatos.Rows
Dr("Seleccionado") = False
Next
For Each Dr As DataRow In DtDatosEdoCuenta.Rows
Dr("Seleccionado") = False
Next
End If
ObjBancos.Dispose()
ObjOI.Dispose()
End Sub
Protected Sub LnkConciliarManual_Click(sender As Object, e As EventArgs)
ModalidadConciliacion = "M"
If DdlCriterio.Items.FindByValue("2") Is Nothing Then DdlCriterio.Items.Add(New ListItem("Importe - Tipo Movimiento", "2"))
DdlCriterio.SelectedIndex = 0
DivCriterio.Visible = True
TxtFechaAplicado.Text = txtFechaI.Text
UpModalCriterio.Update()
RegistraScript("$('#DModalCriterio').modal()")
End Sub
Private Sub ConciliacionManual()
Dim SumaSIGAbono As Double = 0
Dim SumaSIGCargo As Double = 0
Dim SumaExcelAbono As Double = 0
Dim SumaExcelCargo As Double = 0
Dim Seleccionados As Integer = 0
Dim Fecha As Date
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.FCCheckBox("ChkConciliado").Checked And Gvr.FCCheckBox("ChkConciliado").Enabled Then
Seleccionados += 1
Fecha = Gvr.DataKey("FechaDocumento").ToDate
If Gvr.DataKey("Tipo") = "Cargo" Then
If Gvr.DataKey("Importe").ToDouble < 0 Then ' cuando es negativo suma para el abono
SumaSIGAbono += Math.Abs(Gvr.DataKey("Importe").ToDouble)
Else
SumaSIGCargo += Gvr.DataKey("Importe").ToDouble
End If
ElseIf Gvr.DataKey("Tipo") = "Abono" Then
If Gvr.DataKey("Importe").ToDouble < 0 Then ' cuando es negativo suma para el cargo
SumaSIGCargo += Math.Abs(Gvr.DataKey("Importe").ToDouble)
Else
SumaSIGAbono += Gvr.DataKey("Importe").ToDouble
End If
End If
End If
Next
If Seleccionados > 1 Then
Alert("Tiene que tener seleccionado solamente un movimiento.", TipoMensaje.MsgAdvertencia)
Exit Sub
ElseIf Not Seleccionados > 0 Then
Alert("Tiene que tener seleccionado .", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
For Each Gvr As GridViewRow In GvEdoConciliacion.Rows
If Gvr.FCCheckBox("ChkConciliado").Checked And Gvr.FCCheckBox("ChkConciliado").Enabled Then
If (Gvr.DataKey("FechaDocumento").ToDate = Fecha And DdlCriterio.SelectedValue.ToEntero = 1) Or DdlCriterio.SelectedValue.ToEntero = 2 Then
If Gvr.DataKey("Tipo") = "Cargo" Then
SumaExcelCargo += Gvr.DataKey("Importe").ToDouble
ElseIf Gvr.DataKey("Tipo") = "Abono" Then
SumaExcelAbono += Gvr.DataKey("Importe").ToDouble
End If
Else
Alert("Las fechas no coinciden.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
Next
If SumaSIGCargo <> SumaExcelCargo OrElse SumaSIGAbono <> SumaExcelAbono Then
Alert($"La suma de los importes no cuadran ({SumaSIGCargo}-{SumaExcelCargo}**{SumaSIGAbono}-{SumaExcelAbono})", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjBancos As New ClsBancos
Dim ObjOI As New ClsOIEventos(ObjBancos.IniciaTransacSQL())
Dim ErrorTrans As Boolean = False
Dim CveIE As Integer = 0
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.FCCheckBox("ChkConciliado").Checked And Gvr.FCCheckBox("ChkConciliado").Enabled Then
Dim FechaConciliado As Date = TxtFechaAplicado.Text.ToDate 'If(Gvr.DataKey("FechaDocumento").ToString.ToDate < txtFechaI.Text.ToDate, TxtFechaAplicado.Text.ToDate, Gvr.DataKey("FechaDocumento").ToString.ToDate)
If Not ObjBancos.UpdateConciliacionBancaria(Gvr.DataKey("CveIE").ToEntero, FechaConciliado, -1, 1, 1, UsuarioActual.CveUsuario) Then
ErrorTrans = True
Else
If Not ObjOI.AddEventoBitacora("El pago ha sido conciliado", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=Gvr.DataKey("CveIE").ToEntero) Then
ErrorTrans = True
Else
CveIE = Gvr.DataKey("CveIE").ToEntero
End If
End If
End If
Next
For Each Gvr As GridViewRow In GvEdoConciliacion.Rows
If Gvr.FCCheckBox("ChkConciliado").Checked And Gvr.FCCheckBox("ChkConciliado").Enabled Then
Dim FechaConciliado As Date = TxtFechaAplicado.Text.ToDate 'If(Gvr.DataKey("FechaDocumento").ToString.ToDate < txtFechaI.Text.ToDate, TxtFechaAplicado.Text.ToDate, Gvr.DataKey("FechaDocumento").ToString.ToDate)
If Not ObjBancos.UpdateConciliacionBancaria(CveIE, FechaConciliado, Gvr.DataKey("CveIEEstadoCuenta").ToEntero, 1, 2, UsuarioActual.CveUsuario) Then
'If Not ObjBancos.UpdateIEEstadoCuenta(Gvr.DataKey("CveIEEstadoCuenta").ToEntero, Gvr.DataKey("Importe").ToDouble, True, CveIE, Gvr.DataKey("Referencia").ToString,
' Gvr.DataKey("Tipo").ToString, Gvr.DataKey("FechaDocumento").ToDate, Gvr.DataKey("CveCuenta").ToEntero) Then
ErrorTrans = True
End If
End If
Next
If Not ErrorTrans Then
ObjBancos.Commit()
Consulta()
ConsultaEdoConciliacion()
Alert("Conciliados Correctamente")
Else
ObjBancos.RollBack()
End If
ObjBancos.Dispose()
ObjOI.Dispose()
End Sub
Protected Sub LnlConciliarAutomaticamente_Click(sender As Object, e As EventArgs)
ModalidadConciliacion = "A"
DdlCriterio.Items.Remove(DdlCriterio.Items.FindByValue("2"))
DivCriterio.Visible = True
TxtFechaAplicado.Text = txtFechaI.Text
UpModalCriterio.Update()
RegistraScript("$('#DModalCriterio').modal()")
End Sub
Protected Sub BtnConciliar_Click(sender As Object, e As EventArgs)
RegistraScript("$('#DModalCriterio').modal('hide')")
If ModalidadConciliacion = "A" Then
ConciliacionAutomatica()
ElseIf ModalidadConciliacion = "M" Then
ConciliacionManual()
ElseIf ModalidadConciliacion = "D" Then
ConciliacionDirecta()
End If
End Sub
Protected Sub LnbkConciliarDirectamente_Click(sender As Object, e As EventArgs)
ModalidadConciliacion = "D"
DdlCriterio.SelectedIndex = 0
DivCriterio.Visible = False
TxtFechaAplicado.Text = txtFechaI.Text
UpModalCriterio.Update()
RegistraScript("$('#DModalCriterio').modal()")
End Sub
Private Sub ConciliacionDirecta()
Dim ObjBancos As New ClsBancos
Dim ObjOI As New ClsOIEventos(ObjBancos.IniciaTransacSQL())
Dim ErrorTrans As Boolean = False
Dim Selecciono As Boolean = False
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.FCCheckBox("ChkConciliado").Checked And Gvr.FCCheckBox("ChkConciliado").Enabled Then
Selecciono = True
If Not ObjBancos.UpdateConciliacionBancaria(Gvr.DataKey("CveIE").ToEntero, If(Gvr.DataKey("FechaDocumento").ToString.ToDate < txtFechaI.Text.ToDate, TxtFechaAplicado.Text.ToDate, Gvr.DataKey("FechaDocumento").ToString.ToDate), -1, 1, 1, UsuarioActual.CveUsuario) Then
ErrorTrans = True
Else
If Not ObjOI.AddEventoBitacora("El pago ha sido conciliado", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=Gvr.DataKey("CveIE").ToEntero) Then
ErrorTrans = True
End If
End If
End If
Next
If Not ErrorTrans Then
ObjBancos.Commit()
If Selecciono Then
Consulta()
ConsultaEdoConciliacion()
Alert("Conciliados Correctamente")
Else
Alert("Tiene que tener al menos uno seleccionado.", TipoMensaje.MsgAdvertencia)
End If
Else
ObjBancos.RollBack()
End If
ObjBancos.Dispose()
ObjOI.Dispose()
End Sub
#End Region
#Region "DESCONCILIAR"
Protected Sub LnkDesconciliar_Click(sender As Object, e As EventArgs)
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
ModalidadDesconciliar = "D"
TxtFechaDesconciliado.Text = txtFechaF.Text
CveIEDesconciliar = gvRow.DataKey("CveIE").ToEntero
UpDesconciliar.Update()
RegistraScript("$('#DModalDesconciliar').modal()")
End Sub
Protected Sub LnkDesconciliarTodos_Click(sender As Object, e As EventArgs)
ModalidadDesconciliar = "DT"
TxtFechaDesconciliado.Text = NowADS().ToShortDateString
CveIEDesconciliar = 0
UpDesconciliar.Update()
RegistraScript("$('#DModalDesconciliar').modal()")
End Sub
Protected Sub BtnDesconciliar_Click(sender As Object, e As EventArgs)
Dim ObjBancos As New ClsBancos
Dim ObjOI As New ClsOIEventos(ObjBancos.IniciaTransacSQL())
Dim ErrorTrans As Boolean = False
If ModalidadDesconciliar = "D" Then
If ObjBancos.DesconciliarIE(CveIEDesconciliar, TxtFechaDesconciliado.Text.ToDate(), UsuarioActual.CveUsuario, ChkDejarConciliado.Checked) Then
If Not ObjOI.AddEventoBitacora("El pago ha sido desconciliado", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=CveIEDesconciliar) Then
ErrorTrans = True
End If
Else
ErrorTrans = True
End If
ElseIf ModalidadDesconciliar = "DT" Then
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.FCCheckBox("ChkConciliado").Checked And Not Gvr.FCCheckBox("ChkConciliado").Enabled Then
If Not ObjBancos.DesconciliarIE(Gvr.DataKey("CveIE").ToEntero, TxtFechaDesconciliado.Text.ToDate(), UsuarioActual.CveUsuario, ChkDejarConciliado.Checked) Then
ErrorTrans = True
Else
If Not ObjOI.AddEventoBitacora("El pago ha sido desconciliado", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveIE:=Gvr.DataKey("CveIE").ToEntero) Then
ErrorTrans = True
End If
End If
End If
Next
End If
If Not ErrorTrans Then
ObjBancos.Commit()
Alert("Desconciliado correctamente")
Consulta()
ConsultaEdoConciliacion()
RegistraScript("$('#DModalDesconciliar').modal('hide')")
Else
ObjBancos.RollBack()
End If
ObjBancos.Dispose()
ObjOI.Dispose()
End Sub
#End Region
#Region "GRIDVIEW"
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 0 Then
e.Row.CssClass = "Totales"
e.Row.Cells(0).Text = "Total"
Else
e.Row.Attributes.Add("data-cveie", e.Row.DBCampo("CveIE"))
e.Row.FCCheckBox("ChkConciliado").Attributes.Add("onclick", "CalculaSeleccionados();")
If Not e.Row.DBCampo("Cargo").ToDouble <> 0 Then
e.Row.Cells(4).Text = ""
End If
If Not e.Row.DBCampo("Abono").ToDouble <> 0 Then
e.Row.Cells(5).Text = ""
End If
If CBool(e.Row.DBCampo("FueConciliado").ToString) Then
e.Row.FCLinkButton("LnkDesconciliar").Visible = True
e.Row.FCLinkButton("LnkVerVinculadosIE").Visible = True
End If
End If
End If
End Sub
Protected Sub GvEdoConciliacion_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex = 0 Then
e.Row.CssClass = "Totales"
e.Row.Cells(0).Text = "Total"
Else
e.Row.Attributes.Add("data-cveie", e.Row.DBCampo("CveIE"))
e.Row.FCCheckBox("ChkConciliado").Attributes.Add("onclick", "CalculaSeleccionadosEdoCuenta();")
If Not e.Row.DBCampo("Cargo").ToDouble > 0 Then
e.Row.Cells(3).Text = ""
End If
If Not e.Row.DBCampo("Abono").ToDouble > 0 Then
e.Row.Cells(4).Text = ""
End If
If CBool(e.Row.DBCampo("FueConciliado").ToString) Then
e.Row.FCLinkButton("LnkDesconciliarEdoConciliacion").Visible = True
e.Row.FCLinkButton("LnkVerVinculadosIEEstadoCuenta").Visible = True
End If
End If
End If
End Sub
Protected Sub LnkVerVinculadosIEEstadoCuenta_Click(sender As Object, e As EventArgs)
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
If gvRow.DataKey("CveIE").ToEntero > 0 Then
Dim ObjBancos As New ClsBancos
If ObjBancos.GetBancosIE(gvRow.DataKey("CveIE").ToEntero, UsuarioActual.CveEmpresa) Then
If ObjBancos.DtResultados.Rows.Count > 0 Then
Dim Dr As DataRow = ObjBancos.DtResultados.Rows(0)
LblTituloObservaciones.Text = "Observaciones"
DivFolio.Visible = True
HlFolio.Text = Dr("Folio").ToString
HlFolio.NavigateUrl = $"/Bancos/IE.aspx?CveIE={gvRow.DataKey("CveIE").ToString}"
LblFecha.Text = Dr("FechaDocumento").ToString.ToDate.ToShortDateString
LblObservaciones.Text = Dr("Observaciones").ToString
LblTipo.Text = Dr("Tipo").ToString
LblImporte.Text = Dr("Importe").ToString.FormatoNumero
UpModalVinculado.Update()
RegistraScript("$('#DModalVinculado').modal()")
End If
End If
ObjBancos.Dispose()
End If
GvEdoConciliacion.DataSource = DtDatosEdoCuenta
GvEdoConciliacion.DataBind()
End Sub
Protected Sub LnkVerVinculadosIE_Click(sender As Object, e As EventArgs)
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
If gvRow.DataKey("CveIEEstadoCuenta").ToEntero > 0 Then
Dim ObjBancos As New ClsBancos
If ObjBancos.GetIEEstadoCuenta(gvRow.DataKey("CveIEEstadoCuenta").ToEntero, MinFecha, MaxFecha, 1, -1, UsuarioActual.CveEmpresa) Then
If ObjBancos.DtResultados.Rows.Count > 1 Then
Dim Dr As DataRow = ObjBancos.DtResultados.Rows(1)
LblTituloObservaciones.Text = "Referencia"
DivFolio.Visible = False
LblFecha.Text = Dr("FechaDocumento").ToString.ToDate.ToShortDateString
LblObservaciones.Text = Dr("Referencia").ToString
LblTipo.Text = Dr("Tipo").ToString
LblImporte.Text = Dr("Importe").ToString.FormatoNumero
UpModalVinculado.Update()
RegistraScript("$('#DModalVinculado').modal()")
End If
End If
ObjBancos.Dispose()
End If
GvDatos.DataSource = DtDatos
GvDatos.DataBind()
End Sub
#End Region
#Region "IMPRESIONES"
Protected Sub LnkPdf_Click(sender As Object, e As EventArgs)
Formato = "PDF"
RegistraScript("$('#DModalSaldoFinalEdoCuenta').modal()")
End Sub
Protected Sub LnkExportar_Click(sender As Object, e As EventArgs)
Formato = "EXCEL"
RegistraScript("$('#DModalSaldoFinalEdoCuenta').modal()")
End Sub
Protected Sub BtnGenerarImpresion_Click(sender As Object, e As EventArgs)
RegistraScript("$('#DModalSaldoFinalEdoCuenta').modal('hide')")
GeneraPDF(Formato)
End Sub
Protected Sub GeneraPDF(Formato As String)
Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
Dim params As New List(Of ReportParameter)()
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
params.Add(New ReportParameter("FechaImpresion", NowADS().ToString()))
Dim FormatoFecha As DateTimeFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat
Dim NombreMes As String = FormatoFecha.GetMonthName(txtFechaI.Text.ToDate.Month).ToUpper
params.Add(New ReportParameter("Encabezado", $"{DdlCuenta.SelectedItem.Text} {NombreMes} {txtFechaI.Text.ToDate.Year}"))
Dim Dt1 As New DataTable
Dt1 = DtDatos.FiltraParametros($"FueConciliado = 0 And Tipo = 'Abono'")
Dim TotalDt1 As Decimal = Dt1.SUMD("Importe")
Dim Row1 As DataRow = Dt1.NewRow
Row1("Importe") = TotalDt1
Row1("Folio") = "Total"
Dt1.Rows.InsertAt(Row1, 0)
Dt1.AcceptChanges()
Dim Dt2 As New DataTable
Dt2 = DtDatosEdoCuenta.FiltraParametros($"FueConciliado = 0 And Tipo = 'Abono'")
Dim TotalDt2 As Decimal = Dt2.SUMD("Importe")
Dim Row2 As DataRow = Dt2.NewRow
Row2("Importe") = TotalDt2
Row2("Folio") = "Total"
Dt2.Rows.InsertAt(Row2, 0)
Dt2.AcceptChanges()
Dim Dt3 As New DataTable
Dt3 = DtDatos.FiltraParametros($"FueConciliado = 0 And Tipo = 'Cargo'")
Dim TotalDt3 As Decimal = Dt3.SUMD("Importe")
Dim Row3 As DataRow = Dt3.NewRow
Row3("Importe") = TotalDt3
Row3("Folio") = "Total"
Dt3.Rows.InsertAt(Row3, 0)
Dt3.AcceptChanges()
Dim Dt4 As New DataTable
Dt4 = DtDatosEdoCuenta.FiltraParametros($"FueConciliado = 0 And Tipo = 'Cargo'")
Dim TotalDt4 As Decimal = Dt4.SUMD("Importe")
Dim Row4 As DataRow = Dt4.NewRow
Row4("Importe") = TotalDt4
Row4("Folio") = "Total"
Dt4.Rows.InsertAt(Row4, 0)
Dt4.AcceptChanges()
Dim lrds As List(Of ReportDataSource) = New List(Of ReportDataSource)()
Dim rds As ReportDataSource = New ReportDataSource()
rds.Name = "DataSet1"
rds.Value = Dt1
Dim rds2 As ReportDataSource = New ReportDataSource()
rds2.Name = "DataSet2"
rds2.Value = Dt2
Dim rds3 As ReportDataSource = New ReportDataSource()
rds3.Name = "DataSet3"
rds3.Value = Dt3
Dim rds4 As ReportDataSource = New ReportDataSource()
rds4.Name = "DataSet4"
rds4.Value = Dt4
lrds.Add(rds)
lrds.Add(rds2)
lrds.Add(rds3)
lrds.Add(rds4)
params.Add(New ReportParameter("SaldoFinalEstadoCuenta", (TxtSaldoFinal.Text.FormatoNumero)))
Dim SaldoFinalLibros As Decimal = (TxtSaldoFinal.Text.ToDecimal - TotalDt1 + TotalDt2 + TotalDt3 - TotalDt4)
params.Add(New ReportParameter("SaldoFinalLibros", SaldoFinalLibros.FormatoNumero))
Dim SaldoFinalContabilidad As Double = 0
Dim SaldoFinalContabilidadComplementaria As Double = 0
If DdlCuenta.SelectedValue.ToEntero > 0 Then
Dim CveCuenta As Integer = 0
Dim CveCuentaComplementaria As Integer = 0
Dim CveMoneda As Integer = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros($"CveCuenta = {DdlCuenta.SelectedValue}").Rows(0)("CveMoneda").ToString.ToEntero
Dim ObjConta As New ClsContabilidad
If ObjConta.GetCuentasAsignaciones(UsuarioActual.CveEmpresa) Then
CveCuenta = ObjConta.DtResultados.FiltroPrimeroValor("CveCuenta", $"CveConceptoContable = 30 AND CveBancoCuenta = {DdlCuenta.SelectedValue}").ToEntero
If CveMoneda > 1 Then
CveCuentaComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("CveCuenta", $"CveConceptoContable = 204 AND CveBancoCuenta = {DdlCuenta.SelectedValue}").ToEntero
End If
End If
If CveCuenta > 0 Then
If ObjConta.GetMovimientosAuxiliaresCatalogo(CveCuenta, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, CveMoneda, -1, -1, UsuarioActual.CveEmpresa, "1", -1) Then
If ObjConta.DtResultados.Rows.Count > 1 Then
SaldoFinalContabilidad = ObjConta.DtResultados.Rows(1)("SaldoActual").ToString.ToDouble
End If
End If
End If
If CveCuentaComplementaria > 0 Then
If ObjConta.GetMovimientosAuxiliaresCatalogo(CveCuentaComplementaria, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, CveMoneda, -1, -1, UsuarioActual.CveEmpresa, "1", -1) Then
If ObjConta.DtResultados.Rows.Count > 1 Then
SaldoFinalContabilidadComplementaria = ObjConta.DtResultados.Rows(1)("SaldoActual").ToString.ToDouble
End If
End If
End If
ObjConta.Dispose()
End If
Dim Filtros As String = String.Format("<b>Cuenta: </b>{0}&emsp;<b>Conciliado: </b>{1}&emsp;<b>Fecha Inicial: </b>{2}&emsp;<b>Fecha Final: </b>{3}", DdlCuenta.SelectedItem.Text, DdlConciliado.SelectedItem.Text, txtFechaI.Text, txtFechaF.Text)
params.Add(New ReportParameter("SaldoFinalContabilidad", (SaldoFinalContabilidad.FormatoNumero)))
params.Add(New ReportParameter("SaldoFinalContabilidadComplementaria", (SaldoFinalContabilidadComplementaria.FormatoNumero)))
params.Add(New ReportParameter("Diferencia", (SaldoFinalLibros - SaldoFinalContabilidad).FormatoNumero))
params.Add(New ReportParameter("Filtros", Filtros))
params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", "")))
Dim Archivo As String = $"{UsuarioActual.Empresa.Ruta}Formatos/Conciliacion.rdlc"
If Not IO.File.Exists(Archivo) Then
Archivo = "Empresas/Grales/Formatos/Conciliacion.rdlc"
End If
ImprimirPDF(Archivo, lrds, params, $"Conciliacion Bancaria {NombreMes} {txtFechaI.Text.ToDate.Year}", Formato)
End Sub
#End Region
End Class