diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index 17149b773..3715fdc45 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -2180,7 +2180,7 @@ Namespace Modelos IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaGananciaCambiaria CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria End If - Dim ImporteFluctuacion As Decimal = Math.Abs((Importe251 * difFluctuacion).RoundSQL) + Dim ImporteFluctuacion As Decimal = Math.Abs((Importe251 * difFluctuacion).RoundSQL) * ValorMultiplicador If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovtoFluctua, ImporteFluctuacion, Referencia, CveConceptoFluctua, Concepto, FechaMovimiento, IdCtaContableFluctua, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=Dr("CveVenta").ToString.ToEntero, ImporteMX:=ImporteFluctuacion, ImporteME:=ImporteFluctuacion, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=TipoCambioNC, TipoCambioPago:=Dr("TCCambioValuacion").ToString.ToDecimal, CveCuenta:=CveCuenta) Then ErrorPrepoliza = True @@ -2273,7 +2273,7 @@ Namespace Modelos IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaGananciaCambiaria CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria End If - Dim ImporteFluctuacion As Decimal = Math.Abs((importeMovimientoDev * difFluctuacion).RoundSQL) + Dim ImporteFluctuacion As Decimal = Math.Abs((importeMovimientoDev * difFluctuacion).RoundSQL) * ValorMultiplicador If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovtoFluctua, ImporteFluctuacion, Referencia, CveConceptoFluctua, Concepto, FechaMovimiento, IdCtaContableFluctua, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=CveVentaDevolucion, ImporteMX:=ImporteFluctuacion, ImporteME:=ImporteFluctuacion, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio, TipoCambioPago:=TipoCambioFactura, CveCuenta:=CveCuenta) Then ErrorPrepoliza = True @@ -2439,30 +2439,118 @@ Namespace Modelos CveSubProyectoContabilizar = CveSubProyectoVenta - If importeMovimiento <> 0 Then - - If ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, importeMovimiento, Referencia, 251, Concepto, FechaMovimiento, - IdCtaContable, -1, CveVenta:=row2("CveVentaNC").ToString.ToEntero, - CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=ObjFactura.CveVenta, - ImporteMX:=importeMovimiento * tipoCambio, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), - CveCuenta:=CveCuenta, CveSubProyecto:=CveSubProyectoContabilizar, Contabilizable:=Contabilizable) Then - If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, importeMovimiento, Referencia, 91, Concepto, - FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, - CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=row2("CveVentaNC").ToString.ToEntero, - ImporteMX:=importeMovimiento * tipoCambio, ImporteME:=If(tipoCambio = 1, 0, importeMovimiento), CveCuenta:=CveCuenta, - CveSubProyecto:=CveSubProyectoContabilizar, Contabilizable:=Contabilizable) Then - ErrorPrepoliza = True - Exit For - End If - Else - ErrorPrepoliza = True - Exit For + If importeMovimiento <> 0 Then + + Dim Importe91 As Decimal = 0 + Dim ImporteMN91 As Decimal = 0 + Dim Importe251 As Decimal = 0 + Dim ImporteMN251 As Decimal = 0 + + If ObjFactura.CveMoneda = 1 AndAlso Not row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = row2("Importe").ToString.ToDecimal + Importe91 = row2("Importe").ToString.ToDecimal + ImporteMN91 = row2("Importe").ToString.ToDecimal + tipoCambio = 1 + ElseIf ObjFactura.CveMoneda = 2 AndAlso Not row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = row2("Importe").ToString.ToDecimal + Importe91 = row2("Importe").ToString.ToDecimal + ImporteMN91 = row2("Importe").ToString.ToDecimal * tipoCambio + ElseIf ObjFactura.CveMoneda = 2 AndAlso row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = row2("Importe").ToString.ToDecimal + Importe91 = row2("Importe").ToString.ToDecimal + ImporteMN91 = row2("Importe").ToString.ToDecimal * tipoCambio + ElseIf ObjFactura.CveMoneda = 1 AndAlso row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + + Importe91 = row2("Importe").ToString.ToDecimal / tipoCambio + ImporteMN91 = row2("Importe").ToString.ToDecimal + End If + + Dim TCFluctuacion As Decimal = row2("TCCambioValuacion").ToString.ToDecimal + + If TCFluctuacion = 1 AndAlso tipoCambio > 1 Then + TCFluctuacion = GlobalTipoCambio(ObjFactura.Fecha).ToDecimal + End If + + If ObjFactura.CveMoneda = 2 AndAlso Not row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + ImporteMN251 = row2("Importe").ToString.ToDecimal * TCFluctuacion + ElseIf ObjFactura.CveMoneda = 2 AndAlso row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + ImporteMN251 = row2("Importe").ToString.ToDecimal * TCFluctuacion + ElseIf ObjFactura.CveMoneda = 1 AndAlso row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + Importe251 = row2("Importe").ToString.ToDecimal / TCFluctuacion + ImporteMN251 = row2("Importe").ToString.ToDecimal + Else + ImporteMN251 = row2("Importe").ToString.ToDecimal + End If + + Importe251 = (Importe251 * Multiplicador * ValorMultiplicador).RoundSQL + ImporteMN251 = ImporteMN251 * ValorMultiplicador + Importe91 = (Importe91 * ValorMultiplicador).RoundSQL + ImporteMN91 = (ImporteMN91 * Multiplicador * ValorMultiplicador).RoundSQL + + + If tipoCambio > 1 Then Concepto += $" TC:{tipoCambio} ${Importe91.FormatoNumero(2)}" + + Dim CveUltimaVenta = row2("CveVenta").ToString.ToEntero + + Dim ImporteComplementarioIngreso As Decimal = 0 + If UsaComplementariaClientes = True AndAlso tipoCambio > 1 Then + ImporteMN91 = Importe91 + ImporteComplementarioIngreso = ((Importe91 * tipoCambio) - Importe91).RoundSQL + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, Importe91, Referencia, 203, Concepto, FechaMovimiento, ObjFactura.Cliente.IdCtaContComplementaria, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=row2("CveVenta").ToString.ToEntero, ImporteMX:=ImporteComplementarioIngreso, ImporteME:=If(tipoCambio = 1, 0, Importe91), CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio, TipoCambioPago:=row2("TCCambioValuacion").ToString.ToDecimal) Then + ErrorPrepoliza = True + Exit For + End If + End If + + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, False, Importe91, Referencia, 91, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=row2("CveVenta").ToString.ToEntero, ImporteMX:=ImporteMN91, ImporteME:=If(tipoCambio = 1, 0, Importe91), CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio) Then + ErrorPrepoliza = True + Exit For + End If + + + If UsaComplementariaClientes = True AndAlso row2("TCCambioValuacion").ToString.ToDecimal > 1 Then + ImporteMN251 = Importe251 + Dim ImporteComplementarioNC As Decimal = ((Importe251 * row2("TCCambioValuacion").ToString.ToDecimal) - Importe251).RoundSQL + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, Importe251, Referencia, 207, Concepto, FechaMovimiento, ObjFactura.Cliente.IdCtaContComplementaria, -1, CveVenta:=row2("CveVenta").ToString.ToEntero, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteComplementarioNC, ImporteME:=If(row2("TCCambioValuacion").ToString.ToDecimal = 1, 0, Importe251), CveSubProyecto:=CveSubProyectoContabilizar, CveVentaAmortizacion:=ObjFactura.CveVenta, TipoCambio:=row2("TCCambioValuacion").ToString.ToDecimal) Then + ErrorPrepoliza = True + Exit For + End If + End If + + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, True, Importe251, Referencia, 251, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=row2("CveVenta").ToString.ToEntero, CveCliente:=ObjFactura.CveCliente, ImporteMX:=ImporteMN251, ImporteME:=If(row2("TCCambioValuacion").ToString.ToDecimal = 1, 0, Importe251), CveSubProyecto:=CveSubProyectoContabilizar, CveVentaAmortizacion:=ObjFactura.CveVenta, TipoCambio:=row2("TCCambioValuacion").ToString.ToDecimal, TipoCambioPago:=tipoCambio) Then + ErrorPrepoliza = True + Exit For + End If + + 'CONSIDERO FLUCTUACIÓN. + If 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 + CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + Else + CveConceptoFluctua = 64 + TipoMovtoFluctua = True + IdCtaContableFluctua = UsuarioActual.Empresa.IdCuentaGananciaCambiaria + CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + End If + Dim ImporteFluctuacion As Decimal = Math.Abs((Importe251 * difFluctuacion).RoundSQL) * ValorMultiplicador + + If Not ObjConta.AddPrePolizasDetalle(ObjFactura.CvePrePoliza, TipoMovtoFluctua, ImporteFluctuacion, Referencia, CveConceptoFluctua, Concepto, FechaMovimiento, IdCtaContableFluctua, -1, CveVenta:=ObjFactura.CveVenta, CveCliente:=ObjFactura.CveCliente, CveVentaAmortizacion:=row2("CveVenta").ToString.ToEntero, ImporteMX:=ImporteFluctuacion, ImporteME:=ImporteFluctuacion, CveSubProyecto:=CveSubProyectoContabilizar, TipoCambio:=tipoCambio, TipoCambioPago:=row2("TCCambioValuacion").ToString.ToDecimal, CveCuenta:=CveCuenta) Then + ErrorPrepoliza = True + Exit For + End If End If + End If End If Next End If - Else If ObjFactura.DtAnticipos IsNot Nothing Then For Each row2 As DataRow In ObjFactura.DtAnticipos.Rows @@ -4089,7 +4177,7 @@ Namespace Modelos Dim CveMovimiento As Integer = 0 Dim Folio As Integer = 0 - If Not ErrorCancelar AndAlso RealizarDevolucionAlmacen Then + If Not ErrorCancelar AndAlso RealizarDevolucionAlmacen AndAlso ObjFactura.SaldoAlmacen <> 0 Then Dim CveAlmacenDevolucion = ObjFactura.CveAlmacenDevolucion 'SALIDA DE ALMACEN - SALIDA POR TRASPASO CUANDO ES REMISION - DEVOLUCION (SI ES TRASPASO Y TIENE CONTRATO NO HACE DEVOLUCIóN)