Files
SIG/Bancos/Transferencias.aspx.vb
2023-09-08 10:51:52 -07:00

716 lines
35 KiB
VB.net

Imports System.IO
Imports Extensiones
Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel.Design
Partial Class Bancos_Transferencias
Inherits ClsPaginas
#Region "Propiedades"
Private Property DtCuentas As DataTable
Get
Return CType(ViewState("DtCuentas"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtCuentas") = value
End Set
End Property
Private Property Opcion As Integer
Get
Return ViewState("Opcion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("Opcion") = value
End Set
End Property
Private Property tCveMonedaOrigen As Integer
Get
Return ViewState("tCveMonedaOrigen").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("tCveMonedaOrigen") = value
End Set
End Property
Private Property tCveMonedaDestino As Integer
Get
Return ViewState("tCveMonedaDestino").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("tCveMonedaDestino") = 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
tCveMonedaOrigen = 0
tCveMonedaDestino = 0
If Request("OPC") IsNot Nothing AndAlso IsNumeric(Request("OPC")) Then
Opcion = Request("OPC").ToEntero
Else
Opcion = -1
End If
DtCuentas = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa)
If Opcion = 1 Then
LtlTitulo.Text = "Domicialización de tarjeta"
RBLOpcion.Visible = True
TrCuentaOrigen.Visible = False
chkMovimientoTarjeta.Checked = True
chkMovimientoTarjeta.Enabled = False
chkMovimientoTarjeta_CheckedChanged(Nothing, Nothing)
CargaCuenta(-1, DdlCuentaDestino)
CargaFolio(DdlCuentaDestino.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
Else
CargaCuenta(-1, DdlCuentaOrigen)
CargaCuenta(DdlCuentaOrigen.SelectedValue.ToEntero, DdlCuentaDestino)
CargaFolio(DdlCuentaOrigen.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
End If
TxtFechaDocumento.Text = Now.ToShortDateString
DdlTipoMovto_SelectedIndexChanged(Nothing, Nothing)
End If
End Sub
Private Sub CargaCuenta(CveCuenta As Integer, Ddl As DropDownList)
Ddl.Items.Clear()
If UsuarioActual.CveEmpresa = 119 Then
Ddl.DataSource = DtCuentas
Else
Ddl.DataSource = DtCuentas.FiltraParametros(String.Format("CveCuenta <> {0}", CveCuenta))
End If
Ddl.DataBind()
DdlCuentaDestino_SelectedIndexChanged(Nothing, Nothing)
If CveCuenta > 0 Then VerificaMonedas()
End Sub
Private Sub VerificaMonedas()
'si es la destino verifico si la moneda es la misma, sino pregunto por la paridad cambiaria
Dim drOrigen As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta = {0}", DdlCuentaOrigen.SelectedValue.ToEntero))
Dim drDestino As DataRow = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta = {0}", DdlCuentaDestino.SelectedValue.ToEntero))
'Dim tCveMonedaOrigen, tCveMonedaDestino As Integer
If drOrigen IsNot Nothing AndAlso drDestino IsNot Nothing Then
tCveMonedaOrigen = drOrigen("CveMoneda").ToString.ToEntero
tCveMonedaDestino = drDestino("CveMoneda").ToString.ToEntero
End If
If drOrigen IsNot Nothing AndAlso drDestino IsNot Nothing AndAlso drOrigen("CveMoneda").ToString <> drDestino("CveMoneda").ToString Then
If tCveMonedaOrigen = 1 AndAlso tCveMonedaDestino <> 1 Then
'pesos a otra moneda se divide
TxtTipoCambio.Attributes.Add("onkeyup", "$get('HdnTC').value='2'; Calcula();")
RegistraScript("$get('TrTC').style.display=''; $get('HdnTC').value='2'; Calcula();")
ElseIf tCveMonedaOrigen <> 1 AndAlso tCveMonedaDestino = 1 Then
'de otra moneda a pesos se multiplica
TxtTipoCambio.Attributes.Add("onkeyup", "$get('HdnTC').value='1'; Calcula();")
RegistraScript("$get('TrTC').style.display=''; $get('HdnTC').value='1'; Calcula();")
End If
PnlTipoCambio.Visible = True
'RegistraScript("$get('TrTC').style.display='';")
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
TxtTipoCambio.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
Else
PnlTipoCambio.Visible = False
RegistraScript("$get('TrTC').style.display='none';")
TxtFechaDocumento.Attributes.Remove("onchange")
End If
If drOrigen IsNot Nothing AndAlso drDestino IsNot Nothing AndAlso tCveMonedaOrigen = 2 OrElse tCveMonedaDestino = 2 Then
PnlTipoCambio.Visible = True
RegistraScript("$get('TrTC').style.display='';")
TxtFechaDocumento.Attributes.Add("onchange", "CambiaTC(this);")
TxtTipoCambio.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
End If
End Sub
Protected Sub DdlCuentaOrigen_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuentaOrigen.SelectedIndexChanged
CargaFolio(DdlCuentaOrigen.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
CargaCuenta(DdlCuentaOrigen.SelectedValue.ToEntero, DdlCuentaDestino)
If DdlCuentaOrigen.SelectedValue.ToEntero() > 0 Then
If DtCuentas.FiltroPrimeroValor("CveTipoCuenta", String.Format("CveCuenta = {0}", DdlCuentaOrigen.SelectedValue)) = "1" Then
CargaMovimientosCajaChica()
TrCajaChica.Visible = True
Else
DdlCajaChica.DataSource = Nothing
DdlCajaChica.DataBind()
TrCajaChica.Visible = False
End If
End If
End Sub
Protected Sub DdlCuentaDestino_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlCuentaDestino.SelectedIndexChanged
VerificaMonedas()
If Opcion = 1 Then
CargaFolio(DdlCuentaDestino.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
End If
If chkMovimientoTarjeta.Checked AndAlso GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveCuenta = {0} AND UsaTarjeta = 1", DdlCuentaDestino.SelectedValue.ToEntero)).Rows.Count > 0 Then
CargaGridTarjetas()
Else
GvTC.Visible = False
End If
End Sub
Private Sub CargaGridTarjetas()
Dim ObjCreditos As New ClsBancos
If ObjCreditos.GetTarjetasCreditos(DdlCuentaDestino.SelectedValue.ToEntero) Then
If ObjCreditos.DtResultados.Rows.Count > 0 Then
GvTC.DataSource = ObjCreditos.DtResultados
End If
GvTC.DataBind()
UpGvTC.Update()
GvTC.Visible = True
End If
ObjCreditos.Dispose()
End Sub
Protected Sub BtnGuardar_Click(sender As Object, e As System.EventArgs) Handles BtnGuardar.Click
'VALIDACIONES
Dim SumaImportesTarjeta As Decimal = 0D
If GvTC.Visible Then
For Each row As GridViewRow In GvTC.Rows
SumaImportesTarjeta += row.FCTextBox("TxtAbono").Text.ToDecimal
Next
If TxtImporte.Text.ToDouble <> SumaImportesTarjeta Then
Alert("Las Cantidades a Abonar no Coinciden con el Importe a Transferir", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
If DdlCuentaDestino.SelectedValue = "" Then
Alert("Seleccione cuenta destino", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If TxtImporte.Text.ToDouble <= 0 Then
Alert("Debe ingresar un importe", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If TxtTipoCambio.Visible AndAlso TxtTipoCambio.Text.ToDouble <= 0 Then
Alert("Debe ingresar el tipo de cambio", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim MsgError As String = ""
Dim ImporteDestino As Decimal = TxtImporte.Text.Trim.ToDecimal
Dim ImporteMXOrigen As Decimal = TxtImporte.Text.Trim.ToDecimal
Dim ImporteMXDestino As Decimal = TxtImporte.Text.Trim.ToDecimal
Dim ObjIE As New ClsBancos()
Dim ObjMov As New ClsContabilidad(ObjIE.IniciaTransacSQL)
'Dim ObjComp As New ClsCompras(ObjIE.IniciaTransacSQL)
Dim TipoCambio As Double = If(TxtTipoCambio.Visible, TxtTipoCambio.Text.ToDecimal, 0)
Dim CveMonedaOrigen, CveMonedaDestino As Integer
Dim FolioOrigen As String = TxtFolio.Text.Trim
Dim FolioDestino As String = GetFolio(DdlCuentaDestino.SelectedValue.ToEntero, If(DdlTipoMovto.SelectedValue = "2", 8, 3))
Dim CveIE As Integer
Dim CveIEDestino As Integer
Dim CuentaDestino As String = ""
Dim Observaciones As String = ""
Dim dr As DataRow
Dim AlertaGlobal As New StringBuilder
'COMPROBANTE
Dim filesgral As List(Of Archivo) = Anexo.getfiles().Archivos
Dim filemove As String = ""
Dim Comprobante As String = ""
For Each fileItem As Archivo In filesgral
Comprobante = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "")
filemove = fileItem.filename
Next
dr = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta={0}", DdlCuentaDestino.SelectedValue))
If dr IsNot Nothing Then CveMonedaDestino = dr("CveMoneda").ToString.ToEntero
If Opcion = -1 Then
dr = GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveCuenta={0}", DdlCuentaOrigen.SelectedValue))
If dr IsNot Nothing Then CveMonedaOrigen = dr("CveMoneda").ToString.ToEntero
Else
CveMonedaOrigen = CveMonedaDestino
End If
If CveMonedaOrigen = 1 AndAlso CveMonedaDestino <> 1 Then
'pesos a otra moneda se divide
ImporteDestino = Math.Round(TxtImporte.Text.Trim.ToDecimal / TxtTipoCambio.Text.ToDecimal, 2)
ImporteMXDestino = TxtImporte.Text.Trim.ToDecimal
ElseIf CveMonedaOrigen <> 1 AndAlso CveMonedaDestino = 1 Then
'de otra moneda a pesos se multiplica
ImporteDestino = Math.Round(TxtImporte.Text.Trim.ToDecimal * TxtTipoCambio.Text.ToDecimal, 2)
ImporteMXDestino = Math.Round(TxtImporte.Text.Trim.ToDecimal * TxtTipoCambio.Text.ToDecimal, 2)
ImporteMXOrigen = Math.Round(TxtImporte.Text.Trim.ToDecimal * TxtTipoCambio.Text.ToDecimal, 2)
ElseIf CveMonedaOrigen <> 1 AndAlso CveMonedaDestino <> 1 Then
ImporteMXDestino = Math.Round(TxtImporte.Text.Trim.ToDecimal * TxtTipoCambio.Text.ToDecimal, 2)
ImporteMXOrigen = Math.Round(TxtImporte.Text.Trim.ToDecimal * TxtTipoCambio.Text.ToDecimal, 2)
End If
If CveMonedaOrigen = 2 AndAlso CveMonedaDestino = 2 Then
TipoCambio = TxtTipoCambio.Text.ToDouble 'GlobalTipoCambio(TxtFechaDocumento.Text.ToDate)
End If
Dim CvePrePoliza As Integer = ObjMov.AddPrePolizas("Bancos/Transferencias", 13, TxtImporte.Text.Trim.ToDouble, TxtImporte.Text.Trim.ToDouble, CveMonedaOrigen, TxtFechaDocumento.Text.ToDate, $"Transferencia entre cuentas {TxtObservaciones.Text}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If UsuarioActual.CveEmpresa = 48 Then
CuentaDestino = "Alumbrado publico de Hermosillo S.A de C.V"
Observaciones = String.Format("{0} {1}", DdlCuentaDestino.SelectedItem.Text, TxtObservaciones.Text.Trim)
Else
CuentaDestino = String.Format("Transferencia Cta: {0}", DdlCuentaDestino.SelectedItem.Text)
Observaciones = TxtObservaciones.Text.Trim
End If
If Opcion = 1 Then 'ESTO ES TRANSFERENCIA ENTRE
CveIE = ObjIE.AddBancos_IE(DdlCuentaDestino.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero, TxtFechaDocumento.Text.Trim.ToDate, TxtFolio.Text.Trim, CuentaDestino, ImporteMXOrigen, CveMonedaOrigen, TipoCambio, Observaciones, "", False, False, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
CveIEDestino = CveIE
Else
If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then
FolioDestino = TxtFolio.Text.Trim
If TxtPaguese.Text.Trim <> "" Then
CuentaDestino = TxtPaguese.Text.Trim
End If
Else
If DdlTipoMovto.SelectedValue.ToEntero = 1 Then
CuentaDestino = TxtPaguese.Text.Trim
End If
End If
CveIE = ObjIE.AddBancos_IE(DdlCuentaOrigen.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero, TxtFechaDocumento.Text.Trim.ToDate, TxtFolio.Text.Trim, CuentaDestino, TxtImporte.Text.Trim.ToDouble, CveMonedaOrigen, TipoCambio, TxtObservaciones.Text.Trim, "", False, False, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If Not chkMovimientoTarjeta.Checked Then
CveIEDestino = ObjIE.AddBancos_IE(DdlCuentaDestino.SelectedValue.ToEntero, If(DdlTipoMovto.SelectedValue = "2", 8, 3), TxtFechaDocumento.Text.Trim.ToDate, FolioDestino, String.Format("Transferencia Cta: {0}", DdlCuentaOrigen.SelectedItem.Text), ImporteDestino, CveMonedaDestino, TipoCambio, TxtObservaciones.Text.Trim, "", False, False, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
End If
End If
Dim CveIEDevolucion As Integer = -1
If DdlCajaChica.SelectedValue.ToEntero() > 0 AndAlso TrCajaChica.Visible Then
CveIEDevolucion = DdlCajaChica.SelectedValue.ToEntero()
End If
If (CveIE > 0 AndAlso CveIEDestino > 0 Or CveIE > 0 AndAlso chkMovimientoTarjeta.Checked AndAlso SumaImportesTarjeta <> 0) Then
If filemove <> "" Then
filemove.FilesMove(CveIE.ToString, String.Format("{0}IE", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase:=False)
End If
'inserto los movimientos de la conta para abonar al saldo
If MsgError = "" Then
If CvePrePoliza > 0 Then
Dim alertaContabilizacion As String = "Se envió correctamente la siguiente póliza:<br><br>"
Dim CuentasContablesInvalidas As New StringBuilder
Dim RowCuentaOrigen As DataRow = Nothing
Dim TipoMovtoDetalle As Boolean = True
If RBLOpcion.SelectedValue = "2" Then TipoMovtoDetalle = False ' cuando sea un reembolso/devolución, es ingreso a bancos
Dim TC As Decimal = TxtTipoCambio.Text.ToDecimal
If ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovtoDetalle,
TxtImporte.Text.ToDecimal, If(Not UsuarioActual.CveEmpresa.Contiene(13, 83), TxtImporte.Text.ToDecimal, ImporteMXOrigen), 30,
$"Transferencia entre cuentas {TxtObservaciones.Text}", $"Transferencia entre cuentas {TxtObservaciones.Text}", CveIE:=CveIE,
ImporteME:=If(CveMonedaOrigen > 1, TxtImporte.Text.ToDecimal * TC, 0),
CveIEDevolucion:=CveIEDevolucion) Then
If CveMonedaOrigen > 1 AndAlso Not UsuarioActual.CveEmpresa.Contiene(13, 83) Then
'Agregamos complementaria
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, TipoMovtoDetalle,
0, (TxtImporte.Text.ToDecimal * TC - TxtImporte.Text.ToDecimal).RoundSQL, 204,
$"Transferencia entre cuentas {TxtObservaciones.Text}", $"Transferencia entre cuentas {TxtObservaciones.Text}", CveIE:=CveIE,
ImporteME:=TxtImporte.Text.ToDecimal,
TipoCambio:=TC) Then
MsgError = "Ocurrió un error al registrar el asiento del ingreso."
End If
End If
'Agregamos los Movimientos de Acreedor cuando es tarjeta
If GvTC.Visible Then
AlertaGlobal.Append("<br/><br/>Recepción:<br/>")
For Each row As GridViewRow In GvTC.Rows
FolioDestino = GetFolio(row.DataKey("CveCuenta").ToEntero, If(DdlTipoMovto.SelectedValue = "2", 8, 3), TransaccioSQL:=ObjIE.IniciaTransacSQL())
If FolioDestino.Trim.Length = 0 Then
MsgError = "Ocurrio un error al obtener el folio destino."
Exit For
End If
CveIEDestino = ObjIE.AddBancos_IE(row.DataKey("CveCuenta").ToEntero, If(DdlTipoMovto.SelectedValue = "2", 8, 3), TxtFechaDocumento.Text.Trim.ToDate, FolioDestino, String.Format("Transferencia Cta: {0}", DdlCuentaOrigen.SelectedItem.Text), row.FCTextBox("TxtAbono").Text.ToDecimal, CveMonedaDestino, TipoCambio, TxtObservaciones.Text.Trim, "", False, False, -1, CvePrePoliza, Comprobante, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovtoDetalle, row.FCTextBox("TxtAbono").Text.ToDecimal, row.FCTextBox("TxtAbono").Text.ToDecimal, 30,
$"Transferencia entre cuentas {TxtObservaciones.Text}", $"Transferencia entre cuentas {TxtObservaciones.Text}",
CveIE:=CveIEDestino) Then
MsgError = "Ocurrio un error al ingresar la prepoliza"
Exit For
Else
AlertaGlobal.AppendFormat("<a class=""Texto"" target='_blank' href=""/Bancos/IE.aspx?CveIE={0}"">{1}</a><br/>", CveIEDestino, FolioDestino)
End If
Next
'Agregamos la contraria a bancos cuando es cuenta
Else
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovtoDetalle,
ImporteDestino, If(Not UsuarioActual.CveEmpresa.Contiene(13, 83), ImporteDestino, ImporteMXDestino),
30, $"Transferencia entre cuentas {TxtObservaciones.Text}", $"Transferencia entre cuentas {TxtObservaciones.Text}", CveIE:=CveIEDestino,
ImporteME:=If(CveMonedaDestino > 1, ImporteDestino, 0)) Then
MsgError = "Ocurrio un error al ingresar la prepoliza"
End If
If CveMonedaDestino > 1 AndAlso Not UsuarioActual.CveEmpresa.Contiene(13, 83) Then
'Agregamos complementaria
If Not ObjMov.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovtoDetalle,
0, (ImporteMXDestino - ImporteDestino).RoundSQL, 204,
$"Transferencia entre cuentas {TxtObservaciones.Text}", $"Transferencia entre cuentas {TxtObservaciones.Text}", CveIE:=CveIEDestino,
ImporteME:=ImporteDestino, TipoCambio:=TC) Then
MsgError = "Ocurrió un error al registrar el asiento del ingreso."
End If
End If
End If
If MsgError = "" Then
If ObjMov.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then
If ObjMov.ValorPolizaDescuadre > 0 Then
MsgError = ObjMov.MensajePolizaDescuadre
GuardaLogAD($"Bancos/Transferencias | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas")
End If
Else
MsgError = "No se pudo validar la prepoliza de cuadre."
End If
End If
If MsgError = "" Then
'Conta ContPAQ
If UsuarioActual.Empresa.Funcionalidad(200) = "1" And MsgError = "" Then
If ObjMov.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, Fecha:=TxtFechaDocumento.Text.ToDate) Then
If ObjMov.ContaIdPoliza > 0 Then
AlertaGlobal.AppendFormat("<br/><br/><a class=""Texto"" target='_blank' href=""/Contabilidad/RegPoliza.aspx?IdPoliza={0}"">Ver Póliza</a>", ObjMov.ContaIdPoliza)
End If
Else
MsgError = "Ocurrio un error al contabilizar, pongase en contacto con Soporte Técnico"
End If
End If
If CveIE > 0 Then
AlertaGlobal.AppendFormat("<br/><br/>Movimiento: <a class=""Texto"" target='_blank' href=""/Bancos/IE.aspx?CveIE={0}"">{1}</a>", CveIE, FolioOrigen)
End If
If CveIEDestino > 0 AndAlso CveIE <> CveIEDestino Then
If Not chkMovimientoTarjeta.Checked Then
AlertaGlobal.AppendFormat("<br/><br/>Recepción: <a class=""Texto"" target='_blank' href=""/Bancos/IE.aspx?CveIE={0}"">{1}</a>", CveIEDestino, FolioDestino)
End If
End If
Else
MsgError = "no se pudo insertar el detalle de la póliza2"
End If
Else
MsgError = "no se pudo insertar el detalle de la póliza"
End If
Else
MsgError = "No se pudo insertar la póliza"
End If
Else
MsgError = "No se insertó el encabezado"
End If
Else
MsgError = "Error al guardar"
End If
If MsgError = "" Then
ObjIE.Commit()
Alert(String.Format("El Movimiento se realizo correctamente.<br>{0}", AlertaGlobal), TipoMensaje.MsgInformacion)
Anexo.Text = ""
'Enviar Correo a los usuarios que tienen acceso a las dos cuentas
If UsuarioActual.CveEmpresa = 13 Then EnviaCorreo(Comprobante)
'LIMPIA
CargaFolio(DdlCuentaOrigen.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
TxtImporte.Text = ""
TxtObservaciones.Text = ""
GeneraChequePDF(CveIEDestino, UsuarioActual.Empresa)
Else
ObjIE.RollBack()
Alert(MsgError)
End If
ObjIE.Dispose()
ObjMov.Dispose()
'If ObjComp IsNot Nothing Then ObjComp.Dispose()
End Sub
Private Sub EnviaCorreo(Comprobante As String)
Dim dtcorreo As DataTable = GlobalDTBancosCuentas(-1, DdlCuentaOrigen.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa)
dtcorreo.Merge(GlobalDTBancosCuentas(-1, DdlCuentaDestino.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa))
' Dim CorreosCCP As New List(Of String)
Dim StrCorreos As New StringBuilder
For Each Row As DataRow In dtcorreo.Rows
' CorreosCCP.Add(GlobalDTUsuarios(Row("CveUsuario").ToString.ToEntero)(0)("correo").ToString)
StrCorreos.AppendFormat("{0};", GlobalDTUsuarios(Row("CveUsuario").ToString.ToEntero)(0)("correo").ToString)
Next
Dim strBody As New StringBuilder
strBody.Append("<html xmlns=""http://www.w3.org/1999/xhtml""> ")
strBody.Append("<head> ")
strBody.Append(" <style type=""text/css""> ")
strBody.Append(" body ")
strBody.Append(" { ")
strBody.Append(" margin:0px; ")
strBody.Append(" padding:0px 0px 0px 0px; ")
strBody.Append(" font-family: Verdana, Arial, Helvetica, sans-serif; ")
strBody.Append(" font-size: 10px; ")
strBody.Append(" background-color:#F0F0F0; ")
strBody.Append(" } ")
strBody.Append(" a.Texto ")
strBody.Append(" { ")
strBody.Append(" font-size:11px; ")
strBody.Append(" background-color:#F7F6F3; ")
strBody.Append(" text-decoration:none; ")
strBody.Append(" font-weight:bold; ")
strBody.Append(" } ")
strBody.Append(" .Texto ")
strBody.Append(" { ")
strBody.Append(" background-color:#F7F6F3; color:Black; font-family:Verdana; font-size:10px; text-align:center; vertical-align:middle; height:20px;")
strBody.Append(" } ")
strBody.Append(" .TextoAlterno ")
strBody.Append(" { ")
strBody.Append(" background-color:White; color:Black; font-family:Verdana; font-size:10px; text-align:center; ")
strBody.Append(" vertical-align:middle; height:20px;")
strBody.Append(" } ")
strBody.Append(" .BarraIdentidad ")
strBody.Append(" { ")
strBody.Append(" color:#FFFFFF; ")
strBody.Append(" background:#F0F0F0; ")
strBody.Append(" font-weight:bold; ")
strBody.Append(" font-size:19px; ")
strBody.Append(" font-style:oblique; ")
strBody.Append(" } ")
strBody.Append(" .Titulos ")
strBody.Append(" { ")
strBody.Append(" background-color: Gray;")
strBody.Append(" color:White; ")
strBody.Append(" font-family:Verdana; font-size:12px; text-align:center; ")
strBody.Append(" vertical-align:middle; font-weight:bold; height:30px; ")
strBody.Append(" text-decoration:none; ")
strBody.Append(" } ")
strBody.Append(" .Verde {color: #00CC00;} ")
strBody.Append(" .Negro {color: #000000;} ")
strBody.Append(" .Rojo {color: #FF0000;} ")
strBody.Append(" </style> ")
strBody.Append("</head> ")
strBody.Append("<body> ")
strBody.Append(" <div id=""C_divOC"" style=""width: 550px""> <fieldset> <legend><b>Transferencia Bancaria</b></legend> ")
strBody.Append(" <table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""100%""> ")
strBody.Append(" <tr style=""height: 22px""> ")
strBody.AppendFormat(" <td style=""width: 90px""> Cuenta Origen:</td><td colspan=""3""><b>{0}</b></td></td> ", DdlCuentaOrigen.SelectedItem.Text)
strBody.Append(" </tr> ")
strBody.Append(" <tr style=""height: 22px""> ")
strBody.AppendFormat(" <td style=""width: 90px""> Cuenta Destino:</td><td colspan=""3""><b>{0}</b></td> ", DdlCuentaDestino.SelectedItem.Text)
strBody.Append(" </tr> ")
strBody.Append(" <tr style=""height: 20px""> ")
strBody.AppendFormat(" <td>Folio:</td><td colspan='3'><b>{0}</b></td> ", TxtFolio.Text.Trim)
strBody.Append(" </tr> ")
strBody.Append(" <tr style=""height: 20px""> ")
strBody.AppendFormat(" <td>Importe:</td><td colspan='3'>$ <b>{0}</b></td> ", TxtImporte.Text.FormatoNumero)
strBody.Append(" </tr> ")
strBody.Append(" <tr style=""height: 20px""> ")
strBody.AppendFormat(" <td>Fecha:</td><td colspan='3'> <b>{0}</b></td> ", TxtFechaDocumento.Text)
strBody.Append(" </tr> ")
strBody.Append(" <tr style=""height: 20px""> ")
strBody.AppendFormat(" <td>Observaciones</td><td colspan=""3""><textarea name=""ctlTJ"" rows=""5"" cols=""20"" readonly=""readonly""id=""ctlTJ"" style=""width: 300px;"">{0}</textarea></td> ", TxtObservaciones.Text)
strBody.Append(" </tr> ")
strBody.Append(" </table> ")
strBody.Append(" </fieldset> ")
strBody.Append(" </div> ")
strBody.Append("</body></html>")
Try
ViewState("Para") = StrCorreos.ToString 'String.Join(";", CorreosCCP.Distinct().ToArray)
'ViewState("ArrayCC") =
ViewState("Asunto") = "SIG -Transferencia Realizada"
ViewState("Body") = strBody.ToString
ViewState("Adjunto") = Comprobante
Dim Hilo As New System.Threading.Thread(AddressOf MandaCorreo)
Hilo.Start()
' If NotificarAlert = True Then Alert("Se enviara correo por cambio de Estatus")
Catch ex As Exception
OnError("Ocurrió error al mandar MAIL", ex)
End Try
End Sub
Private Sub MandaCorreo()
'Dim ArrayAttachment As New List(Of String)
Dim ListaArchivos As New List(Of ClsSisMail.ArchivoMail)
If ViewState("Adjunto") IsNot Nothing AndAlso ViewState("Adjunto").ToString <> "" Then
' ArrayAttachment.Add(ViewState("Adjunto").ToString)
ListaArchivos.Add(New ClsSisMail.ArchivoMail With {.Ruta = ViewState("Adjunto").ToString})
End If
Dim Mail As New ClsSisMail()
'Mail.MandaCorreo(EmpresaNotificaciones, ViewState("Para").ToString, ViewState("Asunto").ToString, ViewState("Body").ToString, ArrayAttachment:=ArrayAttachment)
Mail.SendMail(EmpresaNotificaciones, ViewState("Para").ToString, ViewState("Asunto").ToString, ViewState("Body").ToString, Archivos:=ListaArchivos)
End Sub
Private Sub CargaFolio(CveCuenta As Integer, CveTipoTransaccion As Integer)
TxtFolio.Text = GetFolio(CveCuenta, CveTipoTransaccion)
End Sub
Private Function GetFolio(CveCuenta As Integer, CveTipoTransaccion As Integer, Optional ByRef TransaccioSQL As SqlTransaction = Nothing) As String
Dim Folio As String
Dim Banco As ClsBancos
If TransaccioSQL Is Nothing Then
Banco = New ClsBancos
Else
Banco = New ClsBancos(TransaccioSQL)
End If
Folio = Banco.GetNextFolio(CveCuenta, CveTipoTransaccion).ToString
If TransaccioSQL Is Nothing Then
Banco.Dispose()
End If
Return Folio
End Function
Private Sub chkMovimientoTarjeta_CheckedChanged(sender As Object, e As EventArgs) Handles chkMovimientoTarjeta.CheckedChanged
If chkMovimientoTarjeta.Checked Then
'If GlobalDTBancosCuentas(UsuarioActual.CveUsuario, CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveCuenta = {0} AND UsaTarjeta = 1", DdlCuentaDestino.SelectedValue.ToEntero)).Rows.Count > 0 Then
CargaGridTarjetas()
'End If
Else
GvTC.Visible = False
UpGvTC.Update()
End If
End Sub
Private Sub DdlTipoMovto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoMovto.SelectedIndexChanged
RFVTxtPaguese.Visible = False
If Opcion = 1 Then
CargaFolio(DdlCuentaDestino.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
Else
CargaFolio(DdlCuentaOrigen.SelectedValue.ToEntero, DdlTipoMovto.SelectedValue.ToEntero)
If DdlTipoMovto.SelectedValue.ToEntero = 1 And Opcion <> 1 Then 'CHEQUE ACTIVA EL REQUIRED DE TxtPaguese
RFVTxtPaguese.Visible = True
End If
End If
UPPDatos.Update()
End Sub
Protected Sub RBLOpcion_SelectedIndexChanged(sender As Object, e As EventArgs)
If RBLOpcion.SelectedValue = "2" Then ' reembolso
DdlTipoMovto.Items.Clear()
DdlTipoMovto.Items.Add(New ListItem("Depósito", "4"))
Else
DdlTipoMovto.Items.Clear()
DdlTipoMovto.Items.Add(New ListItem("Cheque Emitido", "1"))
DdlTipoMovto.Items.Add(New ListItem("Transferencia Bancaria", "2"))
End If
End Sub
Protected Sub BtnCambiaTipoMoneda_Click(sender As Object, e As EventArgs)
CambiaTipoMoneda()
End Sub
Private Sub CambiaTipoMoneda()
If TxtTipoCambio.Visible = True Then
TxtTipoCambio.Text = GlobalTipoCambio(TxtFechaDocumento.Text.ToDate).FormatoNumero(4)
End If
If tCveMonedaOrigen = 1 AndAlso tCveMonedaDestino <> 1 Then
'pesos a otra moneda se divide
RegistraScript("$get('TrTC').style.display=''; $get('HdnTC').value='2'; Calcula();")
ElseIf tCveMonedaOrigen <> 1 AndAlso tCveMonedaDestino = 1 Then
'de otra moneda a pesos se multiplica
RegistraScript("$get('TrTC').style.display=''; $get('HdnTC').value='1'; Calcula();")
End If
UPPDatos.Update()
End Sub
Private Sub CargaMovimientosCajaChica()
Dim CveCajaChica As Integer = DdlCuentaOrigen.SelectedValue.ToEntero()
Dim ObjMovtos As New ClsMovimientos
If ObjMovtos.GetCajaChicaDetalle(CveCajaChica, UsuarioActual.CveEmpresa) Then
DdlCajaChica.DataSource = ObjMovtos.DtResultados.FiltraParametros("CveIE > 0", "FechaDocumento, FolioFecha")
End If
ObjMovtos.Dispose()
DdlCajaChica.DataBind()
DdlCajaChica.Items.Insert(0, New ListItem("Seleccione", "-1"))
End Sub
End Class