diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index ab0e74c3a..21e8ecf2f 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -2415,31 +2415,83 @@ Namespace Modelos Select Case ConceptoContable Case 1 'Cliente If Not ObjFactura.TipoDocto.Contiene("Egs", "Rem", "RNC") Then + Dim TCCliente As Decimal = tipoCambio + Dim TCFluctuacion As Decimal = tipoCambio + 'TOMA EL TC DE LA ULTIMA FLUCTUACION + If ValorMultiplicador = -1 AndAlso UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso ObjFactura.CveMoneda = 2 Then + Dim UltimaFluctuacion As ClsPaginas.MTipoCambioFluctuacion = GlobalTipoCambioUltimaFluctuacion(Now) + + If UsuarioActual.Empresa.Funcionalidad(703) = "1" AndAlso UltimaFluctuacion IsNot Nothing Then + If UltimaFluctuacion.FechaFluctuacion <= Now Then + TCCliente = UltimaFluctuacion.TCFluctuacion + TCFluctuacion = UltimaFluctuacion.TCFluctuacion + End If + End If + End If + If ObjFactura.CveMoneda > 1 Then ConceptoContable = 291 importeMovimiento = (ObjFactura.Total - TotalOtrosConceptos) * ValorMultiplicador - importeMX = importeMovimiento * tipoCambio * Multiplicador + importeMX = importeMovimiento * TCCliente * Multiplicador FechaMovimiento = ObjFactura.FechaPago CveSubProyectoContabilizar = CveSubProyectoVenta 'If ObjFactura.TipoDocto.Contiene("Ant") Then ' TipoMovimiento = Not TipoMovimiento 'lo contrario a ingreso, en este caso es anticipo 'End If - If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${importeMovimiento.FormatoNumero(2)}" + If TCCliente > 1 Then Concepto += $" TC:{TCCliente} ${importeMovimiento.FormatoNumero(2)}" - If tipoCambio = 1 Then + If TCCliente = 1 Then IdCtaContable = ObjFactura.Cliente.IdCtaContClientes Else IdCtaContable = ObjFactura.Cliente.IdCtaContComplementaria If importeMovimiento <> 0 AndAlso (IdCtaContable > 0 Or UsaComplementariaClientes) Then importeMX = importeMovimiento - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, 0, Referencia, 203, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIE, ImporteMX:=Math.Round(importeMovimiento * tipoCambio - importeMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), TipoCambio:=tipoCambio, CveSubProyecto:=CveSubProyectoContabilizar, Contabilizable:=SeContabiliza) Then + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, 0, Referencia, 203, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIE, ImporteMX:=Math.Round(importeMovimiento * TCCliente - importeMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=If(TCCliente = 1, 0, importeMovimiento), TipoCambio:=TCCliente, CveSubProyecto:=CveSubProyectoContabilizar, Contabilizable:=SeContabiliza) Then ErrorPrepoliza = True End If + + 'CONSIDERO FLUCTUACIÓN. + If ValorMultiplicador = -1 AndAlso tipoCambio <> TCFluctuacion AndAlso TCFluctuacion > 1 AndAlso tipoCambio > 1 Then + Dim difFluctuacion As Decimal = tipoCambio - TCFluctuacion + Dim CveConceptoFluctua As Integer = 64 '64.ganacia, 65.perdida + Dim TipoMovtoFluctua As Boolean = True + Dim IdCtaContableFluctua As Integer + If difFluctuacion < 0 Then + CveConceptoFluctua = 65 + TipoMovtoFluctua = False + IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria + Else + CveConceptoFluctua = 64 + TipoMovtoFluctua = True + IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + End If + Dim ImporteFluctuacion As Decimal = Math.Abs((importeMovimiento * difFluctuacion).RoundSQL) + + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovtoFluctua, ImporteFluctuacion, Referencia, CveConceptoFluctua, Concepto, FechaMovimiento, IdCtaContableFluctua, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteFluctuacion, ImporteME:=ImporteFluctuacion, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio, TipoCambioPago:=TCCliente) Then + ErrorPrepoliza = True + Exit For + End If + + End If End If IdCtaContable = ObjFactura.Cliente.IdCtaContMonedaExtranjera End If IdCtaContableCliente = IdCtaContable + + If ValorMultiplicador = -1 AndAlso ConceptoContable = 291 Then + If IdCtaContable <= 0 Then + CuentasContablesInvalidas.Append("
" & GlobalDTContaConceptosContables(-1).FiltroPrimero(String.Format("CveConceptoContable = {0}", ConceptoContable))("ConceptoContable").ToString) + idCuentaContabilizacion = 0 + End If + + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovimiento, importeMovimiento, Referencia, 291, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveIE:=CveIE, ImporteMX:=importeMX, ImporteME:=If(TCCliente = 1, 0, importeMovimiento), CveSubProyecto:=CveSubProyectoContabilizar, PorcentajeImpuesto:=PorcentajeImpuesto, TipoCambio:=TCCliente, Contabilizable:=SeContabiliza) Then + ErrorPrepoliza = True + Exit For + End If + + importeMovimiento = 0 + End If End If Case 3 'Cliente @@ -2801,7 +2853,7 @@ Namespace Modelos End If - Case 136 'Otros Conceptos Dinamicos + Case 136 'Otros Conceptos Dinamicos If ObjFactura.DtOtrosConceptos IsNot Nothing Then For Each row2 As DataRow In ObjFactura.DtOtrosConceptos.Rows If row2("Importe").ToString().ToDecimal > 0 Then @@ -4953,7 +5005,7 @@ Namespace Modelos CveEstatusRefacturacion = 0 End If - Dim CancelacionFecha As Date + Dim CancelacionFecha As Date = MinFecha Dim FolioFiscal As String = ObjFactura.FolioFiscal Dim SolicitudCancelacionAcuse As String = "" Dim CancelacionAcuse As String = "" @@ -6319,9 +6371,13 @@ Namespace Modelos Dim CveVentaDetalleRem = DrRem("CveVentaDetalleRemision").ToString.ToEntero Dim CantidadRem = DrRem("Cantidad").ToString.ToDecimal + 'SI NO UTILIZA EL CAMPO DEBE TOMAR DE LA VENTA If Not CveVentaDetalleRem > 0 Then - ErrorCancelar = True - Exit For + CveVentaDetalleRem = DrRem("CveVentaDetalle").ToString.ToEntero + If Not CveVentaDetalleRem > 0 Then + ErrorCancelar = True + Exit For + End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaDevRem, DrRem("Cantidad").ToString.ToDecimal, DrRem("CveUM").ToString.ToEntero, DrRem("CvePS").ToString.ToEntero, DrRem("PU").ToString.ToDecimal, CveAF:=DrRem("CveActivoFijo").ToString.ToEntero, Serie:=DrRem("Serie").ToString, Lote:=DrRem("Lote").ToString, FechaCaducidad:=DrRem("FechaCaducidad").ToString.ToDate, CveVentaDetalle:=CveVentaDetalleRem, CveMovimientoDetalleEntrada:=DrRem("CveMovimientoDetalle").ToString().ToEntero(), CveSeccionAlmacen:=-3) Then @@ -8794,6 +8850,42 @@ Namespace Modelos HttpContext.Current.Application("GlobalDTTiposDocumentos") = value End Set End Property + Public ReadOnly Property GlobalTipoCambioUltimaFluctuacion(Optional Fecha As Date = MinFecha) As ClsPaginas.MTipoCambioFluctuacion + Get + + If HttpContext.Current.Application("GlobalTipoCambioUltimaFluctuacion") Is Nothing Then + Dim ObjGral As New ClsGenerales + If ObjGral.GetTipoCambioUltimaFluctuacion(-1, Now) AndAlso ObjGral.DtResultados.Rows.Count > 0 Then + HttpContext.Current.Application("GlobalTipoCambioUltimaFluctuacion") = ObjGral.DtResultados.Copy() + Else + HttpContext.Current.Application("GlobalTipoCambioUltimaFluctuacion") = Nothing + End If + ObjGral.Dispose() + End If + + Dim fluctuacion = New ClsPaginas.MTipoCambioFluctuacion() With { + .TCFluctuacion = 0, + .FechaFluctuacion = MinFecha + } + + 'sino tiene dato lo recargo por si ya esta insertado + If Fecha = MinFecha Then Fecha = Now + + If HttpContext.Current.Application("GlobalTipoCambioUltimaFluctuacion") IsNot Nothing Then + + Dim dr = DirectCast(HttpContext.Current.Application("GlobalTipoCambioUltimaFluctuacion"), DataTable).FiltroPrimero(String.Format("Fecha <= '{0}'", Fecha), Orderby:="Fecha DESC") + If dr IsNot Nothing Then + fluctuacion.TCFluctuacion = dr("TCFluctuacion").ToString().ToDecimal() + fluctuacion.FechaFluctuacion = dr("FechaFluctuacion").ToString().ToDateTime() + End If + + Return fluctuacion + Else + Return fluctuacion + End If + + End Get + End Property Property GlobalDTCobranzaEstatus(CveEmpresa As Integer) As DataTable Get If CveEmpresa <> -1 Then