Option Explicit On Option Strict On Imports System.Data Imports Extensiones Partial Class Bancos_FluctuacionCambiaria Inherits ClsPaginas #Region "PROPIEDADES" Private Property LblTotal() As String Get Return ViewState("Total").ToString End Get Set(value As String) ViewState("Total") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then CargarCentrosDeCosto(Nothing, DdlSubproyecto, Nothing, LblSubProyecto) CargaUltimaFluctuacion() End If End Sub #Region "CARGAS" Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click CargaTipoCambio() If T.ActiveTabIndex = 0 Then CargaDatosCompra() If T.ActiveTabIndex = 1 Then CargaDatosVentas() If T.ActiveTabIndex = 2 Then CargaDatosCuentas() If T.ActiveTabIndex = 3 Then CargaDatosDeudores() If T.ActiveTabIndex = 4 Then CargaDatosAcreedores() If T.ActiveTabIndex = 5 Then CargaDatosFiliales() UpTabs.Update() End Sub Private Sub CargaTipoCambio() Dim ObjGenerales As New ClsGenerales ObjGenerales.GetTipoCambio(-1, TxtFecha.Text.ToDate) If ObjGenerales.DtResultados.Rows.Count > 0 Then LtTipoCambioActual.Text = ObjGenerales.DtResultados.Rows(0)("TipoCambio").ToString TxtConceptoFluctuacion.Text = "Fluctuación a " & TxtFecha.Text End If ObjGenerales.Dispose() End Sub Private Sub CargaUltimaFluctuacion() Dim Obj As New ClsBancos If Obj.GetFluctuacionesBitacora(UsuarioActual.CveEmpresa) Then Dim dt As DataTable = Obj.DtResultados.FiltraParametros("TipoFluctuacion = 1", "Fecha DESC") If dt.Rows.Count > 0 Then LtlUltimaFluctuacion.Text = String.Format("Ultima Fluctuación : {0}", dt.Rows(0)("Fecha").ToString.ToDate.ToShortDateString) 'si la ultima fluctuacion es mayor o igual al fin de mes anterior, entonces pon la fecha actual If dt.Rows(0)("Fecha").ToString.ToDate >= Now.AddMonths(-1).LastDayOfMonth Then TxtFecha.Text = Now.ToShortDateString Else TxtFecha.Text = Now.AddMonths(-1).LastDayOfMonth.ToShortDateString() End If End If End If Obj.Dispose() CargaTipoCambio() End Sub Private Sub CargaDatosCompra() Dim ObjBancos As New ClsBancos 'LblTotalCompras.Text = "0.00" If ObjBancos.GetFluctuaciones(TxtFecha.Text.ToDate, 1, UsuarioActual.CveEmpresa) Then GvCompras.DataSource = ObjBancos.DtResultados 'LblTotalCompras.Text = ObjBancos.DtResultados.SUM("Fluctuacion").FormatoNumero Dim Perdida As DataTable = ObjBancos.DtResultados.FiltraParametros("Fluctuacion < 0 ") Dim Ganancias As DataTable = ObjBancos.DtResultados.FiltraParametros("Fluctuacion > 0 ") Dim PerdidaAux As Double = Perdida.SUM("Fluctuacion").Abs Dim GanaciaAux As Double = Ganancias.SUM("Fluctuacion") Dim Final As Double = GanaciaAux - PerdidaAux IImagenResultado.Attributes("class") = If(Final > 0, "widget-thumb-icon bg-green-jungle fa fa-usd", "widget-thumb-icon bg-red fa fa-usd") LtIndicador_ExistenciaPerdida.Text = PerdidaAux.ToString.FormatoNumero LtIndicador_ValorPesosGanancia.Text = GanaciaAux.ToString.FormatoNumero LtIndicador_CPPesosFinal.Text = Final.Abs.ToString.FormatoNumero LblComprasPerdidaGanancia.Text = If(Final > 0, "Ganancia", "Pérdida") LblTotal = ObjBancos.DtResultados.SUM("Fluctuacion").FormatoNumero Else GvCompras.DataSource = Nothing Alert("Ocurrio un error al cargar las compras", TipoMensaje.MsgAdvertencia) End If ObjBancos.Dispose() GvCompras.DataBind() UpIndicadores.Visible = True If GvCompras.Rows.Count > 0 Then GvCompras.Rows(GvCompras.Rows.Count - 1).CssClass = "SubTotales2" End If End Sub Private Sub CargaDatosVentas() Dim ObjBancos As New ClsBancos LblTotalVentas.Text = "0.00" If ObjBancos.GetFluctuaciones(TxtFecha.Text.ToDate, 2, UsuarioActual.CveEmpresa) Then GvVentas.DataSource = ObjBancos.DtResultados Dim Perdida As DataTable = ObjBancos.DtResultados.FiltraParametros("Fluctuacion < 0") Dim Ganancias As DataTable = ObjBancos.DtResultados.FiltraParametros("Fluctuacion > 0") Dim PerdidaAux As Double = Perdida.SUM("Fluctuacion", "Fluctuacion < 0").Abs Dim GanaciaAux As Double = Ganancias.SUM("Fluctuacion", "Fluctuacion > 0") Dim Final As Double = GanaciaAux - PerdidaAux IImagenFinalVentas.Attributes("class") = If(Final > 0, "widget-thumb-icon bg-green-jungle fa fa-usd", "widget-thumb-icon bg-red fa fa-usd") LtIndicador_PerdidasVentas.Text = PerdidaAux.ToString.FormatoNumero LtIndicador_GanaciaVentas.Text = GanaciaAux.ToString.FormatoNumero LtIndicador_FinalVentas.Text = Final.ToString.FormatoNumero LblVentasPerdidaGanancia.Text = If(Final < 0, "Pérdida", "Ganancia") LblTotalVentas.Text = ObjBancos.DtResultados.SUM("Fluctuacion").FormatoNumero UpIndicadoresVentas.Visible = True Else GvVentas.DataSource = Nothing Alert("Ocurrio un error al cargar las compras", TipoMensaje.MsgAdvertencia) End If ObjBancos.Dispose() GvVentas.DataBind() End Sub Private Sub CargaDatosCuentas() Dim ObjBancos As New ClsBancos LblTotalBancos.Text = "0.00" If ObjBancos.GetFluctuaciones(TxtFecha.Text.ToDate, 4, UsuarioActual.CveEmpresa) Then Dim DtTemp As DataTable = ObjBancos.DtResultados.Copy Dim TCCierreFluctuacion As Decimal = LtTipoCambioActual.Text.ToDecimal Dim TotAcumulado As Decimal = 0 Dim Conta As New ClsContabilidad For Each Dr As DataRow In DtTemp.Rows Dim Total As Decimal = 0 Dim CveCuentaExtranjera As Integer = Dr("CveCuentaExtranjera").ToString.ToEntero If CveCuentaExtranjera > 0 Then If Conta.GetMovimientosAuxiliaresCatalogo(CveCuentaExtranjera, MinFecha, TxtFecha.Text.ToDate, 2, "-1", UsuarioActual.CveEmpresa, "1") Then If Conta.DtResultados.Rows.Count > 1 Then Total = Conta.DtResultados.Rows(1)("SaldoActual").ToString.ToDecimal End If End If End If Dr("Saldo") = Total Total = Total * TCCierreFluctuacion - Total Dim SaldoActualContabilidad As Decimal = 0 Dim CveCuentaComplementaria As Integer = Dr("CveCuentaComplementaria").ToString.ToEntero If CveCuentaComplementaria > 0 Then If Conta.GetMovimientosAuxiliaresCatalogo(CveCuentaComplementaria, MinFecha, TxtFecha.Text.ToDate, 2, "-1", UsuarioActual.CveEmpresa, "1") Then If Conta.DtResultados.Rows.Count > 1 Then SaldoActualContabilidad = Conta.DtResultados.Rows(1)("SaldoActual").ToString.ToDecimal End If End If End If Total = Total - SaldoActualContabilidad TotAcumulado += Math.Round(Total, 2) Dr("Fluctuacion") = Total Next DtTemp.AcceptChanges() Conta.Dispose() GvCuentas.DataSource = DtTemp LblTotalBancos.Text = TotAcumulado.FormatoNumero Else GvCuentas.DataSource = Nothing Alert("Ocurrio un error al cargar las cuentas", TipoMensaje.MsgAdvertencia) End If ObjBancos.Dispose() GvCuentas.DataBind() End Sub Private Sub CargaDatosDeudores() Dim ObjBancos As New ClsBancos LblTotalDeudores.Text = "0.00" If ObjBancos.GetFluctuaciones(TxtFecha.Text.ToDate, 5, UsuarioActual.CveEmpresa) Then GvDeudores.DataSource = ObjBancos.DtResultados LblTotalDeudores.Text = ObjBancos.DtResultados.SUM("Fluctuacion").FormatoNumero Else GvDeudores.DataSource = Nothing Alert("Ocurrio un error al cargar los deudores", TipoMensaje.MsgAdvertencia) End If ObjBancos.Dispose() GvDeudores.DataBind() End Sub Private Sub CargaDatosAcreedores() Dim ObjBancos As New ClsBancos LblTotalAcreedores.Text = "0.00" If ObjBancos.GetFluctuaciones(TxtFecha.Text.ToDate, 6, UsuarioActual.CveEmpresa) Then GvAcreedores.DataSource = ObjBancos.DtResultados LblTotalAcreedores.Text = ObjBancos.DtResultados.SUM("Fluctuacion").FormatoNumero Else GvAcreedores.DataSource = Nothing Alert("Ocurrio un error al cargar los acreedores", TipoMensaje.MsgAdvertencia) End If ObjBancos.Dispose() GvAcreedores.DataBind() End Sub Private Sub CargaDatosFiliales() Dim ObjBancos As New ClsBancos LblTotalAcreedores.Text = "0.00" If ObjBancos.GetFluctuaciones(TxtFecha.Text.ToDate, 7, UsuarioActual.CveEmpresa) Then GvFiliales.DataSource = ObjBancos.DtResultados.FiltraParametros("Saldo > 0") LblTotalAcreedores.Text = ObjBancos.DtResultados.SUM("Fluctuacion").FormatoNumero Else GvFiliales.DataSource = Nothing Alert("Ocurrio un error al cargar los acreedores", TipoMensaje.MsgAdvertencia) End If ObjBancos.Dispose() GvFiliales.DataBind() End Sub #End Region #Region "FLUCTUACION COMPRAS" Protected Sub BtnGeneraCompras_Click(sender As Object, e As EventArgs) If DdlSubproyecto.SelectedValue.ToEntero < 0 Then Alert($"Debe de seleccionar un {LblSubProyecto.Text}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim Total As Decimal = 0 Dim Conta As New ClsContabilidad Conta.IniciaTransacSQL() Dim CvePrePoliza As Integer = Conta.AddPrePolizas("Banc/Fluctua", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Fluctuación", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim idCta As Integer = 0 Dim CveCuenta As Integer = 0 Dim CveCuentaPerdida, CveCuentaGanancia As Integer Dim idCtaPerdida, IdCtaGanancia As Integer Dim TipoMovto As Boolean = False Dim CveConceptoContable As Integer = 0 Dim CveCuentaComplementaria As Integer = 55175 Dim IdCtaComplementaria As Integer = 1248 Dim ErrorRegistrar As Boolean = False CveCuentaPerdida = 0 '55379 CveCuentaGanancia = 0 ' 55382 idCtaPerdida = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria '1227 IdCtaGanancia = UsuarioActual.Empresa.IdCuentaGananciaCambiaria '1230 Dim TC As Decimal = 2 ' se pone 2, para que cumpla con el check constrains de complementarias Total = LblTotal.ToDecimal If Total > 0 Then CveConceptoContable = 64 CveCuenta = CveCuentaGanancia idCta = IdCtaGanancia TipoMovto = True Else CveConceptoContable = 65 CveCuenta = CveCuentaPerdida idCta = idCtaPerdida TipoMovto = False End If If Not Conta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Math.Abs(Total), " ", CveConceptoContable, "Fluctuación", Now, idCta, 0, ImporteMX:=Math.Abs(Total), CveCuenta:=CveCuenta, CveSubProyecto:=DdlSubproyecto.SelectedValue.ToEntero) Then ErrorRegistrar = True End If 'saco las cuentas de pérdida y ganancia For Each gvr As GridViewRow In GvCompras.Rows Total = gvr.DataKey("Fluctuacion").ToDecimal 'si es pérdida o ganancia 'movimiento de complementaria If Not Conta.AddPrePolizasDetalle(CvePrePoliza, False, Total, gvr.DataKey("SerieFolio"), 201, gvr.DataKey("SerieFolio"), Now, IdCtaComplementaria, 0, CveCompra:=gvr.DataKey("CveCompra").ToEntero, TipoCambio:=TC, ImporteMX:=Total, ImporteME:=Total, CveCuenta:=CveCuentaComplementaria) Then ErrorRegistrar = True Exit For End If Next If Not ErrorRegistrar Then Conta.Commit() Alert(String.Format("La Fluctuación se ha generado
Ver PrePóliza", CvePrePoliza), TipoMensaje.MsgInformacion) Else Conta.RollBack() End If Conta.Dispose() End Sub #End Region #Region "FLUCTUACION VENTAS" Protected Sub BtnGeneraVentas_Click(sender As Object, e As EventArgs) If DdlSubproyecto.SelectedValue.ToEntero < 0 Then Alert($"Debe de seleccionar un {LblSubProyecto.Text}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim Total As Decimal = 0 Dim Conta As New ClsContabilidad Conta.IniciaTransacSQL() Dim CvePrePoliza As Integer = Conta.AddPrePolizas("Banc/Fluctua", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Fluctuación", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim idCta As Integer = 0 Dim CveCuenta As Integer = 0 Dim CveCuentaPerdida, CveCuentaGanancia As Integer Dim idCtaPerdida, IdCtaGanancia As Integer Dim TipoMovto As Boolean = False Dim CveConceptoContable As Integer = 0 Dim CveCuentaComplementaria As Integer = 54141 Dim IdCtaComplementaria As Integer = 70 Dim ErrorRegistrar As Boolean = False CveCuentaPerdida = 0 '55379 CveCuentaGanancia = 0 ' 55382 idCtaPerdida = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria '1227 IdCtaGanancia = UsuarioActual.Empresa.IdCuentaGananciaCambiaria '1230 Dim TC As Decimal = 2 ' se pone 2, para que cumpla con el check constrains de complementarias Total = LblTotalVentas.Text.ToDecimal If Total > 0 Then CveConceptoContable = 64 CveCuenta = CveCuentaGanancia TipoMovto = True idCta = IdCtaGanancia Else CveConceptoContable = 65 CveCuenta = CveCuentaPerdida idCta = idCtaPerdida TipoMovto = False End If If Not Conta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Math.Abs(Total), " ", CveConceptoContable, "Fluctuación", Now, idCta, 0, ImporteMX:=Math.Abs(Total), CveCuenta:=CveCuenta, CveSubProyecto:=DdlSubproyecto.SelectedValue.ToEntero) Then ErrorRegistrar = True End If Dim CveConconceptoCliente As Integer = 203 'saco las cuentas de pérdida y ganancia For Each gvr As GridViewRow In GvVentas.Rows Total = -gvr.DataKey("Fluctuacion").ToDecimal If gvr.DataKey("CveIE").ToEntero > 0 AndAlso gvr.DataKey("CveVenta").ToEntero < 0 Then CveConconceptoCliente = 226 Else CveConconceptoCliente = 203 End If 'movimiento de complementaria If Not Conta.AddPrePolizasDetalle(CvePrePoliza, True, Total, gvr.DataKey("SerieFolio"), CveConconceptoCliente, gvr.DataKey("SerieFolio"), Now, IdCtaComplementaria, 0, CveVenta:=gvr.DataKey("CveVenta").ToEntero, TipoCambio:=TC, ImporteMX:=Total, ImporteME:=Total, CveCuenta:=CveCuentaComplementaria, CveIE:=gvr.DataKey("CveIE").ToEntero) Then ErrorRegistrar = True Exit For End If Next If Not ErrorRegistrar Then Conta.Commit() Alert(String.Format("La Fluctuación se ha generado
Ver PrePóliza", CvePrePoliza), TipoMensaje.MsgInformacion) Else Conta.RollBack() End If Conta.Dispose() End Sub #End Region #Region "FLUCTUACION BANCOS" Protected Sub BtnGeneraBancos_Click(sender As Object, e As EventArgs) If DdlSubproyecto.SelectedValue.ToEntero < 0 Then Alert($"Debe de seleccionar un {LblSubProyecto.Text}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim Total As Decimal = 0 Dim Conta As New ClsContabilidad Conta.IniciaTransacSQL() Dim ObjContPaq As New ClsContPAQi(UsuarioActual.Empresa) ObjContPaq.IniciaTransacSQL() Dim CvePrePoliza As Integer = Conta.AddPrePolizas("Banc/Fluctua", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Fluctuación", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim idCta As Integer = 0 Dim CveCuenta As Integer = 0 Dim CveCuentaPerdida, CveCuentaGanancia As Integer Dim idCtaPerdida, IdCtaGanancia As Integer Dim TipoMovto As Boolean = False Dim CveConceptoContable As Integer = 0 Dim ErrorRegistrar As Boolean = False Dim TCCierreFluctuacion As Decimal = LtTipoCambioActual.Text.ToDecimal CveCuentaPerdida = 0 ' 55379 CveCuentaGanancia = 0 ' 55382 idCtaPerdida = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria '1227 IdCtaGanancia = UsuarioActual.Empresa.IdCuentaGananciaCambiaria '1230 Dim TC As Decimal = 2 ' se pone 2, para que cumpla con el check constrains de complementarias Total = LblTotalBancos.Text.ToDecimal Dim CveConconceptoBancos As Integer = 204 'saco las cuentas de pérdida y ganancia For Each gvr As GridViewRow In GvCuentas.Rows Dim cb As CheckBox = gvr.FCCheckBox("ChkGenerarBancos") If cb.Checked Then Total = gvr.DataKey("Fluctuacion").ToDecimal Dim IdCtaComplementaria As Integer = gvr.DataKey("IdCtaAfectable").ToEntero Dim ConceptoReferencia As String = $"{gvr.DataKey("Banco")} - {gvr.DataKey("NumCuenta")} " 'MOVIMIENTO DE FLUCTUACION If Total > 0 Then CveConceptoContable = 64 CveCuenta = CveCuentaGanancia TipoMovto = True idCta = IdCtaGanancia Else CveConceptoContable = 65 CveCuenta = CveCuentaPerdida idCta = idCtaPerdida TipoMovto = False End If 'movimiento de complementaria If Not Conta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovto, Math.Abs(Total), ConceptoReferencia, CveConconceptoBancos, ConceptoReferencia, Now, IdCtaComplementaria, 0, TipoCambio:=TC, ImporteMX:=Math.Abs(Total), ImporteME:=Math.Abs(Total)) Then ErrorRegistrar = True Exit For End If If Not Conta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Math.Abs(Total), " ", CveConceptoContable, "Fluctuación", Now, idCta, 0, ImporteMX:=Math.Abs(Total), CveCuenta:=CveCuenta, CveSubProyecto:=DdlSubproyecto.SelectedValue.ToEntero) Then ErrorRegistrar = True End If End If Next Dim SeContabilizo As Boolean = False Dim AutoConta As Boolean = UsuarioActual.Empresa.Funcionalidad(200) = "1" If AutoConta Then If Conta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContPaq) Then SeContabilizo = True Else ErrorRegistrar = True Alert("Ocurrio un Error al contabilizar, pongase en contacto con Soporte Técnico", TipoMensaje.MsgError) End If End If If Not ErrorRegistrar And SeContabilizo Then Conta.Commit() ObjContPaq.Commit() Alert(String.Format("La Fluctuación se ha generado
Ver PrePóliza", CvePrePoliza), TipoMensaje.MsgInformacion) CargaDatosCuentas() Else Conta.RollBack() ObjContPaq.Dispose() End If Conta.Dispose() End Sub #End Region #Region "FLUCTUACION DEUDOR" Protected Sub BtnGeneraDedudores_Click(sender As Object, e As EventArgs) If DdlSubproyecto.SelectedValue.ToEntero < 0 Then Alert($"Debe de seleccionar un {LblSubProyecto.Text}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim Total As Decimal = 0 Dim Conta As New ClsContabilidad Dim Banco As New ClsBancos(Conta.IniciaTransacSQL()) Dim CvePrePoliza As Integer = Conta.AddPrePolizas("Banc/FluctuaDD", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Fluctuación Deudor", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim idCta As Integer = 0 Dim CveCuenta As Integer = 0 Dim CveCuentaPerdida, CveCuentaGanancia As Integer Dim idCtaPerdida, IdCtaGanancia As Integer Dim TipoMovto As Boolean = False Dim CveConceptoContable As Integer = 0 Dim ErrorRegistrar As Boolean = False CveCuentaPerdida = 0 '55379 CveCuentaGanancia = 0 ' 55382 idCtaPerdida = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria '1227 IdCtaGanancia = UsuarioActual.Empresa.IdCuentaGananciaCambiaria '1230 Dim TC As Decimal = 2 ' se pone 2, para que cumpla con el check constrains de complementarias Dim TCCierreFluctuacion As Decimal = LtTipoCambioActual.Text.ToDecimal Total = LblTotalAcreedores.Text.ToDecimal Dim ConceptoFluctuacion As String = String.Format("Fluctuación Filiales {0} ", TxtFecha.Text) Dim CveConconceptoDeudores As Integer = 256 'saco las cuentas de pérdida y ganancia For Each gvr As GridViewRow In GvDeudores.Rows Total = gvr.DataKey("Fluctuacion").ToDecimal.RoundSQL If gvr.DataKey("CveIE").ToEntero = 0 Then If Total > 0 Then CveConceptoContable = 64 CveCuenta = CveCuentaGanancia idCta = IdCtaGanancia TipoMovto = True Else CveConceptoContable = 65 CveCuenta = CveCuentaPerdida idCta = idCtaPerdida TipoMovto = False End If If Not Conta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Math.Abs(Total), " ", CveConceptoContable, ConceptoFluctuacion, Now, idCta, 0, ImporteMX:=Math.Abs(Total), CveCuenta:=CveCuenta, CveSubProyecto:=DdlSubproyecto.SelectedValue.ToEntero) Then ErrorRegistrar = True End If Dim IdCtaComplementaria As Integer = gvr.DataKey("IdCtaAfectable").ToEntero 'movimiento de complementaria If Not Conta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovto, Math.Abs(Total), ConceptoFluctuacion, CveConconceptoDeudores, ConceptoFluctuacion & gvr.DataKey("RazonSocial"), Now, IdCtaComplementaria, 0, TipoCambio:=TC, ImporteMX:=Math.Abs(Total), ImporteME:=Math.Abs(Total)) Then ErrorRegistrar = True Exit For End If Else 'actualizar el TC del IE, al nuevo TC de la fluctuación Banco.UpdateBancosTipoCambioValuacion(TCCierreFluctuacion, gvr.DataKey("CveIE").ToEntero, UsuarioActual.CveEmpresa) End If Next If Not ErrorRegistrar Then Conta.Commit() Alert(String.Format("La Fluctuación se ha generado
Ver Póliza", CvePrePoliza), TipoMensaje.MsgInformacion) Else Conta.RollBack() End If Conta.Dispose() Banco.Dispose() End Sub #End Region #Region "FLUCTUACION FILIALES" Protected Sub BtnGeneraFiliales_Click(sender As Object, e As EventArgs) If DdlSubproyecto.SelectedValue.ToEntero < 0 Then Alert($"Debe de seleccionar un {LblSubProyecto.Text}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim Total As Decimal = 0 Dim Conta As New ClsContabilidad Dim Banco As New ClsBancos(Conta.IniciaTransacSQL()) Dim ObjContPaq As New ClsContPAQi(UsuarioActual.Empresa) ObjContPaq.IniciaTransacSQL() Dim CvePrePoliza As Integer = Conta.AddPrePolizas("Banc/FluctuaFilial", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Fluctuación Filiales", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim idCta As Integer = 0 Dim CveCuenta As Integer = 0 Dim CveCuentaPerdida, CveCuentaGanancia As Integer Dim idCtaPerdida, IdCtaGanancia As Integer Dim TipoMovto As Boolean = False Dim CveConceptoContable As Integer = 0 Dim CveCuentaComplementaria As Integer = 55201 Dim IdCtaComplementaria As Integer = 1274 Dim ErrorRegistrar As Boolean = False CveCuentaPerdida = 0 '55379 CveCuentaGanancia = 0 ' 55382 idCtaPerdida = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria '1227 IdCtaGanancia = UsuarioActual.Empresa.IdCuentaGananciaCambiaria '1230 Dim TC As Decimal = 2 ' se pone 2, para que cumpla con el check constrains de complementarias Dim TCCierreFluctuacion As Decimal = LtTipoCambioActual.Text.ToDecimal Total = LblTotalAcreedores.Text.ToDecimal Dim ConceptoFluctuacion As String = String.Format("Fluctuación Filiales {0} ", TxtFecha.Text) 'saco las cuentas de pérdida y ganancia For Each gvr As GridViewRow In GvFiliales.Rows Total = gvr.DataKey("Fluctuacion").ToDecimal 'si es pérdida o ganancia 'cuando es acumulado, SOLO REGISTRA If gvr.DataKey("CveIE").ToEntero = 0 Then If Total < 0 Then CveConceptoContable = 64 CveCuenta = CveCuentaGanancia idCta = IdCtaGanancia TipoMovto = True Else CveConceptoContable = 65 CveCuenta = CveCuentaPerdida idCta = idCtaPerdida TipoMovto = False End If If Not Conta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Math.Abs(Total), " ", CveConceptoContable, ConceptoFluctuacion, Now, idCta, 0, ImporteMX:=Math.Abs(Total), CveCuenta:=CveCuenta, CveSubProyecto:=DdlSubproyecto.SelectedValue.ToEntero) Then ErrorRegistrar = True End If 'movimiento de complementaria If Not Conta.AddPrePolizasDetalle(CvePrePoliza, Not TipoMovto, Math.Abs(Total), ConceptoFluctuacion, 202, ConceptoFluctuacion & gvr.DataKey("RazonSocial"), Now, IdCtaComplementaria, 0, TipoCambio:=TC, ImporteMX:=Math.Abs(Total), ImporteME:=Math.Abs(Total), CveCuenta:=CveCuentaComplementaria) Then ErrorRegistrar = True Exit For End If Else 'actualizar el TC del IE, al nuevo TC de la fluctuación Banco.UpdateBancosTipoCambioValuacion(TCCierreFluctuacion, gvr.DataKey("CveIE").ToEntero, UsuarioActual.CveEmpresa) End If Next If Not ErrorRegistrar Then 'Inicio auto conta Dim AutoConta As Boolean = UsuarioActual.Empresa.Funcionalidad(200) = "1" If AutoConta Then If Conta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContPaq) Then Else Alert("Ocurrio un Error al contabilizar, pongase en contacto con Soporte Técnico", TipoMensaje.MsgError) End If End If If ObjContPaq IsNot Nothing Then ObjContPaq.Commit() 'Fin autoconta Conta.Commit() Alert(String.Format("La Fluctuación se ha generado
Ver Póliza", CvePrePoliza), TipoMensaje.MsgInformacion) Else Conta.RollBack() ObjContPaq.RollBack() End If Conta.Dispose() Banco.Dispose() ObjContPaq.Dispose() End Sub #End Region #Region "FLUCTUACION ACREEDORES" Protected Sub BtnGeneraAcreedores_Click(sender As Object, e As EventArgs) If DdlSubproyecto.SelectedValue.ToEntero < 0 Then Alert($"Debe de seleccionar un {LblSubProyecto.Text}", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim Total As Decimal = 0 Dim Conta As New ClsContabilidad Conta.IniciaTransacSQL() Dim CvePrePoliza As Integer = Conta.AddPrePolizas("Banc/Fluctua", 1, 0, 0, 1, TxtFecha.Text.ToDate, "Fluctuación", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim idCta As Integer = 0 Dim CveCuenta As Integer = 0 Dim CveCuentaPerdida, CveCuentaGanancia As Integer Dim idCtaPerdida, IdCtaGanancia As Integer Dim TipoMovto As Boolean = False Dim CveConceptoContable As Integer = 0 Dim CveCuentaComplementaria As Integer = 55206 Dim IdCtaComplementaria As Integer = 1081 Dim ErrorRegistrar As Boolean = False CveCuentaPerdida = 0 '55379 CveCuentaGanancia = 0 ' 55382 idCtaPerdida = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria '1227 IdCtaGanancia = UsuarioActual.Empresa.IdCuentaGananciaCambiaria '1230 Dim TC As Decimal = 2 ' se pone 2, para que cumpla con el check constrains de complementarias Total = LblTotalAcreedores.Text.ToDecimal If Total > 0 Then CveConceptoContable = 64 CveCuenta = CveCuentaGanancia idCta = IdCtaGanancia TipoMovto = True Else CveConceptoContable = 65 CveCuenta = CveCuentaPerdida idCta = idCtaPerdida TipoMovto = False End If If Not Conta.AddPrePolizasDetalle(CvePrePoliza, TipoMovto, Math.Abs(Total), " ", CveConceptoContable, "Fluctuación", Now, idCta, 0, ImporteMX:=Math.Abs(Total), CveCuenta:=CveCuenta, CveSubProyecto:=DdlSubproyecto.SelectedValue.ToEntero) Then ErrorRegistrar = True End If 'saco las cuentas de pérdida y ganancia For Each gvr As GridViewRow In GvAcreedores.Rows Total = gvr.DataKey("Fluctuacion").ToDecimal 'si es pérdida o ganancia 'movimiento de complementaria If Not Conta.AddPrePolizasDetalle(CvePrePoliza, False, Total, gvr.DataKey("SerieFolio"), 202, gvr.DataKey("SerieFolio"), Now, IdCtaComplementaria, 0, CveCompra:=gvr.DataKey("CveCompra").ToEntero, TipoCambio:=TC, ImporteMX:=Total, ImporteME:=Total, CveCuenta:=CveCuentaComplementaria) Then ErrorRegistrar = True Exit For End If Next If Not ErrorRegistrar Then Conta.Commit() Alert(String.Format("La Fluctuación se ha generado
Ver Póliza", CvePrePoliza), TipoMensaje.MsgInformacion) Else Conta.RollBack() End If Conta.Dispose() End Sub #End Region #Region "FLUCTUACION GENERAL" ' Protected Sub BtnGenerar_Click(sender As Object, e As EventArgs) ' Dim AcumuladoGananciaCompras = 0.0, AcumuladoPerdidaCompras = 0.0, AcumuladoGananciaBancos = 0.0, AcumuladoPerdidaBancos = 0.0 ' Dim IDPoliza = -1 ' 'Valida datos de Compras ' For Each gvr As GridViewRow In GvCompras.Rows ' If gvr.DataKey("SinTipoCambio").ToString.ToEntero > 0 AndAlso Not gvr.DataKey("IdCtaAfectable").ToString.ToEntero > 0 Then ' Alert("No se puede Generar la Fluctuación ya que faltan datos en Compras") ' 'Exit Sub ' Else ' If gvr.DataKey("IdCtaAfectable").ToString.ToEntero > 0 Then ' If gvr.DataKey("Fluctuacion").ToString.ToDouble > 0 Then ' AcumuladoGananciaCompras += gvr.DataKey("Fluctuacion").ToString.ToDouble ' Else ' AcumuladoPerdidaCompras += gvr.DataKey("Fluctuacion").ToString.ToDouble * -1 ' End If ' End If ' End If ' Next ' 'Valida datos de Bancos ' For Each gvr As GridViewRow In GvCuentas.Rows ' If Not gvr.DataKey("TipoCambio").ToString.ToEntero > 0 AndAlso Not gvr.DataKey("IdCtaAfectable").ToString.ToEntero > 0 Then ' Alert("No se puede Generar la Fluctuación ya que faltan datos en Cuentas Bancarias") ' 'Exit Sub ' Else ' If gvr.DataKey("IdCtaAfectable").ToString.ToEntero > 0 Then ' If gvr.DataKey("Fluctuacion").ToString.ToDouble > 0 Then ' AcumuladoGananciaBancos += gvr.DataKey("Fluctuacion").ToString.ToDouble ' Else ' AcumuladoPerdidaBancos += gvr.DataKey("Fluctuacion").ToString.ToDouble * -1 ' End If ' End If ' End If ' Next ' Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) ' ObjConta.IniciaTransacSQL() ' Dim ObjBancos As New ClsBancos ' ObjBancos.IniciaTransacSQL() ' Dim ErrorGenerar = False ' Dim Fecha As Date = TxtFecha.Text.ToDate ' IDPoliza = ObjConta.AddPoliza(3, "Fluctuación Cambiaria", (AcumuladoGananciaCompras + AcumuladoPerdidaCompras) * 2, (AcumuladoGananciaCompras + AcumuladoPerdidaCompras) * 2, UsuarioActual.CveUsuario, Fecha) ' If IDPoliza > 0 Then ' 'COMIENZA: AGREGA CUENTAS BANCARIAS ' If AcumuladoGananciaBancos > 0 Or AcumuladoPerdidaBancos > 0 Then ' 'Agrega movimientos ' Dim Fluc As Double ' For Each gvr As GridViewRow In GvCuentas.Rows ' Fluc = gvr.DataKey("Fluctuacion").ToString.ToDouble ' If Math.Abs(Fluc) > 0 AndAlso gvr.DataKey("IdCtaAfectable").ToString.ToEntero > 0 Then ' If Not ObjConta.AddMovimiento(IDPoliza, gvr.DataKey("IdCtaAfectable").ToString.ToEntero, Not Fluc > 0, Math.Abs(Fluc), "", String.Format("{0} Cambiaria de Cuentas Bancarias", If(Fluc > 0, "Ganancia", "Perdida")), 0, Fecha, "") Then ' ErrorGenerar = True ' Exit For ' End If ' End If ' Next ' 'Agrega acumulados ' If Not ErrorGenerar AndAlso AcumuladoGananciaBancos > 0 Then ' If Not ObjConta.AddMovimiento(IDPoliza, 2195, AcumuladoGananciaBancos > 0, AcumuladoGananciaBancos, "", "Acumulado Ganancia Cambiaria de Cuentas Bancarias", 0, Fecha, "") Then ' ErrorGenerar = True ' End If ' End If ' If Not ErrorGenerar AndAlso AcumuladoPerdidaBancos > 0 Then ' If Not ObjConta.AddMovimiento(IDPoliza, 4695, AcumuladoPerdidaBancos > 0, AcumuladoPerdidaBancos, "", "Acumulado Pérdida Cambiaria de Cuentas Bancarias", 0, Fecha, "") Then ' ErrorGenerar = True ' End If ' End If ' Else ' ErrorGenerar = True ' End If ' 'TERMINA: AGREGA CUENTAS BANCARIAS ' 'COMIENZA: AGREGA COMPRAS ' If AcumuladoGananciaCompras > 0 Or AcumuladoPerdidaCompras > 0 Then ' 'Agrega movimientos ' Dim Fluc As Double ' For Each gvr As GridViewRow In GvCompras.Rows ' Fluc = gvr.DataKey("Fluctuacion").ToString.ToDouble ' If Math.Abs(Fluc) > 0 AndAlso gvr.DataKey("IdCtaAfectable").ToString.ToEntero > 0 Then ' If Not ObjConta.AddMovimiento(IDPoliza, gvr.DataKey("IdCtaAfectable").ToString.ToEntero, Not Fluc > 0, Math.Abs(Fluc), "", String.Format("{0} Cambiaria de Compras", If(Fluc > 0, "Ganancia", "Pérdida")), 0, Fecha, "") Then ' ErrorGenerar = True ' Exit For ' End If ' End If ' Next ' 'Agrega acumulados ' If Not ErrorGenerar AndAlso AcumuladoGananciaCompras > 0 Then ' If Not ObjConta.AddMovimiento(IDPoliza, UsuarioActual.Empresa.IdCuentaGananciaCambiaria, Not AcumuladoGananciaCompras > 0, AcumuladoGananciaCompras, "", "Acumulado Ganancia Cambiaria de Compras", 0, Fecha, "") Then ' ErrorGenerar = True ' End If ' End If ' If Not ErrorGenerar AndAlso AcumuladoPerdidaCompras > 0 Then ' If Not ObjConta.AddMovimiento(IDPoliza, UsuarioActual.Empresa.IdCuentaPerdidaCambiaria, Not AcumuladoPerdidaCompras > 0, AcumuladoPerdidaCompras, "", "Acumulado Pérdida Cambiaria de Compras", 0, Fecha, "") Then ' ErrorGenerar = True ' End If ' End If ' Else ' ErrorGenerar = True ' End If ' 'TERMINA: AGREGA COMPRAS ' Else ' ErrorGenerar = True ' End If ' 'Agrega en Bitacoras ' If Not ErrorGenerar Then ' If ObjBancos.AddFluctuacionesBitacora(IDPoliza, Fecha, 1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then ' If Not ObjBancos.AddFluctuacionesBitacora(IDPoliza, Fecha, 2, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then ' ErrorGenerar = True ' End If ' Else ' ErrorGenerar = True ' End If ' End If ' If Not ErrorGenerar Then ' ObjConta.AjustaPoliza(IDPoliza) ' ObjConta.Commit() ' ObjBancos.Commit() ' Alert(String.Format("Fluctuación realizada con exito.

Ver Póliza", IDPoliza)) ' Else ' ObjConta.RollBack() ' ObjBancos.RollBack() ' Alert("Ocurrio un error al generar la poliza", TipoMensaje.MsgAdvertencia) ' End If ' ObjConta.Dispose() ' ObjBancos.Dispose() ' End Sub #End Region #Region "GRIDVIEWS" Protected Sub GvCompras_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCompras.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'TipoCambio = e.Row.DBCampo("TipoCambio").ToString.ToDouble 'e.Row.FCLabel("LbTipoCambioActual").Text = TipoCambioActual.ToString 'e.Row.FCLabel("LbTipoCambio").Text = If(TipoCambio > 0, TipoCambio.ToString, "No hay TipoCambio") 'e.Row.FCLabel("LbFluctuacion").Text = If(TipoCambio > 0, ((TipoCambio - TipoCambioActual) * e.Row.DBCampo("Saldo").ToString.ToDouble).ToString.FormatoNumero, "No aplica") 'If e.Row.FCLabel("LbFluctuacion").Text = "No aplica" Then ' e.Row.BackColor = Drawing.Color.LightSalmon 'ElseIf e.Row.FCLabel("LbFluctuacion").Text.ToDouble < 0 Then ' e.Row.BackColor = Drawing.Color.LightGoldenrodYellow 'End If 'e.Row.FCHyperLink("HLProveedor").NavigateUrl = String.Format("/Compras/Proveedores.aspx?CveProveedor={0}", e.Row.DBCampo("CveProveedor").ToString.ToEntero) 'If Not e.Row.DBCampo("IdCtaContProveedores").ToString.ToEntero > 0 Then ' e.Row.FCHyperLink("HLProveedor").ForeColor = Drawing.Color.Red 'End If 'If e.Row.DBCampo("Fluctuacion").ToString.ToDouble < 0 Then ' e.Row.BackColor = Drawing.Color.LightGoldenrodYellow 'End If 'If e.Row.DBCampo("SinTipoCambio").ToString.ToEntero > 0 Then ' e.Row.BackColor = Drawing.Color.LightSalmon 'End If End If End Sub Protected Sub GvCuentas_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCuentas.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'TipoCambio = e.Row.DBCampo("TipoCambio").ToString.ToDouble 'e.Row.FCLabel("LbTipoCambioActual").Text = TipoCambioActual.ToString 'e.Row.FCLabel("LbTipoCambio").Text = If(TipoCambio > 0, TipoCambio.ToString, "No hay TipoCambio") 'e.Row.FCLabel("LbFluctuacion").Text = If(TipoCambio > 0, ((TipoCambio - TipoCambioActual) * e.Row.DBCampo("Saldo").ToString.ToDouble).ToString, "No aplica") If Not e.Row.DBCampo("IdCtaContable").ToString.ToEntero > 0 Then ' e.Row.FCLabel("LabelBanco").ForeColor = Drawing.Color.Red End If End If End Sub Private Sub GvFiliales_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvFiliales.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CveIE").ToString.ToEntero = 0 Then e.Row.CssClass = "SubTotales" End If End If End Sub Private Sub GvDeudores_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDeudores.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CveIE").ToString.ToEntero = 0 Then e.Row.CssClass = "SubTotales" End If End If End Sub #End Region End Class