diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index b6d971977..d9fd38461 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -11183,6 +11183,7 @@ Partial Class Ventas Dim ObjConta As New ClsContabilidad Dim ObjVenta As New ClsVentas(ObjConta.IniciaTransacSQL()) + Dim ObjIE As New ClsBancos(ObjConta.IniciaTransacSQL()) Dim ObjContpaq As ClsContPAQi = Nothing Dim CvePrepoliza As Integer @@ -11215,11 +11216,16 @@ Partial Class Ventas ' FechaMaxima = "01/01/2018".ToDate 'End If + + + + CvePrepoliza = ObjConta.AddPrePolizas("Ventas/Anticipos", CvePlantillaPoliza, TxtTotal.Text.ToDecimal, TxtTotal.Text.ToDecimal, DdlMoneda.SelectedValue.ToEntero, TxtFechaAnticipoCliente.Text.ToDate, String.Format("{0} {1} {2}-{3}", If(EsAnticipo2017Jam, "Aplicación Anticipo 2017", ""), NombreCliente, Serie, TxtFolio.Text), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If CvePrepoliza > 0 Then Dim tipoCambioPago As Decimal = 1 Dim tipoCambioVenta As Decimal = 1 + Dim tipoCambioVentaValuacion As Decimal = 1 Dim PorcentajePago As Decimal = 100 Dim dtConceptos As DataTable = Nothing Dim CveMonedaVenta = DdlMoneda.SelectedValue.ToEntero @@ -11243,21 +11249,42 @@ Partial Class Ventas For Each gvr As GridViewRow In GVAnticipos.Rows If gvr.FCCheckBox("Chk" & gvr.RowIndex).Checked Then + + Dim FechaUltimaFluctuacion As Date = MinFecha + Dim TipoCambioFluctuacion As Decimal = 1 + If ObjIE.GetFluctuacionesBitacora(UsuarioActual.CveEmpresa) Then + If ObjIE.DtResultados.Rows.Count > 0 Then + Dim tFecha As Date = gvr.DataKey("Fecha").ToDate + Dim Fecha As String = String.Format("{0}/{1}/{2}", tFecha.Year, tFecha.Month, tFecha.Day) + Dim drr As DataRow = ObjIE.DtResultados.FiltroPrimero("Fecha < #" & Fecha & "#", "Fecha DESC") + + If drr IsNot Nothing Then + FechaUltimaFluctuacion = drr("Fecha").ToString.ToDate + TipoCambioFluctuacion = drr("TipoCambio").ToString.ToDecimal + End If + + End If + End If + If DdlMoneda.SelectedValue.ToEntero = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then 'Si la venta viene en Pesos y se va a pagar en Pesos tipoCambioPago = 1 tipoCambioVenta = 1 + tipoCambioVentaValuacion = 1 PorcentajePago = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal / gvr.DataKey("Original").ToDecimal ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then 'Si la venta viene en Dolares y se va a pagar en Pesos tipoCambioPago = gvr.FCTextBox("TxtTC" & gvr.RowIndex).Text.ToDecimal tipoCambioVenta = TxtTipoCambio.Text.ToDecimal + tipoCambioVentaValuacion = If(TxtFecha.Text.ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, TxtTipoCambio.Text.ToDecimal) PorcentajePago = (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal) / gvr.DataKey("Original").ToDecimal ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then 'Si la venta viene en Dolares y se va a pagar en DOLARES tipoCambioPago = gvr.DataKey("TipoCambio").ToString.ToDecimal tipoCambioVenta = TxtTipoCambio.Text.ToDecimal + tipoCambioVentaValuacion = If(TxtFecha.Text.ToDate < FechaUltimaFluctuacion, TipoCambioFluctuacion, TxtTipoCambio.Text.ToDecimal) PorcentajePago = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal / gvr.DataKey("Original").ToDecimal ElseIf DdlMoneda.SelectedValue.ToEntero = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then 'Si la venta viene en pesos y se va a pagar en DOLARES tipoCambioPago = gvr.FCTextBox("TxtTC" & gvr.RowIndex).Text.ToDecimal tipoCambioVenta = 1 + tipoCambioVentaValuacion = 1 PorcentajePago = (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal) / gvr.DataKey("Original").ToDecimal End If @@ -11284,17 +11311,17 @@ Partial Class Ventas importeMX = importeMovimiento ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 1 Then importeMovimiento = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal - importeMX = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioVenta + importeMX = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioVentaValuacion ElseIf DdlMoneda.SelectedValue.ToEntero = 2 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then importeMovimiento = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal - importeMX = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioVenta + importeMX = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioVentaValuacion ElseIf DdlMoneda.SelectedValue.ToEntero = 1 AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then importeMovimiento = gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal importeMX = importeMovimiento End If importeMovimiento = Math.Round(importeMovimiento, 2) importeMX = Math.Round(importeMX, 2) - TipoCambioGeneral = tipoCambioVenta + TipoCambioGeneral = tipoCambioVentaValuacion If CveMonedaVenta = 1 Then IdCtaContable = IdCtaContClientes @@ -11315,7 +11342,7 @@ Partial Class Ventas CveCuentaContabilizacion = 0 End If - If Not ObjConta.AddPrePolizasDetalle(CvePrepoliza, TipoMovimiento, 0, Concepto, 207, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=Math.Round(importeMovimiento * tipoCambioVenta - importeMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioVenta) Then + If Not ObjConta.AddPrePolizasDetalle(CvePrepoliza, TipoMovimiento, 0, Concepto, 207, Concepto, FechaMovimiento, IdCtaContable, -1, CveVenta:=CveVenta, CveCliente:=CveCliente, ImporteMX:=Math.Round(importeMovimiento * tipoCambioVenta - importeMovimiento, 2, MidpointRounding.AwayFromZero), ImporteME:=importeMovimiento, CveCuenta:=CveCuenta, TipoCambio:=tipoCambioVentaValuacion) Then ErrorConta = True End If @@ -11543,13 +11570,14 @@ Partial Class Ventas If CveMonedaVenta <> 1 OrElse gvr.DataKey("CveMoneda").ToEntero <> 1 Then IdCtaContable = UsuarioActual.Empresa.IdCuentaGananciaCambiaria CveCuenta = UsuarioActual.Empresa.CveCuentaGananciaCambiaria + Dim TipoCambioGanancia As Decimal = If(Not (gvr.DataKey("CveIE").ToString.ToEntero > 0 AndAlso gvr.DataKey("CveConceptoContable").ToString().ToEntero = 66), tipoCambioVentaValuacion, tipoCambioVenta) - If tipoCambioPago > tipoCambioVenta AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then - importeMovimiento = (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioPago) - (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioVenta) 'Añadimos la diferencia de ganancia en la venta + If tipoCambioPago > TipoCambioGanancia AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then + importeMovimiento = (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioPago) - (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * TipoCambioGanancia) 'Añadimos la diferencia de ganancia en la venta importeMovimiento = Math.Abs(Math.Round(importeMovimiento, 2)) importeMX = importeMovimiento End If - Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, tipoCambioVenta, tipoCambioPago) + Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, TipoCambioGanancia, tipoCambioPago) TipoCambioGeneral = TCImpuestos Else importeMovimiento = 0 @@ -11558,13 +11586,14 @@ Partial Class Ventas If CveMonedaVenta <> 1 OrElse gvr.DataKey("CveMoneda").ToEntero <> 1 Then IdCtaContable = UsuarioActual.Empresa.IdCuentaPerdidaCambiaria CveCuenta = UsuarioActual.Empresa.CveCuentaPerdidaCambiaria + Dim TipoCambioPerdida As Decimal = If(Not (gvr.DataKey("CveIE").ToString.ToEntero > 0 AndAlso gvr.DataKey("CveConceptoContable").ToString().ToEntero = 66), tipoCambioVentaValuacion, tipoCambioVenta) - If tipoCambioPago < tipoCambioVenta AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then - importeMovimiento = (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioVenta) - (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioPago) 'Añadimos la diferencia de perdida en la venta + If tipoCambioPago < TipoCambioPerdida AndAlso gvr.DataKey("CveMoneda").ToEntero = 2 Then + importeMovimiento = (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * TipoCambioPerdida) - (gvr.FCTextBox("TxtAnticipo" & gvr.RowIndex).Text.ToDecimal * tipoCambioPago) 'Añadimos la diferencia de perdida en la venta importeMovimiento = Math.Abs(Math.Round(importeMovimiento, 2)) importeMX = importeMovimiento End If - Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, tipoCambioVenta, tipoCambioPago) + Dim TCImpuestos As Decimal = If(FuncionalidadFluctuacionImpuestos, TipoCambioPerdida, tipoCambioPago) TipoCambioGeneral = TCImpuestos Else importeMovimiento = 0 @@ -11627,6 +11656,8 @@ Partial Class Ventas End If ObjConta.Dispose() + ObjIE.Dispose() + Else 'cuando no se ha registrado la venta @@ -21204,6 +21235,26 @@ Partial Class Ventas TrFolioFiscal.Visible = False TxtFecha.Text = Now.ToShortDateString() TipoCambioFactura = TxtTipoCambio.Text.ToDecimal + + If DdlMoneda.SelectedValue.ToEntero > 1 Then + Dim ObjIE As New ClsBancos + If ObjIE.GetFluctuacionesBitacora(UsuarioActual.CveEmpresa) Then + If ObjIE.DtResultados.Rows.Count > 0 Then + Dim tFecha As Date = TxtFecha.Text.ToDate + Dim Fecha As String = String.Format("{0}/{1}/{2}", tFecha.Year, tFecha.Month, tFecha.Day) + Dim drr As DataRow = ObjIE.DtResultados.FiltroPrimero("Fecha < #" & Fecha & "#", "Fecha DESC") + + If drr IsNot Nothing Then + TipoCambioFactura = drr("TipoCambio").ToString.ToDecimal + End If + + End If + End If + ObjIE.Dispose() + Else + TipoCambioFactura = 1 + End If + TxtTipoCambio.Text = GlobalTipoCambio(Now).ToString DivEstatusFac.Visible = False