Soporte en compras para actualizar contabilizados. Cambiar cargar contratos a gem box. Soporte en Ventas que no se pueda ingresar productos de diferente moneda.
325 lines
13 KiB
VB.net
325 lines
13 KiB
VB.net
Option Strict On
|
|
Option Explicit On
|
|
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
Imports System.Xml
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports GemBox.Spreadsheet
|
|
|
|
Partial Class Bancos_CargarConciliacionesBancarias
|
|
Inherits ClsPaginas
|
|
|
|
#Region "PROPIEDADES"
|
|
|
|
Private Property Modalidad As String
|
|
Get
|
|
Return CType(ViewState("Modalidad"), String)
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("Modalidad") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveIEEstadoCuenta As Integer
|
|
Get
|
|
Return CType(ViewState("CveIEEstadoCuenta"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveIEEstadoCuenta") = 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 / CONSULTA"
|
|
|
|
Private Sub InicializaValores()
|
|
'Cargar Cuentas
|
|
DdlCuenta.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario)
|
|
DdlCuenta.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
DdlCuenta.DataBind()
|
|
|
|
DdlCuentaModal.DataSource = GlobalDTBancosCuentas(UsuarioActual.CveUsuario)
|
|
DdlCuentaModal.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
DdlCuentaModal.DataBind()
|
|
|
|
txtFechaI.Text = Now.FirstDayOfMonth.ToShortDateString
|
|
txtFechaF.Text = Now.ToShortDateString
|
|
|
|
Modalidad = ""
|
|
End Sub
|
|
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
ConsultaEstadoCuentaBancaria()
|
|
End Sub
|
|
|
|
Private Sub ConsultaEstadoCuentaBancaria()
|
|
Dim ObjBancos As New ClsBancos
|
|
If ObjBancos.GetIEEstadoCuenta(-1, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, DdlConciliado.SelectedValue.ToEntero,
|
|
DdlCuenta.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
GvEstadoCuentaBancaria.DataSource = ObjBancos.DtResultados
|
|
End If
|
|
ObjBancos.Dispose()
|
|
GvEstadoCuentaBancaria.DataBind()
|
|
UpEstadoCuentaBancaria.Update()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "CARGA EXCEL"
|
|
|
|
Protected Sub BtnCargaExcel_Click(sender As Object, e As EventArgs)
|
|
If TxtExcel.getfiles().Archivos.Count > 0 Then
|
|
Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
|
|
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch
|
|
Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV")
|
|
CargaExcel(Directorio, file.filename, Tipo)
|
|
Else
|
|
Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable
|
|
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
|
|
Dim excelFile As ExcelFile = ExcelFile.Load(flatFilePath)
|
|
|
|
Dim unnamed As Integer = 0
|
|
Dim cols As Integer
|
|
Dim columns As String()
|
|
Dim curRow As Integer = 0
|
|
Dim curCol As Integer = 0
|
|
Dim dataTable As DataTable = New DataTable()
|
|
Dim worksheet As ExcelWorksheet = excelFile.Worksheets(0)
|
|
|
|
For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1
|
|
|
|
If firstRowHasHeaders Then
|
|
|
|
If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then
|
|
dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString())
|
|
Else
|
|
dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed)))
|
|
End If
|
|
|
|
curRow = 1
|
|
Else
|
|
dataTable.Columns.Add("Column " & (cols + 1))
|
|
End If
|
|
Next
|
|
|
|
While curRow < worksheet.Rows.Count
|
|
columns = New String(cols - 1) {}
|
|
|
|
For curCol = 0 To cols - 1
|
|
|
|
If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then
|
|
columns(curCol) = ""
|
|
Else
|
|
columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString()
|
|
End If
|
|
Next
|
|
|
|
dataTable.Rows.Add(columns)
|
|
curRow += 1
|
|
End While
|
|
|
|
Return dataTable
|
|
End Function
|
|
|
|
Private Sub CargaExcel(Ruta As String, FileName As String, Tipo As String)
|
|
If Not DdlCuenta.SelectedValue.ToEntero > 0 Then
|
|
Alert("Tiene que seleccionar una cuenta", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
Dim dt As New DataTable
|
|
dt = ReadExcelFile(Ruta + FileName, True)
|
|
'Dim Conexion As Odbc.OdbcConnection = Nothing
|
|
'Dim ErrorArchivo = False
|
|
'Dim ErrorExcel = False
|
|
'Dim strConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Ruta + FileName + ";Extended Properties=Excel 8.0;"
|
|
'Dim objDbFactory As Common.DbProviderFactory = Common.DbProviderFactories.GetFactory("System.Data.OleDb")
|
|
'Dim objDbAdapter As Common.DbDataAdapter = objDbFactory.CreateDataAdapter()
|
|
'Dim objDbConnection As Common.DbConnection = objDbFactory.CreateConnection()
|
|
'objDbConnection.ConnectionString = strConnString
|
|
'objDbConnection.Open()
|
|
'Dim objSheetNames As DataTable = objDbConnection.GetSchema("Tables")
|
|
'Dim HojaExcel As String = objSheetNames.FiltroPrimeroValor("TABLE_NAME")
|
|
'Try
|
|
' Select Case Tipo
|
|
' Case "CSV"
|
|
' Conexion = New Odbc.OdbcConnection("Driver={Microsoft Access Text Driver (*.txt, *.csv)};Dbq=" + Ruta + ";Extensions=asc,csv,tab,txt;")
|
|
' Conexion.Open()
|
|
' Dim cmd = Conexion.CreateCommand()
|
|
' cmd.CommandType = CommandType.Text
|
|
' cmd.CommandText = $"SELECT * FROM [{FileName}]"
|
|
' Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd)
|
|
' DataAdapter.Fill(dt)
|
|
' Case "EXCEL"
|
|
' Conexion = New Odbc.OdbcConnection("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + Ruta + FileName + ";")
|
|
' Conexion.Open()
|
|
' Dim cmd = Conexion.CreateCommand()
|
|
' cmd.CommandType = CommandType.Text
|
|
' cmd.CommandText = $"SELECT * FROM [{HojaExcel}]"
|
|
' Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd)
|
|
' DataAdapter.Fill(dt)
|
|
' Case Else
|
|
' Alert("El archivo no tiene el formato correcto", TipoMensaje.MsgError)
|
|
' Exit Sub
|
|
' End Select
|
|
'Catch ex As Exception
|
|
' ErrorArchivo = True
|
|
' OnError("Ocurrio un error al leer el archivo <br/>" & ex.Message, ex)
|
|
'End Try
|
|
'Conexion.Close()
|
|
If dt IsNot Nothing Then
|
|
dt.Columns(0).ColumnName = "FechaDocumento"
|
|
dt.Columns(1).ColumnName = "Referencia"
|
|
dt.Columns(2).ColumnName = "Importe"
|
|
dt.Columns(3).ColumnName = "Cargo"
|
|
dt.Columns(4).ColumnName = "Abono"
|
|
dt.Columns.Add("FueConciliado")
|
|
dt.Columns.Add("Tipo")
|
|
For Each Dr As DataRow In dt.Rows
|
|
If Dr("Abono").ToString.ToDouble > 0 Then
|
|
Dr("Importe") = Dr("Abono").ToString.FormatoNumero
|
|
Dr("Tipo") = "Abono"
|
|
Dr("Cargo") = 0
|
|
ElseIf Dr("Cargo").ToString.ToDouble > 0 Then
|
|
Dr("Importe") = Dr("Cargo").ToString.FormatoNumero
|
|
Dr("Tipo") = "Cargo"
|
|
Dr("Abono") = 0
|
|
End If
|
|
Next
|
|
Dim ObjBancos As New ClsBancos
|
|
Dim ErrorTrans As Boolean = False
|
|
For Each Dr As DataRow In dt.Rows
|
|
If Dr("Importe").ToString.ToDouble > 0 Then
|
|
If Not ObjBancos.AddIEEstadoCuenta(Dr("Referencia").ToString, Dr("FechaDocumento").ToString.ToDate,
|
|
Dr("Importe").ToString.ToDouble, DdlCuenta.SelectedValue.ToEntero,
|
|
UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, Dr("Tipo").ToString) Then
|
|
ErrorTrans = True
|
|
End If
|
|
End If
|
|
Next
|
|
If Not ErrorTrans Then
|
|
ObjBancos.Commit()
|
|
ConsultaEstadoCuentaBancaria()
|
|
RegistraScript("$('#DivCargaExcel').modal('hide')")
|
|
Alert("Cargado Correctamente")
|
|
Else
|
|
ObjBancos.RollBack()
|
|
End If
|
|
ObjBancos.Dispose()
|
|
Else
|
|
Alert("Hubo un error al intentar leer el archivo.", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "AGREGAR / EDITAR / ELIMINAR MOVIMIENTOS"
|
|
|
|
Protected Sub LnkEditar_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
Modalidad = "U"
|
|
CveIEEstadoCuenta = gvRow.DataKey("CveIEEstadoCuenta").ToEntero
|
|
TxtReferencia.Text = gvRow.DataKey("Referencia").ToString
|
|
TxtFecha.Text = gvRow.DataKey("FechaDocumento").ToDate.ToShortDateString
|
|
TxtImporte.Text = gvRow.DataKey("Importe").ToString
|
|
DdlTipo.SelectedValueExist(gvRow.DataKey("Tipo").ToString)
|
|
DdlCuentaModal.SelectedValueExist(gvRow.DataKey("CveCuenta").ToString)
|
|
BtnGuardarModal.Text = "Actualizar"
|
|
UPModalEditar.Update()
|
|
RegistraScript("$('#DModalEditar').modal()")
|
|
End Sub
|
|
|
|
Protected Sub BtnGuardarModal_Click(sender As Object, e As EventArgs)
|
|
Dim ObjBancos As New ClsBancos
|
|
If Modalidad = "A" Then
|
|
If ObjBancos.AddIEEstadoCuenta(TxtReferencia.Text, TxtFecha.Text.ToDate, TxtImporte.Text.ToDouble, DdlCuentaModal.SelectedValue.ToEntero,
|
|
UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, DdlTipo.SelectedValue) Then
|
|
ConsultaEstadoCuentaBancaria()
|
|
Alert("Guardado Correctamente.", TipoMensaje.MsgInformacion, "1")
|
|
RegistraScript("$('#DModalEditar').modal('hide')", "2")
|
|
End If
|
|
ElseIf Modalidad = "U" Then
|
|
If ObjBancos.UpdateIEEstadoCuenta(CveIEEstadoCuenta, TxtImporte.Text.ToDouble, False, -1, TxtReferencia.Text,
|
|
DdlTipo.SelectedValue, TxtFecha.Text.ToDate, DdlCuentaModal.SelectedValue.ToEntero) Then
|
|
ConsultaEstadoCuentaBancaria()
|
|
Alert("Actualizado Correctamente.", TipoMensaje.MsgInformacion, "1")
|
|
RegistraScript("$('#DModalEditar').modal('hide')", "2")
|
|
End If
|
|
End If
|
|
ObjBancos.Dispose()
|
|
End Sub
|
|
Protected Sub LnkEliminar_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
Dim ObjBancos As New ClsBancos
|
|
If ObjBancos.RemoveIEEstadoCuenta(gvRow.DataKey("CveIEEstadoCuenta").ToEntero) Then
|
|
Alert("Eliminado Correctamente.")
|
|
ConsultaEstadoCuentaBancaria()
|
|
End If
|
|
ObjBancos.Dispose()
|
|
End Sub
|
|
Protected Sub LnkAgregarMovimiento_Click(sender As Object, e As EventArgs)
|
|
Modalidad = "A"
|
|
TxtReferencia.Text = ""
|
|
TxtFecha.Text = Now.ToShortDateString
|
|
TxtImporte.Text = ""
|
|
DdlTipo.SelectedIndex = 0
|
|
DdlCuentaModal.SelectedIndex = 0
|
|
BtnGuardarModal.Text = "Guardar"
|
|
UPModalEditar.Update()
|
|
RegistraScript("$('#DModalEditar').modal()")
|
|
End Sub
|
|
|
|
Protected Sub LnkEliminarMovimientos_Click(sender As Object, e As EventArgs)
|
|
Dim ObjBancos As New ClsBancos
|
|
ObjBancos.IniciaTransacSQL()
|
|
Dim ErrorTrans As Boolean = False
|
|
For Each Gvr As GridViewRow In GvEstadoCuentaBancaria.Rows
|
|
If Not CBool(Gvr.DataKey("FueConciliado")) Then
|
|
If Not ObjBancos.RemoveIEEstadoCuenta(Gvr.DataKey("CveIEEstadoCuenta").ToEntero) Then
|
|
ErrorTrans = True
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
If Not ErrorTrans Then
|
|
ObjBancos.Commit()
|
|
Alert("Eliminado Correctamente.")
|
|
ConsultaEstadoCuentaBancaria()
|
|
Else
|
|
ObjBancos.RollBack()
|
|
End If
|
|
ObjBancos.Dispose()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "GRIDVIEW"
|
|
|
|
Protected Sub GvEstadoCuentaBancaria_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"
|
|
ElseIf Not CBool(e.Row.DBCampo("FueConciliado")) Then
|
|
e.Row.FCLinkButton("LnkEditar").Visible = True
|
|
e.Row.FCLinkButton("LnkEliminar").Visible = True
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
End Class
|